// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build cgo
+package user
+/*
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
-int mygetgrouplist(const char* user, gid_t group, gid_t* groups, int* ngroups) {
+static int mygetgrouplist(const char* user, gid_t group, gid_t* groups, int* ngroups) {
int* buf = malloc(*ngroups * sizeof(int));
int rv = getgrouplist(user, (int) group, buf, ngroups);
int i;
free(buf);
return rv;
}
+*/
+import "C"
+
+func getGroupList(name *C.char, userGID C.gid_t, gids *C.gid_t, n *C.int) C.int {
+ return C.mygetgrouplist(name, userGID, gids, n)
+}
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build cgo
// +build dragonfly freebsd !android,linux netbsd openbsd
+package user
+
+/*
#include <unistd.h>
#include <sys/types.h>
#include <grp.h>
-int mygetgrouplist(const char* user, gid_t group, gid_t* groups, int* ngroups) {
+static int mygetgrouplist(const char* user, gid_t group, gid_t* groups, int* ngroups) {
return getgrouplist(user, group, groups, ngroups);
}
+*/
+import "C"
+
+func getGroupList(name *C.char, userGID C.gid_t, gids *C.gid_t, n *C.int) C.int {
+ return C.mygetgrouplist(name, userGID, gids, n)
+}
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
-
-extern int mygetgrouplist(const char* user, gid_t group, gid_t* groups, int* ngroups);
*/
import "C"
n := C.int(256)
gidsC := make([]C.gid_t, n)
- rv := C.mygetgrouplist(nameC, userGID, &gidsC[0], &n)
+ rv := getGroupList(nameC, userGID, &gidsC[0], &n)
if rv == -1 {
// More than initial buffer, but now n contains the correct size.
const maxGroups = 2048
return nil, fmt.Errorf("user: list groups for %s: member of more than %d groups", u.Username, maxGroups)
}
gidsC = make([]C.gid_t, n)
- rv := C.mygetgrouplist(nameC, userGID, &gidsC[0], &n)
+ rv := getGroupList(nameC, userGID, &gidsC[0], &n)
if rv == -1 {
return nil, fmt.Errorf("user: list groups for %s failed (changed groups?)", u.Username)
}