本文整理汇总了C#中System.Security.AccessControl.FileSecurity.GetSecurityDescriptorBinaryForm方法的典型用法代码示例。如果您正苦于以下问题:C# FileSecurity.GetSecurityDescriptorBinaryForm方法的具体用法?C# FileSecurity.GetSecurityDescriptorBinaryForm怎么用?C# FileSecurity.GetSecurityDescriptorBinaryForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.AccessControl.FileSecurity
的用法示例。
在下文中一共展示了FileSecurity.GetSecurityDescriptorBinaryForm方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSecAttrs
private static unsafe Win32Native.SECURITY_ATTRIBUTES GetSecAttrs(FileShare share, FileSecurity fileSecurity, out object pinningHandle)
{
pinningHandle = null;
Win32Native.SECURITY_ATTRIBUTES structure = null;
if (((share & FileShare.Inheritable) != FileShare.None) || (fileSecurity != null))
{
structure = new Win32Native.SECURITY_ATTRIBUTES {
nLength = Marshal.SizeOf(structure)
};
if ((share & FileShare.Inheritable) != FileShare.None)
{
structure.bInheritHandle = 1;
}
if (fileSecurity == null)
{
return structure;
}
byte[] securityDescriptorBinaryForm = fileSecurity.GetSecurityDescriptorBinaryForm();
pinningHandle = GCHandle.Alloc(securityDescriptorBinaryForm, GCHandleType.Pinned);
fixed (byte* numRef = securityDescriptorBinaryForm)
{
structure.pSecurityDescriptor = numRef;
}
}
return structure;
}
示例2: GetSecAttrs
// If pinningHandle is not null, caller must free it AFTER the call to
// CreateFile has returned.
//
// [....]: Copied this from System.IO.FileStream
//
private static unsafe SECURITY_ATTRIBUTES GetSecAttrs(
FileShare share,
FileSecurity fileSecurity,
out object pinningHandle)
{
pinningHandle = null;
SECURITY_ATTRIBUTES secAttrs = null;
if ((share & FileShare.Inheritable) != 0 || fileSecurity != null)
{
secAttrs = new SECURITY_ATTRIBUTES();
secAttrs.nLength = (int)Marshal.SizeOf(secAttrs);
if ((share & FileShare.Inheritable) != 0)
{
secAttrs.bInheritHandle = 1;
}
// For ACLs, 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;
}