diff options
author | Ivo van poorten <ivopvp@gmail.com> | 2013-05-14 00:03:26 -0500 |
---|---|---|
committer | Ivo van poorten <ivopvp@gmail.com> | 2013-05-14 00:03:26 -0500 |
commit | 38aa170897534e31afcb1e940b13d103e40cd1c4 (patch) | |
tree | 636c8f03e2d5d7981010a00518a3dc2e5e30d4a6 | |
parent | 970bf321a3ea466cc6113dc612002f019321fc9a (diff) | |
download | toybox-38aa170897534e31afcb1e940b13d103e40cd1c4.tar.gz |
add groups implementation to id.c
-rw-r--r-- | toys/posix/id.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/toys/posix/id.c b/toys/posix/id.c index 203ad218..48146600 100644 --- a/toys/posix/id.c +++ b/toys/posix/id.c @@ -7,6 +7,7 @@ * See http://opengroup.org/onlinepubs/9699919799/utilities/id.html USE_ID(NEWTOY(id, ">1nGgru[!Ggu]", TOYFLAG_BIN)) +USE_ID_GROUPS(OLDTOY(groups, id, NULL, TOYFLAG_USR|TOYFLAG_BIN)) config ID bool "id" @@ -21,6 +22,16 @@ config ID -g Show only the effective group ID -r Show real ID instead of effective ID -u Show only the effective user ID + +config ID_GROUPS + bool "groups" + default y + depends on ID + help + usage: groups [user] + + Print the groups a user is in. + */ #define FOR_id @@ -57,21 +68,28 @@ struct group *xgetgrgid(gid_t gid) void id_main(void) { - int flags = toys.optflags, i, ngroups; + int flags, i, ngroups, cmd_groups = toys.which->name[0] == 'g'; struct passwd *pw; struct group *grp; uid_t uid = getuid(), euid = geteuid(); gid_t gid = getgid(), egid = getegid(), *groups; + if (cmd_groups) + toys.optflags |= FLAG_G | FLAG_n; + + flags = toys.optflags; + // check if a username is given if (*toys.optargs) { if (!(pw = getpwnam(*toys.optargs))) error_exit("no such user '%s'", *toys.optargs); uid = euid = pw->pw_uid; gid = egid = pw->pw_gid; + if (cmd_groups) + printf("%s : ", pw->pw_name); } - i = toys.optflags & FLAG_r; + i = flags & FLAG_r; pw = xgetpwuid(i ? uid : euid); if (flags & FLAG_u) s_or_u(pw->pw_name, pw->pw_uid, 1); |