diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-28 21:46:41 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-28 21:46:41 +0000 |
commit | 6ea75e2f5db42d102f3a8d2bf59f4d27a4d65863 (patch) | |
tree | 3a01531bb6e1fcd5c41d7c8da4430743b88d25a2 /networking | |
parent | 78ff8197cc5ff8a9b207b0c27a96a292d1f492cc (diff) | |
download | busybox-w32-6ea75e2f5db42d102f3a8d2bf59f4d27a4d65863.tar.gz busybox-w32-6ea75e2f5db42d102f3a8d2bf59f4d27a4d65863.tar.bz2 busybox-w32-6ea75e2f5db42d102f3a8d2bf59f4d27a4d65863.zip |
sendmail: another update from the maintainer
function old new delta
sendgetmail_main 1894 1937 +43
crond_main 1416 1423 +7
packed_usage 24540 24470 -70
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 50/-70) Total: -20 bytes
Diffstat (limited to 'networking')
-rw-r--r-- | networking/sendmail.c | 84 |
1 files changed, 53 insertions, 31 deletions
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); |