internal System.Data.ProviderBase.DbConnectionPool GetConnectionPool(System.Data.ProviderBase.DbConnectionFactory connectionFactory) { object obj2 = null; if (this._poolGroupOptions != null) { System.Data.ProviderBase.DbConnectionPoolIdentity noIdentity = System.Data.ProviderBase.DbConnectionPoolIdentity.NoIdentity; if (this._poolGroupOptions.PoolByIdentity) { noIdentity = System.Data.ProviderBase.DbConnectionPoolIdentity.GetCurrent(); if (noIdentity.IsRestricted) { noIdentity = null; } } if (noIdentity != null) { obj2 = this._poolCollection[noIdentity]; if (obj2 == null) { System.Data.ProviderBase.DbConnectionPoolProviderInfo connectionPoolProviderInfo = connectionFactory.CreateConnectionPoolProviderInfo(this.ConnectionOptions); System.Data.ProviderBase.DbConnectionPool pool = new System.Data.ProviderBase.DbConnectionPool(connectionFactory, this, noIdentity, connectionPoolProviderInfo); lock (this) { HybridDictionary dictionary = this._poolCollection; obj2 = dictionary[noIdentity]; if ((obj2 == null) && this.MarkPoolGroupAsActive()) { pool.Startup(); HybridDictionary dictionary2 = new HybridDictionary(1 + dictionary.Count, false); foreach (DictionaryEntry entry in dictionary) { dictionary2.Add(entry.Key, entry.Value); } dictionary2.Add(noIdentity, pool); connectionFactory.PerformanceCounters.NumberOfActiveConnectionPools.Increment(); this._poolCollection = dictionary2; this._poolCount = dictionary2.Count; obj2 = pool; pool = null; } } if (pool != null) { pool.Shutdown(); } } } } if (obj2 == null) { lock (this) { this.MarkPoolGroupAsActive(); } } return((System.Data.ProviderBase.DbConnectionPool)obj2); }
public override bool Equals(object value) { bool flag = (this == NoIdentity) || (this == value); if (!flag && (value != null)) { System.Data.ProviderBase.DbConnectionPoolIdentity identity = (System.Data.ProviderBase.DbConnectionPoolIdentity)value; flag = ((this._sidString == identity._sidString) && (this._isRestricted == identity._isRestricted)) && (this._isNetwork == identity._isNetwork); } return(flag); }
internal static System.Data.ProviderBase.DbConnectionPoolIdentity GetCurrent() { if (!System.Data.Common.ADP.IsWindowsNT) { return(NoIdentity); } WindowsIdentity currentWindowsIdentity = GetCurrentWindowsIdentity(); IntPtr windowsIdentityToken = GetWindowsIdentityToken(currentWindowsIdentity); uint tokenInformationLength = 0x800; uint tokenString = 0; IntPtr zero = IntPtr.Zero; IntPtr stringSid = IntPtr.Zero; System.Data.Common.UnsafeNativeMethods.SetLastError(0); bool isRestricted = System.Data.Common.UnsafeNativeMethods.IsTokenRestricted(windowsIdentityToken); if (Marshal.GetLastWin32Error() != 0) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } System.Data.ProviderBase.DbConnectionPoolIdentity identity = null; RuntimeHelpers.PrepareConstrainedRegions(); try { bool flag; if (!System.Data.Common.UnsafeNativeMethods.CheckTokenMembership(windowsIdentityToken, NetworkSid, out flag)) { IntegratedSecurityError(1); } RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { zero = System.Data.Common.SafeNativeMethods.LocalAlloc(0, (IntPtr)tokenInformationLength); } if (IntPtr.Zero == zero) { throw new OutOfMemoryException(); } if (!System.Data.Common.UnsafeNativeMethods.GetTokenInformation(windowsIdentityToken, 1, zero, tokenInformationLength, ref tokenString)) { if (tokenString > tokenInformationLength) { tokenInformationLength = tokenString; RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { System.Data.Common.SafeNativeMethods.LocalFree(zero); zero = IntPtr.Zero; zero = System.Data.Common.SafeNativeMethods.LocalAlloc(0, (IntPtr)tokenInformationLength); } if (IntPtr.Zero == zero) { throw new OutOfMemoryException(); } if (!System.Data.Common.UnsafeNativeMethods.GetTokenInformation(windowsIdentityToken, 1, zero, tokenInformationLength, ref tokenString)) { IntegratedSecurityError(2); } } else { IntegratedSecurityError(3); } } currentWindowsIdentity.Dispose(); if (!System.Data.Common.UnsafeNativeMethods.ConvertSidToStringSidW(Marshal.ReadIntPtr(zero, 0), out stringSid)) { IntegratedSecurityError(4); } if (IntPtr.Zero == stringSid) { throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.ConvertSidToStringSidWReturnedNull); } identity = new System.Data.ProviderBase.DbConnectionPoolIdentity(Marshal.PtrToStringUni(stringSid), isRestricted, flag); } finally { if (IntPtr.Zero != zero) { System.Data.Common.SafeNativeMethods.LocalFree(zero); zero = IntPtr.Zero; } if (IntPtr.Zero != stringSid) { System.Data.Common.SafeNativeMethods.LocalFree(stringSid); stringSid = IntPtr.Zero; } } return(identity); }
internal static System.Data.ProviderBase.DbConnectionPoolIdentity GetCurrent() { if (!System.Data.Common.ADP.IsWindowsNT) { return NoIdentity; } WindowsIdentity currentWindowsIdentity = GetCurrentWindowsIdentity(); IntPtr windowsIdentityToken = GetWindowsIdentityToken(currentWindowsIdentity); uint tokenInformationLength = 0x800; uint tokenString = 0; IntPtr zero = IntPtr.Zero; IntPtr stringSid = IntPtr.Zero; System.Data.Common.UnsafeNativeMethods.SetLastError(0); bool isRestricted = System.Data.Common.UnsafeNativeMethods.IsTokenRestricted(windowsIdentityToken); if (Marshal.GetLastWin32Error() != 0) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } System.Data.ProviderBase.DbConnectionPoolIdentity identity = null; RuntimeHelpers.PrepareConstrainedRegions(); try { bool flag; if (!System.Data.Common.UnsafeNativeMethods.CheckTokenMembership(windowsIdentityToken, NetworkSid, out flag)) { IntegratedSecurityError(1); } RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { zero = System.Data.Common.SafeNativeMethods.LocalAlloc(0, (IntPtr) tokenInformationLength); } if (IntPtr.Zero == zero) { throw new OutOfMemoryException(); } if (!System.Data.Common.UnsafeNativeMethods.GetTokenInformation(windowsIdentityToken, 1, zero, tokenInformationLength, ref tokenString)) { if (tokenString > tokenInformationLength) { tokenInformationLength = tokenString; RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { System.Data.Common.SafeNativeMethods.LocalFree(zero); zero = IntPtr.Zero; zero = System.Data.Common.SafeNativeMethods.LocalAlloc(0, (IntPtr) tokenInformationLength); } if (IntPtr.Zero == zero) { throw new OutOfMemoryException(); } if (!System.Data.Common.UnsafeNativeMethods.GetTokenInformation(windowsIdentityToken, 1, zero, tokenInformationLength, ref tokenString)) { IntegratedSecurityError(2); } } else { IntegratedSecurityError(3); } } currentWindowsIdentity.Dispose(); if (!System.Data.Common.UnsafeNativeMethods.ConvertSidToStringSidW(Marshal.ReadIntPtr(zero, 0), out stringSid)) { IntegratedSecurityError(4); } if (IntPtr.Zero == stringSid) { throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.ConvertSidToStringSidWReturnedNull); } identity = new System.Data.ProviderBase.DbConnectionPoolIdentity(Marshal.PtrToStringUni(stringSid), isRestricted, flag); } finally { if (IntPtr.Zero != zero) { System.Data.Common.SafeNativeMethods.LocalFree(zero); zero = IntPtr.Zero; } if (IntPtr.Zero != stringSid) { System.Data.Common.SafeNativeMethods.LocalFree(stringSid); stringSid = IntPtr.Zero; } } return identity; }