sys - add user check

This commit is contained in:
Mahdi Abu Yasmine 2023-11-25 15:48:16 +01:00
parent 15f88996fa
commit 9d8add71f2

View File

@ -8,6 +8,8 @@ import (
"os" "os"
"os/exec" "os/exec"
"os/signal" "os/signal"
"os/user"
"strconv"
"strings" "strings"
"syscall" "syscall"
@ -187,3 +189,30 @@ func CheckSumFile(remoteChecksum string, path string) bool {
} }
return checksum == remoteChecksum 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
}