diff options
author | Rob Landley <rob@landley.net> | 2013-01-31 04:05:02 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2013-01-31 04:05:02 -0600 |
commit | f5b50e96ef3065e189e07746870a38251f33cdc6 (patch) | |
tree | 7c01adaf9eddfc2411d17a3968c17615e2c8704c /toys/posix/id.c | |
parent | 9d6e08806fcb8db77339ccd0e7ac22b38f3dc92f (diff) | |
download | toybox-f5b50e96ef3065e189e07746870a38251f33cdc6.tar.gz |
id: make "id -Gn root" print root's groups instead of current user (and without leading space), enforce max 1 argument and at most one of Ggu.
Diffstat (limited to 'toys/posix/id.c')
-rw-r--r-- | toys/posix/id.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/toys/posix/id.c b/toys/posix/id.c index 0cdd2b0c..203ad218 100644 --- a/toys/posix/id.c +++ b/toys/posix/id.c @@ -6,7 +6,7 @@ * * See http://opengroup.org/onlinepubs/9699919799/utilities/id.html -USE_ID(NEWTOY(id, "nGgru", TOYFLAG_BIN)) +USE_ID(NEWTOY(id, ">1nGgru[!Ggu]", TOYFLAG_BIN)) config ID bool "id" @@ -97,14 +97,16 @@ void id_main(void) } groups = (gid_t *)toybuf; - if (0 >= (ngroups = getgroups(sizeof(toybuf)/sizeof(gid_t), groups))) - perror_exit(0); + i = sizeof(toybuf)/sizeof(gid_t); + ngroups = *toys.optargs ? getgrouplist(*toys.optargs, gid, groups, &i) : getgroups(i, groups); + if (0 >= ngroups) perror_exit(0); - for (i = 0; i < ngroups; i++) { - xputc(' '); + for (i = 0;;) { if (!(grp = getgrgid(groups[i]))) perror_msg(0); else if (flags & FLAG_G) s_or_u(grp->gr_name, grp->gr_gid, 0); else if (grp->gr_gid != egid) showid("", grp->gr_gid, grp->gr_name); + if (++i >= ngroups) break; + xputc(' '); } xputc('\n'); } |