Commit 9780bf2a authored by Ian Lance Taylor's avatar Ian Lance Taylor

os/user: don't create C function mygetgrouplist

Instead of exporting the C function mygetgrouplist as a global symbol to
conflict with other symbols of the same name, use trivial Go code and a
static C function.

Change-Id: I98dd667814d0a0ed8f7b1d4cfc6483d5a6965b26
Reviewed-on: https://go-review.googlesource.com/23008
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 81a89606
......@@ -2,13 +2,14 @@
// 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;
......@@ -20,3 +21,9 @@ int mygetgrouplist(const char* user, gid_t group, gid_t* groups, int* ngroups) {
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)
}
......@@ -2,13 +2,21 @@
// 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)
}
......@@ -16,8 +16,6 @@ import (
#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"
......@@ -32,7 +30,7 @@ func listGroups(u *User) ([]string, error) {
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
......@@ -40,7 +38,7 @@ func listGroups(u *User) ([]string, error) {
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)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment