public static ReplicationConnection FindByName(DirectoryContext context, string name) { ValidateArgument(context, name); context = new DirectoryContext(context); using (DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE)) { string str = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ServerName); string dn = "CN=NTDS Settings," + str; directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dn); ADSearcher searcher = new ADSearcher(directoryEntry, "(&(objectClass=nTDSConnection)(objectCategory=NTDSConnection)(name=" + Utils.GetEscapedFilterValue(name) + "))", new string[] { "distinguishedName" }, SearchScope.OneLevel, false, false); SearchResult result = null; try { result = searcher.FindOne(); } catch (COMException exception) { if (exception.ErrorCode == -2147016656) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ReplicationConnection), name); } throw ExceptionHelper.GetExceptionFromCOMException(context, exception); } if (result == null) { Exception exception2 = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ReplicationConnection), name); throw exception2; } return(new ReplicationConnection(context, result.GetDirectoryEntry(), name)); } }
public static ReplicationConnection FindByName(DirectoryContext context, string name) { ValidateArgument(context, name); // work with copy of the context context = new DirectoryContext(context); // bind to the rootdse to get the servername property DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); try { string serverDN = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ServerName); string connectionContainer = "CN=NTDS Settings," + serverDN; de = DirectoryEntryManager.GetDirectoryEntry(context, connectionContainer); // doing the search to find the connection object based on its name ADSearcher adSearcher = new ADSearcher(de, "(&(objectClass=nTDSConnection)(objectCategory=NTDSConnection)(name=" + Utils.GetEscapedFilterValue(name) + "))", new string[] { "distinguishedName" }, SearchScope.OneLevel, false, /* no paged search */ false /* don't cache results */); SearchResult srchResult = null; try { srchResult = adSearcher.FindOne(); } catch (COMException e) { if (e.ErrorCode == unchecked ((int)0x80072030)) { // object is not found since we cannot even find the container in which to search throw new ActiveDirectoryObjectNotFoundException(SR.DSNotFound, typeof(ReplicationConnection), name); } else { throw ExceptionHelper.GetExceptionFromCOMException(context, e); } } if (srchResult == null) { // no such connection object Exception e = new ActiveDirectoryObjectNotFoundException(SR.DSNotFound, typeof(ReplicationConnection), name); throw e; } else { DirectoryEntry connectionEntry = srchResult.GetDirectoryEntry(); return(new ReplicationConnection(context, connectionEntry, name)); } } finally { de.Dispose(); } }
public static ReplicationConnection FindByName(DirectoryContext context, string name) { ValidateArgument(context, name); // work with copy of the context context = new DirectoryContext(context); // bind to the rootdse to get the servername property DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); try { string serverDN = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ServerName); string connectionContainer = "CN=NTDS Settings," + serverDN; de = DirectoryEntryManager.GetDirectoryEntry(context, connectionContainer); // doing the search to find the connection object based on its name ADSearcher adSearcher = new ADSearcher(de, "(&(objectClass=nTDSConnection)(objectCategory=NTDSConnection)(name=" + Utils.GetEscapedFilterValue(name) + "))", new string[] { "distinguishedName" }, SearchScope.OneLevel, false, /* no paged search */ false /* don't cache results */); SearchResult srchResult = null; try { srchResult = adSearcher.FindOne(); } catch (COMException e) { if (e.ErrorCode == unchecked((int)0x80072030)) { // object is not found since we cannot even find the container in which to search throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DSNotFound), typeof(ReplicationConnection), name); } else { throw ExceptionHelper.GetExceptionFromCOMException(context, e); } } if (srchResult == null) { // no such connection object Exception e = new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DSNotFound), typeof(ReplicationConnection), name); throw e; } else { DirectoryEntry connectionEntry = srchResult.GetDirectoryEntry(); return new ReplicationConnection(context, connectionEntry, name); } } finally { de.Dispose(); } }
public static ReplicationConnection FindByName(DirectoryContext context, string name) { ReplicationConnection replicationConnection; ReplicationConnection.ValidateArgument(context, name); context = new DirectoryContext(context); DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); try { string propertyValue = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ServerName); string str = string.Concat("CN=NTDS Settings,", propertyValue); directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, str); string[] strArrays = new string[1]; strArrays[0] = "distinguishedName"; ADSearcher aDSearcher = new ADSearcher(directoryEntry, string.Concat("(&(objectClass=nTDSConnection)(objectCategory=NTDSConnection)(name=", Utils.GetEscapedFilterValue(name), "))"), strArrays, SearchScope.OneLevel, false, false); SearchResult searchResult = null; try { searchResult = aDSearcher.FindOne(); } catch (COMException cOMException1) { COMException cOMException = cOMException1; if (cOMException.ErrorCode != -2147016656) { throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException); } else { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ReplicationConnection), name); } } if (searchResult != null) { DirectoryEntry directoryEntry1 = searchResult.GetDirectoryEntry(); replicationConnection = new ReplicationConnection(context, directoryEntry1, name); } else { Exception activeDirectoryObjectNotFoundException = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ReplicationConnection), name); throw activeDirectoryObjectNotFoundException; } } finally { directoryEntry.Dispose(); } return(replicationConnection); }
public static ActiveDirectorySiteLink FindByName(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport) { DirectoryEntry directoryEntry; ActiveDirectorySiteLink activeDirectorySiteLink; ActiveDirectorySiteLink.ValidateArgument(context, siteLinkName, transport); context = new DirectoryContext(context); try { directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); string propertyValue = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext); string str = string.Concat("CN=Inter-Site Transports,CN=Sites,", propertyValue); if (transport != ActiveDirectoryTransportType.Rpc) { str = string.Concat("CN=SMTP,", str); } else { str = string.Concat("CN=IP,", str); } directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, str); } catch (COMException cOMException1) { COMException cOMException = cOMException1; throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException); } catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException) { object[] name = new object[1]; name[0] = context.Name; throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", name)); } try { try { string[] strArrays = new string[1]; strArrays[0] = "distinguishedName"; ADSearcher aDSearcher = new ADSearcher(directoryEntry, string.Concat("(&(objectClass=siteLink)(objectCategory=SiteLink)(name=", Utils.GetEscapedFilterValue(siteLinkName), "))"), strArrays, SearchScope.OneLevel, false, false); SearchResult searchResult = aDSearcher.FindOne(); if (searchResult != null) { DirectoryEntry directoryEntry1 = searchResult.GetDirectoryEntry(); ActiveDirectorySiteLink activeDirectorySiteLink1 = new ActiveDirectorySiteLink(context, siteLinkName, transport, true, directoryEntry1); activeDirectorySiteLink = activeDirectorySiteLink1; } else { Exception exception = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySiteLink), siteLinkName); throw exception; } } catch (COMException cOMException3) { COMException cOMException2 = cOMException3; if (cOMException2.ErrorCode != -2147016656) { throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException2); } else { DirectoryEntry directoryEntry2 = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); if (!Utils.CheckCapability(directoryEntry2, Capability.ActiveDirectoryApplicationMode) || transport != ActiveDirectoryTransportType.Smtp) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySiteLink), siteLinkName); } else { throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP")); } } } } finally { directoryEntry.Dispose(); } return activeDirectorySiteLink; }
private void LoadCrossRefAttributes() { DirectoryEntry directoryEntry = null; using (directoryEntry) { try { directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, this.directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.PartitionsContainer)); 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(")("); stringBuilder.Append(PropertyManager.DnsRoot); stringBuilder.Append("="); stringBuilder.Append(Utils.GetEscapedFilterValue(this.partitionName)); stringBuilder.Append("))"); string str = stringBuilder.ToString(); string[] distinguishedName = new string[2]; distinguishedName[0] = PropertyManager.DistinguishedName; distinguishedName[1] = PropertyManager.TrustParent; ADSearcher aDSearcher = new ADSearcher(directoryEntry, str, distinguishedName, SearchScope.OneLevel, false, false); SearchResult searchResult = aDSearcher.FindOne(); this.crossRefDN = (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.DistinguishedName); if (searchResult.Properties[PropertyManager.TrustParent].Count > 0) { this.trustParent = (string)searchResult.Properties[PropertyManager.TrustParent][0]; } } catch (COMException cOMException1) { COMException cOMException = cOMException1; throw ExceptionHelper.GetExceptionFromCOMException(this.context, cOMException); } } }
internal static SearchResult GetPropertiesFromSchemaContainer(DirectoryContext context, DirectoryEntry schemaEntry, string name, bool isDefunctOnServer) { SearchResult result = null; StringBuilder builder = new StringBuilder(15); builder.Append("(&("); builder.Append(PropertyManager.ObjectCategory); builder.Append("=attributeSchema)"); builder.Append("("); if (!isDefunctOnServer) { builder.Append(PropertyManager.LdapDisplayName); } else { builder.Append(PropertyManager.Cn); } builder.Append("="); builder.Append(Utils.GetEscapedFilterValue(name)); builder.Append(")"); if (!isDefunctOnServer) { builder.Append("(!("); } else { builder.Append("("); } builder.Append(PropertyManager.IsDefunct); if (!isDefunctOnServer) { builder.Append("=TRUE)))"); } else { builder.Append("=TRUE))"); } string[] propertiesToLoad = null; if (!isDefunctOnServer) { propertiesToLoad = new string[] { PropertyManager.DistinguishedName, PropertyManager.Cn, PropertyManager.AttributeSyntax, PropertyManager.OMSyntax, PropertyManager.OMObjectClass, PropertyManager.Description, PropertyManager.SearchFlags, PropertyManager.IsMemberOfPartialAttributeSet, PropertyManager.LinkID, PropertyManager.SchemaIDGuid, PropertyManager.RangeLower, PropertyManager.RangeUpper }; } else { propertiesToLoad = new string[] { PropertyManager.DistinguishedName, PropertyManager.Cn, PropertyManager.AttributeSyntax, PropertyManager.OMSyntax, PropertyManager.OMObjectClass, PropertyManager.Description, PropertyManager.SearchFlags, PropertyManager.IsMemberOfPartialAttributeSet, PropertyManager.LinkID, PropertyManager.SchemaIDGuid, PropertyManager.AttributeID, PropertyManager.IsSingleValued, PropertyManager.RangeLower, PropertyManager.RangeUpper, PropertyManager.LdapDisplayName }; } ADSearcher searcher = new ADSearcher(schemaEntry, builder.ToString(), propertiesToLoad, SearchScope.OneLevel, false, false); try { result = searcher.FindOne(); } catch (COMException exception) { if (exception.ErrorCode == -2147016656) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySchemaProperty), name); } throw ExceptionHelper.GetExceptionFromCOMException(context, exception); } if (result == null) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySchemaProperty), name); } return result; }
public static ActiveDirectorySubnet FindByName(DirectoryContext context, string subnetName) { DirectoryEntry directoryEntry; ActiveDirectorySubnet activeDirectorySubnet; ActiveDirectorySubnet activeDirectorySubnet1; ActiveDirectorySubnet.ValidateArgument(context, subnetName); context = new DirectoryContext(context); try { directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); string propertyValue = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext); string str = string.Concat("CN=Subnets,CN=Sites,", propertyValue); directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, str); } catch (COMException cOMException1) { COMException cOMException = cOMException1; throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException); } catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException) { object[] name = new object[1]; name[0] = context.Name; throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", name)); } using (directoryEntry) { try { string[] strArrays = new string[1]; strArrays[0] = "distinguishedName"; ADSearcher aDSearcher = new ADSearcher(directoryEntry, string.Concat("(&(objectClass=subnet)(objectCategory=subnet)(name=", Utils.GetEscapedFilterValue(subnetName), "))"), strArrays, SearchScope.OneLevel, false, false); SearchResult searchResult = aDSearcher.FindOne(); if (searchResult != null) { string str1 = null; DirectoryEntry directoryEntry1 = searchResult.GetDirectoryEntry(); if (directoryEntry1.Properties.Contains("siteObject")) { NativeComInterfaces.IAdsPathname pathname = (NativeComInterfaces.IAdsPathname)(new NativeComInterfaces.Pathname()); pathname.EscapedMode = 4; string item = (string)directoryEntry1.Properties["siteObject"][0]; pathname.Set(item, 4); string str2 = pathname.Retrieve(11); str1 = str2.Substring(3); } if (str1 != null) { activeDirectorySubnet = new ActiveDirectorySubnet(context, subnetName, str1, true); } else { activeDirectorySubnet = new ActiveDirectorySubnet(context, subnetName, null, true); } activeDirectorySubnet.cachedEntry = directoryEntry1; activeDirectorySubnet1 = activeDirectorySubnet; } else { Exception exception = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySubnet), subnetName); throw exception; } } catch (COMException cOMException3) { COMException cOMException2 = cOMException3; if (cOMException2.ErrorCode != -2147016656) { throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException2); } else { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySubnet), subnetName); } } } return(activeDirectorySubnet1); }
public static ApplicationPartition FindByName(DirectoryContext context, string distinguishedName) { ApplicationPartition partition = null; DirectoryEntryManager directoryEntryMgr = null; DirectoryContext appNCContext = null; // check that the argument is not null if (context == null) throw new ArgumentNullException("context"); if ((context.Name == null) && (!context.isRootDomain())) { throw new ArgumentException(Res.GetString(Res.ContextNotAssociatedWithDomain), "context"); } if (context.Name != null) { // the target should be a valid forest name, configset name or a server if (!((context.isRootDomain()) || (context.isADAMConfigSet()) || context.isServer())) { throw new ArgumentException(Res.GetString(Res.NotADOrADAM), "context"); } } // check that the distingushed name of the application partition is not null or empty if (distinguishedName == null) throw new ArgumentNullException("distinguishedName"); if (distinguishedName.Length == 0) throw new ArgumentException(Res.GetString(Res.EmptyStringParameter), "distinguishedName"); if (!Utils.IsValidDNFormat(distinguishedName)) throw new ArgumentException(Res.GetString(Res.InvalidDNFormat), "distinguishedName"); // work with copy of the context context = new DirectoryContext(context); // search in the partitions container of the forest for // crossRef objects that have their nCName set to the specified distinguishedName directoryEntryMgr = new DirectoryEntryManager(context); DirectoryEntry partitionsEntry = null; try { partitionsEntry = DirectoryEntryManager.GetDirectoryEntry(context, directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.PartitionsContainer)); } catch (COMException e) { throw ExceptionHelper.GetExceptionFromCOMException(context, e); } catch (ActiveDirectoryObjectNotFoundException) { // this is the case where the context is a config set and we could not find an ADAM instance in that config set throw new ActiveDirectoryOperationException(Res.GetString(Res.ADAMInstanceNotFoundInConfigSet, context.Name)); } // 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.803:="); str.Append((int)SystemFlag.SystemFlagNtdsDomain); str.Append("))("); str.Append(PropertyManager.NCName); str.Append("="); str.Append(Utils.GetEscapedFilterValue(distinguishedName)); str.Append("))"); string filter = str.ToString(); string[] propertiesToLoad = new string[2]; propertiesToLoad[0] = PropertyManager.DnsRoot; propertiesToLoad[1] = PropertyManager.NCName; ADSearcher searcher = new ADSearcher(partitionsEntry, filter, propertiesToLoad, SearchScope.OneLevel, false /*not paged search*/, false /*no cached results*/); SearchResult res = null; try { res = searcher.FindOne(); } catch (COMException e) { if (e.ErrorCode == unchecked((int)0x80072030)) { // object is not found since we cannot even find the container in which to search throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.AppNCNotFound), typeof(ApplicationPartition), distinguishedName); } else { throw ExceptionHelper.GetExceptionFromCOMException(context, e); } } finally { partitionsEntry.Dispose(); } if (res == null) { // the specified application partition could not be found in the given forest throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.AppNCNotFound), typeof(ApplicationPartition), distinguishedName); } string appNCDnsName = null; try { appNCDnsName = (res.Properties[PropertyManager.DnsRoot].Count > 0) ? (string)res.Properties[PropertyManager.DnsRoot][0] : null; } catch (COMException e) { throw ExceptionHelper.GetExceptionFromCOMException(context, e); } // verify that if the target is a server, then this partition is a naming context on it ApplicationPartitionType appType = GetApplicationPartitionType(context); if (context.ContextType == DirectoryContextType.DirectoryServer) { bool hostsCurrentPartition = false; DistinguishedName appNCDN = new DistinguishedName(distinguishedName); DirectoryEntry rootDSE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); try { foreach (string namingContext in rootDSE.Properties[PropertyManager.NamingContexts]) { DistinguishedName dn = new DistinguishedName(namingContext); if (dn.Equals(appNCDN)) { hostsCurrentPartition = true; break; } } } catch (COMException e) { throw ExceptionHelper.GetExceptionFromCOMException(context, e); } finally { rootDSE.Dispose(); } if (!hostsCurrentPartition) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.AppNCNotFound), typeof(ApplicationPartition), distinguishedName); } appNCContext = context; } else { // we need to find a server which hosts this application partition if (appType == ApplicationPartitionType.ADApplicationPartition) { int errorCode = 0; DomainControllerInfo domainControllerInfo; errorCode = Locator.DsGetDcNameWrapper(null, appNCDnsName, null, (long)PrivateLocatorFlags.OnlyLDAPNeeded, out domainControllerInfo); if (errorCode == NativeMethods.ERROR_NO_SUCH_DOMAIN) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.AppNCNotFound), typeof(ApplicationPartition), distinguishedName); } else if (errorCode != 0) { throw ExceptionHelper.GetExceptionFromErrorCode(errorCode); } Debug.Assert(domainControllerInfo.DomainControllerName.Length > 2, "ApplicationPartition:FindByName - domainControllerInfo.DomainControllerName.Length <= 2"); string serverName = domainControllerInfo.DomainControllerName.Substring(2); appNCContext = Utils.GetNewDirectoryContext(serverName, DirectoryContextType.DirectoryServer, context); } else { // this will find an adam instance that hosts this partition and which is alive and responding. string adamInstName = ConfigurationSet.FindOneAdamInstance(context.Name, context, distinguishedName, null).Name; appNCContext = Utils.GetNewDirectoryContext(adamInstName, DirectoryContextType.DirectoryServer, context); } } partition = new ApplicationPartition(appNCContext, (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.NCName), appNCDnsName, appType, directoryEntryMgr); return partition; }
// // This method retrieves properties for this schema class from the schema container // on the server. For non-defunct classes only properties that are not available in the abstract // schema are retrieved. For defunct classes, all the properties are retrieved. // The retrieved values are stored in a class variable "propertyValuesFromServer" which is a // hashtable indexed on the property name. // internal static SearchResult GetPropertiesFromSchemaContainer(DirectoryContext context, DirectoryEntry schemaEntry, string name, bool isDefunctOnServer) { SearchResult propertyValuesFromServer = null; // // The properties that are loaded from the schemaContainer for non-defunct classes: // DistinguishedName // CommonName // Syntax - AttributeSyntax, OMSyntax, OMObjectClass // Description // IsIndexed, IsIndexedOverContainer, IsInAnr, IsOnTombstonedObject, IsTupleIndexed - SearchFlags // IsInGlobalCatalog - IsMemberOfPartialAttributeSet // LinkId (Link) // SchemaGuid - SchemaIdGuid // RangeLower // RangeUpper // // For defunct class we also load teh remaining properties // LdapDisplayName // Oid // IsSingleValued // // build the filter StringBuilder str = new StringBuilder(15); str.Append("(&("); str.Append(PropertyManager.ObjectCategory); str.Append("=attributeSchema)"); str.Append("("); if (!isDefunctOnServer) { str.Append(PropertyManager.LdapDisplayName); } else { str.Append(PropertyManager.Cn); } str.Append("="); str.Append(Utils.GetEscapedFilterValue(name)); str.Append(")"); if (!isDefunctOnServer) { str.Append("(!("); } else { str.Append("("); } str.Append(PropertyManager.IsDefunct); if (!isDefunctOnServer) { str.Append("=TRUE)))"); } else { str.Append("=TRUE))"); } string[] propertiesToLoad = null; if (!isDefunctOnServer) { propertiesToLoad = new string[12]; propertiesToLoad[0] = PropertyManager.DistinguishedName; propertiesToLoad[1] = PropertyManager.Cn; propertiesToLoad[2] = PropertyManager.AttributeSyntax; propertiesToLoad[3] = PropertyManager.OMSyntax; propertiesToLoad[4] = PropertyManager.OMObjectClass; propertiesToLoad[5] = PropertyManager.Description; propertiesToLoad[6] = PropertyManager.SearchFlags; propertiesToLoad[7] = PropertyManager.IsMemberOfPartialAttributeSet; propertiesToLoad[8] = PropertyManager.LinkID; propertiesToLoad[9] = PropertyManager.SchemaIDGuid; propertiesToLoad[10] = PropertyManager.RangeLower; propertiesToLoad[11] = PropertyManager.RangeUpper; } else { propertiesToLoad = new string[15]; propertiesToLoad[0] = PropertyManager.DistinguishedName; propertiesToLoad[1] = PropertyManager.Cn; propertiesToLoad[2] = PropertyManager.AttributeSyntax; propertiesToLoad[3] = PropertyManager.OMSyntax; propertiesToLoad[4] = PropertyManager.OMObjectClass; propertiesToLoad[5] = PropertyManager.Description; propertiesToLoad[6] = PropertyManager.SearchFlags; propertiesToLoad[7] = PropertyManager.IsMemberOfPartialAttributeSet; propertiesToLoad[8] = PropertyManager.LinkID; propertiesToLoad[9] = PropertyManager.SchemaIDGuid; propertiesToLoad[10] = PropertyManager.AttributeID; propertiesToLoad[11] = PropertyManager.IsSingleValued; propertiesToLoad[12] = PropertyManager.RangeLower; propertiesToLoad[13] = PropertyManager.RangeUpper; propertiesToLoad[14] = PropertyManager.LdapDisplayName; } // // Get all the values (don't need to use range retrieval as there are no multivalued attributes) // ADSearcher searcher = new ADSearcher(schemaEntry, str.ToString(), propertiesToLoad, SearchScope.OneLevel, false /* paged search */, false /* cache results */); try { propertyValuesFromServer = searcher.FindOne(); } catch (COMException e) { if (e.ErrorCode == unchecked((int)0x80072030)) { // object is not found since we cannot even find the container in which to search throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DSNotFound), typeof(ActiveDirectorySchemaProperty), name); } else { throw ExceptionHelper.GetExceptionFromCOMException(context, e); } } if (propertyValuesFromServer == null) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DSNotFound), typeof(ActiveDirectorySchemaProperty), name); } return propertyValuesFromServer; }
public static ReplicationConnection FindByName(DirectoryContext context, string name) { ReplicationConnection replicationConnection; ReplicationConnection.ValidateArgument(context, name); context = new DirectoryContext(context); DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); try { string propertyValue = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ServerName); string str = string.Concat("CN=NTDS Settings,", propertyValue); directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, str); string[] strArrays = new string[1]; strArrays[0] = "distinguishedName"; ADSearcher aDSearcher = new ADSearcher(directoryEntry, string.Concat("(&(objectClass=nTDSConnection)(objectCategory=NTDSConnection)(name=", Utils.GetEscapedFilterValue(name), "))"), strArrays, SearchScope.OneLevel, false, false); SearchResult searchResult = null; try { searchResult = aDSearcher.FindOne(); } catch (COMException cOMException1) { COMException cOMException = cOMException1; if (cOMException.ErrorCode != -2147016656) { throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException); } else { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ReplicationConnection), name); } } if (searchResult != null) { DirectoryEntry directoryEntry1 = searchResult.GetDirectoryEntry(); replicationConnection = new ReplicationConnection(context, directoryEntry1, name); } else { Exception activeDirectoryObjectNotFoundException = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ReplicationConnection), name); throw activeDirectoryObjectNotFoundException; } } finally { directoryEntry.Dispose(); } return replicationConnection; }
public static ActiveDirectorySiteLink FindByName(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport) { DirectoryEntry directoryEntry; ActiveDirectorySiteLink activeDirectorySiteLink; ActiveDirectorySiteLink.ValidateArgument(context, siteLinkName, transport); context = new DirectoryContext(context); try { directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); string propertyValue = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext); string str = string.Concat("CN=Inter-Site Transports,CN=Sites,", propertyValue); if (transport != ActiveDirectoryTransportType.Rpc) { str = string.Concat("CN=SMTP,", str); } else { str = string.Concat("CN=IP,", str); } directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, str); } catch (COMException cOMException1) { COMException cOMException = cOMException1; throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException); } catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException) { object[] name = new object[1]; name[0] = context.Name; throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", name)); } try { try { string[] strArrays = new string[1]; strArrays[0] = "distinguishedName"; ADSearcher aDSearcher = new ADSearcher(directoryEntry, string.Concat("(&(objectClass=siteLink)(objectCategory=SiteLink)(name=", Utils.GetEscapedFilterValue(siteLinkName), "))"), strArrays, SearchScope.OneLevel, false, false); SearchResult searchResult = aDSearcher.FindOne(); if (searchResult != null) { DirectoryEntry directoryEntry1 = searchResult.GetDirectoryEntry(); ActiveDirectorySiteLink activeDirectorySiteLink1 = new ActiveDirectorySiteLink(context, siteLinkName, transport, true, directoryEntry1); activeDirectorySiteLink = activeDirectorySiteLink1; } else { Exception exception = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySiteLink), siteLinkName); throw exception; } } catch (COMException cOMException3) { COMException cOMException2 = cOMException3; if (cOMException2.ErrorCode != -2147016656) { throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException2); } else { DirectoryEntry directoryEntry2 = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); if (!Utils.CheckCapability(directoryEntry2, Capability.ActiveDirectoryApplicationMode) || transport != ActiveDirectoryTransportType.Smtp) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySiteLink), siteLinkName); } else { throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP")); } } } } finally { directoryEntry.Dispose(); } return(activeDirectorySiteLink); }
internal static string GetServerNameFromInvocationID(string serverObjectDN, Guid invocationID, DirectoryServer server) { string propertyValue = null; DirectoryEntry entry3; if (serverObjectDN == null) { string dn = (server is DomainController) ? ((DomainController) server).SiteObjectName : ((AdamInstance) server).SiteObjectName; DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(server.Context, dn); byte[] data = invocationID.ToByteArray(); IntPtr zero = IntPtr.Zero; string str3 = null; int errorCode = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.ADsEncodeBinaryData(data, data.Length, ref zero); if (errorCode == 0) { try { str3 = Marshal.PtrToStringUni(zero); ADSearcher searcher = new ADSearcher(directoryEntry, "(&(objectClass=nTDSDSA)(invocationID=" + str3 + "))", new string[] { "distinguishedName" }, SearchScope.Subtree, false, false); SearchResult result = null; try { result = searcher.FindOne(); if (result != null) { DirectoryEntry parent = result.GetDirectoryEntry().Parent; propertyValue = (string) PropertyManager.GetPropertyValue(server.Context, parent, PropertyManager.DnsHostName); } return propertyValue; } catch (COMException exception) { throw System.DirectoryServices.ActiveDirectory.ExceptionHelper.GetExceptionFromCOMException(server.Context, exception); } goto Label_010C; } finally { if (zero != IntPtr.Zero) { System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.FreeADsMem(zero); } } } throw System.DirectoryServices.ActiveDirectory.ExceptionHelper.GetExceptionFromCOMException(new COMException(System.DirectoryServices.ActiveDirectory.ExceptionHelper.GetErrorMessage(errorCode, true), errorCode)); } Label_010C: entry3 = DirectoryEntryManager.GetDirectoryEntry(server.Context, serverObjectDN); try { propertyValue = (string) PropertyManager.GetPropertyValue(entry3.Parent, PropertyManager.DnsHostName); } catch (COMException exception2) { if (exception2.ErrorCode != -2147016656) { throw System.DirectoryServices.ActiveDirectory.ExceptionHelper.GetExceptionFromCOMException(server.Context, exception2); } return null; } if (server is AdamInstance) { int num2 = (int) PropertyManager.GetPropertyValue(server.Context, entry3, PropertyManager.MsDSPortLDAP); if (num2 != 0x185) { propertyValue = propertyValue + ":" + num2; } } return propertyValue; }
public static ReplicationConnection FindByName(DirectoryContext context, string name) { ValidateArgument(context, name); context = new DirectoryContext(context); using (DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE)) { string str = (string) PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ServerName); string dn = "CN=NTDS Settings," + str; directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dn); ADSearcher searcher = new ADSearcher(directoryEntry, "(&(objectClass=nTDSConnection)(objectCategory=NTDSConnection)(name=" + Utils.GetEscapedFilterValue(name) + "))", new string[] { "distinguishedName" }, SearchScope.OneLevel, false, false); SearchResult result = null; try { result = searcher.FindOne(); } catch (COMException exception) { if (exception.ErrorCode == -2147016656) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ReplicationConnection), name); } throw ExceptionHelper.GetExceptionFromCOMException(context, exception); } if (result == null) { Exception exception2 = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ReplicationConnection), name); throw exception2; } return new ReplicationConnection(context, result.GetDirectoryEntry(), name); } }
public static ActiveDirectorySubnet FindByName(DirectoryContext context, string subnetName) { DirectoryEntry directoryEntry; ActiveDirectorySubnet activeDirectorySubnet; ActiveDirectorySubnet activeDirectorySubnet1; ActiveDirectorySubnet.ValidateArgument(context, subnetName); context = new DirectoryContext(context); try { directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); string propertyValue = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext); string str = string.Concat("CN=Subnets,CN=Sites,", propertyValue); directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, str); } catch (COMException cOMException1) { COMException cOMException = cOMException1; throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException); } catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException) { object[] name = new object[1]; name[0] = context.Name; throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", name)); } using (directoryEntry) { try { string[] strArrays = new string[1]; strArrays[0] = "distinguishedName"; ADSearcher aDSearcher = new ADSearcher(directoryEntry, string.Concat("(&(objectClass=subnet)(objectCategory=subnet)(name=", Utils.GetEscapedFilterValue(subnetName), "))"), strArrays, SearchScope.OneLevel, false, false); SearchResult searchResult = aDSearcher.FindOne(); if (searchResult != null) { string str1 = null; DirectoryEntry directoryEntry1 = searchResult.GetDirectoryEntry(); if (directoryEntry1.Properties.Contains("siteObject")) { NativeComInterfaces.IAdsPathname pathname = (NativeComInterfaces.IAdsPathname)(new NativeComInterfaces.Pathname()); pathname.EscapedMode = 4; string item = (string)directoryEntry1.Properties["siteObject"][0]; pathname.Set(item, 4); string str2 = pathname.Retrieve(11); str1 = str2.Substring(3); } if (str1 != null) { activeDirectorySubnet = new ActiveDirectorySubnet(context, subnetName, str1, true); } else { activeDirectorySubnet = new ActiveDirectorySubnet(context, subnetName, null, true); } activeDirectorySubnet.cachedEntry = directoryEntry1; activeDirectorySubnet1 = activeDirectorySubnet; } else { Exception exception = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySubnet), subnetName); throw exception; } } catch (COMException cOMException3) { COMException cOMException2 = cOMException3; if (cOMException2.ErrorCode != -2147016656) { throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException2); } else { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySubnet), subnetName); } } } return activeDirectorySubnet1; }
internal static string GetServerNameFromInvocationID(string serverObjectDN, Guid invocationID, DirectoryServer server) { string originatingServerName = null; if (serverObjectDN == null) { // this is the win2k case, we need to get the DSA address first string siteName = (server is DomainController) ? ((DomainController)server).SiteObjectName : ((AdamInstance)server).SiteObjectName; DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(server.Context, siteName); // get the string representation of the invocationID byte[] byteGuid = invocationID.ToByteArray(); IntPtr ptr = (IntPtr)0; string stringGuid = null; // encode the byte arry into binary string representation int hr = UnsafeNativeMethods.ADsEncodeBinaryData(byteGuid, byteGuid.Length, ref ptr); if (hr == 0) { try { stringGuid = Marshal.PtrToStringUni(ptr); } finally { if (ptr != (IntPtr)0) UnsafeNativeMethods.FreeADsMem(ptr); } } else { // throw exception as the call failed throw ExceptionHelper.GetExceptionFromCOMException(new COMException(ExceptionHelper.GetErrorMessage(hr, true), hr)); } ADSearcher adSearcher = new ADSearcher(de, "(&(objectClass=nTDSDSA)(invocationID=" + stringGuid + "))", new string[] { "distinguishedName" }, SearchScope.Subtree, false, /* don't need paged search */ false /* don't need to cache result */); SearchResult srchResult = null; try { srchResult = adSearcher.FindOne(); if (srchResult != null) { DirectoryEntry srvEntry = srchResult.GetDirectoryEntry().Parent; originatingServerName = (string)PropertyManager.GetPropertyValue(server.Context, srvEntry, PropertyManager.DnsHostName); } } catch (COMException e) { throw ExceptionHelper.GetExceptionFromCOMException(server.Context, e); } } else { DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(server.Context, serverObjectDN); try { originatingServerName = (string)PropertyManager.GetPropertyValue(de.Parent, PropertyManager.DnsHostName); } catch (COMException e) { if (e.ErrorCode == unchecked((int)0x80072030)) return null; else throw ExceptionHelper.GetExceptionFromCOMException(server.Context, e); } if (server is AdamInstance) { // we might need to add the port number int portnumber = (int)PropertyManager.GetPropertyValue(server.Context, de, PropertyManager.MsDSPortLDAP); if (portnumber != 389) originatingServerName = originatingServerName + ":" + portnumber; } } return originatingServerName; }
internal static DirectoryEntry GetCrossRefEntry(DirectoryContext context, DirectoryEntry partitionsEntry, string partitionName) { // search for the crossRef that matches this one and // 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.803:="); str.Append((int)SystemFlag.SystemFlagNtdsDomain); str.Append("))("); str.Append(PropertyManager.NCName); str.Append("="); str.Append(Utils.GetEscapedFilterValue(partitionName)); str.Append("))"); string filter = str.ToString(); string[] propertiesToLoad = new string[1]; propertiesToLoad[0] = PropertyManager.DistinguishedName; ADSearcher searcher = new ADSearcher(partitionsEntry, filter, propertiesToLoad, SearchScope.OneLevel, false /*not paged search*/, false /*no cached results*/); SearchResult res = null; try { res = searcher.FindOne(); if (res == null) { // should not happen throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.AppNCNotFound), typeof(ActiveDirectoryPartition), partitionName); } } catch (COMException e) { throw ExceptionHelper.GetExceptionFromCOMException(context, e); } string crossRefDN = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DistinguishedName); return res.GetDirectoryEntry(); }
// // This function returns a hashtable, where key = propertyname (lowercase) and value = ArrayList of values for that property // (It always searches for one object matching the searching criteria and returns the values for the specified properties using // range retrieval) // internal static Hashtable GetValuesWithRangeRetrieval(DirectoryEntry searchRootEntry, string filter, ArrayList propertiesWithRangeRetrieval, ArrayList propertiesWithoutRangeRetrieval, SearchScope searchScope) { ADSearcher searcher = new ADSearcher(searchRootEntry, filter, new string[] { }, searchScope, false /* paged search */, false /* cache results */); SearchResult res = null; int rangeStart = 0; Hashtable results = new Hashtable(); Hashtable propertyNamesWithRangeInfo = new Hashtable(); ArrayList propertyNamesWithoutRangeInfo = new ArrayList(); ArrayList propertiesStillToLoad = new ArrayList(); // // The logic is as follows: // For each property in the propertiesWithRangeRetrieval we add the range as 0-*, e.g. member would be "member;range=0-*" // When the results are returned if the property name is not present or is still "member;range=0-*", then we got the last batch and so we // will not retrieve this property in the next round. However, if the property comes back as "member;range=0-1499" this means // we still have more values to retrieve, so we will retrieve "member;range=5000-*" next time and so on... // // Properties in the propertiesWithoutRangeRetrieval arraylist, we only include the properties in the first search without any range info // foreach (string propertyName in propertiesWithoutRangeRetrieval) { // need to convert to lower case since S.DS returns property names in all lower case string lowerCasePropertyName = propertyName.ToLower(CultureInfo.InvariantCulture); propertyNamesWithoutRangeInfo.Add(lowerCasePropertyName); results.Add(lowerCasePropertyName, new ArrayList()); // add to the seachers's propertiesToLoad searcher.PropertiesToLoad.Add(propertyName); } // keep a list of properties for which we have not yet retrieved all the // results foreach (string propertyName in propertiesWithRangeRetrieval) { // need to convert to lower case since S.DS returns property names in all lower case string lowerCasePropertyName = propertyName.ToLower(CultureInfo.InvariantCulture); propertiesStillToLoad.Add(lowerCasePropertyName); results.Add(lowerCasePropertyName, new ArrayList()); } do { foreach (string propertyName in propertiesStillToLoad) { string propertyToLoad = propertyName + ";range=" + rangeStart + "-*"; searcher.PropertiesToLoad.Add(propertyToLoad); // need to convert to lower case since S.DS returns property names in all lower case propertyNamesWithRangeInfo.Add(propertyName.ToLower(CultureInfo.InvariantCulture), propertyToLoad); } //clear for the nezxt round propertiesStillToLoad.Clear(); res = searcher.FindOne(); if (res != null) { foreach (string propertyNameWithRangeInfo in res.Properties.PropertyNames) { int index = propertyNameWithRangeInfo.IndexOf(';'); string propertyName = null; if (index != -1) { propertyName = propertyNameWithRangeInfo.Substring(0, index); } else { propertyName = propertyNameWithRangeInfo; } if (!propertyNamesWithRangeInfo.Contains(propertyName) && !propertyNamesWithoutRangeInfo.Contains(propertyName)) { // we're not interested in this property (could be adspath), so just skip continue; } ArrayList values = (ArrayList)results[propertyName]; values.AddRange(res.Properties[propertyNameWithRangeInfo]); if (propertyNamesWithRangeInfo.Contains(propertyName)) { // // if this is a property retrieved along with range retrieval, check if we need to include // it in the next round. // string propertyToLoad = (string)propertyNamesWithRangeInfo[propertyName]; if ((propertyNameWithRangeInfo.Length >= propertyToLoad.Length) && (Utils.Compare(propertyToLoad, 0, propertyToLoad.Length, propertyNameWithRangeInfo, 0, propertyToLoad.Length) != 0)) { propertiesStillToLoad.Add(propertyName); rangeStart += res.Properties[propertyNameWithRangeInfo].Count; } } } } else { throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DSNotFound)); } // clear for the next round searcher.PropertiesToLoad.Clear(); propertyNamesWithRangeInfo.Clear(); } while (propertiesStillToLoad.Count > 0); return results; }
public static ApplicationPartition FindByName(DirectoryContext context, string distinguishedName) { DomainControllerInfo domainControllerInfo = null; string item; DirectoryContext newDirectoryContext = null; if (context != null) { if (context.Name != null || context.isRootDomain()) { if (context.Name == null || context.isRootDomain() || context.isADAMConfigSet() || context.isServer()) { if (distinguishedName != null) { if (distinguishedName.Length != 0) { if (Utils.IsValidDNFormat(distinguishedName)) { context = new DirectoryContext(context); DirectoryEntryManager directoryEntryManager = new DirectoryEntryManager(context); DirectoryEntry directoryEntry = null; try { directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, directoryEntryManager.ExpandWellKnownDN(WellKnownDN.PartitionsContainer)); } catch (COMException cOMException1) { COMException cOMException = cOMException1; throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException); } catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException) { object[] name = new object[1]; name[0] = context.Name; throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", name)); } 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.803:="); stringBuilder.Append(2); stringBuilder.Append("))("); stringBuilder.Append(PropertyManager.NCName); stringBuilder.Append("="); stringBuilder.Append(Utils.GetEscapedFilterValue(distinguishedName)); stringBuilder.Append("))"); string str = stringBuilder.ToString(); string[] dnsRoot = new string[2]; dnsRoot[0] = PropertyManager.DnsRoot; dnsRoot[1] = PropertyManager.NCName; ADSearcher aDSearcher = new ADSearcher(directoryEntry, str, dnsRoot, SearchScope.OneLevel, false, false); SearchResult searchResult = null; try { try { searchResult = aDSearcher.FindOne(); } catch (COMException cOMException3) { COMException cOMException2 = cOMException3; if (cOMException2.ErrorCode != -2147016656) { throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException2); } else { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AppNCNotFound"), typeof(ApplicationPartition), distinguishedName); } } } finally { directoryEntry.Dispose(); } if (searchResult != null) { string str1 = null; try { if (searchResult.Properties[PropertyManager.DnsRoot].Count > 0) { item = (string)searchResult.Properties[PropertyManager.DnsRoot][0]; } else { item = null; } str1 = item; } catch (COMException cOMException5) { COMException cOMException4 = cOMException5; throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException4); } ApplicationPartitionType applicationPartitionType = ApplicationPartition.GetApplicationPartitionType(context); if (context.ContextType != DirectoryContextType.DirectoryServer) { if (applicationPartitionType != ApplicationPartitionType.ADApplicationPartition) { string name1 = ConfigurationSet.FindOneAdamInstance(context.Name, context, distinguishedName, null).Name; newDirectoryContext = Utils.GetNewDirectoryContext(name1, DirectoryContextType.DirectoryServer, context); } else { int num = Locator.DsGetDcNameWrapper(null, str1, null, (long)0x8000, out domainControllerInfo); if (num != 0x54b) { if (num == 0) { string str2 = domainControllerInfo.DomainControllerName.Substring(2); newDirectoryContext = Utils.GetNewDirectoryContext(str2, DirectoryContextType.DirectoryServer, context); } else { throw ExceptionHelper.GetExceptionFromErrorCode(num); } } else { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AppNCNotFound"), typeof(ApplicationPartition), distinguishedName); } } } else { bool flag = false; DistinguishedName distinguishedName1 = new DistinguishedName(distinguishedName); DirectoryEntry directoryEntry1 = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); try { try { foreach (string item1 in directoryEntry1.Properties[PropertyManager.NamingContexts]) { DistinguishedName distinguishedName2 = new DistinguishedName(item1); if (!distinguishedName2.Equals(distinguishedName1)) { continue; } flag = true; break; } } catch (COMException cOMException7) { COMException cOMException6 = cOMException7; throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException6); } } finally { directoryEntry1.Dispose(); } if (flag) { newDirectoryContext = context; } else { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AppNCNotFound"), typeof(ApplicationPartition), distinguishedName); } } ApplicationPartition applicationPartition = new ApplicationPartition(newDirectoryContext, (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.NCName), str1, applicationPartitionType, directoryEntryManager); return applicationPartition; } else { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AppNCNotFound"), typeof(ApplicationPartition), distinguishedName); } } else { throw new ArgumentException(Res.GetString("InvalidDNFormat"), "distinguishedName"); } } else { throw new ArgumentException(Res.GetString("EmptyStringParameter"), "distinguishedName"); } } else { throw new ArgumentNullException("distinguishedName"); } } else { throw new ArgumentException(Res.GetString("NotADOrADAM"), "context"); } } else { throw new ArgumentException(Res.GetString("ContextNotAssociatedWithDomain"), "context"); } } else { throw new ArgumentNullException("context"); } }
internal static Hashtable GetValuesWithRangeRetrieval(DirectoryEntry searchRootEntry, string filter, ArrayList propertiesWithRangeRetrieval, ArrayList propertiesWithoutRangeRetrieval, SearchScope searchScope) { ADSearcher searcher = new ADSearcher(searchRootEntry, filter, new string[0], searchScope, false, false); SearchResult result = null; int num = 0; Hashtable hashtable = new Hashtable(); Hashtable hashtable2 = new Hashtable(); ArrayList list = new ArrayList(); ArrayList list2 = new ArrayList(); foreach (string str in propertiesWithoutRangeRetrieval) { string str2 = str.ToLower(CultureInfo.InvariantCulture); list.Add(str2); hashtable.Add(str2, new ArrayList()); searcher.PropertiesToLoad.Add(str); } foreach (string str3 in propertiesWithRangeRetrieval) { string str4 = str3.ToLower(CultureInfo.InvariantCulture); list2.Add(str4); hashtable.Add(str4, new ArrayList()); } do { foreach (string str5 in list2) { string str6 = string.Concat(new object[] { str5, ";range=", num, "-*" }); searcher.PropertiesToLoad.Add(str6); hashtable2.Add(str5.ToLower(CultureInfo.InvariantCulture), str6); } list2.Clear(); result = searcher.FindOne(); if (result == null) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound")); } foreach (string str7 in result.Properties.PropertyNames) { int index = str7.IndexOf(';'); string key = null; if (index != -1) { key = str7.Substring(0, index); } else { key = str7; } if (hashtable2.Contains(key) || list.Contains(key)) { ((ArrayList) hashtable[key]).AddRange(result.Properties[str7]); if (hashtable2.Contains(key)) { string str9 = (string) hashtable2[key]; if ((str7.Length >= str9.Length) && (Compare(str9, 0, str9.Length, str7, 0, str9.Length) != 0)) { list2.Add(key); num += result.Properties[str7].Count; } } } } searcher.PropertiesToLoad.Clear(); hashtable2.Clear(); } while (list2.Count > 0); return hashtable; }
internal static DirectoryEntry GetCrossRefEntry(DirectoryContext context, DirectoryEntry partitionsEntry, string partitionName) { 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.803:="); stringBuilder.Append(2); stringBuilder.Append("))("); stringBuilder.Append(PropertyManager.NCName); stringBuilder.Append("="); stringBuilder.Append(Utils.GetEscapedFilterValue(partitionName)); stringBuilder.Append("))"); string str = stringBuilder.ToString(); string[] distinguishedName = new string[1]; distinguishedName[0] = PropertyManager.DistinguishedName; ADSearcher aDSearcher = new ADSearcher(partitionsEntry, str, distinguishedName, SearchScope.OneLevel, false, false); SearchResult searchResult = null; try { searchResult = aDSearcher.FindOne(); if (searchResult == null) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AppNCNotFound"), typeof(ActiveDirectoryPartition), partitionName); } } catch (COMException cOMException1) { COMException cOMException = cOMException1; throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException); } return searchResult.GetDirectoryEntry(); }
internal static DirectoryEntry GetCrossRefEntry(DirectoryContext context, DirectoryEntry partitionsEntry, string partitionName) { 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(GetEscapedFilterValue(partitionName)); builder.Append("))"); string filter = builder.ToString(); string[] propertiesToLoad = new string[] { PropertyManager.DistinguishedName }; ADSearcher searcher = new ADSearcher(partitionsEntry, filter, propertiesToLoad, SearchScope.OneLevel, false, false); SearchResult res = null; try { res = searcher.FindOne(); if (res == null) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AppNCNotFound"), typeof(ActiveDirectoryPartition), partitionName); } } catch (COMException exception) { throw System.DirectoryServices.ActiveDirectory.ExceptionHelper.GetExceptionFromCOMException(context, exception); } string searchResultPropertyValue = (string) PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DistinguishedName); return res.GetDirectoryEntry(); }
internal static SearchResult GetPropertiesFromSchemaContainer(DirectoryContext context, DirectoryEntry schemaEntry, string name, bool isDefunctOnServer) { string[] distinguishedName; SearchResult searchResult = null; StringBuilder stringBuilder = new StringBuilder(15); stringBuilder.Append("(&("); stringBuilder.Append(PropertyManager.ObjectCategory); stringBuilder.Append("=attributeSchema)"); stringBuilder.Append("("); if (isDefunctOnServer) { stringBuilder.Append(PropertyManager.Cn); } else { stringBuilder.Append(PropertyManager.LdapDisplayName); } stringBuilder.Append("="); stringBuilder.Append(Utils.GetEscapedFilterValue(name)); stringBuilder.Append(")"); if (isDefunctOnServer) { stringBuilder.Append("("); } else { stringBuilder.Append("(!("); } stringBuilder.Append(PropertyManager.IsDefunct); if (isDefunctOnServer) { stringBuilder.Append("=TRUE))"); } else { stringBuilder.Append("=TRUE)))"); } if (isDefunctOnServer) { distinguishedName = new string[15]; distinguishedName[0] = PropertyManager.DistinguishedName; distinguishedName[1] = PropertyManager.Cn; distinguishedName[2] = PropertyManager.AttributeSyntax; distinguishedName[3] = PropertyManager.OMSyntax; distinguishedName[4] = PropertyManager.OMObjectClass; distinguishedName[5] = PropertyManager.Description; distinguishedName[6] = PropertyManager.SearchFlags; distinguishedName[7] = PropertyManager.IsMemberOfPartialAttributeSet; distinguishedName[8] = PropertyManager.LinkID; distinguishedName[9] = PropertyManager.SchemaIDGuid; distinguishedName[10] = PropertyManager.AttributeID; distinguishedName[11] = PropertyManager.IsSingleValued; distinguishedName[12] = PropertyManager.RangeLower; distinguishedName[13] = PropertyManager.RangeUpper; distinguishedName[14] = PropertyManager.LdapDisplayName; } else { distinguishedName = new string[12]; distinguishedName[0] = PropertyManager.DistinguishedName; distinguishedName[1] = PropertyManager.Cn; distinguishedName[2] = PropertyManager.AttributeSyntax; distinguishedName[3] = PropertyManager.OMSyntax; distinguishedName[4] = PropertyManager.OMObjectClass; distinguishedName[5] = PropertyManager.Description; distinguishedName[6] = PropertyManager.SearchFlags; distinguishedName[7] = PropertyManager.IsMemberOfPartialAttributeSet; distinguishedName[8] = PropertyManager.LinkID; distinguishedName[9] = PropertyManager.SchemaIDGuid; distinguishedName[10] = PropertyManager.RangeLower; distinguishedName[11] = PropertyManager.RangeUpper; } ADSearcher aDSearcher = new ADSearcher(schemaEntry, stringBuilder.ToString(), distinguishedName, SearchScope.OneLevel, false, false); try { searchResult = aDSearcher.FindOne(); } catch (COMException cOMException1) { COMException cOMException = cOMException1; if (cOMException.ErrorCode != -2147016656) { throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException); } else { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySchemaProperty), name); } } if (searchResult != null) { return searchResult; } else { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySchemaProperty), name); } }
public static ActiveDirectorySite FindByName(DirectoryContext context, string siteName) { // find an existing site ValidateArgument(context, siteName); // work with copy of the context context = new DirectoryContext(context); // bind to the rootdse to get the configurationnamingcontext DirectoryEntry de; string sitedn; try { de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); sitedn = "CN=Sites," + (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext); de = DirectoryEntryManager.GetDirectoryEntry(context, sitedn); } catch (COMException e) { throw ExceptionHelper.GetExceptionFromCOMException(context, e); } catch (ActiveDirectoryObjectNotFoundException) { // this is the case where the context is a config set and we could not find an ADAM instance in that config set throw new ActiveDirectoryOperationException(Res.GetString(Res.ADAMInstanceNotFoundInConfigSet, context.Name)); } try { ADSearcher adSearcher = new ADSearcher(de, "(&(objectClass=site)(objectCategory=site)(name=" + Utils.GetEscapedFilterValue(siteName) + "))", new string[] { "distinguishedName" }, SearchScope.OneLevel, false, /* don't need paged search */ false /* don't need to cache result */); SearchResult srchResult = adSearcher.FindOne(); if (srchResult == null) { // no such site object throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DSNotFound), typeof(ActiveDirectorySite), siteName); } // it is an existing site object ActiveDirectorySite site = new ActiveDirectorySite(context, siteName, true); return site; } catch (COMException e) { if (e.ErrorCode == unchecked((int)0x80072030)) { // object is not found since we cannot even find the container in which to search throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DSNotFound), typeof(ActiveDirectorySite), siteName); } else { throw ExceptionHelper.GetExceptionFromCOMException(context, e); } } finally { de.Dispose(); } }
public static ActiveDirectorySiteLink FindByName(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport) { ValidateArgument(context, siteLinkName, transport); // work with copy of the context context = new DirectoryContext(context); // bind to the rootdse to get the configurationnamingcontext DirectoryEntry de; try { de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext); string containerDN = "CN=Inter-Site Transports,CN=Sites," + config; if (transport == ActiveDirectoryTransportType.Rpc) containerDN = "CN=IP," + containerDN; else containerDN = "CN=SMTP," + containerDN; de = DirectoryEntryManager.GetDirectoryEntry(context, containerDN); } catch (COMException e) { throw ExceptionHelper.GetExceptionFromCOMException(context, e); } catch (ActiveDirectoryObjectNotFoundException) { // this is the case where the context is a config set and we could not find an ADAM instance in that config set throw new ActiveDirectoryOperationException(Res.GetString(Res.ADAMInstanceNotFoundInConfigSet, context.Name)); } try { ADSearcher adSearcher = new ADSearcher(de, "(&(objectClass=siteLink)(objectCategory=SiteLink)(name=" + Utils.GetEscapedFilterValue(siteLinkName) + "))", new string[] { "distinguishedName" }, SearchScope.OneLevel, false, /* don't need paged search */ false /* don't need to cache result */ ); SearchResult srchResult = adSearcher.FindOne(); if (srchResult == null) { // no such sitelink object Exception e = new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DSNotFound), typeof(ActiveDirectorySiteLink), siteLinkName); throw e; } else { DirectoryEntry connectionEntry = srchResult.GetDirectoryEntry(); // it is an existing site object ActiveDirectorySiteLink link = new ActiveDirectorySiteLink(context, siteLinkName, transport, true, connectionEntry); return link; } } catch (COMException e) { if (e.ErrorCode == unchecked((int)0x80072030)) { // if it is ADAM and transport type is SMTP, throw NotSupportedException. DirectoryEntry tmpDE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); if (Utils.CheckCapability(tmpDE, Capability.ActiveDirectoryApplicationMode) && transport == ActiveDirectoryTransportType.Smtp) { throw new NotSupportedException(Res.GetString(Res.NotSupportTransportSMTP)); } else { // object is not found since we cannot even find the container in which to search throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DSNotFound), typeof(ActiveDirectorySiteLink), siteLinkName); } } throw ExceptionHelper.GetExceptionFromCOMException(context, e); } finally { de.Dispose(); } }
internal static SearchResult GetPropertiesFromSchemaContainer(DirectoryContext context, DirectoryEntry schemaEntry, string name, bool isDefunctOnServer) { SearchResult result = null; StringBuilder builder = new StringBuilder(15); builder.Append("(&("); builder.Append(PropertyManager.ObjectCategory); builder.Append("=attributeSchema)"); builder.Append("("); if (!isDefunctOnServer) { builder.Append(PropertyManager.LdapDisplayName); } else { builder.Append(PropertyManager.Cn); } builder.Append("="); builder.Append(Utils.GetEscapedFilterValue(name)); builder.Append(")"); if (!isDefunctOnServer) { builder.Append("(!("); } else { builder.Append("("); } builder.Append(PropertyManager.IsDefunct); if (!isDefunctOnServer) { builder.Append("=TRUE)))"); } else { builder.Append("=TRUE))"); } string[] propertiesToLoad = null; if (!isDefunctOnServer) { propertiesToLoad = new string[] { PropertyManager.DistinguishedName, PropertyManager.Cn, PropertyManager.AttributeSyntax, PropertyManager.OMSyntax, PropertyManager.OMObjectClass, PropertyManager.Description, PropertyManager.SearchFlags, PropertyManager.IsMemberOfPartialAttributeSet, PropertyManager.LinkID, PropertyManager.SchemaIDGuid, PropertyManager.RangeLower, PropertyManager.RangeUpper }; } else { propertiesToLoad = new string[] { PropertyManager.DistinguishedName, PropertyManager.Cn, PropertyManager.AttributeSyntax, PropertyManager.OMSyntax, PropertyManager.OMObjectClass, PropertyManager.Description, PropertyManager.SearchFlags, PropertyManager.IsMemberOfPartialAttributeSet, PropertyManager.LinkID, PropertyManager.SchemaIDGuid, PropertyManager.AttributeID, PropertyManager.IsSingleValued, PropertyManager.RangeLower, PropertyManager.RangeUpper, PropertyManager.LdapDisplayName }; } ADSearcher searcher = new ADSearcher(schemaEntry, builder.ToString(), propertiesToLoad, SearchScope.OneLevel, false, false); try { result = searcher.FindOne(); } catch (COMException exception) { if (exception.ErrorCode == -2147016656) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySchemaProperty), name); } throw ExceptionHelper.GetExceptionFromCOMException(context, exception); } if (result == null) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySchemaProperty), name); } return(result); }
public static ActiveDirectorySite FindByName(DirectoryContext context, string siteName) { DirectoryEntry directoryEntry; ActiveDirectorySite site2; ValidateArgument(context, siteName); context = new DirectoryContext(context); try { directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); string dn = "CN=Sites," + ((string) PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext)); directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dn); } catch (COMException exception) { throw ExceptionHelper.GetExceptionFromCOMException(context, exception); } catch (ActiveDirectoryObjectNotFoundException) { throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", new object[] { context.Name })); } try { ADSearcher searcher = new ADSearcher(directoryEntry, "(&(objectClass=site)(objectCategory=site)(name=" + Utils.GetEscapedFilterValue(siteName) + "))", new string[] { "distinguishedName" }, SearchScope.OneLevel, false, false); if (searcher.FindOne() == null) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySite), siteName); } site2 = new ActiveDirectorySite(context, siteName, true); } catch (COMException exception2) { if (exception2.ErrorCode == -2147016656) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySite), siteName); } throw ExceptionHelper.GetExceptionFromCOMException(context, exception2); } finally { directoryEntry.Dispose(); } return site2; }
public static ActiveDirectorySubnet FindByName(DirectoryContext context, string subnetName) { ValidateArgument(context, subnetName); // work with copy of the context context = new DirectoryContext(context); // bind to the rootdse to get the configurationnamingcontext DirectoryEntry de; try { de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext); string subnetdn = "CN=Subnets,CN=Sites," + config; de = DirectoryEntryManager.GetDirectoryEntry(context, subnetdn); } catch (COMException e) { throw ExceptionHelper.GetExceptionFromCOMException(context, e); } catch (ActiveDirectoryObjectNotFoundException) { // this is the case where the context is a config set and we could not find an ADAM instance in that config set throw new ActiveDirectoryOperationException(Res.GetString(Res.ADAMInstanceNotFoundInConfigSet, context.Name)); } try { ADSearcher adSearcher = new ADSearcher(de, "(&(objectClass=subnet)(objectCategory=subnet)(name=" + Utils.GetEscapedFilterValue(subnetName) + "))", new string[] { "distinguishedName" }, SearchScope.OneLevel, false, /* don't need paged search */ false /* don't need to cache result */); SearchResult srchResult = adSearcher.FindOne(); if (srchResult == null) { // no such subnet object Exception e = new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DSNotFound), typeof(ActiveDirectorySubnet), subnetName); throw e; } else { string siteName = null; DirectoryEntry connectionEntry = srchResult.GetDirectoryEntry(); // try to get the site that this subnet lives in if (connectionEntry.Properties.Contains("siteObject")) { NativeComInterfaces.IAdsPathname pathCracker = (NativeComInterfaces.IAdsPathname)new NativeComInterfaces.Pathname(); // need to turn off the escaping for name pathCracker.EscapedMode = NativeComInterfaces.ADS_ESCAPEDMODE_OFF_EX; string tmp = (string)connectionEntry.Properties["siteObject"][0]; // escaping manipulation pathCracker.Set(tmp, NativeComInterfaces.ADS_SETTYPE_DN); string rdn = pathCracker.Retrieve(NativeComInterfaces.ADS_FORMAT_LEAF); Debug.Assert(rdn != null && Utils.Compare(rdn, 0, 3, "CN=", 0, 3) == 0); siteName = rdn.Substring(3); } // it is an existing subnet object ActiveDirectorySubnet subnet = null; if (siteName == null) subnet = new ActiveDirectorySubnet(context, subnetName, null, true); else subnet = new ActiveDirectorySubnet(context, subnetName, siteName, true); subnet.cachedEntry = connectionEntry; return subnet; } } catch (COMException e) { if (e.ErrorCode == unchecked((int)0x80072030)) { // object is not found since we cannot even find the container in which to search throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DSNotFound), typeof(ActiveDirectorySubnet), subnetName); } else { throw ExceptionHelper.GetExceptionFromCOMException(context, e); } } finally { if (de != null) de.Dispose(); } }
private void LoadCrossRefAttributes() { DirectoryEntry partitionsEntry = null; try { partitionsEntry = DirectoryEntryManager.GetDirectoryEntry(context, directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.PartitionsContainer)); // now within the partitions container search for the // crossRef object that has it's "dnsRoot" attribute equal to the // dns name of the current domain // 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.DnsRoot); str.Append("="); str.Append(Utils.GetEscapedFilterValue(partitionName)); str.Append("))"); string filter = str.ToString(); string[] propertiesToLoad = new string[2]; propertiesToLoad[0] = PropertyManager.DistinguishedName; propertiesToLoad[1] = PropertyManager.TrustParent; ADSearcher searcher = new ADSearcher(partitionsEntry, filter, propertiesToLoad, SearchScope.OneLevel, false /*not paged search*/, false /*no cached results*/); SearchResult res = searcher.FindOne(); _crossRefDN = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DistinguishedName); // "trustParent" attribute may not be set if (res.Properties[PropertyManager.TrustParent].Count > 0) { _trustParent = (string)res.Properties[PropertyManager.TrustParent][0]; } } catch (COMException e) { throw ExceptionHelper.GetExceptionFromCOMException(context, e); } finally { if (partitionsEntry != null) { partitionsEntry.Dispose(); } } }
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)); }
public static ActiveDirectorySiteLink FindByName(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport) { ValidateArgument(context, siteLinkName, transport); // work with copy of the context context = new DirectoryContext(context); // bind to the rootdse to get the configurationnamingcontext DirectoryEntry de; try { de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext); string containerDN = "CN=Inter-Site Transports,CN=Sites," + config; if (transport == ActiveDirectoryTransportType.Rpc) { containerDN = "CN=IP," + containerDN; } else { containerDN = "CN=SMTP," + containerDN; } de = DirectoryEntryManager.GetDirectoryEntry(context, containerDN); } catch (COMException e) { throw ExceptionHelper.GetExceptionFromCOMException(context, e); } catch (ActiveDirectoryObjectNotFoundException) { // this is the case where the context is a config set and we could not find an ADAM instance in that config set throw new ActiveDirectoryOperationException(String.Format(CultureInfo.CurrentCulture, SR.ADAMInstanceNotFoundInConfigSet, context.Name)); } try { ADSearcher adSearcher = new ADSearcher(de, "(&(objectClass=siteLink)(objectCategory=SiteLink)(name=" + Utils.GetEscapedFilterValue(siteLinkName) + "))", new string[] { "distinguishedName" }, SearchScope.OneLevel, false, /* don't need paged search */ false /* don't need to cache result */ ); SearchResult srchResult = adSearcher.FindOne(); if (srchResult == null) { // no such sitelink object Exception e = new ActiveDirectoryObjectNotFoundException(SR.DSNotFound, typeof(ActiveDirectorySiteLink), siteLinkName); throw e; } else { DirectoryEntry connectionEntry = srchResult.GetDirectoryEntry(); // it is an existing site object ActiveDirectorySiteLink link = new ActiveDirectorySiteLink(context, siteLinkName, transport, true, connectionEntry); return(link); } } catch (COMException e) { if (e.ErrorCode == unchecked ((int)0x80072030)) { // if it is ADAM and transport type is SMTP, throw NotSupportedException. DirectoryEntry tmpDE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); if (Utils.CheckCapability(tmpDE, Capability.ActiveDirectoryApplicationMode) && transport == ActiveDirectoryTransportType.Smtp) { throw new NotSupportedException(SR.NotSupportTransportSMTP); } else { // object is not found since we cannot even find the container in which to search throw new ActiveDirectoryObjectNotFoundException(SR.DSNotFound, typeof(ActiveDirectorySiteLink), siteLinkName); } } throw ExceptionHelper.GetExceptionFromCOMException(context, e); } finally { de.Dispose(); } }
internal static string GetServerNameFromInvocationID(string serverObjectDN, Guid invocationID, DirectoryServer server) { DirectoryEntry directoryEntry; string str; string siteObjectName; string propertyValue = null; if (serverObjectDN != null) { directoryEntry = DirectoryEntryManager.GetDirectoryEntry(server.Context, serverObjectDN); try { propertyValue = (string)PropertyManager.GetPropertyValue(directoryEntry.Parent, PropertyManager.DnsHostName); goto Label0; } catch (COMException cOMException1) { COMException cOMException = cOMException1; if (cOMException.ErrorCode != -2147016656) { throw ExceptionHelper.GetExceptionFromCOMException(server.Context, cOMException); } else { str = null; } } return str; } else { if (server as DomainController != null) { siteObjectName = ((DomainController)server).SiteObjectName; } else { siteObjectName = ((AdamInstance)server).SiteObjectName; } string str1 = siteObjectName; DirectoryEntry directoryEntry1 = DirectoryEntryManager.GetDirectoryEntry(server.Context, str1); byte[] byteArray = invocationID.ToByteArray(); IntPtr intPtr = (IntPtr)0; string stringUni = null; int num = UnsafeNativeMethods.ADsEncodeBinaryData(byteArray, (int)byteArray.Length, ref intPtr); if (num != 0) { throw ExceptionHelper.GetExceptionFromCOMException(new COMException(ExceptionHelper.GetErrorMessage(num, true), num)); } else { try { stringUni = Marshal.PtrToStringUni(intPtr); } finally { if (intPtr != (IntPtr)0) { UnsafeNativeMethods.FreeADsMem(intPtr); } } string[] strArrays = new string[1]; strArrays[0] = "distinguishedName"; ADSearcher aDSearcher = new ADSearcher(directoryEntry1, string.Concat("(&(objectClass=nTDSDSA)(invocationID=", stringUni, "))"), strArrays, SearchScope.Subtree, false, false); try { SearchResult searchResult = aDSearcher.FindOne(); if (searchResult != null) { DirectoryEntry parent = searchResult.GetDirectoryEntry().Parent; propertyValue = (string)PropertyManager.GetPropertyValue(server.Context, parent, PropertyManager.DnsHostName); } } catch (COMException cOMException3) { COMException cOMException2 = cOMException3; throw ExceptionHelper.GetExceptionFromCOMException(server.Context, cOMException2); } } } return propertyValue; Label0: if (server as AdamInstance != null) { int propertyValue1 = (int)PropertyManager.GetPropertyValue(server.Context, directoryEntry, PropertyManager.MsDSPortLDAP); if (propertyValue1 != 0x185) { propertyValue = string.Concat(propertyValue, ":", propertyValue1); return propertyValue; } else { return propertyValue; } } else { return propertyValue; } }
public static ActiveDirectorySite FindByName(DirectoryContext context, string siteName) { DirectoryEntry directoryEntry; ActiveDirectorySite activeDirectorySite; ActiveDirectorySite.ValidateArgument(context, siteName); context = new DirectoryContext(context); try { directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); string str = string.Concat("CN=Sites,", (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext)); directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, str); } catch (COMException cOMException1) { COMException cOMException = cOMException1; throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException); } catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException) { object[] name = new object[1]; name[0] = context.Name; throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", name)); } try { try { string[] strArrays = new string[1]; strArrays[0] = "distinguishedName"; ADSearcher aDSearcher = new ADSearcher(directoryEntry, string.Concat("(&(objectClass=site)(objectCategory=site)(name=", Utils.GetEscapedFilterValue(siteName), "))"), strArrays, SearchScope.OneLevel, false, false); SearchResult searchResult = aDSearcher.FindOne(); if (searchResult != null) { ActiveDirectorySite activeDirectorySite1 = new ActiveDirectorySite(context, siteName, true); activeDirectorySite = activeDirectorySite1; } else { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySite), siteName); } } catch (COMException cOMException3) { COMException cOMException2 = cOMException3; if (cOMException2.ErrorCode != -2147016656) { throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException2); } else { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySite), siteName); } } } finally { directoryEntry.Dispose(); } return activeDirectorySite; }
internal static Hashtable GetValuesWithRangeRetrieval(DirectoryEntry searchRootEntry, string filter, ArrayList propertiesWithRangeRetrieval, ArrayList propertiesWithoutRangeRetrieval, SearchScope searchScope) { string str; ADSearcher aDSearcher = new ADSearcher(searchRootEntry, filter, new string[0], searchScope, false, false); int count = 0; Hashtable hashtables = new Hashtable(); Hashtable hashtables1 = new Hashtable(); ArrayList arrayLists = new ArrayList(); ArrayList arrayLists1 = new ArrayList(); foreach (string str1 in propertiesWithoutRangeRetrieval) { string lower = str1.ToLower(CultureInfo.InvariantCulture); arrayLists.Add(lower); hashtables.Add(lower, new ArrayList()); aDSearcher.PropertiesToLoad.Add(str1); } foreach (string str2 in propertiesWithRangeRetrieval) { string lower1 = str2.ToLower(CultureInfo.InvariantCulture); arrayLists1.Add(lower1); hashtables.Add(lower1, new ArrayList()); } do { foreach (string arrayList in arrayLists1) { object[] objArray = new object[4]; objArray[0] = arrayList; objArray[1] = ";range="; objArray[2] = count; objArray[3] = "-*"; string str3 = string.Concat(objArray); aDSearcher.PropertiesToLoad.Add(str3); hashtables1.Add(arrayList.ToLower(CultureInfo.InvariantCulture), str3); } arrayLists1.Clear(); SearchResult searchResult = aDSearcher.FindOne(); if (searchResult == null) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound")); } else { foreach (string propertyName in searchResult.Properties.PropertyNames) { int num = propertyName.IndexOf(';'); if (num == -1) { str = propertyName; } else { str = propertyName.Substring(0, num); } if (!hashtables1.Contains(str) && !arrayLists.Contains(str)) { continue; } ArrayList item = (ArrayList)hashtables[str]; item.AddRange(searchResult.Properties[propertyName]); if (!hashtables1.Contains(str)) { continue; } string item1 = (string)hashtables1[str]; if (propertyName.Length < item1.Length || Utils.Compare(item1, 0, item1.Length, propertyName, 0, item1.Length) == 0) { continue; } arrayLists1.Add(str); count = count + searchResult.Properties[propertyName].Count; } aDSearcher.PropertiesToLoad.Clear(); hashtables1.Clear(); } } while (arrayLists1.Count > 0); return hashtables; }
public static ActiveDirectorySubnet FindByName(DirectoryContext context, string subnetName) { ValidateArgument(context, subnetName); // work with copy of the context context = new DirectoryContext(context); // bind to the rootdse to get the configurationnamingcontext DirectoryEntry de; try { de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext); string subnetdn = "CN=Subnets,CN=Sites," + config; de = DirectoryEntryManager.GetDirectoryEntry(context, subnetdn); } catch (COMException e) { throw ExceptionHelper.GetExceptionFromCOMException(context, e); } catch (ActiveDirectoryObjectNotFoundException) { // this is the case where the context is a config set and we could not find an ADAM instance in that config set throw new ActiveDirectoryOperationException(Res.GetString(Res.ADAMInstanceNotFoundInConfigSet, context.Name)); } try { ADSearcher adSearcher = new ADSearcher(de, "(&(objectClass=subnet)(objectCategory=subnet)(name=" + Utils.GetEscapedFilterValue(subnetName) + "))", new string[] { "distinguishedName" }, SearchScope.OneLevel, false, /* don't need paged search */ false /* don't need to cache result */); SearchResult srchResult = adSearcher.FindOne(); if (srchResult == null) { // no such subnet object Exception e = new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DSNotFound), typeof(ActiveDirectorySubnet), subnetName); throw e; } else { string siteName = null; DirectoryEntry connectionEntry = srchResult.GetDirectoryEntry(); // try to get the site that this subnet lives in if (connectionEntry.Properties.Contains("siteObject")) { NativeComInterfaces.IAdsPathname pathCracker = (NativeComInterfaces.IAdsPathname) new NativeComInterfaces.Pathname(); // need to turn off the escaping for name pathCracker.EscapedMode = NativeComInterfaces.ADS_ESCAPEDMODE_OFF_EX; string tmp = (string)connectionEntry.Properties["siteObject"][0]; // escaping manipulation pathCracker.Set(tmp, NativeComInterfaces.ADS_SETTYPE_DN); string rdn = pathCracker.Retrieve(NativeComInterfaces.ADS_FORMAT_LEAF); Debug.Assert(rdn != null && Utils.Compare(rdn, 0, 3, "CN=", 0, 3) == 0); siteName = rdn.Substring(3); } // it is an existing subnet object ActiveDirectorySubnet subnet = null; if (siteName == null) { subnet = new ActiveDirectorySubnet(context, subnetName, null, true); } else { subnet = new ActiveDirectorySubnet(context, subnetName, siteName, true); } subnet.cachedEntry = connectionEntry; return(subnet); } } catch (COMException e) { if (e.ErrorCode == unchecked ((int)0x80072030)) { // object is not found since we cannot even find the container in which to search throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DSNotFound), typeof(ActiveDirectorySubnet), subnetName); } else { throw ExceptionHelper.GetExceptionFromCOMException(context, e); } } finally { if (de != null) { de.Dispose(); } } }
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); }