示例#1
0
 public void SetPermission(
     AbsoluteDirectoryPath dir,
     FileSystemPermission permission,
     FileSystemGroup group,
     bool recursive = false)
 {
     _filePermissionImpl.SetPermission(dir, permission, group, recursive);
 }
示例#2
0
        public void SetPermission(
            AbsoluteFilePath file,
            FileSystemPermission permission,
            FileSystemGroup group)
        {
            var permissionWithGroupBits = GetPermissionBits(permission, @group);

            Syscall.chmod(file.NativePath, (FilePermissions)permissionWithGroupBits);
        }
示例#3
0
        void ReplaceAllDescendantPermissionsFromObject(
            DirectoryInfo dInfo,
            DirectorySecurity dSecurity,
            FileSystemPermission fileSystemPermission,
            FileSystemGroup group)
        {
            dInfo.SetAccessControl(dSecurity);

            foreach (FileInfo fi in dInfo.GetFiles())
            {
                SetPermission(AbsoluteFilePath.Parse(fi.FullName), fileSystemPermission, group);
            }

            dInfo.GetDirectories().ToList()
            .ForEach(d => ReplaceAllDescendantPermissionsFromObject(d, dSecurity, fileSystemPermission, group));
        }
示例#4
0
        static IdentityReference GetIdentity(FileSystemGroup group)
        {
            IdentityReference identity;

            if (group.HasFlag(FileSystemGroup.Everyone))
            {
                identity = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
            }
            else if (group.HasFlag(FileSystemGroup.User))
            {
                identity = WindowsIdentity.GetCurrent().User;
            }
            else
            {
                throw new NotImplementedException("Be free to implement it.");
            }
            return(identity);
        }
示例#5
0
        public void SetPermission(
            AbsoluteDirectoryPath dir,
            FileSystemPermission permission,
            FileSystemGroup group,
            bool recursive)
        {
            var dInfo = new DirectoryInfo(dir.NativePath);
            var dSec  = new DirectorySecurity();

            dSec.AddAccessRule(new FileSystemAccessRule(
                                   GetIdentity(group),
                                   CreateSystemRightsFile(permission),
                                   AccessControlType.Allow));
            dInfo.SetAccessControl(dSec);

            if (recursive)
            {
                ReplaceAllDescendantPermissionsFromObject(dInfo, dSec, permission, group);
            }
        }
示例#6
0
        static int GetPermissionBits(FileSystemPermission permission, FileSystemGroup @group)
        {
            var permissionBits = 0;

            if (permission.HasFlag(FileSystemPermission.Execute))
            {
                permissionBits |= (int)FilePermissions.S_IXOTH;
            }
            if (permission.HasFlag(FileSystemPermission.Read))
            {
                permissionBits |= (int)FilePermissions.S_IROTH;
            }
            if (permission.HasFlag(FileSystemPermission.Write))
            {
                permissionBits |= (int)FilePermissions.S_IWOTH;
            }

            var permissionWithGroupBits = 0;

            if (group.HasFlag(FileSystemGroup.Others))
            {
                permissionWithGroupBits |= permissionBits;
            }

            if (group.HasFlag(FileSystemGroup.Group))
            {
                permissionWithGroupBits |= permissionBits << 3;
            }

            if (group.HasFlag(FileSystemGroup.User))
            {
                permissionWithGroupBits |= permissionBits << 6;
            }

            return(permissionWithGroupBits);
        }
示例#7
0
        public void SetPermission(
            AbsoluteDirectoryPath dir,
            FileSystemPermission permission,
            FileSystemGroup group,
            bool recursive)
        {
            var permissionBits = GetPermissionBits(permission, group);

            Syscall.chmod(dir.NativePath, (FilePermissions)permissionBits);

            if (recursive)
            {
                foreach (var file in Directory.GetFiles(dir.NativePath))
                {
                    var filePermission = (int)permission & ~(int)FileSystemPermission.Execute;
                    SetPermission(AbsoluteFilePath.Parse(file), (FileSystemPermission)filePermission, group);
                }

                foreach (var directory in Directory.GetDirectories(dir.NativePath))
                {
                    SetPermission(AbsoluteDirectoryPath.Parse(directory), permission, group, recursive);
                }
            }
        }
示例#8
0
        public void SetPermission(AbsoluteFilePath file, FileSystemPermission permission, FileSystemGroup group)
        {
            var identity = GetIdentity(group);

            var fileSecurity = new FileSecurity();

            fileSecurity.SetAccessRule(new FileSystemAccessRule(
                                           identity,
                                           CreateSystemRightsFile(permission),
                                           AccessControlType.Allow));

            File.SetAccessControl(file.NativePath, fileSecurity);
        }
示例#9
0
 public void SetPermission(AbsoluteFilePath file, FileSystemPermission permission, FileSystemGroup group)
 {
     _filePermissionImpl.SetPermission(file, permission, group);
 }