diff options
Diffstat (limited to 'internal/syscallcompat/asuser_linux.go')
-rw-r--r-- | internal/syscallcompat/asuser_linux.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/internal/syscallcompat/asuser_linux.go b/internal/syscallcompat/asuser_linux.go index dac94f4..d0224bc 100644 --- a/internal/syscallcompat/asuser_linux.go +++ b/internal/syscallcompat/asuser_linux.go @@ -1,7 +1,11 @@ package syscallcompat import ( + "fmt" + "io/ioutil" "runtime" + "strconv" + "strings" "golang.org/x/sys/unix" @@ -47,3 +51,29 @@ func asUser(f func() (int, error), context *fuse.Context) (int, error) { return f() } + +func getSupplementaryGroups(pid uint32) (gids []int) { + procPath := fmt.Sprintf("/proc/%d/task/%d/status", pid, pid) + blob, err := ioutil.ReadFile(procPath) + if err != nil { + return nil + } + + lines := strings.Split(string(blob), "\n") + for _, line := range lines { + if strings.HasPrefix(line, "Groups:") { + f := strings.Fields(line[7:]) + gids = make([]int, len(f)) + for i := range gids { + val, err := strconv.ParseInt(f[i], 10, 32) + if err != nil { + return nil + } + gids[i] = int(val) + } + return gids + } + } + + return nil +} |