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 IEnumerable <ADObject> FetchRemainingRangeRetrievalAttributeValues(ADObjectSearcher newSearcher, ADObjectSearcher originalSearcher, HashSet <string> rangeRetrievedObjects, HashSet <string> rangeRetrievedAttributes, int rangeRetrievalNextIndex) { DebugLogger.LogInfo("ADObjectSearcher", string.Concat("Inside FetchRemainingRangeRetrievalAttributeValues. Fetching next range starting from: ", rangeRetrievalNextIndex)); newSearcher.AutoRangeRetrieve = false; newSearcher.PageSize = originalSearcher.PageSize; newSearcher.Scope = originalSearcher.Scope; newSearcher.SearchRoot = originalSearcher.SearchRoot; newSearcher.SchemaTranslation = originalSearcher.SchemaTranslation; newSearcher.ShowDeleted = originalSearcher.ShowDeleted; newSearcher.ShowDeactivatedLink = originalSearcher.ShowDeactivatedLink; newSearcher.SuppressServerRangeRetrievalError = true; List <IADOPathNode> aDOPathNodes = new List <IADOPathNode>(); foreach (string rangeRetrievedObject in rangeRetrievedObjects) { aDOPathNodes.Add(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "distinguishedName", rangeRetrievedObject)); } if (aDOPathNodes.Count != 1) { newSearcher.Filter = ADOPathUtil.CreateOrClause(aDOPathNodes.ToArray()); } else { newSearcher.Filter = aDOPathNodes[0]; } List <string> strs = new List <string>(rangeRetrievedAttributes.Count); StringBuilder stringBuilder = new StringBuilder(); foreach (string rangeRetrievedAttribute in rangeRetrievedAttributes) { stringBuilder.Remove(0, stringBuilder.Length); stringBuilder.Append(rangeRetrievedAttribute).Append(";range=").Append(rangeRetrievalNextIndex).Append("-*"); strs.Add(stringBuilder.ToString()); } newSearcher.Properties = strs; return(newSearcher.FindAll()); }