internal static ADObject GetObjectFromIdentitySearcher(ADObjectSearcher searcher, ADEntity identityObj, string searchRoot, AttributeSetRequest attrs, CmdletSessionInfo cmdletSessionInfo, out string[] warningMessages) { ADObject aDObject; bool flag = false; warningMessages = new string[0]; using (searcher) { searcher.Properties.AddRange(attrs.DirectoryAttributes); DebugLogger.LogInfo("ADFactoryUtil", string.Format("GetObjectFromIdentity: Searching for identity using filter: {0} searchbase: {1}", searcher.Filter.GetLdapFilterString(), searcher.SearchRoot)); aDObject = searcher.FindOne(out flag); if (aDObject != null) { if (flag) { throw new ADMultipleMatchingIdentitiesException(StringResources.MultipleMatches); } } else { DebugLogger.LogInfo("ADFactoryUtil", string.Format("GetObjectFromIdentity: Identity not found.", new object[0])); object[] str = new object[2]; str[0] = identityObj.ToString(); str[1] = searchRoot; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.IdentityNotFound, str)); } } string str1 = ADForestPartitionInfo.ExtractPartitionInfo(cmdletSessionInfo.ADRootDSE, aDObject.DistinguishedName, false); if (cmdletSessionInfo.CmdletParameters.Contains("Partition")) { string item = cmdletSessionInfo.CmdletParameters["Partition"] as string; if (!ADPathModule.ComparePath(item, str1, ADPathFormat.X500)) { string[] strArrays = new string[1]; object[] objArray = new object[3]; objArray[0] = identityObj.ToString(); objArray[1] = str1; objArray[2] = item; strArrays[0] = string.Format(CultureInfo.CurrentCulture, StringResources.IdentityInWrongPartition, objArray); warningMessages = strArrays; } } cmdletSessionInfo.DefaultPartitionPath = str1; return(aDObject); }
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 GetGroupMembershipProcessCSRoutine() { this._partitionPath = this._cmdletParameters["Partition"] as string; this._identityADPrincipal = this._cmdletParameters["Identity"] as ADPrincipal; base.SetPipelinedSessionInfo(this._identityADPrincipal.SessionInfo); CmdletSessionInfo cmdletSessionInfo = base.GetCmdletSessionInfo(); ADPrincipalFactory <ADPrincipal> aDPrincipalFactory = new ADPrincipalFactory <ADPrincipal>(); aDPrincipalFactory.SetCmdletSessionInfo(cmdletSessionInfo); this.ValidateParameters(); ADObject directoryObjectFromIdentity = aDPrincipalFactory.GetDirectoryObjectFromIdentity(this._identityADPrincipal, cmdletSessionInfo.DefaultPartitionPath); using (ADAccountManagement aDAccountManagement = new ADAccountManagement(cmdletSessionInfo.ADSessionInfo)) { if (!string.IsNullOrEmpty(this._resourceContextServer) && string.IsNullOrEmpty(this._resourceContextPartition)) { ADSessionInfo aDSessionInfo = cmdletSessionInfo.ADSessionInfo.Copy(); aDSessionInfo.Server = this._resourceContextServer; using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(aDSessionInfo)) { ADRootDSE rootDSE = aDObjectSearcher.GetRootDSE(); if (rootDSE.DefaultNamingContext != null) { this._resourceContextPartition = rootDSE.DefaultNamingContext; } else { object[] objArray = new object[1]; objArray[0] = "ResourceContextPartition"; base.ThrowTerminatingError(new ErrorRecord(new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ParameterRequired, objArray)), "1", ErrorCategory.InvalidArgument, null)); } } } ADGroup[] principalGroupMembership = aDAccountManagement.GetPrincipalGroupMembership(cmdletSessionInfo.DefaultPartitionPath, directoryObjectFromIdentity.DistinguishedName, this._resourceContextServer, this._resourceContextPartition); ADGroup[] aDGroupArray = principalGroupMembership; for (int i = 0; i < (int)aDGroupArray.Length; i++) { ADGroup aDGroup = aDGroupArray[i]; base.WriteObject(aDGroup); } } return(true); }
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 string GetWellKnownGuidDN(ADSessionInfo adSession, string partitionDN, string wellKnownGuid) { string distinguishedName; if (partitionDN != null) { ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(adSession); try { try { aDObjectSearcher.SearchRoot = string.Format("<WKGUID={0},{1}>", wellKnownGuid, partitionDN); aDObjectSearcher.Scope = ADSearchScope.Base; aDObjectSearcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*"); ADObject aDObject = aDObjectSearcher.FindOne(); if (aDObject == null) { distinguishedName = null; } else { distinguishedName = aDObject.DistinguishedName; } } catch (ADIdentityNotFoundException aDIdentityNotFoundException1) { ADIdentityNotFoundException aDIdentityNotFoundException = aDIdentityNotFoundException1; DebugLogger.LogError("Utils", string.Format("Error in searching for WKGUID {0}", aDIdentityNotFoundException.Message)); distinguishedName = null; } } finally { aDObjectSearcher.Dispose(); } return(distinguishedName); } else { return(null); } }
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"); } }
private bool GetADRootDSEBeginCSRoutine() { bool flag; Collection <string> strs = new Collection <string>(); string[] item = this._cmdletParameters["Properties"] as string[]; strs.Add("*"); if (item != null) { for (int i = 0; i < (int)item.Length; i++) { strs.Add(item[i]); } } ADObjectSearcher aDObjectSearcher = null; using (aDObjectSearcher) { try { aDObjectSearcher = new ADObjectSearcher(this.GetSessionInfo()); ADRootDSE rootDSE = aDObjectSearcher.GetRootDSE(strs); rootDSE.SessionInfo = base.GetCmdletSessionInfo().ADSessionInfo; base.WriteObject(rootDSE); flag = true; } catch (ADException aDException1) { ADException aDException = aDException1; base.WriteError(ADUtilities.GetErrorRecord(aDException, "GetADRootDSE:BeginProcessing:ADError", null)); flag = false; } catch (AuthenticationException authenticationException1) { AuthenticationException authenticationException = authenticationException1; base.WriteError(ADUtilities.GetErrorRecord(authenticationException, "GetADRootDSE:BeginProcessing:InvalidCredentials", null)); flag = false; } } return(flag); }
internal static IdentityResolverDelegate GetGenericIdentityResolverWithSamName(string[] identityLdapAttributes) { return((object identityObject, string searchBase, CmdletSessionInfo cmdletSessionInfo, out bool useSearchFilter) => { useSearchFilter = true; ADObjectSearcher aDObjectSearcher = IdentityResolverMethods.BuildGenericSearcher(identityLdapAttributes, identityObject, searchBase, cmdletSessionInfo, out useSearchFilter); if (aDObjectSearcher != null) { string str = identityObject as string; if (str != null && !str.EndsWith("$", StringComparison.OrdinalIgnoreCase)) { IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "sAMAccountName", string.Concat(str, "$")); IADOPathNode[] filter = new IADOPathNode[2]; filter[0] = aDObjectSearcher.Filter; filter[1] = aDOPathNode; aDObjectSearcher.Filter = ADOPathUtil.CreateOrClause(filter); } } return aDObjectSearcher; } ); }
internal override ADObject GetDirectoryObjectFromIdentity(T identityObj, string searchRoot, bool showDeleted) { ADObject aDObject = identityObj; if (aDObject != null) { if (base.CmdletSessionInfo != null) { if (aDObject.IsSearchResult && aDObject.Contains("isDeleted")) { showDeleted = true; } ADObjectSearcher aDObjectSearcherFromIdentity = ADFactoryUtil.GetADObjectSearcherFromIdentity(identityObj, searchRoot, showDeleted, this.StructuralObjectFilter, this.BuildIdentityFilter(identityObj), this.IdentityResolvers, base.CmdletSessionInfo); AttributeSetRequest attributeSetRequest = this.ConstructAttributeSetRequest(null); string[] strArrays = new string[0]; ADObject objectFromIdentitySearcher = ADFactoryUtil.GetObjectFromIdentitySearcher(aDObjectSearcherFromIdentity, identityObj, searchRoot, attributeSetRequest, base.CmdletSessionInfo, out strArrays); objectFromIdentitySearcher.TrackChanges = true; objectFromIdentitySearcher.SessionInfo = base.CmdletSessionInfo.ADSessionInfo; string[] strArrays1 = strArrays; for (int i = 0; i < (int)strArrays1.Length; i++) { string str = strArrays1[i]; base.CmdletSessionInfo.CmdletMessageWriter.WriteWarningBuffered(str); } return(objectFromIdentitySearcher); } else { throw new ArgumentNullException(StringResources.SessionRequired); } } else { object[] type = new object[2]; type[0] = "GetDirectoryObjectFromIdentity"; type[1] = identityObj.GetType(); throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.MethodNotSupportedForObjectType, type)); } }
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); } }
internal override void PerServerProcessRecord() { ADEntity rootDSE; CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo(); this._factory.SetCmdletSessionInfo(cmdletSessionInfo); string[] strArrays = new string[2]; strArrays[0] = "msDS-ReplConnectionFailures"; strArrays[1] = "msDS-ReplLinkFailures"; string[] strArrays1 = strArrays; using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(cmdletSessionInfo.ADSessionInfo)) { rootDSE = aDObjectSearcher.GetRootDSE(strArrays1); } foreach (ADReplicationFailure extendedObjectFromDirectoryObject in this._factory.GetExtendedObjectFromDirectoryObject(rootDSE, "msDS-ReplLinkFailures", "DS_REPL_KCC_DSA_FAILURE")) { base.WriteObject(extendedObjectFromDirectoryObject); } foreach (ADReplicationFailure aDReplicationFailure in this._factory.GetExtendedObjectFromDirectoryObject(rootDSE, "msDS-ReplConnectionFailures", "DS_REPL_KCC_DSA_FAILURE")) { base.WriteObject(aDReplicationFailure); } }
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); }
private bool ADMoveCmdletBaseProcessCSRoutine() { bool flag; O item = (O)this._cmdletParameters["Identity"]; this.SetPipelinedSessionInfo(item.SessionInfo); CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo(); this._factory.SetCmdletSessionInfo(cmdletSessionInfo); this.ValidateParameters(); string defaultPartitionPath = this.GetDefaultPartitionPath(); ADObject directoryObjectFromIdentity = this._factory.GetDirectoryObjectFromIdentity(item, defaultPartitionPath); using (ADActiveObject aDActiveObject = new ADActiveObject(cmdletSessionInfo.ADSessionInfo, directoryObjectFromIdentity)) { if (base.ShouldProcessOverride(directoryObjectFromIdentity.DistinguishedName, "Move")) { O o = default(O); if (this._factory.PreCommitProcesing(ADFactory <O> .DirectoryOperation.Move, o, this._cmdletParameters, directoryObjectFromIdentity)) { aDActiveObject.Update(); } string str = this._cmdletParameters["TargetPath"] as string; string childName = ADPathModule.GetChildName(directoryObjectFromIdentity.DistinguishedName, ADPathFormat.X500); string item1 = null; if (!this._cmdletParameters.Contains("TargetServer")) { aDActiveObject.Move(str, childName); } else { item1 = this._cmdletParameters["TargetServer"] as string; aDActiveObject.CrossDomainMove(str, childName, item1); } O o1 = default(O); this._factory.PostCommitProcesing(ADFactory <O> .DirectoryOperation.Move, o1, this._cmdletParameters, directoryObjectFromIdentity); if (this._cmdletParameters.GetSwitchParameterBooleanValue("PassThru")) { ADSessionInfo aDSessionInfo = cmdletSessionInfo.ADSessionInfo; if (this._cmdletParameters.Contains("TargetServer")) { aDSessionInfo.Server = item1; } string str1 = ADPathModule.MakePath(str, childName, ADPathFormat.X500); F f = Activator.CreateInstance <F>(); using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(aDSessionInfo)) { ADRootDSE rootDSE = aDObjectSearcher.GetRootDSE(); ADCmdletCache aDCmdletCache = new ADCmdletCache(); aDSessionInfo.ServerType = Utils.ADServerTypeFromRootDSE(rootDSE); CmdletSessionInfo cmdletSessionInfo1 = new CmdletSessionInfo(aDSessionInfo, rootDSE, rootDSE.DefaultNamingContext, rootDSE.DefaultNamingContext, rootDSE.DefaultNamingContext, aDSessionInfo.ServerType, aDCmdletCache, this, this, this._cmdletParameters); f.SetCmdletSessionInfo(cmdletSessionInfo1); O extendedObjectFromDN = this._factory.GetExtendedObjectFromDN(str1); base.WriteObject(extendedObjectFromDN); aDCmdletCache.Clear(); } } return(true); } else { flag = false; } } return(flag); }
private bool SyncADObjectProcessCSRoutine() { CmdletSessionInfo cmdletSessionInfo; ADRootDSE rootDSE; ADObject directoryObjectFromIdentity; bool flag; string empty; this.ValidateParameters(); ADObject obj = this._cmdletParameters.Object; string destination = this._cmdletParameters.Destination; if (this.sourceServer == null) { if (!obj.IsSearchResult) { if (this.currentADDriveServer == null) { object[] objArray = new object[1]; objArray[0] = "Source"; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ParameterRequired, objArray)); } else { this.sourceServer = this.currentADDriveServer; } } else { this.sourceServer = obj.SessionInfo.Server; } } try { cmdletSessionInfo = this.GetCmdletSessionInfo(); } catch (ADServerDownException aDServerDownException1) { ADServerDownException aDServerDownException = aDServerDownException1; object[] objArray1 = new object[1]; objArray1[0] = destination; throw new ADServerDownException(string.Format(CultureInfo.CurrentCulture, StringResources.DestinationServerDown, objArray1), aDServerDownException.InnerException, destination); } if (!cmdletSessionInfo.ADRootDSE.IsWritable() || !this._cmdletParameters.GetSwitchParameterBooleanValue("PasswordOnly")) { string dSServiceName = null; ADSessionInfo aDSessionInfo = cmdletSessionInfo.ADSessionInfo.Copy(); aDSessionInfo.Server = this.sourceServer; string distinguishedName = null; using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(aDSessionInfo)) { try { rootDSE = aDObjectSearcher.GetRootDSE(); dSServiceName = rootDSE.DSServiceName; } catch (ADIdentityNotFoundException aDIdentityNotFoundException) { object[] objArray2 = new object[1]; objArray2[0] = this.sourceServer; throw new ADServerDownException(string.Format(CultureInfo.CurrentCulture, StringResources.SourceServerDown, objArray2), this.sourceServer); } if (!obj.IsSearchResult) { ADCmdletCache aDCmdletCache = new ADCmdletCache(); aDSessionInfo.ServerType = Utils.ADServerTypeFromRootDSE(rootDSE); CmdletSessionInfo cmdletSessionInfo1 = new CmdletSessionInfo(aDSessionInfo, rootDSE, rootDSE.DefaultNamingContext, rootDSE.DefaultNamingContext, rootDSE.DefaultNamingContext, aDSessionInfo.ServerType, aDCmdletCache, this, null, this._cmdletParameters); this._adObjectFactory.SetCmdletSessionInfo(cmdletSessionInfo1); try { directoryObjectFromIdentity = this._adObjectFactory.GetDirectoryObjectFromIdentity(obj, cmdletSessionInfo1.DefaultPartitionPath); distinguishedName = directoryObjectFromIdentity.DistinguishedName; } catch (ADIdentityNotFoundException aDIdentityNotFoundException2) { this._adObjectFactory.SetCmdletSessionInfo(cmdletSessionInfo); try { directoryObjectFromIdentity = this._adObjectFactory.GetDirectoryObjectFromIdentity(obj, cmdletSessionInfo.DefaultPartitionPath); Guid?objectGuid = directoryObjectFromIdentity.ObjectGuid; distinguishedName = string.Concat("<GUID=", objectGuid.ToString(), ">"); } catch (ADIdentityNotFoundException aDIdentityNotFoundException1) { object[] str = new object[1]; str[0] = obj.ToString(); throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ObjectToReplicateNotFoundOnSource, str)); } } aDCmdletCache.Clear(); } else { distinguishedName = obj.DistinguishedName; } } ADObject aDObject = new ADObject(); aDObject.DistinguishedName = ""; string str1 = string.Concat(dSServiceName, ":", distinguishedName); if (this._cmdletParameters.GetSwitchParameterBooleanValue("PasswordOnly")) { str1 = string.Concat(str1, ":SECRETS_ONLY"); } aDObject.Add("replicateSingleObject", str1); aDObject.TrackChanges = false; using (ADActiveObject aDActiveObject = new ADActiveObject(cmdletSessionInfo.ADSessionInfo, aDObject)) { if (base.ShouldProcessOverride(obj.IdentifyingString, "Sync")) { try { aDActiveObject.Update(); } catch (ADIdentityNotFoundException aDIdentityNotFoundException3) { object[] objArray3 = new object[2]; objArray3[0] = this.sourceServer; objArray3[1] = destination; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.SourceServerObjNotFoundOrObjToReplicateNotFound, objArray3)); } catch (ArgumentException argumentException1) { ArgumentException argumentException = argumentException1; Win32Exception win32Exception = new Win32Exception(0x200a); if (string.Compare(win32Exception.Message, 0, argumentException.Message, 0, win32Exception.Message.Length, StringComparison.OrdinalIgnoreCase) != 0 || string.Compare("replicateSingleObject", argumentException.ParamName, StringComparison.OrdinalIgnoreCase) != 0) { throw argumentException; } else { object[] objArray4 = new object[1]; objArray4[0] = destination; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.DestinationServerDoesNotSupportSynchronizingObject, objArray4)); } } if (this._cmdletParameters.GetSwitchParameterBooleanValue("PassThru")) { this._adObjectFactory.SetCmdletSessionInfo(cmdletSessionInfo); ADObject extendedObjectFromDN = this._adObjectFactory.GetExtendedObjectFromDN(distinguishedName); base.WriteObject(extendedObjectFromDN); } return(false); } else { flag = false; } } return(flag); } else { CultureInfo currentCulture = CultureInfo.CurrentCulture; string passwordOnlySwitchAllowedOnlyOnRODC = StringResources.PasswordOnlySwitchAllowedOnlyOnRODC; object[] objArray5 = new object[1]; object[] objArray6 = objArray5; int num = 0; string dNSHostName = cmdletSessionInfo.ADRootDSE.DNSHostName; int? portLDAP = cmdletSessionInfo.ADRootDSE.PortLDAP; if (!portLDAP.HasValue) { empty = string.Empty; } else { int?nullable = cmdletSessionInfo.ADRootDSE.PortLDAP; empty = string.Concat(":", nullable.ToString()); } objArray6[num] = string.Concat(dNSHostName, empty); throw new ArgumentException(string.Format(currentCulture, passwordOnlySwitchAllowedOnlyOnRODC, objArray5)); } }
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 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 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); }
private void ValidateMemberOfParameter() { ADGroup extendedObjectFromIdentity; if (!this._isMemberOfValidated) { this._validExtendedGroupPartitionPairList = new List <SetADPrincipalGroupMembership <P> .ADGroupPartitionDNPair>(); object item = this._cmdletParameters["MemberOf"]; ADPrincipal[] aDPrincipalArray = item as ADGroup[]; if (aDPrincipalArray == null) { ADGroup aDGroup = item as ADGroup; if (aDGroup != null) { ADGroup[] aDGroupArray = new ADGroup[1]; aDGroupArray[0] = aDGroup; aDPrincipalArray = aDGroupArray; } } if (aDPrincipalArray != null) { new Hashtable(); ADGroupFactory <ADGroup> aDGroupFactory = new ADGroupFactory <ADGroup>(); CmdletSessionInfo cmdletSessionInfo = base.GetCmdletSessionInfo(); aDGroupFactory.SetCmdletSessionInfo(cmdletSessionInfo); ADPrincipal[] aDPrincipalArray1 = aDPrincipalArray; for (int i = 0; i < (int)aDPrincipalArray1.Length; i++) { ADGroup aDGroup1 = (ADGroup)aDPrincipalArray1[i]; try { if (!aDGroup1.IsSearchResult) { extendedObjectFromIdentity = aDGroupFactory.GetExtendedObjectFromIdentity(aDGroup1, cmdletSessionInfo.DefaultPartitionPath); this._validExtendedGroupPartitionPairList.Add(new SetADPrincipalGroupMembership <P> .ADGroupPartitionDNPair(extendedObjectFromIdentity)); } else { extendedObjectFromIdentity = aDGroup1; using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(extendedObjectFromIdentity.SessionInfo)) { ADRootDSE rootDSE = aDObjectSearcher.GetRootDSE(); string str = ADForestPartitionInfo.ExtractAndValidatePartitionInfo(rootDSE, extendedObjectFromIdentity.DistinguishedName); this._validExtendedGroupPartitionPairList.Add(new SetADPrincipalGroupMembership <P> .ADGroupPartitionDNPair(extendedObjectFromIdentity, str)); } } } catch (ADIdentityNotFoundException aDIdentityNotFoundException1) { ADIdentityNotFoundException aDIdentityNotFoundException = aDIdentityNotFoundException1; DebugLogger.LogError("SetADPrincipalGroupMembership", aDIdentityNotFoundException.ToString()); base.ThrowTerminatingError(new ErrorRecord(aDIdentityNotFoundException, "SetADPrincipalGroupMembership:ValidateMemberOfParameter", ErrorCategory.ObjectNotFound, aDGroup1)); } } } this._isMemberOfValidated = true; return; } else { return; } }
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); } }
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 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])); } }
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 bool ADGetADTrustCmdletProcessInputObjectCSRoutine() { if (this._cmdletParameters.Contains("InputObject")) { object item = this._cmdletParameters["InputObject"]; if (item as PSObject != null) { item = ((PSObject)item).BaseObject; } ADEntity aDEntity = item as ADEntity; string str = item as string; if (aDEntity == null) { if (str == null) { object[] type = new object[2]; type[0] = item.GetType(); type[1] = "InputObject"; base.WriteErrorBuffered(this.ConstructErrorRecord(new ParameterBindingException(string.Format(CultureInfo.CurrentCulture, StringResources.UnsupportedParameterType, type)))); return(false); } else { this._cmdletParameters["Identity"] = new ADTrust(str); } } else { if (aDEntity.IsSearchResult) { if (aDEntity as ADForest != null || aDEntity as ADDomain != null || aDEntity as ADClaimTransformPolicy != null) { CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo(); ADTrustFactory <ADTrust> aDTrustFactory = new ADTrustFactory <ADTrust>(); IADOPathNode structuralObjectFilter = aDTrustFactory.StructuralObjectFilter; if (aDEntity as ADForest != null || aDEntity as ADDomain != null) { if (!this._cmdletParameters.Contains("Server")) { ADSessionInfo aDSessionInfo = new ADSessionInfo(aDEntity["Name"].Value as string); if (aDEntity as ADForest != null) { aDSessionInfo.SetDefaultPort(LdapConstants.LDAP_GC_PORT); } if (cmdletSessionInfo.ADSessionInfo != null) { aDSessionInfo.Credential = cmdletSessionInfo.ADSessionInfo.Credential; } cmdletSessionInfo.ADRootDSE = null; cmdletSessionInfo.ADSessionInfo = aDSessionInfo; using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(aDSessionInfo)) { cmdletSessionInfo.ADRootDSE = aDObjectSearcher.GetRootDSE(); cmdletSessionInfo.ADRootDSE.SessionInfo = aDSessionInfo; } this.SetPipelinedSessionInfo(aDSessionInfo); } else { base.WriteErrorBuffered(this.ConstructErrorRecord(new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ServerParameterNotSupported, new object[0])))); return(false); } } else { IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "msDS-EgressClaimsTransformationPolicy", aDEntity["DistinguishedName"].Value as string); IADOPathNode aDOPathNode1 = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "msDS-IngressClaimsTransformationPolicy", aDEntity["DistinguishedName"].Value as string); IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2]; aDOPathNodeArray[0] = aDOPathNode; aDOPathNodeArray[1] = aDOPathNode1; structuralObjectFilter = ADOPathUtil.CreateOrClause(aDOPathNodeArray); } base.BuildPropertySet(); this._factory.SetCmdletSessionInfo(cmdletSessionInfo); base.ValidateParameters(); base.OutputSearchResults(structuralObjectFilter); return(false); } else { if (aDEntity as ADTrust == null) { if (string.Compare(this._factory.StructuralObjectClass, aDEntity["ObjectClass"].Value as string, StringComparison.OrdinalIgnoreCase) == 0) { this._cmdletParameters["Identity"] = new ADTrust((string)aDEntity["DistinguishedName"].Value); } else { object[] objArray = new object[2]; objArray[0] = aDEntity.GetType(); objArray[1] = "InputObject"; base.WriteErrorBuffered(this.ConstructErrorRecord(new ParameterBindingException(string.Format(CultureInfo.CurrentCulture, StringResources.UnsupportedParameterType, objArray)))); return(false); } } else { this._cmdletParameters["Identity"] = (ADTrust)aDEntity; } } } else { base.WriteErrorBuffered(this.ConstructErrorRecord(new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.OnlySearchResultsSupported, new object[0])))); return(false); } } } return(true); }
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); }