private unsafe static Interop.SECURITY_ATTRIBUTES GetSecAttrs(FileShare share, FileSecurity fileSecurity, out GCHandle?pinningHandle) { pinningHandle = null; Interop.SECURITY_ATTRIBUTES secAttrs = null; if ((share & FileShare.Inheritable) != 0 || fileSecurity != null) { secAttrs = new Interop.SECURITY_ATTRIBUTES(); secAttrs.nLength = Marshal.SizeOf(secAttrs); if ((share & FileShare.Inheritable) != 0) { secAttrs.bInheritHandle = 1; } // For ACL's, get the security descriptor from the FileSecurity. if (fileSecurity != null) { byte[] sd = fileSecurity.GetSecurityDescriptorBinaryForm(); pinningHandle = GCHandle.Alloc(sd, GCHandleType.Pinned); fixed(byte *pSecDescriptor = sd) secAttrs.pSecurityDescriptor = pSecDescriptor; } } return(secAttrs); }
private static Interop.SECURITY_ATTRIBUTES GetSecAttrs(FileShare share) { Interop.SECURITY_ATTRIBUTES secAttrs = null; if ((share & FileShare.Inheritable) != 0) { secAttrs = new Interop.SECURITY_ATTRIBUTES(); secAttrs.nLength = Marshal.SizeOf(secAttrs); secAttrs.bInheritHandle = 1; } return(secAttrs); }