aboutsummaryrefslogtreecommitdiff
path: root/coreutils/id.c
diff options
context:
space:
mode:
authorvodz <vodz@69ca8d6d-28ef-0310-b511-8ec308f3f277>2005-10-11 14:38:01 +0000
committervodz <vodz@69ca8d6d-28ef-0310-b511-8ec308f3f277>2005-10-11 14:38:01 +0000
commit7b5bcb9d3f7691ee325ad704d76590bb939c5020 (patch)
treedcf88d0a287b1f154984bfc0acb292631df2f1f3 /coreutils/id.c
parentb30a4590a2a185ed36221548661507f65345b0ac (diff)
downloadbusybox-w32-7b5bcb9d3f7691ee325ad704d76590bb939c5020.tar.gz
busybox-w32-7b5bcb9d3f7691ee325ad704d76590bb939c5020.tar.bz2
busybox-w32-7b5bcb9d3f7691ee325ad704d76590bb939c5020.zip
- use complementally '!' to '?' - 'ask' is best 'free' char for this.
- more long opt compatibility, can set flag for long opt struct now - more logic: check opt-depend requires and global requires, special for 'id' and 'start-stop-daemon' applets. git-svn-id: svn://busybox.net/trunk/busybox@11828 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'coreutils/id.c')
-rw-r--r--coreutils/id.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/coreutils/id.c b/coreutils/id.c
index 28050ddf2..14497b416 100644
--- a/coreutils/id.c
+++ b/coreutils/id.c
@@ -22,7 +22,7 @@
22 22
23/* BB_AUDIT SUSv3 _NOT_ compliant -- option -G is not currently supported. */ 23/* BB_AUDIT SUSv3 _NOT_ compliant -- option -G is not currently supported. */
24/* Hacked by Tito Ragusa (C) 2004 to handle usernames of whatever length and to 24/* Hacked by Tito Ragusa (C) 2004 to handle usernames of whatever length and to
25 * be more similar to GNU id. 25 * be more similar to GNU id.
26 */ 26 */
27 27
28#include "busybox.h" 28#include "busybox.h"
@@ -41,10 +41,10 @@
41#define JUST_GROUP 8 41#define JUST_GROUP 8
42 42
43static short printf_full(unsigned int id, const char *arg, const char prefix) 43static short printf_full(unsigned int id, const char *arg, const char prefix)
44{ 44{
45 const char *fmt = "%cid=%u"; 45 const char *fmt = "%cid=%u";
46 short status=EXIT_FAILURE; 46 short status=EXIT_FAILURE;
47 47
48 if(arg) { 48 if(arg) {
49 fmt = "%cid=%u(%s)"; 49 fmt = "%cid=%u(%s)";
50 status=EXIT_SUCCESS; 50 status=EXIT_SUCCESS;
@@ -61,15 +61,14 @@ extern int id_main(int argc, char **argv)
61 unsigned long flags; 61 unsigned long flags;
62 short status; 62 short status;
63 63
64 bb_opt_complementally = "!u~g:g~u"; 64 /* Don't allow -n -r -nr -ug -rug -nug -rnug */
65 bb_opt_complementally = "?u~g:g~u:r?ug:n?ug";
65 flags = bb_getopt_ulflags(argc, argv, "rnug"); 66 flags = bb_getopt_ulflags(argc, argv, "rnug");
66 67
67 /* Don't allow -n -r -nr */
68 if ((flags <= 3 && flags > 0)
69 /* Don't allow more than one username */ 68 /* Don't allow more than one username */
70 || (argc > optind + 1)) 69 if (argc > (optind + 1))
71 bb_show_usage(); 70 bb_show_usage();
72 71
73 /* This values could be overwritten later */ 72 /* This values could be overwritten later */
74 uid = geteuid(); 73 uid = geteuid();
75 gid = getegid(); 74 gid = getegid();
@@ -77,13 +76,13 @@ extern int id_main(int argc, char **argv)
77 uid = getuid(); 76 uid = getuid();
78 gid = getgid(); 77 gid = getgid();
79 } 78 }
80 79
81 if(argv[optind]) { 80 if(argv[optind]) {
82 p=getpwnam(argv[optind]); 81 p=getpwnam(argv[optind]);
83 /* bb_xgetpwnam is needed because it exits on failure */ 82 /* bb_xgetpwnam is needed because it exits on failure */
84 uid = bb_xgetpwnam(argv[optind]); 83 uid = bb_xgetpwnam(argv[optind]);
85 gid = p->pw_gid; 84 gid = p->pw_gid;
86 /* in this case PRINT_REAL is the same */ 85 /* in this case PRINT_REAL is the same */
87 } 86 }
88 87
89 if(flags & (JUST_GROUP | JUST_USER)) { 88 if(flags & (JUST_GROUP | JUST_USER)) {
@@ -94,7 +93,7 @@ extern int id_main(int argc, char **argv)
94 } else { 93 } else {
95 bb_printf("%u\n",(flags & JUST_USER) ? uid : gid); 94 bb_printf("%u\n",(flags & JUST_USER) ? uid : gid);
96 } 95 }
97 /* exit */ 96 /* exit */
98 bb_fflush_stdout_and_exit(EXIT_SUCCESS); 97 bb_fflush_stdout_and_exit(EXIT_SUCCESS);
99 } 98 }
100 99