diff options
| author | Joseph Richey <joerichey94@gmail.com> | 2017-10-19 03:37:54 -0700 |
|---|---|---|
| committer | Joseph Richey <joerichey94@gmail.com> | 2017-10-19 03:54:50 -0700 |
| commit | 3269bc539e52cdced8c03a628e4fdf22942ece4b (patch) | |
| tree | 062792c21fe6751e14f827616bf454e62210a1dc /util/users.go | |
| parent | fe76f6f1cc71c75bc1124f4fe3171c679c06aa1c (diff) | |
util: Add CheckIfRoot
Replace IsUserRoot with CheckIfRoot. This allows all functions to use
the same error handling when a user is not root.
Diffstat (limited to 'util/users.go')
| -rw-r--r-- | util/users.go | 8 |
1 files changed, 8 insertions, 0 deletions
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 +} |