Esempio n. 1
0
        public DOMAIN_PASSWORD_INFORMATION GetDomainPasswordInformation(SecurityIdentifier domainSid)
        {
            if (domainSid == null)
            {
                throw new ArgumentNullException(nameof(domainSid));
            }

            var sid = new byte[domainSid.BinaryLength];

            domainSid.GetBinaryForm(sid, 0);

            Check(Samlib.SamOpenDomain(_handle, DOMAIN_ACCESS_MASK.DOMAIN_READ_PASSWORD_PARAMETERS, sid, out IntPtr domain));
            var info = IntPtr.Zero;

            try
            {
                Check(Samlib.SamQueryInformationDomain(domain, DOMAIN_INFORMATION_CLASS.DomainPasswordInformation, out info));
                return((DOMAIN_PASSWORD_INFORMATION)Marshal.PtrToStructure(info, typeof(DOMAIN_PASSWORD_INFORMATION)));
            }
            finally
            {
                Samlib.SamFreeMemory(info);
                Samlib.SamCloseHandle(domain);
            }
        }
Esempio n. 2
0
        public void SetDomainPasswordInformation(SecurityIdentifier domainSid, DOMAIN_PASSWORD_INFORMATION passwordInformation)
        {
            if (domainSid == null)
            {
                throw new ArgumentNullException(nameof(domainSid));
            }

            var sid = new byte[domainSid.BinaryLength];

            domainSid.GetBinaryForm(sid, 0);

            Check(Samlib.SamOpenDomain(_handle, DOMAIN_ACCESS_MASK.DOMAIN_WRITE_PASSWORD_PARAMS, sid, out IntPtr domain));
            IntPtr info = Marshal.AllocHGlobal(Marshal.SizeOf(passwordInformation));

            Marshal.StructureToPtr(passwordInformation, info, false);
            try
            {
                Check(Samlib.SamSetInformationDomain(domain, DOMAIN_INFORMATION_CLASS.DomainPasswordInformation, info));
            }
            finally
            {
                Marshal.FreeHGlobal(info);
                Samlib.SamCloseHandle(domain);
            }
        }