diff options
author | robert <robert@FreeBSD.org> | 2005-04-29 10:11:18 +0000 |
---|---|---|
committer | robert <robert@FreeBSD.org> | 2005-04-29 10:11:18 +0000 |
commit | a07b9094ad893a73695ba55126bfa58cfa9ac113 (patch) | |
tree | 7f43a298b6d42cf63a36eba8b8aecf7b78f97ffa /usr.bin/id | |
parent | 1695f347828c8049132cd222fced75b38986d241 (diff) | |
download | FreeBSD-src-a07b9094ad893a73695ba55126bfa58cfa9ac113.zip FreeBSD-src-a07b9094ad893a73695ba55126bfa58cfa9ac113.tar.gz |
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).
Diffstat (limited to 'usr.bin/id')
-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 e546e8c..20a348e 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) { |