public int[] GetAliasMembership(Sid sid)
        {
            NtStatus status;
            IntPtr   aliases;
            int      count;

            if ((status = Win32.SamGetAliasMembership(
                     this,
                     1,
                     new IntPtr[] { sid },
                     out count,
                     out aliases
                     )) >= NtStatus.Error)
            {
                Win32.Throw(status);
            }

            if (aliases != IntPtr.Zero)
            {
                using (var aliasesAlloc = new SamMemoryAlloc(aliases))
                    return(aliasesAlloc.ReadInt32Array(0, count));
            }
            else
            {
                return(new int[0]);
            }
        }
        public int[] LookupNames(string[] names, out SidNameUse[] uses)
        {
            NtStatus status;

            UnicodeString[] nameStr;
            IntPtr          relativeIds;
            IntPtr          use;

            nameStr = new UnicodeString[names.Length];

            for (int i = 0; i < names.Length; i++)
            {
                nameStr[i] = new UnicodeString(names[i]);
            }

            try
            {
                if ((status = Win32.SamLookupNamesInDomain(
                         this,
                         names.Length,
                         nameStr,
                         out relativeIds,
                         out use
                         )) >= NtStatus.Error)
                {
                    Win32.Throw(status);
                }
            }
            finally
            {
                for (int i = 0; i < names.Length; i++)
                {
                    nameStr[i].Dispose();
                }
            }

            using (var relativeIdsAlloc = new SamMemoryAlloc(relativeIds))
                using (var useAlloc = new SamMemoryAlloc(use))
                {
                    SidNameUse[] useArray = new SidNameUse[names.Length];

                    for (int i = 0; i < names.Length; i++)
                    {
                        useArray[i] = (SidNameUse)useAlloc.ReadInt32(0, i);
                    }

                    uses = useArray;

                    return(relativeIdsAlloc.ReadInt32Array(0, names.Length));
                }
        }
Example #3
0
        public int[] GetGroups()
        {
            NtStatus status;
            IntPtr   groups;
            int      count;

            if ((status = Win32.SamGetGroupsForUser(
                     this,
                     out groups,
                     out count
                     )) >= NtStatus.Error)
            {
                Win32.Throw(status);
            }

            using (var groupsAlloc = new SamMemoryAlloc(groups))
            {
                return(groupsAlloc.ReadInt32Array(0, count));
            }
        }
        public int[] GetAliasMembership(Sid sid)
        {
            IntPtr aliases;
            int    count;

            Win32.SamGetAliasMembership(
                this,
                1,
                new IntPtr[] { sid },
                out count,
                out aliases
                ).ThrowIf();

            if (aliases != IntPtr.Zero)
            {
                using (var aliasesAlloc = new SamMemoryAlloc(aliases))
                    return(aliasesAlloc.ReadInt32Array(0, count));
            }

            return(new int[0]);
        }
Example #5
0
        public int[] GetMembers()
        {
            NtStatus status;
            IntPtr   memberIds;
            IntPtr   attributes;
            int      count;

            if ((status = Win32.SamGetMembersInGroup(
                     this,
                     out memberIds,
                     out attributes,
                     out count
                     )) >= NtStatus.Error)
            {
                Win32.Throw(status);
            }

            using (var memberIdsAlloc = new SamMemoryAlloc(memberIds))
                using (var attributesAlloc = new SamMemoryAlloc(attributes))
                {
                    return(memberIdsAlloc.ReadInt32Array(0, count));
                }
        }