Do not exit without printing the id information if the uid of the

user executing the command cannot be looked up in the password file.
This commit is contained in:
Mike Pritchard 2006-12-09 12:58:14 +00:00
parent 76cb7acf30
commit f2588359cb
1 changed files with 15 additions and 6 deletions

View File

@ -205,7 +205,7 @@ main(int argc, char *argv[])
}
else {
id = getuid();
if ((pw = getpwuid(id)) != NULL)
pw = getpwuid(id);
id_print(pw, 0, 1, 1);
}
exit(0);
@ -261,10 +261,16 @@ id_print(struct passwd *pw, int use_ggl, int p_euid, int p_egid)
gid_t groups[NGROUPS + 1];
const char *fmt;
if (pw != NULL) {
uid = pw->pw_uid;
gid = pw->pw_gid;
}
else {
uid = getuid();
gid = getgid();
}
if (use_ggl) {
if (use_ggl && pw != NULL) {
ngroups = NGROUPS + 1;
getgrouplist(pw->pw_name, gid, groups, &ngroups);
}
@ -272,7 +278,10 @@ id_print(struct passwd *pw, int use_ggl, int p_euid, int p_egid)
ngroups = getgroups(NGROUPS + 1, groups);
}
if (pw != NULL)
printf("uid=%u(%s)", uid, pw->pw_name);
else
printf("uid=%u", getuid());
printf(" gid=%u", gid);
if ((gr = getgrgid(gid)))
(void)printf("(%s)", gr->gr_name);