From 7f3135415255ae92a5dc6dc0f55f658b85adbcfa Mon Sep 17 00:00:00 2001 From: Robert Drehmel Date: Fri, 29 Apr 2005 10:11:18 +0000 Subject: [PATCH] Add flag to choose whether to use getgrouplist(3) or getgroups(2) to the id_print() function. Use getgrouplist(3) for the case when an user was specified, and getgroups(2) when no user was given. That reverts to the expected behaviour and makes it easy to implement an option later to force using getgrouplist(3). --- usr.bin/id/id.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/usr.bin/id/id.c b/usr.bin/id/id.c index e546e8c430f9..20a348e81767 100644 --- a/usr.bin/id/id.c +++ b/usr.bin/id/id.c @@ -57,7 +57,7 @@ __FBSDID("$FreeBSD$"); #include #include -void id_print(struct passwd *, int, int); +void id_print(struct passwd *, int, int, int); void pline(struct passwd *); void pretty(struct passwd *); void group(struct passwd *, int); @@ -180,12 +180,12 @@ main(int argc, char *argv[]) } if (pw) { - id_print(pw, 0, 0); + id_print(pw, 1, 0, 0); } else { id = getuid(); if ((pw = getpwuid(id)) != NULL) - id_print(pw, 1, 1); + id_print(pw, 0, 1, 1); } exit(0); } @@ -231,7 +231,7 @@ pretty(struct passwd *pw) } void -id_print(struct passwd *pw, int p_euid, int p_egid) +id_print(struct passwd *pw, int use_ggl, int p_euid, int p_egid) { struct group *gr; gid_t gid, egid, lastgid; @@ -243,8 +243,13 @@ id_print(struct passwd *pw, int p_euid, int p_egid) uid = pw->pw_uid; gid = pw->pw_gid; - ngroups = NGROUPS + 1; - getgrouplist(pw->pw_name, gid, groups, &ngroups); + if (use_ggl) { + ngroups = NGROUPS + 1; + getgrouplist(pw->pw_name, gid, groups, &ngroups); + } + else { + ngroups = getgroups(NGROUPS + 1, groups); + } printf("uid=%u(%s)", uid, pw->pw_name); if (p_euid && (euid = geteuid()) != uid) {