Ejemplo n.º 1
0
        private void ProcessName()
        {
            foreach (string right in Name)
            {
                WriteVerbose($"Getting current membership for the privilege/right '{right}'");
                IdentityReference[] actualMembers;
                try
                {
                    actualMembers = Lsa.EnumerateAccountsWithUserRight(_lsa, right).ToArray();
                }
                catch (ArgumentException e)
                {
                    WriteError(new ErrorRecord(e, "InvalidPrivilegeRightName", ErrorCategory.InvalidArgument, right));
                    continue;
                }

                if (actualMembers.Length > 0)
                {
                    WriteVerbose($"Privilege/right '{right}' contains members, removing");
                    foreach (IdentityReference member in actualMembers)
                    {
                        if (ShouldProcess(member.Value, $"Remove from the rights {right}"))
                        {
                            Lsa.RemoveAccountRights(_lsa, member, new string[] { right });
                        }
                    }
                }
                else
                {
                    WriteVerbose($"Privilege/right '{right}' has no members, no action required");
                }
            }
        }
Ejemplo n.º 2
0
        protected override void ProcessRecord()
        {
            foreach (string right in Name)
            {
                List <SecurityIdentifier> actualMembers;
                try
                {
                    actualMembers = Lsa.EnumerateAccountsWithUserRight(_lsa, right);
                }
                catch (ArgumentException e)
                {
                    WriteError(new ErrorRecord(e, "InvalidPrivilegeRightName", ErrorCategory.InvalidArgument, right));
                    continue;
                }

                SecurityIdentifier[] toChange = CalculateChanges(actualMembers);
                foreach (SecurityIdentifier id in toChange)
                {
                    if (!_setInfo.ContainsKey(id))
                    {
                        _setInfo[id] = new List <string>();
                    }

                    _setInfo[id].Add(right);
                }
            }
        }
Ejemplo n.º 3
0
        protected override void ProcessRecord()
        {
            // Will be invalid if it failed to be opened in begin.
            if (_lsa.IsInvalid)
            {
                return;
            }

            if (Account == null && Name.Length == 0)
            {
                Name = PrivilegeHelper.ALL_PRIVILEGES.Concat(Lsa.ALL_RIGHTS.Keys).ToArray();
            }
            else if (Account != null)
            {
                string[] accountRights = Lsa.EnumerateAccountRights(_lsa, Account).ToArray();
                if (Name.Length > 0)
                {
                    accountRights = accountRights.Intersect(Name).ToArray();
                }

                Name = accountRights;
            }

            WriteVerbose("Getting details for the following rights: " + String.Join(", ", Name));
            foreach (string right in Name)
            {
                string description = "";
                if (Lsa.ALL_RIGHTS.ContainsKey(right))
                {
                    description = Lsa.ALL_RIGHTS[right];
                }
                else if (PrivilegeHelper.CheckPrivilegeName(right))
                {
                    description = PrivilegeHelper.GetPrivilegeDisplayName(right);
                }
                else
                {
                    WriteWarning($"Unknown right {right}, cannot get description");
                }

                WriteVerbose($"Enumerating accounts with the privilege/rights '{right}'");
                IdentityReference[] rightAccounts;
                try
                {
                    rightAccounts = Lsa.EnumerateAccountsWithUserRight(_lsa, right)
                                    .Select(i => TranslateIdentity(i, IdentityType))
                                    .ToArray();
                }
                catch (ArgumentException e)
                {
                    WriteError(new ErrorRecord(e, "InvalidPrivilegeRightName", ErrorCategory.InvalidArgument, right));
                    continue;
                }

                WriteObject(new Right()
                {
                    Name         = right,
                    ComputerName = ComputerName,
                    Description  = description,
                    Accounts     = rightAccounts,
                });
            }
        }