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);
                }
        }
Example #2
0
        public void EnumDomains(EnumDomainsDelegate callback)
        {
            int    enumerationContext = 0;
            IntPtr buffer;
            int    count;

            while (true)
            {
                Win32.SamEnumerateDomainsInSamServer(
                    this,
                    ref enumerationContext,
                    out buffer,
                    0x100,
                    out count
                    ).ThrowIf();

                if (count == 0)
                {
                    break;
                }

                using (SamMemoryAlloc bufferAlloc = new SamMemoryAlloc(buffer))
                {
                    for (int i = 0; i < count; i++)
                    {
                        SamSidEnumeration data = bufferAlloc.ReadStruct <SamSidEnumeration>(0, SamSidEnumeration.SizeOf, i);

                        if (!callback(data.Name.Text))
                        {
                            return;
                        }
                    }
                }
            }
        }
        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);
                }
        }
        public DomainPasswordPolicy GetPasswordPolicy()
        {
            using (SamMemoryAlloc data = this.GetInformation(DomainInformationClass.DomainPasswordInformation))
            {
                DomainPasswordInformation info = data.ReadStruct <DomainPasswordInformation>();

                return(new DomainPasswordPolicy(
                           info.MinPasswordLength,
                           info.PasswordHistoryLength,
                           info.PasswordProperties,
                           new TimeSpan(-info.MaxPasswordAge),
                           new TimeSpan(-info.MinPasswordAge)
                           ));
            }
        }
        public void EnumUsers(EnumUsersDelegate callback, UserAccountFlags flags)
        {
            NtStatus status;
            int      enumerationContext = 0;
            IntPtr   buffer;
            int      count;

            while (true)
            {
                status = Win32.SamEnumerateUsersInDomain(
                    this,
                    ref enumerationContext,
                    flags,
                    out buffer,
                    0x100,
                    out count
                    );

                if (status >= NtStatus.Error)
                {
                    Win32.Throw(status);
                }
                if (count == 0)
                {
                    break;
                }

                using (var bufferAlloc = new SamMemoryAlloc(buffer))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var data = bufferAlloc.ReadStruct <SamRidEnumeration>(i);

                        if (!callback(data.Name.Read(), data.RelativeId))
                        {
                            return;
                        }
                    }
                }
            }
        }
Example #6
0
        public void EnumDomains(EnumDomainsDelegate callback)
        {
            NtStatus status;
            int      enumerationContext = 0;
            IntPtr   buffer;
            int      count;

            while (true)
            {
                status = Win32.SamEnumerateDomainsInSamServer(
                    this,
                    ref enumerationContext,
                    out buffer,
                    0x100,
                    out count
                    );

                if (status >= NtStatus.Error)
                {
                    Win32.Throw(status);
                }
                if (count == 0)
                {
                    break;
                }

                using (var bufferAlloc = new SamMemoryAlloc(buffer))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var data = bufferAlloc.ReadStruct <SamSidEnumeration>(i);

                        if (!callback(data.Name.Read()))
                        {
                            return;
                        }
                    }
                }
            }
        }
        public void EnumUsers(EnumUsersDelegate callback, UserAccountFlags flags)
        {
            int    enumerationContext = 0;
            IntPtr buffer;
            int    count;

            while (true)
            {
                Win32.SamEnumerateUsersInDomain(
                    this,
                    ref enumerationContext,
                    flags,
                    out buffer,
                    0x100,
                    out count
                    ).ThrowIf();

                if (count == 0)
                {
                    break;
                }

                using (SamMemoryAlloc bufferAlloc = new SamMemoryAlloc(buffer))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var data = bufferAlloc.ReadStruct <SamRidEnumeration>(0, SamRidEnumeration.SizeOf, i);

                        if (!callback(data.Name.Text, data.RelativeId))
                        {
                            return;
                        }
                    }
                }
            }
        }