private static DirectoryEntry GetSearchRootEntry(Forest forest) { DirectoryContext directoryContext = forest.GetDirectoryContext(); bool flag = false; bool flag2 = false; AuthenticationTypes defaultAuthType = Utils.DefaultAuthType; if (directoryContext.ContextType == DirectoryContextType.DirectoryServer) { flag = true; DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(directoryContext, WellKnownDN.RootDSE); string str = (string)PropertyManager.GetPropertyValue(directoryContext, directoryEntry, PropertyManager.IsGlobalCatalogReady); flag2 = Utils.Compare(str, "TRUE") == 0; } if (flag) { if (DirectoryContext.ServerBindSupported) { defaultAuthType |= AuthenticationTypes.ServerBind; } if (flag2) { return(new DirectoryEntry("GC://" + directoryContext.GetServerName(), directoryContext.UserName, directoryContext.Password, defaultAuthType)); } return(new DirectoryEntry("LDAP://" + directoryContext.GetServerName(), directoryContext.UserName, directoryContext.Password, defaultAuthType)); } return(new DirectoryEntry("GC://" + forest.Name, directoryContext.UserName, directoryContext.Password, defaultAuthType)); }
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 bool Contains(ActiveDirectorySubnet subnet) { if (subnet != null) { if (subnet.existing) { string propertyValue = (string)PropertyManager.GetPropertyValue(subnet.context, subnet.cachedEntry, PropertyManager.DistinguishedName); int num = 0; while (num < base.InnerList.Count) { ActiveDirectorySubnet item = (ActiveDirectorySubnet)base.InnerList[num]; string str = (string)PropertyManager.GetPropertyValue(item.context, item.cachedEntry, PropertyManager.DistinguishedName); if (Utils.Compare(str, propertyValue) != 0) { num++; } else { return(true); } } return(false); } else { object[] name = new object[1]; name[0] = subnet.Name; throw new InvalidOperationException(Res.GetString("SubnetNotCommitted", name)); } } else { throw new ArgumentNullException("subnet"); } }
public int IndexOf(ReplicationConnection connection) { if (connection != null) { if (connection.existingConnection) { string propertyValue = (string)PropertyManager.GetPropertyValue(connection.context, connection.cachedDirectoryEntry, PropertyManager.DistinguishedName); int num = 0; while (num < base.InnerList.Count) { ReplicationConnection item = (ReplicationConnection)base.InnerList[num]; string str = (string)PropertyManager.GetPropertyValue(item.context, item.cachedDirectoryEntry, PropertyManager.DistinguishedName); if (Utils.Compare(str, propertyValue) != 0) { num++; } else { return(num); } } return(-1); } else { object[] name = new object[1]; name[0] = connection.Name; throw new InvalidOperationException(Res.GetString("ConnectionNotCommitted", name)); } } else { throw new ArgumentNullException("connection"); } }
public ActiveDirectorySubnet(DirectoryContext context, string subnetName) { ValidateArgument(context, subnetName); context = new DirectoryContext(context); this.context = context; this.name = subnetName; DirectoryEntry directoryEntry = null; try { directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); string str = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext); string dn = "CN=Subnets,CN=Sites," + str; directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dn); string escapedPath = Utils.GetEscapedPath("cn=" + this.name); this.cachedEntry = directoryEntry.Children.Add(escapedPath, "subnet"); } catch (COMException exception) { ExceptionHelper.GetExceptionFromCOMException(context, exception); } catch (ActiveDirectoryObjectNotFoundException) { throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", new object[] { context.Name })); } finally { if (directoryEntry != null) { directoryEntry.Dispose(); } } }
public bool Contains(ActiveDirectorySite site) { if (site != null) { string propertyValue = (string)PropertyManager.GetPropertyValue(site.context, site.cachedEntry, PropertyManager.DistinguishedName); int num = 0; while (num < base.InnerList.Count) { ActiveDirectorySite item = (ActiveDirectorySite)base.InnerList[num]; string str = (string)PropertyManager.GetPropertyValue(item.context, item.cachedEntry, PropertyManager.DistinguishedName); if (Utils.Compare(str, propertyValue) != 0) { num++; } else { return(true); } } return(false); } else { throw new ArgumentNullException("site"); } }
protected override void OnInsertComplete(int index, object value) { if (initialized) { ActiveDirectorySubnet subnet = (ActiveDirectorySubnet)value; string dn = (string)PropertyManager.GetPropertyValue(subnet.context, subnet.cachedEntry, PropertyManager.DistinguishedName); try { if (changeList.Contains(dn)) { ((DirectoryEntry)changeList[dn]).Properties["siteObject"].Value = _siteDN; } else { DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(_context, MakePath(dn)); de.Properties["siteObject"].Value = _siteDN; changeList.Add(dn, de); } } catch (COMException e) { throw ExceptionHelper.GetExceptionFromCOMException(_context, e); } } }
public int IndexOf(ReplicationConnection connection) { if (connection == null) { throw new ArgumentNullException("connection"); } if (!connection.existingConnection) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, SR.ConnectionNotCommitted, connection.Name)); } string dn = (string)PropertyManager.GetPropertyValue(connection.context, connection.cachedDirectoryEntry, PropertyManager.DistinguishedName); for (int i = 0; i < InnerList.Count; i++) { ReplicationConnection tmp = (ReplicationConnection)InnerList[i]; string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedDirectoryEntry, PropertyManager.DistinguishedName); if (Utils.Compare(tmpDn, dn) == 0) { return(i); } } return(-1); }
protected override void OnInsertComplete(int index, object value) { if (this.initialized) { ActiveDirectorySubnet subnet = (ActiveDirectorySubnet)value; string key = (string)PropertyManager.GetPropertyValue(subnet.context, subnet.cachedEntry, PropertyManager.DistinguishedName); try { if (this.changeList.Contains(key)) { ((DirectoryEntry)this.changeList[key]).Properties["siteObject"].Value = this.siteDN; } else { DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, this.MakePath(key)); directoryEntry.Properties["siteObject"].Value = this.siteDN; this.changeList.Add(key, directoryEntry); } } catch (COMException exception) { throw ExceptionHelper.GetExceptionFromCOMException(this.context, exception); } } }
public void Remove(ActiveDirectorySiteLink link) { if (link == null) { throw new ArgumentNullException("link"); } if (!link.existing) { throw new InvalidOperationException(Res.GetString(Res.SiteLinkNotCommitted, link.Name)); } string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName); for (int i = 0; i < InnerList.Count; i++) { ActiveDirectorySiteLink tmp = (ActiveDirectorySiteLink)InnerList[i]; string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); if (Utils.Compare(tmpDn, dn) == 0) { List.Remove(tmp); return; } } // something that does not exist in the collectio throw new ArgumentException(Res.GetString(Res.NotFoundInCollection, link), "link"); }
public int IndexOf(ActiveDirectorySiteLink link) { if (link == null) { throw new ArgumentNullException("link"); } if (!link.existing) { throw new InvalidOperationException(Res.GetString(Res.SiteLinkNotCommitted, link.Name)); } string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName); for (int i = 0; i < InnerList.Count; i++) { ActiveDirectorySiteLink tmp = (ActiveDirectorySiteLink)InnerList[i]; string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); if (Utils.Compare(tmpDn, dn) == 0) { return(i); } } return(-1); }
public ActiveDirectorySubnet(DirectoryContext context, string subnetName) { ActiveDirectorySubnet.ValidateArgument(context, subnetName); context = new DirectoryContext(context); this.context = context; this.name = subnetName; DirectoryEntry directoryEntry = null; using (directoryEntry) { 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); string escapedPath = string.Concat("cn=", this.name); escapedPath = Utils.GetEscapedPath(escapedPath); this.cachedEntry = directoryEntry.Children.Add(escapedPath, "subnet"); } catch (COMException cOMException1) { COMException cOMException = cOMException1; ExceptionHelper.GetExceptionFromCOMException(context, cOMException); } catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException) { object[] name = new object[1]; name[0] = context.Name; throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", name)); } } }
public int IndexOf(ActiveDirectorySiteLink link) { if (link != null) { if (link.existing) { string propertyValue = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName); int num = 0; while (num < base.InnerList.Count) { ActiveDirectorySiteLink item = (ActiveDirectorySiteLink)base.InnerList[num]; string str = (string)PropertyManager.GetPropertyValue(item.context, item.cachedEntry, PropertyManager.DistinguishedName); if (Utils.Compare(str, propertyValue) != 0) { num++; } else { return(num); } } return(-1); } else { object[] name = new object[1]; name[0] = link.Name; throw new InvalidOperationException(Res.GetString("SiteLinkNotCommitted", name)); } } else { throw new ArgumentNullException("link"); } }
public int IndexOf(ActiveDirectorySite site) { if (site == null) { throw new ArgumentNullException("site"); } if (!site.existing) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, SR.SiteNotCommitted, site.Name)); } string dn = (string)PropertyManager.GetPropertyValue(site.context, site.cachedEntry, PropertyManager.DistinguishedName); for (int i = 0; i < InnerList.Count; i++) { ActiveDirectorySite tmp = (ActiveDirectorySite)InnerList[i]; string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); if (Utils.Compare(tmpDn, dn) == 0) { return(i); } } return(-1); }
public bool Contains(ReplicationConnection connection) { if (connection == null) { throw new ArgumentNullException(nameof(connection)); } if (!connection.existingConnection) { throw new InvalidOperationException(SR.Format(SR.ConnectionNotCommitted, connection.Name)); } string?dn = (string?)PropertyManager.GetPropertyValue(connection.context, connection.cachedDirectoryEntry, PropertyManager.DistinguishedName); for (int i = 0; i < InnerList.Count; i++) { ReplicationConnection tmp = (ReplicationConnection)InnerList[i] !; string?tmpDn = (string?)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedDirectoryEntry, PropertyManager.DistinguishedName); if (Utils.Compare(tmpDn, dn) == 0) { return(true); } } return(false); }
public bool Contains(ActiveDirectorySiteLink link) { if (link == null) { throw new ArgumentNullException("link"); } if (!link.existing) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, SR.SiteLinkNotCommitted, link.Name)); } string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName); for (int i = 0; i < InnerList.Count; i++) { ActiveDirectorySiteLink tmp = (ActiveDirectorySiteLink)InnerList[i]; string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); if (Utils.Compare(tmpDn, dn) == 0) { return(true); } } return(false); }
public void Remove(ActiveDirectorySite site) { if (site == null) { throw new ArgumentNullException("site"); } if (!site.existing) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, SR.SiteNotCommitted, site.Name)); } string dn = (string)PropertyManager.GetPropertyValue(site.context, site.cachedEntry, PropertyManager.DistinguishedName); for (int i = 0; i < InnerList.Count; i++) { ActiveDirectorySite tmp = (ActiveDirectorySite)InnerList[i]; string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); if (Utils.Compare(tmpDn, dn) == 0) { List.Remove(tmp); return; } } // something that does not exist in the collectio throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SR.NotFoundInCollection, site), "site"); }
public bool Contains(ActiveDirectorySubnet subnet) { if (subnet == null) { throw new ArgumentNullException("subnet"); } if (!subnet.existing) { throw new InvalidOperationException(Res.GetString(Res.SubnetNotCommitted, subnet.Name)); } string dn = (string)PropertyManager.GetPropertyValue(subnet.context, subnet.cachedEntry, PropertyManager.DistinguishedName); for (int i = 0; i < InnerList.Count; i++) { ActiveDirectorySubnet tmp = (ActiveDirectorySubnet)InnerList[i]; string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); if (Utils.Compare(tmpDn, dn) == 0) { return(true); } } return(false); }
public int IndexOf(ActiveDirectorySiteLinkBridge bridge) { if (bridge != null) { string propertyValue = (string)PropertyManager.GetPropertyValue(bridge.context, bridge.cachedEntry, PropertyManager.DistinguishedName); int num = 0; while (num < base.InnerList.Count) { ActiveDirectorySiteLinkBridge item = (ActiveDirectorySiteLinkBridge)base.InnerList[num]; string str = (string)PropertyManager.GetPropertyValue(item.context, item.cachedEntry, PropertyManager.DistinguishedName); if (Utils.Compare(str, propertyValue) != 0) { num++; } else { return(num); } } return(-1); } else { throw new ArgumentNullException("bridge"); } }
public static ActiveDirectorySiteLink FindByName(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport) { DirectoryEntry directoryEntry; ActiveDirectorySiteLink link2; ValidateArgument(context, siteLinkName, transport); context = new DirectoryContext(context); try { directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); string str = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext); string dn = "CN=Inter-Site Transports,CN=Sites," + str; if (transport == ActiveDirectoryTransportType.Rpc) { dn = "CN=IP," + dn; } else { dn = "CN=SMTP," + dn; } 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 { SearchResult result = new ADSearcher(directoryEntry, "(&(objectClass=siteLink)(objectCategory=SiteLink)(name=" + Utils.GetEscapedFilterValue(siteLinkName) + "))", new string[] { "distinguishedName" }, SearchScope.OneLevel, false, false).FindOne(); if (result == null) { Exception exception2 = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySiteLink), siteLinkName); throw exception2; } DirectoryEntry entry = result.GetDirectoryEntry(); link2 = new ActiveDirectorySiteLink(context, siteLinkName, transport, true, entry); } catch (COMException exception3) { if (exception3.ErrorCode != -2147016656) { throw ExceptionHelper.GetExceptionFromCOMException(context, exception3); } if (Utils.CheckCapability(DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE), Capability.ActiveDirectoryApplicationMode) && (transport == ActiveDirectoryTransportType.Smtp)) { throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP")); } throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySiteLink), siteLinkName); } finally { directoryEntry.Dispose(); } return(link2); }
internal static AdamInstance FindAnyAdamInstance(DirectoryContext context) { if (context.ContextType != DirectoryContextType.ConfigurationSet) { DirectoryEntryManager directoryEntryMgr = new DirectoryEntryManager(context); DirectoryEntry cachedDirectoryEntry = directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE); if (!Utils.CheckCapability(cachedDirectoryEntry, Capability.ActiveDirectoryApplicationMode)) { directoryEntryMgr.RemoveIfExists(directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.RootDSE)); throw new ArgumentException(Res.GetString("TargetShouldBeServerORConfigSet"), "context"); } return(new AdamInstance(context, (string)PropertyManager.GetPropertyValue(context, cachedDirectoryEntry, PropertyManager.DnsHostName), directoryEntryMgr)); } DirectoryEntry searchRootEntry = GetSearchRootEntry(Forest.GetCurrentForest()); ArrayList adamInstanceNames = new ArrayList(); try { string text1 = (string)searchRootEntry.Properties["distinguishedName"].Value; StringBuilder builder = new StringBuilder(15); builder.Append("(&("); builder.Append(PropertyManager.ObjectCategory); builder.Append("=serviceConnectionPoint)"); builder.Append("("); builder.Append(PropertyManager.Keywords); builder.Append("=1.2.840.113556.1.4.1851)("); builder.Append(PropertyManager.Keywords); builder.Append("="); builder.Append(Utils.GetEscapedFilterValue(context.Name)); builder.Append("))"); string filter = builder.ToString(); string[] propertiesToLoad = new string[] { PropertyManager.ServiceBindingInformation }; ADSearcher searcher = new ADSearcher(searchRootEntry, filter, propertiesToLoad, SearchScope.Subtree, false, false); using (SearchResultCollection results = searcher.FindAll()) { foreach (SearchResult result in results) { string strB = "ldap://"; foreach (string str4 in result.Properties[PropertyManager.ServiceBindingInformation]) { if ((str4.Length > strB.Length) && (string.Compare(str4.Substring(0, strB.Length), strB, StringComparison.OrdinalIgnoreCase) == 0)) { adamInstanceNames.Add(str4.Substring(strB.Length)); } } } } } catch (COMException exception) { throw ExceptionHelper.GetExceptionFromCOMException(context, exception); } finally { searchRootEntry.Dispose(); } return(FindAliveAdamInstance(null, context, adamInstanceNames)); }
public ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport, ActiveDirectorySchedule schedule) { DirectoryEntry directoryEntry; this.systemDefaultInterval = new TimeSpan(0, 15, 0); this.sites = new ActiveDirectorySiteCollection(); ValidateArgument(context, siteLinkName, transport); context = new DirectoryContext(context); this.context = context; this.name = siteLinkName; this.transport = transport; try { directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); string str = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext); string dn = null; if (transport == ActiveDirectoryTransportType.Rpc) { dn = "CN=IP,CN=Inter-Site Transports,CN=Sites," + str; } else { dn = "CN=SMTP,CN=Inter-Site Transports,CN=Sites," + str; } 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 { string escapedPath = Utils.GetEscapedPath("cn=" + this.name); this.cachedEntry = directoryEntry.Children.Add(escapedPath, "siteLink"); this.cachedEntry.Properties["cost"].Value = 100; this.cachedEntry.Properties["replInterval"].Value = 180; if (schedule != null) { this.cachedEntry.Properties["schedule"].Value = schedule.GetUnmanagedSchedule(); } } catch (COMException exception2) { if (((exception2.ErrorCode == -2147016656) && Utils.CheckCapability(DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE), Capability.ActiveDirectoryApplicationMode)) && (transport == ActiveDirectoryTransportType.Smtp)) { throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP")); } throw ExceptionHelper.GetExceptionFromCOMException(context, exception2); } finally { directoryEntry.Dispose(); } }
private ArrayList GetApplicationPartitions() { ArrayList arrayLists = new ArrayList(); DirectoryEntry cachedDirectoryEntry = this.directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE); DirectoryEntry directoryEntry = this.directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.PartitionsContainer); StringBuilder stringBuilder = new StringBuilder(100); 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(")))"); string str = stringBuilder.ToString(); string[] nCName = new string[2]; nCName[0] = PropertyManager.NCName; nCName[1] = PropertyManager.MsDSNCReplicaLocations; ADSearcher aDSearcher = new ADSearcher(directoryEntry, str, nCName, SearchScope.OneLevel); SearchResultCollection searchResultCollections = null; using (searchResultCollections) { try { searchResultCollections = aDSearcher.FindAll(); string propertyValue = (string)PropertyManager.GetPropertyValue(this.context, cachedDirectoryEntry, PropertyManager.SchemaNamingContext); string propertyValue1 = (string)PropertyManager.GetPropertyValue(this.context, cachedDirectoryEntry, PropertyManager.ConfigurationNamingContext); foreach (SearchResult searchResult in searchResultCollections) { string searchResultPropertyValue = (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.NCName); if (searchResultPropertyValue.Equals(propertyValue) || searchResultPropertyValue.Equals(propertyValue1)) { continue; } ResultPropertyValueCollection item = searchResult.Properties[PropertyManager.MsDSNCReplicaLocations]; if (item.Count <= 0) { continue; } string adamDnsHostNameFromNTDSA = Utils.GetAdamDnsHostNameFromNTDSA(this.context, (string)item[Utils.GetRandomIndex(item.Count)]); DirectoryContext newDirectoryContext = Utils.GetNewDirectoryContext(adamDnsHostNameFromNTDSA, DirectoryContextType.DirectoryServer, this.context); arrayLists.Add(new ApplicationPartition(newDirectoryContext, searchResultPropertyValue, null, ApplicationPartitionType.ADAMApplicationPartition, new DirectoryEntryManager(newDirectoryContext))); } } catch (COMException cOMException1) { COMException cOMException = cOMException1; throw ExceptionHelper.GetExceptionFromCOMException(this.context, cOMException); } } return(arrayLists); }
private void ValidateApplicationPartitionParameters(DirectoryContext context, string distinguishedName, string objectClass, bool objectClassSpecified) { if (context == null) { throw new ArgumentNullException("context"); } if ((context.Name == null) || !context.isServer()) { throw new ArgumentException(Res.GetString("TargetShouldBeServer"), "context"); } if (distinguishedName == null) { throw new ArgumentNullException("distinguishedName"); } if (distinguishedName.Length == 0) { throw new ArgumentException(Res.GetString("EmptyStringParameter"), "distinguishedName"); } base.context = new DirectoryContext(context); base.directoryEntryMgr = new DirectoryEntryManager(base.context); this.dnsName = Utils.GetDnsNameFromDN(distinguishedName); base.partitionName = distinguishedName; if (Utils.GetDNComponents(distinguishedName).Length == 1) { throw new NotSupportedException(Res.GetString("OneLevelPartitionNotSupported")); } this.appType = GetApplicationPartitionType(base.context); if ((this.appType == ApplicationPartitionType.ADApplicationPartition) && objectClassSpecified) { throw new InvalidOperationException(Res.GetString("NoObjectClassForADPartition")); } if (objectClassSpecified) { if (objectClass == null) { throw new ArgumentNullException("objectClass"); } if (objectClass.Length == 0) { throw new ArgumentException(Res.GetString("EmptyStringParameter"), "objectClass"); } } if (this.appType == ApplicationPartitionType.ADApplicationPartition) { string name = null; try { DirectoryEntry cachedDirectoryEntry = base.directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE); name = (string)PropertyManager.GetPropertyValue(base.context, cachedDirectoryEntry, PropertyManager.DnsHostName); } catch (COMException exception) { ExceptionHelper.GetExceptionFromCOMException(base.context, exception); } base.context = Utils.GetNewDirectoryContext(name, DirectoryContextType.DirectoryServer, context); } }
private ArrayList GetApplicationPartitions() { ArrayList list = new ArrayList(); DirectoryEntry cachedDirectoryEntry = this.directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE); DirectoryEntry searchRoot = this.directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.PartitionsContainer); StringBuilder builder = new StringBuilder(100); 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(")))"); string filter = builder.ToString(); string[] propertiesToLoad = new string[] { PropertyManager.NCName, PropertyManager.MsDSNCReplicaLocations }; ADSearcher searcher = new ADSearcher(searchRoot, filter, propertiesToLoad, SearchScope.OneLevel); SearchResultCollection results = null; try { results = searcher.FindAll(); string str2 = (string)PropertyManager.GetPropertyValue(this.context, cachedDirectoryEntry, PropertyManager.SchemaNamingContext); string str3 = (string)PropertyManager.GetPropertyValue(this.context, cachedDirectoryEntry, PropertyManager.ConfigurationNamingContext); foreach (SearchResult result in results) { string searchResultPropertyValue = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.NCName); if (!searchResultPropertyValue.Equals(str2) && !searchResultPropertyValue.Equals(str3)) { ResultPropertyValueCollection values = result.Properties[PropertyManager.MsDSNCReplicaLocations]; if (values.Count > 0) { DirectoryContext context = Utils.GetNewDirectoryContext(Utils.GetAdamDnsHostNameFromNTDSA(this.context, (string)values[Utils.GetRandomIndex(values.Count)]), DirectoryContextType.DirectoryServer, this.context); list.Add(new ApplicationPartition(context, searchResultPropertyValue, null, ApplicationPartitionType.ADAMApplicationPartition, new DirectoryEntryManager(context))); } } } return(list); } catch (COMException exception) { throw ExceptionHelper.GetExceptionFromCOMException(this.context, exception); } finally { if (results != null) { results.Dispose(); } } return(list); }
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(); } }
internal static string ExpandWellKnownDN(DirectoryContext context, WellKnownDN dn) { switch (dn) { case WellKnownDN.RootDSE: return("RootDSE"); case WellKnownDN.DefaultNamingContext: { using (DirectoryEntry entry2 = GetDirectoryEntry(context, "RootDSE")) { return((string)PropertyManager.GetPropertyValue(context, entry2, PropertyManager.DefaultNamingContext)); } } case WellKnownDN.SchemaNamingContext: { using (DirectoryEntry entry3 = GetDirectoryEntry(context, "RootDSE")) { return((string)PropertyManager.GetPropertyValue(context, entry3, PropertyManager.SchemaNamingContext)); } } case WellKnownDN.ConfigurationNamingContext: { using (DirectoryEntry entry4 = GetDirectoryEntry(context, "RootDSE")) { return((string)PropertyManager.GetPropertyValue(context, entry4, PropertyManager.ConfigurationNamingContext)); } } case WellKnownDN.PartitionsContainer: return("CN=Partitions," + ExpandWellKnownDN(context, WellKnownDN.ConfigurationNamingContext)); case WellKnownDN.SitesContainer: return("CN=Sites," + ExpandWellKnownDN(context, WellKnownDN.ConfigurationNamingContext)); case WellKnownDN.SystemContainer: return("CN=System," + ExpandWellKnownDN(context, WellKnownDN.DefaultNamingContext)); case WellKnownDN.RidManager: return("CN=RID Manager$," + ExpandWellKnownDN(context, WellKnownDN.SystemContainer)); case WellKnownDN.Infrastructure: return("CN=Infrastructure," + ExpandWellKnownDN(context, WellKnownDN.DefaultNamingContext)); case WellKnownDN.RootDomainNamingContext: { using (DirectoryEntry entry = GetDirectoryEntry(context, "RootDSE")) { return((string)PropertyManager.GetPropertyValue(context, entry, PropertyManager.RootDomainNamingContext)); } } } throw new InvalidEnumArgumentException("dn", (int)dn, typeof(WellKnownDN)); }
public ReplicationSecurityLevel GetSecurityLevel() { CheckIfDisposed(); if (_cachedSecurityLevel == (ReplicationSecurityLevel)(-1)) { DirectoryEntry configEntry = _directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.ConfigurationNamingContext); _cachedSecurityLevel = (ReplicationSecurityLevel)((int)PropertyManager.GetPropertyValue(_context, configEntry, PropertyManager.MsDSReplAuthenticationMode)); } return(_cachedSecurityLevel); }
public ReplicationSecurityLevel GetSecurityLevel() { this.CheckIfDisposed(); if (this.cachedSecurityLevel == ~ReplicationSecurityLevel.NegotiatePassThrough) { DirectoryEntry cachedDirectoryEntry = this.directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.ConfigurationNamingContext); this.cachedSecurityLevel = (ReplicationSecurityLevel)((int)PropertyManager.GetPropertyValue(this.context, cachedDirectoryEntry, PropertyManager.MsDSReplAuthenticationMode)); } return(this.cachedSecurityLevel); }
internal string ExpandWellKnownDN(WellKnownDN dn) { string propertyValue = null; WellKnownDN wellKnownDN = dn; if (wellKnownDN == WellKnownDN.RootDSE) { propertyValue = "RootDSE"; } else if (wellKnownDN == WellKnownDN.DefaultNamingContext) { DirectoryEntry cachedDirectoryEntry = this.GetCachedDirectoryEntry("RootDSE"); propertyValue = (string)PropertyManager.GetPropertyValue(this.context, cachedDirectoryEntry, PropertyManager.DefaultNamingContext); } else if (wellKnownDN == WellKnownDN.SchemaNamingContext) { DirectoryEntry directoryEntry = this.GetCachedDirectoryEntry("RootDSE"); propertyValue = (string)PropertyManager.GetPropertyValue(this.context, directoryEntry, PropertyManager.SchemaNamingContext); } else if (wellKnownDN == WellKnownDN.ConfigurationNamingContext) { DirectoryEntry cachedDirectoryEntry1 = this.GetCachedDirectoryEntry("RootDSE"); propertyValue = (string)PropertyManager.GetPropertyValue(this.context, cachedDirectoryEntry1, PropertyManager.ConfigurationNamingContext); } else if (wellKnownDN == WellKnownDN.PartitionsContainer) { propertyValue = string.Concat("CN=Partitions,", this.ExpandWellKnownDN(WellKnownDN.ConfigurationNamingContext)); } else if (wellKnownDN == WellKnownDN.SitesContainer) { propertyValue = string.Concat("CN=Sites,", this.ExpandWellKnownDN(WellKnownDN.ConfigurationNamingContext)); } else if (wellKnownDN == WellKnownDN.SystemContainer) { propertyValue = string.Concat("CN=System,", this.ExpandWellKnownDN(WellKnownDN.DefaultNamingContext)); } else if (wellKnownDN == WellKnownDN.RidManager) { propertyValue = string.Concat("CN=RID Manager$,", this.ExpandWellKnownDN(WellKnownDN.SystemContainer)); } else if (wellKnownDN == WellKnownDN.Infrastructure) { propertyValue = string.Concat("CN=Infrastructure,", this.ExpandWellKnownDN(WellKnownDN.DefaultNamingContext)); } else if (wellKnownDN == WellKnownDN.RootDomainNamingContext) { DirectoryEntry directoryEntry1 = this.GetCachedDirectoryEntry("RootDSE"); propertyValue = (string)PropertyManager.GetPropertyValue(this.context, directoryEntry1, PropertyManager.RootDomainNamingContext); } else { throw new InvalidEnumArgumentException("dn", (int)dn, typeof(WellKnownDN)); } return(propertyValue); }