public DirectoryServer(ADServer server, NtdsDsa ntdsdsa) { if (server == null) { throw new ArgumentNullException("server"); } if (ntdsdsa == null) { throw new ArgumentNullException("ntdsdsa"); } if (!ntdsdsa.Id.Parent.Equals(server.Id)) { throw new ArgumentException("ntdsdsa mismatch with server"); } if (string.IsNullOrEmpty(server.DnsHostName)) { throw new ArgumentException("server.DnsHostName null or empty"); } this.server = server; this.isGC = (NtdsdsaOptions.IsGC == ntdsdsa.Options); this.SuitabilityResult = new SuitabilityCheckResult(); this.suitableRoles = (ADServerRole.DomainController | ADServerRole.ConfigurationDomainController); if (this.IsGC) { this.suitableRoles |= ADServerRole.GlobalCatalog; } this.SuitabilityResult.IsEnabled = true; ADObjectId adobjectId = ntdsdsa.MasterNCs.Find((ADObjectId x) => x.DescendantDN(0).Equals(x)); this.writableDomainNC = adobjectId; }
internal static RidMasterInfo GetRidMasterInfo(IConfigurationSession session) { bool useConfigNC = session.UseConfigNC; RidMasterInfo result; try { session.UseConfigNC = false; RidManagerContainer[] array = session.Find <RidManagerContainer>(null, QueryScope.SubTree, null, null, 1); if (array == null || array.Length != 1) { throw new RidMasterConfigException(Strings.ErrorCannotRetrieveRidManagerContainer((array == null) ? "0" : array.Length.ToString())); } session.UseConfigNC = true; ADObjectId fsmoRoleOwner = array[0].FsmoRoleOwner; if (fsmoRoleOwner == null) { throw new RidMasterConfigException(Strings.ErrorEmptyFsmoRoleOwnerAttribute); } ADServer adserver = session.Read <ADServer>(fsmoRoleOwner.Parent); if (adserver == null) { throw new RidMasterConfigException(Strings.ErrorCannotRetrieveServer(fsmoRoleOwner.Parent.ToString())); } string dnsHostName = adserver.DnsHostName; int fsmoRoleOwnerVersion = SyncDaemonArbitrationConfigHelper.GetFsmoRoleOwnerVersion(array[0].ReplicationAttributeMetadata); result = new RidMasterInfo(dnsHostName, fsmoRoleOwnerVersion); } finally { session.UseConfigNC = useConfigNC; } return(result); }
public static ADServer PickGlobalCatalog(string configDCName) { ADServer adserver = DirectoryUtilities.DomainControllerFromName(configDCName); if (adserver != null && DirectoryUtilities.IsGlobalCatalog(adserver) && adserver.IsAvailable()) { return(adserver); } ADForest localForest = ADForest.GetLocalForest(); ADSite localSite = DirectoryUtilities.ConfigurationSession.GetLocalSite(); if (localSite == null) { throw new ADInitializationException(Strings.LocalSiteNotFound); } ReadOnlyCollection <ADServer> readOnlyCollection = localForest.FindAllGlobalCatalogs(); foreach (ADServer adserver2 in readOnlyCollection) { if (adserver2.ValidateRead().Length == 0 && adserver2.Site.Equals(localSite.Id) && adserver2.IsAvailable()) { return(adserver2); } } foreach (ADServer adserver3 in readOnlyCollection) { if (adserver3.ValidateRead().Length == 0 && adserver3.IsAvailable()) { return(adserver3); } } throw new ADInitializationException(Strings.NoGCsAvailableException(localForest.Fqdn)); }
protected override void InternalBeginProcessing() { TaskLogger.LogEnter(); this.readOnlyRecipientSession = PermissionTaskHelper.GetReadOnlyRecipientSession(this.DomainController); if (this.readOnlyRecipientSession.UseGlobalCatalog) { this.globalCatalogRecipientSession = this.readOnlyRecipientSession; } else { this.globalCatalogRecipientSession = PermissionTaskHelper.GetReadOnlyRecipientSession(null); } this.readOnlyConfigurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(this.DomainController, true, ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromRootOrgScopeSet(), 207, "InternalBeginProcessing", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\RecipientTasks\\permission\\SetPermissionTaskBase.cs"); if (this.DomainController != null) { ADServer adserver = DirectoryUtilities.DomainControllerFromName(this.DomainController); if (adserver == null) { base.ThrowTerminatingError(new RecipientTaskException(Strings.DCWithGivenNameCouldNotBeFound(this.DomainController)), ErrorCategory.ObjectNotFound, null); } this.domainControllerDomainId = adserver.DomainId; } this.modifiedAcl.Clear(); this.modifiedObjects.Clear(); TaskLogger.LogExit(); }
public static ADServer GetSchemaMasterDomainController() { string schemaMasterDC = DirectoryUtilities.ConfigurationSession.GetSchemaMasterDC(); ADServer adserver = DirectoryUtilities.DomainControllerFromName(schemaMasterDC); if (adserver == null) { throw new SchemaMasterDCNotFoundException(Strings.DCWithGivenNameCouldNotBeFound(schemaMasterDC)); } return(adserver); }
private string CheckOUExists(ADServer server, string[] OUs, out bool success) { var starTime = DateTime.Now; string errors = ""; success = false; foreach (var OU in OUs) { string destPath = server.path + "/" + OU; for (int trials = 0; trials < 6; trials++) { if (DateTime.Now.Subtract(starTime).TotalSeconds > 60) { success = false; return("Unable to connect to [" + server.ToString() + "]"); } try { using (var destOU = new DirectoryEntry(destPath, server.ServerUserName, server.ServerPassword, server.authTypes)) { var n = destOU.Name.ToString(); success = true; log.LogDebug(" found OU: " + destPath); break; } } catch (Exception e) { var msg = "Fail to check OU [" + OU + "] in " + server.ToString(); // ""specified in config"; // if (e.HResult == -2147016661 || e.HResult == -2147016656) //0x8007202b. A referral was returned from the server if (trials == 0) { errors += msg + ". " + e.Message; } if (e.HResult == -2147016656 || // object not found e.HResult == -2147023570 || // user name or passw incorrect e.HResult == -2147016672 || // An operations error occurred. e.HResult == -2147016661 // 0x8007202b. A referral was returned from the server ) { break; } else { // if -2147016646 //server is not operational // and other errors means that server is down or not responding Thread.Sleep(10 * 1000); } } } // tries } return(errors); }
public ADServer GetAdServer(string fqdn) { if (this.topologyScope != ExchangeTopologyScope.Complete && this.topologyScope != ExchangeTopologyScope.ADAndExchangeServerAndSiteTopology) { throw new InvalidOperationException("GetAdSever is only supported for Complete and ADAndExchangeServerAndSiteTopology scopes"); } ADServer adserver = null; this.adServerDictionary.TryGetValue(fqdn, out adserver); ExTraceGlobals.ExchangeTopologyTracer.TraceDebug <string, string>((long)this.GetHashCode(), "Mapped {0} to {1}", fqdn, (adserver == null) ? "<null>" : adserver.DistinguishedName); return(adserver); }
protected MsoMainStreamCookieManager(string serviceInstanceName, int maxCookieHistoryCount, TimeSpan cookieHistoryInterval) : base(serviceInstanceName, maxCookieHistoryCount, cookieHistoryInterval) { ADServer adserver = this.FindRidMasterDomainController(); if (adserver == null) { ExTraceGlobals.ADTopologyTracer.TraceError((long)this.GetHashCode(), "RID master not found"); throw new InvalidOperationException("RID master not found"); } ExTraceGlobals.ADTopologyTracer.TraceDebug <string>((long)this.GetHashCode(), "ridMaster.DnsHostName \"{0}\"", adserver.DnsHostName); this.cookieSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(adserver.DnsHostName, false, ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromRootOrgScopeSet(), 56, ".ctor", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\Sync\\CookieManager\\MsoMainStreamCookieManager.cs"); this.cookieSession.UseConfigNC = false; }
private void ValidateGC(string fqdn) { ADServer adserver = this.ValidateDC(fqdn); if (!base.HasErrors) { NtdsDsa[] array = base.GlobalConfigSession.Find <NtdsDsa>((ADObjectId)adserver.Identity, QueryScope.SubTree, new BitMaskAndFilter(NtdsDsaSchema.Options, 1UL), null, 1); if (array == null && array.Length == 0) { base.WriteError(new InvalidOperationException(Strings.ErrorDCIsNotGC(fqdn)), ErrorCategory.InvalidOperation, this.Identity); } } }
private void LoadUsersByGroups(ADServer server, DirectoryEntry rootDSE, string prevHighUSN) { //HashSet<string> usersInGroup = new HashSet<string>(StringComparer.OrdinalIgnoreCase); List <string> usersToUpdate = new List <string>(); using (DirectorySearcher ds = new DirectorySearcher(rootDSE)) { // if '>=' then we get last update twice // Note that the operators "<" and ">" are not supported. See "LDAP syntax filter clause" ds.Filter = string.Format("(&(objectClass=group)(uSNChanged>={0})(!(uSNChanged={0})))", prevHighUSN); ds.SizeLimit = 0; // unlimited ds.PageSize = 1000; ds.PropertiesToLoad.Add("distinguishedname"); ds.PropertiesToLoad.Add("member"); // looking for changed membership using (SearchResultCollection results = ds.FindAll()) { var cnt = results.Count; if (results != null && cnt > 0) { foreach (SearchResult gr in results) { var dn = (string)gr.Properties["distinguishedname"][0]; var membersGr = gr.Properties["member"]; ISet <string> cachedMembers; if (groupCache.TryGetValue(dn, out cachedMembers)) { var members = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (string m in membersGr) { members.Add(m); } if (!Utils.CheckEquals(cachedMembers, members)) { var usersDiff = cachedMembers.Except(members).Union(members.Except(cachedMembers)).ToArray(); log.LogInfo("Membership changed in Group '" + dn + "' DiffMembers: " + string.Join(";", usersDiff.Take(5))); usersToUpdate.AddRange(usersDiff); } groupCache[dn] = members; // update cache } } } } } foreach (var u in usersToUpdate.Distinct(StringComparer.OrdinalIgnoreCase)) { LoadUsersByFilter(server, rootDSE, "(&(objectClass=user)(objectCategory=person)(distinguishedName=" + u + "))"); } }
public static bool InLocalDomain(ADServer server) { ADDomain addomain = ADForest.GetLocalForest().FindLocalDomain(); if (addomain == null || addomain.Id == null) { throw new ADInitializationException(Strings.LocalDomainNotFoundException); } if (server.DomainId == null) { throw new ADInitializationException(Strings.ServerDoesNotHaveADomain(server.Name)); } return(server.DomainId.Equals(addomain.Id)); }
private static bool IsGlobalCatalog(ADServer server) { ADForest localForest = ADForest.GetLocalForest(); ReadOnlyCollection <ADServer> readOnlyCollection = localForest.FindAllGlobalCatalogs(); foreach (ADServer adserver in readOnlyCollection) { if (adserver.ValidateRead().Length == 0 && adserver.Id.Equals(server.Id)) { return(true); } } return(false); }
private ADServer ValidateDC(string fqdn) { ADServer adserver = base.GlobalConfigSession.FindDCByFqdn(fqdn); if (adserver == null) { base.WriteError(new InvalidOperationException(Strings.ErrorDCNotFound(fqdn)), ErrorCategory.InvalidOperation, this.Identity); } if (!adserver.IsAvailable()) { base.WriteError(new InvalidOperationException(Strings.ErrorDCNotAvailable(fqdn)), ErrorCategory.InvalidOperation, this.Identity); } return(adserver); }
// Token: 0x06000DCA RID: 3530 RVA: 0x0003F910 File Offset: 0x0003DB10 internal bool IsServerInAnyKnownSite(ADServer adServer) { if (adServer == null) { throw new ArgumentNullException("adServer"); } for (int i = 0; i < this.ADServerInfos.Length; i++) { if (!string.IsNullOrEmpty(this.ADServerInfos[i].SiteName) && string.Equals(adServer.Site.Name, this.ADServerInfos[i].SiteName, StringComparison.OrdinalIgnoreCase)) { return(true); } } return(false); }
public override void CheckIfConnectionAllowed() { ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "CheckIfConnectionAllowed entering"); if (!string.IsNullOrEmpty(base.RecipientSession.DomainController)) { ExTraceGlobals.BackSyncTracer.TraceDebug <string>((long)SyncConfiguration.TraceId, "this.RecipientSession.DomainController {0}", base.RecipientSession.DomainController); ADServer adserver = base.RootOrgConfigurationSession.FindDCByFqdn(base.RecipientSession.DomainController); PartitionId partitionId = base.RootOrgConfigurationSession.SessionSettings.PartitionId; if (adserver == null || !ConnectionPoolManager.IsServerInPreferredSite(partitionId.ForestFQDN, adserver)) { ExTraceGlobals.BackSyncTracer.TraceError <string>((long)SyncConfiguration.TraceId, "DC site {0} not in preferred site list.", (adserver != null) ? adserver.Site.DistinguishedName : "<null>"); throw new BackSyncDataSourceNotInPreferredSiteException((adserver != null) ? adserver.DistinguishedName : "<null>"); } } }
private string SendHb(ADServer server) { try { using (LdapConnection connection = server.getLapConnection) { var filter = "(&(objectClass=*))"; var searchRequest = new SearchRequest(null, filter, System.DirectoryServices.Protocols.SearchScope.Base, "highestCommittedUSN", "DnsHostName", "dsServiceName"); var response = connection.SendRequest(searchRequest) as SearchResponse; var result = !string.IsNullOrEmpty(Convert.ToString(response.Entries[0].Attributes["highestcommittedusn"][0])); } } catch (Exception ex) { return(ex.Message); } return(string.Empty); }
internal static IDictionary <string, ISet <string> > GetGroupMembers(ADServer server, ISet <string> groupsFilter) { groupCache = new Dictionary <string, ISet <string> >(); using (DirectoryEntry rootDSE = new DirectoryEntry(server.path, server.ServerUserName, server.ServerPassword, server.authTypes)) { using (DirectorySearcher ds = new DirectorySearcher(rootDSE)) { ds.Filter = "(&(objectClass=group))"; ds.SizeLimit = 0; // unlimited ds.PageSize = 1000; ds.PropertiesToLoad.Add("distinguishedname"); ds.PropertiesToLoad.Add("member"); using (SearchResultCollection results = ds.FindAll()) { var cnt = results.Count; if (results != null && cnt > 0) { //log.LogInfo("Reading " + cnt + " account(s) from " + server.ToString() + ". Current USN='" + CurrentHighUSN + "'. InvocationID='" + GetInvocationID + "'"); foreach (SearchResult gr in results) { var dn = (string)gr.Properties["distinguishedname"][0]; var membersGr = gr.Properties["member"]; if (groupsFilter.Contains(dn)) // only wanted groups needed { var members = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (string m in membersGr) { members.Add(m); } groupCache.Add(dn, members); } #if DEBUG //foreach (var p in gr.Properties) //{ // var prop = (ResultPropertyValueCollection)((System.Collections.DictionaryEntry)p).Value; // var propVal = (prop.Count > 0) ? Convert.ToString(prop[0]) : null; // Console.WriteLine(((System.Collections.DictionaryEntry)p).Key + "=" + propVal); //} #endif } } } } } return(groupCache); }
/// <summary> /// This will read in the ADServer value from the web.config and will return it /// as an LDAP path ie DC=creditsights, DC=cyberelves, DC=com. /// This is required when creating directoryentry other than the root. /// </summary> /// <returns></returns> private static string GetLDAPDomain() { StringBuilder LDAPDomain = new StringBuilder(); string[] LDAPDC = ADServer.Split('.'); for (int i = 0; i < LDAPDC.GetUpperBound(0) + 1; i++) { LDAPDomain.Append("DC=" + LDAPDC[i]); if (i < LDAPDC.GetUpperBound(0)) { LDAPDomain.Append(","); } } return(LDAPDomain.ToString()); }
private static bool IsServerSuitable(Guid invocationId, ITopologyConfigurationSession session, out string dnsHostName, out bool isInLocalSite) { dnsHostName = string.Empty; isInLocalSite = false; ADServer adserver = session.FindDCByInvocationId(invocationId); if (adserver == null) { return(false); } dnsHostName = adserver.DnsHostName; isInLocalSite = adserver.IsInLocalSite; LocalizedString empty = LocalizedString.Empty; string text; return(SuitabilityVerifier.IsServerSuitableIgnoreExceptions(adserver.DnsHostName, true, null, out text, out empty)); }
private static ReconciliationCookie GetReconciliationCookieForDomainController(Fqdn fqdn, ITopologyConfigurationSession configSession, Task.TaskErrorLoggingDelegate errorLogger) { ADServer adserver = configSession.FindDCByFqdn(fqdn); if (adserver != null) { LocalizedString empty = LocalizedString.Empty; string text; if (SuitabilityVerifier.IsServerSuitableIgnoreExceptions(adserver.DnsHostName, true, null, out text, out empty)) { ITopologyConfigurationSession sessionForDC = ProvisioningReconciliationHelper.GetSessionForDC(adserver); RootDse rootDse = sessionForDC.GetRootDse(); Guid invocationIdByDC = sessionForDC.GetInvocationIdByDC(adserver); return(new ReconciliationCookie(ProvisioningReconciliationHelper.CurrentCookieVersion, adserver.DnsHostName, invocationIdByDC, rootDse.HighestCommittedUSN)); } } return(null); }
private ADServer[] ReadServersFromConfig(ADServersElement confServers, string typeOfSource) { var res = new ADServer[confServers.Count]; for (int i = 0; i < res.Length; i++) { var serverElement = confServers[i]; res[i] = new ADServer() { Name = serverElement.Url, ServerUserName = serverElement.User, ServerPassword = serverElement.Password, SSL = !serverElement.allowClearLDAP.Trim().ToLower().Equals("y", StringComparison.OrdinalIgnoreCase), SourceDest = typeOfSource }; } return(res); }
public static ADServer PickLocalDomainController() { ADServer adserver = DirectoryUtilities.DomainControllerFromName("localhost"); if (adserver != null && DirectoryUtilities.IsGlobalCatalog(adserver) && adserver.IsAvailable()) { return(adserver); } ADSite localSite = DirectoryUtilities.ConfigurationSession.GetLocalSite(); if (localSite == null) { throw new ADInitializationException(Strings.LocalSiteNotFound); } ADDomain addomain = ADForest.GetLocalForest().FindLocalDomain(); if (addomain == null) { throw new ADInitializationException(Strings.LocalDomainNotFoundException); } ReadOnlyCollection <ADServer> readOnlyCollection = addomain.FindAllDomainControllers(); foreach (ADServer adserver2 in readOnlyCollection) { if (adserver2.ValidateRead().Length == 0 && adserver2.Site.Equals(localSite.Id) && adserver2.IsAvailable() && DirectoryUtilities.IsGlobalCatalog(adserver2)) { return(adserver2); } } if (adserver != null) { return(adserver); } foreach (ADServer adserver3 in readOnlyCollection) { if (adserver3.ValidateRead().Length == 0 && adserver3.Site.Equals(localSite.Id) && adserver3.IsAvailable()) { return(adserver3); } } throw new ADInitializationException(Strings.NoDCsAvailableException(addomain.Name, localSite.Name)); }
public static ADServer DomainControllerFromName(string domainControllerName) { string dnsHostName = null; try { dnsHostName = Dns.GetHostEntry(domainControllerName).HostName; } catch (SocketException) { return(null); } ADServer adserver = DirectoryUtilities.ConfigurationSession.FindDCByFqdn(dnsHostName); if (adserver != null && adserver.ValidateRead().Length == 0) { return(adserver); } return(null); }
// args[0] - count of threads // args[1] - length of request queue static void Main(string[] args) { #if DEBUG args = new[] { "2", "20" }; #endif if (args.Length < 2) { Console.WriteLine("You should specify THREADS and RQUEUE"); return; } int cthreads = Int32.Parse(args[0]); int lqueue = Int32.Parse(args[1]); #if DEBUG ADServer.Start("http://localhost:8888/", cthreads, lqueue); #endif ADServer.Start("http://*:80/", cthreads, lqueue); }
internal static string FindDomainControllerByInvocationId(Guid dcInvocationId, Exception exceptionOnDcNotFound, PartitionId partitionId) { string result = null; ITopologyConfigurationSession topologyConfigurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(true, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromAccountPartitionRootOrgScopeSet(partitionId), 467, "FindDomainControllerByInvocationId", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\Sync\\BackSync\\Configuration\\SyncConfiguration.cs"); ADServer adserver = topologyConfigurationSession.FindDCByInvocationId(dcInvocationId); if (adserver != null) { result = adserver.DnsHostName; ExTraceGlobals.BackSyncTracer.TraceDebug <string>((long)SyncConfiguration.TraceId, "adServer.DnsHostName{0}", adserver.DnsHostName); } else { ExTraceGlobals.BackSyncTracer.TraceError <Guid>((long)SyncConfiguration.TraceId, "Unable to find a DC for the invocation id {0}", dcInvocationId); if (exceptionOnDcNotFound != null) { throw exceptionOnDcNotFound; } } return(result); }
private WatermarkMap FilterOutNotExistingDCs(IEnumerable <ReplicationCursor> adReplicationCursorCollection, PartitionId partitionId) { WatermarkMap watermarkMap = new WatermarkMap(); ITopologyConfigurationSession topologyConfigurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromAccountPartitionRootOrgScopeSet(partitionId), 336, "FilterOutNotExistingDCs", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\Sync\\BackSync\\MergePageToken.cs"); WatermarkMap watermarkMap2 = null; ADServer adserver = topologyConfigurationSession.FindDCByInvocationId(base.WatermarksInvocationId); if (adserver != null) { topologyConfigurationSession.DomainController = adserver.DnsHostName; watermarkMap2 = SyncConfiguration.GetReplicationCursors(topologyConfigurationSession); } foreach (ReplicationCursor replicationCursor in adReplicationCursorCollection) { if (watermarkMap2 == null || watermarkMap2.ContainsKey(replicationCursor.SourceInvocationId)) { watermarkMap[replicationCursor.SourceInvocationId] = replicationCursor.UpToDatenessUsn; } } return(watermarkMap); }
private ADServer FindRidMasterDomainController() { ExTraceGlobals.ADTopologyTracer.TraceDebug((long)this.GetHashCode(), "Find RID master domain controller ..."); ADServer result = null; IConfigurationSession tenantOrTopologyConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromRootOrgScopeSet(), 273, "FindRidMasterDomainController", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\Sync\\CookieManager\\MsoMainStreamCookieManager.cs"); tenantOrTopologyConfigurationSession.UseConfigNC = false; RidManagerContainer[] array = tenantOrTopologyConfigurationSession.Find <RidManagerContainer>(null, QueryScope.SubTree, null, null, 1); if (array != null && array.Length > 0) { ExTraceGlobals.ADTopologyTracer.TraceDebug <int>((long)this.GetHashCode(), "ridManagerContainer.Length = {0}", array.Length); tenantOrTopologyConfigurationSession.UseConfigNC = true; ADObjectId fsmoRoleOwner = array[0].FsmoRoleOwner; if (fsmoRoleOwner != null) { ExTraceGlobals.ADTopologyTracer.TraceDebug <string>((long)this.GetHashCode(), "ntdsId.DistinguishedName \"{0}\"", fsmoRoleOwner.DistinguishedName); result = tenantOrTopologyConfigurationSession.Read <ADServer>(fsmoRoleOwner.Parent); } } return(result); }
private static string FindRidMasterNameForPartition(PartitionId partitionId) { string result = null; ITopologyConfigurationSession topologyConfigurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromAccountPartitionRootOrgScopeSet(partitionId), 213, "FindRidMasterNameForPartition", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\RelocationCache\\ForestTenantRelocationsCache.cs"); topologyConfigurationSession.UseConfigNC = false; RidManagerContainer[] array = topologyConfigurationSession.Find <RidManagerContainer>(null, QueryScope.SubTree, null, null, 1); if (array != null && array.Length > 0) { ADObjectId fsmoRoleOwner = array[0].FsmoRoleOwner; if (fsmoRoleOwner != null) { topologyConfigurationSession.UseConfigNC = true; ADServer adserver = topologyConfigurationSession.Read <ADServer>(fsmoRoleOwner.Parent); if (adserver != null) { result = adserver.DnsHostName; } } } return(result); }
private static string FindAvailableServerByInvocationId(Guid invocationId, IConfigurationSession configSession, ADObjectId allowedSite) { QueryFilter filter = new ComparisonFilter(ComparisonOperator.Equal, NtdsDsaSchema.InvocationId, invocationId); NtdsDsa[] array = configSession.Find <NtdsDsa>(allowedSite, QueryScope.SubTree, filter, null, 1); if (array == null || array.Length <= 0) { return(null); } ADServer adserver = configSession.Read <ADServer>(array[0].Id.Parent); if (adserver == null) { return(null); } LocalizedString empty = LocalizedString.Empty; string text; if (!SuitabilityVerifier.IsServerSuitableIgnoreExceptions(adserver.DnsHostName, true, null, out text, out empty)) { return(null); } return(adserver.DnsHostName); }
internal static MultiValuedProperty <ReconciliationCookie> GetReconciliationCookiesForNextCycle(string dc, Task.TaskErrorLoggingDelegate errorLogger) { MultiValuedProperty <ReconciliationCookie> multiValuedProperty = new MultiValuedProperty <ReconciliationCookie>(); ITopologyConfigurationSession topologyConfigurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(dc, true, ConsistencyMode.IgnoreInvalid, null, ADSessionSettings.FromRootOrgScopeSet(), 126, "GetReconciliationCookiesForNextCycle", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\Common\\ProvisioningReconciliationHelper.cs"); topologyConfigurationSession.UseConfigNC = false; MultiValuedProperty <ReplicationCursor> multiValuedProperty2 = topologyConfigurationSession.ReadReplicationCursors(ADSession.GetDomainNamingContextForLocalForest()); topologyConfigurationSession.UseConfigNC = true; foreach (ReplicationCursor replicationCursor in multiValuedProperty2) { if (replicationCursor.SourceDsa != null) { ADServer adserver = topologyConfigurationSession.FindDCByInvocationId(replicationCursor.SourceInvocationId); if (adserver != null) { string dnsHostName = adserver.DnsHostName; ReconciliationCookie item = new ReconciliationCookie(ProvisioningReconciliationHelper.CurrentCookieVersion, dnsHostName, replicationCursor.SourceInvocationId, replicationCursor.UpToDatenessUsn); multiValuedProperty.Add(item); } } } return(multiValuedProperty); }