diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-20 00:48:22 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-20 00:48:22 +0000 |
commit | 4a5cf16a368bf513a2c2e3b27821a37d3df3cf89 (patch) | |
tree | 18b0ca034b8b5424e51d6f1684f2805d5041aad4 | |
parent | 6a353c81587e3050b7e48fe522b517de9b29e2f3 (diff) | |
download | busybox-w32-4a5cf16a368bf513a2c2e3b27821a37d3df3cf89.tar.gz busybox-w32-4a5cf16a368bf513a2c2e3b27821a37d3df3cf89.tar.bz2 busybox-w32-4a5cf16a368bf513a2c2e3b27821a37d3df3cf89.zip |
login: use %s - we know that string is not too long there
ping[6]: use getopt32: smaller (-50 bytes) and handles -c6 correctly
(was requiring '-c 6' with mandatory space)
-rw-r--r-- | loginutils/login.c | 6 | ||||
-rw-r--r-- | networking/ping.c | 85 | ||||
-rw-r--r-- | networking/ping6.c | 92 |
3 files changed, 68 insertions, 115 deletions
diff --git a/loginutils/login.c b/loginutils/login.c index 263a5a0a5..bd3c112b9 100644 --- a/loginutils/login.c +++ b/loginutils/login.c | |||
@@ -323,16 +323,16 @@ auth_failed: | |||
323 | username); | 323 | username); |
324 | } | 324 | } |
325 | if (getfilecon(full_tty, &old_tty_sid) < 0) { | 325 | if (getfilecon(full_tty, &old_tty_sid) < 0) { |
326 | bb_perror_msg_and_die("getfilecon(%.100s) failed", | 326 | bb_perror_msg_and_die("getfilecon(%s) failed", |
327 | full_tty); | 327 | full_tty); |
328 | } | 328 | } |
329 | if (security_compute_relabel(user_sid, old_tty_sid, | 329 | if (security_compute_relabel(user_sid, old_tty_sid, |
330 | SECCLASS_CHR_FILE, &new_tty_sid) != 0) { | 330 | SECCLASS_CHR_FILE, &new_tty_sid) != 0) { |
331 | bb_perror_msg_and_die("security_change_sid(%.100s) failed", | 331 | bb_perror_msg_and_die("security_change_sid(%s) failed", |
332 | full_tty); | 332 | full_tty); |
333 | } | 333 | } |
334 | if (setfilecon(full_tty, new_tty_sid) != 0) { | 334 | if (setfilecon(full_tty, new_tty_sid) != 0) { |
335 | bb_perror_msg_and_die("chsid(%.100s, %s) failed", | 335 | bb_perror_msg_and_die("chsid(%s, %s) failed", |
336 | full_tty, new_tty_sid); | 336 | full_tty, new_tty_sid); |
337 | } | 337 | } |
338 | } | 338 | } |
diff --git a/networking/ping.c b/networking/ping.c index 782b801c8..400d565d9 100644 --- a/networking/ping.c +++ b/networking/ping.c | |||
@@ -41,17 +41,10 @@ enum { | |||
41 | PINGINTERVAL = 1 /* second */ | 41 | PINGINTERVAL = 1 /* second */ |
42 | }; | 42 | }; |
43 | 43 | ||
44 | #define O_QUIET (1 << 0) | ||
45 | |||
46 | #define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */ | ||
47 | #define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */ | ||
48 | #define SET(bit) (A(bit) |= B(bit)) | ||
49 | #define CLR(bit) (A(bit) &= (~B(bit))) | ||
50 | #define TST(bit) (A(bit) & B(bit)) | ||
51 | |||
52 | static void ping(const char *host); | 44 | static void ping(const char *host); |
53 | 45 | ||
54 | /* common routines */ | 46 | /* common routines */ |
47 | |||
55 | static int in_cksum(unsigned short *buf, int sz) | 48 | static int in_cksum(unsigned short *buf, int sz) |
56 | { | 49 | { |
57 | int nleft = sz; | 50 | int nleft = sz; |
@@ -75,8 +68,10 @@ static int in_cksum(unsigned short *buf, int sz) | |||
75 | return (ans); | 68 | return (ans); |
76 | } | 69 | } |
77 | 70 | ||
78 | /* simple version */ | ||
79 | #ifndef CONFIG_FEATURE_FANCY_PING | 71 | #ifndef CONFIG_FEATURE_FANCY_PING |
72 | |||
73 | /* simple version */ | ||
74 | |||
80 | static char *hostname; | 75 | static char *hostname; |
81 | 76 | ||
82 | static void noresp(int ign) | 77 | static void noresp(int ign) |
@@ -153,14 +148,21 @@ int ping_main(int argc, char **argv) | |||
153 | } | 148 | } |
154 | 149 | ||
155 | #else /* ! CONFIG_FEATURE_FANCY_PING */ | 150 | #else /* ! CONFIG_FEATURE_FANCY_PING */ |
151 | |||
156 | /* full(er) version */ | 152 | /* full(er) version */ |
153 | |||
154 | #define OPT_STRING "qc:s:I:" | ||
155 | enum { | ||
156 | OPT_QUIET = 1 << 0, | ||
157 | }; | ||
158 | |||
157 | static struct sockaddr_in pingaddr; | 159 | static struct sockaddr_in pingaddr; |
158 | static struct sockaddr_in sourceaddr; | 160 | static struct sockaddr_in sourceaddr; |
159 | static int pingsock = -1; | 161 | static int pingsock = -1; |
160 | static unsigned datalen; /* intentionally uninitialized to work around gcc bug */ | 162 | static unsigned datalen; /* intentionally uninitialized to work around gcc bug */ |
161 | 163 | ||
162 | static unsigned long ntransmitted, nreceived, nrepeats, pingcount; | 164 | static unsigned long ntransmitted, nreceived, nrepeats, pingcount; |
163 | static int myid, options; | 165 | static int myid; |
164 | static unsigned long tmin = ULONG_MAX, tmax, tsum; | 166 | static unsigned long tmin = ULONG_MAX, tmax, tsum; |
165 | static char rcvd_tbl[MAX_DUP_CHK / 8]; | 167 | static char rcvd_tbl[MAX_DUP_CHK / 8]; |
166 | 168 | ||
@@ -170,6 +172,12 @@ static void sendping(int); | |||
170 | static void pingstats(int); | 172 | static void pingstats(int); |
171 | static void unpack(char *, int, struct sockaddr_in *); | 173 | static void unpack(char *, int, struct sockaddr_in *); |
172 | 174 | ||
175 | #define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */ | ||
176 | #define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */ | ||
177 | #define SET(bit) (A(bit) |= B(bit)) | ||
178 | #define CLR(bit) (A(bit) &= (~B(bit))) | ||
179 | #define TST(bit) (A(bit) & B(bit)) | ||
180 | |||
173 | /**************************************************************************/ | 181 | /**************************************************************************/ |
174 | 182 | ||
175 | static void pingstats(int junk) | 183 | static void pingstats(int junk) |
@@ -304,7 +312,7 @@ static void unpack(char *buf, int sz, struct sockaddr_in *from) | |||
304 | dupflag = 0; | 312 | dupflag = 0; |
305 | } | 313 | } |
306 | 314 | ||
307 | if (options & O_QUIET) | 315 | if (option_mask32 & OPT_QUIET) |
308 | return; | 316 | return; |
309 | 317 | ||
310 | printf("%d bytes from %s: icmp_seq=%u", sz, | 318 | printf("%d bytes from %s: icmp_seq=%u", sz, |
@@ -409,55 +417,26 @@ static int parse_nipquad(const char *str, struct sockaddr_in* addr) | |||
409 | 417 | ||
410 | int ping_main(int argc, char **argv) | 418 | int ping_main(int argc, char **argv) |
411 | { | 419 | { |
412 | char *thisarg; | 420 | char *opt_c, *opt_s, *opt_I; |
413 | 421 | ||
414 | datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */ | 422 | datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */ |
415 | 423 | ||
416 | argc--; | 424 | /* exactly one argument needed */ |
417 | argv++; | 425 | opt_complementary = "=1"; |
418 | /* Parse any options */ | 426 | getopt32(argc, argv, OPT_STRING, &opt_c, &opt_s, &opt_I); |
419 | while (argc >= 1 && **argv == '-') { | 427 | if (option_mask32 & 2) pingcount = xatoul(opt_c); // -c |
420 | thisarg = *argv; | 428 | if (option_mask32 & 4) datalen = xatou16(opt_s); // -s |
421 | thisarg++; | 429 | if (option_mask32 & 8) { // -I |
422 | switch (*thisarg) { | 430 | /* TODO: ping6 accepts iface too: |
423 | case 'q': | 431 | if_index = if_nametoindex(*argv); |
424 | options |= O_QUIET; | 432 | if (!if_index) ... |
425 | break; | 433 | make it true for ping. */ |
426 | case 'c': | 434 | if (parse_nipquad(opt_I, &sourceaddr)) |
427 | if (--argc <= 0) | ||
428 | bb_show_usage(); | ||
429 | argv++; | ||
430 | pingcount = xatoul(*argv); | ||
431 | break; | ||
432 | case 's': | ||
433 | if (--argc <= 0) | ||
434 | bb_show_usage(); | ||
435 | argv++; | ||
436 | datalen = xatou16(*argv); | ||
437 | break; | ||
438 | case 'I': | ||
439 | if (--argc <= 0) | ||
440 | bb_show_usage(); | ||
441 | argv++; | ||
442 | /* ping6 accepts iface too: | ||
443 | if_index = if_nametoindex(*argv); | ||
444 | if (!if_index) ... | ||
445 | make it true for ping too. TODO. | ||
446 | */ | ||
447 | if (parse_nipquad(*argv, &sourceaddr)) | ||
448 | bb_show_usage(); | ||
449 | break; | ||
450 | default: | ||
451 | bb_show_usage(); | 435 | bb_show_usage(); |
452 | } | ||
453 | argc--; | ||
454 | argv++; | ||
455 | } | 436 | } |
456 | if (argc < 1) | ||
457 | bb_show_usage(); | ||
458 | 437 | ||
459 | myid = (int16_t) getpid(); | 438 | myid = (int16_t) getpid(); |
460 | ping(*argv); | 439 | ping(argv[optind]); |
461 | return EXIT_SUCCESS; | 440 | return EXIT_SUCCESS; |
462 | } | 441 | } |
463 | #endif /* ! CONFIG_FEATURE_FANCY_PING */ | 442 | #endif /* ! CONFIG_FEATURE_FANCY_PING */ |
diff --git a/networking/ping6.c b/networking/ping6.c index af9c00e22..6ab9ce0f1 100644 --- a/networking/ping6.c +++ b/networking/ping6.c | |||
@@ -53,19 +53,12 @@ enum { | |||
53 | PINGINTERVAL = 1 /* second */ | 53 | PINGINTERVAL = 1 /* second */ |
54 | }; | 54 | }; |
55 | 55 | ||
56 | #define O_QUIET (1 << 0) | ||
57 | #define O_VERBOSE (1 << 1) | ||
58 | |||
59 | #define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */ | ||
60 | #define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */ | ||
61 | #define SET(bit) (A(bit) |= B(bit)) | ||
62 | #define CLR(bit) (A(bit) &= (~B(bit))) | ||
63 | #define TST(bit) (A(bit) & B(bit)) | ||
64 | |||
65 | static void ping(const char *host); | 56 | static void ping(const char *host); |
66 | 57 | ||
67 | /* simple version */ | ||
68 | #ifndef CONFIG_FEATURE_FANCY_PING6 | 58 | #ifndef CONFIG_FEATURE_FANCY_PING6 |
59 | |||
60 | /* simple version */ | ||
61 | |||
69 | static struct hostent *h; | 62 | static struct hostent *h; |
70 | 63 | ||
71 | static void noresp(int ign) | 64 | static void noresp(int ign) |
@@ -142,14 +135,22 @@ int ping6_main(int argc, char **argv) | |||
142 | } | 135 | } |
143 | 136 | ||
144 | #else /* ! CONFIG_FEATURE_FANCY_PING6 */ | 137 | #else /* ! CONFIG_FEATURE_FANCY_PING6 */ |
138 | |||
145 | /* full(er) version */ | 139 | /* full(er) version */ |
140 | |||
141 | #define OPT_STRING "qvc:s:I:" | ||
142 | enum { | ||
143 | OPT_QUIET = 1 << 0, | ||
144 | OPT_VERBOSE = 1 << 1, | ||
145 | }; | ||
146 | |||
146 | static struct sockaddr_in6 pingaddr; | 147 | static struct sockaddr_in6 pingaddr; |
147 | static int pingsock = -1; | 148 | static int pingsock = -1; |
148 | static unsigned datalen; /* intentionally uninitialized to work around gcc bug */ | 149 | static unsigned datalen; /* intentionally uninitialized to work around gcc bug */ |
149 | static int if_index; | 150 | static int if_index; |
150 | 151 | ||
151 | static unsigned long ntransmitted, nreceived, nrepeats, pingcount; | 152 | static unsigned long ntransmitted, nreceived, nrepeats, pingcount; |
152 | static int myid, options; | 153 | static int myid; |
153 | static unsigned long tmin = ULONG_MAX, tmax, tsum; | 154 | static unsigned long tmin = ULONG_MAX, tmax, tsum; |
154 | static char rcvd_tbl[MAX_DUP_CHK / 8]; | 155 | static char rcvd_tbl[MAX_DUP_CHK / 8]; |
155 | 156 | ||
@@ -159,6 +160,12 @@ static void sendping(int); | |||
159 | static void pingstats(int); | 160 | static void pingstats(int); |
160 | static void unpack(char *, int, struct sockaddr_in6 *, int); | 161 | static void unpack(char *, int, struct sockaddr_in6 *, int); |
161 | 162 | ||
163 | #define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */ | ||
164 | #define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */ | ||
165 | #define SET(bit) (A(bit) |= B(bit)) | ||
166 | #define CLR(bit) (A(bit) &= (~B(bit))) | ||
167 | #define TST(bit) (A(bit) & B(bit)) | ||
168 | |||
162 | /**************************************************************************/ | 169 | /**************************************************************************/ |
163 | 170 | ||
164 | static void pingstats(int junk) | 171 | static void pingstats(int junk) |
@@ -294,7 +301,7 @@ static void unpack(char *packet, int sz, struct sockaddr_in6 *from, int hoplimit | |||
294 | dupflag = 0; | 301 | dupflag = 0; |
295 | } | 302 | } |
296 | 303 | ||
297 | if (options & O_QUIET) | 304 | if (option_mask32 & OPT_QUIET) |
298 | return; | 305 | return; |
299 | 306 | ||
300 | printf("%d bytes from %s: icmp6_seq=%u", sz, | 307 | printf("%d bytes from %s: icmp6_seq=%u", sz, |
@@ -336,7 +343,7 @@ static void ping(const char *host) | |||
336 | #ifdef ICMP6_FILTER | 343 | #ifdef ICMP6_FILTER |
337 | { | 344 | { |
338 | struct icmp6_filter filt; | 345 | struct icmp6_filter filt; |
339 | if (!(options & O_VERBOSE)) { | 346 | if (!(option_mask32 & OPT_VERBOSE)) { |
340 | ICMP6_FILTER_SETBLOCKALL(&filt); | 347 | ICMP6_FILTER_SETBLOCKALL(&filt); |
341 | ICMP6_FILTER_SETPASS(ICMP6_ECHO_REPLY, &filt); | 348 | ICMP6_FILTER_SETPASS(ICMP6_ECHO_REPLY, &filt); |
342 | } else { | 349 | } else { |
@@ -416,57 +423,24 @@ static void ping(const char *host) | |||
416 | 423 | ||
417 | int ping6_main(int argc, char **argv) | 424 | int ping6_main(int argc, char **argv) |
418 | { | 425 | { |
419 | char *thisarg; | 426 | char *opt_c, *opt_s, *opt_I; |
420 | 427 | ||
421 | datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */ | 428 | datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */ |
422 | 429 | ||
423 | argc--; | 430 | /* exactly one argument needed, -v and -q don't mix */ |
424 | argv++; | 431 | opt_complementary = "=1:q--v:v--q"; |
425 | /* Parse any options */ | 432 | getopt32(argc, argv, OPT_STRING, &opt_c, &opt_s, &opt_I); |
426 | while (argc >= 1 && **argv == '-') { | 433 | if (option_mask32 & 4) pingcount = xatoul(opt_c); // -c |
427 | thisarg = *argv; | 434 | if (option_mask32 & 8) datalen = xatou16(opt_s); // -s |
428 | thisarg++; | 435 | if (option_mask32 & 0x10) { // -I |
429 | switch (*thisarg) { | 436 | if_index = if_nametoindex(opt_I); |
430 | case 'v': | 437 | if (!if_index) |
431 | options &= ~O_QUIET; | 438 | bb_error_msg_and_die( |
432 | options |= O_VERBOSE; | 439 | "%s: invalid interface name", opt_I); |
433 | break; | ||
434 | case 'q': | ||
435 | options &= ~O_VERBOSE; | ||
436 | options |= O_QUIET; | ||
437 | break; | ||
438 | case 'c': | ||
439 | if (--argc <= 0) | ||
440 | bb_show_usage(); | ||
441 | argv++; | ||
442 | pingcount = xatoul(*argv); | ||
443 | break; | ||
444 | case 's': | ||
445 | if (--argc <= 0) | ||
446 | bb_show_usage(); | ||
447 | argv++; | ||
448 | datalen = xatou16(*argv); | ||
449 | break; | ||
450 | case 'I': | ||
451 | if (--argc <= 0) | ||
452 | bb_show_usage(); | ||
453 | argv++; | ||
454 | if_index = if_nametoindex(*argv); | ||
455 | if (!if_index) | ||
456 | bb_error_msg_and_die( | ||
457 | "%s: invalid interface name", *argv); | ||
458 | break; | ||
459 | default: | ||
460 | bb_show_usage(); | ||
461 | } | ||
462 | argc--; | ||
463 | argv++; | ||
464 | } | 440 | } |
465 | if (argc < 1) | ||
466 | bb_show_usage(); | ||
467 | 441 | ||
468 | myid = (int16_t) getpid(); | 442 | myid = (int16_t)getpid(); |
469 | ping(*argv); | 443 | ping(argv[optind]); |
470 | return EXIT_SUCCESS; | 444 | return EXIT_SUCCESS; |
471 | } | 445 | } |
472 | #endif /* ! CONFIG_FEATURE_FANCY_PING6 */ | 446 | #endif /* ! CONFIG_FEATURE_FANCY_PING6 */ |