Mercurial > hg > toybox
annotate toys/id.c @ 430:74f152c5fa30
This id implementation is not remotely SUSv4 compliant, default n until I get a chance to finish it.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sun, 05 Feb 2012 15:25:17 -0600 |
parents | 12add511705e |
children | 42a322adbd17 |
rev | line source |
---|---|
413 | 1 /* vi: set sw=4 ts=4: |
2 * | |
3 * id.c - print real and effective user and group IDs | |
4 * | |
5 * Copyright 2012 Sony Network Entertainment, Inc. | |
6 * | |
7 * by Tim Bird <tim.bird@am.sony.com> | |
8 * | |
9 * See http://www.opengroup.org/onlinepubs/009695399/utilities/id.html | |
10 | |
11 USE_ID(NEWTOY(id, "gru", TOYFLAG_BIN)) | |
12 | |
13 config ID | |
14 bool "id" | |
430
74f152c5fa30
This id implementation is not remotely SUSv4 compliant, default n until I get a chance to finish it.
Rob Landley <rob@landley.net>
parents:
413
diff
changeset
|
15 default n |
413 | 16 help |
17 usage: id [-gru] | |
18 | |
19 Print user and group ID. | |
20 | |
21 -g Show only the effective group ID | |
22 -r Show real ID instead of effective ID | |
23 -u Show only the effective user ID | |
24 */ | |
25 | |
26 #include "toys.h" | |
27 | |
28 #define FLAG_g (1<<2) | |
29 #define FLAG_r (1<<1) | |
30 #define FLAG_u 1 | |
31 | |
32 void id_main(void) | |
33 { | |
34 int flags = toys.optflags; | |
35 | |
36 uid_t uid; | |
37 gid_t gid; | |
38 | |
39 /* show effective, unless user specifies real */ | |
40 uid = geteuid(); | |
41 gid = getegid(); | |
42 | |
43 if (flags & FLAG_r) { | |
44 uid = getuid(); | |
45 gid = getgid(); | |
46 } | |
47 if (flags & FLAG_u) { | |
48 printf("%d\n", uid); | |
49 return; | |
50 } | |
51 if (flags & FLAG_g) { | |
52 printf("%d\n", gid); | |
53 return; | |
54 } | |
55 printf("%d %d\n", uid, gid); | |
56 } |