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 override ADObject GetDirectoryObjectFromIdentity(T identityObj, string searchRoot, bool showDeleted) { ADObject aDSessionInfo; this.ValidateIdentity(identityObj); string str = string.Concat("CN=Partitions,", base.CmdletSessionInfo.ADRootDSE.ConfigurationNamingContext); ADObjectSearcher structuralObjectFilter = SearchUtility.BuildSearcher(base.CmdletSessionInfo.ADSessionInfo, str, ADSearchScope.Base); using (structuralObjectFilter) { AttributeSetRequest attributeSetRequest = this.ConstructAttributeSetRequest(null); structuralObjectFilter.Properties.AddRange(attributeSetRequest.DirectoryAttributes); structuralObjectFilter.Filter = this.StructuralObjectFilter; DebugLogger.LogInfo("ADForestFactory", string.Format("GetDirectoryObjectFromIdentity: Searching for identity using filter: {0} searchbase: {1}", structuralObjectFilter.Filter.GetLdapFilterString(), structuralObjectFilter.SearchRoot)); aDSessionInfo = structuralObjectFilter.FindOne(); if (aDSessionInfo == null) { DebugLogger.LogInfo("ADForestFactory", string.Format("GetDirectoryObjectFromIdentity: Identity not found.", new object[0])); object[] objArray = new object[2]; objArray[0] = identityObj.ToString(); objArray[1] = structuralObjectFilter.SearchRoot; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.IdentityNotFound, objArray)); } } aDSessionInfo.TrackChanges = true; aDSessionInfo.SessionInfo = base.CmdletSessionInfo.ADSessionInfo; return(aDSessionInfo); }
internal static ADObjectSearcher BuildSidBaseSearcher(SecurityIdentifier sidObject, string searchRoot, CmdletSessionInfo cmdletSessionInfo) { ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, searchRoot, ADSearchScope.Subtree); aDObjectSearcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectSid", sidObject); return(aDObjectSearcher); }
private void ValidateIdentity(T identityObj) { string str; if (identityObj != null) { if (base.CmdletSessionInfo != null) { if (!identityObj.IsSearchResult) { if (identityObj.Identity as ADDomain == null || !((ADDomain)identityObj.Identity).IsSearchResult) { str = identityObj.Identity.ToString(); } else { str = ((ADDomain)identityObj.Identity).DNSRoot; } } else { str = identityObj.Name; } ADRootDSE aDRootDSE = base.CmdletSessionInfo.ADRootDSE; string str1 = string.Concat("CN=Partitions,", aDRootDSE.ConfigurationNamingContext); ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(base.CmdletSessionInfo.ADSessionInfo, str1, ADSearchScope.OneLevel); using (aDObjectSearcher) { IADOPathNode[] aDOPathNodeArray = new IADOPathNode[3]; aDOPathNodeArray[0] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "crossRef"); IADOPathNode[] aDOPathNodeArray1 = new IADOPathNode[2]; aDOPathNodeArray1[0] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "dnsRoot", str); aDOPathNodeArray1[1] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "nETBIOSName", str); aDOPathNodeArray[1] = ADOPathUtil.CreateOrClause(aDOPathNodeArray1); aDOPathNodeArray[2] = ADOPathUtil.CreateFilterClause(ADOperator.Band, "systemFlags", 3); aDObjectSearcher.Filter = ADOPathUtil.CreateAndClause(aDOPathNodeArray); ADObject aDObject = aDObjectSearcher.FindOne(); if (aDObject == null) { object[] objArray = new object[1]; objArray[0] = str; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.CouldNotFindForestIdentity, objArray)); } } return; } else { throw new ArgumentNullException(StringResources.SessionRequired); } } else { object[] type = new object[2]; type[0] = "ValidateIdentity"; type[1] = identityObj.GetType(); throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.MethodNotSupportedForObjectType, type)); } }
internal static ADObjectSearcher BuildObjectGuidSearcher(Guid?guidObject, string searchBase, CmdletSessionInfo cmdletSessionInfo) { ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, searchBase, ADSearchScope.Subtree); Guid value = guidObject.Value; aDObjectSearcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectGUID", value.ToByteArray()); return(aDObjectSearcher); }
private static ADObjectSearcher BuildADOFGuidSearcher(Guid guidObject, string searchBase, CmdletSessionInfo cmdletSessionInfo) { ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, searchBase, ADSearchScope.Subtree); IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectGUID", guidObject.ToByteArray()); IADOPathNode aDOPathNode1 = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "msDS-OptionalFeatureGUID", guidObject.ToByteArray()); IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2]; aDOPathNodeArray[0] = aDOPathNode; aDOPathNodeArray[1] = aDOPathNode1; aDObjectSearcher.Filter = ADOPathUtil.CreateOrClause(aDOPathNodeArray); return(aDObjectSearcher); }
internal override ADObject GetDirectoryObjectFromIdentity(T identityObj, string searchRoot, bool showDeleted) { ADObject aDObject = null; ADObject aDObject1 = null; ADObject aDObject2 = null; ADObject aDSessionInfo; if (base.CmdletSessionInfo != null) { //base.CmdletSessionInfo.ADRootDSE.ConfigurationNamingContext; string nTDSSettingsDN = this.ResolveIdentityToNTDSSettingsDN(identityObj, ADDirectoryServerFactory <T> ._directoryServerDefaultAttributes, false, out aDObject, out aDObject1, out aDObject2); if (nTDSSettingsDN != null) { if (aDObject1 == null) { string str = nTDSSettingsDN.Substring("CN=NTDS Settings,".Length); ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(base.CmdletSessionInfo.ADSessionInfo, str, ADSearchScope.Base); using (aDObjectSearcher) { aDObjectSearcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*"); aDObjectSearcher.Properties.AddRange(ADDirectoryServerFactory <T> ._directoryServerDefaultAttributes); aDSessionInfo = aDObjectSearcher.FindOne(); if (aDSessionInfo == null) { DebugLogger.LogInfo("ADDirectoryServerFactory", string.Format("GetDirectoryObjectFromIdentity: Identity not found.", new object[0])); object[] objArray = new object[2]; objArray[0] = identityObj.ToString(); objArray[1] = str; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.IdentityNotFound, objArray)); } } } else { aDSessionInfo = aDObject1; } aDSessionInfo.TrackChanges = true; aDSessionInfo.SessionInfo = base.CmdletSessionInfo.ADSessionInfo; return(aDSessionInfo); } else { DebugLogger.LogInfo("ADDirectoryServerFactory", string.Format("GetDirectoryObjectFromIdentity: NTDS Settings DN for the given identity not found", new object[0])); object[] identity = new object[1]; identity[0] = identityObj.Identity; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.DirectoryServerNotFound, identity)); } } else { throw new ArgumentNullException(StringResources.SessionRequired); } }
private double GetInactiveTimeSpanDays(CmdletSessionInfo cmdletSessionInfo) { double num = 0; double num1; ADRootDSE rootDSE = this.GetRootDSE(); string defaultNamingContext = rootDSE.DefaultNamingContext; if (rootDSE.ServerType != ADServerType.ADDS || defaultNamingContext == null) { return(15); } else { SearchADAccountCmdlet._accountInactiveTimeSpanLock.EnterReadLock(); try { if (!SearchADAccountCmdlet._accountInactiveTimeSpanCache.TryGetValue(defaultNamingContext, out num)) { double value = 15; ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, defaultNamingContext, ADSearchScope.Base); using (aDObjectSearcher) { aDObjectSearcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*"); aDObjectSearcher.Properties.Add("msDS-LogonTimeSyncInterval"); ADObject aDObject = aDObjectSearcher.FindOne(); if (aDObject != null && aDObject.Contains("msDS-LogonTimeSyncInterval") && aDObject["msDS-LogonTimeSyncInterval"].Count > 0) { value = (double)((int)aDObject["msDS-LogonTimeSyncInterval"].Value); } } SearchADAccountCmdlet._accountInactiveTimeSpanLock.EnterWriteLock(); try { SearchADAccountCmdlet._accountInactiveTimeSpanCache[defaultNamingContext] = value; } finally { SearchADAccountCmdlet._accountInactiveTimeSpanLock.ExitWriteLock(); } return(value); } else { num1 = num; } } finally { SearchADAccountCmdlet._accountInactiveTimeSpanLock.ExitReadLock(); } return(num1); } }
private static int GetNTMixedDomainMode(CmdletSessionInfo cmdletSessionInfo) { int value; ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, cmdletSessionInfo.ADRootDSE.DefaultNamingContext, ADSearchScope.Base); using (aDObjectSearcher) { aDObjectSearcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*"); aDObjectSearcher.Properties.Add("ntMixedDomain"); ADObject aDObject = aDObjectSearcher.FindOne(); value = (int)aDObject["ntMixedDomain"].Value; } return(value); }
internal static ADObjectSearcher ADOFGuidIdentityResolver(object identityObject, string searchBase, CmdletSessionInfo cmdletSessionInfo, out bool useSearchFilter) { useSearchFilter = true; if (identityObject != null) { SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, searchBase, ADSearchScope.Subtree); Guid? nullable = null; string str = identityObject as string; if (string.IsNullOrEmpty(str) || !Utils.TryParseGuid(str, out nullable)) { if (!(identityObject is Guid)) { ADOptionalFeature aDOptionalFeature = identityObject as ADOptionalFeature; if (aDOptionalFeature != null) { Guid?objectGuid = aDOptionalFeature.ObjectGuid; if (!objectGuid.HasValue) { Guid?featureGUID = aDOptionalFeature.FeatureGUID; if (featureGUID.HasValue) { Guid?featureGUID1 = aDOptionalFeature.FeatureGUID; ADOptionalFeatureFactory <T> .BuildADOFGuidSearcher(featureGUID1.Value, searchBase, cmdletSessionInfo); } } else { useSearchFilter = true; Guid?objectGuid1 = aDOptionalFeature.ObjectGuid; return(IdentityResolverMethods.BuildGuidBaseSearcher(new Guid?(objectGuid1.Value), cmdletSessionInfo)); } } return(null); } else { return(ADOptionalFeatureFactory <T> .BuildADOFGuidSearcher((Guid)identityObject, searchBase, cmdletSessionInfo)); } } else { return(ADOptionalFeatureFactory <T> .BuildADOFGuidSearcher(nullable.Value, searchBase, cmdletSessionInfo)); } } else { throw new ArgumentNullException("identityObject"); } }
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)); } }
internal override ADObject GetDirectoryObjectFromIdentity(T identityObj, string searchRoot, bool showDeleted) { ADObject aDSessionInfo; if (base.CmdletSessionInfo != null) { string defaultNamingContext = base.CmdletSessionInfo.ADRootDSE.DefaultNamingContext; ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(base.CmdletSessionInfo.ADSessionInfo, defaultNamingContext, ADSearchScope.Base); using (aDObjectSearcher) { AttributeSetRequest attributeSetRequest = this.ConstructAttributeSetRequest(null); aDObjectSearcher.Properties.AddRange(attributeSetRequest.DirectoryAttributes); IADOPathNode[] structuralObjectFilter = new IADOPathNode[2]; structuralObjectFilter[0] = this.StructuralObjectFilter; structuralObjectFilter[1] = this.BuildIdentityFilter(identityObj); aDObjectSearcher.Filter = ADOPathUtil.CreateAndClause(structuralObjectFilter); DebugLogger.LogInfo("ADDefaultDomainPasswordPolicyFactory", string.Format("GetDirectoryObjectFromIdentity: Searching for identity using filter: {0} searchbase: {1}", aDObjectSearcher.Filter.GetLdapFilterString(), aDObjectSearcher.SearchRoot)); aDSessionInfo = aDObjectSearcher.FindOne(); if (aDSessionInfo == null) { DebugLogger.LogInfo("ADDefaultDomainPasswordPolicyFactory", string.Format("GetDirectoryObjectFromIdentity: 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)); } } if (!aDSessionInfo.ObjectClass.Equals("domainDNS", StringComparison.OrdinalIgnoreCase)) { object[] objArray = new object[2]; objArray[0] = identityObj.ToString(); objArray[1] = defaultNamingContext; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.IdentityNotFound, objArray)); } else { aDSessionInfo.TrackChanges = true; aDSessionInfo.SessionInfo = base.CmdletSessionInfo.ADSessionInfo; return(aDSessionInfo); } } else { throw new ArgumentNullException(StringResources.SessionRequired); } }
private bool MoveADDirectoryServerProcessCSRoutine() { this._identityDSObj = this._cmdletParameters["Identity"] as ADDirectoryServer; base.SetPipelinedSessionInfo(this._identityDSObj.SessionInfo); CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo(); ADDirectoryServerFactory <ADDirectoryServer> aDDirectoryServerFactory = new ADDirectoryServerFactory <ADDirectoryServer>(); aDDirectoryServerFactory.SetCmdletSessionInfo(cmdletSessionInfo); ADObject directoryObjectFromIdentity = aDDirectoryServerFactory.GetDirectoryObjectFromIdentity(this._identityDSObj, cmdletSessionInfo.DefaultPartitionPath); string str = string.Concat("CN=Servers,", this._siteDirObj.DistinguishedName); ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, str, ADSearchScope.Base); using (aDObjectSearcher) { aDObjectSearcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*"); ADObject aDObject = aDObjectSearcher.FindOne(); if (aDObject == null) { base.ThrowTerminatingError(ADUtilities.GetErrorRecord(new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ObjectNotFound, new object[0])), "MoveADDirectoryServer:ProcessRecord", str)); } StringBuilder stringBuilder = new StringBuilder("Move-ADObject -identity $args[0] -Partition $args[1] -TargetPath $args[2] "); try { object[] configurationNamingContext = new object[3]; configurationNamingContext[0] = directoryObjectFromIdentity; configurationNamingContext[1] = cmdletSessionInfo.ADRootDSE.ConfigurationNamingContext; configurationNamingContext[2] = aDObject.DistinguishedName; base.InvokeCommand.InvokeScript(stringBuilder.ToString(), false, PipelineResultTypes.Output, null, configurationNamingContext); } catch (RuntimeException runtimeException1) { RuntimeException runtimeException = runtimeException1; object[] distinguishedName = new object[3]; distinguishedName[0] = directoryObjectFromIdentity.DistinguishedName; distinguishedName[1] = this._siteDirObj.DistinguishedName; distinguishedName[2] = runtimeException.Message; string str1 = string.Format(CultureInfo.CurrentCulture, "Failed moving the directory server: {0} to new site: {1}. Error: {2}", distinguishedName); DebugLogger.LogError("MoveADDirectoryServer", str1); base.WriteError(new ErrorRecord(runtimeException, "0", ErrorCategory.WriteError, this._identityDSObj)); } } return(true); }
internal static ADObjectSearcher BuildAggregatedSearchFilterIdentityResolver(IdentityResolverDelegate[] identityDelegates, ADOperator op, object identity, string searchRoot, CmdletSessionInfo cmdletSessionInfo, out bool useSearchFilter) { ADObjectSearcher item; List <IADOPathNode> aDOPathNodes = new List <IADOPathNode>((int)identityDelegates.Length); IdentityResolverDelegate[] identityResolverDelegateArray = identityDelegates; for (int i = 0; i < (int)identityResolverDelegateArray.Length; i++) { bool V_1; IdentityResolverDelegate identityResolverDelegate = identityResolverDelegateArray[i]; item = identityResolverDelegate(identity, searchRoot, cmdletSessionInfo, out V_1); if (item != null) { aDOPathNodes.Add(item.Filter); } } item = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, searchRoot, ADSearchScope.Subtree); if (aDOPathNodes.Count <= 1) { if (aDOPathNodes.Count != 1) { item = null; } else { item.Filter = aDOPathNodes[0]; } } else { if (ADOperator.Or != op) { item.Filter = ADOPathUtil.CreateAndClause(aDOPathNodes.ToArray()); } else { item.Filter = ADOPathUtil.CreateOrClause(aDOPathNodes.ToArray()); } } useSearchFilter = true; return(item); }
internal static bool IsStaleServerObject(ADSessionInfo sessionInfo, string serverObjectDN) { bool flag; if (serverObjectDN != null) { ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(sessionInfo, serverObjectDN, ADSearchScope.OneLevel); using (aDObjectSearcher) { aDObjectSearcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "nTDSDSA"); ADObject aDObject = aDObjectSearcher.FindOne(); flag = aDObject == null; } return(flag); } else { throw new ArgumentNullException("serverObjectDN"); } }
internal static ADObjectSearcher SamAccountNameIdentityResolver(object identityObject, string searchBase, CmdletSessionInfo cmdletSessionInfo, out bool useSearchFilter) { useSearchFilter = true; if (identityObject != null) { ADPrincipal aDPrincipal = identityObject as ADPrincipal; if (aDPrincipal == null || aDPrincipal.SamAccountName == null) { return(null); } else { ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, searchBase, ADSearchScope.Subtree); aDObjectSearcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "sAMAccountName", aDPrincipal.SamAccountName); return(aDObjectSearcher); } } else { throw new ArgumentNullException("identityObject"); } }
internal static ADObjectSearcher BuildGenericSearcher(string[] identityLdapAttributes, object identity, string searchRoot, CmdletSessionInfo cmdletSessionInfo, out bool useSearchFilter) { useSearchFilter = true; string str = identity as string; if (!string.IsNullOrEmpty(str)) { ADObjectSearcher item = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, searchRoot, ADSearchScope.Subtree); List <IADOPathNode> aDOPathNodes = new List <IADOPathNode>((int)identityLdapAttributes.Length); string[] strArrays = identityLdapAttributes; for (int i = 0; i < (int)strArrays.Length; i++) { string str1 = strArrays[i]; if (str1 != "distinguishedName") { aDOPathNodes.Add(ADOPathUtil.CreateFilterClause(ADOperator.Eq, str1, str)); } else { string str2 = Utils.EscapeDNForFilter(str); aDOPathNodes.Add(ADOPathUtil.CreateFilterClause(ADOperator.Eq, str1, str2)); } } if (aDOPathNodes.Count <= 1) { item.Filter = aDOPathNodes[0]; } else { item.Filter = ADOPathUtil.CreateOrClause(aDOPathNodes.ToArray()); } return(item); } else { return(null); } }
private bool GetADAcctResPrpProcessCSRoutine() { ADResultantPasswordReplicationPolicy aDResultantPasswordReplicationPolicy = ADResultantPasswordReplicationPolicy.DenyExplicit; int?value; this._partitionPath = this._cmdletParameters["Partition"] as string; this._identityADAccount = this._cmdletParameters["Identity"] as ADAccount; this._targetDCAccount = this._cmdletParameters["DomainController"] as ADDomainController; base.SetPipelinedSessionInfo(this._identityADAccount.SessionInfo); CmdletSessionInfo cmdletSessionInfo = base.GetCmdletSessionInfo(); if (cmdletSessionInfo.ADRootDSE.IsWindows2008AndAbove()) { if (!cmdletSessionInfo.ADRootDSE.IsWritable()) { object[] dNSHostName = new object[1]; dNSHostName[0] = cmdletSessionInfo.ADRootDSE.DNSHostName; base.WriteWarning(string.Format(CultureInfo.CurrentCulture, StringResources.WarningResultantPRPNotAccurateOnRODC, dNSHostName)); } ADDomainControllerFactory <ADDomainController> aDDomainControllerFactory = new ADDomainControllerFactory <ADDomainController>(); aDDomainControllerFactory.SetCmdletSessionInfo(cmdletSessionInfo); ADAccountFactory <ADAccount> aDAccountFactory = new ADAccountFactory <ADAccount>(); aDAccountFactory.SetCmdletSessionInfo(cmdletSessionInfo); ADObject directoryObjectFromIdentity = aDDomainControllerFactory.GetDirectoryObjectFromIdentity(this._targetDCAccount, cmdletSessionInfo.DefaultPartitionPath); ADObject aDObject = aDAccountFactory.GetDirectoryObjectFromIdentity(this._identityADAccount, cmdletSessionInfo.DefaultPartitionPath); ADObjectSearcher distinguishedName = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, directoryObjectFromIdentity.DistinguishedName, ADSearchScope.Base); using (distinguishedName) { distinguishedName.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*"); distinguishedName.Properties.Add("msDS-IsUserCachableAtRodc"); distinguishedName.InputDN = aDObject.DistinguishedName; ADObject aDObject1 = distinguishedName.FindOne(); if (aDObject1["msDS-IsUserCachableAtRodc"] == null) { int?nullable = null; value = nullable; } else { value = (int?)aDObject1["msDS-IsUserCachableAtRodc"].Value; } int?nullable1 = value; if (nullable1.HasValue) { if (!Utils.TryParseEnum <ADResultantPasswordReplicationPolicy>(nullable1.ToString(), out aDResultantPasswordReplicationPolicy)) { DebugLogger.LogInfo("GetADAccountResultantPasswordReplicationPolicy", string.Format("Error parsing resultant prp: {0} for account {1} on RODC {2}", aDResultantPasswordReplicationPolicy, aDObject.DistinguishedName, directoryObjectFromIdentity.DistinguishedName)); base.WriteObject(ADResultantPasswordReplicationPolicy.Unknown); } else { base.WriteObject(aDResultantPasswordReplicationPolicy); } } else { base.WriteObject(ADResultantPasswordReplicationPolicy.Unknown); } } return(true); } else { base.WriteError(new ErrorRecord(new ArgumentException(StringResources.ErrorResultantPRPSpecifyWindows2008OrAbove), "GetADAccountResultantPasswordReplicationPolicy:ProcessRecord", ErrorCategory.InvalidData, null)); return(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])); } }
private bool MoveADDSOperationMasterRoleProcessCSRoutine() { ADObject aDObject; bool flag = false; string value; int? nullable; this._identityDSObj = this._cmdletParameters["Identity"] as ADDirectoryServer; this._seize = this._cmdletParameters.GetSwitchParameterBooleanValue("Force"); this._operationMasterRolesToTransfer = this._cmdletParameters["OperationMasterRole"] as ADOperationMasterRole[]; base.SetPipelinedSessionInfo(this._identityDSObj.SessionInfo); CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo(); if (cmdletSessionInfo.ConnectedADServerType == ADServerType.ADLDS) { ADOperationMasterRole[] aDOperationMasterRoleArray = this._operationMasterRolesToTransfer; for (int i = 0; i < (int)aDOperationMasterRoleArray.Length; i++) { ADOperationMasterRole aDOperationMasterRole = aDOperationMasterRoleArray[i]; ADOperationMasterRole aDOperationMasterRole1 = aDOperationMasterRole; switch (aDOperationMasterRole1) { case ADOperationMasterRole.PDCEmulator: case ADOperationMasterRole.RIDMaster: case ADOperationMasterRole.InfrastructureMaster: { object[] str = new object[1]; str[0] = aDOperationMasterRole.ToString(); throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.MoveOperationMasterRoleNotApplicableForADLDS, str)); } } } } ADDirectoryServerFactory <ADDirectoryServer> aDDirectoryServerFactory = new ADDirectoryServerFactory <ADDirectoryServer>(); aDDirectoryServerFactory.SetCmdletSessionInfo(cmdletSessionInfo); ADObject directoryObjectFromIdentity = aDDirectoryServerFactory.GetDirectoryObjectFromIdentity(this._identityDSObj, cmdletSessionInfo.DefaultPartitionPath); string distinguishedName = directoryObjectFromIdentity.DistinguishedName; ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, distinguishedName, ADSearchScope.Base); using (aDObjectSearcher) { aDObjectSearcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*"); aDObjectSearcher.Properties.Add("dNSHostName"); directoryObjectFromIdentity = aDObjectSearcher.FindOne(); if (directoryObjectFromIdentity != null) { if (directoryObjectFromIdentity["dNSHostName"] == null) { value = null; } else { value = (string)directoryObjectFromIdentity["dNSHostName"].Value; } string str1 = value; if (!string.IsNullOrEmpty(str1)) { if (cmdletSessionInfo.ConnectedADServerType == ADServerType.ADLDS) { string str2 = string.Concat("CN=NTDS Settings,", distinguishedName); ADObjectSearcher aDObjectSearcher1 = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, str2, ADSearchScope.Base); using (aDObjectSearcher1) { aDObjectSearcher1.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*"); aDObjectSearcher1.Properties.Add("msDS-PortLDAP"); aDObject = aDObjectSearcher1.FindOne(); } if (aDObject != null) { if (aDObject["msDS-PortLDAP"] == null) { int?nullable1 = null; nullable = nullable1; } else { nullable = (int?)aDObject["msDS-PortLDAP"].Value; } int?nullable2 = nullable; if (nullable2.HasValue) { str1 = string.Concat(str1, ":", nullable2); } else { object[] objArray = new object[2]; objArray[0] = "msDS-PortLDAP"; objArray[1] = aDObject.DistinguishedName; throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.AttributeNotFoundOnObject, objArray)); } } else { throw new ADIdentityNotFoundException(string.Concat(StringResources.ObjectNotFound, " : ", str2)); } } ADSessionInfo aDSessionInfo = cmdletSessionInfo.ADSessionInfo.Copy(); aDSessionInfo.Server = str1; using (ADTopologyManagement aDTopologyManagement = new ADTopologyManagement(aDSessionInfo)) { ADOperationMasterRole[] aDOperationMasterRoleArray1 = this._operationMasterRolesToTransfer; for (int j = 0; j < (int)aDOperationMasterRoleArray1.Length; j++) { ADOperationMasterRole aDOperationMasterRole2 = aDOperationMasterRoleArray1[j]; string str3 = string.Format(CultureInfo.CurrentCulture, StringResources.MoveOperationMasterRoleDescription, new object[0]); object[] objArray1 = new object[2]; objArray1[0] = aDOperationMasterRole2.ToString(); objArray1[1] = str1; string str4 = string.Format(CultureInfo.CurrentCulture, StringResources.MoveOperationMasterRoleWarning, objArray1); string str5 = string.Format(CultureInfo.CurrentCulture, StringResources.MoveOperationMasterRoleCaption, new object[0]); if (base.ShouldProcessOverride(str3, str4, str5)) { aDTopologyManagement.MoveOperationMasterRole(aDOperationMasterRole2, this._seize, out flag); } } } } else { object[] distinguishedName1 = new object[2]; distinguishedName1[0] = "dNSHostName"; distinguishedName1[1] = directoryObjectFromIdentity.DistinguishedName; throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.AttributeNotFoundOnObject, distinguishedName1)); } } else { throw new ADIdentityNotFoundException(string.Concat(StringResources.ObjectNotFound, " : ", distinguishedName)); } } return(true); }
internal static ADObjectSearcher BuildSearcher(ADSessionInfo session, string searchRoot, ADSearchScope searchScope) { return(SearchUtility.BuildSearcher(session, searchRoot, searchScope, false)); }
internal static ADObjectSearcher BuildDNBaseSearcher(string DN, CmdletSessionInfo cmdletSessionInfo) { return(SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, DN, ADSearchScope.Base)); }
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); }
internal static ADObjectSearcher GetADObjectSearcherFromIdentity(ADEntity identityObj, string searchRoot, bool showDeleted, IADOPathNode structuralObjectFilter, IADOPathNode identityFilter, IdentityResolverDelegate[] identityResolvers, CmdletSessionInfo cmdletSessionInfo) { ADObjectSearcher identity = null; IADOPathNode aDOPathNode = null; bool flag = true; IdentityResolverDelegate[] identityResolverDelegateArray = identityResolvers; int num = 0; while (num < (int)identityResolverDelegateArray.Length) { IdentityResolverDelegate identityResolverDelegate = identityResolverDelegateArray[num]; if (identityObj.Identity == null) { identity = identityResolverDelegate(identityObj, searchRoot, cmdletSessionInfo, out flag); } else { identity = identityResolverDelegate(identityObj.Identity, searchRoot, cmdletSessionInfo, out flag); } if (identity == null) { num++; } else { if (!flag) { aDOPathNode = structuralObjectFilter; break; } else { IADOPathNode[] filter = new IADOPathNode[2]; filter[0] = identity.Filter; filter[1] = structuralObjectFilter; aDOPathNode = ADOPathUtil.CreateAndClause(filter); break; } } } if (identity == null) { if (searchRoot != null) { if (identityFilter != null) { IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2]; aDOPathNodeArray[0] = identityFilter; aDOPathNodeArray[1] = structuralObjectFilter; aDOPathNode = ADOPathUtil.CreateAndClause(aDOPathNodeArray); identity = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, searchRoot, ADSearchScope.Subtree); } else { object[] str = new object[2]; str[0] = identityObj.ToString(); str[1] = searchRoot; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.IdentityNotFound, str)); } } else { throw new ADIdentityResolutionException(StringResources.IdentityResolutionPartitionRequired); } } identity.Filter = aDOPathNode; identity.ShowDeleted = showDeleted; return(identity); }
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); }
internal ADObject GetDirectoryObjectFromIdentity(T identityObj, string searchRoot, ICollection <string> propertiesToFetch) { ADObject aDObject = null; ADObject aDObject1 = null; ADObject aDObject2 = null; HashSet <string> strs = new HashSet <string>(ADDomainControllerFactory <T> ._domainControllerDefaultAttributes, StringComparer.OrdinalIgnoreCase); if (propertiesToFetch != null) { strs.UnionWith(propertiesToFetch); } string[] strArrays = new string[strs.Count]; strs.CopyTo(strArrays); string nTDSSettingsDN = base.ResolveIdentityToNTDSSettingsDN(identityObj, strArrays, true, out aDObject, out aDObject1, out aDObject2); if (nTDSSettingsDN != null) { ADObject aDSessionInfo = null; if (aDObject == null) { string value = null; if (aDObject1 == null) { string str = nTDSSettingsDN.Substring("CN=NTDS Settings,".Length); ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(base.CmdletSessionInfo.ADSessionInfo, str, ADSearchScope.Base); using (aDObjectSearcher) { aDObjectSearcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*"); string[] strArrays1 = new string[1]; strArrays1[0] = "serverReference"; aDObjectSearcher.Properties.AddRange(strArrays1); ADObject aDObject3 = aDObjectSearcher.FindOne(); if (aDObject3 != null) { value = aDObject3["serverReference"].Value as string; } } } else { value = aDObject1["serverReference"].Value as string; } if (value != null) { ADObjectSearcher aDObjectSearcher1 = SearchUtility.BuildSearcher(base.CmdletSessionInfo.ADSessionInfo, value, ADSearchScope.Base); using (aDObjectSearcher1) { aDObjectSearcher1.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*"); aDObjectSearcher1.Properties.AddRange(strArrays); aDSessionInfo = aDObjectSearcher1.FindOne(); if (aDSessionInfo == null) { DebugLogger.LogInfo("ADDomainControllerFactory", string.Format("GetDirectoryObjectFromIdentity: Identity not found. Filter used: {0}", value)); object[] objArray = new object[2]; objArray[0] = nTDSSettingsDN; objArray[1] = aDObjectSearcher1.SearchRoot; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.IdentityNotFound, objArray)); } } } else { object[] identity = new object[1]; identity[0] = identityObj.Identity; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.DirectoryServerNotFound, identity)); } } else { aDSessionInfo = aDObject; } aDSessionInfo.TrackChanges = true; aDSessionInfo.SessionInfo = base.CmdletSessionInfo.ADSessionInfo; return(aDSessionInfo); } else { DebugLogger.LogInfo("ADDomainControllerFactory", string.Format("GetDirectoryObjectFromIdentity: NTDS Settings DN for the given directory server identity not found", new object[0])); object[] identity1 = new object[1]; identity1[0] = identityObj.Identity; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.DirectoryServerNotFound, identity1)); } }
internal static ADObjectSearcher BuildGuidBaseSearcher(Guid?guidObject, CmdletSessionInfo cmdletSessionInfo) { string str = string.Concat("<GUID=", guidObject, ">"); return(SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, str, ADSearchScope.Base)); }
private bool GetADForestCalculateIdentityCSRoutine() { bool hasValue; bool flag; string value = null; string item = this._cmdletParameters["Server"] as string; ADCurrentForestType?nullable = (ADCurrentForestType?)(this._cmdletParameters["Current"] as ADCurrentForestType?); if (this._cmdletParameters["Identity"] == null) { if (!nullable.HasValue) { if (item != null || ProviderUtils.IsCurrentDriveAD(base.SessionState)) { ADRootDSE rootDSE = this.GetRootDSE(); string str = string.Concat("CN=Partitions,", rootDSE.ConfigurationNamingContext); ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(this.GetSessionInfo(), str, ADSearchScope.OneLevel); using (aDObjectSearcher) { IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2]; aDOPathNodeArray[0] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "crossRef"); aDOPathNodeArray[1] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "nCName", rootDSE.RootDomainNamingContext); aDObjectSearcher.Filter = ADOPathUtil.CreateAndClause(aDOPathNodeArray); aDObjectSearcher.Properties.Add("dnsRoot"); ADObject aDObject = aDObjectSearcher.FindOne(); if (aDObject != null) { value = aDObject["dnsRoot"].Value as string; } if (value == null) { object[] rootDomainNamingContext = new object[1]; rootDomainNamingContext[0] = rootDSE.RootDomainNamingContext; throw new ADIdentityResolutionException(string.Format(CultureInfo.CurrentCulture, StringResources.CouldNotFindForestIdentity, rootDomainNamingContext)); } } } else { nullable = new ADCurrentForestType?(ADCurrentForestType.LoggedOnUser); } } ADCurrentForestType?nullable1 = nullable; if (nullable1.GetValueOrDefault() != ADCurrentForestType.LocalComputer) { hasValue = false; } else { hasValue = nullable1.HasValue; } if (!hasValue) { ADCurrentForestType?nullable2 = nullable; if (nullable2.GetValueOrDefault() != ADCurrentForestType.LoggedOnUser) { flag = false; } else { flag = nullable2.HasValue; } if (!flag) { if (nullable.HasValue) { throw new ArgumentException("Current"); } } else { value = base.EffectiveDomainName; } } else { SelectQuery selectQuery = new SelectQuery(WMIConstants.ComputerSystem); ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(selectQuery); ManagementObjectCollection managementObjectCollections = managementObjectSearcher.Get(); ManagementObjectCollection.ManagementObjectEnumerator enumerator = managementObjectCollections.GetEnumerator(); using (enumerator) { if (enumerator.MoveNext()) { ManagementObject current = (ManagementObject)enumerator.Current; value = current[WMIConstants.Domain] as string; } } if (value == null) { throw new ArgumentException(StringResources.CouldNotDetermineLocalComputerDomain); } } if (value != null) { this._cmdletParameters["Identity"] = new ADForest(value); } return(true); } else { return(true); } }