diff options
-rw-r--r-- | include/usage.h | 62 | ||||
-rw-r--r-- | miscutils/crond.c | 6 | ||||
-rw-r--r-- | networking/sendmail.c | 84 |
3 files changed, 83 insertions, 69 deletions
diff --git a/include/usage.h b/include/usage.h index dd66728be..d7bc018a5 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -1088,18 +1088,16 @@ | |||
1088 | "\n -S SECTORS" \ | 1088 | "\n -S SECTORS" \ |
1089 | 1089 | ||
1090 | #define fetchmail_trivial_usage \ | 1090 | #define fetchmail_trivial_usage \ |
1091 | "[-w timeout] [-H server[:port]] [-U user] -P password [-X] [-t] [-z] maildir [prog]" | 1091 | "[-w timeout] [-H [user:pass@]server[:port]] [-S] [-t] [-z] maildir [prog]" |
1092 | #define fetchmail_full_usage "\n\n" \ | 1092 | #define fetchmail_full_usage "\n\n" \ |
1093 | "Fetch content of remote mailbox to local Maildir.\n" \ | 1093 | "Fetch content of remote mailbox to local maildir\n" \ |
1094 | "\nOptions:" \ | 1094 | "\nOptions:" \ |
1095 | "\n -w timeout Set timeout on network operations" \ | 1095 | "\n -w timeout Network timeout" \ |
1096 | "\n -H server[:port] Set server" \ | 1096 | "\n -H [user:pass@]server[:port] Server" \ |
1097 | "\n -U username Authenticate with specified username/password" \ | 1097 | "\n -S Use openssl connection helper for secure servers" \ |
1098 | "\n -P password" \ | ||
1099 | "\n -X Use openssl connection helper for secured servers" \ | ||
1100 | "\n -t Get only headers" \ | 1098 | "\n -t Get only headers" \ |
1101 | "\n -z Delete messages on server" \ | 1099 | "\n -z Delete messages on server" \ |
1102 | "\n prog Run prog <message_file> on message delivery" \ | 1100 | "\n prog Run 'prog <message_file>' on message delivery" \ |
1103 | 1101 | ||
1104 | #define findfs_trivial_usage \ | 1102 | #define findfs_trivial_usage \ |
1105 | "LABEL=label or UUID=uuid" | 1103 | "LABEL=label or UUID=uuid" |
@@ -3123,7 +3121,7 @@ | |||
3123 | " 742 andersen andersen S [bash]\n" \ | 3121 | " 742 andersen andersen S [bash]\n" \ |
3124 | " 743 andersen andersen S -bash\n" \ | 3122 | " 743 andersen andersen S -bash\n" \ |
3125 | " 745 root root S [getty]\n" \ | 3123 | " 745 root root S [getty]\n" \ |
3126 | " 2990 andersen andersen R ps\n" | 3124 | " 2990 andersen andersen R ps\n" \ |
3127 | 3125 | ||
3128 | #define pscan_trivial_usage \ | 3126 | #define pscan_trivial_usage \ |
3129 | "[-cb] [-p MIN_PORT] [-P MAX_PORT] [-t TIMEOUT] [-T MIN_RTT] HOST" | 3127 | "[-cb] [-p MIN_PORT] [-P MAX_PORT] [-t TIMEOUT] [-T MIN_RTT] HOST" |
@@ -3426,33 +3424,31 @@ | |||
3426 | #define selinuxenabled_full_usage "" | 3424 | #define selinuxenabled_full_usage "" |
3427 | 3425 | ||
3428 | #define sendmail_trivial_usage \ | 3426 | #define sendmail_trivial_usage \ |
3429 | "[-w timeout] [-H server[:port]] [-U user] [-P password] [-X]\n" \ | 3427 | "[-w timeout] [-H [user:pass@]server[:port]] [-S]\n" \ |
3430 | "[-c charset] [-n] [-i] [-s subject] [-a attach]... [-t] [-f sender] [rcpt]..." | 3428 | "[-c charset] [-N type] [-i] [-s subject] [-a attach]... [-t] [-f sender] [rcpt]..." |
3431 | #define sendmail_full_usage "\n\n" \ | 3429 | #define sendmail_full_usage "\n\n" \ |
3432 | "Send an email.\n" \ | 3430 | "Send an email\n" \ |
3433 | "\nOptions:" \ | 3431 | "\nOptions:" \ |
3434 | "\n -w timeout Set timeout on network operations" \ | 3432 | "\n -w timeout Network timeout" \ |
3435 | "\n -H server[:port] Set server" \ | 3433 | "\n -H [user:pass@]server[:port] Server" \ |
3436 | "\n -U username Authenticate with specified username/password" \ | 3434 | "\n -S Use openssl connection helper for secure servers" \ |
3437 | "\n -P password" \ | 3435 | "\n -c charset Assume charset for body and subject (utf-8)" \ |
3438 | "\n -X Use openssl connection helper for secured servers" \ | 3436 | "\n -N type Request delivery notification. Type is ignored" \ |
3439 | "\n -c charset Assumed charset for body and subject [utf-8]" \ | ||
3440 | "\n -n Request delivery notification to sender" \ | ||
3441 | "\n -i Ignore single dots in mail body. Implied" \ | 3437 | "\n -i Ignore single dots in mail body. Implied" \ |
3442 | "\n -s subject Subject" \ | 3438 | "\n -s subject Subject" \ |
3443 | "\n -a file File to attach. May be multiple" \ | 3439 | "\n -a file File to attach. May be multiple" \ |
3444 | "\n -t Read recipients and subject from body" \ | 3440 | "\n -t Read recipients and subject from body" \ |
3445 | "\n -f Set sender address" \ | 3441 | "\n -f sender Sender" \ |
3446 | 3442 | ||
3447 | #define seq_trivial_usage \ | 3443 | #define seq_trivial_usage \ |
3448 | "[first [increment]] last" | 3444 | "[first [increment]] last" |
3449 | #define seq_full_usage "\n\n" \ | 3445 | #define seq_full_usage "\n\n" \ |
3450 | "Print numbers from FIRST to LAST, in steps of INCREMENT.\n" \ | 3446 | "Print numbers from FIRST to LAST, in steps of INCREMENT.\n" \ |
3451 | "FIRST, INCREMENT default to 1" \ | 3447 | "FIRST, INCREMENT default to 1\n" \ |
3452 | "\n\nArguments:\n" \ | 3448 | "\nArguments:" \ |
3453 | " LAST\n" \ | 3449 | "\n LAST" \ |
3454 | " FIRST LAST\n" \ | 3450 | "\n FIRST LAST" \ |
3455 | " FIRST INCREMENT LAST" | 3451 | "\n FIRST INCREMENT LAST" \ |
3456 | 3452 | ||
3457 | #define sestatus_trivial_usage \ | 3453 | #define sestatus_trivial_usage \ |
3458 | "[-vb]" | 3454 | "[-vb]" |
@@ -3764,7 +3760,7 @@ | |||
3764 | " %S Fundamental block size (for block counts)\n" \ | 3760 | " %S Fundamental block size (for block counts)\n" \ |
3765 | " %t Type in hex\n" \ | 3761 | " %t Type in hex\n" \ |
3766 | " %T Type in human readable form" \ | 3762 | " %T Type in human readable form" \ |
3767 | ) | 3763 | ) \ |
3768 | 3764 | ||
3769 | #define strings_trivial_usage \ | 3765 | #define strings_trivial_usage \ |
3770 | "[-afo] [-n length] [file...]" | 3766 | "[-afo] [-n length] [file...]" |
@@ -3821,9 +3817,9 @@ | |||
3821 | "up: if service isn't running, start it. If service stops, restart it\n" \ | 3817 | "up: if service isn't running, start it. If service stops, restart it\n" \ |
3822 | "once: like 'up', but if service stops, don't restart it\n" \ | 3818 | "once: like 'up', but if service stops, don't restart it\n" \ |
3823 | "down: send TERM and CONT signals. If ./run exits, start ./finish\n" \ | 3819 | "down: send TERM and CONT signals. If ./run exits, start ./finish\n" \ |
3824 | " if it exists. After it stops, do not restart service\n" \ | 3820 | " if it exists. After it stops, do not restart service\n" \ |
3825 | "exit: send TERM and CONT signals to service and log service. If they exit,\n" \ | 3821 | "exit: send TERM and CONT signals to service and log service. If they exit,\n" \ |
3826 | " runsv exits too\n" \ | 3822 | " runsv exits too\n" \ |
3827 | "pause, cont, hup, alarm, interrupt, quit, 1, 2, term, kill: send\n" \ | 3823 | "pause, cont, hup, alarm, interrupt, quit, 1, 2, term, kill: send\n" \ |
3828 | "STOP, CONT, HUP, ALRM, INT, QUIT, USR1, USR2, TERM, KILL signal to service" \ | 3824 | "STOP, CONT, HUP, ALRM, INT, QUIT, USR1, USR2, TERM, KILL signal to service" \ |
3829 | 3825 | ||
@@ -3930,10 +3926,10 @@ | |||
3930 | "\n -q Never output headers giving file names" \ | 3926 | "\n -q Never output headers giving file names" \ |
3931 | "\n -s SEC Wait SEC seconds between reads with -f" \ | 3927 | "\n -s SEC Wait SEC seconds between reads with -f" \ |
3932 | "\n -v Always output headers giving file names" \ | 3928 | "\n -v Always output headers giving file names" \ |
3933 | "\n\n" \ | 3929 | "\n" \ |
3934 | "If the first character of N (bytes or lines) is a '+', output begins with\n" \ | 3930 | "\nIf the first character of N (bytes or lines) is a '+', output begins with" \ |
3935 | "the Nth item from the start of each file, otherwise, print the last N items\n" \ | 3931 | "\nthe Nth item from the start of each file, otherwise, print the last N items" \ |
3936 | "in the file. N bytes may be suffixed by k (x1024), b (x512), or m (1024^2)." ) \ | 3932 | "\nin the file. N bytes may be suffixed by k (x1024), b (x512), or m (1024^2)." ) \ |
3937 | 3933 | ||
3938 | #define tail_example_usage \ | 3934 | #define tail_example_usage \ |
3939 | "$ tail -n 1 /etc/resolv.conf\n" \ | 3935 | "$ tail -n 1 /etc/resolv.conf\n" \ |
diff --git a/miscutils/crond.c b/miscutils/crond.c index 2bed5a4b1..27f24dd85 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c | |||
@@ -33,11 +33,7 @@ | |||
33 | #define SENDMAIL "sendmail" | 33 | #define SENDMAIL "sendmail" |
34 | #endif | 34 | #endif |
35 | #ifndef SENDMAIL_ARGS | 35 | #ifndef SENDMAIL_ARGS |
36 | # if ENABLE_SENDMAIL | 36 | #define SENDMAIL_ARGS "-ti", "oem" |
37 | # define SENDMAIL_ARGS "localhost", line->cl_MailTo | ||
38 | # else | ||
39 | # define SENDMAIL_ARGS "-ti", "oem" | ||
40 | # endif | ||
41 | #endif | 37 | #endif |
42 | #ifndef CRONUPDATE | 38 | #ifndef CRONUPDATE |
43 | #define CRONUPDATE "cron.update" | 39 | #define CRONUPDATE "cron.update" |
diff --git a/networking/sendmail.c b/networking/sendmail.c index 071d9d62d..b81c8525f 100644 --- a/networking/sendmail.c +++ b/networking/sendmail.c | |||
@@ -262,32 +262,49 @@ static void pop3_message(const char *filename) | |||
262 | } | 262 | } |
263 | #endif | 263 | #endif |
264 | 264 | ||
265 | static char *parse_url(char *url, char **user, char **pass) | ||
266 | { | ||
267 | // parse [user[:pass]@]host | ||
268 | // return host | ||
269 | char *s = strchr(url, '@'); | ||
270 | *user = *pass = NULL; | ||
271 | if (s) { | ||
272 | *s++ = '\0'; | ||
273 | *user = url; | ||
274 | url = s; | ||
275 | s = strchr(*user, ':'); | ||
276 | if (s) { | ||
277 | *s++ = '\0'; | ||
278 | *pass = s; | ||
279 | } | ||
280 | } | ||
281 | return url; | ||
282 | } | ||
283 | |||
265 | int sendgetmail_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 284 | int sendgetmail_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
266 | int sendgetmail_main(int argc ATTRIBUTE_UNUSED, char **argv) | 285 | int sendgetmail_main(int argc ATTRIBUTE_UNUSED, char **argv) |
267 | { | 286 | { |
268 | llist_t *opt_recipients = NULL; | 287 | llist_t *opt_recipients = NULL; |
269 | llist_t *opt_attachments = NULL; | 288 | llist_t *opt_attachments = NULL; |
270 | char *opt_from; | 289 | char *opt_from; |
271 | const char *opt_user; | 290 | char *opt_user; |
272 | const char *opt_pass; | 291 | char *opt_pass; |
273 | enum { | 292 | enum { |
274 | OPT_w = 1 << 0, // network timeout | 293 | OPT_w = 1 << 0, // network timeout |
275 | OPT_H = 1 << 1, // server[:port] | 294 | OPT_H = 1 << 1, // [user:password@]server[:port] |
276 | OPT_U = 1 << 2, // user | 295 | OPT_S = 1 << 2, // connect using openssl s_client helper |
277 | OPT_P = 1 << 3, // password | ||
278 | OPT_X = 1 << 4, // connect using openssl s_client helper | ||
279 | 296 | ||
280 | OPTS_t = 1 << 5, // sendmail: read addresses from body | 297 | OPTS_t = 1 << 3, // sendmail: read addresses from body |
281 | OPTF_t = 1 << 5, // fetchmail: use "TOP" not "RETR" | 298 | OPTF_t = 1 << 3, // fetchmail: use "TOP" not "RETR" |
282 | 299 | ||
283 | OPTS_s = 1 << 6, // sendmail: subject | 300 | OPTS_s = 1 << 4, // sendmail: subject |
284 | OPTF_z = 1 << 6, // fetchmail: delete from server | 301 | OPTF_z = 1 << 4, // fetchmail: delete from server |
285 | 302 | ||
286 | OPTS_c = 1 << 7, // sendmail: assumed charset | 303 | OPTS_c = 1 << 5, // sendmail: assumed charset |
287 | OPTS_a = 1 << 8, // sendmail: attachment(s) | 304 | OPTS_a = 1 << 6, // sendmail: attachment(s) |
288 | OPTS_i = 1 << 9, // sendmail: ignore lone dots in message body (implied) | 305 | OPTS_i = 1 << 7, // sendmail: ignore lone dots in message body (implied) |
289 | 306 | ||
290 | OPTS_n = 1 << 10, // sendmail: request notification | 307 | OPTS_N = 1 << 8, // sendmail: request notification |
291 | }; | 308 | }; |
292 | const char *options; | 309 | const char *options; |
293 | int opts; | 310 | int opts; |
@@ -303,18 +320,18 @@ int sendgetmail_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
303 | // save initial stdin (body or attachements can be piped!) | 320 | // save initial stdin (body or attachements can be piped!) |
304 | xdup2(STDIN_FILENO, INITIAL_STDIN_FILENO); | 321 | xdup2(STDIN_FILENO, INITIAL_STDIN_FILENO); |
305 | opt_complementary = "w+:a::"; | 322 | opt_complementary = "w+:a::"; |
306 | options = "w:H:U:P:Xt" "s:c:a:inf:"; | 323 | options = "w:H:St" "s:c:a:iN:f:"; |
307 | // body is pseudo attachment read from stdin | 324 | // body is pseudo attachment read from stdin |
308 | llist_add_to_end(&opt_attachments, (char *)"-"); | 325 | llist_add_to_end(&opt_attachments, (char *)"-"); |
309 | } else { | 326 | } else { |
310 | // FETCHMAIL | 327 | // FETCHMAIL |
311 | opt_after_connect = NULL; | 328 | opt_after_connect = NULL; |
312 | opt_complementary = "-1:w+:P"; | 329 | opt_complementary = "-1:w+"; |
313 | options = "w:H:U:P:Xt" "z"; | 330 | options = "w:H:St" "z"; |
314 | } | 331 | } |
315 | opts = getopt32(argv, options, | 332 | opts = getopt32(argv, options, |
316 | &timeout, &opt_connect, &opt_user, &opt_pass, | 333 | &timeout /* -w */, &opt_connect /* -H */, |
317 | &opt_subject, &opt_charset, &opt_attachments, &opt_from | 334 | &opt_subject, &opt_charset, &opt_attachments, NULL, &opt_from |
318 | ); | 335 | ); |
319 | //argc -= optind; | 336 | //argc -= optind; |
320 | argv += optind; | 337 | argv += optind; |
@@ -326,8 +343,14 @@ int sendgetmail_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
326 | if (!opt_connect) | 343 | if (!opt_connect) |
327 | opt_connect = "127.0.0.1"; | 344 | opt_connect = "127.0.0.1"; |
328 | } | 345 | } |
346 | // fetch username and password, if any | ||
347 | // NB: parse_url modifies opt_connect[] ONLY if '@' is there. | ||
348 | // Thus "127.0.0.1" won't be modified, an is ok that it is RO. | ||
349 | opt_connect = parse_url((char*)opt_connect, &opt_user, &opt_pass); | ||
350 | // bb_error_msg("H[%s] U[%s] P[%s]", opt_connect, opt_user, opt_pass); | ||
351 | |||
329 | // SSL ordered? -> | 352 | // SSL ordered? -> |
330 | if (opts & OPT_X) { | 353 | if (opts & OPT_S) { |
331 | // ... use openssl helper | 354 | // ... use openssl helper |
332 | launch_helper(xargs); | 355 | launch_helper(xargs); |
333 | // no SSL ordered? -> | 356 | // no SSL ordered? -> |
@@ -340,10 +363,8 @@ int sendgetmail_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
340 | xdup2(STDIN_FILENO, STDOUT_FILENO); | 363 | xdup2(STDIN_FILENO, STDOUT_FILENO); |
341 | } | 364 | } |
342 | 365 | ||
343 | #if ENABLE_FETCHMAIL | ||
344 | // are we sendmail? | 366 | // are we sendmail? |
345 | if (opt_after_connect) | 367 | if (!ENABLE_FETCHMAIL || opt_after_connect) |
346 | #endif | ||
347 | /*************************************************** | 368 | /*************************************************** |
348 | * SENDMAIL | 369 | * SENDMAIL |
349 | ***************************************************/ | 370 | ***************************************************/ |
@@ -364,7 +385,7 @@ int sendgetmail_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
364 | } | 385 | } |
365 | 386 | ||
366 | // we didn't use SSL helper? -> | 387 | // we didn't use SSL helper? -> |
367 | if (!(opts & OPT_X)) { | 388 | if (!(opts & OPT_S)) { |
368 | // ... wait for initial server OK | 389 | // ... wait for initial server OK |
369 | smtp_check(NULL, 220); | 390 | smtp_check(NULL, 220); |
370 | } | 391 | } |
@@ -402,14 +423,13 @@ int sendgetmail_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
402 | // set sender | 423 | // set sender |
403 | // NOTE: if password has not been specified | 424 | // NOTE: if password has not been specified |
404 | // then no authentication is possible | 425 | // then no authentication is possible |
405 | code = (opts & OPT_P) ? -1 : 250; | 426 | code = (opt_pass) ? -1 : 250; |
406 | // first try softly without authentication | 427 | // first try softly without authentication |
407 | while (250 != smtp_checkp("MAIL FROM:<%s>", opt_from, code)) { | 428 | while (250 != smtp_checkp("MAIL FROM:<%s>", opt_from, code)) { |
408 | // MAIL FROM failed -> authentication needed | 429 | // MAIL FROM failed -> authentication needed |
409 | // have we got username? | 430 | // have we got username? |
410 | if (!(opts & OPT_U)) { | 431 | if (!opt_user) { |
411 | // no! fetch it from "from" option | 432 | // no! fetch it from "from" option |
412 | //opts |= OPT_U; | ||
413 | opt_user = xstrdup(opt_from); | 433 | opt_user = xstrdup(opt_from); |
414 | *strchrnul(opt_user, '@') = '\0'; | 434 | *strchrnul(opt_user, '@') = '\0'; |
415 | } | 435 | } |
@@ -450,7 +470,7 @@ int sendgetmail_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
450 | } | 470 | } |
451 | 471 | ||
452 | // put notification | 472 | // put notification |
453 | if (opts & OPTS_n) | 473 | if (opts & OPTS_N) |
454 | printf("Disposition-Notification-To: %s\r\n", opt_from); | 474 | printf("Disposition-Notification-To: %s\r\n", opt_from); |
455 | 475 | ||
456 | // make a random string -- it will delimit message parts | 476 | // make a random string -- it will delimit message parts |
@@ -515,7 +535,6 @@ int sendgetmail_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
515 | * FETCHMAIL | 535 | * FETCHMAIL |
516 | ***************************************************/ | 536 | ***************************************************/ |
517 | else { | 537 | else { |
518 | |||
519 | char *buf; | 538 | char *buf; |
520 | unsigned nmsg; | 539 | unsigned nmsg; |
521 | char *hostname; | 540 | char *hostname; |
@@ -533,11 +552,14 @@ int sendgetmail_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
533 | *fargs = *argv; | 552 | *fargs = *argv; |
534 | 553 | ||
535 | // authenticate | 554 | // authenticate |
536 | if (!(opts & OPT_U)) { | 555 | if (!opt_user) { |
537 | //opts |= OPT_U; | ||
538 | // N.B. IMHO getenv("USER") can be way easily spoofed! | 556 | // N.B. IMHO getenv("USER") can be way easily spoofed! |
539 | opt_user = bb_getpwuid(NULL, -1, getuid()); | 557 | opt_user = bb_getpwuid(NULL, -1, getuid()); |
540 | } | 558 | } |
559 | // password is mandatory | ||
560 | if (!opt_pass) { | ||
561 | bb_error_msg_and_die("no password"); | ||
562 | } | ||
541 | 563 | ||
542 | // get server greeting | 564 | // get server greeting |
543 | pop3_checkr(NULL, NULL, &buf); | 565 | pop3_checkr(NULL, NULL, &buf); |