diff options
author | Giuseppe Scrivano <gscrivan@redhat.com> | 2019-09-03 13:47:24 +0200 |
---|---|---|
committer | Giuseppe Scrivano <gscrivan@redhat.com> | 2019-09-03 14:38:08 +0200 |
commit | 1a24ac7ad63464817a1b3df46ab7da1c0be6c842 (patch) | |
tree | ab9261470887c12cea4745a399e526c00d84236c | |
parent | cfe1d2768847929b44ddd10184eff28fd5762c2d (diff) | |
download | podman-1a24ac7ad63464817a1b3df46ab7da1c0be6c842.tar.gz podman-1a24ac7ad63464817a1b3df46ab7da1c0be6c842.tar.bz2 podman-1a24ac7ad63464817a1b3df46ab7da1c0be6c842.zip |
pkg/util: use rootless function to read additional users
make pkg/rootless.GetConfiguredMappings public so that it can be used
from pkg/util.
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
-rw-r--r-- | pkg/rootless/rootless_linux.go | 7 | ||||
-rw-r--r-- | pkg/rootless/rootless_unsupported.go | 6 | ||||
-rw-r--r-- | pkg/util/utils.go | 16 |
3 files changed, 14 insertions, 15 deletions
diff --git a/pkg/rootless/rootless_linux.go b/pkg/rootless/rootless_linux.go index a78336d7a..ecb84f6a9 100644 --- a/pkg/rootless/rootless_linux.go +++ b/pkg/rootless/rootless_linux.go @@ -347,7 +347,8 @@ func joinUserAndMountNS(pid uint, pausePid string) (bool, int, error) { return true, int(ret), nil } -func getConfiguredMappings() ([]idtools.IDMap, []idtools.IDMap, error) { +// GetConfiguredMappings returns the additional IDs configured for the current user. +func GetConfiguredMappings() ([]idtools.IDMap, []idtools.IDMap, error) { var uids, gids []idtools.IDMap username := os.Getenv("USER") if username == "" { @@ -413,7 +414,7 @@ func becomeRootInUserNS(pausePid, fileToRead string, fileOutput *os.File) (bool, return false, -1, errors.Errorf("cannot re-exec process") } - uids, gids, err := getConfiguredMappings() + uids, gids, err := GetConfiguredMappings() if err != nil { return false, -1, err } @@ -663,7 +664,7 @@ func ConfigurationMatches() (bool, error) { return true, nil } - uids, gids, err := getConfiguredMappings() + uids, gids, err := GetConfiguredMappings() if err != nil { return false, err } diff --git a/pkg/rootless/rootless_unsupported.go b/pkg/rootless/rootless_unsupported.go index 16ba228e2..ddd9182b0 100644 --- a/pkg/rootless/rootless_unsupported.go +++ b/pkg/rootless/rootless_unsupported.go @@ -5,6 +5,7 @@ package rootless import ( "os" + "github.com/containers/storage/pkg/idtools" "github.com/pkg/errors" ) @@ -59,3 +60,8 @@ func TryJoinFromFilePaths(pausePidPath string, needNewNamespace bool, paths []st func ConfigurationMatches() (bool, error) { return true, nil } + +// GetConfiguredMappings returns the additional IDs configured for the current user. +func GetConfiguredMappings() ([]idtools.IDMap, []idtools.IDMap, error) { + return nil, nil, errors.New("this function is not supported on this os") +} diff --git a/pkg/util/utils.go b/pkg/util/utils.go index 3f73639e7..2261934f0 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -3,7 +3,6 @@ package util import ( "fmt" "os" - ouser "os/user" "path/filepath" "strings" "sync" @@ -156,22 +155,15 @@ func ParseIDMapping(mode namespaces.UsernsMode, UIDMapSlice, GIDMapSlice []strin uid := rootless.GetRootlessUID() gid := rootless.GetRootlessGID() - username := os.Getenv("USER") - if username == "" { - user, err := ouser.LookupId(fmt.Sprintf("%d", uid)) - if err == nil { - username = user.Username - } - } - mappings, err := idtools.NewIDMappings(username, username) + uids, gids, err := rootless.GetConfiguredMappings() if err != nil { - return nil, errors.Wrapf(err, "cannot find mappings for user %s", username) + return nil, errors.Wrapf(err, "cannot read mappings") } maxUID, maxGID := 0, 0 - for _, u := range mappings.UIDs() { + for _, u := range uids { maxUID += u.Size } - for _, g := range mappings.GIDs() { + for _, g := range gids { maxGID += g.Size } |