Mercurial > hg > toybox
annotate toys/posix/id.c @ 1326:78a3eaf5555f draft
killall5 - kill all the processes not in its session.
author | Ashwini Sharma <ak.ashwini1981@gmail.com> |
---|---|
date | Thu, 29 May 2014 08:21:48 -0500 |
parents | 0f42d83199a9 |
children | 855728acd1ad |
rev | line source |
---|---|
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
1 /* id.c - print real and effective user and group IDs |
413 | 2 * |
3 * Copyright 2012 Sony Network Entertainment, Inc. | |
4 * | |
5 * by Tim Bird <tim.bird@am.sony.com> | |
6 * | |
656
6df4ccc0acbe
Regularize command headers, update links to standards documents.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
7 * See http://opengroup.org/onlinepubs/9699919799/utilities/id.html |
413 | 8 |
796
50052f1368b9
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.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
9 USE_ID(NEWTOY(id, ">1nGgru[!Ggu]", TOYFLAG_BIN)) |
899
7b2e8f9db29b
add groups implementation to id.c
Ivo van poorten <ivopvp@gmail.com>
parents:
796
diff
changeset
|
10 USE_ID_GROUPS(OLDTOY(groups, id, NULL, TOYFLAG_USR|TOYFLAG_BIN)) |
1315
0f42d83199a9
logname and whoami are the same as id -un, so merge them.
Isaac Dunham <ibid.ag@gmail.com>
parents:
1130
diff
changeset
|
11 USE_ID_LOGNAME(OLDTOY(logname, id, ">0", TOYFLAG_BIN)) |
0f42d83199a9
logname and whoami are the same as id -un, so merge them.
Isaac Dunham <ibid.ag@gmail.com>
parents:
1130
diff
changeset
|
12 USE_ID_LOGNAME(OLDTOY(whoami, id, ">0", TOYFLAG_BIN)) |
413 | 13 |
14 config ID | |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
15 bool "id" |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
16 default y |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
17 help |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
18 usage: id [-nGgru] |
413 | 19 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
20 Print user and group ID. |
413 | 21 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
22 -n print names instead of numeric IDs (to be used with -Ggu) |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
23 -G Show only the group IDs |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
24 -g Show only the effective group ID |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
25 -r Show real ID instead of effective ID |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
26 -u Show only the effective user ID |
899
7b2e8f9db29b
add groups implementation to id.c
Ivo van poorten <ivopvp@gmail.com>
parents:
796
diff
changeset
|
27 |
7b2e8f9db29b
add groups implementation to id.c
Ivo van poorten <ivopvp@gmail.com>
parents:
796
diff
changeset
|
28 config ID_GROUPS |
7b2e8f9db29b
add groups implementation to id.c
Ivo van poorten <ivopvp@gmail.com>
parents:
796
diff
changeset
|
29 bool "groups" |
7b2e8f9db29b
add groups implementation to id.c
Ivo van poorten <ivopvp@gmail.com>
parents:
796
diff
changeset
|
30 default y |
7b2e8f9db29b
add groups implementation to id.c
Ivo van poorten <ivopvp@gmail.com>
parents:
796
diff
changeset
|
31 depends on ID |
7b2e8f9db29b
add groups implementation to id.c
Ivo van poorten <ivopvp@gmail.com>
parents:
796
diff
changeset
|
32 help |
7b2e8f9db29b
add groups implementation to id.c
Ivo van poorten <ivopvp@gmail.com>
parents:
796
diff
changeset
|
33 usage: groups [user] |
7b2e8f9db29b
add groups implementation to id.c
Ivo van poorten <ivopvp@gmail.com>
parents:
796
diff
changeset
|
34 |
7b2e8f9db29b
add groups implementation to id.c
Ivo van poorten <ivopvp@gmail.com>
parents:
796
diff
changeset
|
35 Print the groups a user is in. |
7b2e8f9db29b
add groups implementation to id.c
Ivo van poorten <ivopvp@gmail.com>
parents:
796
diff
changeset
|
36 |
1315
0f42d83199a9
logname and whoami are the same as id -un, so merge them.
Isaac Dunham <ibid.ag@gmail.com>
parents:
1130
diff
changeset
|
37 config ID_LOGNAME |
0f42d83199a9
logname and whoami are the same as id -un, so merge them.
Isaac Dunham <ibid.ag@gmail.com>
parents:
1130
diff
changeset
|
38 bool "logname" |
0f42d83199a9
logname and whoami are the same as id -un, so merge them.
Isaac Dunham <ibid.ag@gmail.com>
parents:
1130
diff
changeset
|
39 default y |
0f42d83199a9
logname and whoami are the same as id -un, so merge them.
Isaac Dunham <ibid.ag@gmail.com>
parents:
1130
diff
changeset
|
40 depends on ID |
0f42d83199a9
logname and whoami are the same as id -un, so merge them.
Isaac Dunham <ibid.ag@gmail.com>
parents:
1130
diff
changeset
|
41 help |
0f42d83199a9
logname and whoami are the same as id -un, so merge them.
Isaac Dunham <ibid.ag@gmail.com>
parents:
1130
diff
changeset
|
42 usage: logname |
0f42d83199a9
logname and whoami are the same as id -un, so merge them.
Isaac Dunham <ibid.ag@gmail.com>
parents:
1130
diff
changeset
|
43 |
0f42d83199a9
logname and whoami are the same as id -un, so merge them.
Isaac Dunham <ibid.ag@gmail.com>
parents:
1130
diff
changeset
|
44 Print the current user name. |
0f42d83199a9
logname and whoami are the same as id -un, so merge them.
Isaac Dunham <ibid.ag@gmail.com>
parents:
1130
diff
changeset
|
45 |
413 | 46 */ |
47 | |
674
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
48 #define FOR_id |
413 | 49 #include "toys.h" |
50 | |
543
60b97ba66a70
Extensive semi-gratuitous refactoring: factor out common code, handle euid!=uid and egid!=gid cases. (Note: test suite requires root access, possibly container support.)
Rob Landley <rob@landley.net>
parents:
542
diff
changeset
|
51 static void s_or_u(char *s, unsigned u, int done) |
493
42a322adbd17
update id to be SUS compliant
Daniel Walter <d.walter@0x90.at>
parents:
430
diff
changeset
|
52 { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
53 if (toys.optflags & FLAG_n) printf("%s", s); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
54 else printf("%u", u); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
55 if (done) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
56 xputc('\n'); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
57 exit(0); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
58 } |
543
60b97ba66a70
Extensive semi-gratuitous refactoring: factor out common code, handle euid!=uid and egid!=gid cases. (Note: test suite requires root access, possibly container support.)
Rob Landley <rob@landley.net>
parents:
542
diff
changeset
|
59 } |
542
06763d1a2f9d
Tighten up the code a bit, and use actual process group id instead of what /etc/passwd says.
Rob Landley <rob@landley.net>
parents:
533
diff
changeset
|
60 |
543
60b97ba66a70
Extensive semi-gratuitous refactoring: factor out common code, handle euid!=uid and egid!=gid cases. (Note: test suite requires root access, possibly container support.)
Rob Landley <rob@landley.net>
parents:
542
diff
changeset
|
61 static void showid(char *header, unsigned u, char *s) |
60b97ba66a70
Extensive semi-gratuitous refactoring: factor out common code, handle euid!=uid and egid!=gid cases. (Note: test suite requires root access, possibly container support.)
Rob Landley <rob@landley.net>
parents:
542
diff
changeset
|
62 { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
63 printf("%s%u(%s)", header, u, s); |
543
60b97ba66a70
Extensive semi-gratuitous refactoring: factor out common code, handle euid!=uid and egid!=gid cases. (Note: test suite requires root access, possibly container support.)
Rob Landley <rob@landley.net>
parents:
542
diff
changeset
|
64 } |
60b97ba66a70
Extensive semi-gratuitous refactoring: factor out common code, handle euid!=uid and egid!=gid cases. (Note: test suite requires root access, possibly container support.)
Rob Landley <rob@landley.net>
parents:
542
diff
changeset
|
65 |
903
159b84d04b33
Make groups handle multiple usernames on command line.
Ivo van Poorten <ivopvp@gmail.com>
parents:
899
diff
changeset
|
66 void do_id(char *username) |
413 | 67 { |
899
7b2e8f9db29b
add groups implementation to id.c
Ivo van poorten <ivopvp@gmail.com>
parents:
796
diff
changeset
|
68 int flags, i, ngroups, cmd_groups = toys.which->name[0] == 'g'; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
69 struct passwd *pw; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
70 struct group *grp; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
71 uid_t uid = getuid(), euid = geteuid(); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
72 gid_t gid = getgid(), egid = getegid(), *groups; |
413 | 73 |
899
7b2e8f9db29b
add groups implementation to id.c
Ivo van poorten <ivopvp@gmail.com>
parents:
796
diff
changeset
|
74 if (cmd_groups) |
7b2e8f9db29b
add groups implementation to id.c
Ivo van poorten <ivopvp@gmail.com>
parents:
796
diff
changeset
|
75 toys.optflags |= FLAG_G | FLAG_n; |
7b2e8f9db29b
add groups implementation to id.c
Ivo van poorten <ivopvp@gmail.com>
parents:
796
diff
changeset
|
76 |
7b2e8f9db29b
add groups implementation to id.c
Ivo van poorten <ivopvp@gmail.com>
parents:
796
diff
changeset
|
77 flags = toys.optflags; |
7b2e8f9db29b
add groups implementation to id.c
Ivo van poorten <ivopvp@gmail.com>
parents:
796
diff
changeset
|
78 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
79 // check if a username is given |
903
159b84d04b33
Make groups handle multiple usernames on command line.
Ivo van Poorten <ivopvp@gmail.com>
parents:
899
diff
changeset
|
80 if (username) { |
1130
6df194c6de88
Add xgetpwnam() to lib/xwrap.c.
Rob Landley <rob@landley.net>
parents:
1129
diff
changeset
|
81 pw = xgetpwnam(username); |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
82 uid = euid = pw->pw_uid; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
83 gid = egid = pw->pw_gid; |
1130
6df194c6de88
Add xgetpwnam() to lib/xwrap.c.
Rob Landley <rob@landley.net>
parents:
1129
diff
changeset
|
84 if (cmd_groups) printf("%s : ", pw->pw_name); |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
85 } |
493
42a322adbd17
update id to be SUS compliant
Daniel Walter <d.walter@0x90.at>
parents:
430
diff
changeset
|
86 |
899
7b2e8f9db29b
add groups implementation to id.c
Ivo van poorten <ivopvp@gmail.com>
parents:
796
diff
changeset
|
87 i = flags & FLAG_r; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
88 pw = xgetpwuid(i ? uid : euid); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
89 if (flags & FLAG_u) s_or_u(pw->pw_name, pw->pw_uid, 1); |
543
60b97ba66a70
Extensive semi-gratuitous refactoring: factor out common code, handle euid!=uid and egid!=gid cases. (Note: test suite requires root access, possibly container support.)
Rob Landley <rob@landley.net>
parents:
542
diff
changeset
|
90 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
91 grp = xgetgrgid(i ? gid : egid); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
92 if (flags & FLAG_g) s_or_u(grp->gr_name, grp->gr_gid, 1); |
543
60b97ba66a70
Extensive semi-gratuitous refactoring: factor out common code, handle euid!=uid and egid!=gid cases. (Note: test suite requires root access, possibly container support.)
Rob Landley <rob@landley.net>
parents:
542
diff
changeset
|
93 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
94 if (!(flags & FLAG_G)) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
95 showid("uid=", pw->pw_uid, pw->pw_name); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
96 showid(" gid=", grp->gr_gid, grp->gr_name); |
543
60b97ba66a70
Extensive semi-gratuitous refactoring: factor out common code, handle euid!=uid and egid!=gid cases. (Note: test suite requires root access, possibly container support.)
Rob Landley <rob@landley.net>
parents:
542
diff
changeset
|
97 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
98 if (!i) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
99 if (uid != euid) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
100 pw = xgetpwuid(euid); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
101 showid(" euid=", pw->pw_uid, pw->pw_name); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
102 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
103 if (gid != egid) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
104 grp = xgetgrgid(egid); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
105 showid(" egid=", grp->gr_gid, grp->gr_name); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
106 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
107 } |
543
60b97ba66a70
Extensive semi-gratuitous refactoring: factor out common code, handle euid!=uid and egid!=gid cases. (Note: test suite requires root access, possibly container support.)
Rob Landley <rob@landley.net>
parents:
542
diff
changeset
|
108 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
109 showid(" groups=", grp->gr_gid, grp->gr_name); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
110 } |
543
60b97ba66a70
Extensive semi-gratuitous refactoring: factor out common code, handle euid!=uid and egid!=gid cases. (Note: test suite requires root access, possibly container support.)
Rob Landley <rob@landley.net>
parents:
542
diff
changeset
|
111 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
112 groups = (gid_t *)toybuf; |
796
50052f1368b9
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.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
113 i = sizeof(toybuf)/sizeof(gid_t); |
903
159b84d04b33
Make groups handle multiple usernames on command line.
Ivo van Poorten <ivopvp@gmail.com>
parents:
899
diff
changeset
|
114 ngroups = username ? getgrouplist(username, gid, groups, &i) |
159b84d04b33
Make groups handle multiple usernames on command line.
Ivo van Poorten <ivopvp@gmail.com>
parents:
899
diff
changeset
|
115 : getgroups(i, groups); |
796
50052f1368b9
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.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
116 if (0 >= ngroups) perror_exit(0); |
493
42a322adbd17
update id to be SUS compliant
Daniel Walter <d.walter@0x90.at>
parents:
430
diff
changeset
|
117 |
796
50052f1368b9
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.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
118 for (i = 0;;) { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
119 if (!(grp = getgrgid(groups[i]))) perror_msg(0); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
120 else if (flags & FLAG_G) s_or_u(grp->gr_name, grp->gr_gid, 0); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
121 else if (grp->gr_gid != egid) showid("", grp->gr_gid, grp->gr_name); |
796
50052f1368b9
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.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
122 if (++i >= ngroups) break; |
50052f1368b9
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.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
123 xputc(' '); |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
124 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
125 xputc('\n'); |
413 | 126 } |
903
159b84d04b33
Make groups handle multiple usernames on command line.
Ivo van Poorten <ivopvp@gmail.com>
parents:
899
diff
changeset
|
127 |
159b84d04b33
Make groups handle multiple usernames on command line.
Ivo van Poorten <ivopvp@gmail.com>
parents:
899
diff
changeset
|
128 void id_main(void) |
159b84d04b33
Make groups handle multiple usernames on command line.
Ivo van Poorten <ivopvp@gmail.com>
parents:
899
diff
changeset
|
129 { |
1315
0f42d83199a9
logname and whoami are the same as id -un, so merge them.
Isaac Dunham <ibid.ag@gmail.com>
parents:
1130
diff
changeset
|
130 if (toys.which->name[0] > 'i') toys.optflags = (FLAG_u | FLAG_n); |
903
159b84d04b33
Make groups handle multiple usernames on command line.
Ivo van Poorten <ivopvp@gmail.com>
parents:
899
diff
changeset
|
131 if (toys.optc) while(*toys.optargs) do_id(*toys.optargs++); |
159b84d04b33
Make groups handle multiple usernames on command line.
Ivo van Poorten <ivopvp@gmail.com>
parents:
899
diff
changeset
|
132 else do_id(NULL); |
159b84d04b33
Make groups handle multiple usernames on command line.
Ivo van Poorten <ivopvp@gmail.com>
parents:
899
diff
changeset
|
133 } |