-
-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
138 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//go:build !windows | ||
|
||
package utils | ||
|
||
import "os" | ||
|
||
// SetDirPermission sets the permission of a directory. | ||
func SetDirPermission(path string, perm FSPermission) error { | ||
return os.Chmod(path, perm.AsUnixDirExecPermission()) | ||
} | ||
|
||
// SetExecPermission sets the permission of an executable file. | ||
func SetExecPermission(path string, perm FSPermission) error { | ||
return SetDirPermission(path, perm) | ||
} | ||
|
||
// SetFilePermission sets the permission of a non executable file. | ||
func SetFilePermission(path string, perm FSPermission) error { | ||
return os.Chmod(path, perm.AsUnixFilePermission()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//go:build windows | ||
|
||
package utils | ||
|
||
import ( | ||
"github.com/hectane/go-acl" | ||
"golang.org/x/sys/windows" | ||
) | ||
|
||
func SetDirPermission(path string, perm FSPermission) error { | ||
setWindowsFilePermissions(path, perm) | ||
return nil | ||
} | ||
|
||
// SetExecPermission sets the permission of an executable file. | ||
func SetExecPermission(path string, perm FSPermission) error { | ||
return SetDirPermission(path, perm) | ||
} | ||
|
||
func setWindowsFilePermissions(path string, perm FSPermission) { | ||
switch perm { | ||
case AdminOnlyPermission: | ||
// Set only admin rights, remove all others. | ||
acl.Apply(path, true, false, acl.GrantName(windows.GENERIC_ALL|windows.STANDARD_RIGHTS_ALL, "Administrators")) | ||
case PublicReadPermission: | ||
// Set admin rights and read/execute rights for users, remove all others. | ||
acl.Apply(path, true, false, acl.GrantName(windows.GENERIC_ALL|windows.STANDARD_RIGHTS_ALL, "Administrators")) | ||
acl.Apply(path, false, false, acl.GrantName(windows.GENERIC_EXECUTE, "Users")) | ||
acl.Apply(path, false, false, acl.GrantName(windows.GENERIC_READ, "Users")) | ||
case PublicWritePermission: | ||
// Set full control to admin and regular users. Guest users will not have access. | ||
acl.Apply(path, true, false, acl.GrantName(windows.GENERIC_ALL|windows.STANDARD_RIGHTS_ALL, "Administrators")) | ||
acl.Apply(path, false, false, acl.GrantName(windows.GENERIC_ALL|windows.STANDARD_RIGHTS_ALL, "Users")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.