diff options
author | mpp <mpp@FreeBSD.org> | 2006-12-09 12:58:14 +0000 |
---|---|---|
committer | mpp <mpp@FreeBSD.org> | 2006-12-09 12:58:14 +0000 |
commit | f458d34cdf980a9ced5e6ff9f0dfaacba4ebce07 (patch) | |
tree | 4f73eaee3660e9409adcf12aa028475660faeb20 /usr.bin/id | |
parent | 70541a0d663b36e2bed79f69dabc21c4280ae06c (diff) | |
download | FreeBSD-src-f458d34cdf980a9ced5e6ff9f0dfaacba4ebce07.zip FreeBSD-src-f458d34cdf980a9ced5e6ff9f0dfaacba4ebce07.tar.gz |
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.
Diffstat (limited to 'usr.bin/id')
-rw-r--r-- | usr.bin/id/id.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/usr.bin/id/id.c b/usr.bin/id/id.c index 729e97e..8d1736d 100644 --- a/usr.bin/id/id.c +++ b/usr.bin/id/id.c @@ -205,8 +205,8 @@ main(int argc, char *argv[]) } else { id = getuid(); - if ((pw = getpwuid(id)) != NULL) - id_print(pw, 0, 1, 1); + 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; - uid = pw->pw_uid; - gid = pw->pw_gid; + 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); } - printf("uid=%u(%s)", uid, pw->pw_name); + 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); |