/// <summary> /// Convert an SDDL string to a binary security descriptor /// </summary> /// <param name="sddl">The SDDL string</param> /// <param name="throw_on_error">True to throw on error.</param> /// <returns>The binary security descriptor</returns> /// <exception cref="NtException">Thrown if cannot convert from a SDDL string.</exception> public static NtResult <byte[]> SddlToSecurityDescriptor(string sddl, bool throw_on_error) { if (!Win32NativeMethods.ConvertStringSecurityDescriptorToSecurityDescriptor(sddl, 1, out SafeLocalAllocHandle handle, out int return_length)) { return(NtObjectUtils.MapDosErrorToStatus().CreateResultFromError <byte[]>(throw_on_error)); } using (handle) { byte[] ret = new byte[return_length]; Marshal.Copy(handle.DangerousGetHandle(), ret, 0, return_length); return(ret.CreateResult()); } }
/// <summary> /// Convert an SDDL string to a binary security descriptor /// </summary> /// <param name="sddl">The SDDL string</param> /// <returns>The binary security descriptor</returns> /// <exception cref="NtException">Thrown if cannot convert from a SDDL string.</exception> public static byte[] SddlToSecurityDescriptor(string sddl) { if (!Win32NativeMethods.ConvertStringSecurityDescriptorToSecurityDescriptor(sddl, 1, out SafeLocalAllocHandle handle, out int return_length)) { throw new NtException(NtObjectUtils.MapDosErrorToStatus()); } using (handle) { byte[] ret = new byte[return_length]; Marshal.Copy(handle.DangerousGetHandle(), ret, 0, return_length); return(ret); } }