lookup.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package user
  2. import (
  3. "errors"
  4. )
  5. var (
  6. // The current operating system does not provide the required data for user lookups.
  7. ErrUnsupported = errors.New("user lookup: operating system does not provide passwd-formatted data")
  8. // No matching entries found in file.
  9. ErrNoPasswdEntries = errors.New("no matching entries in passwd file")
  10. ErrNoGroupEntries = errors.New("no matching entries in group file")
  11. )
  12. // LookupUser looks up a user by their username in /etc/passwd. If the user
  13. // cannot be found (or there is no /etc/passwd file on the filesystem), then
  14. // LookupUser returns an error.
  15. func LookupUser(username string) (User, error) {
  16. return lookupUser(username)
  17. }
  18. // LookupUid looks up a user by their user id in /etc/passwd. If the user cannot
  19. // be found (or there is no /etc/passwd file on the filesystem), then LookupId
  20. // returns an error.
  21. func LookupUid(uid int) (User, error) {
  22. return lookupUid(uid)
  23. }
  24. // LookupGroup looks up a group by its name in /etc/group. If the group cannot
  25. // be found (or there is no /etc/group file on the filesystem), then LookupGroup
  26. // returns an error.
  27. func LookupGroup(groupname string) (Group, error) {
  28. return lookupGroup(groupname)
  29. }
  30. // LookupGid looks up a group by its group id in /etc/group. If the group cannot
  31. // be found (or there is no /etc/group file on the filesystem), then LookupGid
  32. // returns an error.
  33. func LookupGid(gid int) (Group, error) {
  34. return lookupGid(gid)
  35. }