Debian Codegraph @

libgo/go/os/user/getgrouplist_unix.go

raw
1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //go:build (dragonfly || freebsd || hurd || (!android && linux) || netbsd || openbsd || (solaris && !illumos)) && cgo && !osusergo
6
7 package user
8
9 import (
10 "fmt"
11 "syscall"
12 )
13
14 //extern-sysinfo getgrouplist
15 func getGroupList(name *byte, userGID syscall.Gid_t, gids *syscall.Gid_t, n *int32) int32
16
17 // groupRetry retries getGroupList with much larger size for n. The result is
18 // stored in gids.
19 func groupRetry(username string, name []byte, userGID syscall.Gid_t, gids *[]syscall.Gid_t, n *int32) error {
20 // More than initial buffer, but now n contains the correct size.
21 if *n > maxGroups {
22 return fmt.Errorf("user: %q is a member of more than %d groups", username, maxGroups)
23 }
24 *gids = make([]syscall.Gid_t, *n)
25 rv := getGroupList(&name[0], userGID, &(*gids)[0], n)
26 if rv == -1 {
27 return fmt.Errorf("user: list groups for %s failed", username)
28 }
29 return nil
30 }