diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-06-20 09:01:58 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-06-20 09:01:58 +0000 |
commit | 8876fb2f59a0b515b3121d5894933eef88ce566a (patch) | |
tree | f67de9320202043aca8ded20fb80d668c3b0c2d8 /loginutils/adduser.c | |
parent | dfce3536ace2bcd38bdd3731841998ce344d786e (diff) | |
download | busybox-w32-8876fb2f59a0b515b3121d5894933eef88ce566a.tar.gz busybox-w32-8876fb2f59a0b515b3121d5894933eef88ce566a.tar.bz2 busybox-w32-8876fb2f59a0b515b3121d5894933eef88ce566a.zip |
last_patch89 from vodz:
Manuel,
I rewrite bb_getopt_ulflags() function for more universal usage.
My version support now:
- options with arguments (optional arg as GNU extension also)
- complementaly and/or incomplementaly and/or incongruously and/or list
options
- long_opt (all applets may have long option, add supporting is trivial)
This realisation full compatibile from your version.
Code size grow 480 bytes, but only coreutils/* over compensate this size
after using new function. Last patch reduced over 800 bytes and not full
applied to all. "mkdir" and "mv" applets have long_opt now for demonstrate
trivial addition support long_opt with usage new bb_getopt_ulflags().
Complementaly and/or incomplementaly and/or incongruously and/or list options
logic is not trivial, but new "cut" and "grep" applets using this logic
for examples with full demostrating. New "grep" applet reduced over 300
bytes.
Mark,
Also. I removed bug from "grep" applet.
$ echo a b | busybox grep -e a b
a b
a b
But right is printing one only.
--w
vodz
Diffstat (limited to 'loginutils/adduser.c')
-rw-r--r-- | loginutils/adduser.c | 40 |
1 files changed, 12 insertions, 28 deletions
diff --git a/loginutils/adduser.c b/loginutils/adduser.c index cfaf860e0..6784d32cc 100644 --- a/loginutils/adduser.c +++ b/loginutils/adduser.c | |||
@@ -208,9 +208,15 @@ static int adduser(const char *filename, struct passwd *p) | |||
208 | 208 | ||
209 | 209 | ||
210 | /* return current uid (root is always uid == 0, right?) */ | 210 | /* return current uid (root is always uid == 0, right?) */ |
211 | static inline uid_t i_am_not_root(void) | 211 | #ifndef CONFIG_ADDGROUP |
212 | static inline void if_i_am_not_root(void) | ||
213 | #else | ||
214 | void if_i_am_not_root(void) | ||
215 | #endif | ||
212 | { | 216 | { |
213 | return geteuid(); | 217 | if (geteuid()) { |
218 | bb_error_msg_and_die( "Only root may add a user or group to the system."); | ||
219 | } | ||
214 | } | 220 | } |
215 | 221 | ||
216 | /* | 222 | /* |
@@ -224,11 +230,10 @@ static inline uid_t i_am_not_root(void) | |||
224 | * ________________________________________________________________________ */ | 230 | * ________________________________________________________________________ */ |
225 | int adduser_main(int argc, char **argv) | 231 | int adduser_main(int argc, char **argv) |
226 | { | 232 | { |
227 | int opt; | ||
228 | const char *login; | 233 | const char *login; |
229 | const char *gecos; | 234 | const char *gecos = default_gecos; |
230 | const char *home = NULL; | 235 | const char *home = NULL; |
231 | const char *shell; | 236 | const char *shell = default_shell; |
232 | 237 | ||
233 | struct passwd pw; | 238 | struct passwd pw; |
234 | 239 | ||
@@ -236,30 +241,11 @@ int adduser_main(int argc, char **argv) | |||
236 | if (argc < 2) { | 241 | if (argc < 2) { |
237 | bb_show_usage(); | 242 | bb_show_usage(); |
238 | } | 243 | } |
239 | gecos = default_gecos; | ||
240 | shell = default_shell; | ||
241 | |||
242 | /* get args */ | 244 | /* get args */ |
243 | while ((opt = getopt (argc, argv, "h:g:s:")) != -1) | 245 | bb_getopt_ulflags(argc, argv, "h:g:s:", &home, &gecos, &shell); |
244 | switch (opt) { | ||
245 | case 'h': | ||
246 | home = optarg; | ||
247 | break; | ||
248 | case 'g': | ||
249 | gecos = optarg; | ||
250 | break; | ||
251 | case 's': | ||
252 | shell = optarg; | ||
253 | break; | ||
254 | default: | ||
255 | bb_show_usage(); | ||
256 | break; | ||
257 | } | ||
258 | 246 | ||
259 | /* got root? */ | 247 | /* got root? */ |
260 | if (i_am_not_root()) { | 248 | if_i_am_not_root(); |
261 | bb_error_msg_and_die( "Only root may add a user or group to the system."); | ||
262 | } | ||
263 | 249 | ||
264 | /* get login */ | 250 | /* get login */ |
265 | if (optind >= argc) { | 251 | if (optind >= argc) { |
@@ -288,5 +274,3 @@ int adduser_main(int argc, char **argv) | |||
288 | /* grand finale */ | 274 | /* grand finale */ |
289 | return adduser(bb_path_passwd_file, &pw); | 275 | return adduser(bb_path_passwd_file, &pw); |
290 | } | 276 | } |
291 | |||
292 | /* $Id: adduser.c,v 1.5 2003/03/19 09:12:20 mjn3 Exp $ */ | ||