处理二进制ACL的代码

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);
posted @ 2010-04-13 15:29  Haitao Chen  阅读(495)  评论(0编辑  收藏  举报