public static AdamInstance FindOne(DirectoryContext context, string partitionName) { // validate parameters (partitionName validated by the call to ConfigSet) if (context == null) { throw new ArgumentNullException(nameof(context)); } // contexttype should be ConfigurationSet if (context.ContextType != DirectoryContextType.ConfigurationSet) { throw new ArgumentException(SR.TargetShouldBeConfigSet, nameof(context)); } if (partitionName == null) { throw new ArgumentNullException(nameof(partitionName)); } if (partitionName.Length == 0) { throw new ArgumentException(SR.EmptyStringParameter, nameof(partitionName)); } // work with copy of the context context = new DirectoryContext(context); return(ConfigurationSet.FindOneAdamInstance(context, partitionName, null)); }
public static AdamInstance FindOne(DirectoryContext context, string partitionName) { if (context != null) { if (context.ContextType == DirectoryContextType.ConfigurationSet) { if (partitionName != null) { if (partitionName.Length != 0) { context = new DirectoryContext(context); return(ConfigurationSet.FindOneAdamInstance(context, partitionName, null)); } else { throw new ArgumentException(Res.GetString("EmptyStringParameter"), "partitionName"); } } else { throw new ArgumentNullException("partitionName"); } } else { throw new ArgumentException(Res.GetString("TargetShouldBeConfigSet"), "context"); } } else { throw new ArgumentNullException("context"); } }
internal static AdamInstance FindOneAdamInstance(string configSetName, DirectoryContext context, string partitionName, string siteName) { if (partitionName == null || partitionName.Length != 0) { if (siteName == null || siteName.Length != 0) { ArrayList replicaList = Utils.GetReplicaList(context, partitionName, siteName, false, true, false); if (replicaList.Count >= 1) { return(ConfigurationSet.FindAliveAdamInstance(configSetName, context, replicaList)); } else { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ADAMInstanceNotFound"), typeof(AdamInstance), null); } } else { throw new ArgumentException(Res.GetString("EmptyStringParameter"), "siteName"); } } else { throw new ArgumentException(Res.GetString("EmptyStringParameter"), "partitionName"); } }
public AdamInstanceCollection FindAllAdamInstances(string partitionName, string siteName) { this.CheckIfDisposed(); if (siteName != null) { return(ConfigurationSet.FindAdamInstances(this.context, partitionName, siteName)); } else { throw new ArgumentNullException("siteName"); } }
public AdamInstance FindAdamInstance(string partitionName) { this.CheckIfDisposed(); if (partitionName != null) { return(ConfigurationSet.FindOneAdamInstance(this.Name, this.context, partitionName, null)); } else { throw new ArgumentNullException("partitionName"); } }
public DirectoryServer FindDirectoryServer(bool forceRediscovery) { base.CheckIfDisposed(); if (this.appType == ApplicationPartitionType.ADApplicationPartition) { return(this.FindDirectoryServerInternal(null, forceRediscovery)); } if (!this.committed) { throw new InvalidOperationException(Res.GetString("CannotPerformOperationOnUncommittedObject")); } return(ConfigurationSet.FindOneAdamInstance(base.context, base.Name, null)); }
internal string GetServerName() { if (this.serverName == null) { DirectoryContextType directoryContextType = this.contextType; switch (directoryContextType) { case DirectoryContextType.Domain: case DirectoryContextType.Forest: { if (this.name == null || this.contextType == DirectoryContextType.Forest && this.isCurrentForest()) { this.serverName = DirectoryContext.GetLoggedOnDomain(); break; } else { this.serverName = DirectoryContext.GetDnsDomainName(this.name); break; } } case DirectoryContextType.DirectoryServer: { this.serverName = this.name; break; } case DirectoryContextType.ConfigurationSet: { AdamInstance adamInstance = ConfigurationSet.FindAnyAdamInstance(this); try { this.serverName = adamInstance.Name; break; } finally { adamInstance.Dispose(); } } case DirectoryContextType.ApplicationPartition: { this.serverName = this.name; break; } } } return(this.serverName); }
public ReadOnlyDirectoryServerCollection FindAllDirectoryServers() { base.CheckIfDisposed(); if (this.appType == ApplicationPartitionType.ADApplicationPartition) { return(this.FindAllDirectoryServersInternal(null)); } if (!this.committed) { throw new InvalidOperationException(Res.GetString("CannotPerformOperationOnUncommittedObject")); } ReadOnlyDirectoryServerCollection servers = new ReadOnlyDirectoryServerCollection(); servers.AddRange(ConfigurationSet.FindAdamInstances(base.context, base.Name, null)); return(servers); }
public DirectoryServer FindDirectoryServer(string siteName) { base.CheckIfDisposed(); if (siteName == null) { throw new ArgumentNullException("siteName"); } if (this.appType == ApplicationPartitionType.ADApplicationPartition) { return(this.FindDirectoryServerInternal(siteName, false)); } if (!this.committed) { throw new InvalidOperationException(Res.GetString("CannotPerformOperationOnUncommittedObject")); } return(ConfigurationSet.FindOneAdamInstance(base.context, base.Name, siteName)); }
public static AdamInstanceCollection FindAll(DirectoryContext context, string partitionName) { AdamInstanceCollection adamInstanceCollection; if (context != null) { if (context.ContextType == DirectoryContextType.ConfigurationSet) { if (partitionName != null) { if (partitionName.Length != 0) { context = new DirectoryContext(context); try { adamInstanceCollection = ConfigurationSet.FindAdamInstances(context, partitionName, null); } catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException) { adamInstanceCollection = new AdamInstanceCollection(new ArrayList()); } return(adamInstanceCollection); } else { throw new ArgumentException(Res.GetString("EmptyStringParameter"), "partitionName"); } } else { throw new ArgumentNullException("partitionName"); } } else { throw new ArgumentException(Res.GetString("TargetShouldBeConfigSet"), "context"); } } else { throw new ArgumentNullException("context"); } }
public static AdamInstanceCollection FindAll(DirectoryContext context, string partitionName) { AdamInstanceCollection adamInstanceCollection = null; // validate parameters (partitionName validated by the call to ConfigSet) if (context == null) { throw new ArgumentNullException(nameof(context)); } // contexttype should be ConfigurationSet if (context.ContextType != DirectoryContextType.ConfigurationSet) { throw new ArgumentException(SR.TargetShouldBeConfigSet, nameof(context)); } if (partitionName == null) { throw new ArgumentNullException(nameof(partitionName)); } if (partitionName.Length == 0) { throw new ArgumentException(SR.EmptyStringParameter, nameof(partitionName)); } // work with copy of the context context = new DirectoryContext(context); try { adamInstanceCollection = ConfigurationSet.FindAdamInstances(context, partitionName, null); } catch (ActiveDirectoryObjectNotFoundException) { // this is the case where we could not find an ADAM instance in that config set (return empty collection) adamInstanceCollection = new AdamInstanceCollection(new ArrayList()); } return(adamInstanceCollection); }
internal string GetServerName() { if (this.serverName == null) { switch (this.contextType) { case DirectoryContextType.Domain: case DirectoryContextType.Forest: goto Label_004A; case DirectoryContextType.DirectoryServer: this.serverName = this.name; break; case DirectoryContextType.ConfigurationSet: using (AdamInstance instance = ConfigurationSet.FindAnyAdamInstance(this)) { this.serverName = instance.Name; break; } goto Label_004A; case DirectoryContextType.ApplicationPartition: this.serverName = this.name; break; } } goto Label_009D; Label_004A: if ((this.name == null) || ((this.contextType == DirectoryContextType.Forest) && this.isCurrentForest())) { this.serverName = GetLoggedOnDomain(); } else { this.serverName = GetDnsDomainName(this.name); } Label_009D: return(this.serverName); }
internal static AdamInstance FindOneAdamInstance(DirectoryContext context, string partitionName, string siteName) { return(ConfigurationSet.FindOneAdamInstance(null, context, partitionName, siteName)); }
public AdamInstance FindAdamInstance() { this.CheckIfDisposed(); return(ConfigurationSet.FindOneAdamInstance(this.Name, this.context, null, null)); }
public AdamInstanceCollection FindAllAdamInstances() { this.CheckIfDisposed(); return(ConfigurationSet.FindAdamInstances(this.context, null, null)); }
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"); } } }
internal string GetServerName() { if (serverName == null) { switch (_contextType) { case DirectoryContextType.ConfigurationSet: { AdamInstance adamInst = ConfigurationSet.FindAnyAdamInstance(this); try { serverName = adamInst.Name; } finally { adamInst.Dispose(); } break; } case DirectoryContextType.Domain: case DirectoryContextType.Forest: { // // if the target is not specified OR // if the forest name was explicitly specified and the forest is the same as the current forest // we want to find a DC in the current domain // if ((_name == null) || ((_contextType == DirectoryContextType.Forest) && (isCurrentForest()))) { serverName = GetLoggedOnDomain(); } else { serverName = GetDnsDomainName(_name); } break; } case DirectoryContextType.ApplicationPartition: { // if this is an appNC the target should not be null Debug.Assert(_name != null); serverName = _name; break; } case DirectoryContextType.DirectoryServer: { // this should not happen (We should have checks for this earlier itself) Debug.Assert(_name != null); serverName = _name; break; } default: { Debug.Fail("DirectoryContext::GetServerName - Unknown contextType"); break; } } } return(serverName); }
public static ApplicationPartition FindByName(DirectoryContext context, string distinguishedName) { DirectoryEntryManager directoryEntryMgr = null; DirectoryContext context2 = null; if (context == null) { throw new ArgumentNullException("context"); } if ((context.Name == null) && !context.isRootDomain()) { throw new ArgumentException(Res.GetString("ContextNotAssociatedWithDomain"), "context"); } if (((context.Name != null) && !context.isRootDomain()) && (!context.isADAMConfigSet() && !context.isServer())) { throw new ArgumentException(Res.GetString("NotADOrADAM"), "context"); } if (distinguishedName == null) { throw new ArgumentNullException("distinguishedName"); } if (distinguishedName.Length == 0) { throw new ArgumentException(Res.GetString("EmptyStringParameter"), "distinguishedName"); } if (!Utils.IsValidDNFormat(distinguishedName)) { throw new ArgumentException(Res.GetString("InvalidDNFormat"), "distinguishedName"); } context = new DirectoryContext(context); directoryEntryMgr = new DirectoryEntryManager(context); DirectoryEntry searchRoot = null; try { searchRoot = DirectoryEntryManager.GetDirectoryEntry(context, directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.PartitionsContainer)); } catch (COMException exception) { throw ExceptionHelper.GetExceptionFromCOMException(context, exception); } catch (ActiveDirectoryObjectNotFoundException) { throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", new object[] { context.Name })); } 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("))("); builder.Append(PropertyManager.NCName); builder.Append("="); builder.Append(Utils.GetEscapedFilterValue(distinguishedName)); builder.Append("))"); string filter = builder.ToString(); string[] propertiesToLoad = new string[] { PropertyManager.DnsRoot, PropertyManager.NCName }; ADSearcher searcher = new ADSearcher(searchRoot, filter, propertiesToLoad, SearchScope.OneLevel, false, false); SearchResult res = null; try { res = searcher.FindOne(); } catch (COMException exception2) { if (exception2.ErrorCode == -2147016656) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AppNCNotFound"), typeof(ApplicationPartition), distinguishedName); } throw ExceptionHelper.GetExceptionFromCOMException(context, exception2); } finally { searchRoot.Dispose(); } if (res == null) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AppNCNotFound"), typeof(ApplicationPartition), distinguishedName); } string domainName = null; try { domainName = (res.Properties[PropertyManager.DnsRoot].Count > 0) ? ((string)res.Properties[PropertyManager.DnsRoot][0]) : null; } catch (COMException exception3) { throw ExceptionHelper.GetExceptionFromCOMException(context, exception3); } ApplicationPartitionType applicationPartitionType = GetApplicationPartitionType(context); if (context.ContextType != DirectoryContextType.DirectoryServer) { if (applicationPartitionType == ApplicationPartitionType.ADApplicationPartition) { DomainControllerInfo info; int errorCode = 0; errorCode = Locator.DsGetDcNameWrapper(null, domainName, null, 0x8000L, out info); if (errorCode == 0x54b) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AppNCNotFound"), typeof(ApplicationPartition), distinguishedName); } if (errorCode != 0) { throw ExceptionHelper.GetExceptionFromErrorCode(errorCode); } context2 = Utils.GetNewDirectoryContext(info.DomainControllerName.Substring(2), DirectoryContextType.DirectoryServer, context); } else { context2 = Utils.GetNewDirectoryContext(ConfigurationSet.FindOneAdamInstance(context.Name, context, distinguishedName, null).Name, DirectoryContextType.DirectoryServer, context); } goto Label_03FC; } bool flag = false; DistinguishedName dn = new DistinguishedName(distinguishedName); DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); try { foreach (string str3 in directoryEntry.Properties[PropertyManager.NamingContexts]) { DistinguishedName name2 = new DistinguishedName(str3); if (name2.Equals(dn)) { flag = true; goto Label_0352; } } } catch (COMException exception4) { throw ExceptionHelper.GetExceptionFromCOMException(context, exception4); } finally { directoryEntry.Dispose(); } Label_0352: if (!flag) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AppNCNotFound"), typeof(ApplicationPartition), distinguishedName); } context2 = context; Label_03FC: return(new ApplicationPartition(context2, (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.NCName), domainName, applicationPartitionType, directoryEntryMgr)); }