aboutsummaryrefslogtreecommitdiff
path: root/pkg/rootless
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2020-12-23 10:21:24 +0100
committerGiuseppe Scrivano <gscrivan@redhat.com>2021-01-07 09:41:01 +0100
commitfcc04fbabaf656553fcec9195cbf219c451d4c5a (patch)
treeb8e7c86358468da11f799d697fec953c681ce9cf /pkg/rootless
parent355e387692b15b151d65e58b580581382eee7f62 (diff)
downloadpodman-fcc04fbabaf656553fcec9195cbf219c451d4c5a.tar.gz
podman-fcc04fbabaf656553fcec9195cbf219c451d4c5a.tar.bz2
podman-fcc04fbabaf656553fcec9195cbf219c451d4c5a.zip
rootless: add function to retrieve gid mappings
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'pkg/rootless')
-rw-r--r--pkg/rootless/rootless.go38
1 files changed, 25 insertions, 13 deletions
diff --git a/pkg/rootless/rootless.go b/pkg/rootless/rootless.go
index 799c793d8..2ba0f8e81 100644
--- a/pkg/rootless/rootless.go
+++ b/pkg/rootless/rootless.go
@@ -50,24 +50,36 @@ func TryJoinPauseProcess(pausePidPath string) (bool, int, error) {
}
var (
- availableGids int64
- availableGidsErr error
- availableGidsOnce sync.Once
+ gidMap []user.IDMap
+ gidMapError error
+ gidMapOnce sync.Once
)
-// GetAvailableGids returns how many GIDs are available in the
+// GetAvailableGidMap returns the GID mappings in the
// current user namespace.
-func GetAvailableGids() (int64, error) {
- availableGidsOnce.Do(func() {
- idMap, err := user.ParseIDMapFile("/proc/self/gid_map")
+func GetAvailableGidMap() ([]user.IDMap, error) {
+ gidMapOnce.Do(func() {
+ var err error
+ gidMap, err = user.ParseIDMapFile("/proc/self/gid_map")
if err != nil {
- availableGidsErr = err
+ gidMapError = err
return
}
- availableGids = int64(0)
- for _, r := range idMap {
- availableGids += r.Count
- }
})
- return availableGids, availableGidsErr
+ return gidMap, gidMapError
+}
+
+// GetAvailableGids returns how many GIDs are available in the
+// current user namespace.
+func GetAvailableGids() (int64, error) {
+ gids, err := GetAvailableGidMap()
+ if err != nil {
+ return -1, err
+ }
+
+ availableGids := int64(0)
+ for _, r := range gids {
+ availableGids += r.Count
+ }
+ return availableGids, nil
}