diff options
author | Robert Drehmel <robert@FreeBSD.org> | 2005-04-29 10:11:18 +0000 |
---|---|---|
committer | Robert Drehmel <robert@FreeBSD.org> | 2005-04-29 10:11:18 +0000 |
commit | 7f3135415255ae92a5dc6dc0f55f658b85adbcfa (patch) | |
tree | 7f43a298b6d42cf63a36eba8b8aecf7b78f97ffa /usr.bin | |
parent | 5b8e7b6b29faf7b09c90fbef5870af2e863556cf (diff) | |
download | src-7f3135415255ae92a5dc6dc0f55f658b85adbcfa.tar.gz src-7f3135415255ae92a5dc6dc0f55f658b85adbcfa.zip |
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).
Notes
Notes:
svn path=/head/; revision=145672
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/id/id.c | 17 |
1 files 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 <string.h> #include <unistd.h> -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) { |