protected internal string ResolveIdentityToNTDSSettingsDN(T identityObj, ICollection <string> propertiesToFetch, bool checkForDCs, out ADObject computerObj, out ADObject serverObj, out ADObject ntdsDSAObj) { string str = null; string str1; computerObj = null; serverObj = null; ntdsDSAObj = null; HashSet <string> strs = new HashSet <string>(ADDirectoryServerFactory <T> ._directoryServerDefaultAttributes, StringComparer.OrdinalIgnoreCase); if (propertiesToFetch != null) { strs.UnionWith(propertiesToFetch); } string[] strArrays = new string[strs.Count]; strs.CopyTo(strArrays); string configurationNamingContext = base.CmdletSessionInfo.ADRootDSE.ConfigurationNamingContext; ADSearchScope aDSearchScope = ADSearchScope.Subtree; IADOPathNode aDOPathNode = this.BuildIdentityFilter(identityObj); IADOPathNode[] structuralObjectFilter = new IADOPathNode[2]; structuralObjectFilter[0] = aDOPathNode; structuralObjectFilter[1] = this.StructuralObjectFilter; aDOPathNode = ADOPathUtil.CreateAndClause(structuralObjectFilter); ADObjectSearcher nullable = SearchUtility.BuildSearcher(base.CmdletSessionInfo.ADSessionInfo, configurationNamingContext, aDSearchScope); using (nullable) { nullable.Filter = aDOPathNode; nullable.Properties.AddRange(strArrays); if (checkForDCs) { nullable.SearchOption = new SearchOption?(SearchOption.PhantomRoot); nullable.SearchRoot = string.Empty; } List <ADObject> aDObjects = new List <ADObject>(); foreach (ADObject aDObject in nullable.FindAll()) { aDObjects.Add(aDObject); } if (aDObjects.Count != 0) { DirectoryServerUtil.CheckIfObjectsRefersToSingleDirectoryServer(base.CmdletSessionInfo.ADSessionInfo, aDObjects, checkForDCs, out str, out computerObj, out serverObj, out ntdsDSAObj); if (str == null) { str1 = null; } else { str1 = string.Concat("CN=NTDS Settings,", str); } } else { DebugLogger.LogInfo("ADDirectoryServerFactory", string.Format("Could not find identity using the following filter: {0}", aDOPathNode.GetLdapFilterString())); str1 = null; } } return(str1); }
protected bool ADGetPropertiesCmdletBaseProcessCSRoutine() { if (this._cmdletParameters.Contains("Identity")) { O item = (O)(this._cmdletParameters["Identity"] as O); this.SetPipelinedSessionInfo(item.SessionInfo); CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo(); this._factory.SetCmdletSessionInfo(cmdletSessionInfo); this._returnObjectFactory.SetCmdletSessionInfo(cmdletSessionInfo); if (this.IdentityLookupMode != IdentityLookupMode.DirectoryMode || this.SourcePropertyType != SourcePropertyType.LinkedDN) { if (this.IdentityLookupMode != IdentityLookupMode.FactoryMode || this.SourcePropertyType != SourcePropertyType.IdentityInfo) { if (this.IdentityLookupMode == IdentityLookupMode.DirectoryMode && this.SourcePropertyType == SourcePropertyType.IdentityInfo) { string identityObjectDN = this.GetIdentityObjectDN(); if (identityObjectDN != null) { ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, identityObjectDN, ADSearchScope.Base); using (aDObjectSearcher) { aDObjectSearcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*"); aDObjectSearcher.Properties.Add(this.SourceProperty); ADObject aDObject = aDObjectSearcher.FindOne(); this.WritePropertiesToOutput(item, aDObject); } } } } else { string[] sourceProperty = new string[1]; sourceProperty[0] = this.SourceProperty; O extendedObjectFromIdentity = this._factory.GetExtendedObjectFromIdentity(item, cmdletSessionInfo.DefaultPartitionPath, sourceProperty); this.WritePropertiesToOutput(item, extendedObjectFromIdentity); } } else { string str = this.GetIdentityObjectDN(); if (str != null) { AttributeSetRequest attributeSetRequest = this._returnObjectFactory.ConstructAttributeSetRequest(null); ADObjectSearcher structuralObjectFilter = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, str, ADSearchScope.Base); using (structuralObjectFilter) { structuralObjectFilter.AttributeScopedQuery = this.SourceProperty; structuralObjectFilter.Filter = this._returnObjectFactory.StructuralObjectFilter; structuralObjectFilter.Properties.AddRange(attributeSetRequest.DirectoryAttributes); structuralObjectFilter.AutoRangeRetrieve = this.AutoRangeRetrieve; IEnumerable <ADObject> aDObjects = structuralObjectFilter.FindAll(); if (aDObjects != null) { foreach (ADObject aDObject1 in aDObjects) { if (aDObject1 == null) { continue; } RO rO = this._returnObjectFactory.Construct(aDObject1, attributeSetRequest); base.WriteObject(rO); } } } } } } return(true); }
private void ValidateMembersParameter() { bool flag; if (!this._isMembersValidated) { object item = this._cmdletParameters["Members"]; ADPrincipal[] aDPrincipalArray = item as ADPrincipal[]; if (aDPrincipalArray == null) { ADPrincipal aDPrincipal = item as ADPrincipal; if (aDPrincipal != null) { ADPrincipal[] aDPrincipalArray1 = new ADPrincipal[1]; aDPrincipalArray1[0] = aDPrincipal; aDPrincipalArray = aDPrincipalArray1; } } if (aDPrincipalArray != null) { List <string> strs = new List <string>(); Hashtable hashtables = new Hashtable(); ADPrincipalFactory <ADPrincipal> aDPrincipalFactory = new ADPrincipalFactory <ADPrincipal>(); CmdletSessionInfo cmdletSessionInfo = base.GetCmdletSessionInfo(); aDPrincipalFactory.SetCmdletSessionInfo(cmdletSessionInfo); if (cmdletSessionInfo.ConnectedADServerType != ADServerType.ADDS) { flag = false; } else { flag = this._operationType == SetADGroupMemberOperationType.RemoveGroupMember; } bool flag1 = flag; Dictionary <SecurityIdentifier, string> securityIdentifiers = new Dictionary <SecurityIdentifier, string>(); IADOPathNode aDOPathNode = null; SecurityIdentifier value = null; if (flag1) { ADGroup aDGroup = (ADGroup)this._cmdletParameters["Identity"]; if (!aDGroup.IsSearchResult) { ADObject directoryObjectFromIdentity = aDPrincipalFactory.GetDirectoryObjectFromIdentity(aDGroup, cmdletSessionInfo.DefaultPartitionPath); value = (SecurityIdentifier)directoryObjectFromIdentity["objectSid"].Value; } else { value = aDGroup.SID; } } ADPrincipal[] aDPrincipalArray2 = aDPrincipalArray; for (int i = 0; i < (int)aDPrincipalArray2.Length; i++) { ADPrincipal aDPrincipal1 = aDPrincipalArray2[i]; SecurityIdentifier sID = null; string distinguishedName = null; try { if (!aDPrincipal1.IsSearchResult) { ADObject aDObject = aDPrincipalFactory.GetDirectoryObjectFromIdentity(aDPrincipal1, cmdletSessionInfo.DefaultPartitionPath); sID = (SecurityIdentifier)aDObject["objectSid"].Value; distinguishedName = (string)aDObject["distinguishedName"].Value; } else { sID = aDPrincipal1.SID; distinguishedName = aDPrincipal1.DistinguishedName; } if (distinguishedName != null) { if (sID == null) { object[] objArray = new object[2]; objArray[0] = "objectSid"; objArray[1] = distinguishedName; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.AttributeNotFoundOnObject, objArray)); } } else { object[] identifyingString = new object[2]; identifyingString[0] = "distinguishedName"; identifyingString[1] = aDPrincipal1.IdentifyingString; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.AttributeNotFoundOnObject, identifyingString)); } } catch (ADIdentityNotFoundException aDIdentityNotFoundException1) { ADIdentityNotFoundException aDIdentityNotFoundException = aDIdentityNotFoundException1; DebugLogger.LogError("SetADGroupMember", aDIdentityNotFoundException.ToString()); base.ThrowTerminatingError(new ErrorRecord(aDIdentityNotFoundException, "SetADGroupMember.ValidateMembersParameter", ErrorCategory.ObjectNotFound, aDPrincipal1)); } catch (ArgumentException argumentException1) { ArgumentException argumentException = argumentException1; DebugLogger.LogError("SetADGroupMember", argumentException.ToString()); base.ThrowTerminatingError(new ErrorRecord(argumentException, "SetADGroupMember.ValidateMembersParameter", ErrorCategory.ReadError, aDPrincipal1)); } if (!flag1 || value.IsEqualDomainSid(sID)) { strs.Add(Utils.ConvertSIDToStringizedSid(sID)); } else { IADOPathNode aDOPathNode1 = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectSid", sID); if (aDOPathNode != null) { IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2]; aDOPathNodeArray[0] = aDOPathNode; aDOPathNodeArray[1] = aDOPathNode1; aDOPathNode = ADOPathUtil.CreateOrClause(aDOPathNodeArray); } else { aDOPathNode = aDOPathNode1; } securityIdentifiers.Add(sID, distinguishedName); } } if (aDOPathNode != null) { using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(this.GetSessionInfo())) { IADOPathNode aDOPathNode2 = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "foreignSecurityPrincipal"); aDObjectSearcher.SearchRoot = this.GetRootDSE().DefaultNamingContext; IADOPathNode[] aDOPathNodeArray1 = new IADOPathNode[2]; aDOPathNodeArray1[0] = aDOPathNode2; aDOPathNodeArray1[1] = aDOPathNode; aDObjectSearcher.Filter = ADOPathUtil.CreateAndClause(aDOPathNodeArray1); aDObjectSearcher.Properties.Add("objectSid"); foreach (ADObject aDObject1 in aDObjectSearcher.FindAll()) { SecurityIdentifier securityIdentifier = (SecurityIdentifier)aDObject1["objectSid"].Value; if (!securityIdentifiers.ContainsKey(securityIdentifier)) { continue; } strs.Add(Utils.ConvertSIDToStringizedSid(securityIdentifier)); securityIdentifiers.Remove(securityIdentifier); } foreach (string str in securityIdentifiers.Values) { strs.Add(str); } } } if (this._operationType != SetADGroupMemberOperationType.AddGroupMember) { if (this._operationType == SetADGroupMemberOperationType.RemoveGroupMember) { hashtables.Add(PropertyModifyOp.Remove.ToString(), strs.ToArray()); } } else { hashtables.Add(PropertyModifyOp.Add.ToString(), strs.ToArray()); } this._cmdletParameters.RemoveParameter("Members"); this._cmdletParameters["Members"] = new ADMultivalueHashtableParameter <string>(hashtables); this._isMembersValidated = true; } return; } else { return; } }
internal IEnumerable <T> GetAllDomainControllers(ICollection <string> propertiesToFetch) { IEnumerable <T> ts; string defaultNamingContext = base.CmdletSessionInfo.ADRootDSE.DefaultNamingContext; ADSearchScope aDSearchScope = ADSearchScope.Subtree; IADOPathNode aDOPathNode = ADDomainControllerFactory <T> ._domainControllerComputerObjectFilter; ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(base.CmdletSessionInfo.ADSessionInfo, defaultNamingContext, aDSearchScope); using (aDObjectSearcher) { aDObjectSearcher.Filter = aDOPathNode; aDObjectSearcher.Properties.AddRange(ADDomainControllerFactory <T> ._domainControllerDefaultAttributes); List <ADObject> aDObjects = new List <ADObject>(); foreach (ADObject aDObject in aDObjectSearcher.FindAll()) { aDObjects.Add(aDObject); } if (aDObjects.Count != 0) { List <string> strs = new List <string>(); foreach (ADObject aDObject1 in aDObjects) { string value = aDObject1["serverReferenceBL"].Value as string; if (value == null) { DebugLogger.LogInfo("ADDomainControllerFactory", string.Format("Could not find property: {0} for identity: {1}", "serverReferenceBL", aDObject1.DistinguishedName)); } else { strs.Add(string.Concat("CN=NTDS Settings,", value)); } } if (strs.Count <= 0) { ts = null; } else { using (ADTopologyManagement aDTopologyManagement = new ADTopologyManagement(base.CmdletSessionInfo.ADSessionInfo)) { ADEntity[] domainController = aDTopologyManagement.GetDomainController(strs.ToArray()); if (domainController == null || (int)domainController.Length == 0) { ts = new List <T>(); } else { List <T> ts1 = new List <T>(); AttributeSetRequest attributeSetRequest = this.ConstructAttributeSetRequest(propertiesToFetch); ADEntity[] aDEntityArray = domainController; for (int i = 0; i < (int)aDEntityArray.Length; i++) { ADEntity aDEntity = aDEntityArray[i]; T aDSessionInfo = this.Construct(aDEntity, attributeSetRequest); aDSessionInfo.SessionInfo = base.CmdletSessionInfo.ADSessionInfo; ts1.Add(aDSessionInfo); } ts = ts1; } } } } else { ts = new List <T>(); } } return(ts); }