Exemplo n.º 1
0
 public static ADForest GetForest(string forestFqdn, NetworkCredential credentials)
 {
     if (string.IsNullOrEmpty(forestFqdn))
     {
         throw new ArgumentNullException("forestFqdn");
     }
     if (ADForest.IsLocalForestFqdn(forestFqdn))
     {
         if (credentials != null)
         {
             throw new ArgumentException("The use of credentials is not supported for the local forest '" + forestFqdn + "'");
         }
         return(ADForest.GetLocalForest());
     }
     else
     {
         PartitionId partitionId = new PartitionId(forestFqdn);
         if (ADAccountPartitionLocator.IsKnownPartition(partitionId))
         {
             return(ADForest.GetForest(partitionId));
         }
         ADServerInfo remoteServerFromDomainFqdn = TopologyProvider.GetInstance().GetRemoteServerFromDomainFqdn(forestFqdn, credentials);
         return(new ADForest(forestFqdn, remoteServerFromDomainFqdn.Fqdn, null, credentials, false));
     }
 }
Exemplo n.º 2
0
        internal static IEnumerable <ExtendedOrganizationalUnit> FindSubTreeChildOrganizationalUnit(bool includeContainers, IConfigurationSession session, ADObjectId rootId, QueryFilter preFilter)
        {
            QueryFilter queryFilter = new OrFilter(new QueryFilter[]
            {
                new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.ObjectCategory, ADOrganizationalUnit.MostDerivedClass),
                new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.ObjectCategory, ADDomain.MostDerivedClass)
            });

            if (!ExtendedOrganizationalUnit.IsTenant(session))
            {
                IList <QueryFilter>    list       = new List <QueryFilter>();
                IList <QueryFilter>    list2      = new List <QueryFilter>();
                IEnumerable <ADDomain> enumerable = ADForest.GetLocalForest(session.DomainController).FindDomains();
                foreach (ADDomain addomain in enumerable)
                {
                    ExchangeOrganizationalUnit exchangeOrganizationalUnit = session.ResolveWellKnownGuid <ExchangeOrganizationalUnit>(WellKnownGuid.DomainControllersWkGuid, addomain.Id);
                    if (exchangeOrganizationalUnit != null)
                    {
                        list.Add(new ComparisonFilter(ComparisonOperator.NotEqual, ADObjectSchema.Id, exchangeOrganizationalUnit.Id));
                    }
                    ExchangeOrganizationalUnit exchangeOrganizationalUnit2 = session.ResolveWellKnownGuid <ExchangeOrganizationalUnit>(WellKnownGuid.UsersWkGuid, addomain.Id);
                    if (exchangeOrganizationalUnit2 != null)
                    {
                        list2.Add(new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.Id, exchangeOrganizationalUnit2.Id));
                    }
                }
                foreach (QueryFilter queryFilter2 in list)
                {
                    queryFilter = new AndFilter(new QueryFilter[]
                    {
                        queryFilter,
                        queryFilter2
                    });
                }
                if (includeContainers)
                {
                    foreach (QueryFilter queryFilter3 in list2)
                    {
                        queryFilter = new OrFilter(new QueryFilter[]
                        {
                            queryFilter,
                            queryFilter3
                        });
                    }
                }
            }
            if (preFilter != null)
            {
                queryFilter = new AndFilter(new QueryFilter[]
                {
                    preFilter,
                    queryFilter
                });
            }
            return(session.FindPaged <ExtendedOrganizationalUnit>(rootId, QueryScope.SubTree, queryFilter, null, 0));
        }
Exemplo n.º 3
0
 private ADForest(string fqdn, string domainController, string globalCatalog, NetworkCredential networkCredential, bool knownForest)
 {
     this.fqdn              = fqdn;
     this.domainController  = domainController;
     this.globalCatalog     = globalCatalog;
     this.networkCredential = networkCredential;
     this.partitionId       = (Datacenter.IsMicrosoftHostedOnly(true) ? new PartitionId(fqdn) : PartitionId.LocalForest);
     this.isKnownForest     = knownForest;
     this.isLocalForest     = ADForest.IsLocalForestFqdn(fqdn);
 }
Exemplo n.º 4
0
        public static ADForest GetLocalForest(string domainController)
        {
            if (string.IsNullOrEmpty(domainController))
            {
                return(ADForest.LocalForestInstance);
            }
            string text = null;

            if (ADForest.IsDcAlsoGcAndAvailable(domainController, null))
            {
                text = domainController;
            }
            return(new ADForest(domainController, text));
        }
Exemplo n.º 5
0
        public static ADForest GetForest(PartitionId partitionId)
        {
            if (null == partitionId)
            {
                throw new ArgumentNullException("partitionId");
            }
            if (ADForest.IsLocalForestFqdn(partitionId.ForestFQDN))
            {
                return(ADForest.GetLocalForest());
            }
            IList <ADServerInfo> serversForRole  = TopologyProvider.GetInstance().GetServersForRole(partitionId.ForestFQDN, new List <string>(0), ADServerRole.DomainController, 1, false);
            IList <ADServerInfo> serversForRole2 = TopologyProvider.GetInstance().GetServersForRole(partitionId.ForestFQDN, new List <string>(0), ADServerRole.GlobalCatalog, 1, false);

            if (serversForRole == null || serversForRole2 == null || serversForRole.Count == 0 || serversForRole2.Count == 0)
            {
                throw new ADOperationException(DirectoryStrings.CannotGetForestInfo(partitionId.ForestFQDN));
            }
            return(new ADForest(partitionId.ForestFQDN, serversForRole[0].Fqdn, serversForRole2[0].Fqdn, null, true));
        }
Exemplo n.º 6
0
 public static ADForest GetLocalForest()
 {
     return(ADForest.GetLocalForest(null));
 }