示例#1
0
        private bool SetADComputerServiceAccountBeginCSRoutine()
        {
            object item = this._cmdletParameters["ServiceAccount"];

            ADServiceAccount[] aDServiceAccountArray = item as ADServiceAccount[];
            if (aDServiceAccountArray == null)
            {
                ADServiceAccount aDServiceAccount = item as ADServiceAccount;
                if (aDServiceAccount != null)
                {
                    ADServiceAccount[] aDServiceAccountArray1 = new ADServiceAccount[1];
                    aDServiceAccountArray1[0] = aDServiceAccount;
                    aDServiceAccountArray     = aDServiceAccountArray1;
                }
            }
            if (aDServiceAccountArray == null)
            {
                ArgumentException argumentException = new ArgumentException(StringResources.ObjectNotFound);
                base.ThrowTerminatingError(new ErrorRecord(argumentException, "SetADComputerServiceAccount:BeginProcessingOverride", ErrorCategory.ObjectNotFound, this));
            }
            else
            {
                List <string>           strs = new List <string>();
                List <ADServiceAccount> aDServiceAccounts = new List <ADServiceAccount>();
                Hashtable hashtables = new Hashtable();
                ADServiceAccountFactory <ADServiceAccount> aDServiceAccountFactory = new ADServiceAccountFactory <ADServiceAccount>();
                ADServiceAccount[] aDServiceAccountArray2 = aDServiceAccountArray;
                for (int i = 0; i < (int)aDServiceAccountArray2.Length; i++)
                {
                    ADServiceAccount aDServiceAccount1 = aDServiceAccountArray2[i];
                    base.SetPipelinedSessionInfo(aDServiceAccount1.SessionInfo);
                    CmdletSessionInfo cmdletSessionInfo = base.GetCmdletSessionInfo();
                    aDServiceAccountFactory.SetCmdletSessionInfo(cmdletSessionInfo);
                    try
                    {
                        ADObject directoryObjectFromIdentity = aDServiceAccountFactory.GetDirectoryObjectFromIdentity(aDServiceAccount1, cmdletSessionInfo.DefaultPartitionPath);
                        strs.Add(directoryObjectFromIdentity.DistinguishedName);
                        this._resolvedServiceAccountList.Add(directoryObjectFromIdentity);
                    }
                    catch (ADIdentityNotFoundException aDIdentityNotFoundException1)
                    {
                        ADIdentityNotFoundException aDIdentityNotFoundException = aDIdentityNotFoundException1;
                        DebugLogger.LogError("SetADComputerServiceAccount", aDIdentityNotFoundException.ToString());
                        aDServiceAccounts.Add(aDServiceAccount1);
                    }
                }
                if (aDServiceAccounts.Count > 0)
                {
                    ArgumentException argumentException1 = new ArgumentException(StringResources.ObjectNotFound);
                    base.ThrowTerminatingError(new ErrorRecord(argumentException1, "SetADComputerServiceAccount:BeginProcessingOverride", ErrorCategory.ObjectNotFound, aDServiceAccounts.ToArray()));
                }
                hashtables.Add(this._modifyOpString, strs.ToArray());
                this._cmdletParameters.RemoveParameter("ServiceAccount");
                this._cmdletParameters["ServiceAccount"] = new ADMultivalueHashtableParameter <string>(hashtables);
            }
            return(true);
        }
示例#2
0
        private void ValidateSubjectsAndAddToList()
        {
            object item = this._cmdletParameters["Subjects"];

            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;
                }
            }
            ADPrincipalFactory <ADPrincipal> aDPrincipalFactory = new ADPrincipalFactory <ADPrincipal>();

            if (aDPrincipalArray[0].IsSearchResult)
            {
                this.SetPipelinedSessionInfo(aDPrincipalArray[0].SessionInfo);
            }
            CmdletSessionInfo cmdletSessionInfo = base.GetCmdletSessionInfo();

            aDPrincipalFactory.SetCmdletSessionInfo(cmdletSessionInfo);
            if (aDPrincipalArray != null)
            {
                new Hashtable();
                ADPrincipal[] aDPrincipalArray2 = aDPrincipalArray;
                for (int i = 0; i < (int)aDPrincipalArray2.Length; i++)
                {
                    ADPrincipal aDPrincipal1 = aDPrincipalArray2[i];
                    try
                    {
                        ADObject directoryObjectFromIdentity = aDPrincipalFactory.GetDirectoryObjectFromIdentity(aDPrincipal1, cmdletSessionInfo.DefaultPartitionPath);
                        this._appliesToDNList.Add(directoryObjectFromIdentity.DistinguishedName);
                    }
                    catch (ADIdentityNotFoundException aDIdentityNotFoundException1)
                    {
                        ADIdentityNotFoundException aDIdentityNotFoundException = aDIdentityNotFoundException1;
                        DebugLogger.LogError("SetADFineGrainedPasswordPolicySubject", aDIdentityNotFoundException.ToString());
                        base.ThrowTerminatingError(ADUtilities.GetErrorRecord(aDIdentityNotFoundException, "SetADFineGrainedPasswordPolicySubject:ValidateSubjectsAndAddToList", aDPrincipal1));
                    }
                }
            }
        }
示例#3
0
        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;
            }
        }
        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 SetADDCPrpBeginCSRoutine()
        {
            SecurityIdentifier value;

            ADPrincipal[] item = null;
            if (base.ParameterSetName != "AllowedPRP")
            {
                if (base.ParameterSetName == "DeniedPRP")
                {
                    item = this._cmdletParameters["DeniedList"] as ADPrincipal[];
                }
            }
            else
            {
                item = this._cmdletParameters["AllowedList"] as ADPrincipal[];
            }
            if (item != null)
            {
                List <string> strs = new List <string>();
                ADPrincipalFactory <ADPrincipal> aDPrincipalFactory = new ADPrincipalFactory <ADPrincipal>();
                ADPrincipal[] aDPrincipalArray = item;
                for (int i = 0; i < (int)aDPrincipalArray.Length; i++)
                {
                    ADPrincipal aDPrincipal = aDPrincipalArray[i];
                    base.SetPipelinedSessionInfo(aDPrincipal.SessionInfo);
                    CmdletSessionInfo cmdletSessionInfo = base.GetCmdletSessionInfo();
                    aDPrincipalFactory.SetCmdletSessionInfo(cmdletSessionInfo);
                    try
                    {
                        if (!aDPrincipal.IsSearchResult)
                        {
                            ADObject directoryObjectFromIdentity = aDPrincipalFactory.GetDirectoryObjectFromIdentity(aDPrincipal, cmdletSessionInfo.DefaultPartitionPath);
                            value = (SecurityIdentifier)directoryObjectFromIdentity["objectSid"].Value;
                        }
                        else
                        {
                            value = aDPrincipal.SID;
                        }
                        if (value != null)
                        {
                            string stringizedSid = Utils.ConvertSIDToStringizedSid(value);
                            strs.Add(stringizedSid);
                        }
                        else
                        {
                            object[] distinguishedName = new object[2];
                            distinguishedName[0] = "objectSid";
                            distinguishedName[1] = aDPrincipal.DistinguishedName;
                            throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.AttributeNotFoundOnObject, distinguishedName));
                        }
                    }
                    catch (ADIdentityNotFoundException aDIdentityNotFoundException1)
                    {
                        ADIdentityNotFoundException aDIdentityNotFoundException = aDIdentityNotFoundException1;
                        DebugLogger.LogError("SetADDCPasswordReplicationPolicy", aDIdentityNotFoundException.ToString());
                        base.ThrowTerminatingError(new ErrorRecord(aDIdentityNotFoundException, "SetADDCPasswordReplicationPolicy:BeginProcessing", ErrorCategory.ReadError, aDPrincipal));
                    }
                    catch (ArgumentException argumentException1)
                    {
                        ArgumentException argumentException = argumentException1;
                        DebugLogger.LogError("SetADDCPasswordReplicationPolicy", argumentException.ToString());
                        base.ThrowTerminatingError(new ErrorRecord(argumentException, "SetADDCPasswordReplicationPolicy:BeginProcessing", ErrorCategory.ReadError, aDPrincipal));
                    }
                }
                this._principalsToAddOrRemove = new Hashtable();
                if (base.ParameterSetName != "AllowedPRP")
                {
                    if (base.ParameterSetName == "DeniedPRP")
                    {
                        this._principalsToAddOrRemove.Add("msDS-NeverRevealGroup", strs.ToArray());
                    }
                }
                else
                {
                    this._principalsToAddOrRemove.Add("msDS-RevealOnDemandGroup", strs.ToArray());
                }
            }
            return(true);
        }