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); }
internal static ADObjectSearcher BuildSearcher(ADSessionInfo session, string searchRoot, ADSearchScope searchScope, bool showDeleted) { ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(session); aDObjectSearcher.PageSize = 0x100; aDObjectSearcher.SearchRoot = searchRoot; aDObjectSearcher.Scope = searchScope; if (showDeleted) { aDObjectSearcher.ShowDeleted = true; aDObjectSearcher.ShowDeactivatedLink = true; } return aDObjectSearcher; }
internal override T GetExtendedObjectFromIdentity(T identityObj, string identityQueryPath, ICollection <string> propertiesToFetch, bool showDeleted) { ADObject aDObject; ADDefaultDomainPasswordPolicy aDDefaultDomainPasswordPolicy = identityObj; if (aDDefaultDomainPasswordPolicy != null) { if (base.CmdletSessionInfo != null) { AttributeSetRequest attributeSetRequest = this.ConstructAttributeSetRequest(propertiesToFetch); IADOPathNode[] structuralObjectFilter = new IADOPathNode[2]; structuralObjectFilter[0] = this.StructuralObjectFilter; structuralObjectFilter[1] = this.BuildIdentityFilter(identityObj); IADOPathNode aDOPathNode = ADOPathUtil.CreateAndClause(structuralObjectFilter); string defaultNamingContext = base.CmdletSessionInfo.ADRootDSE.DefaultNamingContext; ADSearchScope aDSearchScope = ADSearchScope.Base; ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(base.CmdletSessionInfo.ADSessionInfo, defaultNamingContext, aDSearchScope, showDeleted); using (aDObjectSearcher) { aDObjectSearcher.Filter = aDOPathNode; aDObjectSearcher.Properties.AddRange(attributeSetRequest.DirectoryAttributes); DebugLogger.LogInfo("ADDefaultDomainPasswordPolicyFactory", string.Format("ADFactory: GetExtendedObjectFromIdentity: Searching for identity using filter: {0} searchbase: {1} scope: {2}", aDObjectSearcher.Filter.GetLdapFilterString(), aDObjectSearcher.SearchRoot, aDObjectSearcher.Scope)); aDObject = aDObjectSearcher.FindOne(); if (aDObject == null) { DebugLogger.LogInfo("ADDefaultDomainPasswordPolicyFactory", string.Format("ADFactory: GetExtendedObjectFromIdentity: Identity not found", new object[0])); object[] str = new object[2]; str[0] = identityObj.ToString(); str[1] = aDObjectSearcher.SearchRoot; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.IdentityNotFound, str)); } } T aDSessionInfo = this.Construct(aDObject, attributeSetRequest); aDSessionInfo.SessionInfo = base.CmdletSessionInfo.ADSessionInfo; return(aDSessionInfo); } else { throw new ArgumentNullException(StringResources.SessionRequired); } } else { object[] type = new object[2]; type[0] = "GetExtendedObjectFromIdentity"; type[1] = identityObj.GetType(); throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.MethodNotSupportedForObjectType, type)); } }
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); } } }
internal override IEnumerable <T> GetExtendedObjectFromFilter(IADOPathNode filter, string searchBase, ADSearchScope searchScope, ICollection <string> propertiesToFetch, int?resultSetSize, int?pageSize, bool showDeleted) { if (base.CmdletSessionInfo != null) { MappingTable <AttributeConverterEntry> item = ADNtdsSiteSettingFactory <ADNtdsSiteSetting> .AttributeTable[base.ConnectedStore]; MappingTable <AttributeConverterEntry> mappingTable = ADReplicationSiteFactory <T> .AttributeTable[base.ConnectedStore]; ICollection <string> parentAttributes = ADTopologyUtil.GetParentAttributes(mappingTable, item, propertiesToFetch); ICollection <string> childAttributes = ADTopologyUtil.GetChildAttributes(mappingTable, item, propertiesToFetch); if (!parentAttributes.Contains("*")) { parentAttributes.Add("*"); } IEnumerable <T> extendedObjectFromFilter = base.GetExtendedObjectFromFilter(this.StructuralObjectFilter, searchBase, searchScope, parentAttributes, resultSetSize, pageSize, showDeleted); ADNtdsSiteSettingFactory <ADNtdsSiteSetting> aDNtdsSiteSettingFactory = new ADNtdsSiteSettingFactory <ADNtdsSiteSetting>(); aDNtdsSiteSettingFactory.SetCmdletSessionInfo(base.CmdletSessionInfo); IEnumerable <ADNtdsSiteSetting> aDNtdsSiteSettings = aDNtdsSiteSettingFactory.GetExtendedObjectFromFilter(aDNtdsSiteSettingFactory.StructuralObjectFilter, searchBase, searchScope, childAttributes, resultSetSize, pageSize, showDeleted); Dictionary <string, ADNtdsSiteSetting> strs = new Dictionary <string, ADNtdsSiteSetting>(); foreach (ADNtdsSiteSetting aDNtdsSiteSetting in aDNtdsSiteSettings) { strs.Add(aDNtdsSiteSetting.DistinguishedName, aDNtdsSiteSetting); } List <T> ts = new List <T>(); foreach (T t in extendedObjectFromFilter) { string str = ADPathModule.MakePath(t.DistinguishedName, "CN=NTDS Site Settings,", ADPathFormat.X500); if (strs.ContainsKey(str)) { ADNtdsSiteSetting item1 = strs[str]; ADTopologyUtil.MergeADObjectProperties(t, item1); } ts.Add(t); } IEnumerable <T> ts1 = this.ApplyClientSideFilter(ts); return(ADTopologyUtil.RemoveExtraPropertiesFromADAggregateObject <T>(mappingTable, item, propertiesToFetch, ts1)); } else { throw new ArgumentNullException(StringResources.SessionRequired); } }
internal static ADObjectSearcher BuildSearcher(ADSessionInfo session, string searchRoot, ADSearchScope searchScope, bool showDeleted) { ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(session); aDObjectSearcher.PageSize = 0x100; aDObjectSearcher.SearchRoot = searchRoot; aDObjectSearcher.Scope = searchScope; if (showDeleted) { aDObjectSearcher.ShowDeleted = true; aDObjectSearcher.ShowDeactivatedLink = true; } return(aDObjectSearcher); }
internal static ADObjectSearcher BuildSearcher(ADSessionInfo session, string searchRoot, ADSearchScope searchScope) { return(SearchUtility.BuildSearcher(session, searchRoot, searchScope, false)); }
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 GetChildItemsOrNames(string path, ADSearchScope scope, bool namesOnly, ReturnContainers returnContainers, string filter) { IADOPathNode ldapFilterADOPathNode; int sizeLimit; this.Trace(DebugLogLevel.Verbose, "Entering GetChildItemsOrNames"); path = this.ValidateAndNormalizePath(path); this.Trace(DebugLogLevel.Info, string.Format("GetChildItemsOrNames: path = {0}", path)); this.Trace(DebugLogLevel.Info, string.Format("GetChildItemsOrNames: scope = {0}", scope)); this.Trace(DebugLogLevel.Info, string.Format("GetChildItemsOrNames: namesOnly = {0}", namesOnly)); this.Trace(DebugLogLevel.Info, string.Format("GetChildItemsOrNames: returnContainers = {0}", returnContainers)); this.Trace(DebugLogLevel.Info, string.Format("GetChildItemsOrNames: filter = {0}", filter)); ADProviderSearchParameters dynamicParameters = base.DynamicParameters as ADProviderSearchParameters; ADSessionInfo sessionInfo = this.GetSessionInfo(dynamicParameters, base.Credential, this.ExtendedDriveInfo); if (this.ValidateDynamicParameters(path, dynamicParameters, sessionInfo)) { ADPathFormat formatType = this.GetFormatType(dynamicParameters, this.ExtendedDriveInfo); ADProvider aDProvider = this; string str = path; ADSearchScope aDSearchScope = scope; if (filter != null) { ldapFilterADOPathNode = new LdapFilterADOPathNode(filter); } else { ldapFilterADOPathNode = null; } ADObjectSearcher aDObjectSearcher = aDProvider.GetADObjectSearcher(str, aDSearchScope, ldapFilterADOPathNode, dynamicParameters, base.Credential, this.ExtendedDriveInfo); using (aDObjectSearcher) { try { int num = 0; if (dynamicParameters != null) { sizeLimit = dynamicParameters.SizeLimit; } else { sizeLimit = 0; } int num1 = sizeLimit; sessionInfo.ServerType = this.GetServerType(sessionInfo); IEnumerator<ADObject> enumerator = aDObjectSearcher.FindAll().GetEnumerator(); using (enumerator) { do { Label1: if (!enumerator.MoveNext()) { break; } ADObject current = enumerator.Current; if (formatType != ADPathFormat.Canonical || current.Contains("canonicalName")) { if (!namesOnly) { this.WriteADObject(current, sessionInfo, dynamicParameters, this.ExtendedDriveInfo); } else { this.WriteADObjectName(current, dynamicParameters, this.ExtendedDriveInfo); } num++; } else { this.Trace(DebugLogLevel.Warning, string.Format("GetChildItemsOrNames: Unable to read canonical name for object {0}, skipping..", current.DistinguishedName)); goto Label1; } } while (num != num1); } } catch (ADException aDException1) { ADException aDException = aDException1; base.WriteError(ADUtilities.GetErrorRecord(aDException, "ADProvider:GetChildItemsOrNames:ADError", path)); this.Trace(DebugLogLevel.Error, "Leaving GetChildItemsOrNames: ADException: AD error"); return; } catch (AuthenticationException authenticationException1) { AuthenticationException authenticationException = authenticationException1; base.WriteError(ADUtilities.GetErrorRecord(authenticationException, "ADProvider:GetChildItemsOrNames:InvalidCredentials", path)); this.Trace(DebugLogLevel.Error, "Leaving GetChildItemsOrNames: ADException: invalid credentials"); return; } } this.Trace(DebugLogLevel.Verbose, "Leaving GetChildItemsOrNames"); return; } else { this.Trace(DebugLogLevel.Verbose, "Leaving GetChildItemsOrNames : ValidateDynamicParameters returned false"); return; } }
private ADObjectSearcher GetADObjectSearcher(string path, ADSearchScope scope, IADOPathNode filter, ADProviderSearchParameters parameters, PSCredential credential, ADDriveInfo extendedDriveInfo) { this.Trace(DebugLogLevel.Verbose, "Entering GetADObjectSearcher"); ADSessionInfo sessionInfo = this.GetSessionInfo(parameters, credential, extendedDriveInfo); ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(sessionInfo); aDObjectSearcher.SearchRoot = path; aDObjectSearcher.Scope = scope; if (filter != null) { aDObjectSearcher.Filter = filter; } if (parameters != null) { if (parameters.Properties != null) { aDObjectSearcher.Properties.AddRange(parameters.Properties); } aDObjectSearcher.PageSize = parameters.PageSize; } if (this.GetFormatType(parameters, extendedDriveInfo) == ADPathFormat.Canonical) { aDObjectSearcher.Properties.Add("canonicalName"); } this.Trace(DebugLogLevel.Verbose, "Leaving GetADObjectSearcher"); return aDObjectSearcher; }
internal virtual void OutputSearchResults(IADOPathNode filter) { string item; ADSessionInfo sessionInfo = base.GetSessionInfo(); int? nullable = (int?)this._cmdletParameters["ResultSetSize"]; int? nullable1 = null; ADSearchScope aDSearchScope = (ADSearchScope)this._cmdletParameters["SearchScope"]; bool flag = false; if (this._cmdletParameters.Contains("SearchBase")) { item = this._cmdletParameters["SearchBase"] as string; flag = true; } else { item = this.GetDefaultQueryPath(); } if (!flag || !(string.Empty == item) || sessionInfo.ConnectedToGC) { if (item == null || !sessionInfo.ConnectedToGC && item == string.Empty) { object[] objArray = new object[1]; objArray[0] = "SearchBase"; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ParameterRequired, objArray)); } else { if (this._cmdletParameters.Contains("ResultPageSize")) { nullable1 = new int?((int)this._cmdletParameters["ResultPageSize"]); } IEnumerable <O> extendedObjectFromFilter = this._factory.GetExtendedObjectFromFilter(filter, item, aDSearchScope, this._propertiesRequested, nullable, nullable1, this._showDeleted); if (extendedObjectFromFilter != null) { if (this._outputFilterFunction != null) { foreach (O o in extendedObjectFromFilter) { if (!this._outputFilterFunction(o)) { continue; } base.WriteObject(o); } } else { foreach (O o1 in extendedObjectFromFilter) { base.WriteObject(o1); } } } return; } } else { object[] objArray1 = new object[1]; objArray1[0] = "SearchBase"; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.EmptySearchBaseNotSupported, objArray1)); } }
internal static ADObjectSearcher BuildSearcher(ADSessionInfo session, string searchRoot, ADSearchScope searchScope) { return SearchUtility.BuildSearcher(session, searchRoot, searchScope, false); }
internal override T GetExtendedObjectFromIdentity(T identityObj, string identityQueryPath, ICollection <string> propertiesToFetch, bool showDeleted) { AttributeSetRequest attributeSetRequest; string distinguishedName; ADObject domain; if (!identityObj.IsSearchResult) { ADObject aDObject = identityObj; if (aDObject != null) { if (base.CmdletSessionInfo != null) { attributeSetRequest = this.ConstructAttributeSetRequest(null); attributeSetRequest.DirectoryAttributes.Add("distinguishedName"); IADOPathNode aDOPathNode = this.BuildIdentityFilter(identityObj); IADOPathNode[] structuralObjectFilter = new IADOPathNode[2]; structuralObjectFilter[0] = aDOPathNode; structuralObjectFilter[1] = this.StructuralObjectFilter; aDOPathNode = ADOPathUtil.CreateAndClause(structuralObjectFilter); string str = identityQueryPath; ADSearchScope aDSearchScope = ADSearchScope.Subtree; bool flag = false; ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(base.CmdletSessionInfo.ADSessionInfo, str, aDSearchScope, showDeleted); using (aDObjectSearcher) { aDObjectSearcher.Filter = aDOPathNode; aDObjectSearcher.Properties.AddRange(attributeSetRequest.DirectoryAttributes); DebugLogger.LogInfo(this._debugCategory, string.Format("ADFactory: GetExtendedObjectFromIdentity: Searching for identity using filter: {0} searchbase: {1} scope: {2}", aDObjectSearcher.Filter.GetLdapFilterString(), aDObjectSearcher.SearchRoot, aDObjectSearcher.Scope)); ADObject aDObject1 = aDObjectSearcher.FindOne(out flag); if (aDObject1 != null) { if (!flag) { distinguishedName = aDObject1.DistinguishedName; } else { throw new ADMultipleMatchingIdentitiesException(StringResources.MultipleMatches); } } else { DebugLogger.LogInfo(this._debugCategory, string.Format("ADFactory: GetExtendedObjectFromIdentity: Identity not found", new object[0])); object[] searchRoot = new object[2]; searchRoot[0] = identityObj.ToString(); searchRoot[1] = aDObjectSearcher.SearchRoot; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.IdentityNotFound, searchRoot)); } } } else { throw new ArgumentNullException(StringResources.SessionRequired); } } else { object[] type = new object[2]; type[0] = "GetExtendedObjectFromIdentity"; type[1] = identityObj.GetType(); throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.MethodNotSupportedForObjectType, type)); } } else { distinguishedName = identityObj.DistinguishedName; } if (string.Compare(distinguishedName, base.CmdletSessionInfo.ADRootDSE.DefaultNamingContext, StringComparison.OrdinalIgnoreCase) == 0) { using (ADTopologyManagement aDTopologyManagement = new ADTopologyManagement(base.CmdletSessionInfo.ADSessionInfo)) { domain = aDTopologyManagement.GetDomain(); } if (domain != null) { domain.SessionInfo = base.CmdletSessionInfo.ADSessionInfo; domain.IsSearchResult = true; attributeSetRequest = base.ConstructAttributeSetRequest(propertiesToFetch); return(this.Construct(domain, attributeSetRequest)); } else { DebugLogger.LogInfo(this._debugCategory, string.Format("GetExtendedObjectFromIdentity: No objects returned from custom action", new object[0])); throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ObjectNotFound, new object[0])); } } else { throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ObjectNotFound, new object[0])); } }
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); }