Ejemplo n.º 1
0
        public string[] LookupIds(int[] relativeIds, out SidNameUse[] uses)
        {
            IntPtr names;
            IntPtr use;

            Win32.SamLookupIdsInDomain(
                this,
                relativeIds.Length,
                relativeIds,
                out names,
                out use
                ).ThrowIf();

            using (SamMemoryAlloc namesAlloc = new SamMemoryAlloc(names))
                using (SamMemoryAlloc useAlloc = new SamMemoryAlloc(use))
                {
                    string[]     nameArray = new string[relativeIds.Length];
                    SidNameUse[] useArray  = new SidNameUse[relativeIds.Length];

                    for (int i = 0; i < relativeIds.Length; i++)
                    {
                        nameArray[i] = namesAlloc.ReadStruct <UnicodeString>(0, UnicodeString.SizeOf, i).Text;
                        useArray[i]  = (SidNameUse)useAlloc.ReadInt32(0, i);
                    }

                    uses = useArray;

                    return(nameArray);
                }
        }
Ejemplo n.º 2
0
        public string[] LookupIds(int[] relativeIds, out SidNameUse[] uses)
        {
            NtStatus status;
            IntPtr   names;
            IntPtr   use;

            if ((status = Win32.SamLookupIdsInDomain(
                     this,
                     relativeIds.Length,
                     relativeIds,
                     out names,
                     out use
                     )) >= NtStatus.Error)
            {
                Win32.Throw(status);
            }

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

                    for (int i = 0; i < relativeIds.Length; i++)
                    {
                        nameArray[i] = namesAlloc.ReadStruct <UnicodeString>(i).Read();
                        useArray[i]  = (SidNameUse)useAlloc.ReadInt32(0, i);
                    }

                    uses = useArray;

                    return(nameArray);
                }
        }
Ejemplo n.º 3
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));
                }
        }