aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-01-25 05:12:02 +0000
committerEric Andersen <andersen@codepoet.org>2001-01-25 05:12:02 +0000
commitc1b8f1224c8f1160155ff9294080a899364ad799 (patch)
tree092433d84f312e08b8eb118b26b4fd02558eeca4
parent155c89b0c3aa0e86c630bccc0af4143223b49121 (diff)
downloadbusybox-w32-c1b8f1224c8f1160155ff9294080a899364ad799.tar.gz
busybox-w32-c1b8f1224c8f1160155ff9294080a899364ad799.tar.bz2
busybox-w32-c1b8f1224c8f1160155ff9294080a899364ad799.zip
Apply a patch from Brent Priddy <brent.priddy@adtran.com> to add
'id -n' support. -Erik
-rw-r--r--applets/usage.c1
-rw-r--r--coreutils/id.c24
-rw-r--r--docs/busybox.pod3
-rw-r--r--docs/busybox.sgml1
-rw-r--r--id.c24
-rw-r--r--usage.c1
6 files changed, 41 insertions, 13 deletions
diff --git a/applets/usage.c b/applets/usage.c
index a9862fd3d..534958e7d 100644
--- a/applets/usage.c
+++ b/applets/usage.c
@@ -532,6 +532,7 @@ const char id_usage[] =
532 "Options:\n" 532 "Options:\n"
533 "\t-g\tprints only the group ID\n" 533 "\t-g\tprints only the group ID\n"
534 "\t-u\tprints only the user ID\n" 534 "\t-u\tprints only the user ID\n"
535 "\t-n\tprint a name instead of a number (with for -ug)\n"
535 "\t-r\tprints the real user ID instead of the effective ID (with -ug)" 536 "\t-r\tprints the real user ID instead of the effective ID (with -ug)"
536#endif 537#endif
537 ; 538 ;
diff --git a/coreutils/id.c b/coreutils/id.c
index 3a8e77a1f..59cfafa0a 100644
--- a/coreutils/id.c
+++ b/coreutils/id.c
@@ -31,6 +31,7 @@
31extern int id_main(int argc, char **argv) 31extern int id_main(int argc, char **argv)
32{ 32{
33 int no_user = 0, no_group = 0, print_real = 0; 33 int no_user = 0, no_group = 0, print_real = 0;
34 int name_not_number = 0;
34 char user[9], group[9]; 35 char user[9], group[9];
35 long gid; 36 long gid;
36 long pwnam, grnam; 37 long pwnam, grnam;
@@ -38,7 +39,7 @@ extern int id_main(int argc, char **argv)
38 39
39 gid = 0; 40 gid = 0;
40 41
41 while ((opt = getopt(argc, argv, "ugr")) > 0) { 42 while ((opt = getopt(argc, argv, "ugrn")) > 0) {
42 switch (opt) { 43 switch (opt) {
43 case 'u': 44 case 'u':
44 no_group++; 45 no_group++;
@@ -49,6 +50,9 @@ extern int id_main(int argc, char **argv)
49 case 'r': 50 case 'r':
50 print_real++; 51 print_real++;
51 break; 52 break;
53 case 'n':
54 name_not_number++;
55 break;
52 default: 56 default:
53 usage(id_usage); 57 usage(id_usage);
54 } 58 }
@@ -76,12 +80,20 @@ extern int id_main(int argc, char **argv)
76 if (gid == -1 || pwnam==-1 || grnam==-1) { 80 if (gid == -1 || pwnam==-1 || grnam==-1) {
77 error_msg_and_die("%s: No such user\n", user); 81 error_msg_and_die("%s: No such user\n", user);
78 } 82 }
79 if (no_group) 83
80 printf("%ld\n", pwnam); 84 if (no_group) {
81 else if (no_user) 85 if(name_not_number && user)
82 printf("%ld\n", grnam); 86 printf("%s\n",user);
83 else 87 else
88 printf("%ld\n", pwnam);
89 } else if (no_user) {
90 if(name_not_number && group)
91 printf("%s\n", group);
92 else
93 printf("%ld\n", grnam);
94 } else {
84 printf("uid=%ld(%s) gid=%ld(%s)\n", pwnam, user, grnam, group); 95 printf("uid=%ld(%s) gid=%ld(%s)\n", pwnam, user, grnam, group);
96 }
85 return(0); 97 return(0);
86} 98}
87 99
diff --git a/docs/busybox.pod b/docs/busybox.pod
index ba88bee0c..e3da284f1 100644
--- a/docs/busybox.pod
+++ b/docs/busybox.pod
@@ -871,6 +871,7 @@ Options:
871 871
872 -g prints only the group ID 872 -g prints only the group ID
873 -u prints only the user ID 873 -u prints only the user ID
874 -n print a name instead of a number (with for -ug)
874 -r prints the real user ID instead of the effective ID (with -ug) 875 -r prints the real user ID instead of the effective ID (with -ug)
875 876
876Example: 877Example:
@@ -2321,4 +2322,4 @@ Enrique Zanardi <ezanardi@ull.es>
2321 2322
2322=cut 2323=cut
2323 2324
2324# $Id: busybox.pod,v 1.87 2001/01/24 19:15:07 andersen Exp $ 2325# $Id: busybox.pod,v 1.88 2001/01/25 05:12:02 andersen Exp $
diff --git a/docs/busybox.sgml b/docs/busybox.sgml
index 8b77c5117..58d7df859 100644
--- a/docs/busybox.sgml
+++ b/docs/busybox.sgml
@@ -1474,6 +1474,7 @@
1474 <screen> 1474 <screen>
1475 -g Print only the group ID 1475 -g Print only the group ID
1476 -u Print only the user ID 1476 -u Print only the user ID
1477 -n print a name instead of a number (with for -ug)
1477 -r Print the real user ID instead of the effective ID (with -ug) 1478 -r Print the real user ID instead of the effective ID (with -ug)
1478 </screen> 1479 </screen>
1479 </para> 1480 </para>
diff --git a/id.c b/id.c
index 3a8e77a1f..59cfafa0a 100644
--- a/id.c
+++ b/id.c
@@ -31,6 +31,7 @@
31extern int id_main(int argc, char **argv) 31extern int id_main(int argc, char **argv)
32{ 32{
33 int no_user = 0, no_group = 0, print_real = 0; 33 int no_user = 0, no_group = 0, print_real = 0;
34 int name_not_number = 0;
34 char user[9], group[9]; 35 char user[9], group[9];
35 long gid; 36 long gid;
36 long pwnam, grnam; 37 long pwnam, grnam;
@@ -38,7 +39,7 @@ extern int id_main(int argc, char **argv)
38 39
39 gid = 0; 40 gid = 0;
40 41
41 while ((opt = getopt(argc, argv, "ugr")) > 0) { 42 while ((opt = getopt(argc, argv, "ugrn")) > 0) {
42 switch (opt) { 43 switch (opt) {
43 case 'u': 44 case 'u':
44 no_group++; 45 no_group++;
@@ -49,6 +50,9 @@ extern int id_main(int argc, char **argv)
49 case 'r': 50 case 'r':
50 print_real++; 51 print_real++;
51 break; 52 break;
53 case 'n':
54 name_not_number++;
55 break;
52 default: 56 default:
53 usage(id_usage); 57 usage(id_usage);
54 } 58 }
@@ -76,12 +80,20 @@ extern int id_main(int argc, char **argv)
76 if (gid == -1 || pwnam==-1 || grnam==-1) { 80 if (gid == -1 || pwnam==-1 || grnam==-1) {
77 error_msg_and_die("%s: No such user\n", user); 81 error_msg_and_die("%s: No such user\n", user);
78 } 82 }
79 if (no_group) 83
80 printf("%ld\n", pwnam); 84 if (no_group) {
81 else if (no_user) 85 if(name_not_number && user)
82 printf("%ld\n", grnam); 86 printf("%s\n",user);
83 else 87 else
88 printf("%ld\n", pwnam);
89 } else if (no_user) {
90 if(name_not_number && group)
91 printf("%s\n", group);
92 else
93 printf("%ld\n", grnam);
94 } else {
84 printf("uid=%ld(%s) gid=%ld(%s)\n", pwnam, user, grnam, group); 95 printf("uid=%ld(%s) gid=%ld(%s)\n", pwnam, user, grnam, group);
96 }
85 return(0); 97 return(0);
86} 98}
87 99
diff --git a/usage.c b/usage.c
index a9862fd3d..534958e7d 100644
--- a/usage.c
+++ b/usage.c
@@ -532,6 +532,7 @@ const char id_usage[] =
532 "Options:\n" 532 "Options:\n"
533 "\t-g\tprints only the group ID\n" 533 "\t-g\tprints only the group ID\n"
534 "\t-u\tprints only the user ID\n" 534 "\t-u\tprints only the user ID\n"
535 "\t-n\tprint a name instead of a number (with for -ug)\n"
535 "\t-r\tprints the real user ID instead of the effective ID (with -ug)" 536 "\t-r\tprints the real user ID instead of the effective ID (with -ug)"
536#endif 537#endif
537 ; 538 ;