本文整理汇总了C#中System.Security.AccessControl.RawAcl.GetBinaryForm方法的典型用法代码示例。如果您正苦于以下问题:C# RawAcl.GetBinaryForm方法的具体用法?C# RawAcl.GetBinaryForm怎么用?C# RawAcl.GetBinaryForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.AccessControl.RawAcl
的用法示例。
在下文中一共展示了RawAcl.GetBinaryForm方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BinaryRoundtrip
public void BinaryRoundtrip ()
{
RawAcl acl = CreateRoundtripRawAcl ();
byte[] binaryForm1 = new byte[acl.BinaryLength];
acl.GetBinaryForm (binaryForm1, 0);
RawAcl acl2 = new RawAcl (binaryForm1, 0);
byte[] binaryForm2 = new byte[acl2.BinaryLength];
acl2.GetBinaryForm (binaryForm2, 0);
CompareBinaryForms (binaryForm1, binaryForm2);
}
示例2: GetBinaryForm
public void GetBinaryForm ()
{
RawAcl acl = new RawAcl (1, 0);
byte[] buffer = new byte[acl.BinaryLength];
acl.GetBinaryForm (buffer, 0);
byte[] sdBinary = new byte[] { 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 };
Assert.AreEqual (sdBinary, buffer);
SecurityIdentifier builtInAdmins = new SecurityIdentifier (WellKnownSidType.BuiltinAdministratorsSid, null);
CommonAce ace = new CommonAce (AceFlags.None, AceQualifier.AccessAllowed, 0x7FFFFFFF, builtInAdmins, false, null);
acl.InsertAce (0, ace);
buffer = new byte[acl.BinaryLength];
acl.GetBinaryForm (buffer, 0);
sdBinary = new byte[] {
0x01, 0x00, 0x20, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x18, 0x00, 0xFF, 0xFF, 0xFF, 0x7F, 0x01, 0x02, 0x00, 0x00,
0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x20, 0x02,
0x00, 0x00 };
Assert.AreEqual (sdBinary, buffer);
}
示例3: SetSamDacl
/// <summary>
/// Set the DACL of a SAM object.
/// </summary>
/// <param name="objectHandle">
/// A handle to the SAM object whose DACL is to be retrieved.
/// </param>
/// <param name="rawAcl">
/// A <see cref="RawAcl"/> object containing the DACL to be set into
/// the SAM object.
/// </param>
private void SetSamDacl(IntPtr objectHandle, RawAcl rawAcl)
{
IntPtr ipsd = IntPtr.Zero;
IntPtr ipDacl = IntPtr.Zero;
try
{
bool present = false;
// create a new security descriptor
var sd = new SECURITY_DESCRIPTOR() { Revision = 1 };
ipsd = Marshal.AllocHGlobal(ClrFacade.SizeOf<SECURITY_DESCRIPTOR>());
if (rawAcl != null && rawAcl.BinaryLength > 0)
{
ClrFacade.StructureToPtr<SECURITY_DESCRIPTOR>(sd, ipsd, false);
// put the DACL into unmanaged memory
var length = rawAcl.BinaryLength;
var bytes = new byte[length];
rawAcl.GetBinaryForm(bytes, 0);
ipDacl = Marshal.AllocHGlobal(length);
Marshal.Copy(bytes, 0, ipDacl, length);
present = true;
}
// set the DACL into our new security descriptor
var ok = Win32.SetSecurityDescriptorDacl(ipsd, present, ipDacl, false);
if (!ok)
{
var error = Marshal.GetLastWin32Error();
if (error == Win32.ERROR_ACCESS_DENIED)
throw new AccessDeniedException(context.target);
else
throw new Win32InternalException(error, context.target);
}
var status = SamApi.SamSetSecurityObject(objectHandle, Win32.DACL_SECURITY_INFORMATION, ipsd);
ThrowOnFailure(status);
}
finally
{
Marshal.FreeHGlobal(ipDacl);
Marshal.FreeHGlobal(ipsd);
}
}