public static IEnumerable <FileSystemAccessRule2> GetFileSystemAccessRules(FileSystemSecurity2 sd, bool includeExplicit, bool includeInherited, bool getInheritedFrom = false)
        {
            List <FileSystemAccessRule2> aceList = new List <FileSystemAccessRule2>();
            List <string> inheritedFrom          = null;

            if (getInheritedFrom)
            {
                inheritedFrom = Win32.GetInheritedFrom(sd.Item, sd.SecurityDescriptor);
            }

            var aceCounter = 0;
            var acl        = !sd.IsFile ?
                             ((DirectorySecurity)sd.SecurityDescriptor).GetAccessRules(includeExplicit, includeInherited, typeof(SecurityIdentifier)) :
                             ((FileSecurity)sd.SecurityDescriptor).GetAccessRules(includeExplicit, includeInherited, typeof(SecurityIdentifier));

            foreach (FileSystemAccessRule ace in acl)
            {
                var ace2 = new FileSystemAccessRule2(ace)
                {
                    FullName = sd.Item.FullName, InheritanceEnabled = !sd.SecurityDescriptor.AreAccessRulesProtected
                };
                if (getInheritedFrom)
                {
                    ace2.inheritedFrom = string.IsNullOrEmpty(inheritedFrom[aceCounter]) ? "" : inheritedFrom[aceCounter].Substring(0, inheritedFrom[aceCounter].Length - 1);
                    aceCounter++;
                }

                aceList.Add(ace2);
            }

            return(aceList);
        }
Exemplo n.º 2
0
 public static void AddFileSystemAccessRule(FileSystemAccessRule2 rule)
 {
     AddFileSystemAccessRule(rule.fullName,
                             rule.Account,
                             rule.AccessRights,
                             rule.AccessControlType,
                             rule.InheritanceFlags,
                             rule.PropagationFlags);
 }
Exemplo n.º 3
0
 public EffectiveAccessInfo(FileSystemAccessRule2 ace, bool fromRemote, Exception authzException = null)
 {
     this.ace            = ace;
     this.fromRemote     = fromRemote;
     this.authzException = authzException;
 }