user

package
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2024 License: Apache-2.0 Imports: 2 Imported by: 1,314

Documentation

Overview

Package user is an alias for github.com/moby/sys/user.

Deprecated: use github.com/moby/sys/user.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoPasswdEntries is returned if no matching entries were found in /etc/group.
	ErrNoPasswdEntries = user.ErrNoPasswdEntries
	// ErrNoGroupEntries is returned if no matching entries were found in /etc/passwd.
	ErrNoGroupEntries = user.ErrNoGroupEntries
	// ErrRange is returned if a UID or GID is outside of the valid range.
	ErrRange = user.ErrRange
)

Functions

func CurrentGroup

func CurrentGroup() (user.Group, error)

CurrentGroup looks up the current user's group by their primary group id's entry in /etc/passwd. If the group cannot be found (or there is no /etc/group file on the filesystem), then CurrentGroup returns an error.

func CurrentProcessGIDMap added in v1.0.0

func CurrentProcessGIDMap() ([]user.IDMap, error)

func CurrentProcessUIDMap added in v1.0.0

func CurrentProcessUIDMap() ([]user.IDMap, error)

func CurrentUser

func CurrentUser() (user.User, error)

CurrentUser looks up the current 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 CurrentUser returns an error.

func CurrentUserSubGIDs added in v1.0.0

func CurrentUserSubGIDs() ([]user.SubID, error)

func CurrentUserSubUIDs added in v1.0.0

func CurrentUserSubUIDs() ([]user.SubID, error)

func GetAdditionalGroups

func GetAdditionalGroups(additionalGroups []string, group io.Reader) ([]int, error)

GetAdditionalGroups looks up a list of groups by name or group id against the given /etc/group formatted data. If a group name cannot be found, an error will be returned. If a group id cannot be found, or the given group data is nil, the id will be returned as-is provided it is in the legal range.

func GetAdditionalGroupsPath

func GetAdditionalGroupsPath(additionalGroups []string, groupPath string) ([]int, error)

GetAdditionalGroupsPath is a wrapper around GetAdditionalGroups that opens the groupPath given and gives it as an argument to GetAdditionalGroups.

func GetExecUser

func GetExecUser(userSpec string, defaults *user.ExecUser, passwd, group io.Reader) (*user.ExecUser, error)

GetExecUser parses a user specification string (using the passwd and group readers as sources for /etc/passwd and /etc/group data, respectively). In the case of blank fields or missing data from the sources, the values in defaults is used.

GetExecUser will return an error if a user or group literal could not be found in any entry in passwd and group respectively.

Examples of valid user specifications are:

  • ""
  • "user"
  • "uid"
  • "user:group"
  • "uid:gid
  • "user:gid"
  • "uid:group"

It should be noted that if you specify a numeric user or group id, they will not be evaluated as usernames (only the metadata will be filled). So attempting to parse a user with user.Name = "1337" will produce the user with a UID of 1337.

func GetExecUserPath

func GetExecUserPath(userSpec string, defaults *user.ExecUser, passwdPath, groupPath string) (*user.ExecUser, error)

GetExecUserPath is a wrapper for GetExecUser. It reads data from each of the given file paths and uses that data as the arguments to GetExecUser. If the files cannot be opened for any reason, the error is ignored and a nil io.Reader is passed instead.

func GetGroup

func GetGroup() (io.ReadCloser, error)

func GetGroupPath

func GetGroupPath() (string, error)

func GetPasswd

func GetPasswd() (io.ReadCloser, error)

func GetPasswdPath

func GetPasswdPath() (string, error)

func LookupGid

func LookupGid(gid int) (user.Group, error)

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 LookupGroup

func LookupGroup(groupname string) (user.Group, error)

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 LookupUid

func LookupUid(uid int) (user.User, error)

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 LookupUser

func LookupUser(username string) (user.User, error)

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 ParseGroup

func ParseGroup(group io.Reader) ([]user.Group, error)

func ParseGroupFile

func ParseGroupFile(path string) ([]user.Group, error)

func ParseGroupFileFilter

func ParseGroupFileFilter(path string, filter func(user.Group) bool) ([]user.Group, error)

func ParseGroupFilter

func ParseGroupFilter(r io.Reader, filter func(user.Group) bool) ([]user.Group, error)

func ParseIDMap added in v1.0.0

func ParseIDMap(r io.Reader) ([]user.IDMap, error)

func ParseIDMapFile added in v1.0.0

func ParseIDMapFile(path string) ([]user.IDMap, error)

func ParseIDMapFileFilter added in v1.0.0

func ParseIDMapFileFilter(path string, filter func(user.IDMap) bool) ([]user.IDMap, error)

func ParseIDMapFilter added in v1.0.0

func ParseIDMapFilter(r io.Reader, filter func(user.IDMap) bool) ([]user.IDMap, error)

func ParsePasswd

func ParsePasswd(passwd io.Reader) ([]user.User, error)

func ParsePasswdFile

func ParsePasswdFile(path string) ([]user.User, error)

func ParsePasswdFileFilter

func ParsePasswdFileFilter(path string, filter func(user.User) bool) ([]user.User, error)

func ParsePasswdFilter

func ParsePasswdFilter(r io.Reader, filter func(user.User) bool) ([]user.User, error)

func ParseSubID added in v1.0.0

func ParseSubID(subid io.Reader) ([]user.SubID, error)

func ParseSubIDFile added in v1.0.0

func ParseSubIDFile(path string) ([]user.SubID, error)

func ParseSubIDFileFilter added in v1.0.0

func ParseSubIDFileFilter(path string, filter func(user.SubID) bool) ([]user.SubID, error)

func ParseSubIDFilter added in v1.0.0

func ParseSubIDFilter(r io.Reader, filter func(user.SubID) bool) ([]user.SubID, error)

Types

type ExecUser

type ExecUser = user.ExecUser

type Group

type Group = user.Group

type IDMap added in v1.0.0

type IDMap = user.IDMap

IDMap represents an entry in /proc/PID/{u,g}id_map.

type SubID added in v1.0.0

type SubID = user.SubID

SubID represents an entry in /etc/sub{u,g}id.

type User

type User = user.User

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL