Пример #1
0
        private string GetSuitableDomainController(string forestFqdn)
        {
            ADForest adforest;

            if (string.IsNullOrEmpty(forestFqdn))
            {
                adforest = ADForest.GetLocalForest();
            }
            else
            {
                adforest = ADForest.GetForest(forestFqdn, null);
            }
            if (adforest != null)
            {
                ReadOnlyCollection <ADServer> readOnlyCollection = adforest.FindAllGlobalCatalogs();
                foreach (ADServer adserver in readOnlyCollection)
                {
                    if (adserver.IsAvailable())
                    {
                        return(adserver.ServerReference.Name);
                    }
                }
            }
            return(null);
        }
Пример #2
0
        internal override Guid SelectDomainController(PartitionId partitionId)
        {
            ExTraceGlobals.ActiveDirectoryTracer.TraceDebug <Guid>((long)base.TenantExternalDirectoryId.GetHashCode(), "Selecting a DC for Merge operation of {0}. Will examine all DCs in the local site AND domain", base.TenantExternalDirectoryId);
            if (base.InvocationId != Guid.Empty)
            {
                ExTraceGlobals.ActiveDirectoryTracer.TraceError <Guid>((long)base.TenantExternalDirectoryId.GetHashCode(), "MergePageToken.SelectDomainController this.InvocationId {0} is not Guid.Empty", base.InvocationId);
                throw new InvalidOperationException("InvocationId");
            }
            ITopologyConfigurationSession session        = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromAccountPartitionRootOrgScopeSet(partitionId), 390, "SelectDomainController", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\Sync\\BackSync\\MergePageToken.cs");
            IList <ADServerInfo>          serversForRole = TopologyProvider.GetInstance().GetServersForRole(partitionId.ForestFQDN, new List <string>(0), ADServerRole.DomainController, int.MaxValue, false);

            ExTraceGlobals.ActiveDirectoryTracer.TraceDebug((long)base.TenantExternalDirectoryId.GetHashCode(), "MergePageToken.SelectDomainController searching dcs in preferred site");
            foreach (ADServerInfo adserverInfo in serversForRole)
            {
                Guid result;
                if (this.TrySelectDomainController(session, adserverInfo.Fqdn, partitionId, false, out result))
                {
                    return(result);
                }
            }
            ReadOnlyCollection <ADServer> readOnlyCollection = ADForest.GetForest(partitionId).FindRootDomain().FindAllDomainControllers();

            ExTraceGlobals.ActiveDirectoryTracer.TraceDebug((long)base.TenantExternalDirectoryId.GetHashCode(), "MergePageToken.SelectDomainController searching dcs in other sites");
            foreach (ADServer adserver in readOnlyCollection)
            {
                Guid result2;
                if (!ConnectionPoolManager.IsServerInPreferredSite(partitionId.ForestFQDN, adserver) && this.TrySelectDomainController(session, adserver.DnsHostName, partitionId, true, out result2))
                {
                    return(result2);
                }
            }
            ExTraceGlobals.ActiveDirectoryTracer.TraceError <Guid, string>((long)base.TenantExternalDirectoryId.GetHashCode(), "Could not find any DC that has all changes reported by the Tenant Full Sync Watermarks for {0}. \r\nFull sync watermarks: \r\n{1}", base.TenantExternalDirectoryId, base.Watermarks.SerializeToString());
            throw new BackSyncDataSourceUnavailableException();
        }
Пример #3
0
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter();
            ADForest adforest;

            if (this.Forest == null)
            {
                adforest = ADForest.GetLocalForest();
            }
            else
            {
                adforest = ADForest.GetForest(this.Forest, this.Credential);
            }
            List <ADServer> list = new List <ADServer>();

            if (this.GlobalCatalog)
            {
                list.AddRange(adforest.FindAllGlobalCatalogs(false));
            }
            else
            {
                if (this.DomainName == null)
                {
                    using (ReadOnlyCollection <ADDomain> .Enumerator enumerator = adforest.FindDomains().GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            ADDomain addomain = enumerator.Current;
                            list.AddRange(addomain.FindAllDomainControllers(false));
                        }
                        goto IL_F3;
                    }
                }
                ADDomain addomain2;
                if (this.Credential == null)
                {
                    addomain2 = adforest.FindDomainByFqdn(this.DomainName.ToString());
                }
                else
                {
                    addomain2 = ADForest.FindExternalDomain(this.DomainName.ToString(), this.Credential);
                }
                if (addomain2 != null)
                {
                    list.AddRange(addomain2.FindAllDomainControllers(false));
                }
                else
                {
                    base.WriteError(new DomainNotFoundException(this.DomainName.ToString()), ErrorCategory.InvalidArgument, null);
                }
            }
IL_F3:
            this.WriteResult <ADServer>(list);
            TaskLogger.LogExit();
        }
Пример #4
0
 private void ReadRootDomainFromDc(OrganizationId orgId)
 {
     this.rootDomain = null;
     if (orgId.Equals(OrganizationId.ForestWideOrgId))
     {
         this.rootDomain = ADForest.GetLocalForest().FindRootDomain(true);
     }
     else
     {
         this.rootDomain = ADForest.GetForest(orgId.PartitionId).FindRootDomain(true);
     }
     if (this.rootDomain == null)
     {
         base.ThrowTerminatingError(new RootDomainNotFoundException(), ErrorCategory.InvalidData, null);
     }
     this.LogReadObject(this.rootDomain);
 }
Пример #5
0
        private void PopulateADServersList()
        {
            List <ADServer> list = new List <ADServer>();

            foreach (ADDomain addomain in ADForest.GetForest(new PartitionId(this.forestFqdn)).FindDomains())
            {
                foreach (ADServer adserver in addomain.FindAllDomainControllers(true))
                {
                    if (adserver.DnsHostName != null)
                    {
                        list.Add(adserver);
                    }
                }
            }
            this.lastTopologyUpdateTime = ExDateTime.UtcNow;
            this.serversList            = list;
        }
Пример #6
0
        private bool WaitForReplicationConvergenceInTargetForest(string domainController, TimeSpan timeout)
        {
            base.WriteVerbose(Strings.VerboseWaitingForReplicationInTargetForest);
            WatermarkMap watermarkMap = new WatermarkMap();
            ReadOnlyCollection <ADServer> readOnlyCollection = ADForest.GetForest(this.DataObject.TargetForest, null).FindRootDomain().FindAllDomainControllers();
            DateTime utcNow = DateTime.UtcNow;

            foreach (ADServer adserver in readOnlyCollection)
            {
                string          text;
                LocalizedString localizedString;
                if (SuitabilityVerifier.IsServerSuitableIgnoreExceptions(adserver.DnsHostName, false, null, out text, out localizedString))
                {
                    Guid         key;
                    WatermarkMap watermarkMap2;
                    long         value = this.ReadDcHighestUSN(this.DataObject.TargetOrganizationId.PartitionId, adserver.DnsHostName, false, out key, out watermarkMap2);
                    watermarkMap[key] = value;
                }
            }
            ITopologyConfigurationSession session = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(domainController, true, ConsistencyMode.PartiallyConsistent, null, ADSessionSettings.FromAccountPartitionRootOrgScopeSet(this.DataObject.TargetOrganizationId.PartitionId), 514, "WaitForReplicationConvergenceInTargetForest", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\Relocation\\RemoveTenantRelocationRequest.cs");
            bool flag = false;

            while (!flag)
            {
                flag = this.CheckReplicationStatus(session, watermarkMap, false);
                if (flag || utcNow + timeout < DateTime.UtcNow)
                {
                    break;
                }
                Thread.Sleep(5000);
            }
            if (flag)
            {
                base.WriteVerbose(Strings.VerboseTargetDcIsUpToDate(domainController));
            }
            return(flag);
        }
Пример #7
0
        protected override IConfigurable ResolveDataObject()
        {
            IConfigurable configurable   = null;
            Exception     innerException = null;
            ADObjectId    adobjectId     = null;
            ADObjectId    rootID         = RecipientTaskHelper.IsValidDistinguishedName(this.Identity, out adobjectId) ? adobjectId.Parent : null;

            try
            {
                configurable = base.GetDataObject <ADRecipient>(this.Identity, base.DataSession, rootID, null, new LocalizedString?(Strings.ErrorRecipientNotUnique(this.Identity.ToString())));
            }
            catch (ADTransientException ex)
            {
                innerException = ex;
                base.WriteVerbose(Strings.VerboseCannotReadObject(this.Identity.ToString(), base.DataSession.Source, ex.Message));
            }
            catch (ADOperationException ex2)
            {
                innerException = ex2;
                base.WriteVerbose(Strings.VerboseCannotReadObject(this.Identity.ToString(), base.DataSession.Source, ex2.Message));
            }
            catch (ManagementObjectNotFoundException ex3)
            {
                innerException = ex3;
                base.WriteVerbose(Strings.VerboseCannotReadObject(this.Identity.ToString(), base.DataSession.Source, ex3.Message));
            }
            if (configurable == null)
            {
                base.WriteError(new ManagementObjectNotFoundException(Strings.ErrorObjectNotFound(this.Identity.ToString()), innerException), ErrorCategory.ObjectNotFound, this.Identity);
            }
            if (this.globalCatalog == null || (base.DomainController == null && !StringComparer.InvariantCultureIgnoreCase.Equals(this.configurationSession.DomainController, ((ADObject)configurable).OriginatingServer)))
            {
                if (base.DomainController == null)
                {
                    ADObject          adobject          = (ADObject)configurable;
                    string            originatingServer = adobject.OriginatingServer;
                    ADSessionSettings sessionSettings   = ADSessionSettings.FromRootOrgScopeSet();
                    if (!adobject.OrganizationId.Equals(OrganizationId.ForestWideOrgId))
                    {
                        sessionSettings = ADSessionSettings.FromAccountPartitionRootOrgScopeSet(adobject.OrganizationId.PartitionId);
                    }
                    this.configurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(originatingServer, true, ConsistencyMode.PartiallyConsistent, base.NetCredential, sessionSettings, 210, "ResolveDataObject", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\RecipientTasks\\recipient\\UpdateRecipient.cs");
                }
                string text = NativeHelpers.CanonicalNameFromDistinguishedName(this.configurationSession.GetRootDomainNamingContextFromCurrentReadConnection());
                this.globalCatalog = null;
                if (this.IsServerSuitableAsGC(this.configurationSession.DomainController, this.configurationSession.NetworkCredential))
                {
                    this.globalCatalog = this.configurationSession.DomainController;
                }
                else
                {
                    NetworkCredential             credentials        = ADForest.IsLocalForestFqdn(text) ? null : this.configurationSession.NetworkCredential;
                    ADForest                      forest             = ADForest.GetForest(text, credentials);
                    ReadOnlyCollection <ADServer> readOnlyCollection = forest.FindAllGlobalCatalogs(false);
                    if (readOnlyCollection != null && readOnlyCollection.Count != 0)
                    {
                        foreach (ADServer adserver in readOnlyCollection)
                        {
                            if (this.IsServerSuitableAsGC(adserver.DnsHostName, this.configurationSession.NetworkCredential))
                            {
                                this.globalCatalog = adserver.DnsHostName;
                                break;
                            }
                        }
                    }
                    if (string.IsNullOrEmpty(this.globalCatalog))
                    {
                        base.WriteError(new InvalidOperationException(Strings.ErrorNoGlobalGatalogFound(text)), (ErrorCategory)1011, this.Identity);
                    }
                }
                if (ADForest.IsLocalForestFqdn(text) || !OrganizationId.ForestWideOrgId.Equals(base.OrgWideSessionSettings.CurrentOrganizationId))
                {
                    this.domainRecipientSession.LinkResolutionServer = this.localForestLinkResolutionServer;
                }
                else
                {
                    this.domainRecipientSession.LinkResolutionServer = null;
                }
            }
            return(configurable);
        }