Beispiel #1
0
        private void DoServerVerifyAndPropRetrieval()
        {
            _serverProperties = new ServerProperties();
            if (_contextType == ContextType.ApplicationDirectory || _contextType == ContextType.Domain)
            {
                ReadServerConfig(_name, ref _serverProperties);

                if (_serverProperties.contextType != _contextType)
                {
                    throw new ArgumentException(SR.Format(SR.PassedContextTypeDoesNotMatchDetectedType, _serverProperties.contextType.ToString()));
                }
            }
        }
Beispiel #2
0
 private void DoServerVerifyAndPropRetrieval()
 {
     this.serverProperties = new ServerProperties();
     if (this.contextType == ContextType.ApplicationDirectory || this.contextType == ContextType.Domain)
     {
         this.ReadServerConfig(this.name, ref this.serverProperties);
         if (this.serverProperties.contextType != this.contextType)
         {
             object[] str = new object[1];
             str[0] = this.serverProperties.contextType.ToString();
             throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.PassedContextTypeDoesNotMatchDetectedType, str));
         }
     }
 }
Beispiel #3
0
        public CredentialValidator(ContextType contextType, string serverName, ServerProperties serverProperties)
        {
            _fastConcurrentSupported = !(serverProperties.OsVersion == DomainControllerMode.Win2k);

            if (contextType == ContextType.Machine && serverName == null)
            {
                _serverName = Environment.MachineName;
            }
            else
            {
                _serverName = serverName;
            }

            _contextType      = contextType;
            _serverProperties = serverProperties;
        }
Beispiel #4
0
        public CredentialValidator(ContextType contextType, string serverName, ServerProperties serverProperties)
        {
            _fastConcurrentSupported = !(serverProperties.OsVersion == DomainControllerMode.Win2k);

            if (contextType == ContextType.Machine && serverName == null)
            {
                _serverName = Environment.MachineName;
            }
            else
            {
                _serverName = serverName;
            }

            _contextType = contextType;
            _serverProperties = serverProperties;
        }
 public CredentialValidator(ContextType contextType, string serverName, ServerProperties serverProperties)
 {
     this.fastConcurrentSupported = true;
     this.connCache               = new Hashtable(4);
     this.cacheLock               = new object();
     this.lastBindMethod          = CredentialValidator.AuthMethod.Simple;
     this.fastConcurrentSupported = serverProperties.OsVersion != DomainControllerMode.Win2k;
     if (contextType != ContextType.Machine || serverName != null)
     {
         this.serverName = serverName;
     }
     else
     {
         this.serverName = Environment.MachineName;
     }
     this.contextType      = contextType;
     this.serverProperties = serverProperties;
 }
Beispiel #6
0
		public CredentialValidator(ContextType contextType, string serverName, ServerProperties serverProperties)
		{
			this.fastConcurrentSupported = true;
			this.connCache = new Hashtable(4);
			this.cacheLock = new object();
			this.lastBindMethod = CredentialValidator.AuthMethod.Simple;
			this.fastConcurrentSupported = serverProperties.OsVersion != DomainControllerMode.Win2k;
			if (contextType != ContextType.Machine || serverName != null)
			{
				this.serverName = serverName;
			}
			else
			{
				this.serverName = Environment.MachineName;
			}
			this.contextType = contextType;
			this.serverProperties = serverProperties;
		}
Beispiel #7
0
        internal void ReadServerConfig(string serverName, ref ServerProperties properties)
        {
            string[]       proplist       = new string[] { "msDS-PortSSL", "msDS-PortLDAP", "domainControllerFunctionality", "dnsHostName", "supportedCapabilities" };
            LdapConnection ldapConnection = null;

            try
            {
                bool useSSL = (_options & ContextOptions.SecureSocketLayer) > 0;

                if (useSSL && _contextType == ContextType.Domain)
                {
                    LdapDirectoryIdentifier directoryid = new LdapDirectoryIdentifier(serverName, LdapConstants.LDAP_SSL_PORT);
                    ldapConnection = new LdapConnection(directoryid);
                }
                else
                {
                    ldapConnection = new LdapConnection(serverName);
                }

                ldapConnection.AutoBind = false;
                // If SSL was enabled on the initial connection then turn it on for the search.
                // This is required bc the appended port number will be SSL and we don't know what port LDAP is running on.
                ldapConnection.SessionOptions.SecureSocketLayer = useSSL;

                string         baseDN           = null; // specify base as null for RootDSE search
                string         ldapSearchFilter = "(objectClass=*)";
                SearchResponse searchResponse   = null;

                SearchRequest searchRequest = new SearchRequest(baseDN, ldapSearchFilter, System.DirectoryServices.Protocols
                                                                .SearchScope.Base, proplist);

                try
                {
                    searchResponse = (SearchResponse)ldapConnection.SendRequest(searchRequest);
                }
                catch (LdapException ex)
                {
                    throw new PrincipalServerDownException(SR.ServerDown, ex);
                }

                // Fill in the struct with the casted properties from the serach results.
                // there will always be only 1 item on the rootDSE so all entry indexes are 0
                properties.dnsHostName         = (string)searchResponse.Entries[0].Attributes["dnsHostName"][0];
                properties.SupportCapabilities = new string[searchResponse.Entries[0].Attributes["supportedCapabilities"].Count];
                for (int i = 0; i < searchResponse.Entries[0].Attributes["supportedCapabilities"].Count; i++)
                {
                    properties.SupportCapabilities[i] = (string)searchResponse.Entries[0].Attributes["supportedCapabilities"][i];
                }

                foreach (string capability in properties.SupportCapabilities)
                {
                    if (CapabilityMap.LDAP_CAP_ACTIVE_DIRECTORY_ADAM_OID == capability)
                    {
                        properties.contextType = ContextType.ApplicationDirectory;
                    }
                    else if (CapabilityMap.LDAP_CAP_ACTIVE_DIRECTORY_OID == capability)
                    {
                        properties.contextType = ContextType.Domain;
                    }
                }

                // If we can't determine the OS vesion so we must fall back to lowest level of functionality
                if (searchResponse.Entries[0].Attributes.Contains("domainControllerFunctionality"))
                {
                    properties.OsVersion = (DomainControllerMode)Convert.ToInt32(searchResponse.Entries[0].Attributes["domainControllerFunctionality"][0], CultureInfo.InvariantCulture);
                }
                else
                {
                    properties.OsVersion = DomainControllerMode.Win2k;
                }

                if (properties.contextType == ContextType.ApplicationDirectory)
                {
                    if (searchResponse.Entries[0].Attributes.Contains("msDS-PortSSL"))
                    {
                        properties.portSSL = Convert.ToInt32(searchResponse.Entries[0].Attributes["msDS-PortSSL"][0]);
                    }
                    if (searchResponse.Entries[0].Attributes.Contains("msDS-PortLDAP"))
                    {
                        properties.portLDAP = Convert.ToInt32(searchResponse.Entries[0].Attributes["msDS-PortLDAP"][0]);
                    }
                }

                GlobalDebug.WriteLineIf(GlobalDebug.Info, "ReadServerConfig", "OsVersion : " + properties.OsVersion.ToString());
                GlobalDebug.WriteLineIf(GlobalDebug.Info, "ReadServerConfig", "dnsHostName : " + properties.dnsHostName);
                GlobalDebug.WriteLineIf(GlobalDebug.Info, "ReadServerConfig", "contextType : " + properties.contextType.ToString());
                GlobalDebug.WriteLineIf(GlobalDebug.Info, "ReadServerConfig", "portSSL : " + properties.portSSL.ToString(CultureInfo.InvariantCulture));
                GlobalDebug.WriteLineIf(GlobalDebug.Info, "ReadServerConfig", "portLDAP :" + properties.portLDAP.ToString(CultureInfo.InvariantCulture));
            }
            finally
            {
                ldapConnection?.Dispose();
            }
        }
Beispiel #8
0
        private void DoServerVerifyAndPropRetrieval()
        {
            _serverProperties = new ServerProperties();
            if (_contextType == ContextType.ApplicationDirectory || _contextType == ContextType.Domain)
            {
                ReadServerConfig(_name, ref _serverProperties);

                if (_serverProperties.contextType != _contextType)
                {
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.PassedContextTypeDoesNotMatchDetectedType, _serverProperties.contextType.ToString()));
                }
            }
        }
Beispiel #9
0
        internal void ReadServerConfig(string serverName, ref ServerProperties properties)
        {
            string[] proplist = new string[] { "msDS-PortSSL", "msDS-PortLDAP", "domainControllerFunctionality", "dnsHostName", "supportedCapabilities" };
            LdapConnection ldapConnection = null;

            try
            {
                bool useSSL = (_options & ContextOptions.SecureSocketLayer) > 0;

                if (useSSL && _contextType == ContextType.Domain)
                {
                    LdapDirectoryIdentifier directoryid = new LdapDirectoryIdentifier(serverName, LdapConstants.LDAP_SSL_PORT);
                    ldapConnection = new LdapConnection(directoryid);
                }
                else
                {
                    ldapConnection = new LdapConnection(serverName);
                }

                ldapConnection.AutoBind = false;
                // If SSL was enabled on the initial connection then turn it on for the search.
                // This is requried bc the appended port number will be SSL and we don't know what port LDAP is running on.
                ldapConnection.SessionOptions.SecureSocketLayer = useSSL;

                string baseDN = null; // specify base as null for RootDSE search
                string ldapSearchFilter = "(objectClass=*)";
                SearchResponse searchResponse = null;

                SearchRequest searchRequest = new SearchRequest(baseDN, ldapSearchFilter, System.DirectoryServices.Protocols
                    .SearchScope.Base, proplist);

                try
                {
                    searchResponse = (SearchResponse)ldapConnection.SendRequest(searchRequest);
                }
                catch (LdapException ex)
                {
                    throw new PrincipalServerDownException(StringResources.ServerDown, ex);
                }

                // Fill in the struct with the casted properties from the serach results.
                // there will always be only 1 item on the rootDSE so all entry indexes are 0
                properties.dnsHostName = (string)searchResponse.Entries[0].Attributes["dnsHostName"][0];
                properties.SupportCapabilities = new string[searchResponse.Entries[0].Attributes["supportedCapabilities"].Count];
                for (int i = 0; i < searchResponse.Entries[0].Attributes["supportedCapabilities"].Count; i++)
                {
                    properties.SupportCapabilities[i] = (string)searchResponse.Entries[0].Attributes["supportedCapabilities"][i];
                }

                foreach (string capability in properties.SupportCapabilities)
                {
                    if (CapabilityMap.LDAP_CAP_ACTIVE_DIRECTORY_ADAM_OID == capability)
                    {
                        properties.contextType = ContextType.ApplicationDirectory;
                    }
                    else if (CapabilityMap.LDAP_CAP_ACTIVE_DIRECTORY_OID == capability)
                    {
                        properties.contextType = ContextType.Domain;
                    }
                }

                // If we can't determine the OS vesion so we must fall back to lowest level of functionality
                if (searchResponse.Entries[0].Attributes.Contains("domainControllerFunctionality"))
                {
                    properties.OsVersion = (DomainControllerMode)Convert.ToInt32(searchResponse.Entries[0].Attributes["domainControllerFunctionality"][0], CultureInfo.InvariantCulture);
                }
                else
                {
                    properties.OsVersion = DomainControllerMode.Win2k;
                }

                if (properties.contextType == ContextType.ApplicationDirectory)
                {
                    if (searchResponse.Entries[0].Attributes.Contains("msDS-PortSSL"))
                    {
                        properties.portSSL = Convert.ToInt32(searchResponse.Entries[0].Attributes["msDS-PortSSL"][0]);
                    }
                    if (searchResponse.Entries[0].Attributes.Contains("msDS-PortLDAP"))
                    {
                        properties.portLDAP = Convert.ToInt32(searchResponse.Entries[0].Attributes["msDS-PortLDAP"][0]);
                    }
                }

                GlobalDebug.WriteLineIf(GlobalDebug.Info, "ReadServerConfig", "OsVersion : " + properties.OsVersion.ToString());
                GlobalDebug.WriteLineIf(GlobalDebug.Info, "ReadServerConfig", "dnsHostName : " + properties.dnsHostName);
                GlobalDebug.WriteLineIf(GlobalDebug.Info, "ReadServerConfig", "contextType : " + properties.contextType.ToString());
                GlobalDebug.WriteLineIf(GlobalDebug.Info, "ReadServerConfig", "portSSL : " + properties.portSSL.ToString(CultureInfo.InvariantCulture));
                GlobalDebug.WriteLineIf(GlobalDebug.Info, "ReadServerConfig", "portLDAP :" + properties.portLDAP.ToString(CultureInfo.InvariantCulture));
            }
            finally
            {
                if (ldapConnection != null)
                {
                    ldapConnection.Dispose();
                }
            }
        }
Beispiel #10
0
		internal void ReadServerConfig(string serverName, ref ServerProperties properties)
		{
			string[] strArrays = new string[5];
			strArrays[0] = "msDS-PortSSL";
			strArrays[1] = "msDS-PortLDAP";
			strArrays[2] = "domainControllerFunctionality";
			strArrays[3] = "dnsHostName";
			strArrays[4] = "supportedCapabilities";
			string[] strArrays1 = strArrays;
			LdapConnection ldapConnection = null;
			using (ldapConnection)
			{
				bool flag = (this.options & ContextOptions.SecureSocketLayer) > 0;
				if (!flag || this.contextType != ContextType.Domain)
				{
					ldapConnection = new LdapConnection(serverName);
				}
				else
				{
					LdapDirectoryIdentifier ldapDirectoryIdentifier = new LdapDirectoryIdentifier(serverName, LdapConstants.LDAP_SSL_PORT);
					ldapConnection = new LdapConnection(ldapDirectoryIdentifier);
				}
				ldapConnection.AutoBind = false;
				ldapConnection.SessionOptions.SecureSocketLayer = flag;
				string str = null;
				string str1 = "(objectClass=*)";
				SearchResponse searchResponse = null;
				SearchRequest searchRequest = new SearchRequest(str, str1, SearchScope.Base, strArrays1);
				try
				{
					searchResponse = (SearchResponse)ldapConnection.SendRequest(searchRequest);
				}
				catch (LdapException ldapException1)
				{
					LdapException ldapException = ldapException1;
					throw new PrincipalServerDownException(StringResources.ServerDown, ldapException);
				}
				properties.dnsHostName = (string)searchResponse.Entries[0].Attributes["dnsHostName"][0];
				properties.SupportCapabilities = new string[searchResponse.Entries[0].Attributes["supportedCapabilities"].Count];
				for (int i = 0; i < searchResponse.Entries[0].Attributes["supportedCapabilities"].Count; i++)
				{
					properties.SupportCapabilities[i] = (string)searchResponse.Entries[0].Attributes["supportedCapabilities"][i];
				}
				string[] supportCapabilities = properties.SupportCapabilities;
				for (int j = 0; j < (int)supportCapabilities.Length; j++)
				{
					string str2 = supportCapabilities[j];
					if ("1.2.840.113556.1.4.1851" != str2)
					{
						if ("1.2.840.113556.1.4.800" == str2)
						{
							properties.contextType = ContextType.Domain;
						}
					}
					else
					{
						properties.contextType = ContextType.ApplicationDirectory;
					}
				}
				if (!searchResponse.Entries[0].Attributes.Contains("domainControllerFunctionality"))
				{
					properties.OsVersion = DomainControllerMode.Win2k;
				}
				else
				{
					properties.OsVersion = (DomainControllerMode)Convert.ToInt32(searchResponse.Entries[0].Attributes["domainControllerFunctionality"][0], CultureInfo.InvariantCulture);
				}
				if (properties.contextType == ContextType.ApplicationDirectory)
				{
					if (searchResponse.Entries[0].Attributes.Contains("msDS-PortSSL"))
					{
						properties.portSSL = Convert.ToInt32(searchResponse.Entries[0].Attributes["msDS-PortSSL"][0]);
					}
					if (searchResponse.Entries[0].Attributes.Contains("msDS-PortLDAP"))
					{
						properties.portLDAP = Convert.ToInt32(searchResponse.Entries[0].Attributes["msDS-PortLDAP"][0]);
					}
				}
			}
		}
Beispiel #11
0
		private void DoServerVerifyAndPropRetrieval()
		{
			this.serverProperties = new ServerProperties();
			if (this.contextType == ContextType.ApplicationDirectory || this.contextType == ContextType.Domain)
			{
				this.ReadServerConfig(this.name, ref this.serverProperties);
				if (this.serverProperties.contextType != this.contextType)
				{
					object[] str = new object[1];
					str[0] = this.serverProperties.contextType.ToString();
					throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.PassedContextTypeDoesNotMatchDetectedType, str));
				}
			}
		}
Beispiel #12
0
        internal void ReadServerConfig(string serverName, ref ServerProperties properties)
        {
            string[] strArrays = new string[5];
            strArrays[0] = "msDS-PortSSL";
            strArrays[1] = "msDS-PortLDAP";
            strArrays[2] = "domainControllerFunctionality";
            strArrays[3] = "dnsHostName";
            strArrays[4] = "supportedCapabilities";
            string[]       strArrays1     = strArrays;
            LdapConnection ldapConnection = null;

            using (ldapConnection)
            {
                bool flag = (this.options & ContextOptions.SecureSocketLayer) > 0;
                if (!flag || this.contextType != ContextType.Domain)
                {
                    ldapConnection = new LdapConnection(serverName);
                }
                else
                {
                    LdapDirectoryIdentifier ldapDirectoryIdentifier = new LdapDirectoryIdentifier(serverName, LdapConstants.LDAP_SSL_PORT);
                    ldapConnection = new LdapConnection(ldapDirectoryIdentifier);
                }
                ldapConnection.AutoBind = false;
                ldapConnection.SessionOptions.SecureSocketLayer = flag;
                string         str            = null;
                string         str1           = "(objectClass=*)";
                SearchResponse searchResponse = null;
                SearchRequest  searchRequest  = new SearchRequest(str, str1, SearchScope.Base, strArrays1);
                try
                {
                    searchResponse = (SearchResponse)ldapConnection.SendRequest(searchRequest);
                }
                catch (LdapException ldapException1)
                {
                    LdapException ldapException = ldapException1;
                    throw new PrincipalServerDownException(StringResources.ServerDown, ldapException);
                }
                properties.dnsHostName         = (string)searchResponse.Entries[0].Attributes["dnsHostName"][0];
                properties.SupportCapabilities = new string[searchResponse.Entries[0].Attributes["supportedCapabilities"].Count];
                for (int i = 0; i < searchResponse.Entries[0].Attributes["supportedCapabilities"].Count; i++)
                {
                    properties.SupportCapabilities[i] = (string)searchResponse.Entries[0].Attributes["supportedCapabilities"][i];
                }
                string[] supportCapabilities = properties.SupportCapabilities;
                for (int j = 0; j < (int)supportCapabilities.Length; j++)
                {
                    string str2 = supportCapabilities[j];
                    if ("1.2.840.113556.1.4.1851" != str2)
                    {
                        if ("1.2.840.113556.1.4.800" == str2)
                        {
                            properties.contextType = ContextType.Domain;
                        }
                    }
                    else
                    {
                        properties.contextType = ContextType.ApplicationDirectory;
                    }
                }
                if (!searchResponse.Entries[0].Attributes.Contains("domainControllerFunctionality"))
                {
                    properties.OsVersion = DomainControllerMode.Win2k;
                }
                else
                {
                    properties.OsVersion = (DomainControllerMode)Convert.ToInt32(searchResponse.Entries[0].Attributes["domainControllerFunctionality"][0], CultureInfo.InvariantCulture);
                }
                if (properties.contextType == ContextType.ApplicationDirectory)
                {
                    if (searchResponse.Entries[0].Attributes.Contains("msDS-PortSSL"))
                    {
                        properties.portSSL = Convert.ToInt32(searchResponse.Entries[0].Attributes["msDS-PortSSL"][0]);
                    }
                    if (searchResponse.Entries[0].Attributes.Contains("msDS-PortLDAP"))
                    {
                        properties.portLDAP = Convert.ToInt32(searchResponse.Entries[0].Attributes["msDS-PortLDAP"][0]);
                    }
                }
            }
        }