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]); } }
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 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; } }
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()); }
public ADObjectSearcher(ADSessionInfo sessionInfo, ADObject obj) { this._searchScope = ADSearchScope.Subtree; this._filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*"); this._propertyList = new List <string>(ADObject.DefaultProperties); this._timeLimit = TimeSpan.Zero; this._schemaTranslationEnabled = true; this._pageSize = 0x100; this._searchOption = null; this._autoRangeRetrieve = true; this._sdFlags = SecurityMasks.Owner | SecurityMasks.Group | SecurityMasks.Dacl; if (sessionInfo == null) { if (obj == null) { this._adSession = ADSession.ConstructSession(null); } else { this._adSession = ADSession.ConstructSession(obj.SessionInfo); } } else { this._adSession = ADSession.ConstructSession(sessionInfo); } if (obj != null) { this._adObject = obj; this._searchRoot = this._adObject.DistinguishedName; foreach (string propertyName in this._adObject.PropertyNames) { this._propertyList.Add(propertyName); } } }
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); }
static ADObjectSearcher() { ADObjectSearcher.AllProperties = "*"; ADObjectSearcher.DefaultSearchFilterString = "(objectClass=*)"; ADObjectSearcher.DefaultSearchFilter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*"); }