示例#1
0
        /// <summary>[AlphaFS] Check if the directory has permission inheritance enabled.</summary>
        /// <param name="path">The full path to the directory to check.</param>
        /// <returns><see langword="true"/> if permission inheritance is enabled, <see langword="false"/> if permission inheritance is disabled.</returns>
        public static bool HasInheritedPermissions(string path)
        {
            if (Utils.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException("path");
            }

            var acl = File.GetAccessControlCore <DirectorySecurity>(true, path, AccessControlSections.Access | AccessControlSections.Group | AccessControlSections.Owner, PathFormat.RelativePath);

            return(acl.GetAccessRules(false, true, typeof(SecurityIdentifier)).Count > 0);
        }
        /// <summary>[AlphaFS] Checks if the directory has permission inheritance enabled.</summary>
        /// <returns><see langword="true"/> if permission inheritance is enabled, <see langword="false"/> if permission inheritance is disabled.</returns>
        /// <param name="path">The full path to the directory to check.</param>
        /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
        public static bool HasInheritedPermissions(string path, PathFormat pathFormat)
        {
            if (Utils.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException("path");
            }


            var acl = File.GetAccessControlCore <DirectorySecurity>(true, path, AccessControlSections.Access | AccessControlSections.Group | AccessControlSections.Owner, pathFormat);

            var rawBytes = acl.GetSecurityDescriptorBinaryForm();

            var rsd = new RawSecurityDescriptor(rawBytes, 0);


            // "Include inheritable permissions from this object's parent" is unchecked
            var inheritanceDisabled = (rsd.ControlFlags & ControlFlags.DiscretionaryAclProtected) == ControlFlags.DiscretionaryAclProtected;

            return(!inheritanceDisabled);
        }
 public FileSecurity GetAccessControl(AccessControlSections includeSections)
 {
     return(File.GetAccessControlCore <FileSecurity>(false, LongFullName, includeSections, PathFormat.LongFullPath));
 }
 public FileSecurity GetAccessControl()
 {
     return(File.GetAccessControlCore <FileSecurity>(false, LongFullName, AccessControlSections.Access | AccessControlSections.Group | AccessControlSections.Owner, PathFormat.LongFullPath));
 }
 public static DirectorySecurity GetAccessControl(string path, AccessControlSections includeSections, PathFormat pathFormat)
 {
     return(File.GetAccessControlCore <DirectorySecurity>(true, path, includeSections, pathFormat));
 }
 public static DirectorySecurity GetAccessControl(string path, PathFormat pathFormat)
 {
     return(File.GetAccessControlCore <DirectorySecurity>(true, path, AccessControlSections.Access | AccessControlSections.Group | AccessControlSections.Owner, pathFormat));
 }
 public DirectorySecurity GetAccessControl(AccessControlSections includeSections)
 {
     return(File.GetAccessControlCore <DirectorySecurity>(true, LongFullName, includeSections, PathFormat.LongFullPath));
 }
 public DirectorySecurity GetAccessControl()
 {
     return(File.GetAccessControlCore <DirectorySecurity>(true, LongFullName, AccessControlSections.Access | AccessControlSections.Group | AccessControlSections.Owner, PathFormat.LongFullPath));
 }