diff options
author | Ivo van Poorten <ivopvp@gmail.com> | 2013-05-18 22:33:40 -0500 |
---|---|---|
committer | Ivo van Poorten <ivopvp@gmail.com> | 2013-05-18 22:33:40 -0500 |
commit | 1c1db048ad86067de70305a6e737802cf96ea302 (patch) | |
tree | 6c1e71bec419fe04eacdf82fe29df0b1221bf39f /toys | |
parent | 0ae71803f7ea7dc5c76ed3c330f5a4c3a5fe5f87 (diff) | |
download | toybox-1c1db048ad86067de70305a6e737802cf96ea302.tar.gz |
Make groups handle multiple usernames on command line.
Diffstat (limited to 'toys')
-rw-r--r-- | toys/posix/id.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/toys/posix/id.c b/toys/posix/id.c index 48146600..dbcf9a15 100644 --- a/toys/posix/id.c +++ b/toys/posix/id.c @@ -66,7 +66,7 @@ struct group *xgetgrgid(gid_t gid) return group; } -void id_main(void) +void do_id(char *username) { int flags, i, ngroups, cmd_groups = toys.which->name[0] == 'g'; struct passwd *pw; @@ -80,9 +80,9 @@ void id_main(void) 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); + if (username) { + if (!(pw = getpwnam(username))) + error_exit("no such user '%s'", username); uid = euid = pw->pw_uid; gid = egid = pw->pw_gid; if (cmd_groups) @@ -116,7 +116,8 @@ void id_main(void) groups = (gid_t *)toybuf; i = sizeof(toybuf)/sizeof(gid_t); - ngroups = *toys.optargs ? getgrouplist(*toys.optargs, gid, groups, &i) : getgroups(i, groups); + ngroups = username ? getgrouplist(username, gid, groups, &i) + : getgroups(i, groups); if (0 >= ngroups) perror_exit(0); for (i = 0;;) { @@ -128,3 +129,9 @@ void id_main(void) } xputc('\n'); } + +void id_main(void) +{ + if (toys.optc) while(*toys.optargs) do_id(*toys.optargs++); + else do_id(NULL); +} |