2014-08-29 16:43:40 +08:00
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// The current operating system does not provide the required data for user lookups.
|
|
|
|
ErrUnsupported = errors.New("user lookup: operating system does not provide passwd-formatted data")
|
2016-03-18 01:23:12 +08:00
|
|
|
// No matching entries found in file.
|
|
|
|
ErrNoPasswdEntries = errors.New("no matching entries in passwd file")
|
|
|
|
ErrNoGroupEntries = errors.New("no matching entries in group file")
|
2014-08-29 16:43:40 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// LookupUser looks up a user by their username in /etc/passwd. If the user
|
|
|
|
// cannot be found (or there is no /etc/passwd file on the filesystem), then
|
|
|
|
// LookupUser returns an error.
|
|
|
|
func LookupUser(username string) (User, error) {
|
2018-03-01 03:14:24 +08:00
|
|
|
return lookupUser(username)
|
2014-08-29 16:43:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// LookupUid looks up a user by their user id in /etc/passwd. If the user cannot
|
|
|
|
// be found (or there is no /etc/passwd file on the filesystem), then LookupId
|
|
|
|
// returns an error.
|
|
|
|
func LookupUid(uid int) (User, error) {
|
2018-03-01 03:14:24 +08:00
|
|
|
return lookupUid(uid)
|
2014-08-29 16:43:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// LookupGroup looks up a group by its name in /etc/group. If the group cannot
|
|
|
|
// be found (or there is no /etc/group file on the filesystem), then LookupGroup
|
|
|
|
// returns an error.
|
|
|
|
func LookupGroup(groupname string) (Group, error) {
|
2018-03-01 03:14:24 +08:00
|
|
|
return lookupGroup(groupname)
|
2014-08-29 16:43:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// LookupGid looks up a group by its group id in /etc/group. If the group cannot
|
|
|
|
// be found (or there is no /etc/group file on the filesystem), then LookupGid
|
|
|
|
// returns an error.
|
|
|
|
func LookupGid(gid int) (Group, error) {
|
2018-03-01 03:14:24 +08:00
|
|
|
return lookupGid(gid)
|
2014-08-29 16:43:40 +08:00
|
|
|
}
|