public void SetPermission( AbsoluteDirectoryPath dir, FileSystemPermission permission, FileSystemGroup group, bool recursive = false) { _filePermissionImpl.SetPermission(dir, permission, group, recursive); }
public void SetPermission( AbsoluteFilePath file, FileSystemPermission permission, FileSystemGroup group) { var permissionWithGroupBits = GetPermissionBits(permission, @group); Syscall.chmod(file.NativePath, (FilePermissions)permissionWithGroupBits); }
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)); }
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); }
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); } }
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); }
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); } } }
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); }
public void SetPermission(AbsoluteFilePath file, FileSystemPermission permission, FileSystemGroup group) { _filePermissionImpl.SetPermission(file, permission, group); }