1 Index: coreutils/Config.in
2 ===================================================================
3 RCS file: /var/cvs/busybox/coreutils/Config.in,v
4 retrieving revision 1.24
5 diff -u -r1.24 Config.in
6 --- a/coreutils/Config.in 15 Mar 2004 08:28:19 -0000 1.24
7 +++ b/coreutils/Config.in 1 May 2004 11:39:04 -0000
10 id displays the current user and group ID names.
12 +config CONFIG_FEATURE_ID_GROUPS_ALIAS
13 + bool " Support 'groups' as alias to 'id -Gn'"
15 + depends on CONFIG_ID
17 + Print the groups a user is in. This is an alias to 'id -Gn' on
24 ===================================================================
25 RCS file: /var/cvs/busybox/coreutils/id.c,v
26 retrieving revision 1.24
28 --- a/coreutils/id.c 15 Mar 2004 08:28:20 -0000 1.24
29 +++ b/coreutils/id.c 1 May 2004 11:39:05 -0000
31 * Mini id implementation for busybox
33 * Copyright (C) 2000 by Randolph Chung <tausq@debian.org>
34 + * Copyright (C) 2004 by Tony J. White <tjw@tjw.org>
35 + * Copyright (C) 2004 by Glenn McGrath <bug1@iinet.net.au>
37 * This program is free software; you can redistribute it and/or modify
38 * it under the terms of the GNU General Public License as published by
43 -/* BB_AUDIT SUSv3 _NOT_ compliant -- option -G is not currently supported. */
48 #include <flask_util.h>
54 -#define NAME_NOT_NUMBER 8
55 +#define ID_OPT_JUST_USER 1
56 +#define ID_OPT_JUST_GROUP 2
57 +#define ID_OPT_ALL_GROUPS 4
58 +#define ID_OPT_PRINT_REAL 8
59 +#define ID_OPT_NAME_NOT_NUMBER 16
61 +static void print_groups(unsigned long flags, const char sep)
67 + gid_count = getgroups(64, gids);
69 + for (i = 0; i < gid_count; i++) {
70 + struct group *tmp_grp;
75 + tmp_grp = getgrgid(gids[i]);
76 + if (flags & ID_OPT_NAME_NOT_NUMBER) {
77 + if (tmp_grp == NULL) {
80 + printf("%s", tmp_grp->gr_name);
82 + printf("%u", gids[i]);
83 + if (!(flags & ID_OPT_ALL_GROUPS)) {
84 + if (tmp_grp == NULL) {
87 + printf("(%s)", tmp_grp->gr_name);
93 extern int id_main(int argc, char **argv)
95 - char user[9], group[9];
100 + struct passwd *usr;
101 + unsigned long flags;
106 #ifdef CONFIG_SELINUX
107 int is_flask_enabled_flag = is_flask_enabled();
110 - flags = bb_getopt_ulflags(argc, argv, "ugrn");
111 + bb_opt_complementaly = "u~gG:g~uG:G~ug:~n";
112 + flags = bb_getopt_ulflags(argc, argv, "ugGrn");
114 - if (((flags & (JUST_USER | JUST_GROUP)) == (JUST_USER | JUST_GROUP))
115 - || (argc > optind + 1)
117 + /* Check one and only one context option was given */
118 + if ((flags & 0x80000000UL) ||
119 + (flags & (ID_OPT_PRINT_REAL | ID_OPT_ALL_GROUPS)) ||
120 + ((flags & (ID_OPT_PRINT_REAL | ID_OPT_NAME_NOT_NUMBER)) ==
121 + (ID_OPT_PRINT_REAL | ID_OPT_NAME_NOT_NUMBER))) {
125 +#ifdef CONFIG_FEATURE_ID_GROUPS_ALIAS
126 + /* groups command is an alias for 'id -Gn' */
127 + if (bb_applet_name[0] == 'g') {
128 + flags |= (ID_OPT_ALL_GROUPS + ID_OPT_NAME_NOT_NUMBER);
137 + if (flags & ID_OPT_PRINT_REAL) {
142 if (argv[optind] == NULL) {
143 - if (flags & PRINT_REAL) {
150 - my_getpwuid(user, uid);
151 + usr = getpwuid(euid);
152 + grp = getgrgid(egid);
154 - safe_strncpy(user, argv[optind], sizeof(user));
155 - gid = my_getpwnamegid(user);
156 + usr = getpwnam(argv[optind]);
157 + grp = getgrnam(argv[optind]);
159 - my_getgrgid(group, gid);
161 - pwnam=my_getpwnam(user);
162 - grnam=my_getgrnam(group);
164 + bb_perror_msg_and_die("cannot find user name");
167 + bb_perror_msg_and_die("cannot find group name");
170 - if (flags & (JUST_GROUP | JUST_USER)) {
172 - if (flags & JUST_USER) {
175 + if (flags & ID_OPT_JUST_USER) {
176 + if (flags & ID_OPT_NAME_NOT_NUMBER) {
177 + printf("%s", grp->gr_name);
179 + printf("%u", euid);
181 - if (flags & NAME_NOT_NUMBER) {
184 + else if (flags & ID_OPT_JUST_GROUP) {
185 + if (flags & ID_OPT_NAME_NOT_NUMBER) {
186 + printf("%s", grp->gr_name);
188 - printf("%ld\n", grnam);
189 + printf("%u", egid);
192 + else if (flags & ID_OPT_ALL_GROUPS) {
193 + print_groups(flags, ' ');
195 -#ifdef CONFIG_SELINUX
196 - printf("uid=%ld(%s) gid=%ld(%s)", pwnam, user, grnam, group);
197 - if(is_flask_enabled_flag)
199 - security_id_t mysid = getsecsid();
201 - int len = sizeof(context);
203 - if(security_sid_to_context(mysid, context, &len))
204 - strcpy(context, "unknown");
205 - printf(" context=%s\n", context);
210 - printf("uid=%ld(%s) gid=%ld(%s)\n", pwnam, user, grnam, group);
212 + printf("uid=%u(%s) gid=%u(%s)", uid, usr->pw_name, gid, grp->gr_name);
214 + struct passwd *eusr;
215 + printf(" euid=%u", euid);
216 + eusr = getpwuid(euid);
217 + if (eusr != NULL) {
218 + printf("(%s)", eusr->pw_name);
222 + struct group *egrp;
223 + printf(" egid=%u", egid);
224 + egrp = getgrgid(egid);
225 + if (egrp != NULL) {
226 + printf("(%s)", egrp->gr_name);
229 + printf(" groups=");
230 + print_groups(flags, ',');
233 +#ifdef CONFIG_SELINUX
234 + if (is_flask_enabled_flag)
236 + security_id_t mysid = getsecsid();
238 + int len = sizeof(context);
241 + if (security_sid_to_context(mysid, len, &len)) {
242 + strcpy(context, "unknown");
244 + printf(" context=%s", context);
249 bb_fflush_stdout_and_exit(0);
251 Index: include/applets.h
252 ===================================================================
253 RCS file: /var/cvs/busybox/include/applets.h,v
254 retrieving revision 1.113
255 diff -u -r1.113 applets.h
256 --- a/include/applets.h 6 Apr 2004 16:59:43 -0000 1.113
257 +++ b/include/applets.h 1 May 2004 11:39:06 -0000
260 APPLET(grep, grep_main, _BB_DIR_BIN, _BB_SUID_NEVER)
262 +#if defined(CONFIG_FEATURE_ID_GROUPS_ALIAS)
263 + APPLET(groups, id_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
266 APPLET(gunzip, gunzip_main, _BB_DIR_BIN, _BB_SUID_NEVER)
268 Index: include/usage.h
269 ===================================================================
270 RCS file: /var/cvs/busybox/include/usage.h,v
271 retrieving revision 1.207
272 diff -u -r1.207 usage.h
273 --- a/include/usage.h 14 Apr 2004 17:59:21 -0000 1.207
274 +++ b/include/usage.h 1 May 2004 11:39:10 -0000
276 "$ grep ^[rR]oo. /etc/passwd\n" \
277 "root:x:0:0:root:/root:/bin/bash\n"
279 +#define groups_trivial_usage \
281 +#define groups_full_usage \
282 + "Print all group names that USERNAME is a member of."
283 +#define groups_example_usage \
285 + "andersen users\n" \
289 #define gunzip_trivial_usage \
291 #define gunzip_full_usage \
292 @@ -1035,7 +1045,7 @@
295 #define id_trivial_usage \
296 - "[OPTIONS]... [USERNAME]"
297 + "[-Ggu[nr]]] [USERNAME]"
298 #define id_full_usage \
299 "Print information for USERNAME or the current user\n\n" \
301 @@ -1043,10 +1053,11 @@
302 "\t-g\tprints only the group ID\n" \
303 "\t-u\tprints only the user ID\n" \
304 "\t-n\tprint a name instead of a number\n" \
305 - "\t-r\tprints the real user ID instead of the effective ID"
306 + "\t-r\tprints the real user ID instead of the effective ID\n" \
307 + "\t-G\tprints all groups the user belongs to"
308 #define id_example_usage \
310 - "uid=1000(andersen) gid=1000(andersen)\n"
311 + "uid=1000(andersen) gid=1000(andersen) groups=1000(andersen),100(users)\n"
313 #ifdef CONFIG_FEATURE_IFCONFIG_SLIP
314 #define USAGE_SIOCSKEEPALIVE(a) a