internal AdamTopologyProvider(int adamPort)
 {
     ExTraceGlobals.TopologyProviderTracer.TraceDebug <int, int>((long)this.GetHashCode(), "Creating new ADAM topo provider instance {0}, port {1}", this.GetHashCode(), adamPort);
     this.adamPort        = adamPort;
     this.topologyVersion = 1;
     ADProviderPerf.AddDCInstance(Environment.MachineName);
 }
        protected override IList <ADServerInfo> InternalGetServersForRole(string partitionFqdn, IList <string> currentlyUsedServers, ADServerRole role, int serversRequested, bool forestWideAffinityRequested = false)
        {
            LdapTopologyProvider.MiniTopology miniTopology = new LdapTopologyProvider.MiniTopology(partitionFqdn);
            miniTopology = this.topologies.GetOrAdd(partitionFqdn, miniTopology);
            if (ExTraceGlobals.TopologyProviderTracer.IsTraceEnabled(TraceType.DebugTrace))
            {
                ExTraceGlobals.TopologyProviderTracer.TraceDebug((long)this.GetHashCode(), "PartitionFqdn {0}. GetServersForRole {1}, {2} current: [{3}], need {4} servers", new object[]
                {
                    partitionFqdn,
                    role,
                    currentlyUsedServers.Count,
                    string.Join(",", currentlyUsedServers ?? Enumerable.Empty <string>()),
                    serversRequested
                });
            }
            ADServerInfo adserverInfo = null;

            if (miniTopology.DCInfo == null)
            {
                adserverInfo = this.GetDirectoryServer(partitionFqdn, ADRole.DomainController);
                miniTopology.SetServerInfo(adserverInfo, ADServerRole.DomainController);
                miniTopology.IncrementTopologyVersion();
                adserverInfo = null;
            }
            switch (role)
            {
            case ADServerRole.GlobalCatalog:
                adserverInfo = miniTopology.GCInfo;
                if (adserverInfo == null)
                {
                    adserverInfo = this.GetDirectoryServer(partitionFqdn, ADRole.GlobalCatalog);
                    miniTopology.SetServerInfo(adserverInfo, role);
                    miniTopology.IncrementTopologyVersion();
                }
                break;

            case ADServerRole.DomainController:
            case ADServerRole.ConfigurationDomainController:
                adserverInfo = ((ADServerRole.DomainController == role) ? miniTopology.DCInfo : miniTopology.CDCInfo);
                if (adserverInfo == null)
                {
                    adserverInfo = this.GetDirectoryServer(partitionFqdn, ADRole.DomainController);
                    miniTopology.SetServerInfo(adserverInfo, role);
                    miniTopology.IncrementTopologyVersion();
                }
                break;
            }
            ExTraceGlobals.TopologyProviderTracer.TraceDebug <string, string>((long)this.GetHashCode(), "PartitionFqdn {0}. GetServerForRole returning 1 server {1}", partitionFqdn, adserverInfo.FqdnPlusPort);
            ADProviderPerf.AddDCInstance(adserverInfo.Fqdn);
            ADServerInfo adserverInfo2 = (ADServerInfo)adserverInfo.Clone();

            adserverInfo2.Mapping = (adserverInfo2.Fqdn.Equals((currentlyUsedServers == null || currentlyUsedServers.Count == 0) ? string.Empty : currentlyUsedServers[0], StringComparison.OrdinalIgnoreCase) ? 0 : -1);
            return(new List <ADServerInfo>
            {
                adserverInfo2
            });
        }
        // Token: 0x06000DCB RID: 3531 RVA: 0x0003F978 File Offset: 0x0003DB78
        internal static PooledLdapConnection CreateOneTimeConnection(NetworkCredential networkCredential, ADServerInfo serverInfo, LocatorFlags connectionFlags = LocatorFlags.None)
        {
            string arg = "<null>\\<null>";

            if (networkCredential != null)
            {
                arg = networkCredential.Domain + "\\" + networkCredential.UserName;
            }
            else
            {
                using (WindowsIdentity current = WindowsIdentity.GetCurrent())
                {
                    if (current.ImpersonationLevel == TokenImpersonationLevel.Delegation || current.ImpersonationLevel == TokenImpersonationLevel.Impersonation)
                    {
                        arg = current.Name;
                    }
                }
            }
            ExTraceGlobals.ConnectionTracer.TraceDebug <string, string>(0L, "LdapConnectionPool::CreateOneTimeConnection - opening new ONE-TIME PooledLdapConnection to {0} as {1}", serverInfo.FqdnPlusPort, arg);
            ADProviderPerf.AddDCInstance(serverInfo.Fqdn);
            ADServerRole         role = (serverInfo.Port == 389) ? ADServerRole.DomainController : ADServerRole.GlobalCatalog;
            bool                 flag = false;
            PooledLdapConnection pooledLdapConnection = null;
            PooledLdapConnection result;

            try
            {
                pooledLdapConnection = new PooledLdapConnection(serverInfo, role, false, networkCredential);
                if (LocatorFlags.None != connectionFlags)
                {
                    pooledLdapConnection.SessionOptions.LocatorFlag |= connectionFlags;
                }
                Globals.LogEvent(DirectoryEventLogConstants.Tuple_DSC_EVENT_NEW_CONNECTION, null, new object[]
                {
                    serverInfo.Fqdn,
                    serverInfo.Port,
                    string.Empty
                });
                pooledLdapConnection.BindWithRetry(3);
                pooledLdapConnection.SetNamingContexts();
                flag   = true;
                result = pooledLdapConnection;
            }
            catch (LdapException ex)
            {
                throw new ADTransientException(DirectoryStrings.ExceptionCreateLdapConnection(serverInfo.FqdnPlusPort, ex.Message, (uint)ex.ErrorCode), ex);
            }
            finally
            {
                if (!flag && pooledLdapConnection != null)
                {
                    pooledLdapConnection.ReturnToPool();
                }
            }
            return(result);
        }
 public override void SetConfigDC(string partitionFqdn, string serverName, int port)
 {
     base.SetConfigDC(partitionFqdn, serverName, port);
     ExTraceGlobals.TopologyProviderTracer.TraceDebug <string, string, int>((long)this.GetHashCode(), "PartitionFqdn {0} setting Config DC to {1}:{2}", partitionFqdn, serverName, port);
     LdapTopologyProvider.MiniTopology miniTopology = new LdapTopologyProvider.MiniTopology(partitionFqdn);
     miniTopology = this.topologies.GetOrAdd(partitionFqdn, miniTopology);
     miniTopology.SetServerInfo(new ADServerInfo(serverName, partitionFqdn, port, null, 100, AuthType.Kerberos, true), ADServerRole.ConfigurationDomainController);
     miniTopology.IncrementTopologyVersion();
     ADProviderPerf.AddDCInstance(serverName);
 }
 // Token: 0x06000DC7 RID: 3527 RVA: 0x0003F2F4 File Offset: 0x0003D4F4
 internal void AppendCustomServer(ADServerInfo serverInfo, ref bool presentAndDownOrDisconnected)
 {
     presentAndDownOrDisconnected = false;
     try
     {
         this.poolLock.AcquireWriterLock(-1);
         if (!this.isActive)
         {
             ExTraceGlobals.GetConnectionTracer.TraceWarning((long)this.GetHashCode(), "Pool is not active, skipping AppendCustomServer");
         }
         else
         {
             for (int i = 0; i < this.connectionInfos.Length; i++)
             {
                 ConnectionInfo connectionInfo = this.connectionInfos[i];
                 if (connectionInfo.ADServerInfo.Equals(serverInfo))
                 {
                     ExTraceGlobals.GetConnectionTracer.TraceWarning <string>((long)this.GetHashCode(), "AppendCustomServer: {0} is already in the list", serverInfo.FqdnPlusPort);
                     if (connectionInfo.ConnectionState == ConnectionState.Disconnected || (connectionInfo.ConnectionState == ConnectionState.Connected && !connectionInfo.PooledLdapConnection.IsUp))
                     {
                         ExTraceGlobals.GetConnectionTracer.TraceWarning <string, string>((long)this.GetHashCode(), "AppendCustomServer: {0} is {1}", serverInfo.FqdnPlusPort, (connectionInfo.ConnectionState == ConnectionState.Disconnected) ? "Disconnected" : "Down");
                         presentAndDownOrDisconnected = true;
                     }
                     return;
                 }
             }
             ExTraceGlobals.GetConnectionTracer.TraceDebug <string>((long)this.GetHashCode(), "Adding custom connection to {0}", serverInfo.Fqdn);
             ADProviderPerf.AddDCInstance(serverInfo.Fqdn);
             ConnectionInfo[] array = new ConnectionInfo[this.connectionInfos.Length + 1];
             this.connectionInfos.CopyTo(array, 0);
             array[array.Length - 1] = new ConnectionInfo(serverInfo);
             this.connectionInfos    = array;
             ADServerInfo[] array2 = new ADServerInfo[this.serverInfos.Length + 1];
             this.serverInfos.CopyTo(array2, 0);
             array2[array2.Length - 1] = serverInfo;
             this.serverInfos          = array2;
         }
     }
     finally
     {
         try
         {
             this.poolLock.ReleaseWriterLock();
         }
         catch (ApplicationException)
         {
         }
     }
 }