// (c) 2006 Richard Grimes // www.grimes.demon.co.uk using System; using System.IO; using System.Security.AccessControl; using System.Security.Principal; class App { static void Main(string[] args) { if (args.Length < 1) return; Console.WriteLine("for {0}:", args[0]); FileInfo fi = new FileInfo(args[0]); FileSecurity sd = fi.GetAccessControl(); NTAccount owner = (NTAccount)sd.GetOwner(typeof(NTAccount)); Console.WriteLine("Owner is: {0}", owner.ToString()); NTAccount group = (NTAccount)sd.GetGroup(typeof(NTAccount)); Console.WriteLine("Primary group is: {0}", group.ToString()); Console.WriteLine("Access Rules:"); foreach (FileSystemAccessRule rule in sd.GetAccessRules(true, true, typeof(NTAccount))) { Console.WriteLine("\t{0} user: {1} rights: {2}", rule.AccessControlType, rule.IdentityReference, rule.FileSystemRights); Console.WriteLine("\t\t{0}, inheritance: {1} propagation: {2}", rule.IsInherited ? "inherited right" : "direct right", rule.InheritanceFlags, rule.PropagationFlags); } Console.WriteLine("\n{0}\n", sd.GetSecurityDescriptorSddlForm(AccessControlSections.All)); byte[] sdBytes = sd.GetSecurityDescriptorBinaryForm(); CommonSecurityDescriptor csd = new CommonSecurityDescriptor(false, false, sdBytes, 0); Console.WriteLine("Owner is: {0}", csd.Owner.Translate(typeof(NTAccount))); Console.WriteLine("Primary group is: {0}", csd.Group.Translate(typeof(NTAccount))); Console.WriteLine("Access Rules:"); foreach (CommonAce ace in csd.DiscretionaryAcl) { Console.WriteLine("\t{0} user: {1} rights: {2:x8}", ace.AceType, ace.SecurityIdentifier.Translate(typeof(NTAccount)), ace.AccessMask); Console.WriteLine("\t\t{0}, inheritance: {1} propagation: {2}", ace.IsInherited ? "inherited right" : "direct right", ace.InheritanceFlags, ace.PropagationFlags); } } }