Example #1
0
        protected override void ProcessRecord()
        {
            this.UserName = PswaHelper.TranslateLocalAccountName(this.UserName);
            PswaAuthorizationRule[] rule = this.Rule;
            if (rule == null)
            {
                SortedList <int, PswaAuthorizationRule> nums = PswaAuthorizationRuleCommandHelper.LoadFromFile(this, "Test");
                if (nums != null)
                {
                    rule = nums.Values.ToArray <PswaAuthorizationRule>();
                }
                else
                {
                    return;
                }
            }
            MatchingWildcard matchingWildcard = MatchingWildcard.None;

            if (this.UserName == "*")
            {
                matchingWildcard = matchingWildcard | MatchingWildcard.User;
            }
            if (this.ConfigurationName == "*")
            {
                matchingWildcard = matchingWildcard | MatchingWildcard.Configuration;
            }
            try
            {
                if (base.ParameterSetName != "ComputerName")
                {
                    if (base.ParameterSetName == "ConnectionUri")
                    {
                        PswaAuthorizationRuleManager.Instance.TestRule(rule, this.UserName, this.ConnectionUri, this.ConfigurationName, true, matchingWildcard);
                    }
                }
                else
                {
                    if (this.ComputerName == "*")
                    {
                        matchingWildcard = matchingWildcard | MatchingWildcard.Destination;
                    }
                    PswaAuthorizationRuleManager.Instance.TestRule(rule, this.UserName, this.ComputerName, this.ConfigurationName, true, matchingWildcard);
                }
                if (this.matches == 0 && this.warnings > 0)
                {
                    throw new Exception(Resources.TestRule_NoMatchWithWarnings);
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                base.WriteError(new ErrorRecord(exception, "TestRuleError", ErrorCategory.InvalidOperation, null));
            }
        }
Example #2
0
        protected override void ProcessRecord()
        {
            SortedList <int, PswaAuthorizationRule> nums = PswaAuthorizationRuleCommandHelper.LoadFromFile(this, "Get");

            if (nums != null)
            {
                PswaAuthorizationRule[] rule = null;
                try
                {
                    string parameterSetName = base.ParameterSetName;
                    string str = parameterSetName;
                    if (parameterSetName != null)
                    {
                        if (str == "ID")
                        {
                            rule = PswaAuthorizationRuleManager.Instance.GetRule(nums, this.Id);
                        }
                        else
                        {
                            if (str == "Name")
                            {
                                rule = PswaAuthorizationRuleManager.Instance.GetRule(nums, this.RuleName);
                            }
                        }
                    }
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    base.WriteError(new ErrorRecord(exception, "GetRuleError", ErrorCategory.InvalidOperation, null));
                }
                if (rule != null)
                {
                    base.WriteObject(rule, true);
                }
                return;
            }
            else
            {
                return;
            }
        }
Example #3
0
        internal static SortedList <int, PswaAuthorizationRule> LoadFromFile(Cmdlet cmdlet, string operationName)
        {
            SortedList <int, PswaAuthorizationRule> nums;
            bool flag;
            SortedList <int, PswaAuthorizationRule> nums1;

            try
            {
                ArrayList arrayLists = new ArrayList();
                SortedList <int, PswaAuthorizationRule> nums2 = PswaAuthorizationRuleManager.Instance.LoadFromFile(arrayLists);
                if (!PswaAuthorizationRuleCommandHelper.WriteLoadError(cmdlet, arrayLists, string.Concat(operationName, "RuleError")))
                {
                    flag = false;
                }
                else
                {
                    flag = nums2 != null;
                }
                bool flag1 = flag;
                if (flag1)
                {
                    nums1 = nums2;
                }
                else
                {
                    nums1 = null;
                }
                nums = nums1;
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                cmdlet.WriteError(new ErrorRecord(exception, string.Concat(operationName, "RuleError"), ErrorCategory.InvalidOperation, null));
                nums = null;
            }
            return(nums);
        }
        protected override void ProcessRecord()
        {
            PswaAuthorizationRule[] rule;
            SortedList <int, PswaAuthorizationRule> nums = PswaAuthorizationRuleCommandHelper.LoadFromFile(this, "Remove");

            if (nums != null)
            {
                if (string.Compare(base.ParameterSetName, "ID", StringComparison.OrdinalIgnoreCase) != 0)
                {
                    rule = this.Rule;
                }
                else
                {
                    rule = PswaAuthorizationRuleManager.Instance.GetRule(nums, this.Id);
                }
                ArrayList arrayLists = new ArrayList();
                PswaAuthorizationRule[] pswaAuthorizationRuleArray = rule;
                for (int i = 0; i < (int)pswaAuthorizationRuleArray.Length; i++)
                {
                    PswaAuthorizationRule pswaAuthorizationRule = pswaAuthorizationRuleArray[i];
                    try
                    {
                        if (!this.Force)
                        {
                            object[] ruleName = new object[2];
                            ruleName[0] = pswaAuthorizationRule.RuleName;
                            ruleName[1] = pswaAuthorizationRule.Id;
                            if (!base.ShouldProcess(string.Format(CultureInfo.CurrentCulture, Resources.AuthorizationRuleIdName_DisplayFormat, ruleName)))
                            {
                                continue;
                            }
                        }
                        PswaAuthorizationRule pswaAuthorizationRule1 = PswaAuthorizationRuleManager.Instance.RemoveRule(nums, pswaAuthorizationRule.Id);
                        if (pswaAuthorizationRule1 != null)
                        {
                            arrayLists.Add(pswaAuthorizationRule1);
                            if (arrayLists.Count >= this.batchAmount)
                            {
                                this.SaveCurrentBatch(nums, arrayLists);
                            }
                        }
                        else
                        {
                            this.ReportRuleNotFoundById(pswaAuthorizationRule.Id);
                        }
                    }
                    catch (Exception exception1)
                    {
                        Exception exception = exception1;
                        this.SaveCurrentBatch(nums, arrayLists);
                        base.WriteError(new ErrorRecord(exception, "RemoveRuleError", ErrorCategory.InvalidOperation, null));
                    }
                }
                if (arrayLists.Count > 0)
                {
                    this.SaveCurrentBatch(nums, arrayLists);
                }
                return;
            }
            else
            {
                return;
            }
        }
        protected override void ProcessRecord()
        {
            string       str;
            PswaUserType pswaUserType;
            bool         flag;
            bool         flag1;
            bool         flag2;

            string[]            userName            = new string[0];
            PswaUserType        pswaUserType1       = PswaUserType.User;
            string              empty               = string.Empty;
            PswaDestinationType pswaDestinationType = PswaDestinationType.Computer;

            if (base.ParameterSetName == "UserNameComputerName" || base.ParameterSetName == "UserNameComputerGroupName")
            {
                userName      = this.UserName;
                pswaUserType1 = PswaUserType.User;
                for (int i = 0; i < (int)userName.Length; i++)
                {
                    userName[i] = PswaHelper.TranslateLocalAccountName(userName[i]);
                }
            }
            else
            {
                if (base.ParameterSetName == "UserGroupNameComputerName" || base.ParameterSetName == "UserGroupNameComputerGroupName")
                {
                    userName      = this.UserGroupName;
                    pswaUserType1 = PswaUserType.UserGroup;
                    for (int j = 0; j < (int)userName.Length; j++)
                    {
                        userName[j] = PswaHelper.TranslateLocalAccountName(userName[j]);
                    }
                }
            }
            if (base.ParameterSetName == "UserNameComputerName" || base.ParameterSetName == "UserGroupNameComputerName")
            {
                empty = this.ComputerName;
                pswaDestinationType = PswaDestinationType.Computer;
            }
            else
            {
                if (base.ParameterSetName == "UserNameComputerGroupName" || base.ParameterSetName == "UserGroupNameComputerGroupName")
                {
                    empty = PswaHelper.TranslateLocalAccountName(this.ComputerGroupName);
                    pswaDestinationType = PswaDestinationType.ComputerGroup;
                }
            }
            if (empty == "*")
            {
                pswaDestinationType = PswaDestinationType.All;
            }
            SortedList <int, PswaAuthorizationRule> nums = PswaAuthorizationRuleCommandHelper.LoadFromFile(this, "Add");

            if (nums != null)
            {
                str = null;
                try
                {
                    if (pswaDestinationType == PswaDestinationType.Computer)
                    {
                        string str1 = PswaAuthorizationRuleManager.Instance.TryParseDestinationIpAddress(empty);
                        if (str1 == null)
                        {
                            if (!PswaAuthorizationRuleManager.Instance.IsCurrentComputerDomainJoined())
                            {
                                str = empty;
                            }
                            else
                            {
                                string str2 = null;
                                PswaAuthorizationRuleManager.Instance.GetComputerFqdnAndSid(empty, out str2, out str);
                                if (str != null)
                                {
                                    if (string.Compare(str2, empty, StringComparison.OrdinalIgnoreCase) != 0)
                                    {
                                        if (this.Force)
                                        {
                                            flag = true;
                                        }
                                        else
                                        {
                                            object[] objArray = new object[1];
                                            objArray[0] = str2;
                                            flag        = base.ShouldContinue(string.Format(CultureInfo.CurrentCulture, Resources.AuthorizationRule_UseFqdnQuery, objArray), "");
                                        }
                                        bool flag3 = flag;
                                        if (flag3)
                                        {
                                            empty = str2;
                                        }
                                        else
                                        {
                                            return;
                                        }
                                    }
                                }
                                else
                                {
                                    if (this.Force)
                                    {
                                        flag1 = true;
                                    }
                                    else
                                    {
                                        object[] objArray1 = new object[1];
                                        objArray1[0] = empty;
                                        flag1        = base.ShouldContinue(string.Format(CultureInfo.CurrentCulture, Resources.AuthorizationRule_ForceComputerNameQuery, objArray1), "");
                                    }
                                    bool flag4 = flag1;
                                    if (flag4)
                                    {
                                        str = empty;
                                    }
                                    else
                                    {
                                        return;
                                    }
                                }
                            }
                        }
                        else
                        {
                            empty = str1;
                            if (this.Force)
                            {
                                flag2 = true;
                            }
                            else
                            {
                                object[] objArray2 = new object[1];
                                objArray2[0] = empty;
                                flag2        = base.ShouldContinue(string.Format(CultureInfo.CurrentCulture, Resources.AuthorizationRule_UseIpAddressQuery, objArray2), "");
                            }
                            bool flag5 = flag2;
                            if (flag5)
                            {
                                str = empty;
                            }
                            else
                            {
                                return;
                            }
                        }
                    }
                    goto Label0;
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    base.WriteError(new ErrorRecord(exception, "AddRuleError", ErrorCategory.InvalidOperation, null));
                }
                return;
            }
            else
            {
                return;
            }
Label0:
            ArrayList arrayLists = new ArrayList();

            string[] strArrays = userName;
            int      num       = 0;

            while (num < (int)strArrays.Length)
            {
                string str3 = strArrays[num];
                try
                {
                    PswaAuthorizationRuleManager            instance = PswaAuthorizationRuleManager.Instance;
                    SortedList <int, PswaAuthorizationRule> nums1    = nums;
                    string ruleName = this.RuleName;
                    string str4     = str3;
                    if (str3 == "*")
                    {
                        pswaUserType = PswaUserType.All;
                    }
                    else
                    {
                        pswaUserType = pswaUserType1;
                    }
                    PswaAuthorizationRule pswaAuthorizationRule = instance.AddRule(nums1, ruleName, str4, pswaUserType, empty, pswaDestinationType, this.ConfigurationName, str);
                    arrayLists.Add(pswaAuthorizationRule);
                    if (arrayLists.Count >= this.batchAmount)
                    {
                        this.SaveCurrentBatch(nums, arrayLists);
                    }
                }
                catch (Exception exception3)
                {
                    Exception exception2 = exception3;
                    this.SaveCurrentBatch(nums, arrayLists);
                    base.WriteError(new ErrorRecord(exception2, "AddRuleError", ErrorCategory.InvalidOperation, null));
                }
                num++;
            }
            if (arrayLists.Count > 0)
            {
                this.SaveCurrentBatch(nums, arrayLists);
                return;
            }
            else
            {
                return;
            }
        }