You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
916 B
Go

package staros
import (
"os/user"
"strconv"
)
// GetUidGid
func GetUidGid(uname string) (uint32, uint32, string, error) {
usr, err := user.Lookup(uname)
if err != nil {
return 0, 0, "", err
}
uidInt, _ := strconv.Atoi(usr.Uid)
gidInt, _ := strconv.Atoi(usr.Gid)
return uint32(uidInt), uint32(gidInt), usr.HomeDir, nil
}
// GetUid
func GetUid(uname string) (uint32, error) {
usr, err := user.Lookup(uname)
if err != nil {
return 0, err
}
uidInt, _ := strconv.Atoi(usr.Uid)
return uint32(uidInt), nil
}
// GetGid
func GetGid(uname string) (uint32, error) {
usr, err := user.LookupGroup(uname)
if err != nil {
return 0, err
}
gidInt, _ := strconv.Atoi(usr.Gid)
return uint32(gidInt), nil
}
// GetGidByName
func GetGidByName(uname string) (uint32, error) {
usr, err := user.Lookup(uname)
if err != nil {
return 0, err
}
uidInt, _ := strconv.Atoi(usr.Gid)
return uint32(uidInt), nil
}