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).
This commit is contained in:
Robert Drehmel 2005-04-29 10:11:18 +00:00
parent 5b8e7b6b29
commit 7f31354152
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=145672

View File

@ -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) {