Beispiel #1
0
        public void SetDnsDomainInformation(LsaDnsDomainInformation newDomainInfo)
        {
            // TODO: Validation
            Validator.AssertNotNull(newDomainInfo, "newDomainInfo");

            // Convert values to unmanaged types
            byte[] binarySid = newDomainInfo.Sid != null?newDomainInfo.Sid.GetBinaryForm() : null;

            var pinnedSid = GCHandle.Alloc(binarySid, GCHandleType.Pinned);

            try
            {
                var nativeInfo = new LsaDnsDomainInformationNative()
                {
                    DnsDomainName = new UnicodeString(newDomainInfo.DnsDomainName),
                    DnsForestName = new UnicodeString(newDomainInfo.DnsForestName),
                    Name          = new UnicodeString(newDomainInfo.Name),
                    DomainGuid    = newDomainInfo.Guid.HasValue ? newDomainInfo.Guid.Value : Guid.Empty,
                    Sid           = pinnedSid.AddrOfPinnedObject()
                };

                var status = NativeMethods.LsaSetInformationPolicy(this.policyHandle, nativeInfo);
                Validator.AssertSuccess(status);
            }
            finally
            {
                pinnedSid.Free();
            }
        }
Beispiel #2
0
 internal LsaDnsDomainInformation(LsaDnsDomainInformationNative nativeInfo)
 {
     this.Name          = nativeInfo.Name.Buffer;
     this.DnsDomainName = nativeInfo.DnsDomainName.Buffer;
     this.DnsForestName = nativeInfo.DnsForestName.Buffer;
     this.Guid          = nativeInfo.DomainGuid != System.Guid.Empty ? nativeInfo.DomainGuid : (Guid?)null;
     this.Sid           = nativeInfo.Sid != IntPtr.Zero ? new SecurityIdentifier(nativeInfo.Sid) : null;
 }