sys - add user check
This commit is contained in:
parent
15f88996fa
commit
9d8add71f2
29
sys/sys.go
29
sys/sys.go
|
@ -8,6 +8,8 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"os/user"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
|
@ -187,3 +189,30 @@ func CheckSumFile(remoteChecksum string, path string) bool {
|
|||
}
|
||||
return checksum == remoteChecksum
|
||||
}
|
||||
|
||||
func IsRootUser() bool {
|
||||
done := false
|
||||
if usr, err := user.Current(); err != nil {
|
||||
done = usr.Uid == "0" && usr.HomeDir == "/root"
|
||||
}
|
||||
return done
|
||||
}
|
||||
|
||||
func IsUser(name string) bool {
|
||||
done := false
|
||||
if usr, err := user.Current(); err != nil {
|
||||
done = usr.Name == name
|
||||
}
|
||||
return done
|
||||
}
|
||||
|
||||
func IsSystemUser(name string) bool {
|
||||
done := false
|
||||
if usr, err := user.Current(); err != nil {
|
||||
var id int
|
||||
if id, err = strconv.Atoi(usr.Uid); err != nil {
|
||||
done = id < 1000
|
||||
}
|
||||
}
|
||||
return done
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user