diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-11-01 11:11:40 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-11-01 11:11:40 -0400 |
commit | 3a1068cec448b98745ec3fef62e92f9efafb62f9 (patch) | |
tree | 3fae89d897fda1216d9a1f56ee588a7b5b27df65 | |
parent | c04b446449b687d960e72dda674db786c8893a51 (diff) |
use get_name() in print_groups() to get the user name
-rw-r--r-- | id.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -71,12 +71,11 @@ static void print_id(const char *prefix, const char *name, id_t id, enum display static void print_groups(uid_t uid, gid_t rgid, gid_t egid, enum display mode) { - struct passwd *pwd = getpwuid(uid); - if (pwd == NULL) { + char *name = get_name(USER, uid); + if (name == NULL) { return; } - struct group *grp = NULL; char *prefix = ""; if (mode == FULL) { prefix = " groups="; @@ -94,6 +93,7 @@ static void print_groups(uid_t uid, gid_t rgid, gid_t egid, enum display mode) print_id(prefix, get_name(GROUP, egid), egid, mode); } + struct group *grp = NULL; setgrent(); while ((grp = getgrent()) != NULL) { if (grp->gr_gid == rgid || grp->gr_gid == egid) { @@ -101,7 +101,7 @@ static void print_groups(uid_t uid, gid_t rgid, gid_t egid, enum display mode) } for (int i = 0; grp->gr_mem[i] != NULL; i++) { - if (!strcmp(pwd->pw_name, grp->gr_mem[i])) { + if (!strcmp(name, grp->gr_mem[i])) { print_id(prefix, grp->gr_name, grp->gr_gid, mode); } } |