Beispiel #1
0
        private static NtResult <List <Sid> > GetSids(SafeLsaHandle policy, string name, bool throw_on_error)
        {
            if (name is null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            NtStatus status = SecurityNativeMethods.LsaEnumerateAccountsWithUserRight(policy, new UnicodeString(name),
                                                                                      out SafeLsaMemoryBuffer buffer, out int count);

            if (status == NtStatus.STATUS_NO_MORE_ENTRIES)
            {
                return(new List <Sid>().CreateResult());
            }
            return(status.CreateResult(throw_on_error, () => ParseSids(buffer, count)));
        }
        /// <summary>
        /// Enumerate accounts with a user right.
        /// </summary>
        /// <param name="user_right">The name of the user right.</param>
        /// <param name="throw_on_error">True to throw on error.</param>
        /// <returns>The list of SIDs with the user right.</returns>
        public NtResult <IReadOnlyList <Sid> > EnumerateAccountsWithUserRight(string user_right, bool throw_on_error)
        {
            if (user_right is null)
            {
                throw new ArgumentNullException(nameof(user_right));
            }

            NtStatus status = SecurityNativeMethods.LsaEnumerateAccountsWithUserRight(Handle,
                                                                                      new UnicodeString(user_right), out SafeLsaMemoryBuffer buffer, out int count);

            if (status == NtStatus.STATUS_NO_MORE_ENTRIES)
            {
                return(new List <Sid>().AsReadOnly().CreateResult <IReadOnlyList <Sid> >());
            }
            return(status.CreateResult(throw_on_error, () => ParseSids(buffer, count)));
        }