Exemplo n.º 1
1
		internal ReplicationConnectionCollection GetOutboundConnectionsHelper()
		{
			string siteObjectName;
			string serverObjectName;
			if (this.outbound == null)
			{
				if (this as DomainController != null)
				{
					siteObjectName = ((DomainController)this).SiteObjectName;
				}
				else
				{
					siteObjectName = ((AdamInstance)this).SiteObjectName;
				}
				string str = siteObjectName;
				DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(Utils.GetNewDirectoryContext(this.Name, DirectoryContextType.DirectoryServer, this.context), str);
				if (this as DomainController != null)
				{
					serverObjectName = ((DomainController)this).ServerObjectName;
				}
				else
				{
					serverObjectName = ((AdamInstance)this).ServerObjectName;
				}
				string str1 = serverObjectName;
				string[] strArrays = new string[2];
				strArrays[0] = "objectClass";
				strArrays[1] = "cn";
				ADSearcher aDSearcher = new ADSearcher(directoryEntry, string.Concat("(&(objectClass=nTDSConnection)(objectCategory=nTDSConnection)(fromServer=CN=NTDS Settings,", str1, "))"), strArrays, SearchScope.Subtree);
				SearchResultCollection searchResultCollections = null;
				DirectoryContext newDirectoryContext = Utils.GetNewDirectoryContext(this.Name, DirectoryContextType.DirectoryServer, this.context);
				try
				{
					try
					{
						searchResultCollections = aDSearcher.FindAll();
						this.outbound = new ReplicationConnectionCollection();
						foreach (SearchResult searchResult in searchResultCollections)
						{
							ReplicationConnection replicationConnection = new ReplicationConnection(newDirectoryContext, searchResult.GetDirectoryEntry(), (string)searchResult.Properties["cn"][0]);
							this.outbound.Add(replicationConnection);
						}
					}
					catch (COMException cOMException1)
					{
						COMException cOMException = cOMException1;
						throw ExceptionHelper.GetExceptionFromCOMException(newDirectoryContext, cOMException);
					}
				}
				finally
				{
					if (searchResultCollections != null)
					{
						searchResultCollections.Dispose();
					}
					directoryEntry.Dispose();
				}
			}
			return this.outbound;
		}
 internal ReplicationConnectionCollection GetInboundConnectionsHelper()
 {
     if (this.inbound == null)
     {
         this.inbound = new ReplicationConnectionCollection();
         DirectoryContext       context        = Utils.GetNewDirectoryContext(this.Name, DirectoryContextType.DirectoryServer, this.context);
         string                 str            = (this is DomainController) ? ((DomainController)this).ServerObjectName : ((AdamInstance)this).ServerObjectName;
         string                 dn             = "CN=NTDS Settings," + str;
         DirectoryEntry         directoryEntry = DirectoryEntryManager.GetDirectoryEntry(Utils.GetNewDirectoryContext(this.Name, DirectoryContextType.DirectoryServer, this.context), dn);
         ADSearcher             searcher       = new ADSearcher(directoryEntry, "(&(objectClass=nTDSConnection)(objectCategory=nTDSConnection))", new string[] { "cn" }, SearchScope.OneLevel);
         SearchResultCollection results        = null;
         try
         {
             results = searcher.FindAll();
             foreach (SearchResult result in results)
             {
                 ReplicationConnection connection = new ReplicationConnection(context, result.GetDirectoryEntry(), (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.Cn));
                 this.inbound.Add(connection);
             }
         }
         catch (COMException exception)
         {
             throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
         }
         finally
         {
             if (results != null)
             {
                 results.Dispose();
             }
             directoryEntry.Dispose();
         }
     }
     return(this.inbound);
 }
 internal ReplicationConnectionCollection GetOutboundConnectionsHelper()
 {
     if (this.outbound == null)
     {
         string                 dn             = (this is DomainController) ? ((DomainController)this).SiteObjectName : ((AdamInstance)this).SiteObjectName;
         DirectoryEntry         directoryEntry = DirectoryEntryManager.GetDirectoryEntry(Utils.GetNewDirectoryContext(this.Name, DirectoryContextType.DirectoryServer, this.context), dn);
         string                 str2           = (this is DomainController) ? ((DomainController)this).ServerObjectName : ((AdamInstance)this).ServerObjectName;
         ADSearcher             searcher       = new ADSearcher(directoryEntry, "(&(objectClass=nTDSConnection)(objectCategory=nTDSConnection)(fromServer=CN=NTDS Settings," + str2 + "))", new string[] { "objectClass", "cn" }, SearchScope.Subtree);
         SearchResultCollection results        = null;
         DirectoryContext       context        = Utils.GetNewDirectoryContext(this.Name, DirectoryContextType.DirectoryServer, this.context);
         try
         {
             results       = searcher.FindAll();
             this.outbound = new ReplicationConnectionCollection();
             foreach (SearchResult result in results)
             {
                 ReplicationConnection connection = new ReplicationConnection(context, result.GetDirectoryEntry(), (string)result.Properties["cn"][0]);
                 this.outbound.Add(connection);
             }
         }
         catch (COMException exception)
         {
             throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
         }
         finally
         {
             if (results != null)
             {
                 results.Dispose();
             }
             directoryEntry.Dispose();
         }
     }
     return(this.outbound);
 }
Exemplo n.º 4
0
        private ArrayList GetSites()
        {
            ArrayList      arrayLists           = new ArrayList();
            DirectoryEntry cachedDirectoryEntry = this.directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.SitesContainer);
            string         str = string.Concat("(", PropertyManager.ObjectCategory, "=site)");

            string[] cn = new string[1];
            cn[0] = PropertyManager.Cn;
            ADSearcher             aDSearcher = new ADSearcher(cachedDirectoryEntry, str, cn, SearchScope.OneLevel);
            SearchResultCollection searchResultCollections = null;

            using (searchResultCollections)
            {
                try
                {
                    searchResultCollections = aDSearcher.FindAll();
                    foreach (SearchResult searchResult in searchResultCollections)
                    {
                        arrayLists.Add(new ActiveDirectorySite(this.context, (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.Cn), true));
                    }
                }
                catch (COMException cOMException1)
                {
                    COMException cOMException = cOMException1;
                    throw ExceptionHelper.GetExceptionFromCOMException(this.context, cOMException);
                }
            }
            return(arrayLists);
        }
        private ArrayList GetSites()
        {
            ArrayList      list = new ArrayList();
            DirectoryEntry cachedDirectoryEntry = this.directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.SitesContainer);
            string         filter = "(" + PropertyManager.ObjectCategory + "=site)";

            string[]               propertiesToLoad = new string[] { PropertyManager.Cn };
            ADSearcher             searcher         = new ADSearcher(cachedDirectoryEntry, filter, propertiesToLoad, SearchScope.OneLevel);
            SearchResultCollection results          = null;

            try
            {
                results = searcher.FindAll();
                foreach (SearchResult result in results)
                {
                    list.Add(new ActiveDirectorySite(this.context, (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.Cn), true));
                }
                return(list);
            }
            catch (COMException exception)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(this.context, exception);
            }
            finally
            {
                if (results != null)
                {
                    results.Dispose();
                }
            }
            return(list);
        }
        internal static AdamInstance FindAnyAdamInstance(DirectoryContext context)
        {
            if (context.ContextType != DirectoryContextType.ConfigurationSet)
            {
                DirectoryEntryManager directoryEntryMgr    = new DirectoryEntryManager(context);
                DirectoryEntry        cachedDirectoryEntry = directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE);
                if (!Utils.CheckCapability(cachedDirectoryEntry, Capability.ActiveDirectoryApplicationMode))
                {
                    directoryEntryMgr.RemoveIfExists(directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.RootDSE));
                    throw new ArgumentException(Res.GetString("TargetShouldBeServerORConfigSet"), "context");
                }
                return(new AdamInstance(context, (string)PropertyManager.GetPropertyValue(context, cachedDirectoryEntry, PropertyManager.DnsHostName), directoryEntryMgr));
            }
            DirectoryEntry searchRootEntry   = GetSearchRootEntry(Forest.GetCurrentForest());
            ArrayList      adamInstanceNames = new ArrayList();

            try
            {
                string        text1   = (string)searchRootEntry.Properties["distinguishedName"].Value;
                StringBuilder builder = new StringBuilder(15);
                builder.Append("(&(");
                builder.Append(PropertyManager.ObjectCategory);
                builder.Append("=serviceConnectionPoint)");
                builder.Append("(");
                builder.Append(PropertyManager.Keywords);
                builder.Append("=1.2.840.113556.1.4.1851)(");
                builder.Append(PropertyManager.Keywords);
                builder.Append("=");
                builder.Append(Utils.GetEscapedFilterValue(context.Name));
                builder.Append("))");
                string     filter           = builder.ToString();
                string[]   propertiesToLoad = new string[] { PropertyManager.ServiceBindingInformation };
                ADSearcher searcher         = new ADSearcher(searchRootEntry, filter, propertiesToLoad, SearchScope.Subtree, false, false);
                using (SearchResultCollection results = searcher.FindAll())
                {
                    foreach (SearchResult result in results)
                    {
                        string strB = "ldap://";
                        foreach (string str4 in result.Properties[PropertyManager.ServiceBindingInformation])
                        {
                            if ((str4.Length > strB.Length) && (string.Compare(str4.Substring(0, strB.Length), strB, StringComparison.OrdinalIgnoreCase) == 0))
                            {
                                adamInstanceNames.Add(str4.Substring(strB.Length));
                            }
                        }
                    }
                }
            }
            catch (COMException exception)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
            }
            finally
            {
                searchRootEntry.Dispose();
            }
            return(FindAliveAdamInstance(null, context, adamInstanceNames));
        }
Exemplo n.º 7
0
        private ArrayList GetApplicationPartitions()
        {
            ArrayList      arrayLists           = new ArrayList();
            DirectoryEntry cachedDirectoryEntry = this.directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE);
            DirectoryEntry directoryEntry       = this.directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.PartitionsContainer);
            StringBuilder  stringBuilder        = new StringBuilder(100);

            stringBuilder.Append("(&(");
            stringBuilder.Append(PropertyManager.ObjectCategory);
            stringBuilder.Append("=crossRef)(");
            stringBuilder.Append(PropertyManager.SystemFlags);
            stringBuilder.Append(":1.2.840.113556.1.4.804:=");
            stringBuilder.Append(1);
            stringBuilder.Append(")(!(");
            stringBuilder.Append(PropertyManager.SystemFlags);
            stringBuilder.Append(":1.2.840.113556.1.4.803:=");
            stringBuilder.Append(2);
            stringBuilder.Append(")))");
            string str = stringBuilder.ToString();

            string[] nCName = new string[2];
            nCName[0] = PropertyManager.NCName;
            nCName[1] = PropertyManager.MsDSNCReplicaLocations;
            ADSearcher             aDSearcher = new ADSearcher(directoryEntry, str, nCName, SearchScope.OneLevel);
            SearchResultCollection searchResultCollections = null;

            using (searchResultCollections)
            {
                try
                {
                    searchResultCollections = aDSearcher.FindAll();
                    string propertyValue  = (string)PropertyManager.GetPropertyValue(this.context, cachedDirectoryEntry, PropertyManager.SchemaNamingContext);
                    string propertyValue1 = (string)PropertyManager.GetPropertyValue(this.context, cachedDirectoryEntry, PropertyManager.ConfigurationNamingContext);
                    foreach (SearchResult searchResult in searchResultCollections)
                    {
                        string searchResultPropertyValue = (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.NCName);
                        if (searchResultPropertyValue.Equals(propertyValue) || searchResultPropertyValue.Equals(propertyValue1))
                        {
                            continue;
                        }
                        ResultPropertyValueCollection item = searchResult.Properties[PropertyManager.MsDSNCReplicaLocations];
                        if (item.Count <= 0)
                        {
                            continue;
                        }
                        string           adamDnsHostNameFromNTDSA = Utils.GetAdamDnsHostNameFromNTDSA(this.context, (string)item[Utils.GetRandomIndex(item.Count)]);
                        DirectoryContext newDirectoryContext      = Utils.GetNewDirectoryContext(adamDnsHostNameFromNTDSA, DirectoryContextType.DirectoryServer, this.context);
                        arrayLists.Add(new ApplicationPartition(newDirectoryContext, searchResultPropertyValue, null, ApplicationPartitionType.ADAMApplicationPartition, new DirectoryEntryManager(newDirectoryContext)));
                    }
                }
                catch (COMException cOMException1)
                {
                    COMException cOMException = cOMException1;
                    throw ExceptionHelper.GetExceptionFromCOMException(this.context, cOMException);
                }
            }
            return(arrayLists);
        }
Exemplo n.º 8
0
        internal static ReadOnlyActiveDirectorySchemaClassCollection GetAllClasses(DirectoryContext context, DirectoryEntry schemaEntry, string filter)
        {
            ArrayList classList = new ArrayList();

            string[] propertiesToLoad = new string[3];
            propertiesToLoad[0] = PropertyManager.LdapDisplayName;
            propertiesToLoad[1] = PropertyManager.Cn;
            propertiesToLoad[2] = PropertyManager.IsDefunct;

            ADSearcher             searcher = new ADSearcher(schemaEntry, filter, propertiesToLoad, SearchScope.OneLevel);
            SearchResultCollection resCol   = null;

            try
            {
                resCol = searcher.FindAll();
                foreach (SearchResult res in resCol)
                {
                    string         ldapDisplayName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.LdapDisplayName);
                    DirectoryEntry directoryEntry  = res.GetDirectoryEntry();

                    directoryEntry.AuthenticationType = Utils.DefaultAuthType;
                    directoryEntry.Username           = context.UserName;
                    directoryEntry.Password           = context.Password;

                    bool isDefunct = false;

                    if ((res.Properties[PropertyManager.IsDefunct] != null) && (res.Properties[PropertyManager.IsDefunct].Count > 0))
                    {
                        isDefunct = (bool)res.Properties[PropertyManager.IsDefunct][0];
                    }

                    if (isDefunct)
                    {
                        string commonName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.Cn);
                        classList.Add(new ActiveDirectorySchemaClass(context, commonName, ldapDisplayName, directoryEntry, schemaEntry));
                    }
                    else
                    {
                        classList.Add(new ActiveDirectorySchemaClass(context, ldapDisplayName, directoryEntry, schemaEntry));
                    }
                }
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            finally
            {
                // dispose off the result collection
                if (resCol != null)
                {
                    resCol.Dispose();
                }
            }

            return(new ReadOnlyActiveDirectorySchemaClassCollection(classList));
        }
        private ArrayList GetApplicationPartitions()
        {
            ArrayList      list = new ArrayList();
            DirectoryEntry cachedDirectoryEntry = this.directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE);
            DirectoryEntry searchRoot           = this.directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.PartitionsContainer);
            StringBuilder  builder = new StringBuilder(100);

            builder.Append("(&(");
            builder.Append(PropertyManager.ObjectCategory);
            builder.Append("=crossRef)(");
            builder.Append(PropertyManager.SystemFlags);
            builder.Append(":1.2.840.113556.1.4.804:=");
            builder.Append(1);
            builder.Append(")(!(");
            builder.Append(PropertyManager.SystemFlags);
            builder.Append(":1.2.840.113556.1.4.803:=");
            builder.Append(2);
            builder.Append(")))");
            string filter = builder.ToString();

            string[]               propertiesToLoad = new string[] { PropertyManager.NCName, PropertyManager.MsDSNCReplicaLocations };
            ADSearcher             searcher         = new ADSearcher(searchRoot, filter, propertiesToLoad, SearchScope.OneLevel);
            SearchResultCollection results          = null;

            try
            {
                results = searcher.FindAll();
                string str2 = (string)PropertyManager.GetPropertyValue(this.context, cachedDirectoryEntry, PropertyManager.SchemaNamingContext);
                string str3 = (string)PropertyManager.GetPropertyValue(this.context, cachedDirectoryEntry, PropertyManager.ConfigurationNamingContext);
                foreach (SearchResult result in results)
                {
                    string searchResultPropertyValue = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.NCName);
                    if (!searchResultPropertyValue.Equals(str2) && !searchResultPropertyValue.Equals(str3))
                    {
                        ResultPropertyValueCollection values = result.Properties[PropertyManager.MsDSNCReplicaLocations];
                        if (values.Count > 0)
                        {
                            DirectoryContext context = Utils.GetNewDirectoryContext(Utils.GetAdamDnsHostNameFromNTDSA(this.context, (string)values[Utils.GetRandomIndex(values.Count)]), DirectoryContextType.DirectoryServer, this.context);
                            list.Add(new ApplicationPartition(context, searchResultPropertyValue, null, ApplicationPartitionType.ADAMApplicationPartition, new DirectoryEntryManager(context)));
                        }
                    }
                }
                return(list);
            }
            catch (COMException exception)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(this.context, exception);
            }
            finally
            {
                if (results != null)
                {
                    results.Dispose();
                }
            }
            return(list);
        }
Exemplo n.º 10
0
        private ArrayList GetApplicationPartitions()
        {
            ArrayList      list           = new ArrayList();
            DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, this.directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.PartitionsContainer));
            StringBuilder  builder        = new StringBuilder(15);

            builder.Append("(&(");
            builder.Append(PropertyManager.ObjectCategory);
            builder.Append("=crossRef)(");
            builder.Append(PropertyManager.SystemFlags);
            builder.Append(":1.2.840.113556.1.4.804:=");
            builder.Append(1);
            builder.Append(")(!(");
            builder.Append(PropertyManager.SystemFlags);
            builder.Append(":1.2.840.113556.1.4.803:=");
            builder.Append(2);
            builder.Append(")))");
            string filter = builder.ToString();

            string[]               propertiesToLoad = new string[] { PropertyManager.DnsRoot, PropertyManager.NCName };
            ADSearcher             searcher         = new ADSearcher(directoryEntry, filter, propertiesToLoad, SearchScope.OneLevel);
            SearchResultCollection results          = null;

            try
            {
                results = searcher.FindAll();
                string str2 = this.directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.SchemaNamingContext);
                string str3 = this.directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.ConfigurationNamingContext);
                foreach (SearchResult result in results)
                {
                    string searchResultPropertyValue = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.NCName);
                    if (!searchResultPropertyValue.Equals(str2) && !searchResultPropertyValue.Equals(str3))
                    {
                        string           name    = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.DnsRoot);
                        DirectoryContext context = Utils.GetNewDirectoryContext(name, DirectoryContextType.ApplicationPartition, this.context);
                        list.Add(new ApplicationPartition(context, searchResultPropertyValue, (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.DnsRoot), ApplicationPartitionType.ADApplicationPartition, new DirectoryEntryManager(context)));
                    }
                }
                return(list);
            }
            catch (COMException exception)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(this.context, exception);
            }
            finally
            {
                if (results != null)
                {
                    results.Dispose();
                }
                directoryEntry.Dispose();
            }
            return(list);
        }
Exemplo n.º 11
0
        internal ReplicationConnectionCollection GetInboundConnectionsHelper()
        {
            string serverObjectName;

            if (this.inbound == null)
            {
                this.inbound = new ReplicationConnectionCollection();
                DirectoryContext newDirectoryContext = Utils.GetNewDirectoryContext(this.Name, DirectoryContextType.DirectoryServer, this.context);
                if (this as DomainController != null)
                {
                    serverObjectName = ((DomainController)this).ServerObjectName;
                }
                else
                {
                    serverObjectName = ((AdamInstance)this).ServerObjectName;
                }
                string         str            = serverObjectName;
                string         str1           = string.Concat("CN=NTDS Settings,", str);
                DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(Utils.GetNewDirectoryContext(this.Name, DirectoryContextType.DirectoryServer, this.context), str1);
                string[]       strArrays      = new string[1];
                strArrays[0] = "cn";
                ADSearcher             aDSearcher = new ADSearcher(directoryEntry, "(&(objectClass=nTDSConnection)(objectCategory=nTDSConnection))", strArrays, SearchScope.OneLevel);
                SearchResultCollection searchResultCollections = null;
                try
                {
                    try
                    {
                        searchResultCollections = aDSearcher.FindAll();
                        foreach (SearchResult searchResult in searchResultCollections)
                        {
                            ReplicationConnection replicationConnection = new ReplicationConnection(newDirectoryContext, searchResult.GetDirectoryEntry(), (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.Cn));
                            this.inbound.Add(replicationConnection);
                        }
                    }
                    catch (COMException cOMException1)
                    {
                        COMException cOMException = cOMException1;
                        throw ExceptionHelper.GetExceptionFromCOMException(newDirectoryContext, cOMException);
                    }
                }
                finally
                {
                    if (searchResultCollections != null)
                    {
                        searchResultCollections.Dispose();
                    }
                    directoryEntry.Dispose();
                }
            }
            return(this.inbound);
        }
Exemplo n.º 12
0
        internal static ReadOnlyActiveDirectorySchemaPropertyCollection GetAllProperties(DirectoryContext context, DirectoryEntry schemaEntry, string filter)
        {
            ArrayList arrayLists = new ArrayList();

            string[] ldapDisplayName = new string[3];
            ldapDisplayName[0] = PropertyManager.LdapDisplayName;
            ldapDisplayName[1] = PropertyManager.Cn;
            ldapDisplayName[2] = PropertyManager.IsDefunct;
            ADSearcher             aDSearcher = new ADSearcher(schemaEntry, filter, ldapDisplayName, SearchScope.OneLevel);
            SearchResultCollection searchResultCollections = null;

            using (searchResultCollections)
            {
                try
                {
                    searchResultCollections = aDSearcher.FindAll();
                    foreach (SearchResult searchResult in searchResultCollections)
                    {
                        string         searchResultPropertyValue = (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.LdapDisplayName);
                        DirectoryEntry directoryEntry            = searchResult.GetDirectoryEntry();
                        directoryEntry.AuthenticationType = Utils.DefaultAuthType;
                        directoryEntry.Username           = context.UserName;
                        directoryEntry.Password           = context.Password;
                        bool item = false;
                        if (searchResult.Properties[PropertyManager.IsDefunct] != null && searchResult.Properties[PropertyManager.IsDefunct].Count > 0)
                        {
                            item = (bool)searchResult.Properties[PropertyManager.IsDefunct][0];
                        }
                        if (!item)
                        {
                            arrayLists.Add(new ActiveDirectorySchemaProperty(context, searchResultPropertyValue, directoryEntry, schemaEntry));
                        }
                        else
                        {
                            string str = (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.Cn);
                            arrayLists.Add(new ActiveDirectorySchemaProperty(context, str, searchResultPropertyValue, directoryEntry, schemaEntry));
                        }
                    }
                }
                catch (COMException cOMException1)
                {
                    COMException cOMException = cOMException1;
                    throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException);
                }
            }
            return(new ReadOnlyActiveDirectorySchemaPropertyCollection(arrayLists));
        }
        internal static ReadOnlyActiveDirectorySchemaPropertyCollection GetAllProperties(DirectoryContext context, DirectoryEntry schemaEntry, string filter)
        {
            ArrayList values = new ArrayList();

            string[]               propertiesToLoad = new string[] { PropertyManager.LdapDisplayName, PropertyManager.Cn, PropertyManager.IsDefunct };
            ADSearcher             searcher         = new ADSearcher(schemaEntry, filter, propertiesToLoad, SearchScope.OneLevel);
            SearchResultCollection results          = null;

            try
            {
                results = searcher.FindAll();
                foreach (SearchResult result in results)
                {
                    string         searchResultPropertyValue = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.LdapDisplayName);
                    DirectoryEntry directoryEntry            = result.GetDirectoryEntry();
                    directoryEntry.AuthenticationType = Utils.DefaultAuthType;
                    directoryEntry.Username           = context.UserName;
                    directoryEntry.Password           = context.Password;
                    bool flag = false;
                    if ((result.Properties[PropertyManager.IsDefunct] != null) && (result.Properties[PropertyManager.IsDefunct].Count > 0))
                    {
                        flag = (bool)result.Properties[PropertyManager.IsDefunct][0];
                    }
                    if (flag)
                    {
                        string commonName = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.Cn);
                        values.Add(new ActiveDirectorySchemaProperty(context, commonName, searchResultPropertyValue, directoryEntry, schemaEntry));
                    }
                    else
                    {
                        values.Add(new ActiveDirectorySchemaProperty(context, searchResultPropertyValue, directoryEntry, schemaEntry));
                    }
                }
            }
            catch (COMException exception)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
            }
            finally
            {
                if (results != null)
                {
                    results.Dispose();
                }
            }
            return(new ReadOnlyActiveDirectorySchemaPropertyCollection(values));
        }
Exemplo n.º 14
0
        internal ReplicationConnectionCollection GetOutboundConnectionsHelper()
        {
            // this is the first time that user tries to retrieve this property, so get it from the directory
            if (_outbound == null)
            {
                // search base is the site container
                string         siteName = (this is DomainController) ? ((DomainController)this).SiteObjectName : ((AdamInstance)this).SiteObjectName;
                DirectoryEntry de       = DirectoryEntryManager.GetDirectoryEntry(Utils.GetNewDirectoryContext(Name, DirectoryContextType.DirectoryServer, context), siteName);

                string     serverName = (this is DomainController) ? ((DomainController)this).ServerObjectName : ((AdamInstance)this).ServerObjectName;
                ADSearcher adSearcher = new ADSearcher(de,
                                                       "(&(objectClass=nTDSConnection)(objectCategory=nTDSConnection)(fromServer=CN=NTDS Settings," + serverName + "))",
                                                       new string[] { "objectClass", "cn" },
                                                       SearchScope.Subtree);

                SearchResultCollection results    = null;
                DirectoryContext       newContext = Utils.GetNewDirectoryContext(Name, DirectoryContextType.DirectoryServer, context);

                try
                {
                    results   = adSearcher.FindAll();
                    _outbound = new ReplicationConnectionCollection();

                    foreach (SearchResult result in results)
                    {
                        ReplicationConnection con = new ReplicationConnection(newContext, result.GetDirectoryEntry(), (string)result.Properties["cn"][0]);
                        _outbound.Add(con);
                    }
                }
                catch (COMException e)
                {
                    throw ExceptionHelper.GetExceptionFromCOMException(newContext, e);
                }
                finally
                {
                    if (results != null)
                    {
                        results.Dispose();
                    }

                    de.Dispose();
                }
            }

            return(_outbound);
        }
Exemplo n.º 15
0
        internal ReplicationConnectionCollection GetInboundConnectionsHelper()
        {
            if (_inbound == null)
            {
                // construct the replicationconnection collection
                _inbound = new ReplicationConnectionCollection();
                DirectoryContext newContext = Utils.GetNewDirectoryContext(Name, DirectoryContextType.DirectoryServer, context);

                // this is the first time that user tries to retrieve this property, so get it from the directory
                string         serverName = (this is DomainController) ? ((DomainController)this).ServerObjectName : ((AdamInstance)this).ServerObjectName;
                string         srchDN     = "CN=NTDS Settings," + serverName;
                DirectoryEntry de         = DirectoryEntryManager.GetDirectoryEntry(Utils.GetNewDirectoryContext(Name, DirectoryContextType.DirectoryServer, context), srchDN);

                ADSearcher adSearcher = new ADSearcher(de,
                                                       "(&(objectClass=nTDSConnection)(objectCategory=nTDSConnection))",
                                                       new string[] { "cn" },
                                                       SearchScope.OneLevel);
                SearchResultCollection srchResults = null;

                try
                {
                    srchResults = adSearcher.FindAll();
                    foreach (SearchResult r in srchResults)
                    {
                        ReplicationConnection con = new ReplicationConnection(newContext, r.GetDirectoryEntry(), (string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.Cn));
                        _inbound.Add(con);
                    }
                }
                catch (COMException e)
                {
                    throw ExceptionHelper.GetExceptionFromCOMException(newContext, e);
                }
                finally
                {
                    if (srchResults != null)
                    {
                        srchResults.Dispose();
                    }

                    de.Dispose();
                }
            }

            return(_inbound);
        }
Exemplo n.º 16
0
        private ArrayList GetSites()
        {
            ArrayList      sites      = new ArrayList();
            DirectoryEntry sitesEntry = _directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.SitesContainer);

            // search for all the "site" objects
            // (one-level search is good enough)
            // setup the directory searcher object
            string filter = "(" + PropertyManager.ObjectCategory + "=site)";

            string[] propertiesToLoad = new string[1];

            propertiesToLoad[0] = PropertyManager.Cn;

            ADSearcher             searcher = new ADSearcher(sitesEntry, filter, propertiesToLoad, SearchScope.OneLevel);
            SearchResultCollection resCol   = null;

            try
            {
                resCol = searcher.FindAll();

                foreach (SearchResult res in resCol)
                {
                    // an existing site
                    sites.Add(new ActiveDirectorySite(_context, (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.Cn), true));
                }
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(_context, e);
            }
            finally
            {
                if (resCol != null)
                {
                    // call dispose on search result collection
                    resCol.Dispose();
                }
            }
            return(sites);
        }
Exemplo n.º 17
0
        private void GetSubnets()
        {
            // performs a search to find out the subnets that belong to this site     
            DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
            string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext);
            string subnetContainer = "CN=Subnets,CN=Sites," + config;
            de = DirectoryEntryManager.GetDirectoryEntry(context, subnetContainer);

            ADSearcher adSearcher = new ADSearcher(de,
                                                  "(&(objectClass=subnet)(objectCategory=subnet)(siteObject=" + Utils.GetEscapedFilterValue((string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName)) + "))",
                                                  new string[] { "cn", "location" },
                                                  SearchScope.OneLevel
                                                  );
            SearchResultCollection results = null;

            try
            {
                results = adSearcher.FindAll();
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }

            try
            {
                string subnetName = null;
                foreach (SearchResult result in results)
                {
                    subnetName = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.Cn);
                    ActiveDirectorySubnet subnet = new ActiveDirectorySubnet(context, subnetName, null, true);
                    // set the cached entry
                    subnet.cachedEntry = result.GetDirectoryEntry();
                    // set the site info
                    subnet.Site = this;

                    _subnets.Add(subnet);
                }
            }
            finally
            {
                results.Dispose();
                de.Dispose();
            }
        }
Exemplo n.º 18
0
		private void GetSubnets()
		{
			DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, WellKnownDN.RootDSE);
			string propertyValue = (string)PropertyManager.GetPropertyValue(this.context, directoryEntry, PropertyManager.ConfigurationNamingContext);
			string str = string.Concat("CN=Subnets,CN=Sites,", propertyValue);
			directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, str);
			string[] strArrays = new string[2];
			strArrays[0] = "cn";
			strArrays[1] = "location";
			ADSearcher aDSearcher = new ADSearcher(directoryEntry, string.Concat("(&(objectClass=subnet)(objectCategory=subnet)(siteObject=", Utils.GetEscapedFilterValue((string)PropertyManager.GetPropertyValue(this.context, this.cachedEntry, PropertyManager.DistinguishedName)), "))"), strArrays, SearchScope.OneLevel);
			SearchResultCollection searchResultCollections = null;
			try
			{
				searchResultCollections = aDSearcher.FindAll();
			}
			catch (COMException cOMException1)
			{
				COMException cOMException = cOMException1;
				throw ExceptionHelper.GetExceptionFromCOMException(this.context, cOMException);
			}
			try
			{
				foreach (SearchResult searchResult in searchResultCollections)
				{
					string searchResultPropertyValue = (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.Cn);
					ActiveDirectorySubnet activeDirectorySubnet = new ActiveDirectorySubnet(this.context, searchResultPropertyValue, null, true);
					activeDirectorySubnet.cachedEntry = searchResult.GetDirectoryEntry();
					activeDirectorySubnet.Site = this;
					this.subnets.Add(activeDirectorySubnet);
				}
			}
			finally
			{
				searchResultCollections.Dispose();
				directoryEntry.Dispose();
			}
		}
Exemplo n.º 19
0
		private ReadOnlyDirectoryServerCollection GetBridgeheadServers()
		{
			DirectoryServer domainController;
			NativeComInterfaces.IAdsPathname pathname = (NativeComInterfaces.IAdsPathname)(new NativeComInterfaces.Pathname());
			pathname.EscapedMode = 4;
			ReadOnlyDirectoryServerCollection readOnlyDirectoryServerCollection = new ReadOnlyDirectoryServerCollection();
			if (this.existing)
			{
				Hashtable hashtables = new Hashtable();
				Hashtable hashtables1 = new Hashtable();
				Hashtable hashtables2 = new Hashtable();
				string str = string.Concat("CN=Servers,", (string)PropertyManager.GetPropertyValue(this.context, this.cachedEntry, PropertyManager.DistinguishedName));
				DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, str);
				try
				{
					string[] strArrays = new string[4];
					strArrays[0] = "fromServer";
					strArrays[1] = "distinguishedName";
					strArrays[2] = "dNSHostName";
					strArrays[3] = "objectCategory";
					ADSearcher aDSearcher = new ADSearcher(directoryEntry, "(|(objectCategory=server)(objectCategory=NTDSConnection))", strArrays, SearchScope.Subtree, true, true);
					SearchResultCollection searchResultCollections = null;
					try
					{
						searchResultCollections = aDSearcher.FindAll();
					}
					catch (COMException cOMException1)
					{
						COMException cOMException = cOMException1;
						throw ExceptionHelper.GetExceptionFromCOMException(this.context, cOMException);
					}
					try
					{
						foreach (SearchResult searchResult in searchResultCollections)
						{
							string searchResultPropertyValue = (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.ObjectCategory);
							if (Utils.Compare(searchResultPropertyValue, 0, "CN=Server".Length, "CN=Server", 0, "CN=Server".Length) != 0)
							{
								continue;
							}
							hashtables2.Add((string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.DistinguishedName), (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.DnsHostName));
						}
						foreach (SearchResult searchResult1 in searchResultCollections)
						{
							string searchResultPropertyValue1 = (string)PropertyManager.GetSearchResultPropertyValue(searchResult1, PropertyManager.ObjectCategory);
							if (Utils.Compare(searchResultPropertyValue1, 0, "CN=Server".Length, "CN=Server", 0, "CN=Server".Length) == 0)
							{
								continue;
							}
							string str1 = (string)PropertyManager.GetSearchResultPropertyValue(searchResult1, PropertyManager.FromServer);
							string partialDN = Utils.GetPartialDN(str1, 3);
							pathname.Set(partialDN, 4);
							partialDN = pathname.Retrieve(11);
							partialDN = partialDN.Substring(3);
							string partialDN1 = Utils.GetPartialDN((string)PropertyManager.GetSearchResultPropertyValue(searchResult1, PropertyManager.DistinguishedName), 2);
							if (hashtables.Contains(partialDN1))
							{
								continue;
							}
							string item = (string)hashtables2[partialDN1];
							if (!hashtables1.Contains(partialDN1))
							{
								hashtables1.Add(partialDN1, item);
							}
							if (Utils.Compare((string)PropertyManager.GetPropertyValue(this.context, this.cachedEntry, PropertyManager.Cn), partialDN) == 0)
							{
								continue;
							}
							hashtables.Add(partialDN1, item);
							hashtables1.Remove(partialDN1);
						}
					}
					finally
					{
						searchResultCollections.Dispose();
					}
				}
				finally
				{
					directoryEntry.Dispose();
				}
				if (hashtables1.Count != 0)
				{
					DirectoryEntry directoryEntry1 = DirectoryEntryManager.GetDirectoryEntry(this.context, this.siteDN);
					StringBuilder stringBuilder = new StringBuilder(100);
					if (hashtables1.Count > 1)
					{
						stringBuilder.Append("(|");
					}
					foreach (DictionaryEntry hashtable in hashtables1)
					{
						stringBuilder.Append("(fromServer=");
						stringBuilder.Append("CN=NTDS Settings,");
						stringBuilder.Append(Utils.GetEscapedFilterValue((string)hashtable.Key));
						stringBuilder.Append(")");
					}
					if (hashtables1.Count > 1)
					{
						stringBuilder.Append(")");
					}
					string[] strArrays1 = new string[2];
					strArrays1[0] = "fromServer";
					strArrays1[1] = "distinguishedName";
					ADSearcher aDSearcher1 = new ADSearcher(directoryEntry1, string.Concat("(&(objectClass=nTDSConnection)(objectCategory=NTDSConnection)", stringBuilder.ToString(), ")"), strArrays1, SearchScope.Subtree);
					SearchResultCollection searchResultCollections1 = null;
					try
					{
						searchResultCollections1 = aDSearcher1.FindAll();
					}
					catch (COMException cOMException3)
					{
						COMException cOMException2 = cOMException3;
						throw ExceptionHelper.GetExceptionFromCOMException(this.context, cOMException2);
					}
					try
					{
						foreach (SearchResult searchResult2 in searchResultCollections1)
						{
							string searchResultPropertyValue2 = (string)PropertyManager.GetSearchResultPropertyValue(searchResult2, PropertyManager.FromServer);
							string str2 = searchResultPropertyValue2.Substring(17);
							if (!hashtables1.Contains(str2))
							{
								continue;
							}
							string partialDN2 = Utils.GetPartialDN((string)PropertyManager.GetSearchResultPropertyValue(searchResult2, PropertyManager.DistinguishedName), 4);
							pathname.Set(partialDN2, 4);
							partialDN2 = pathname.Retrieve(11);
							partialDN2 = partialDN2.Substring(3);
							if (Utils.Compare(partialDN2, (string)PropertyManager.GetPropertyValue(this.context, this.cachedEntry, PropertyManager.Cn)) == 0)
							{
								continue;
							}
							string item1 = (string)hashtables1[str2];
							hashtables1.Remove(str2);
							hashtables.Add(str2, item1);
						}
					}
					finally
					{
						searchResultCollections1.Dispose();
						directoryEntry1.Dispose();
					}
				}
				foreach (DictionaryEntry dictionaryEntry in hashtables)
				{
					string value = (string)dictionaryEntry.Value;
					if (!this.IsADAM)
					{
						domainController = new DomainController(Utils.GetNewDirectoryContext(value, DirectoryContextType.DirectoryServer, this.context), value);
					}
					else
					{
						DirectoryEntry directoryEntry2 = DirectoryEntryManager.GetDirectoryEntry(this.context, string.Concat("CN=NTDS Settings,", dictionaryEntry.Key));
						int propertyValue = (int)PropertyManager.GetPropertyValue(this.context, directoryEntry2, PropertyManager.MsDSPortLDAP);
						string str3 = value;
						if (propertyValue != 0x185)
						{
							str3 = string.Concat(value, ":", propertyValue);
						}
						domainController = new AdamInstance(Utils.GetNewDirectoryContext(str3, DirectoryContextType.DirectoryServer, this.context), str3);
					}
					readOnlyDirectoryServerCollection.Add(domainController);
				}
			}
			return readOnlyDirectoryServerCollection;
		}
Exemplo n.º 20
0
		private ArrayList GetSites()
		{
			ArrayList arrayLists = new ArrayList();
			DirectoryEntry cachedDirectoryEntry = this.directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.SitesContainer);
			string str = string.Concat("(", PropertyManager.ObjectCategory, "=site)");
			string[] cn = new string[1];
			cn[0] = PropertyManager.Cn;
			ADSearcher aDSearcher = new ADSearcher(cachedDirectoryEntry, str, cn, SearchScope.OneLevel);
			SearchResultCollection searchResultCollections = null;
			using (searchResultCollections)
			{
				try
				{
					searchResultCollections = aDSearcher.FindAll();
					foreach (SearchResult searchResult in searchResultCollections)
					{
						arrayLists.Add(new ActiveDirectorySite(this.context, (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.Cn), true));
					}
				}
				catch (COMException cOMException1)
				{
					COMException cOMException = cOMException1;
					throw ExceptionHelper.GetExceptionFromCOMException(this.context, cOMException);
				}
			}
			return arrayLists;
		}
Exemplo n.º 21
0
		private void GetPreferredBridgeheadServers(ActiveDirectoryTransportType transport)
		{
			string str;
			DirectoryServer domainController;
			string str1 = string.Concat("CN=Servers,", PropertyManager.GetPropertyValue(this.context, this.cachedEntry, PropertyManager.DistinguishedName));
			if (transport != ActiveDirectoryTransportType.Smtp)
			{
				str = string.Concat("CN=IP,CN=Inter-Site Transports,", this.siteDN);
			}
			else
			{
				str = string.Concat("CN=SMTP,CN=Inter-Site Transports,", this.siteDN);
			}
			DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, str1);
			string[] strArrays = new string[2];
			strArrays[0] = "dNSHostName";
			strArrays[1] = "distinguishedName";
			ADSearcher aDSearcher = new ADSearcher(directoryEntry, string.Concat("(&(objectClass=server)(objectCategory=Server)(bridgeheadTransportList=", Utils.GetEscapedFilterValue(str), "))"), strArrays, SearchScope.OneLevel);
			SearchResultCollection searchResultCollections = null;
			try
			{
				searchResultCollections = aDSearcher.FindAll();
			}
			catch (COMException cOMException1)
			{
				COMException cOMException = cOMException1;
				throw ExceptionHelper.GetExceptionFromCOMException(this.context, cOMException);
			}
			try
			{
				DirectoryEntry directoryEntry1 = null;
				foreach (SearchResult searchResult in searchResultCollections)
				{
					string searchResultPropertyValue = (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.DnsHostName);
					DirectoryEntry directoryEntry2 = searchResult.GetDirectoryEntry();
					try
					{
						directoryEntry1 = directoryEntry2.Children.Find("CN=NTDS Settings", "nTDSDSA");
					}
					catch (COMException cOMException3)
					{
						COMException cOMException2 = cOMException3;
						throw ExceptionHelper.GetExceptionFromCOMException(this.context, cOMException2);
					}
					if (!this.IsADAM)
					{
						domainController = new DomainController(Utils.GetNewDirectoryContext(searchResultPropertyValue, DirectoryContextType.DirectoryServer, this.context), searchResultPropertyValue);
					}
					else
					{
						int propertyValue = (int)PropertyManager.GetPropertyValue(this.context, directoryEntry1, PropertyManager.MsDSPortLDAP);
						string str2 = searchResultPropertyValue;
						if (propertyValue != 0x185)
						{
							str2 = string.Concat(searchResultPropertyValue, ":", propertyValue);
						}
						domainController = new AdamInstance(Utils.GetNewDirectoryContext(str2, DirectoryContextType.DirectoryServer, this.context), str2);
					}
					if (transport != ActiveDirectoryTransportType.Smtp)
					{
						this.RPCBridgeheadServers.Add(domainController);
					}
					else
					{
						this.SMTPBridgeheadServers.Add(domainController);
					}
				}
			}
			finally
			{
				directoryEntry.Dispose();
				searchResultCollections.Dispose();
			}
		}
Exemplo n.º 22
0
        internal ReplicationConnectionCollection GetOutboundConnectionsHelper()
        {
            // this is the first time that user tries to retrieve this property, so get it from the directory
            if (_outbound == null)
            {
                // search base is the site container
                string siteName = (this is DomainController) ? ((DomainController)this).SiteObjectName : ((AdamInstance)this).SiteObjectName;
                DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(Utils.GetNewDirectoryContext(Name, DirectoryContextType.DirectoryServer, context), siteName);

                string serverName = (this is DomainController) ? ((DomainController)this).ServerObjectName : ((AdamInstance)this).ServerObjectName;
                ADSearcher adSearcher = new ADSearcher(de,
                                                               "(&(objectClass=nTDSConnection)(objectCategory=nTDSConnection)(fromServer=CN=NTDS Settings," + serverName + "))",
                                                               new string[] { "objectClass", "cn" },
                                                               SearchScope.Subtree);

                SearchResultCollection results = null;
                DirectoryContext newContext = Utils.GetNewDirectoryContext(Name, DirectoryContextType.DirectoryServer, context);

                try
                {
                    results = adSearcher.FindAll();
                    _outbound = new ReplicationConnectionCollection();

                    foreach (SearchResult result in results)
                    {
                        ReplicationConnection con = new ReplicationConnection(newContext, result.GetDirectoryEntry(), (string)result.Properties["cn"][0]);
                        _outbound.Add(con);
                    }
                }
                catch (COMException e)
                {
                    throw ExceptionHelper.GetExceptionFromCOMException(newContext, e);
                }
                finally
                {
                    if (results != null)
                        results.Dispose();

                    de.Dispose();
                }
            }

            return _outbound;
        }
Exemplo n.º 23
0
        private ReadOnlyDirectoryServerCollection GetBridgeheadServers()
        {
            NativeComInterfaces.IAdsPathname pathCracker = (NativeComInterfaces.IAdsPathname)new NativeComInterfaces.Pathname();
            // need to turn off the escaping for name
            pathCracker.EscapedMode = NativeComInterfaces.ADS_ESCAPEDMODE_OFF_EX;

            ReadOnlyDirectoryServerCollection collection = new ReadOnlyDirectoryServerCollection();
            if (existing)
            {
                Hashtable bridgeHeadTable = new Hashtable();
                Hashtable nonBridgHeadTable = new Hashtable();
                Hashtable hostNameTable = new Hashtable();
                const string ocValue = "CN=Server";

                // get destination bridgehead servers

                // first go to the servers container under the current site and then do a search to get the all server objects.
                string serverContainer = "CN=Servers," + (string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName);
                DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, serverContainer);

                try
                {
                    // go through connection objects and find out its fromServer property. 
                    ADSearcher adSearcher = new ADSearcher(de,
                                                          "(|(objectCategory=server)(objectCategory=NTDSConnection))",
                                                          new string[] { "fromServer", "distinguishedName", "dNSHostName", "objectCategory" },
                                                          SearchScope.Subtree,
                                                          true, /* need paged search */
                                                          true /* need cached result as we need to go back to the first record */);
                    SearchResultCollection conResults = null;
                    try
                    {
                        conResults = adSearcher.FindAll();
                    }
                    catch (COMException e)
                    {
                        throw ExceptionHelper.GetExceptionFromCOMException(context, e);
                    }

                    try
                    {
                        // find out whether fromServer indicates replicating from a server in another site.
                        foreach (SearchResult r in conResults)
                        {
                            string objectCategoryValue = (string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.ObjectCategory);
                            if (Utils.Compare(objectCategoryValue, 0, ocValue.Length, ocValue, 0, ocValue.Length) == 0)
                            {
                                hostNameTable.Add((string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.DistinguishedName), (string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.DnsHostName));
                            }
                        }

                        foreach (SearchResult r in conResults)
                        {
                            string objectCategoryValue = (string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.ObjectCategory);
                            if (Utils.Compare(objectCategoryValue, 0, ocValue.Length, ocValue, 0, ocValue.Length) != 0)
                            {
                                string fromServer = (string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.FromServer);

                                // escaping manipulation                                
                                string fromSite = Utils.GetPartialDN(fromServer, 3);
                                pathCracker.Set(fromSite, NativeComInterfaces.ADS_SETTYPE_DN);
                                fromSite = pathCracker.Retrieve(NativeComInterfaces.ADS_FORMAT_LEAF);
                                Debug.Assert(fromSite != null && Utils.Compare(fromSite, 0, 3, "CN=", 0, 3) == 0);
                                fromSite = fromSite.Substring(3);

                                string serverObjectName = Utils.GetPartialDN((string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.DistinguishedName), 2);
                                // don't know whether it is a bridgehead server yet.
                                if (!bridgeHeadTable.Contains(serverObjectName))
                                {
                                    string hostName = (string)hostNameTable[serverObjectName];
                                    // add if not yet done
                                    if (!nonBridgHeadTable.Contains(serverObjectName))
                                        nonBridgHeadTable.Add(serverObjectName, hostName);

                                    // check whether from different site
                                    if (Utils.Compare((string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.Cn), fromSite) != 0)
                                    {
                                        // the server is a bridgehead server
                                        bridgeHeadTable.Add(serverObjectName, hostName);
                                        nonBridgHeadTable.Remove(serverObjectName);
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        conResults.Dispose();
                    }
                }
                finally
                {
                    de.Dispose();
                }

                // get source bridgehead server
                if (nonBridgHeadTable.Count != 0)
                {
                    // go to sites container to get all the connecdtion object that replicates from servers in the current sites that have
                    // not been determined whether it is a bridgehead server or not.
                    DirectoryEntry serverEntry = DirectoryEntryManager.GetDirectoryEntry(context, _siteDN);
                    // constructing the filter
                    StringBuilder str = new StringBuilder(100);
                    if (nonBridgHeadTable.Count > 1)
                        str.Append("(|");
                    foreach (DictionaryEntry val in nonBridgHeadTable)
                    {
                        str.Append("(fromServer=");
                        str.Append("CN=NTDS Settings,");
                        str.Append(Utils.GetEscapedFilterValue((string)val.Key));
                        str.Append(")");
                    }
                    if (nonBridgHeadTable.Count > 1)
                        str.Append(")");
                    ADSearcher adSearcher = new ADSearcher(serverEntry,
                                                          "(&(objectClass=nTDSConnection)(objectCategory=NTDSConnection)" + str.ToString() + ")",
                                                          new string[] { "fromServer", "distinguishedName" },
                                                          SearchScope.Subtree);
                    SearchResultCollection conResults = null;
                    try
                    {
                        conResults = adSearcher.FindAll();
                    }
                    catch (COMException e)
                    {
                        throw ExceptionHelper.GetExceptionFromCOMException(context, e);
                    }

                    try
                    {
                        foreach (SearchResult r in conResults)
                        {
                            string fromServer = (string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.FromServer);
                            string serverObject = fromServer.Substring(17);

                            if (nonBridgHeadTable.Contains(serverObject))
                            {
                                string otherSite = Utils.GetPartialDN((string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.DistinguishedName), 4);
                                // escaping manipulation
                                pathCracker.Set(otherSite, NativeComInterfaces.ADS_SETTYPE_DN);
                                otherSite = pathCracker.Retrieve(NativeComInterfaces.ADS_FORMAT_LEAF);
                                Debug.Assert(otherSite != null && Utils.Compare(otherSite, 0, 3, "CN=", 0, 3) == 0);
                                otherSite = otherSite.Substring(3);

                                // check whether from different sites
                                if (Utils.Compare(otherSite, (string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.Cn)) != 0)
                                {
                                    string val = (string)nonBridgHeadTable[serverObject];
                                    nonBridgHeadTable.Remove(serverObject);
                                    bridgeHeadTable.Add(serverObject, val);
                                }
                            }
                        }
                    }
                    finally
                    {
                        conResults.Dispose();
                        serverEntry.Dispose();
                    }
                }

                DirectoryEntry ADAMEntry = null;
                foreach (DictionaryEntry e in bridgeHeadTable)
                {
                    DirectoryServer replica = null;
                    string host = (string)e.Value;
                    // construct directoryreplica
                    if (IsADAM)
                    {
                        ADAMEntry = DirectoryEntryManager.GetDirectoryEntry(context, "CN=NTDS Settings," + e.Key);
                        int port = (int)PropertyManager.GetPropertyValue(context, ADAMEntry, PropertyManager.MsDSPortLDAP);
                        string fullhost = host;
                        if (port != 389)
                        {
                            fullhost = host + ":" + port;
                        }
                        replica = new AdamInstance(Utils.GetNewDirectoryContext(fullhost, DirectoryContextType.DirectoryServer, context), fullhost);
                    }
                    else
                    {
                        replica = new DomainController(Utils.GetNewDirectoryContext(host, DirectoryContextType.DirectoryServer, context), host);
                    }

                    collection.Add(replica);
                }
            }

            return collection;
        }
 private ArrayList GetSites()
 {
     ArrayList list = new ArrayList();
     DirectoryEntry cachedDirectoryEntry = this.directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.SitesContainer);
     string filter = "(" + PropertyManager.ObjectCategory + "=site)";
     string[] propertiesToLoad = new string[] { PropertyManager.Cn };
     ADSearcher searcher = new ADSearcher(cachedDirectoryEntry, filter, propertiesToLoad, SearchScope.OneLevel);
     SearchResultCollection results = null;
     try
     {
         results = searcher.FindAll();
         foreach (SearchResult result in results)
         {
             list.Add(new ActiveDirectorySite(this.context, (string) PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.Cn), true));
         }
         return list;
     }
     catch (COMException exception)
     {
         throw ExceptionHelper.GetExceptionFromCOMException(this.context, exception);
     }
     finally
     {
         if (results != null)
         {
             results.Dispose();
         }
     }
     return list;
 }
Exemplo n.º 25
0
        internal ReplicationConnectionCollection GetInboundConnectionsHelper()
        {
            if (_inbound == null)
            {
                // construct the replicationconnection collection
                _inbound = new ReplicationConnectionCollection();
                DirectoryContext newContext = Utils.GetNewDirectoryContext(Name, DirectoryContextType.DirectoryServer, context);

                // this is the first time that user tries to retrieve this property, so get it from the directory   
                string serverName = (this is DomainController) ? ((DomainController)this).ServerObjectName : ((AdamInstance)this).ServerObjectName;
                string srchDN = "CN=NTDS Settings," + serverName;
                DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(Utils.GetNewDirectoryContext(Name, DirectoryContextType.DirectoryServer, context), srchDN);

                ADSearcher adSearcher = new ADSearcher(de,
                                                      "(&(objectClass=nTDSConnection)(objectCategory=nTDSConnection))",
                                                      new string[] { "cn" },
                                                      SearchScope.OneLevel);
                SearchResultCollection srchResults = null;

                try
                {
                    srchResults = adSearcher.FindAll();
                    foreach (SearchResult r in srchResults)
                    {
                        ReplicationConnection con = new ReplicationConnection(newContext, r.GetDirectoryEntry(), (string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.Cn));
                        _inbound.Add(con);
                    }
                }
                catch (COMException e)
                {
                    throw ExceptionHelper.GetExceptionFromCOMException(newContext, e);
                }
                finally
                {
                    if (srchResults != null)
                        srchResults.Dispose();

                    de.Dispose();
                }
            }

            return _inbound;
        }
 private ArrayList GetApplicationPartitions()
 {
     ArrayList list = new ArrayList();
     DirectoryEntry cachedDirectoryEntry = this.directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE);
     DirectoryEntry searchRoot = this.directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.PartitionsContainer);
     StringBuilder builder = new StringBuilder(100);
     builder.Append("(&(");
     builder.Append(PropertyManager.ObjectCategory);
     builder.Append("=crossRef)(");
     builder.Append(PropertyManager.SystemFlags);
     builder.Append(":1.2.840.113556.1.4.804:=");
     builder.Append(1);
     builder.Append(")(!(");
     builder.Append(PropertyManager.SystemFlags);
     builder.Append(":1.2.840.113556.1.4.803:=");
     builder.Append(2);
     builder.Append(")))");
     string filter = builder.ToString();
     string[] propertiesToLoad = new string[] { PropertyManager.NCName, PropertyManager.MsDSNCReplicaLocations };
     ADSearcher searcher = new ADSearcher(searchRoot, filter, propertiesToLoad, SearchScope.OneLevel);
     SearchResultCollection results = null;
     try
     {
         results = searcher.FindAll();
         string str2 = (string) PropertyManager.GetPropertyValue(this.context, cachedDirectoryEntry, PropertyManager.SchemaNamingContext);
         string str3 = (string) PropertyManager.GetPropertyValue(this.context, cachedDirectoryEntry, PropertyManager.ConfigurationNamingContext);
         foreach (SearchResult result in results)
         {
             string searchResultPropertyValue = (string) PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.NCName);
             if (!searchResultPropertyValue.Equals(str2) && !searchResultPropertyValue.Equals(str3))
             {
                 ResultPropertyValueCollection values = result.Properties[PropertyManager.MsDSNCReplicaLocations];
                 if (values.Count > 0)
                 {
                     DirectoryContext context = Utils.GetNewDirectoryContext(Utils.GetAdamDnsHostNameFromNTDSA(this.context, (string) values[Utils.GetRandomIndex(values.Count)]), DirectoryContextType.DirectoryServer, this.context);
                     list.Add(new ApplicationPartition(context, searchResultPropertyValue, null, ApplicationPartitionType.ADAMApplicationPartition, new DirectoryEntryManager(context)));
                 }
             }
         }
         return list;
     }
     catch (COMException exception)
     {
         throw ExceptionHelper.GetExceptionFromCOMException(this.context, exception);
     }
     finally
     {
         if (results != null)
         {
             results.Dispose();
         }
     }
     return list;
 }
 internal static AdamInstance FindAnyAdamInstance(DirectoryContext context)
 {
     if (context.ContextType != DirectoryContextType.ConfigurationSet)
     {
         DirectoryEntryManager directoryEntryMgr = new DirectoryEntryManager(context);
         DirectoryEntry cachedDirectoryEntry = directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE);
         if (!Utils.CheckCapability(cachedDirectoryEntry, Capability.ActiveDirectoryApplicationMode))
         {
             directoryEntryMgr.RemoveIfExists(directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.RootDSE));
             throw new ArgumentException(Res.GetString("TargetShouldBeServerORConfigSet"), "context");
         }
         return new AdamInstance(context, (string) PropertyManager.GetPropertyValue(context, cachedDirectoryEntry, PropertyManager.DnsHostName), directoryEntryMgr);
     }
     DirectoryEntry searchRootEntry = GetSearchRootEntry(Forest.GetCurrentForest());
     ArrayList adamInstanceNames = new ArrayList();
     try
     {
         string text1 = (string) searchRootEntry.Properties["distinguishedName"].Value;
         StringBuilder builder = new StringBuilder(15);
         builder.Append("(&(");
         builder.Append(PropertyManager.ObjectCategory);
         builder.Append("=serviceConnectionPoint)");
         builder.Append("(");
         builder.Append(PropertyManager.Keywords);
         builder.Append("=1.2.840.113556.1.4.1851)(");
         builder.Append(PropertyManager.Keywords);
         builder.Append("=");
         builder.Append(Utils.GetEscapedFilterValue(context.Name));
         builder.Append("))");
         string filter = builder.ToString();
         string[] propertiesToLoad = new string[] { PropertyManager.ServiceBindingInformation };
         ADSearcher searcher = new ADSearcher(searchRootEntry, filter, propertiesToLoad, SearchScope.Subtree, false, false);
         using (SearchResultCollection results = searcher.FindAll())
         {
             foreach (SearchResult result in results)
             {
                 string strB = "ldap://";
                 foreach (string str4 in result.Properties[PropertyManager.ServiceBindingInformation])
                 {
                     if ((str4.Length > strB.Length) && (string.Compare(str4.Substring(0, strB.Length), strB, StringComparison.OrdinalIgnoreCase) == 0))
                     {
                         adamInstanceNames.Add(str4.Substring(strB.Length));
                     }
                 }
             }
         }
     }
     catch (COMException exception)
     {
         throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
     }
     finally
     {
         searchRootEntry.Dispose();
     }
     return FindAliveAdamInstance(null, context, adamInstanceNames);
 }
Exemplo n.º 28
0
		internal static ArrayList GetReplicaList(DirectoryContext context, string partitionName, string siteName, bool isDefaultNC, bool isADAM, bool isGC)
		{
			string dnsHostNameFromNTDSA;
			string str = null;
			string str1 = null;
			string str2 = null;
			string str3 = null;
			ArrayList arrayLists;
			string[] objectCategory;
			IDisposable disposable;
			IEnumerator enumerator;
			object[] msDSHasInstantiatedNCs;
			ArrayList arrayLists1 = new ArrayList();
			ArrayList arrayLists2 = new ArrayList();
			Hashtable hashtables = new Hashtable();
			Hashtable hashtables1 = new Hashtable();
			StringBuilder stringBuilder = new StringBuilder(10);
			StringBuilder stringBuilder1 = new StringBuilder(10);
			StringBuilder stringBuilder2 = new StringBuilder(10);
			StringBuilder stringBuilder3 = new StringBuilder(10);
			bool flag = false;
			string str4 = null;
			try
			{
				str4 = DirectoryEntryManager.ExpandWellKnownDN(context, WellKnownDN.ConfigurationNamingContext);
			}
			catch (COMException cOMException1)
			{
				COMException cOMException = cOMException1;
				throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException);
			}
			if (partitionName != null && !isDefaultNC)
			{
				DistinguishedName distinguishedName = new DistinguishedName(partitionName);
				DistinguishedName distinguishedName1 = new DistinguishedName(str4);
				DistinguishedName distinguishedName2 = new DistinguishedName(string.Concat("CN=Schema,", str4));
				if (!distinguishedName1.Equals(distinguishedName) && !distinguishedName2.Equals(distinguishedName))
				{
					flag = true;
				}
			}
			if (flag)
			{
				DirectoryEntry directoryEntry = null;
				DirectoryEntry directoryEntry1 = null;
				try
				{
					try
					{
						directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, string.Concat("CN=Partitions,", str4));
						if (!isADAM)
						{
							dnsHostNameFromNTDSA = Utils.GetDnsHostNameFromNTDSA(context, (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.FsmoRoleOwner));
						}
						else
						{
							dnsHostNameFromNTDSA = Utils.GetAdamDnsHostNameFromNTDSA(context, (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.FsmoRoleOwner));
						}
						DirectoryContext newDirectoryContext = Utils.GetNewDirectoryContext(dnsHostNameFromNTDSA, DirectoryContextType.DirectoryServer, context);
						directoryEntry1 = DirectoryEntryManager.GetDirectoryEntry(newDirectoryContext, string.Concat("CN=Partitions,", str4));
						objectCategory = new string[7];
						objectCategory[0] = "(&(";
						objectCategory[1] = PropertyManager.ObjectCategory;
						objectCategory[2] = "=crossRef)(";
						objectCategory[3] = PropertyManager.NCName;
						objectCategory[4] = "=";
						objectCategory[5] = Utils.GetEscapedFilterValue(partitionName);
						objectCategory[6] = "))";
						string str5 = string.Concat(objectCategory);
						ArrayList arrayLists3 = new ArrayList();
						arrayLists3.Add(PropertyManager.MsDSNCReplicaLocations);
						arrayLists3.Add(PropertyManager.MsDSNCROReplicaLocations);
						Hashtable valuesWithRangeRetrieval = null;
						try
						{
							valuesWithRangeRetrieval = Utils.GetValuesWithRangeRetrieval(directoryEntry1, str5, arrayLists3, SearchScope.OneLevel);
						}
						catch (COMException cOMException3)
						{
							COMException cOMException2 = cOMException3;
							throw ExceptionHelper.GetExceptionFromCOMException(newDirectoryContext, cOMException2);
						}
						catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException)
						{
							arrayLists = arrayLists2;
							return arrayLists;
						}
						ArrayList item = (ArrayList)valuesWithRangeRetrieval[PropertyManager.MsDSNCReplicaLocations.ToLower(CultureInfo.InvariantCulture)];
						ArrayList item1 = (ArrayList)valuesWithRangeRetrieval[PropertyManager.MsDSNCROReplicaLocations.ToLower(CultureInfo.InvariantCulture)];
						if (item.Count != 0)
						{
							foreach (string str6 in item)
							{
								stringBuilder.Append("(");
								stringBuilder.Append(PropertyManager.DistinguishedName);
								stringBuilder.Append("=");
								stringBuilder.Append(Utils.GetEscapedFilterValue(str6));
								stringBuilder.Append(")");
								stringBuilder1.Append("(");
								stringBuilder1.Append(PropertyManager.DistinguishedName);
								stringBuilder1.Append("=");
								stringBuilder1.Append(Utils.GetEscapedFilterValue(Utils.GetPartialDN(str6, 1)));
								stringBuilder1.Append(")");
							}
							foreach (string str7 in item1)
							{
								stringBuilder2.Append("(");
								stringBuilder2.Append(PropertyManager.DistinguishedName);
								stringBuilder2.Append("=");
								stringBuilder2.Append(Utils.GetEscapedFilterValue(str7));
								stringBuilder2.Append(")");
								stringBuilder3.Append("(");
								stringBuilder3.Append(PropertyManager.DistinguishedName);
								stringBuilder3.Append("=");
								stringBuilder3.Append(Utils.GetEscapedFilterValue(Utils.GetPartialDN(str7, 1)));
								stringBuilder3.Append(")");
							}
						}
						else
						{
							arrayLists = arrayLists2;
							return arrayLists;
						}
					}
					catch (COMException cOMException5)
					{
						COMException cOMException4 = cOMException5;
						throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException4);
					}
				}
				finally
				{
					if (directoryEntry != null)
					{
						directoryEntry.Dispose();
					}
					if (directoryEntry1 != null)
					{
						directoryEntry1.Dispose();
					}
				}
			}
			DirectoryEntry directoryEntry2 = null;
			using (directoryEntry2)
			{
				if (siteName == null)
				{
					str = string.Concat("CN=Sites,", str4);
				}
				else
				{
					str = string.Concat("CN=Servers,CN=", siteName, ",CN=Sites,", str4);
				}
				directoryEntry2 = DirectoryEntryManager.GetDirectoryEntry(context, str);
				if (stringBuilder.ToString().Length != 0)
				{
					if (!isGC)
					{
						if (stringBuilder2.Length <= 0)
						{
							objectCategory = new string[13];
							objectCategory[0] = "(|(&(";
							objectCategory[1] = PropertyManager.ObjectCategory;
							objectCategory[2] = "=nTDSDSA)(";
							objectCategory[3] = PropertyManager.MsDSHasMasterNCs;
							objectCategory[4] = "=";
							objectCategory[5] = Utils.GetEscapedFilterValue(partitionName);
							objectCategory[6] = ")(|";
							objectCategory[7] = stringBuilder.ToString();
							objectCategory[8] = "))(&(";
							objectCategory[9] = PropertyManager.ObjectCategory;
							objectCategory[10] = "=server)(|";
							objectCategory[11] = stringBuilder1.ToString();
							objectCategory[12] = ")))";
							str1 = string.Concat(objectCategory);
						}
						else
						{
							objectCategory = new string[21];
							objectCategory[0] = "(|(&(";
							objectCategory[1] = PropertyManager.ObjectCategory;
							objectCategory[2] = "=nTDSDSA)(";
							objectCategory[3] = PropertyManager.MsDSHasMasterNCs;
							objectCategory[4] = "=";
							objectCategory[5] = Utils.GetEscapedFilterValue(partitionName);
							objectCategory[6] = ")(|";
							objectCategory[7] = stringBuilder.ToString();
							objectCategory[8] = "))(&(";
							objectCategory[9] = PropertyManager.ObjectCategory;
							objectCategory[10] = "=nTDSDSARO)(|";
							objectCategory[11] = stringBuilder2.ToString();
							objectCategory[12] = "))(&(";
							objectCategory[13] = PropertyManager.ObjectCategory;
							objectCategory[14] = "=server)(|";
							objectCategory[15] = stringBuilder1.ToString();
							objectCategory[16] = "))(&(";
							objectCategory[17] = PropertyManager.ObjectCategory;
							objectCategory[18] = "=server)(|";
							objectCategory[19] = stringBuilder3.ToString();
							objectCategory[20] = ")))";
							str1 = string.Concat(objectCategory);
						}
					}
					else
					{
						if (stringBuilder2.Length <= 0)
						{
							objectCategory = new string[15];
							objectCategory[0] = "(|(&(";
							objectCategory[1] = PropertyManager.ObjectCategory;
							objectCategory[2] = "=nTDSDSA)(";
							objectCategory[3] = PropertyManager.Options;
							objectCategory[4] = ":1.2.840.113556.1.4.804:=1)(";
							objectCategory[5] = PropertyManager.MsDSHasMasterNCs;
							objectCategory[6] = "=";
							objectCategory[7] = Utils.GetEscapedFilterValue(partitionName);
							objectCategory[8] = ")(|";
							objectCategory[9] = stringBuilder.ToString();
							objectCategory[10] = "))(&(";
							objectCategory[11] = PropertyManager.ObjectCategory;
							objectCategory[12] = "=server)(|";
							objectCategory[13] = stringBuilder1.ToString();
							objectCategory[14] = ")))";
							str1 = string.Concat(objectCategory);
						}
						else
						{
							objectCategory = new string[25];
							objectCategory[0] = "(|(&(";
							objectCategory[1] = PropertyManager.ObjectCategory;
							objectCategory[2] = "=nTDSDSA)(";
							objectCategory[3] = PropertyManager.Options;
							objectCategory[4] = ":1.2.840.113556.1.4.804:=1)(";
							objectCategory[5] = PropertyManager.MsDSHasMasterNCs;
							objectCategory[6] = "=";
							objectCategory[7] = Utils.GetEscapedFilterValue(partitionName);
							objectCategory[8] = ")(|";
							objectCategory[9] = stringBuilder.ToString();
							objectCategory[10] = "))(&(";
							objectCategory[11] = PropertyManager.ObjectCategory;
							objectCategory[12] = "=nTDSDSARO)(";
							objectCategory[13] = PropertyManager.Options;
							objectCategory[14] = ":1.2.840.113556.1.4.804:=1)(|";
							objectCategory[15] = stringBuilder2.ToString();
							objectCategory[16] = "))(&(";
							objectCategory[17] = PropertyManager.ObjectCategory;
							objectCategory[18] = "=server)(|";
							objectCategory[19] = stringBuilder1.ToString();
							objectCategory[20] = "))(&(";
							objectCategory[21] = PropertyManager.ObjectCategory;
							objectCategory[22] = "=server)(|";
							objectCategory[23] = stringBuilder3.ToString();
							objectCategory[24] = ")))";
							str1 = string.Concat(objectCategory);
						}
					}
				}
				else
				{
					if (!isDefaultNC)
					{
						if (!isGC)
						{
							objectCategory = new string[7];
							objectCategory[0] = "(|(";
							objectCategory[1] = PropertyManager.ObjectCategory;
							objectCategory[2] = "=nTDSDSA)(";
							objectCategory[3] = PropertyManager.ObjectCategory;
							objectCategory[4] = "=nTDSDSARO)(";
							objectCategory[5] = PropertyManager.ObjectCategory;
							objectCategory[6] = "=server))";
							str1 = string.Concat(objectCategory);
						}
						else
						{
							objectCategory = new string[11];
							objectCategory[0] = "(|(&(";
							objectCategory[1] = PropertyManager.ObjectCategory;
							objectCategory[2] = "=nTDSDSA)(";
							objectCategory[3] = PropertyManager.Options;
							objectCategory[4] = ":1.2.840.113556.1.4.804:=1))(&(";
							objectCategory[5] = PropertyManager.ObjectCategory;
							objectCategory[6] = "=nTDSDSARO)(";
							objectCategory[7] = PropertyManager.Options;
							objectCategory[8] = ":1.2.840.113556.1.4.804:=1))(";
							objectCategory[9] = PropertyManager.ObjectCategory;
							objectCategory[10] = "=server))";
							str1 = string.Concat(objectCategory);
						}
					}
					else
					{
						objectCategory = new string[15];
						objectCategory[0] = "(|(&(";
						objectCategory[1] = PropertyManager.ObjectCategory;
						objectCategory[2] = "=nTDSDSA)(";
						objectCategory[3] = PropertyManager.HasMasterNCs;
						objectCategory[4] = "=";
						objectCategory[5] = Utils.GetEscapedFilterValue(partitionName);
						objectCategory[6] = "))(&(";
						objectCategory[7] = PropertyManager.ObjectCategory;
						objectCategory[8] = "=nTDSDSARO)(";
						objectCategory[9] = PropertyManager.MsDSHasFullReplicaNCs;
						objectCategory[10] = "=";
						objectCategory[11] = Utils.GetEscapedFilterValue(partitionName);
						objectCategory[12] = "))(";
						objectCategory[13] = PropertyManager.ObjectCategory;
						objectCategory[14] = "=server))";
						str1 = string.Concat(objectCategory);
					}
				}
				ADSearcher aDSearcher = new ADSearcher(directoryEntry2, str1, new string[0], SearchScope.Subtree);
				bool flag1 = false;
				ArrayList arrayLists4 = new ArrayList();
				int num = 0;
				string str8 = string.Concat(PropertyManager.MsDSHasInstantiatedNCs, ";range=0-*");
				aDSearcher.PropertiesToLoad.Add(PropertyManager.DistinguishedName);
				aDSearcher.PropertiesToLoad.Add(PropertyManager.DnsHostName);
				aDSearcher.PropertiesToLoad.Add(str8);
				aDSearcher.PropertiesToLoad.Add(PropertyManager.ObjectCategory);
				if (isADAM)
				{
					aDSearcher.PropertiesToLoad.Add(PropertyManager.MsDSPortLDAP);
				}
				try
				{
					string str9 = "CN=NTDS-DSA";
					string str10 = "CN=NTDS-DSA-RO";
					SearchResultCollection searchResultCollections = aDSearcher.FindAll();
					using (searchResultCollections)
					{
						foreach (SearchResult searchResult in searchResultCollections)
						{
							string searchResultPropertyValue = (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.ObjectCategory);
							if (searchResultPropertyValue.Length < str9.Length || Utils.Compare(searchResultPropertyValue, 0, str9.Length, str9, 0, str9.Length) != 0)
							{
								if (!searchResult.Properties.Contains(PropertyManager.DnsHostName))
								{
									continue;
								}
								hashtables.Add(string.Concat("CN=NTDS Settings,", (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.DistinguishedName)), (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.DnsHostName));
							}
							else
							{
								string searchResultPropertyValue1 = (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.DistinguishedName);
								if (!flag)
								{
									arrayLists1.Add(searchResultPropertyValue1);
									if (!isADAM)
									{
										continue;
									}
									hashtables1.Add(searchResultPropertyValue1, (int)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.MsDSPortLDAP));
								}
								else
								{
									if (searchResultPropertyValue.Length < str10.Length || Utils.Compare(searchResultPropertyValue, 0, str10.Length, str10, 0, str10.Length) != 0)
									{
										if (searchResult.Properties.Contains(str8))
										{
											str2 = str8;
										}
										else
										{
											foreach (string propertyName in searchResult.Properties.PropertyNames)
											{
												if (propertyName.Length < PropertyManager.MsDSHasInstantiatedNCs.Length || Utils.Compare(propertyName, 0, PropertyManager.MsDSHasInstantiatedNCs.Length, PropertyManager.MsDSHasInstantiatedNCs, 0, PropertyManager.MsDSHasInstantiatedNCs.Length) != 0)
												{
													continue;
												}
												str2 = propertyName;
												break;
											}
										}
										if (str2 == null)
										{
											continue;
										}
										bool flag2 = false;
										int num1 = 0;
										foreach (string item2 in searchResult.Properties[str2])
										{
											if (item2.Length - 13 >= partitionName.Length && Utils.Compare(item2, 13, partitionName.Length, partitionName, 0, partitionName.Length) == 0)
											{
												flag2 = true;
												if (string.Compare(item2, 10, "0", 0, 1, StringComparison.OrdinalIgnoreCase) == 0)
												{
													arrayLists1.Add(searchResultPropertyValue1);
													if (!isADAM)
													{
														break;
													}
													hashtables1.Add(searchResultPropertyValue1, (int)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.MsDSPortLDAP));
													break;
												}
											}
											num1++;
										}
										if (flag2 || str2.Length < str8.Length || Utils.Compare(str2, 0, str8.Length, str8, 0, str8.Length) == 0)
										{
											continue;
										}
										flag1 = true;
										arrayLists4.Add(searchResultPropertyValue1);
										num = num1;
									}
									else
									{
										arrayLists1.Add(searchResultPropertyValue1);
										if (!isADAM)
										{
											continue;
										}
										hashtables1.Add(searchResultPropertyValue1, (int)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.MsDSPortLDAP));
									}
								}
							}
						}
					}
					if (flag1)
					{
						do
						{
							StringBuilder stringBuilder4 = new StringBuilder(20);
							if (arrayLists4.Count > 1)
							{
								stringBuilder4.Append("(|");
							}
							foreach (string arrayList in arrayLists4)
							{
								stringBuilder4.Append("(");
								stringBuilder4.Append(PropertyManager.NCName);
								stringBuilder4.Append("=");
								stringBuilder4.Append(Utils.GetEscapedFilterValue(arrayList));
								stringBuilder4.Append(")");
							}
							if (arrayLists4.Count > 1)
							{
								stringBuilder4.Append(")");
							}
							arrayLists4.Clear();
							flag1 = false;
							objectCategory = new string[5];
							objectCategory[0] = "(&(";
							objectCategory[1] = PropertyManager.ObjectCategory;
							objectCategory[2] = "=nTDSDSA)";
							objectCategory[3] = stringBuilder4.ToString();
							objectCategory[4] = ")";
							aDSearcher.Filter = string.Concat(objectCategory);
							msDSHasInstantiatedNCs = new object[4];
							msDSHasInstantiatedNCs[0] = PropertyManager.MsDSHasInstantiatedNCs;
							msDSHasInstantiatedNCs[1] = ";range=";
							msDSHasInstantiatedNCs[2] = num;
							msDSHasInstantiatedNCs[3] = "-*";
							string str11 = string.Concat(msDSHasInstantiatedNCs);
							aDSearcher.PropertiesToLoad.Clear();
							aDSearcher.PropertiesToLoad.Add(str11);
							aDSearcher.PropertiesToLoad.Add(PropertyManager.DistinguishedName);
							SearchResultCollection searchResultCollections1 = aDSearcher.FindAll();
							try
							{
								foreach (SearchResult searchResult1 in searchResultCollections1)
								{
									string searchResultPropertyValue2 = (string)PropertyManager.GetSearchResultPropertyValue(searchResult1, PropertyManager.DistinguishedName);
									str3 = null;
									if (searchResult1.Properties.Contains(str11))
									{
										str3 = str11;
									}
									else
									{
										enumerator = searchResult1.Properties.PropertyNames.GetEnumerator();
										try
										{
											while (enumerator.MoveNext())
											{
												string str12 = searchResult1.ToString ();
												if (string.Compare(str12, 0, PropertyManager.MsDSHasInstantiatedNCs, 0, PropertyManager.MsDSHasInstantiatedNCs.Length, StringComparison.OrdinalIgnoreCase) != 0)
												{
													continue;
												}
												str3 = str12;
												break;
											}
										}
										finally
										{
											disposable = enumerator as IDisposable;
											if (disposable != null)
											{
												disposable.Dispose();
											}
										}
									}
									if (str3 == null)
									{
										continue;
									}
									bool flag3 = false;
									int num2 = 0;
									enumerator = searchResult1.Properties[str3].GetEnumerator();
									try
									{
										while (enumerator.MoveNext())
										{
											string str13 = searchResult1.ToString ();
											if (str13.Length - 13 >= partitionName.Length && Utils.Compare(str13, 13, partitionName.Length, partitionName, 0, partitionName.Length) == 0)
											{
												if (string.Compare(str13, 10, "0", 0, 1, StringComparison.OrdinalIgnoreCase) == 0)
												{
													arrayLists1.Add(searchResultPropertyValue2);
													if (!isADAM)
													{
														break;
													}
													hashtables1.Add(searchResultPropertyValue2, (int)PropertyManager.GetSearchResultPropertyValue(searchResult1, PropertyManager.MsDSPortLDAP));
													break;
												}
											}
											num2++;
										}
									}
									finally
									{
										disposable = enumerator as IDisposable;
										if (disposable != null)
										{
											disposable.Dispose();
										}
									}
									if (flag3 || str3.Length < str11.Length || Utils.Compare(str3, 0, str11.Length, str11, 0, str11.Length) == 0)
									{
										continue;
									}
									flag1 = true;
									arrayLists4.Add(searchResultPropertyValue2);
									num = num + num2;
								}
							}
							finally
							{
								searchResultCollections1.Dispose();
							}
						}
						while (flag1);
					}
				}
				catch (COMException cOMException7)
				{
					COMException cOMException6 = cOMException7;
					if (cOMException6.ErrorCode != -2147016656 || siteName == null)
					{
						throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException6);
					}
					else
					{
						arrayLists = arrayLists2;
						return arrayLists;
					}
				}
				foreach (string arrayList1 in arrayLists1)
				{
					string item3 = (string)hashtables[arrayList1];
					if (item3 != null)
					{
						if (!isADAM || hashtables1[arrayList1] != null)
						{
							if (!isADAM)
							{
								arrayLists2.Add(item3);
							}
							else
							{
								arrayLists2.Add(string.Concat(item3, ":", (object)((int)hashtables1[arrayList1])));
							}
						}
						else
						{
							msDSHasInstantiatedNCs = new object[1];
							msDSHasInstantiatedNCs[0] = arrayList1;
							throw new ActiveDirectoryOperationException(Res.GetString("NoHostNameOrPortNumber", msDSHasInstantiatedNCs));
						}
					}
					else
					{
						if (!isADAM)
						{
							msDSHasInstantiatedNCs = new object[1];
							msDSHasInstantiatedNCs[0] = arrayList1;
							throw new ActiveDirectoryOperationException(Res.GetString("NoHostName", msDSHasInstantiatedNCs));
						}
						else
						{
							msDSHasInstantiatedNCs = new object[1];
							msDSHasInstantiatedNCs[0] = arrayList1;
							throw new ActiveDirectoryOperationException(Res.GetString("NoHostNameOrPortNumber", msDSHasInstantiatedNCs));
						}
					}
				}
				return arrayLists2;
			}
			return arrayLists;
		}
Exemplo n.º 29
0
		internal static AdamInstance FindAnyAdamInstance(DirectoryContext context)
		{
			if (context.ContextType == DirectoryContextType.ConfigurationSet)
			{
				DirectoryEntry searchRootEntry = ConfigurationSet.GetSearchRootEntry(Forest.GetCurrentForest());
				ArrayList arrayLists = new ArrayList();
				try
				{
					try
					{
						StringBuilder stringBuilder = new StringBuilder(15);
						stringBuilder.Append("(&(");
						stringBuilder.Append(PropertyManager.ObjectCategory);
						stringBuilder.Append("=serviceConnectionPoint)");
						stringBuilder.Append("(");
						stringBuilder.Append(PropertyManager.Keywords);
						stringBuilder.Append("=1.2.840.113556.1.4.1851)(");
						stringBuilder.Append(PropertyManager.Keywords);
						stringBuilder.Append("=");
						stringBuilder.Append(Utils.GetEscapedFilterValue(context.Name));
						stringBuilder.Append("))");
						string str = stringBuilder.ToString();
						string[] serviceBindingInformation = new string[1];
						serviceBindingInformation[0] = PropertyManager.ServiceBindingInformation;
						ADSearcher aDSearcher = new ADSearcher(searchRootEntry, str, serviceBindingInformation, SearchScope.Subtree, false, false);
						SearchResultCollection searchResultCollections = aDSearcher.FindAll();
						try
						{
							foreach (SearchResult item in searchResultCollections)
							{
								string str1 = "ldap://";
								IEnumerator enumerator = item.Properties[PropertyManager.ServiceBindingInformation].GetEnumerator();
								try
								{
									while (enumerator.MoveNext())
									{
										string str2 = item.ToString ();
										if (str2.Length <= str1.Length || string.Compare(str2.Substring(0, str1.Length), str1, StringComparison.OrdinalIgnoreCase) != 0)
										{
											continue;
										}
										arrayLists.Add(str2.Substring(str1.Length));
									}
								}
								finally
								{
									IDisposable disposable = enumerator as IDisposable;
									if (disposable != null)
									{
										disposable.Dispose();
									}
								}
							}
						}
						finally
						{
							searchResultCollections.Dispose();
						}
					}
					catch (COMException cOMException1)
					{
						COMException cOMException = cOMException1;
						throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException);
					}
				}
				finally
				{
					searchRootEntry.Dispose();
				}
				return ConfigurationSet.FindAliveAdamInstance(null, context, arrayLists);
			}
			else
			{
				DirectoryEntryManager directoryEntryManager = new DirectoryEntryManager(context);
				DirectoryEntry cachedDirectoryEntry = directoryEntryManager.GetCachedDirectoryEntry(WellKnownDN.RootDSE);
				if (Utils.CheckCapability(cachedDirectoryEntry, Capability.ActiveDirectoryApplicationMode))
				{
					string propertyValue = (string)PropertyManager.GetPropertyValue(context, cachedDirectoryEntry, PropertyManager.DnsHostName);
					return new AdamInstance(context, propertyValue, directoryEntryManager);
				}
				else
				{
					directoryEntryManager.RemoveIfExists(directoryEntryManager.ExpandWellKnownDN(WellKnownDN.RootDSE));
					throw new ArgumentException(Res.GetString("TargetShouldBeServerORConfigSet"), "context");
				}
			}
		}
Exemplo n.º 30
0
        private void GetPreferredBridgeheadServers(ActiveDirectoryTransportType transport)
        {
            string serverContainerDN = "CN=Servers," + PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName);
            string transportDN = null;
            if (transport == ActiveDirectoryTransportType.Smtp)
                transportDN = "CN=SMTP,CN=Inter-Site Transports," + _siteDN;
            else
                transportDN = "CN=IP,CN=Inter-Site Transports," + _siteDN;

            DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, serverContainerDN);
            ADSearcher adSearcher = new ADSearcher(de,
                                                  "(&(objectClass=server)(objectCategory=Server)(bridgeheadTransportList=" + Utils.GetEscapedFilterValue(transportDN) + "))",
                                                  new string[] { "dNSHostName", "distinguishedName" },
                                                  SearchScope.OneLevel);
            SearchResultCollection results = null;

            try
            {
                results = adSearcher.FindAll();
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }

            try
            {
                DirectoryEntry ADAMEntry = null;
                foreach (SearchResult result in results)
                {
                    string hostName = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.DnsHostName);
                    DirectoryEntry resultEntry = result.GetDirectoryEntry();
                    DirectoryServer replica = null;

                    try
                    {
                        ADAMEntry = resultEntry.Children.Find("CN=NTDS Settings", "nTDSDSA");
                    }
                    catch (COMException e)
                    {
                        throw ExceptionHelper.GetExceptionFromCOMException(context, e);
                    }

                    if (IsADAM)
                    {
                        int port = (int)PropertyManager.GetPropertyValue(context, ADAMEntry, PropertyManager.MsDSPortLDAP);
                        string fullHostName = hostName;
                        if (port != 389)
                        {
                            fullHostName = hostName + ":" + port;
                        }
                        replica = new AdamInstance(Utils.GetNewDirectoryContext(fullHostName, DirectoryContextType.DirectoryServer, context), fullHostName);
                    }
                    else
                        replica = new DomainController(Utils.GetNewDirectoryContext(hostName, DirectoryContextType.DirectoryServer, context), hostName);

                    if (transport == ActiveDirectoryTransportType.Smtp)
                        _SMTPBridgeheadServers.Add(replica);
                    else
                        _RPCBridgeheadServers.Add(replica);
                }
            }
            finally
            {
                de.Dispose();
                results.Dispose();
            }
        }
Exemplo n.º 31
0
		private ArrayList GetApplicationPartitions()
		{
			ArrayList arrayLists = new ArrayList();
			DirectoryEntry cachedDirectoryEntry = this.directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE);
			DirectoryEntry directoryEntry = this.directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.PartitionsContainer);
			StringBuilder stringBuilder = new StringBuilder(100);
			stringBuilder.Append("(&(");
			stringBuilder.Append(PropertyManager.ObjectCategory);
			stringBuilder.Append("=crossRef)(");
			stringBuilder.Append(PropertyManager.SystemFlags);
			stringBuilder.Append(":1.2.840.113556.1.4.804:=");
			stringBuilder.Append(1);
			stringBuilder.Append(")(!(");
			stringBuilder.Append(PropertyManager.SystemFlags);
			stringBuilder.Append(":1.2.840.113556.1.4.803:=");
			stringBuilder.Append(2);
			stringBuilder.Append(")))");
			string str = stringBuilder.ToString();
			string[] nCName = new string[2];
			nCName[0] = PropertyManager.NCName;
			nCName[1] = PropertyManager.MsDSNCReplicaLocations;
			ADSearcher aDSearcher = new ADSearcher(directoryEntry, str, nCName, SearchScope.OneLevel);
			SearchResultCollection searchResultCollections = null;
			using (searchResultCollections)
			{
				try
				{
					searchResultCollections = aDSearcher.FindAll();
					string propertyValue = (string)PropertyManager.GetPropertyValue(this.context, cachedDirectoryEntry, PropertyManager.SchemaNamingContext);
					string propertyValue1 = (string)PropertyManager.GetPropertyValue(this.context, cachedDirectoryEntry, PropertyManager.ConfigurationNamingContext);
					foreach (SearchResult searchResult in searchResultCollections)
					{
						string searchResultPropertyValue = (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.NCName);
						if (searchResultPropertyValue.Equals(propertyValue) || searchResultPropertyValue.Equals(propertyValue1))
						{
							continue;
						}
						ResultPropertyValueCollection item = searchResult.Properties[PropertyManager.MsDSNCReplicaLocations];
						if (item.Count <= 0)
						{
							continue;
						}
						string adamDnsHostNameFromNTDSA = Utils.GetAdamDnsHostNameFromNTDSA(this.context, (string)item[Utils.GetRandomIndex(item.Count)]);
						DirectoryContext newDirectoryContext = Utils.GetNewDirectoryContext(adamDnsHostNameFromNTDSA, DirectoryContextType.DirectoryServer, this.context);
						arrayLists.Add(new ApplicationPartition(newDirectoryContext, searchResultPropertyValue, null, ApplicationPartitionType.ADAMApplicationPartition, new DirectoryEntryManager(newDirectoryContext)));
					}
				}
				catch (COMException cOMException1)
				{
					COMException cOMException = cOMException1;
					throw ExceptionHelper.GetExceptionFromCOMException(this.context, cOMException);
				}
			}
			return arrayLists;
		}
Exemplo n.º 32
0
 internal static AdamInstance FindAnyAdamInstance(DirectoryContext context)
 {
     if (context.ContextType == DirectoryContextType.ConfigurationSet)
     {
         DirectoryEntry searchRootEntry = ConfigurationSet.GetSearchRootEntry(Forest.GetCurrentForest());
         ArrayList      arrayLists      = new ArrayList();
         try
         {
             try
             {
                 StringBuilder stringBuilder = new StringBuilder(15);
                 stringBuilder.Append("(&(");
                 stringBuilder.Append(PropertyManager.ObjectCategory);
                 stringBuilder.Append("=serviceConnectionPoint)");
                 stringBuilder.Append("(");
                 stringBuilder.Append(PropertyManager.Keywords);
                 stringBuilder.Append("=1.2.840.113556.1.4.1851)(");
                 stringBuilder.Append(PropertyManager.Keywords);
                 stringBuilder.Append("=");
                 stringBuilder.Append(Utils.GetEscapedFilterValue(context.Name));
                 stringBuilder.Append("))");
                 string   str = stringBuilder.ToString();
                 string[] serviceBindingInformation = new string[1];
                 serviceBindingInformation[0] = PropertyManager.ServiceBindingInformation;
                 ADSearcher             aDSearcher = new ADSearcher(searchRootEntry, str, serviceBindingInformation, SearchScope.Subtree, false, false);
                 SearchResultCollection searchResultCollections = aDSearcher.FindAll();
                 try
                 {
                     foreach (SearchResult item in searchResultCollections)
                     {
                         string      str1       = "ldap://";
                         IEnumerator enumerator = item.Properties[PropertyManager.ServiceBindingInformation].GetEnumerator();
                         try
                         {
                             while (enumerator.MoveNext())
                             {
                                 string str2 = item.ToString();
                                 if (str2.Length <= str1.Length || string.Compare(str2.Substring(0, str1.Length), str1, StringComparison.OrdinalIgnoreCase) != 0)
                                 {
                                     continue;
                                 }
                                 arrayLists.Add(str2.Substring(str1.Length));
                             }
                         }
                         finally
                         {
                             IDisposable disposable = enumerator as IDisposable;
                             if (disposable != null)
                             {
                                 disposable.Dispose();
                             }
                         }
                     }
                 }
                 finally
                 {
                     searchResultCollections.Dispose();
                 }
             }
             catch (COMException cOMException1)
             {
                 COMException cOMException = cOMException1;
                 throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException);
             }
         }
         finally
         {
             searchRootEntry.Dispose();
         }
         return(ConfigurationSet.FindAliveAdamInstance(null, context, arrayLists));
     }
     else
     {
         DirectoryEntryManager directoryEntryManager = new DirectoryEntryManager(context);
         DirectoryEntry        cachedDirectoryEntry  = directoryEntryManager.GetCachedDirectoryEntry(WellKnownDN.RootDSE);
         if (Utils.CheckCapability(cachedDirectoryEntry, Capability.ActiveDirectoryApplicationMode))
         {
             string propertyValue = (string)PropertyManager.GetPropertyValue(context, cachedDirectoryEntry, PropertyManager.DnsHostName);
             return(new AdamInstance(context, propertyValue, directoryEntryManager));
         }
         else
         {
             directoryEntryManager.RemoveIfExists(directoryEntryManager.ExpandWellKnownDN(WellKnownDN.RootDSE));
             throw new ArgumentException(Res.GetString("TargetShouldBeServerORConfigSet"), "context");
         }
     }
 }
Exemplo n.º 33
0
        private void GetServers()
        {
            ADSearcher adSearcher = new ADSearcher(cachedEntry,
                                                  "(&(objectClass=server)(objectCategory=server))",
                                                  new string[] { "dNSHostName" },
                                                  SearchScope.Subtree);
            SearchResultCollection results = null;
            try
            {
                results = adSearcher.FindAll();
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }

            try
            {
                foreach (SearchResult result in results)
                {
                    string hostName = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.DnsHostName);
                    DirectoryEntry de = result.GetDirectoryEntry();
                    DirectoryEntry child = null;
                    DirectoryServer replica = null;
                    // make sure that the server is not demoted
                    try
                    {
                        child = de.Children.Find("CN=NTDS Settings", "nTDSDSA");
                    }
                    catch (COMException e)
                    {
                        if (e.ErrorCode == unchecked((int)0x80072030))
                        {
                            continue;
                        }
                        else
                            throw ExceptionHelper.GetExceptionFromCOMException(context, e);
                    }
                    if (IsADAM)
                    {
                        int port = (int)PropertyManager.GetPropertyValue(context, child, PropertyManager.MsDSPortLDAP);
                        string fullHostName = hostName;
                        if (port != 389)
                        {
                            fullHostName = hostName + ":" + port;
                        }
                        replica = new AdamInstance(Utils.GetNewDirectoryContext(fullHostName, DirectoryContextType.DirectoryServer, context), fullHostName);
                    }
                    else
                        replica = new DomainController(Utils.GetNewDirectoryContext(hostName, DirectoryContextType.DirectoryServer, context), hostName);

                    _servers.Add(replica);
                }
            }
            finally
            {
                results.Dispose();
            }
        }
Exemplo n.º 34
0
        internal static ReadOnlyActiveDirectorySchemaClassCollection GetAllClasses(DirectoryContext context, DirectoryEntry schemaEntry, string filter)
        {
            ArrayList classList = new ArrayList();

            string[] propertiesToLoad = new string[3];
            propertiesToLoad[0] = PropertyManager.LdapDisplayName;
            propertiesToLoad[1] = PropertyManager.Cn;
            propertiesToLoad[2] = PropertyManager.IsDefunct;

            ADSearcher searcher = new ADSearcher(schemaEntry, filter, propertiesToLoad, SearchScope.OneLevel);
            SearchResultCollection resCol = null;
            try
            {
                resCol = searcher.FindAll();
                foreach (SearchResult res in resCol)
                {
                    string ldapDisplayName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.LdapDisplayName);
                    DirectoryEntry directoryEntry = res.GetDirectoryEntry();

                    directoryEntry.AuthenticationType = Utils.DefaultAuthType;
                    directoryEntry.Username = context.UserName;
                    directoryEntry.Password = context.Password;

                    bool isDefunct = false;

                    if ((res.Properties[PropertyManager.IsDefunct] != null) && (res.Properties[PropertyManager.IsDefunct].Count > 0))
                    {
                        isDefunct = (bool)res.Properties[PropertyManager.IsDefunct][0];
                    }

                    if (isDefunct)
                    {
                        string commonName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.Cn);
                        classList.Add(new ActiveDirectorySchemaClass(context, commonName, ldapDisplayName, directoryEntry, schemaEntry));
                    }
                    else
                    {
                        classList.Add(new ActiveDirectorySchemaClass(context, ldapDisplayName, directoryEntry, schemaEntry));
                    }
                }
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            finally
            {
                // dispose off the result collection
                if (resCol != null)
                {
                    resCol.Dispose();
                }
            }

            return new ReadOnlyActiveDirectorySchemaClassCollection(classList);
        }
Exemplo n.º 35
0
		private void GetServers()
		{
			DirectoryServer domainController;
			string[] strArrays = new string[1];
			strArrays[0] = "dNSHostName";
			ADSearcher aDSearcher = new ADSearcher(this.cachedEntry, "(&(objectClass=server)(objectCategory=server))", strArrays, SearchScope.Subtree);
			SearchResultCollection searchResultCollections = null;
			try
			{
				searchResultCollections = aDSearcher.FindAll();
			}
			catch (COMException cOMException1)
			{
				COMException cOMException = cOMException1;
				throw ExceptionHelper.GetExceptionFromCOMException(this.context, cOMException);
			}
			try
			{
				foreach (SearchResult searchResult in searchResultCollections)
				{
					string searchResultPropertyValue = (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.DnsHostName);
					DirectoryEntry directoryEntry = searchResult.GetDirectoryEntry();
					DirectoryEntry directoryEntry1 = null;
					try
					{
						directoryEntry1 = directoryEntry.Children.Find("CN=NTDS Settings", "nTDSDSA");
					}
					catch (COMException cOMException3)
					{
						COMException cOMException2 = cOMException3;
						if (cOMException2.ErrorCode != -2147016656)
						{
							throw ExceptionHelper.GetExceptionFromCOMException(this.context, cOMException2);
						}
						else
						{
							continue;
						}
					}
					if (!this.IsADAM)
					{
						domainController = new DomainController(Utils.GetNewDirectoryContext(searchResultPropertyValue, DirectoryContextType.DirectoryServer, this.context), searchResultPropertyValue);
					}
					else
					{
						int propertyValue = (int)PropertyManager.GetPropertyValue(this.context, directoryEntry1, PropertyManager.MsDSPortLDAP);
						string str = searchResultPropertyValue;
						if (propertyValue != 0x185)
						{
							str = string.Concat(searchResultPropertyValue, ":", propertyValue);
						}
						domainController = new AdamInstance(Utils.GetNewDirectoryContext(str, DirectoryContextType.DirectoryServer, this.context), str);
					}
					this.servers.Add(domainController);
				}
			}
			finally
			{
				searchResultCollections.Dispose();
			}
		}
Exemplo n.º 36
0
		private ArrayList GetDomains()
		{
			ArrayList arrayLists = new ArrayList();
			var dn = this.directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.PartitionsContainer);
			DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, dn);
			StringBuilder stringBuilder = new StringBuilder(15);
			stringBuilder.Append("(&(");
			stringBuilder.Append(PropertyManager.ObjectCategory);
			stringBuilder.Append("=crossRef)(");
			stringBuilder.Append(PropertyManager.SystemFlags);
			stringBuilder.Append(":1.2.840.113556.1.4.804:=");
			stringBuilder.Append(1);
			stringBuilder.Append(")(");
			stringBuilder.Append(PropertyManager.SystemFlags);
			stringBuilder.Append(":1.2.840.113556.1.4.804:=");
			stringBuilder.Append(2);
			stringBuilder.Append("))");
			string str = stringBuilder.ToString();
			string[] dnsRoot = new string[1];
			dnsRoot[0] = PropertyManager.DnsRoot;
			ADSearcher aDSearcher = new ADSearcher(directoryEntry, str, dnsRoot, SearchScope.OneLevel);
			SearchResultCollection searchResultCollections = null;
			try
			{
				try
				{
					searchResultCollections = aDSearcher.FindAll();
					foreach (SearchResult searchResult in searchResultCollections)
					{
						string searchResultPropertyValue = (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.DnsRoot);
						DirectoryContext newDirectoryContext = Utils.GetNewDirectoryContext(searchResultPropertyValue, DirectoryContextType.Domain, this.context);
						arrayLists.Add(new Domain(newDirectoryContext, searchResultPropertyValue));
					}
				}
				catch (COMException cOMException1)
				{
					COMException cOMException = cOMException1;
					throw ExceptionHelper.GetExceptionFromCOMException(this.context, cOMException);
				}
			}
			finally
			{
				if (searchResultCollections != null)
				{
					searchResultCollections.Dispose();
				}
				directoryEntry.Dispose();
			}
			return arrayLists;
		}
Exemplo n.º 37
0
		private void GetAdjacentSites()
		{
			ActiveDirectoryTransportType activeDirectoryTransportType;
			DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, WellKnownDN.RootDSE);
			string item = (string)directoryEntry.Properties["configurationNamingContext"][0];
			string str = string.Concat("CN=Inter-Site Transports,CN=Sites,", item);
			directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, str);
			string[] strArrays = new string[2];
			strArrays[0] = "cn";
			strArrays[1] = "distinguishedName";
			ADSearcher aDSearcher = new ADSearcher(directoryEntry, string.Concat("(&(objectClass=siteLink)(objectCategory=SiteLink)(siteList=", Utils.GetEscapedFilterValue((string)PropertyManager.GetPropertyValue(this.context, this.cachedEntry, PropertyManager.DistinguishedName)), "))"), strArrays, SearchScope.Subtree);
			SearchResultCollection searchResultCollections = null;
			try
			{
				searchResultCollections = aDSearcher.FindAll();
			}
			catch (COMException cOMException1)
			{
				COMException cOMException = cOMException1;
				throw ExceptionHelper.GetExceptionFromCOMException(this.context, cOMException);
			}
			try
			{
				ActiveDirectorySiteLink activeDirectorySiteLink = null;
				foreach (SearchResult searchResult in searchResultCollections)
				{
					string searchResultPropertyValue = (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.DistinguishedName);
					string searchResultPropertyValue1 = (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.Cn);
					string value = Utils.GetDNComponents(searchResultPropertyValue)[1].Value;
					if (string.Compare(value, "IP", StringComparison.OrdinalIgnoreCase) != 0)
					{
						if (string.Compare(value, "SMTP", StringComparison.OrdinalIgnoreCase) != 0)
						{
							object[] objArray = new object[1];
							objArray[0] = value;
							string str1 = Res.GetString("UnknownTransport", objArray);
							throw new ActiveDirectoryOperationException(str1);
						}
						else
						{
							activeDirectoryTransportType = ActiveDirectoryTransportType.Smtp;
						}
					}
					else
					{
						activeDirectoryTransportType = ActiveDirectoryTransportType.Rpc;
					}
					try
					{
						activeDirectorySiteLink = new ActiveDirectorySiteLink(this.context, searchResultPropertyValue1, activeDirectoryTransportType, true, searchResult.GetDirectoryEntry());
						foreach (ActiveDirectorySite site in activeDirectorySiteLink.Sites)
						{
							if (Utils.Compare(site.Name, this.Name) == 0 || this.adjacentSites.Contains(site))
							{
								continue;
							}
							this.adjacentSites.Add(site);
						}
					}
					finally
					{
						activeDirectorySiteLink.Dispose();
					}
				}
			}
			finally
			{
				searchResultCollections.Dispose();
				directoryEntry.Dispose();
			}
		}
Exemplo n.º 38
0
        //
        // This method searches in the schema container for all non-defunct properties of the 
        // specified name (ldapDisplayName).
        //
        private ArrayList GetProperties(ICollection ldapDisplayNames)
        {
            ArrayList properties = new ArrayList();
            SearchResultCollection resCol = null;

            try
            {
                if (ldapDisplayNames.Count < 1)
                {
                    return properties;
                }

                if (_schemaEntry == null)
                {
                    _schemaEntry = DirectoryEntryManager.GetDirectoryEntry(_context, WellKnownDN.SchemaNamingContext);
                }

                // constructing the filter
                StringBuilder str = new StringBuilder(100);

                if (ldapDisplayNames.Count > 1)
                {
                    str.Append("(|");
                }
                foreach (string ldapDisplayName in ldapDisplayNames)
                {
                    str.Append("(");
                    str.Append(PropertyManager.LdapDisplayName);
                    str.Append("=");
                    str.Append(Utils.GetEscapedFilterValue(ldapDisplayName));
                    str.Append(")");
                }
                if (ldapDisplayNames.Count > 1)
                {
                    str.Append(")");
                }

                string filter = "(&(" + PropertyManager.ObjectCategory + "=attributeSchema)" + str.ToString() + "(!(" + PropertyManager.IsDefunct + "=TRUE)))";

                string[] propertiesToLoad = new String[1];
                propertiesToLoad[0] = PropertyManager.LdapDisplayName;

                ADSearcher searcher = new ADSearcher(_schemaEntry, filter, propertiesToLoad, SearchScope.OneLevel);
                resCol = searcher.FindAll();

                foreach (SearchResult res in resCol)
                {
                    string ldapDisplayName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.LdapDisplayName);
                    DirectoryEntry de = res.GetDirectoryEntry();

                    de.AuthenticationType = Utils.DefaultAuthType;
                    de.Username = _context.UserName;
                    de.Password = _context.Password;

                    ActiveDirectorySchemaProperty schemaProperty = new ActiveDirectorySchemaProperty(_context, ldapDisplayName, de, _schemaEntry);

                    properties.Add(schemaProperty);
                }
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(_context, e);
            }
            finally
            {
                if (resCol != null)
                {
                    resCol.Dispose();
                }
            }

            return properties;
        }
Exemplo n.º 39
0
        internal static AdamInstance FindAnyAdamInstance(DirectoryContext context)
        {
            if (context.ContextType != DirectoryContextType.ConfigurationSet)
            {
                // assuming it's an ADAM Instance
                // check that it is an ADAM server only (not AD)
                DirectoryEntryManager directoryEntryMgr = new DirectoryEntryManager(context);
                DirectoryEntry        rootDSE           = directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE);

                if (!Utils.CheckCapability(rootDSE, Capability.ActiveDirectoryApplicationMode))
                {
                    directoryEntryMgr.RemoveIfExists(directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.RootDSE));
                    throw new ArgumentException(SR.TargetShouldBeServerORConfigSet, nameof(context));
                }

                string dnsHostName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DnsHostName);

                return(new AdamInstance(context, dnsHostName, directoryEntryMgr));
            }

            // Now this is the case where context is a Config Set
            // Here we need to search for the service connection points in the forest
            // (if the forest object was created by specifying the server, we stick to that, else search in a GC)
            DirectoryEntry rootEntry         = GetSearchRootEntry(Forest.GetCurrentForest());
            ArrayList      adamInstanceNames = new ArrayList();

            try
            {
                string entryName = (string)rootEntry.Properties["distinguishedName"].Value;

                // Search for computer "serviceConnectionObjects" where the keywords attribute
                // contains the specified keyword
                // set up the searcher object

                // build the filter
                StringBuilder str = new StringBuilder(15);
                str.Append("(&(");
                str.Append(PropertyManager.ObjectCategory);
                str.Append("=serviceConnectionPoint)");
                str.Append("(");
                str.Append(PropertyManager.Keywords);
                str.Append("=1.2.840.113556.1.4.1851)(");
                str.Append(PropertyManager.Keywords);
                str.Append("=");
                str.Append(Utils.GetEscapedFilterValue(context.Name)); // target = config set name
                str.Append("))");

                string   filter           = str.ToString();
                string[] propertiesToLoad = new string[1];

                propertiesToLoad[0] = PropertyManager.ServiceBindingInformation;

                ADSearcher             searcher = new ADSearcher(rootEntry, filter, propertiesToLoad, SearchScope.Subtree, false /*not paged search*/, false /*no cached results*/);
                SearchResultCollection resCol   = searcher.FindAll();

                try
                {
                    foreach (SearchResult res in resCol)
                    {
                        // the binding info contains two values
                        // "ldap://hostname:ldapport"
                        // and "ldaps://hostname:sslport"
                        // we need the "hostname:ldapport" value
                        string prefix = "ldap://";

                        foreach (string bindingInfo in res.Properties[PropertyManager.ServiceBindingInformation])
                        {
                            if ((bindingInfo.Length > prefix.Length) && (string.Equals(bindingInfo.Substring(0, prefix.Length), prefix, StringComparison.OrdinalIgnoreCase)))
                            {
                                adamInstanceNames.Add(bindingInfo.Substring(prefix.Length));
                            }
                        }
                    }
                }
                finally
                {
                    resCol.Dispose();
                }
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            finally
            {
                rootEntry.Dispose();
            }

            //
            // we have all the adam instance names in teh form of server:port from the scp
            // now we need to find one that is alive
            //
            return(FindAliveAdamInstance(null, context, adamInstanceNames));
        }
Exemplo n.º 40
0
        private void GetLinks()
        {
            DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
            string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext);
            string transportContainer = "CN=Inter-Site Transports,CN=Sites," + config;
            de = DirectoryEntryManager.GetDirectoryEntry(context, transportContainer);
            ADSearcher adSearcher = new ADSearcher(de,
                                                  "(&(objectClass=siteLink)(objectCategory=SiteLink)(siteList=" + Utils.GetEscapedFilterValue((string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName)) + "))",
                                                  new string[] { "cn", "distinguishedName" },
                                                  SearchScope.Subtree);
            SearchResultCollection results = null;

            try
            {
                results = adSearcher.FindAll();
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }

            try
            {
                foreach (SearchResult result in results)
                {
                    // construct the sitelinks at the same time
                    DirectoryEntry connectionEntry = result.GetDirectoryEntry();
                    string cn = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.Cn);
                    string transport = Utils.GetDNComponents((string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.DistinguishedName))[1].Value;
                    ActiveDirectorySiteLink link = null;
                    if (String.Compare(transport, "IP", StringComparison.OrdinalIgnoreCase) == 0)
                        link = new ActiveDirectorySiteLink(context, cn, ActiveDirectoryTransportType.Rpc, true, connectionEntry);
                    else if (String.Compare(transport, "SMTP", StringComparison.OrdinalIgnoreCase) == 0)
                        link = new ActiveDirectorySiteLink(context, cn, ActiveDirectoryTransportType.Smtp, true, connectionEntry);
                    else
                    {
                        // should not happen
                        string message = Res.GetString(Res.UnknownTransport, transport);
                        throw new ActiveDirectoryOperationException(message);
                    }

                    _links.Add(link);
                }
            }
            finally
            {
                results.Dispose();
                de.Dispose();
            }
        }
Exemplo n.º 41
0
        private ArrayList GetApplicationPartitions()
        {
            ArrayList      appNCs          = new ArrayList();
            DirectoryEntry rootDSE         = _directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE);
            DirectoryEntry partitionsEntry = _directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.PartitionsContainer);

            // search for all the "crossRef" objects that have the
            // ADS_SYSTEMFLAG_CR_NTDS_NC set and the SYSTEMFLAG_CR_NTDS_DOMAIN flag not set
            // (one-level search is good enough)
            // setup the directory searcher object

            // build the filter
            StringBuilder str = new StringBuilder(100);

            str.Append("(&(");
            str.Append(PropertyManager.ObjectCategory);
            str.Append("=crossRef)(");
            str.Append(PropertyManager.SystemFlags);
            str.Append(":1.2.840.113556.1.4.804:=");
            str.Append((int)SystemFlag.SystemFlagNtdsNC);
            str.Append(")(!(");
            str.Append(PropertyManager.SystemFlags);
            str.Append(":1.2.840.113556.1.4.803:=");
            str.Append((int)SystemFlag.SystemFlagNtdsDomain);
            str.Append(")))");

            string filter = str.ToString();

            string[] propertiesToLoad = new string[2];
            propertiesToLoad[0] = PropertyManager.NCName;
            propertiesToLoad[1] = PropertyManager.MsDSNCReplicaLocations;

            ADSearcher             searcher = new ADSearcher(partitionsEntry, filter, propertiesToLoad, SearchScope.OneLevel);
            SearchResultCollection resCol   = null;

            try
            {
                resCol = searcher.FindAll();

                string schemaNamingContext        = (string)PropertyManager.GetPropertyValue(_context, rootDSE, PropertyManager.SchemaNamingContext);
                string configurationNamingContext = (string)PropertyManager.GetPropertyValue(_context, rootDSE, PropertyManager.ConfigurationNamingContext);

                foreach (SearchResult res in resCol)
                {
                    // add the name of the appNC only if it is not
                    // the Schema or Configuration partition
                    string nCName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.NCName);

                    if ((!(nCName.Equals(schemaNamingContext))) && (!(nCName.Equals(configurationNamingContext))))
                    {
                        ResultPropertyValueCollection replicaLocations = res.Properties[PropertyManager.MsDSNCReplicaLocations];
                        if (replicaLocations.Count > 0)
                        {
                            string           replicaName  = Utils.GetAdamDnsHostNameFromNTDSA(_context, (string)replicaLocations[Utils.GetRandomIndex(replicaLocations.Count)]);
                            DirectoryContext appNCContext = Utils.GetNewDirectoryContext(replicaName, DirectoryContextType.DirectoryServer, _context);
                            appNCs.Add(new ApplicationPartition(appNCContext, nCName, null, ApplicationPartitionType.ADAMApplicationPartition, new DirectoryEntryManager(appNCContext)));
                        }
                    }
                }
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(_context, e);
            }
            finally
            {
                if (resCol != null)
                {
                    // call dispose on search result collection
                    resCol.Dispose();
                }
            }
            return(appNCs);
        }
Exemplo n.º 42
0
        private ArrayList GetChildDomains()
        {
            ArrayList childDomains = new ArrayList();

            if (_crossRefDN == null)
            {
                LoadCrossRefAttributes();
            }

            DirectoryEntry partitionsEntry = null;
            SearchResultCollection resCol = null;
            try
            {
                partitionsEntry = DirectoryEntryManager.GetDirectoryEntry(context, directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.PartitionsContainer));
                // search for all the "crossRef" objects that have the 
                // ADS_SYSTEMFLAG_CR_NTDS_NC and SYSTEMFLAG_CR_NTDS_DOMAIN flags set
                // (one-level search is good enough)

                // setup the directory searcher object

                // build the filter
                StringBuilder str = new StringBuilder(15);
                str.Append("(&(");
                str.Append(PropertyManager.ObjectCategory);
                str.Append("=crossRef)(");
                str.Append(PropertyManager.SystemFlags);
                str.Append(":1.2.840.113556.1.4.804:=");
                str.Append((int)SystemFlag.SystemFlagNtdsNC);
                str.Append(")(");
                str.Append(PropertyManager.SystemFlags);
                str.Append(":1.2.840.113556.1.4.804:=");
                str.Append((int)SystemFlag.SystemFlagNtdsDomain);
                str.Append(")(");
                str.Append(PropertyManager.TrustParent);
                str.Append("=");
                str.Append(Utils.GetEscapedFilterValue(_crossRefDN));
                str.Append("))");

                string filter = str.ToString();
                string[] propertiesToLoad = new string[1];
                propertiesToLoad[0] = PropertyManager.DnsRoot;

                ADSearcher searcher = new ADSearcher(partitionsEntry, filter, propertiesToLoad, SearchScope.OneLevel);
                resCol = searcher.FindAll();

                foreach (SearchResult res in resCol)
                {
                    string childDomainName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DnsRoot);
                    DirectoryContext childContext = Utils.GetNewDirectoryContext(childDomainName, DirectoryContextType.Domain, context);
                    childDomains.Add(new Domain(childContext, childDomainName));
                }
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            finally
            {
                if (resCol != null)
                {
                    resCol.Dispose();
                }
                if (partitionsEntry != null)
                {
                    partitionsEntry.Dispose();
                }
            }
            return childDomains;
        }
 private ArrayList GetDomains()
 {
     ArrayList list = new ArrayList();
     DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, this.directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.PartitionsContainer));
     StringBuilder builder = new StringBuilder(15);
     builder.Append("(&(");
     builder.Append(PropertyManager.ObjectCategory);
     builder.Append("=crossRef)(");
     builder.Append(PropertyManager.SystemFlags);
     builder.Append(":1.2.840.113556.1.4.804:=");
     builder.Append(1);
     builder.Append(")(");
     builder.Append(PropertyManager.SystemFlags);
     builder.Append(":1.2.840.113556.1.4.804:=");
     builder.Append(2);
     builder.Append("))");
     string filter = builder.ToString();
     string[] propertiesToLoad = new string[] { PropertyManager.DnsRoot };
     ADSearcher searcher = new ADSearcher(directoryEntry, filter, propertiesToLoad, SearchScope.OneLevel);
     SearchResultCollection results = null;
     try
     {
         results = searcher.FindAll();
         foreach (SearchResult result in results)
         {
             string searchResultPropertyValue = (string) PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.DnsRoot);
             DirectoryContext context = Utils.GetNewDirectoryContext(searchResultPropertyValue, DirectoryContextType.Domain, this.context);
             list.Add(new Domain(context, searchResultPropertyValue));
         }
         return list;
     }
     catch (COMException exception)
     {
         throw ExceptionHelper.GetExceptionFromCOMException(this.context, exception);
     }
     finally
     {
         if (results != null)
         {
             results.Dispose();
         }
         directoryEntry.Dispose();
     }
     return list;
 }
Exemplo n.º 44
0
		internal static string GetAdamHostNameAndPortsFromNTDSA(DirectoryContext context, string dn)
		{
			string searchResultPropertyValue = null;
			int num = -1;
			int searchResultPropertyValue1 = -1;
			string str = dn;
			string partialDN = Utils.GetPartialDN(dn, 1);
			string partialDN1 = Utils.GetPartialDN(dn, 2);
			string str1 = "CN=NTDS-DSA";
			DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, partialDN1);
			string[] objectCategory = new string[13];
			objectCategory[0] = "(|(&(";
			objectCategory[1] = PropertyManager.ObjectCategory;
			objectCategory[2] = "=server)(";
			objectCategory[3] = PropertyManager.DistinguishedName;
			objectCategory[4] = "=";
			objectCategory[5] = Utils.GetEscapedFilterValue(partialDN);
			objectCategory[6] = "))(&(";
			objectCategory[7] = PropertyManager.ObjectCategory;
			objectCategory[8] = "=nTDSDSA)(";
			objectCategory[9] = PropertyManager.DistinguishedName;
			objectCategory[10] = "=";
			objectCategory[11] = Utils.GetEscapedFilterValue(str);
			objectCategory[12] = ")))";
			string str2 = string.Concat(objectCategory);
			string[] dnsHostName = new string[4];
			dnsHostName[0] = PropertyManager.DnsHostName;
			dnsHostName[1] = PropertyManager.MsDSPortLDAP;
			dnsHostName[2] = PropertyManager.MsDSPortSSL;
			dnsHostName[3] = PropertyManager.ObjectCategory;
			ADSearcher aDSearcher = new ADSearcher(directoryEntry, str2, dnsHostName, SearchScope.Subtree, true, true);
			SearchResultCollection searchResultCollections = aDSearcher.FindAll();
			try
			{
				if (searchResultCollections.Count == 2)
				{
					foreach (SearchResult searchResult in searchResultCollections)
					{
						string searchResultPropertyValue2 = (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.ObjectCategory);
						if (searchResultPropertyValue2.Length < str1.Length || Utils.Compare(searchResultPropertyValue2, 0, str1.Length, str1, 0, str1.Length) != 0)
						{
							searchResultPropertyValue = (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.DnsHostName);
						}
						else
						{
							num = (int)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.MsDSPortLDAP);
							searchResultPropertyValue1 = (int)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.MsDSPortSSL);
						}
					}
				}
				else
				{
					object[] objArray = new object[1];
					objArray[0] = dn;
					throw new ActiveDirectoryOperationException(Res.GetString("NoHostNameOrPortNumber", objArray));
				}
			}
			finally
			{
				searchResultCollections.Dispose();
				directoryEntry.Dispose();
			}
			if (num == -1 || searchResultPropertyValue1 == -1 || searchResultPropertyValue == null)
			{
				object[] objArray1 = new object[1];
				objArray1[0] = dn;
				throw new ActiveDirectoryOperationException(Res.GetString("NoHostNameOrPortNumber", objArray1));
			}
			else
			{
				object[] objArray2 = new object[5];
				objArray2[0] = searchResultPropertyValue;
				objArray2[1] = ":";
				objArray2[2] = num;
				objArray2[3] = ":";
				objArray2[4] = searchResultPropertyValue1;
				return string.Concat(objArray2);
			}
		}
Exemplo n.º 45
0
		private ArrayList GetSites ()
		{
			ArrayList arrayLists = new ArrayList ();



			try {
				DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry (this.context, this.directoryEntryMgr.ExpandWellKnownDN (WellKnownDN.SitesContainer));
				
				ADSearcher aDSearcher = new ADSearcher (directoryEntry, "(&(objectClass=site))", new string[] { "cn" }, SearchScope.OneLevel);
				SearchResultCollection searchResultCollections = null;
				searchResultCollections = aDSearcher.FindAll ();
				foreach(SearchResult result in searchResultCollections)
				{
					var entry = result.GetDirectoryEntry ();
					var site = new System.DirectoryServices.ActiveDirectory.ActiveDirectorySite(this.context, (string)entry.Properties["cn"].Value, true);
					arrayLists.Add (site);
				}
			} catch (Exception ex) 
			{
				var msg = ex.Message;
			}


			/*
			IntPtr zero = IntPtr.Zero;
			IntPtr intPtr = IntPtr.Zero;
			IntPtr zero1 = IntPtr.Zero;
			try
			{
				this.GetDSHandle(out zero, out intPtr);
				IntPtr procAddress = UnsafeNativeMethods.GetProcAddress(DirectoryContext.ADHandle, "DsListSitesW");
				if (procAddress != (IntPtr)0)
				{
					NativeMethods.DsListSites delegateForFunctionPointer = (NativeMethods.DsListSites)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(NativeMethods.DsListSites));
					int num = delegateForFunctionPointer(zero, out zero1);
					if (num != 0)
					{
						throw ExceptionHelper.GetExceptionFromErrorCode(num, this.context.GetServerName());
					}
					else
					{
						try
						{
							DsNameResult dsNameResult = new DsNameResult();
							Marshal.PtrToStructure(zero1, dsNameResult);
							IntPtr intPtr1 = dsNameResult.items;
							for (int i = 0; i < dsNameResult.itemCount; i++)
							{
								DsNameResultItem dsNameResultItem = new DsNameResultItem();
								Marshal.PtrToStructure(intPtr1, dsNameResultItem);
								if (dsNameResultItem.status == 0)
								{
									string value = Utils.GetDNComponents(dsNameResultItem.name)[0].Value;
									arrayLists.Add(new ActiveDirectorySite(this.context, value, true));
								}
								intPtr1 = (IntPtr)((long)intPtr1 + (long)Marshal.SizeOf(dsNameResultItem));
							}
						}
						finally
						{
							if (zero1 != IntPtr.Zero)
							{
								procAddress = UnsafeNativeMethods.GetProcAddress(DirectoryContext.ADHandle, "DsFreeNameResultW");
								if (procAddress != (IntPtr)0)
								{
									UnsafeNativeMethods.DsFreeNameResultW dsFreeNameResultW = (UnsafeNativeMethods.DsFreeNameResultW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(UnsafeNativeMethods.DsFreeNameResultW));
									dsFreeNameResultW(zero1);
								}
								else
								{
									throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
								}
							}
						}
					}
				}
				else
				{
					throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
				}
			}
			finally
			{
				if (zero != (IntPtr)0)
				{
					Utils.FreeDSHandle(zero, DirectoryContext.ADHandle);
				}
				if (intPtr != (IntPtr)0)
				{
					Utils.FreeAuthIdentity(intPtr, DirectoryContext.ADHandle);
				}
			}
			*/
			return arrayLists;
		}
Exemplo n.º 46
0
        private ArrayList GetApplicationPartitions()
        {
            ArrayList appNCs = new ArrayList();
            DirectoryEntry rootDSE = _directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE);
            DirectoryEntry partitionsEntry = _directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.PartitionsContainer);

            // search for all the "crossRef" objects that have the 
            // ADS_SYSTEMFLAG_CR_NTDS_NC set and the SYSTEMFLAG_CR_NTDS_DOMAIN flag not set
            // (one-level search is good enough)
            // setup the directory searcher object

            // build the filter
            StringBuilder str = new StringBuilder(100);
            str.Append("(&(");
            str.Append(PropertyManager.ObjectCategory);
            str.Append("=crossRef)(");
            str.Append(PropertyManager.SystemFlags);
            str.Append(":1.2.840.113556.1.4.804:=");
            str.Append((int)SystemFlag.SystemFlagNtdsNC);
            str.Append(")(!(");
            str.Append(PropertyManager.SystemFlags);
            str.Append(":1.2.840.113556.1.4.803:=");
            str.Append((int)SystemFlag.SystemFlagNtdsDomain);
            str.Append(")))");

            string filter = str.ToString();
            string[] propertiesToLoad = new string[2];
            propertiesToLoad[0] = PropertyManager.NCName;
            propertiesToLoad[1] = PropertyManager.MsDSNCReplicaLocations;

            ADSearcher searcher = new ADSearcher(partitionsEntry, filter, propertiesToLoad, SearchScope.OneLevel);
            SearchResultCollection resCol = null;

            try
            {
                resCol = searcher.FindAll();

                string schemaNamingContext = (string)PropertyManager.GetPropertyValue(_context, rootDSE, PropertyManager.SchemaNamingContext);
                string configurationNamingContext = (string)PropertyManager.GetPropertyValue(_context, rootDSE, PropertyManager.ConfigurationNamingContext);

                foreach (SearchResult res in resCol)
                {
                    // add the name of the appNC only if it is not 
                    // the Schema or Configuration partition
                    string nCName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.NCName);

                    if ((!(nCName.Equals(schemaNamingContext))) && (!(nCName.Equals(configurationNamingContext))))
                    {
                        ResultPropertyValueCollection replicaLocations = res.Properties[PropertyManager.MsDSNCReplicaLocations];
                        if (replicaLocations.Count > 0)
                        {
                            string replicaName = Utils.GetAdamDnsHostNameFromNTDSA(_context, (string)replicaLocations[Utils.GetRandomIndex(replicaLocations.Count)]);
                            DirectoryContext appNCContext = Utils.GetNewDirectoryContext(replicaName, DirectoryContextType.DirectoryServer, _context);
                            appNCs.Add(new ApplicationPartition(appNCContext, nCName, null, ApplicationPartitionType.ADAMApplicationPartition, new DirectoryEntryManager(appNCContext)));
                        }
                    }
                }
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(_context, e);
            }
            finally
            {
                if (resCol != null)
                {
                    // call dispose on search result collection
                    resCol.Dispose();
                }
            }
            return appNCs;
        }
Exemplo n.º 47
0
        private ArrayList GetSites()
        {
            ArrayList sites = new ArrayList();
            DirectoryEntry sitesEntry = _directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.SitesContainer);

            // search for all the "site" objects 
            // (one-level search is good enough)
            // setup the directory searcher object
            string filter = "(" + PropertyManager.ObjectCategory + "=site)";
            string[] propertiesToLoad = new string[1];

            propertiesToLoad[0] = PropertyManager.Cn;

            ADSearcher searcher = new ADSearcher(sitesEntry, filter, propertiesToLoad, SearchScope.OneLevel);
            SearchResultCollection resCol = null;

            try
            {
                resCol = searcher.FindAll();

                foreach (SearchResult res in resCol)
                {
                    // an existing site
                    sites.Add(new ActiveDirectorySite(_context, (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.Cn), true));
                }
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(_context, e);
            }
            finally
            {
                if (resCol != null)
                {
                    // call dispose on search result collection
                    resCol.Dispose();
                }
            }
            return sites;
        }
Exemplo n.º 48
0
        private void GetAdjacentSites()
        {
            DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
            string config = (string)de.Properties["configurationNamingContext"][0];
            string transportContainer = "CN=Inter-Site Transports,CN=Sites," + config;
            de = DirectoryEntryManager.GetDirectoryEntry(context, transportContainer);
            ADSearcher adSearcher = new ADSearcher(de,
                                                  "(&(objectClass=siteLink)(objectCategory=SiteLink)(siteList=" + Utils.GetEscapedFilterValue((string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName)) + "))",
                                                  new string[] { "cn", "distinguishedName" },
                                                  SearchScope.Subtree);
            SearchResultCollection results = null;

            try
            {
                results = adSearcher.FindAll();
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }

            try
            {
                ActiveDirectorySiteLink link = null;

                foreach (SearchResult result in results)
                {
                    string dn = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.DistinguishedName);
                    string linkName = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.Cn);
                    string transportName = (string)Utils.GetDNComponents(dn)[1].Value;
                    ActiveDirectoryTransportType transportType;
                    if (String.Compare(transportName, "IP", StringComparison.OrdinalIgnoreCase) == 0)
                        transportType = ActiveDirectoryTransportType.Rpc;
                    else if (String.Compare(transportName, "SMTP", StringComparison.OrdinalIgnoreCase) == 0)
                        transportType = ActiveDirectoryTransportType.Smtp;
                    else
                    {
                        // should not happen
                        string message = Res.GetString(Res.UnknownTransport, transportName);
                        throw new ActiveDirectoryOperationException(message);
                    }

                    try
                    {
                        link = new ActiveDirectorySiteLink(context, linkName, transportType, true, result.GetDirectoryEntry());
                        foreach (ActiveDirectorySite tmpSite in link.Sites)
                        {
                            // don't add itself                            
                            if (Utils.Compare(tmpSite.Name, Name) == 0)
                                continue;

                            if (!_adjacentSites.Contains(tmpSite))
                                _adjacentSites.Add(tmpSite);
                        }
                    }
                    finally
                    {
                        link.Dispose();
                    }
                }
            }
            finally
            {
                results.Dispose();
                de.Dispose();
            }
        }