github.com/opencontainers/runc@v1.2.0-rc.1.0.20240520010911-492dc558cdd6/libcontainer/user/user_deprecated.go (about)

     1  // Package user is an alias for [github.com/moby/sys/user].
     2  //
     3  // Deprecated: use [github.com/moby/sys/user].
     4  package user
     5  
     6  import (
     7  	"io"
     8  
     9  	"github.com/moby/sys/user"
    10  )
    11  
    12  var (
    13  	// ErrNoPasswdEntries is returned if no matching entries were found in /etc/group.
    14  	ErrNoPasswdEntries = user.ErrNoPasswdEntries
    15  	// ErrNoGroupEntries is returned if no matching entries were found in /etc/passwd.
    16  	ErrNoGroupEntries = user.ErrNoGroupEntries
    17  	// ErrRange is returned if a UID or GID is outside of the valid range.
    18  	ErrRange = user.ErrRange
    19  )
    20  
    21  type (
    22  	User = user.User
    23  
    24  	Group = user.Group
    25  
    26  	// SubID represents an entry in /etc/sub{u,g}id.
    27  	SubID = user.SubID
    28  
    29  	// IDMap represents an entry in /proc/PID/{u,g}id_map.
    30  	IDMap = user.IDMap
    31  
    32  	ExecUser = user.ExecUser
    33  )
    34  
    35  func ParsePasswdFile(path string) ([]user.User, error) {
    36  	return user.ParsePasswdFile(path)
    37  }
    38  
    39  func ParsePasswd(passwd io.Reader) ([]user.User, error) {
    40  	return user.ParsePasswd(passwd)
    41  }
    42  
    43  func ParsePasswdFileFilter(path string, filter func(user.User) bool) ([]user.User, error) {
    44  	return user.ParsePasswdFileFilter(path, filter)
    45  }
    46  
    47  func ParsePasswdFilter(r io.Reader, filter func(user.User) bool) ([]user.User, error) {
    48  	return user.ParsePasswdFilter(r, filter)
    49  }
    50  
    51  func ParseGroupFile(path string) ([]user.Group, error) {
    52  	return user.ParseGroupFile(path)
    53  }
    54  
    55  func ParseGroup(group io.Reader) ([]user.Group, error) {
    56  	return user.ParseGroup(group)
    57  }
    58  
    59  func ParseGroupFileFilter(path string, filter func(user.Group) bool) ([]user.Group, error) {
    60  	return user.ParseGroupFileFilter(path, filter)
    61  }
    62  
    63  func ParseGroupFilter(r io.Reader, filter func(user.Group) bool) ([]user.Group, error) {
    64  	return user.ParseGroupFilter(r, filter)
    65  }
    66  
    67  // GetExecUserPath is a wrapper for GetExecUser. It reads data from each of the
    68  // given file paths and uses that data as the arguments to GetExecUser. If the
    69  // files cannot be opened for any reason, the error is ignored and a nil
    70  // io.Reader is passed instead.
    71  func GetExecUserPath(userSpec string, defaults *user.ExecUser, passwdPath, groupPath string) (*user.ExecUser, error) {
    72  	return user.GetExecUserPath(userSpec, defaults, passwdPath, groupPath)
    73  }
    74  
    75  // GetExecUser parses a user specification string (using the passwd and group
    76  // readers as sources for /etc/passwd and /etc/group data, respectively). In
    77  // the case of blank fields or missing data from the sources, the values in
    78  // defaults is used.
    79  //
    80  // GetExecUser will return an error if a user or group literal could not be
    81  // found in any entry in passwd and group respectively.
    82  //
    83  // Examples of valid user specifications are:
    84  //   - ""
    85  //   - "user"
    86  //   - "uid"
    87  //   - "user:group"
    88  //   - "uid:gid
    89  //   - "user:gid"
    90  //   - "uid:group"
    91  //
    92  // It should be noted that if you specify a numeric user or group id, they will
    93  // not be evaluated as usernames (only the metadata will be filled). So attempting
    94  // to parse a user with user.Name = "1337" will produce the user with a UID of
    95  // 1337.
    96  func GetExecUser(userSpec string, defaults *user.ExecUser, passwd, group io.Reader) (*user.ExecUser, error) {
    97  	return user.GetExecUser(userSpec, defaults, passwd, group)
    98  }
    99  
   100  // GetAdditionalGroups looks up a list of groups by name or group id
   101  // against the given /etc/group formatted data. If a group name cannot
   102  // be found, an error will be returned. If a group id cannot be found,
   103  // or the given group data is nil, the id will be returned as-is
   104  // provided it is in the legal range.
   105  func GetAdditionalGroups(additionalGroups []string, group io.Reader) ([]int, error) {
   106  	return user.GetAdditionalGroups(additionalGroups, group)
   107  }
   108  
   109  // GetAdditionalGroupsPath is a wrapper around GetAdditionalGroups
   110  // that opens the groupPath given and gives it as an argument to
   111  // GetAdditionalGroups.
   112  func GetAdditionalGroupsPath(additionalGroups []string, groupPath string) ([]int, error) {
   113  	return user.GetAdditionalGroupsPath(additionalGroups, groupPath)
   114  }
   115  
   116  func ParseSubIDFile(path string) ([]user.SubID, error) {
   117  	return user.ParseSubIDFile(path)
   118  }
   119  
   120  func ParseSubID(subid io.Reader) ([]user.SubID, error) {
   121  	return user.ParseSubID(subid)
   122  }
   123  
   124  func ParseSubIDFileFilter(path string, filter func(user.SubID) bool) ([]user.SubID, error) {
   125  	return user.ParseSubIDFileFilter(path, filter)
   126  }
   127  
   128  func ParseSubIDFilter(r io.Reader, filter func(user.SubID) bool) ([]user.SubID, error) {
   129  	return user.ParseSubIDFilter(r, filter)
   130  }
   131  
   132  func ParseIDMapFile(path string) ([]user.IDMap, error) {
   133  	return user.ParseIDMapFile(path)
   134  }
   135  
   136  func ParseIDMap(r io.Reader) ([]user.IDMap, error) {
   137  	return user.ParseIDMap(r)
   138  }
   139  
   140  func ParseIDMapFileFilter(path string, filter func(user.IDMap) bool) ([]user.IDMap, error) {
   141  	return user.ParseIDMapFileFilter(path, filter)
   142  }
   143  
   144  func ParseIDMapFilter(r io.Reader, filter func(user.IDMap) bool) ([]user.IDMap, error) {
   145  	return user.ParseIDMapFilter(r, filter)
   146  }