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

被折叠的 条评论
为什么被折叠?



