/// <summary>Returns an array of byte values that represents the information contained in this <see cref="GenericSecurityDescriptor"/> object.</summary>
        /// <param name="sd">The <see cref="GenericSecurityDescriptor"/> object.</param>
        /// <returns>The byte array into which the contents of the <see cref="GenericSecurityDescriptor"/> is marshaled.</returns>
        public static byte[] GetBinaryForm(this GenericSecurityDescriptor sd)
        {
            if (sd == null)
            {
                throw new ArgumentNullException(nameof(sd));
            }
            var bin = new byte[sd.BinaryLength];

            sd.GetBinaryForm(bin, 0);
            return(bin);
        }
Exemple #2
0
 public ObjectAttributes(string object_name, AttributeFlags attributes, SafeKernelObjectHandle root, SecurityQualityOfService sqos, GenericSecurityDescriptor security_descriptor)
 {
     Length = Marshal.SizeOf(this);
     if (object_name != null)
     {
         ObjectName = AllocStruct(new UnicodeString(object_name));
     }
     Attributes = attributes;
     if (sqos != null)
     {
         SecurityQualityOfService = AllocStruct(sqos);
     }
     if (root != null)
     {
         RootDirectory = root.DangerousGetHandle();
     }
     if (security_descriptor != null)
     {
         byte[] sd_binary = new byte[security_descriptor.BinaryLength];
         security_descriptor.GetBinaryForm(sd_binary, 0);
         SecurityDescriptor = Marshal.AllocHGlobal(sd_binary.Length);
         Marshal.Copy(sd_binary, 0, SecurityDescriptor, sd_binary.Length);
     }
 }
Exemple #3
0
 private static byte[] SdToArray(GenericSecurityDescriptor sd)
 {
     byte[] ret = new byte[sd.BinaryLength];
     sd.GetBinaryForm(ret, 0);
     return(ret);
 }
Exemple #4
0
 internal static byte[] ToBytes(this GenericSecurityDescriptor s)
 {
     byte[] b = new byte[s.BinaryLength];
     s.GetBinaryForm(b, 0);
     return(b);
 }