public static void ValidatePartitionDN(ADRootDSE rootDSE, string partitionDN) { IEnumerable <string> partitionList; if (ADForestPartitionInfo.IsValidPartitionDN(rootDSE, partitionDN, false) || ADForestPartitionInfo.IsValidPartitionDN(rootDSE, partitionDN, true)) { return; } else { CultureInfo currentCulture = CultureInfo.CurrentCulture; string invalidPartitionMustBelongToValidSet = StringResources.InvalidPartitionMustBelongToValidSet; object[] objArray = new object[1]; object[] objArray1 = objArray; int num = 0; if (rootDSE.SessionInfo.ConnectedToGC) { partitionList = ADForestPartitionInfo.GetForestPartitionInfo(rootDSE).PartitionList; } else { partitionList = rootDSE.NamingContexts; } objArray1[num] = ADForestPartitionInfo.ConcatList(partitionList, " , "); throw new ArgumentException(string.Format(currentCulture, invalidPartitionMustBelongToValidSet, objArray)); } }
internal string GetRDNPrefix(string objectClass) { ADObject aDObject; ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(this._sessionInfo); using (aDObjectSearcher) { ADRootDSE rootDSE = aDObjectSearcher.GetRootDSE(); aDObjectSearcher.SearchRoot = rootDSE.SchemaNamingContext; aDObjectSearcher.Properties.Add("rDNAttID"); IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "classSchema"); IADOPathNode aDOPathNode1 = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "lDAPDisplayName", objectClass); IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2]; aDOPathNodeArray[0] = aDOPathNode; aDOPathNodeArray[1] = aDOPathNode1; IADOPathNode aDOPathNode2 = ADOPathUtil.CreateAndClause(aDOPathNodeArray); aDObjectSearcher.Filter = aDOPathNode2; aDObject = aDObjectSearcher.FindOne(); } if (aDObject == null) { return(null); } else { return((string)aDObject["rDNAttID"][0]); } }
public ADRootDSE GetRootDSE() { this.Init(); ADRootDSE rootDSE = this._adSession.RootDSE; if (rootDSE == null) { string[] strArrays = new string[2]; strArrays[0] = "*"; strArrays[1] = "msDS-PortLDAP"; ADSearchRequest aDSearchRequest = new ADSearchRequest("", ADObjectSearcher.DefaultSearchFilter.GetLdapFilterString(), SearchScope.Base, strArrays); aDSearchRequest.TimeLimit = this._timeLimit; ADSearchResponse aDSearchResponse = this._syncOps.Search(this._sessionHandle, aDSearchRequest); if (aDSearchResponse.Entries.Count > 0) { rootDSE = new ADRootDSE(); ADObject item = aDSearchResponse.Entries[0]; foreach (string propertyName in item.PropertyNames) { rootDSE.Add(propertyName, item[propertyName]); } this._adSession.RootDSE = rootDSE; } return(rootDSE); } else { return(rootDSE); } }
public static string ExtractAndValidatePartitionInfo(ADRootDSE rootDSE, string objectDN) { IEnumerable <string> partitionList; string str = ADForestPartitionInfo.ExtractPartitionInfo(rootDSE, objectDN, false); if (str == null) { str = ADForestPartitionInfo.ExtractPartitionInfo(rootDSE, objectDN, true); if (str == null) { CultureInfo currentCulture = CultureInfo.CurrentCulture; string invalidDNMustBelongToValidPartitionSet = StringResources.InvalidDNMustBelongToValidPartitionSet; object[] objArray = new object[1]; object[] objArray1 = objArray; int num = 0; if (rootDSE.SessionInfo.ConnectedToGC) { partitionList = ADForestPartitionInfo.GetForestPartitionInfo(rootDSE).PartitionList; } else { partitionList = rootDSE.NamingContexts; } objArray1[num] = ADForestPartitionInfo.ConcatList(partitionList, " , "); throw new ArgumentException(string.Format(currentCulture, invalidDNMustBelongToValidPartitionSet, objArray)); } } return(str); }
public ADRootDSE GetRootDSE(ICollection <string> propertyList, bool propertyNamesOnly) { this.Init(); ADRootDSE aDRootDSE = null; string[] strArrays = null; if (propertyList != null) { strArrays = new string[propertyList.Count]; propertyList.CopyTo(strArrays, 0); } ADSearchRequest aDSearchRequest = new ADSearchRequest("", ADObjectSearcher.DefaultSearchFilter.GetLdapFilterString(), SearchScope.Base, strArrays); aDSearchRequest.TypesOnly = propertyNamesOnly; aDSearchRequest.TimeLimit = this._timeLimit; ADSearchResponse aDSearchResponse = this._syncOps.Search(this._sessionHandle, aDSearchRequest); if (aDSearchResponse.Entries.Count > 0) { aDRootDSE = new ADRootDSE(); ADObject item = aDSearchResponse.Entries[0]; foreach (string propertyName in item.PropertyNames) { aDRootDSE.Add(propertyName, item[propertyName]); } } return(aDRootDSE); }
private void Init() { if (this._schemaProperties == null) { ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(this._sessionInfo); { ADRootDSE rootDSE = aDObjectSearcher.GetRootDSE(); this._subSchemaDN = rootDSE.SubSchemaSubEntry; ADSchema aDSchema = null; lock (ADSchema._schemaTableLock) { ADSchema._schemaTable.TryGetValue(this._subSchemaDN, out aDSchema); } if (aDSchema != null) { this._schemaProperties = aDSchema._schemaProperties; this._userSubClasses = aDSchema._userSubClasses; this._schemaClasses = aDSchema._schemaClasses; this._schemaClassesDnHash = aDSchema._schemaClassesDnHash; } if (this._schemaProperties == null) { if (rootDSE.ServerType == ADServerType.ADDS && this._sessionInfo.ConnectedToGC) { this._sessionInfo.SetEffectivePort(LdapConstants.LDAP_PORT); aDObjectSearcher.Dispose(); aDObjectSearcher = new ADObjectSearcher(this._sessionInfo); } this._schemaProperties = new Dictionary <string, ADSchemaAttribute>(1, StringComparer.OrdinalIgnoreCase); this.ReadConstructedSchema(aDObjectSearcher, this); this.ReadObjectSchema(aDObjectSearcher, this); this._userSubClasses = this.GetUserSubClasses(aDObjectSearcher, rootDSE); } else { return; } } aDObjectSearcher.Dispose(); lock (ADSchema._schemaTableLock) { if (ADSchema._schemaTable.ContainsKey(this._subSchemaDN)) { ADSchema._schemaTable.Remove(this._subSchemaDN); } ADSchema._schemaTable.Add(this._subSchemaDN, this); } return; } else { return; } }
private void Refresh(ADRootDSE rootDSE) { if (rootDSE != null) { if (rootDSE.SessionInfo != null) { if (this._forestId.Equals(rootDSE.SubSchemaSubEntry, StringComparison.OrdinalIgnoreCase)) { object[] objArray = new object[1]; objArray[0] = this._forestId; DebugLogger.LogInfo("ADForestPartitionInfo", "Refreshing PartitionList of Forest: {0}", objArray); List <string> strs = new List <string>(); ADSessionInfo sessionInfo = rootDSE.SessionInfo; if (rootDSE.ServerType == ADServerType.ADDS && sessionInfo.ConnectedToGC) { sessionInfo = sessionInfo.Copy(); sessionInfo.SetEffectivePort(LdapConstants.LDAP_PORT); } using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(sessionInfo)) { aDObjectSearcher.SchemaTranslation = false; aDObjectSearcher.SearchRoot = string.Concat("CN=Partitions,", rootDSE.ConfigurationNamingContext); aDObjectSearcher.Properties.Add("nCName"); aDObjectSearcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "crossRef"); foreach (ADObject aDObject in aDObjectSearcher.FindAll()) { if (aDObject["nCName"] == null || aDObject["nCName"].Count <= 0) { continue; } strs.Add((string)aDObject["nCName"][0]); } this._forestPartitionList = new ReadOnlyCollection <string>(strs); } return; } else { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ForestIdDoesNotMatch, new object[0])); } } else { throw new ArgumentNullException("rootDSE.SessionInfo"); } } else { throw new ArgumentNullException("rootDSE"); } }
private static IEnumerable <string> GetValidPartitionList(ADRootDSE rootDSE, bool refreshForestPartitionList) { if (rootDSE.SessionInfo == null || !rootDSE.SessionInfo.ConnectedToGC) { return(rootDSE.NamingContexts); } else { if (refreshForestPartitionList) { ADForestPartitionInfo.GetForestPartitionInfo(rootDSE).Refresh(rootDSE); } return(ADForestPartitionInfo.GetForestPartitionInfo(rootDSE).PartitionList); } }
private void ReadConstructedSchema(ADObjectSearcher searcher, ADSchema adSchema) { searcher.SchemaTranslation = false; ADRootDSE rootDSE = searcher.GetRootDSE(); searcher.SearchRoot = rootDSE.SubSchemaSubEntry; searcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*"); searcher.Scope = ADSearchScope.Base; searcher.Properties.Clear(); searcher.Properties.Add("extendedAttributeInfo"); searcher.Properties.Add("attributeTypes"); ADObject aDObject = searcher.FindOne(); int success = SchemaConstants.AttributeTypesRegex.GroupNumberFromName(SchemaConstants.NameGroup); int num = SchemaConstants.AttributeTypesRegex.GroupNumberFromName(SchemaConstants.SyntaxGroup); int num1 = SchemaConstants.AttributeTypesRegex.GroupNumberFromName(SchemaConstants.SingleValueGroup); adSchema._schemaProperties = new Dictionary <string, ADSchemaAttribute>(1, StringComparer.OrdinalIgnoreCase); foreach (string item in aDObject["attributeTypes"]) { Match match = SchemaConstants.AttributeTypesRegex.Match(item); if (match != null) { if (!match.Groups[success].Success) { DebugLogger.LogError("adschema", string.Format("AttributeType {0} no match on Name", item)); } if (!match.Groups[num].Success) { DebugLogger.LogError("adschema", string.Format("AttributeType {0} no match on Syntax", item)); } adSchema._schemaProperties.Add(match.Groups[success].Value, new ADSchemaAttribute(ADSyntax.OIDToSyntax(match.Groups[num].Value), match.Groups[num1].Success, false)); } else { DebugLogger.LogError("adschema", string.Format("unable to match AttributeType {0}", item)); throw new ADException(); } } success = SchemaConstants.ExtendedAttrInfoRegex.GroupNumberFromName(SchemaConstants.NameGroup); int num2 = SchemaConstants.ExtendedAttrInfoRegex.GroupNumberFromName(SchemaConstants.SystemOnlyGroup); foreach (string str in aDObject["extendedAttributeInfo"]) { Match match1 = SchemaConstants.ExtendedAttrInfoRegex.Match(str); adSchema._schemaProperties[match1.Groups[success].Value].IsSystemOnly = match1.Groups[num2].Success; } }
internal static IEnumerable <string> ConstructPartitionList(ADRootDSE rootDSE, IEnumerable <string> partitionList, bool refreshForestPartitionList) { IEnumerable <string> validPartitionList; HashSet <string> strs = new HashSet <string>(StringComparer.OrdinalIgnoreCase); IEnumerator <string> enumerator = partitionList.GetEnumerator(); using (enumerator) { while (enumerator.MoveNext()) { string current = enumerator.Current; string str = null; try { str = ADForestPartitionInfo.ConvertFriendlyPartition(rootDSE, current); } catch (ADIdentityNotFoundException aDIdentityNotFoundException) { continue; } if (str == null) { if (!string.Equals(current, "*", StringComparison.OrdinalIgnoreCase)) { if (string.IsNullOrEmpty(current) || !ADForestPartitionInfo.IsValidPartitionDN(rootDSE, current, refreshForestPartitionList)) { continue; } strs.Add(current); } else { validPartitionList = ADForestPartitionInfo.GetValidPartitionList(rootDSE, refreshForestPartitionList); return(validPartitionList); } } else { strs.Add(str); } } return(strs); } return(validPartitionList); }
internal static IEnumerable<string> ConstructPartitionList(ADRootDSE rootDSE, IEnumerable<string> partitionList, bool refreshForestPartitionList) { IEnumerable<string> validPartitionList; HashSet<string> strs = new HashSet<string>(StringComparer.OrdinalIgnoreCase); IEnumerator<string> enumerator = partitionList.GetEnumerator(); using (enumerator) { while (enumerator.MoveNext()) { string current = enumerator.Current; string str = null; try { str = ADForestPartitionInfo.ConvertFriendlyPartition(rootDSE, current); } catch (ADIdentityNotFoundException aDIdentityNotFoundException) { continue; } if (str == null) { if (!string.Equals(current, "*", StringComparison.OrdinalIgnoreCase)) { if (string.IsNullOrEmpty(current) || !ADForestPartitionInfo.IsValidPartitionDN(rootDSE, current, refreshForestPartitionList)) { continue; } strs.Add(current); } else { validPartitionList = ADForestPartitionInfo.GetValidPartitionList(rootDSE, refreshForestPartitionList); return validPartitionList; } } else { strs.Add(str); } } return strs; } return validPartitionList; }
private void ReadObjectSchema(ADObjectSearcher searcher, ADSchema adSchema) { searcher.SchemaTranslation = false; ADRootDSE rootDSE = searcher.GetRootDSE(); searcher.SearchRoot = rootDSE.SchemaNamingContext; IADOPathNode[] aDOPathNodeArray = new IADOPathNode[3]; aDOPathNodeArray[0] = ADOPathUtil.CreateNotClause(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "isDefunct", true)); aDOPathNodeArray[1] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "attributeSchema"); IADOPathNode[] aDOPathNodeArray1 = new IADOPathNode[3]; aDOPathNodeArray1[0] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "attributeSyntax", SchemaConstants.SidAttributeSyntax); aDOPathNodeArray1[1] = ADOPathUtil.CreateFilterClause(ADOperator.Like, "linkID", "*"); aDOPathNodeArray1[2] = ADOPathUtil.CreateFilterClause(ADOperator.Band, "systemFlags", SchemaConstants.systemFlagsConstructedBitMask); aDOPathNodeArray[2] = ADOPathUtil.CreateOrClause(aDOPathNodeArray1); searcher.Filter = ADOPathUtil.CreateAndClause(aDOPathNodeArray); searcher.Scope = ADSearchScope.Subtree; searcher.PageSize = 0x100; searcher.Properties.Clear(); searcher.Properties.Add("lDAPDisplayName"); searcher.Properties.Add("linkID"); searcher.Properties.Add("systemFlags"); searcher.Properties.Add("attributeSyntax"); IEnumerable <ADObject> aDObjects = searcher.FindAll(); foreach (ADObject nullable in aDObjects) { if (adSchema._schemaProperties.ContainsKey((string)nullable["lDAPDisplayName"].Value)) { if (nullable.Contains("linkID")) { adSchema._schemaProperties[(string)nullable["lDAPDisplayName"].Value].LinkID = new int?(int.Parse(nullable["linkID"].Value as string, NumberFormatInfo.InvariantInfo)); } if (nullable.Contains("systemFlags") && (long)0 != (ulong.Parse(nullable["systemFlags"].Value as string, NumberFormatInfo.InvariantInfo) & SchemaConstants.systemFlagsConstructedBitMask)) { adSchema._schemaProperties[(string)nullable["lDAPDisplayName"].Value].IsConstructed = true; } if (!nullable.Contains("attributeSyntax") || string.Compare(nullable["attributeSyntax"].Value as string, SchemaConstants.SidAttributeSyntax, true) != 0) { continue; } adSchema._schemaProperties[(string)nullable["lDAPDisplayName"].Value].Syntax = ADAttributeSyntax.Sid; } } }
private static bool IsValidPartitionDN(ADRootDSE rootDSE, string partitionDN, bool refreshForestPartitionList) { bool flag; if (rootDSE != null) { if (partitionDN != null) { if (rootDSE.SessionInfo == null || !rootDSE.SessionInfo.ConnectedToGC || !partitionDN.Equals(string.Empty)) { IEnumerable <string> validPartitionList = ADForestPartitionInfo.GetValidPartitionList(rootDSE, refreshForestPartitionList); IEnumerator <string> enumerator = validPartitionList.GetEnumerator(); using (enumerator) { while (enumerator.MoveNext()) { string current = enumerator.Current; if (!ADPathModule.ComparePath(partitionDN, current, ADPathFormat.X500)) { continue; } flag = true; return(flag); } return(false); } return(flag); } else { return(true); } } else { throw new ArgumentNullException("partitionDN"); } } else { throw new ArgumentNullException("rootDSE"); } }
private static ADForestPartitionInfo GetForestPartitionInfo(ADRootDSE rootDSE) { if (rootDSE != null) { string subSchemaSubEntry = rootDSE.SubSchemaSubEntry; ADForestPartitionInfo aDForestPartitionInfo = null; lock (ADForestPartitionInfo._forestInfoTableLock) { ADForestPartitionInfo._forestInfoTable.TryGetValue(subSchemaSubEntry, out aDForestPartitionInfo); } if (aDForestPartitionInfo == null) { object[] objArray = new object[1]; objArray[0] = rootDSE.SubSchemaSubEntry; DebugLogger.LogInfo("ADForestPartitionInfo", "Getting forest info from server for Forest: {0}", objArray); aDForestPartitionInfo = new ADForestPartitionInfo(rootDSE); lock (ADForestPartitionInfo._forestInfoTableLock) { if (ADForestPartitionInfo._forestInfoTable.ContainsKey(subSchemaSubEntry)) { ADForestPartitionInfo._forestInfoTable.Remove(subSchemaSubEntry); } ADForestPartitionInfo._forestInfoTable.Add(subSchemaSubEntry, aDForestPartitionInfo); } return(aDForestPartitionInfo); } else { object[] subSchemaSubEntry1 = new object[1]; subSchemaSubEntry1[0] = rootDSE.SubSchemaSubEntry; DebugLogger.LogInfo("ADForestPartitionInfo", "Found ADForestPartitionInfo for Forest: {0} in Cache", subSchemaSubEntry1); return(aDForestPartitionInfo); } } else { throw new ArgumentNullException("rootDSE"); } }
private void PopulateSchemaClasses() { if (this._schemaClasses == null) { ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(this._sessionInfo); { ADRootDSE rootDSE = aDObjectSearcher.GetRootDSE(); this._subSchemaDN = rootDSE.SubSchemaSubEntry; if (rootDSE.ServerType == ADServerType.ADDS && this._sessionInfo.ConnectedToGC) { this._sessionInfo.SetEffectivePort(LdapConstants.LDAP_PORT); aDObjectSearcher.Dispose(); aDObjectSearcher = new ADObjectSearcher(this._sessionInfo); } this._schemaClasses = new Dictionary <string, ADObject>(1, StringComparer.OrdinalIgnoreCase); this._schemaClassesDnHash = new Dictionary <string, string>(1, StringComparer.OrdinalIgnoreCase); this.AddSchemaClassObjects(aDObjectSearcher, this); } aDObjectSearcher.Dispose(); lock (ADSchema._schemaTableLock) { ADSchema aDSchema = null; lock (ADSchema._schemaTableLock) { ADSchema._schemaTable.TryGetValue(this._subSchemaDN, out aDSchema); if (aDSchema != null) { aDSchema._schemaClasses = this._schemaClasses; aDSchema._schemaClassesDnHash = this._schemaClassesDnHash; } } } return; } else { return; } }
internal static string ExtractPartitionInfo(ADRootDSE rootDSE, string objectDN, bool refreshForestPartitionList) { string str = null; if (rootDSE != null) { if (objectDN != null) { if (rootDSE.SessionInfo == null || !rootDSE.SessionInfo.ConnectedToGC || !objectDN.Equals(string.Empty)) { IEnumerable <string> validPartitionList = ADForestPartitionInfo.GetValidPartitionList(rootDSE, refreshForestPartitionList); int length = -1; foreach (string str1 in validPartitionList) { if (str1.Length <= length || !ADPathModule.IsChildPath(objectDN, str1, true, ADPathFormat.X500)) { continue; } length = str1.Length; str = str1; } return(str); } else { return(string.Empty); } } else { throw new ArgumentNullException("objectDN"); } } else { throw new ArgumentNullException("rootDSE"); } }
internal static bool IsDNUnderPartition(ADRootDSE rootDSE, string objectDN, bool refreshForestPartitionList) { bool flag; if (rootDSE != null) { if (!string.IsNullOrEmpty(objectDN)) { IEnumerable <string> validPartitionList = ADForestPartitionInfo.GetValidPartitionList(rootDSE, refreshForestPartitionList); IEnumerator <string> enumerator = validPartitionList.GetEnumerator(); using (enumerator) { while (enumerator.MoveNext()) { string current = enumerator.Current; if (!ADPathModule.IsChildPath(objectDN, current, true, ADPathFormat.X500)) { continue; } flag = true; return(flag); } return(false); } return(flag); } else { return(false); } } else { throw new ArgumentNullException("rootDSE"); } }
private HashSet <string> GetUserSubClasses(ADObjectSearcher searcher, ADRootDSE rootDSE) { HashSet <string> strs = new HashSet <string>(StringComparer.OrdinalIgnoreCase); searcher.SearchRoot = rootDSE.SchemaNamingContext; searcher.Properties.Add("lDAPDisplayName"); string str = string.Concat("CN=Person,", rootDSE.SchemaNamingContext); IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "classSchema"); IADOPathNode aDOPathNode1 = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "subClassOf", "user"); IADOPathNode aDOPathNode2 = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "defaultObjectCategory", str); IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2]; aDOPathNodeArray[0] = aDOPathNode; IADOPathNode[] aDOPathNodeArray1 = new IADOPathNode[2]; aDOPathNodeArray1[0] = aDOPathNode1; aDOPathNodeArray1[1] = aDOPathNode2; aDOPathNodeArray[1] = ADOPathUtil.CreateAndClause(aDOPathNodeArray1); IADOPathNode aDOPathNode3 = ADOPathUtil.CreateAndClause(aDOPathNodeArray); searcher.Filter = aDOPathNode3; IEnumerable <ADObject> aDObjects = searcher.FindAll(); foreach (ADObject aDObject in aDObjects) { var ldapDisplayName = aDObject["lDAPDisplayName"]; if (ldapDisplayName != null) { if (ldapDisplayName.Count > 0) { strs.Add((string)ldapDisplayName[0]); } } } strs.Add("user"); return(strs); }
private void AddSchemaClassObjects(ADObjectSearcher searcher, ADSchema adSchema) { searcher.SchemaTranslation = false; ADRootDSE rootDSE = searcher.GetRootDSE(); searcher.SearchRoot = rootDSE.SchemaNamingContext; IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "classSchema"); IADOPathNode aDOPathNode1 = ADOPathUtil.CreateFilterClause(ADOperator.NotLike, "isDefunct", "*"); IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2]; aDOPathNodeArray[0] = aDOPathNode; aDOPathNodeArray[1] = aDOPathNode1; searcher.Filter = ADOPathUtil.CreateAndClause(aDOPathNodeArray); searcher.Scope = ADSearchScope.Subtree; searcher.PageSize = 0x100; searcher.Properties.Clear(); searcher.Properties.Add("lDAPDisplayName"); searcher.Properties.Add("subClassOf"); searcher.Properties.Add("systemMayContain"); searcher.Properties.Add("mayContain"); searcher.Properties.Add("mustContain"); searcher.Properties.Add("systemMustContain"); searcher.Properties.Add("auxiliaryClass"); searcher.Properties.Add("systemAuxiliaryClass"); IEnumerable <ADObject> aDObjects = searcher.FindAll(); foreach (ADObject aDObject in aDObjects) { if (!aDObject.Contains("lDAPDisplayName") || aDObject["lDAPDisplayName"].Value == null) { continue; } adSchema._schemaClasses.Add((string)aDObject["lDAPDisplayName"].Value, aDObject); adSchema._schemaClassesDnHash.Add((string)aDObject["distinguishedName"].Value, (string)aDObject["lDAPDisplayName"].Value); } }
internal static string ConvertFriendlyPartition(ADRootDSE rootDSE, string partition) { if (!string.Equals(partition, "Default", StringComparison.OrdinalIgnoreCase)) { if (!string.Equals(partition, "Domain", StringComparison.OrdinalIgnoreCase)) { if (string.Equals(partition, "Config", StringComparison.OrdinalIgnoreCase) || string.Equals(partition, "Configuration", StringComparison.OrdinalIgnoreCase)) { if (string.IsNullOrEmpty(rootDSE.ConfigurationNamingContext)) { object[] dNSHostName = new object[2]; dNSHostName[0] = rootDSE.DNSHostName; dNSHostName[1] = partition; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ServerDoesNotHaveFriendlyPartition, dNSHostName)); } else { return rootDSE.ConfigurationNamingContext; } } else { if (!string.Equals(partition, "Schema", StringComparison.OrdinalIgnoreCase)) { return null; } else { if (string.IsNullOrEmpty(rootDSE.SchemaNamingContext)) { object[] objArray = new object[2]; objArray[0] = rootDSE.DNSHostName; objArray[1] = partition; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ServerDoesNotHaveFriendlyPartition, objArray)); } else { return rootDSE.SchemaNamingContext; } } } } else { if (string.IsNullOrEmpty(rootDSE.RootDomainNamingContext)) { object[] dNSHostName1 = new object[2]; dNSHostName1[0] = rootDSE.DNSHostName; dNSHostName1[1] = partition; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ServerDoesNotHaveFriendlyPartition, dNSHostName1)); } else { return rootDSE.RootDomainNamingContext; } } } else { if (string.IsNullOrEmpty(rootDSE.DefaultNamingContext)) { object[] objArray1 = new object[2]; objArray1[0] = rootDSE.DNSHostName; objArray1[1] = partition; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ServerDoesNotHaveFriendlyPartition, objArray1)); } else { return rootDSE.DefaultNamingContext; } } }
public CmdletSessionInfo(ADSessionInfo adSessionInfo, ADRootDSE adRootDse, string defaultQueryPath, string defaultPartitionPath, string defaultCreationPath, ADServerType connectedADServerType, IADCmdletCache cmdletSessionCache, IADCmdletMessageWriter cmdletMessageWriter, PSCmdlet psCmdlet, ADParameterSet cmdletParameters) { this._adSessionInfo = adSessionInfo; this._adRootDse = adRootDse; this._defaultQueryPath = defaultQueryPath; this._defaultPartitionPath = defaultPartitionPath; this._defaultCreationPath = defaultCreationPath; this._connectedADServerType = connectedADServerType; this._cmdletSessionCache = cmdletSessionCache; this._cmdletMessageWriter = cmdletMessageWriter; this._psCmdlet = psCmdlet; this._cmdletParameters = cmdletParameters; }
private ADForestPartitionInfo(ADRootDSE rootDSE) { this._forestId = rootDSE.SubSchemaSubEntry; this.Refresh(rootDSE); }
private void Refresh(ADRootDSE rootDSE) { if (rootDSE != null) { if (rootDSE.SessionInfo != null) { if (this._forestId.Equals(rootDSE.SubSchemaSubEntry, StringComparison.OrdinalIgnoreCase)) { object[] objArray = new object[1]; objArray[0] = this._forestId; DebugLogger.LogInfo("ADForestPartitionInfo", "Refreshing PartitionList of Forest: {0}", objArray); List<string> strs = new List<string>(); ADSessionInfo sessionInfo = rootDSE.SessionInfo; if (rootDSE.ServerType == ADServerType.ADDS && sessionInfo.ConnectedToGC) { sessionInfo = sessionInfo.Copy(); sessionInfo.SetEffectivePort(LdapConstants.LDAP_PORT); } using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(sessionInfo)) { aDObjectSearcher.SchemaTranslation = false; aDObjectSearcher.SearchRoot = string.Concat("CN=Partitions,", rootDSE.ConfigurationNamingContext); aDObjectSearcher.Properties.Add("nCName"); aDObjectSearcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "crossRef"); foreach (ADObject aDObject in aDObjectSearcher.FindAll()) { if (aDObject["nCName"] == null || aDObject["nCName"].Count <= 0) { continue; } strs.Add((string)aDObject["nCName"][0]); } this._forestPartitionList = new ReadOnlyCollection<string>(strs); } return; } else { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ForestIdDoesNotMatch, new object[0])); } } else { throw new ArgumentNullException("rootDSE.SessionInfo"); } } else { throw new ArgumentNullException("rootDSE"); } }
internal static bool IsDNUnderPartition(ADRootDSE rootDSE, string objectDN, bool refreshForestPartitionList) { bool flag; if (rootDSE != null) { if (!string.IsNullOrEmpty(objectDN)) { IEnumerable<string> validPartitionList = ADForestPartitionInfo.GetValidPartitionList(rootDSE, refreshForestPartitionList); IEnumerator<string> enumerator = validPartitionList.GetEnumerator(); using (enumerator) { while (enumerator.MoveNext()) { string current = enumerator.Current; if (!ADPathModule.IsChildPath(objectDN, current, true, ADPathFormat.X500)) { continue; } flag = true; return flag; } return false; } return flag; } else { return false; } } else { throw new ArgumentNullException("rootDSE"); } }
private static ADForestPartitionInfo GetForestPartitionInfo(ADRootDSE rootDSE) { if (rootDSE != null) { string subSchemaSubEntry = rootDSE.SubSchemaSubEntry; ADForestPartitionInfo aDForestPartitionInfo = null; lock (ADForestPartitionInfo._forestInfoTableLock) { ADForestPartitionInfo._forestInfoTable.TryGetValue(subSchemaSubEntry, out aDForestPartitionInfo); } if (aDForestPartitionInfo == null) { object[] objArray = new object[1]; objArray[0] = rootDSE.SubSchemaSubEntry; DebugLogger.LogInfo("ADForestPartitionInfo", "Getting forest info from server for Forest: {0}", objArray); aDForestPartitionInfo = new ADForestPartitionInfo(rootDSE); lock (ADForestPartitionInfo._forestInfoTableLock) { if (ADForestPartitionInfo._forestInfoTable.ContainsKey(subSchemaSubEntry)) { ADForestPartitionInfo._forestInfoTable.Remove(subSchemaSubEntry); } ADForestPartitionInfo._forestInfoTable.Add(subSchemaSubEntry, aDForestPartitionInfo); } return aDForestPartitionInfo; } else { object[] subSchemaSubEntry1 = new object[1]; subSchemaSubEntry1[0] = rootDSE.SubSchemaSubEntry; DebugLogger.LogInfo("ADForestPartitionInfo", "Found ADForestPartitionInfo for Forest: {0} in Cache", subSchemaSubEntry1); return aDForestPartitionInfo; } } else { throw new ArgumentNullException("rootDSE"); } }
internal static string ConvertFriendlyPartition(ADRootDSE rootDSE, string partition) { if (!string.Equals(partition, "Default", StringComparison.OrdinalIgnoreCase)) { if (!string.Equals(partition, "Domain", StringComparison.OrdinalIgnoreCase)) { if (string.Equals(partition, "Config", StringComparison.OrdinalIgnoreCase) || string.Equals(partition, "Configuration", StringComparison.OrdinalIgnoreCase)) { if (string.IsNullOrEmpty(rootDSE.ConfigurationNamingContext)) { object[] dNSHostName = new object[2]; dNSHostName[0] = rootDSE.DNSHostName; dNSHostName[1] = partition; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ServerDoesNotHaveFriendlyPartition, dNSHostName)); } else { return(rootDSE.ConfigurationNamingContext); } } else { if (!string.Equals(partition, "Schema", StringComparison.OrdinalIgnoreCase)) { return(null); } else { if (string.IsNullOrEmpty(rootDSE.SchemaNamingContext)) { object[] objArray = new object[2]; objArray[0] = rootDSE.DNSHostName; objArray[1] = partition; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ServerDoesNotHaveFriendlyPartition, objArray)); } else { return(rootDSE.SchemaNamingContext); } } } } else { if (string.IsNullOrEmpty(rootDSE.RootDomainNamingContext)) { object[] dNSHostName1 = new object[2]; dNSHostName1[0] = rootDSE.DNSHostName; dNSHostName1[1] = partition; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ServerDoesNotHaveFriendlyPartition, dNSHostName1)); } else { return(rootDSE.RootDomainNamingContext); } } } else { if (string.IsNullOrEmpty(rootDSE.DefaultNamingContext)) { object[] objArray1 = new object[2]; objArray1[0] = rootDSE.DNSHostName; objArray1[1] = partition; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ServerDoesNotHaveFriendlyPartition, objArray1)); } else { return(rootDSE.DefaultNamingContext); } } }
public static string ExtractAndValidatePartitionInfo(ADRootDSE rootDSE, string objectDN) { IEnumerable<string> partitionList; string str = ADForestPartitionInfo.ExtractPartitionInfo(rootDSE, objectDN, false); if (str == null) { str = ADForestPartitionInfo.ExtractPartitionInfo(rootDSE, objectDN, true); if (str == null) { CultureInfo currentCulture = CultureInfo.CurrentCulture; string invalidDNMustBelongToValidPartitionSet = StringResources.InvalidDNMustBelongToValidPartitionSet; object[] objArray = new object[1]; object[] objArray1 = objArray; int num = 0; if (rootDSE.SessionInfo.ConnectedToGC) { partitionList = ADForestPartitionInfo.GetForestPartitionInfo(rootDSE).PartitionList; } else { partitionList = rootDSE.NamingContexts; } objArray1[num] = ADForestPartitionInfo.ConcatList(partitionList, " , "); throw new ArgumentException(string.Format(currentCulture, invalidDNMustBelongToValidPartitionSet, objArray)); } } return str; }
internal static string ExtractPartitionInfo(ADRootDSE rootDSE, string objectDN, bool refreshForestPartitionList) { string str = null; if (rootDSE != null) { if (objectDN != null) { if (rootDSE.SessionInfo == null || !rootDSE.SessionInfo.ConnectedToGC || !objectDN.Equals(string.Empty)) { IEnumerable<string> validPartitionList = ADForestPartitionInfo.GetValidPartitionList(rootDSE, refreshForestPartitionList); int length = -1; foreach (string str1 in validPartitionList) { if (str1.Length <= length || !ADPathModule.IsChildPath(objectDN, str1, true, ADPathFormat.X500)) { continue; } length = str1.Length; str = str1; } return str; } else { return string.Empty; } } else { throw new ArgumentNullException("objectDN"); } } else { throw new ArgumentNullException("rootDSE"); } }
private bool IsServerGlobalCatalog(ADSessionInfo sessionInfo, ADRootDSE rootDSE, ADProviderCommonParameters parameters, ADDriveInfo extendedDriveInfo) { bool hasValue; bool flag = false; if (this.GetHostType(parameters, extendedDriveInfo) != ADPathHostType.GC) { bool? globalCatalogReady = rootDSE.GlobalCatalogReady; if (!globalCatalogReady.GetValueOrDefault()) { hasValue = false; } else { hasValue = globalCatalogReady.HasValue; } if (hasValue) { string server = null; if (sessionInfo.Server != null) { server = sessionInfo.Server; } if (server != null) { this.Trace(DebugLogLevel.Info, string.Format("IsServerGlobalCatalog: server = {0}", server)); if (server.EndsWith(":3268") || server.EndsWith(":3269")) { flag = true; } } } } else { flag = true; } this.Trace(DebugLogLevel.Info, string.Format("IsServerGlobalCatalog: result = {0}", flag)); return flag; }
private static IEnumerable<string> GetValidPartitionList(ADRootDSE rootDSE, bool refreshForestPartitionList) { if (rootDSE.SessionInfo == null || !rootDSE.SessionInfo.ConnectedToGC) { return rootDSE.NamingContexts; } else { if (refreshForestPartitionList) { ADForestPartitionInfo.GetForestPartitionInfo(rootDSE).Refresh(rootDSE); } return ADForestPartitionInfo.GetForestPartitionInfo(rootDSE).PartitionList; } }
private HashSet<ADObject> GetAllHostedNamingContexts(ADSessionInfo sessionInfo, ADRootDSE rootDSE, ADDriveInfo extendedDriveInfo, Collection<string> propertiesToRetrieve) { HashSet<ADObject> aDObjects = new HashSet<ADObject>(); this.Trace(DebugLogLevel.Verbose, "Entering GetAllHostedNamingContexts"); if (!this.IsServerGlobalCatalog(sessionInfo, rootDSE, base.DynamicParameters as ADProviderCommonParameters, extendedDriveInfo)) { string[] namingContexts = rootDSE.NamingContexts; for (int i = 0; i < (int)namingContexts.Length; i++) { string str = namingContexts[i]; ADPathFormat formatType = this.GetFormatType(base.DynamicParameters as ADProviderCommonParameters, extendedDriveInfo); ADObject validatedADObject = this.GetValidatedADObject(sessionInfo, str, propertiesToRetrieve, formatType); aDObjects.Add(validatedADObject); } } else { this.Trace(DebugLogLevel.Verbose, "GetAllHostedNamingContexts: Server is GC and we are connected to GC port."); string str1 = "(|(objectcategory=domainDNS)(objectcategory=DMD)(objectcategory=configuration))"; ADObjectSearcher aDObjectSearcher = this.GetADObjectSearcher("", ADSearchScope.Subtree, new LdapFilterADOPathNode(str1), null, base.Credential, extendedDriveInfo); using (aDObjectSearcher) { if (propertiesToRetrieve != null) { aDObjectSearcher.Properties.AddRange(propertiesToRetrieve); } foreach (ADObject aDObject in aDObjectSearcher.FindAll()) { aDObjects.Add(aDObject); } } } this.Trace(DebugLogLevel.Verbose, "Leaving GetAllHostedNamingContexts"); return aDObjects; }
private static bool IsValidPartitionDN(ADRootDSE rootDSE, string partitionDN, bool refreshForestPartitionList) { bool flag; if (rootDSE != null) { if (partitionDN != null) { if (rootDSE.SessionInfo == null || !rootDSE.SessionInfo.ConnectedToGC || !partitionDN.Equals(string.Empty)) { IEnumerable<string> validPartitionList = ADForestPartitionInfo.GetValidPartitionList(rootDSE, refreshForestPartitionList); IEnumerator<string> enumerator = validPartitionList.GetEnumerator(); using (enumerator) { while (enumerator.MoveNext()) { string current = enumerator.Current; if (!ADPathModule.ComparePath(partitionDN, current, ADPathFormat.X500)) { continue; } flag = true; return flag; } return false; } return flag; } else { return true; } } else { throw new ArgumentNullException("partitionDN"); } } else { throw new ArgumentNullException("rootDSE"); } }
private void WriteADRootDSE(ADRootDSE rootDse, ADSessionInfo sessionInfo) { rootDse.SessionInfo = sessionInfo; rootDse.SessionInfo.ServerType = rootDse.ServerType; this.WriteItemObjectWithAbsolutePath(rootDse, "", true); }
public static void ValidatePartitionDN(ADRootDSE rootDSE, string partitionDN) { IEnumerable<string> partitionList; if (ADForestPartitionInfo.IsValidPartitionDN(rootDSE, partitionDN, false) || ADForestPartitionInfo.IsValidPartitionDN(rootDSE, partitionDN, true)) { return; } else { CultureInfo currentCulture = CultureInfo.CurrentCulture; string invalidPartitionMustBelongToValidSet = StringResources.InvalidPartitionMustBelongToValidSet; object[] objArray = new object[1]; object[] objArray1 = objArray; int num = 0; if (rootDSE.SessionInfo.ConnectedToGC) { partitionList = ADForestPartitionInfo.GetForestPartitionInfo(rootDSE).PartitionList; } else { partitionList = rootDSE.NamingContexts; } objArray1[num] = ADForestPartitionInfo.ConcatList(partitionList, " , "); throw new ArgumentException(string.Format(currentCulture, invalidPartitionMustBelongToValidSet, objArray)); } }
public ADRootDSE GetRootDSE() { this.Init(); ADRootDSE rootDSE = this._adSession.RootDSE; if (rootDSE == null) { string[] strArrays = new string[2]; strArrays[0] = "*"; strArrays[1] = "msDS-PortLDAP"; ADSearchRequest aDSearchRequest = new ADSearchRequest("", ADObjectSearcher.DefaultSearchFilter.GetLdapFilterString(), SearchScope.Base, strArrays); aDSearchRequest.TimeLimit = this._timeLimit; ADSearchResponse aDSearchResponse = this._syncOps.Search(this._sessionHandle, aDSearchRequest); if (aDSearchResponse.Entries.Count > 0) { rootDSE = new ADRootDSE(); ADObject item = aDSearchResponse.Entries[0]; foreach (string propertyName in item.PropertyNames) { rootDSE.Add(propertyName, item[propertyName]); } this._adSession.RootDSE = rootDSE; } return rootDSE; } else { return rootDSE; } }
public ADRootDSE GetRootDSE(ICollection<string> propertyList, bool propertyNamesOnly) { this.Init(); ADRootDSE aDRootDSE = null; string[] strArrays = null; if (propertyList != null) { strArrays = new string[propertyList.Count]; propertyList.CopyTo(strArrays, 0); } ADSearchRequest aDSearchRequest = new ADSearchRequest("", ADObjectSearcher.DefaultSearchFilter.GetLdapFilterString(), SearchScope.Base, strArrays); aDSearchRequest.TypesOnly = propertyNamesOnly; aDSearchRequest.TimeLimit = this._timeLimit; ADSearchResponse aDSearchResponse = this._syncOps.Search(this._sessionHandle, aDSearchRequest); if (aDSearchResponse.Entries.Count > 0) { aDRootDSE = new ADRootDSE(); ADObject item = aDSearchResponse.Entries[0]; foreach (string propertyName in item.PropertyNames) { aDRootDSE.Add(propertyName, item[propertyName]); } } return aDRootDSE; }
private ADServerType GetServerType(ADRootDSE rootDse) { return rootDse.ServerType; }
private HashSet<string> GetUserSubClasses(ADObjectSearcher searcher, ADRootDSE rootDSE) { HashSet<string> strs = new HashSet<string>(StringComparer.OrdinalIgnoreCase); searcher.SearchRoot = rootDSE.SchemaNamingContext; searcher.Properties.Add("lDAPDisplayName"); string str = string.Concat("CN=Person,", rootDSE.SchemaNamingContext); IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "classSchema"); IADOPathNode aDOPathNode1 = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "subClassOf", "user"); IADOPathNode aDOPathNode2 = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "defaultObjectCategory", str); IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2]; aDOPathNodeArray[0] = aDOPathNode; IADOPathNode[] aDOPathNodeArray1 = new IADOPathNode[2]; aDOPathNodeArray1[0] = aDOPathNode1; aDOPathNodeArray1[1] = aDOPathNode2; aDOPathNodeArray[1] = ADOPathUtil.CreateAndClause(aDOPathNodeArray1); IADOPathNode aDOPathNode3 = ADOPathUtil.CreateAndClause(aDOPathNodeArray); searcher.Filter = aDOPathNode3; IEnumerable<ADObject> aDObjects = searcher.FindAll(); foreach (ADObject aDObject in aDObjects) { var ldapDisplayName = aDObject["lDAPDisplayName"]; if (ldapDisplayName != null) { if (ldapDisplayName.Count > 0) { strs.Add((string)ldapDisplayName[0]); } } } strs.Add("user"); return strs; }