Source file
src/os/user/getgrouplist_darwin.go
1
2
3
4
5
6
7 package user
8
9
27 import "C"
28 import (
29 "fmt"
30 "unsafe"
31 )
32
33 func getGroupList(name *C.char, userGID C.gid_t, gids *C.gid_t, n *C.int) C.int {
34 return C.mygetgrouplist(name, userGID, gids, n)
35 }
36
37
38
39 func groupRetry(username string, name []byte, userGID C.gid_t, gids *[]C.gid_t, n *C.int) error {
40 *n = C.int(256 * 2)
41 for {
42 *gids = make([]C.gid_t, *n)
43 rv := getGroupList((*C.char)(unsafe.Pointer(&name[0])), userGID, &(*gids)[0], n)
44 if rv >= 0 {
45
46 break
47 }
48 if *n > maxGroups {
49 return fmt.Errorf("user: %q is a member of more than %d groups", username, maxGroups)
50 }
51 *n = *n * C.int(2)
52 }
53 return nil
54 }
55
View as plain text