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
}
