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 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()); }
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); } }
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 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<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(); }
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); } }
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 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; }