Matthew Rich
e695278d0c
All checks were successful
Declarative Tests / test (push) Successful in 48s
45 lines
809 B
Go
45 lines
809 B
Go
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
|
|
|
package resource
|
|
|
|
import (
|
|
"os/user"
|
|
"strconv"
|
|
)
|
|
|
|
func LookupUIDString(userName string) string {
|
|
user, userLookupErr := user.Lookup(userName)
|
|
if userLookupErr != nil {
|
|
return ""
|
|
}
|
|
return user.Uid
|
|
}
|
|
|
|
func LookupUID(userName string) (int, error) {
|
|
user, userLookupErr := user.Lookup(userName)
|
|
if userLookupErr != nil {
|
|
return -1, userLookupErr
|
|
}
|
|
|
|
uid, uidErr := strconv.Atoi(user.Uid)
|
|
if uidErr != nil {
|
|
return -1, uidErr
|
|
}
|
|
|
|
return uid, nil
|
|
}
|
|
|
|
func LookupGID(groupName string) (int, error) {
|
|
group, groupLookupErr := user.LookupGroup(groupName)
|
|
if groupLookupErr != nil {
|
|
return -1, groupLookupErr
|
|
}
|
|
|
|
gid, gidErr := strconv.Atoi(group.Gid)
|
|
if gidErr != nil {
|
|
return -1, gidErr
|
|
}
|
|
|
|
return gid, nil
|
|
}
|