aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/errors.go2
-rw-r--r--util/users.go8
-rw-r--r--util/util.go5
3 files changed, 10 insertions, 5 deletions
diff --git a/util/errors.go b/util/errors.go
index fada687..f0b9403 100644
--- a/util/errors.go
+++ b/util/errors.go
@@ -29,6 +29,8 @@ import (
)
var (
+ // ErrNotRoot indicates the action is restricted to the superuser.
+ ErrNotRoot = errors.New("only root can perform this action")
// ErrSkipIntegration indicates integration tests shouldn't be run.
ErrSkipIntegration = errors.New("skipping integration test")
)
diff --git a/util/users.go b/util/users.go
index 92affa8..49abd32 100644
--- a/util/users.go
+++ b/util/users.go
@@ -48,3 +48,11 @@ func GetUser(uid int) *user.User {
func CurrentUser() *user.User {
return GetUser(CurrentUserID())
}
+
+// CheckIfRoot returns ErrNotRoot if the current user is not the root user.
+func CheckIfRoot() error {
+ if id := CurrentUserID(); id != 0 {
+ return ErrNotRoot
+ }
+ return nil
+}
diff --git a/util/util.go b/util/util.go
index ed78519..df24a99 100644
--- a/util/util.go
+++ b/util/util.go
@@ -117,8 +117,3 @@ func AtoiOrPanic(input string) int {
}
return i
}
-
-// IsUserRoot checks if the effective user is root.
-func IsUserRoot() bool {
- return CurrentUserID() == 0
-}