处理二进制ACL的代码

博客展示了处理二进制ACL的代码。通过创建字节数组表示ACL,利用RawSecurityDescriptor和DiscretionaryAcl等类,添加用户访问权限,获取RawAcl并更新DiscretionaryAcl,最后得到处理后的二进制形式。代码可用于相关权限管理场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Add user access to ACL Binary
Byte[] aclbytes = new byte[] { 1, 0, 20, 128, 80, 0, 0, 0, 96, 0, 0, 0, 20, 0, 0, 0, 28, 0, 0, 0, 2, 0, 8, 0, 0, 0, 0, 0, 2, 0, 52, 0, 2, 0, 0, 0, 0, 3, 20, 0, 3, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 5, 18, 0, 0, 0, 0, 3, 24, 0, 3, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 5, 32, 0, 0, 0, 32, 2, 0, 0, 1, 2, 0, 0, 0, 0, 0, 5, 32, 0, 0, 0, 32, 2, 0, 0, 1, 2, 0, 0, 0, 0, 0, 5, 32, 0, 0, 0, 32, 2, 0, 0 };
RawSecurityDescriptor gsd = new RawSecurityDescriptor(aclbytes, 0);

DiscretionaryAcl dacl = new DiscretionaryAcl(true, true, gsd.DiscretionaryAcl);
dacl.AddAccess(AccessControlType.Allow, new SecurityIdentifier("S-1-5-21-1935655697-562591055-1417001333-65138"), 3, InheritanceFlags.None, PropagationFlags.None);
RawAcl racl = (RawAcl)dacl.GetType().GetProperty("RawAcl", System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(dacl, null);
gsd.DiscretionaryAcl = racl;

byte[] outbuffer = new byte[gsd.BinaryLength];
gsd.GetBinaryForm(outbuffer, 0);

转载于:https://www.cnblogs.com/OpsMgr/archive/2010/04/13/1711157.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值