Minor fixes
* libproto/mailer/smtp.c: fix indentation
Showing
1 changed file
with
233 additions
and
215 deletions
... | @@ -59,7 +59,7 @@ | ... | @@ -59,7 +59,7 @@ |
59 | #include <url0.h> | 59 | #include <url0.h> |
60 | #include <registrar0.h> | 60 | #include <registrar0.h> |
61 | 61 | ||
62 | static int _mailer_smtp_init (mu_mailer_t); | 62 | static int _mailer_smtp_init (mu_mailer_t); |
63 | 63 | ||
64 | static int | 64 | static int |
65 | _url_smtp_init (mu_url_t url) | 65 | _url_smtp_init (mu_url_t url) |
... | @@ -77,7 +77,7 @@ _url_smtp_init (mu_url_t url) | ... | @@ -77,7 +77,7 @@ _url_smtp_init (mu_url_t url) |
77 | 77 | ||
78 | if (url->port == 0) | 78 | if (url->port == 0) |
79 | url->port = MU_SMTP_PORT; | 79 | url->port = MU_SMTP_PORT; |
80 | 80 | ||
81 | return 0; | 81 | return 0; |
82 | } | 82 | } |
83 | 83 | ||
... | @@ -85,7 +85,7 @@ static struct _mu_record _smtp_record = { | ... | @@ -85,7 +85,7 @@ static struct _mu_record _smtp_record = { |
85 | MU_SMTP_PRIO, | 85 | MU_SMTP_PRIO, |
86 | MU_SMTP_SCHEME, | 86 | MU_SMTP_SCHEME, |
87 | _url_smtp_init, /* url init. */ | 87 | _url_smtp_init, /* url init. */ |
88 | _mu_mailer_mailbox_init, /* Mailbox init. */ | 88 | _mu_mailer_mailbox_init, /* Mailbox init. */ |
89 | _mailer_smtp_init, /* Mailer init. */ | 89 | _mailer_smtp_init, /* Mailer init. */ |
90 | _mu_mailer_folder_init, /* Folder init. */ | 90 | _mu_mailer_folder_init, /* Folder init. */ |
91 | NULL, /* No need for a back pointer. */ | 91 | NULL, /* No need for a back pointer. */ |
... | @@ -95,23 +95,24 @@ static struct _mu_record _smtp_record = { | ... | @@ -95,23 +95,24 @@ static struct _mu_record _smtp_record = { |
95 | NULL, /* _get_mailer method. */ | 95 | NULL, /* _get_mailer method. */ |
96 | NULL /* _get_folder method. */ | 96 | NULL /* _get_folder method. */ |
97 | }; | 97 | }; |
98 | |||
98 | /* We export : url parsing and the initialisation of | 99 | /* We export : url parsing and the initialisation of |
99 | the mailbox, via the register entry/record. */ | 100 | the mailbox, via the register entry/record. */ |
100 | mu_record_t mu_smtp_record = &_smtp_record; | 101 | mu_record_t mu_smtp_record = &_smtp_record; |
101 | 102 | ||
102 | struct _smtp | 103 | struct _smtp |
103 | { | 104 | { |
104 | mu_mailer_t mailer; | 105 | mu_mailer_t mailer; |
105 | char *mailhost; | 106 | char *mailhost; |
106 | char *localhost; | 107 | char *localhost; |
107 | 108 | ||
108 | /* IO buffering. */ | 109 | /* IO buffering. */ |
109 | char *buffer; /* Must be freed. */ | 110 | char *buffer; /* Must be freed. */ |
110 | size_t buflen; | 111 | size_t buflen; |
111 | 112 | ||
112 | char *ptr; | 113 | char *ptr; |
113 | char *nl; | 114 | char *nl; |
114 | off_t s_offset; | 115 | off_t s_offset; |
115 | 116 | ||
116 | enum smtp_state | 117 | enum smtp_state |
117 | { | 118 | { |
... | @@ -123,28 +124,28 @@ struct _smtp | ... | @@ -123,28 +124,28 @@ struct _smtp |
123 | } | 124 | } |
124 | state; | 125 | state; |
125 | 126 | ||
126 | int extended; | 127 | int extended; |
127 | unsigned long capa; /* Server capabilities */ | 128 | unsigned long capa; /* Server capabilities */ |
128 | size_t max_size; /* Maximum message size the server is willing | 129 | size_t max_size; /* Maximum message size the server is willing |
129 | to accept */ | 130 | to accept */ |
130 | unsigned long auth_mechs; /* Available ESMTP AUTH mechanisms */ | 131 | unsigned long auth_mechs; /* Available ESMTP AUTH mechanisms */ |
131 | 132 | ||
132 | const char *mail_from; | 133 | const char *mail_from; |
133 | mu_address_t rcpt_to; /* Destroy this if not the same as argto below. */ | 134 | mu_address_t rcpt_to; /* Destroy this if not the same as argto below. */ |
134 | mu_address_t rcpt_bcc; | 135 | mu_address_t rcpt_bcc; |
135 | size_t rcpt_to_count; | 136 | size_t rcpt_to_count; |
136 | size_t rcpt_bcc_count; | 137 | size_t rcpt_bcc_count; |
137 | size_t rcpt_index; | 138 | size_t rcpt_index; |
138 | size_t rcpt_count; | 139 | size_t rcpt_count; |
139 | int bccing; | 140 | int bccing; |
140 | mu_message_t msg; /* Destroy this if not same argmsg. */ | 141 | mu_message_t msg; /* Destroy this if not same argmsg. */ |
141 | 142 | ||
142 | off_t offset; | 143 | off_t offset; |
143 | 144 | ||
144 | /* The mu_mailer_send_message() args. */ | 145 | /* The mu_mailer_send_message() args. */ |
145 | mu_message_t argmsg; | 146 | mu_message_t argmsg; |
146 | mu_address_t argfrom; | 147 | mu_address_t argfrom; |
147 | mu_address_t argto; | 148 | mu_address_t argto; |
148 | }; | 149 | }; |
149 | 150 | ||
150 | typedef struct _smtp *smtp_t; | 151 | typedef struct _smtp *smtp_t; |
... | @@ -163,35 +164,36 @@ typedef struct _smtp *smtp_t; | ... | @@ -163,35 +164,36 @@ typedef struct _smtp *smtp_t; |
163 | #define AUTH_GSSAPI 0x00000010 | 164 | #define AUTH_GSSAPI 0x00000010 |
164 | #define AUTH_EXTERNAL 0x00000020 | 165 | #define AUTH_EXTERNAL 0x00000020 |
165 | 166 | ||
166 | struct auth_mech_record { | 167 | struct auth_mech_record |
167 | unsigned long id; | 168 | { |
168 | char *name; | 169 | unsigned long id; |
170 | char *name; | ||
169 | }; | 171 | }; |
170 | 172 | ||
171 | static struct auth_mech_record auth_mech_list[] = { | 173 | static struct auth_mech_record auth_mech_list[] = { |
172 | { AUTH_LOGIN, "login" }, | 174 | {AUTH_LOGIN, "login"}, |
173 | { AUTH_PLAIN, "plain" }, | 175 | {AUTH_PLAIN, "plain"}, |
174 | { AUTH_CRAM_MD5, "cram-md5" }, | 176 | {AUTH_CRAM_MD5, "cram-md5"}, |
175 | { AUTH_DIGEST_MD5, "digest-md5" }, | 177 | {AUTH_DIGEST_MD5, "digest-md5"}, |
176 | { AUTH_GSSAPI, "gssapi" }, | 178 | {AUTH_GSSAPI, "gssapi"}, |
177 | { AUTH_EXTERNAL, "external" }, | 179 | {AUTH_EXTERNAL, "external"}, |
178 | { 0, NULL }, | 180 | {0, NULL}, |
179 | }; | 181 | }; |
180 | 182 | ||
181 | static void smtp_destroy (mu_mailer_t); | 183 | static void smtp_destroy (mu_mailer_t); |
182 | static int smtp_open (mu_mailer_t, int); | 184 | static int smtp_open (mu_mailer_t, int); |
183 | static int smtp_close (mu_mailer_t); | 185 | static int smtp_close (mu_mailer_t); |
184 | static int smtp_send_message (mu_mailer_t, mu_message_t, mu_address_t, | 186 | static int smtp_send_message (mu_mailer_t, mu_message_t, mu_address_t, |
185 | mu_address_t); | 187 | mu_address_t); |
186 | static int smtp_writeline (smtp_t smtp, const char *format, ...); | 188 | static int smtp_writeline (smtp_t smtp, const char *format, ...); |
187 | static int smtp_readline (smtp_t); | 189 | static int smtp_readline (smtp_t); |
188 | static int smtp_read_ack (smtp_t); | 190 | static int smtp_read_ack (smtp_t); |
189 | static int smtp_parse_ehlo_ack (smtp_t); | 191 | static int smtp_parse_ehlo_ack (smtp_t); |
190 | static int smtp_write (smtp_t); | 192 | static int smtp_write (smtp_t); |
191 | static int smtp_starttls (smtp_t); | 193 | static int smtp_starttls (smtp_t); |
192 | static int smtp_auth (smtp_t); | 194 | static int smtp_auth (smtp_t); |
193 | 195 | ||
194 | static int _smtp_set_rcpt (smtp_t, mu_message_t, mu_address_t); | 196 | static int _smtp_set_rcpt (smtp_t, mu_message_t, mu_address_t); |
195 | 197 | ||
196 | /* Useful little macros, since these are very repetitive. */ | 198 | /* Useful little macros, since these are very repetitive. */ |
197 | 199 | ||
... | @@ -238,7 +240,8 @@ CLEAR_STATE (smtp_t smtp) | ... | @@ -238,7 +240,8 @@ CLEAR_STATE (smtp_t smtp) |
238 | as that which is ongoing. Check this. */ | 240 | as that which is ongoing. Check this. */ |
239 | static int | 241 | static int |
240 | smtp_check_send_resumption (smtp_t smtp, | 242 | smtp_check_send_resumption (smtp_t smtp, |
241 | mu_message_t msg, mu_address_t from, mu_address_t to) | 243 | mu_message_t msg, mu_address_t from, |
244 | mu_address_t to) | ||
242 | { | 245 | { |
243 | if (smtp->state == SMTP_NO_STATE) | 246 | if (smtp->state == SMTP_NO_STATE) |
244 | return 0; | 247 | return 0; |
... | @@ -306,7 +309,7 @@ while (0) | ... | @@ -306,7 +309,7 @@ while (0) |
306 | static int | 309 | static int |
307 | _mailer_smtp_init (mu_mailer_t mailer) | 310 | _mailer_smtp_init (mu_mailer_t mailer) |
308 | { | 311 | { |
309 | smtp_t smtp; | 312 | smtp_t smtp; |
310 | 313 | ||
311 | /* Allocate memory specific to smtp mailer. */ | 314 | /* Allocate memory specific to smtp mailer. */ |
312 | smtp = mailer->data = calloc (1, sizeof (*smtp)); | 315 | smtp = mailer->data = calloc (1, sizeof (*smtp)); |
... | @@ -323,7 +326,8 @@ _mailer_smtp_init (mu_mailer_t mailer) | ... | @@ -323,7 +326,8 @@ _mailer_smtp_init (mu_mailer_t mailer) |
323 | 326 | ||
324 | /* Set our properties. */ | 327 | /* Set our properties. */ |
325 | { | 328 | { |
326 | mu_property_t property = NULL; | 329 | mu_property_t property = NULL; |
330 | |||
327 | mu_mailer_get_property (mailer, &property); | 331 | mu_mailer_get_property (mailer, &property); |
328 | mu_property_set_value (property, "TYPE", "SMTP", 1); | 332 | mu_property_set_value (property, "TYPE", "SMTP", 1); |
329 | } | 333 | } |
... | @@ -334,7 +338,7 @@ _mailer_smtp_init (mu_mailer_t mailer) | ... | @@ -334,7 +338,7 @@ _mailer_smtp_init (mu_mailer_t mailer) |
334 | static void | 338 | static void |
335 | smtp_destroy (mu_mailer_t mailer) | 339 | smtp_destroy (mu_mailer_t mailer) |
336 | { | 340 | { |
337 | smtp_t smtp = mailer->data; | 341 | smtp_t smtp = mailer->data; |
338 | 342 | ||
339 | CLEAR_STATE (smtp); | 343 | CLEAR_STATE (smtp); |
340 | 344 | ||
... | @@ -360,9 +364,9 @@ An SMTP mailer must be opened before any messages can be sent. | ... | @@ -360,9 +364,9 @@ An SMTP mailer must be opened before any messages can be sent. |
360 | static int | 364 | static int |
361 | smtp_open (mu_mailer_t mailer, int flags) | 365 | smtp_open (mu_mailer_t mailer, int flags) |
362 | { | 366 | { |
363 | smtp_t smtp = mailer->data; | 367 | smtp_t smtp = mailer->data; |
364 | int status; | 368 | int status; |
365 | long port; | 369 | long port; |
366 | 370 | ||
367 | /* Sanity checks. */ | 371 | /* Sanity checks. */ |
368 | if (!smtp) | 372 | if (!smtp) |
... | @@ -371,7 +375,7 @@ smtp_open (mu_mailer_t mailer, int flags) | ... | @@ -371,7 +375,7 @@ smtp_open (mu_mailer_t mailer, int flags) |
371 | mailer->flags = flags; | 375 | mailer->flags = flags; |
372 | 376 | ||
373 | if ((status = mu_url_get_port (mailer->url, &port)) != 0) | 377 | if ((status = mu_url_get_port (mailer->url, &port)) != 0) |
374 | return status; | 378 | return status; |
375 | 379 | ||
376 | switch (smtp->state) | 380 | switch (smtp->state) |
377 | { | 381 | { |
... | @@ -384,7 +388,7 @@ smtp_open (mu_mailer_t mailer, int flags) | ... | @@ -384,7 +388,7 @@ smtp_open (mu_mailer_t mailer, int flags) |
384 | 388 | ||
385 | /* Fetch the mailer server name and the port in the mu_url_t. */ | 389 | /* Fetch the mailer server name and the port in the mu_url_t. */ |
386 | if ((status = mu_url_aget_host (mailer->url, &smtp->mailhost)) != 0) | 390 | if ((status = mu_url_aget_host (mailer->url, &smtp->mailhost)) != 0) |
387 | return status; | 391 | return status; |
388 | 392 | ||
389 | if (smtp->localhost) | 393 | if (smtp->localhost) |
390 | { | 394 | { |
... | @@ -420,7 +424,7 @@ smtp_open (mu_mailer_t mailer, int flags) | ... | @@ -420,7 +424,7 @@ smtp_open (mu_mailer_t mailer, int flags) |
420 | { | 424 | { |
421 | status = | 425 | status = |
422 | mu_tcp_stream_create (&mailer->stream, smtp->mailhost, port, | 426 | mu_tcp_stream_create (&mailer->stream, smtp->mailhost, port, |
423 | mailer->flags); | 427 | mailer->flags); |
424 | CHECK_ERROR (smtp, status); | 428 | CHECK_ERROR (smtp, status); |
425 | mu_stream_setbufsiz (mailer->stream, BUFSIZ); | 429 | mu_stream_setbufsiz (mailer->stream, BUFSIZ); |
426 | } | 430 | } |
... | @@ -428,9 +432,8 @@ smtp_open (mu_mailer_t mailer, int flags) | ... | @@ -428,9 +432,8 @@ smtp_open (mu_mailer_t mailer, int flags) |
428 | smtp->state = SMTP_OPEN; | 432 | smtp->state = SMTP_OPEN; |
429 | 433 | ||
430 | case SMTP_OPEN: | 434 | case SMTP_OPEN: |
431 | MU_DEBUG2 (mailer->debug, MU_DEBUG_PROT, | 435 | MU_DEBUG2 (mailer->debug, MU_DEBUG_PROT, |
432 | "smtp_open (host: %s port: %ld)\n", | 436 | "smtp_open (host: %s port: %ld)\n", smtp->mailhost, port); |
433 | smtp->mailhost, port); | ||
434 | status = mu_stream_open (mailer->stream); | 437 | status = mu_stream_open (mailer->stream); |
435 | CHECK_EAGAIN (smtp, status); | 438 | CHECK_EAGAIN (smtp, status); |
436 | smtp->state = SMTP_GREETINGS; | 439 | smtp->state = SMTP_GREETINGS; |
... | @@ -446,7 +449,7 @@ smtp_open (mu_mailer_t mailer, int flags) | ... | @@ -446,7 +449,7 @@ smtp_open (mu_mailer_t mailer, int flags) |
446 | return EACCES; | 449 | return EACCES; |
447 | } | 450 | } |
448 | 451 | ||
449 | ehlo: | 452 | ehlo: |
450 | status = smtp_writeline (smtp, "EHLO %s\r\n", smtp->localhost); | 453 | status = smtp_writeline (smtp, "EHLO %s\r\n", smtp->localhost); |
451 | CHECK_ERROR (smtp, status); | 454 | CHECK_ERROR (smtp, status); |
452 | 455 | ||
... | @@ -475,26 +478,29 @@ ehlo: | ... | @@ -475,26 +478,29 @@ ehlo: |
475 | 478 | ||
476 | if (smtp->capa & CAPA_STARTTLS) | 479 | if (smtp->capa & CAPA_STARTTLS) |
477 | smtp->state = SMTP_STARTTLS; | 480 | smtp->state = SMTP_STARTTLS; |
478 | else if (smtp->capa & CAPA_AUTH && mailer->url->user) { | 481 | else if (smtp->capa & CAPA_AUTH && mailer->url->user) |
479 | smtp->state = SMTP_AUTH; | 482 | { |
480 | } | 483 | smtp->state = SMTP_AUTH; |
484 | } | ||
481 | else | 485 | else |
482 | break; | 486 | break; |
483 | } | 487 | } |
484 | 488 | ||
485 | case SMTP_STARTTLS: | 489 | case SMTP_STARTTLS: |
486 | case SMTP_STARTTLS_ACK: | 490 | case SMTP_STARTTLS_ACK: |
487 | if (smtp->capa & CAPA_STARTTLS) { | 491 | if (smtp->capa & CAPA_STARTTLS) |
488 | smtp_starttls (smtp); | 492 | { |
489 | goto ehlo; | 493 | smtp_starttls (smtp); |
490 | } | 494 | goto ehlo; |
495 | } | ||
491 | 496 | ||
492 | case SMTP_AUTH: | 497 | case SMTP_AUTH: |
493 | case SMTP_AUTH_ACK: | 498 | case SMTP_AUTH_ACK: |
494 | if (smtp->capa & CAPA_AUTH) { | 499 | if (smtp->capa & CAPA_AUTH) |
495 | smtp_auth (smtp); | 500 | { |
496 | break; | 501 | smtp_auth (smtp); |
497 | } | 502 | break; |
503 | } | ||
498 | 504 | ||
499 | case SMTP_HELO: | 505 | case SMTP_HELO: |
500 | if (!smtp->extended) /* FIXME: this will always be false! */ | 506 | if (!smtp->extended) /* FIXME: this will always be false! */ |
... | @@ -530,8 +536,9 @@ ehlo: | ... | @@ -530,8 +536,9 @@ ehlo: |
530 | static int | 536 | static int |
531 | smtp_close (mu_mailer_t mailer) | 537 | smtp_close (mu_mailer_t mailer) |
532 | { | 538 | { |
533 | smtp_t smtp = mailer->data; | 539 | smtp_t smtp = mailer->data; |
534 | int status; | 540 | int status; |
541 | |||
535 | switch (smtp->state) | 542 | switch (smtp->state) |
536 | { | 543 | { |
537 | case SMTP_NO_STATE: | 544 | case SMTP_NO_STATE: |
... | @@ -563,8 +570,9 @@ smtp_close (mu_mailer_t mailer) | ... | @@ -563,8 +570,9 @@ smtp_close (mu_mailer_t mailer) |
563 | static int | 570 | static int |
564 | smtp_reader (void *iodata) | 571 | smtp_reader (void *iodata) |
565 | { | 572 | { |
566 | int status = 0; | 573 | int status = 0; |
567 | smtp_t iop = iodata; | 574 | smtp_t iop = iodata; |
575 | |||
568 | status = smtp_read_ack (iop); | 576 | status = smtp_read_ack (iop); |
569 | CHECK_EAGAIN (iop, status); | 577 | CHECK_EAGAIN (iop, status); |
570 | return status; | 578 | return status; |
... | @@ -573,8 +581,9 @@ smtp_reader (void *iodata) | ... | @@ -573,8 +581,9 @@ smtp_reader (void *iodata) |
573 | static int | 581 | static int |
574 | smtp_writer (void *iodata, char *buf) | 582 | smtp_writer (void *iodata, char *buf) |
575 | { | 583 | { |
576 | smtp_t iop = iodata; | 584 | smtp_t iop = iodata; |
577 | int status; | 585 | int status; |
586 | |||
578 | if (mu_c_strncasecmp (buf, "EHLO", 4) == 0) | 587 | if (mu_c_strncasecmp (buf, "EHLO", 4) == 0) |
579 | status = smtp_writeline (iop, "%s %s\r\n", buf, iop->localhost); | 588 | status = smtp_writeline (iop, "%s %s\r\n", buf, iop->localhost); |
580 | else | 589 | else |
... | @@ -586,9 +595,10 @@ smtp_writer (void *iodata, char *buf) | ... | @@ -586,9 +595,10 @@ smtp_writer (void *iodata, char *buf) |
586 | } | 595 | } |
587 | 596 | ||
588 | static void | 597 | static void |
589 | smtp_stream_ctl (void *iodata, mu_stream_t *pold, mu_stream_t new) | 598 | smtp_stream_ctl (void *iodata, mu_stream_t * pold, mu_stream_t new) |
590 | { | 599 | { |
591 | smtp_t iop = iodata; | 600 | smtp_t iop = iodata; |
601 | |||
592 | if (pold) | 602 | if (pold) |
593 | *pold = iop->mailer->stream; | 603 | *pold = iop->mailer->stream; |
594 | if (new) | 604 | if (new) |
... | @@ -600,9 +610,9 @@ static int | ... | @@ -600,9 +610,9 @@ static int |
600 | smtp_starttls (smtp_t smtp) | 610 | smtp_starttls (smtp_t smtp) |
601 | { | 611 | { |
602 | #ifdef WITH_TLS | 612 | #ifdef WITH_TLS |
603 | int status; | 613 | int status; |
604 | mu_mailer_t mailer = smtp->mailer; | 614 | mu_mailer_t mailer = smtp->mailer; |
605 | char *keywords[] = { "STARTTLS", NULL }; | 615 | char *keywords[] = { "STARTTLS", NULL }; |
606 | 616 | ||
607 | if (!mu_tls_enable || !(smtp->capa & CAPA_STARTTLS)) | 617 | if (!mu_tls_enable || !(smtp->capa & CAPA_STARTTLS)) |
608 | return -1; | 618 | return -1; |
... | @@ -613,7 +623,7 @@ smtp_starttls (smtp_t smtp) | ... | @@ -613,7 +623,7 @@ smtp_starttls (smtp_t smtp) |
613 | smtp_stream_ctl, keywords); | 623 | smtp_stream_ctl, keywords); |
614 | 624 | ||
615 | MU_DEBUG1 (mailer->debug, MU_DEBUG_PROT, "TLS negotiation %s\n", | 625 | MU_DEBUG1 (mailer->debug, MU_DEBUG_PROT, "TLS negotiation %s\n", |
616 | status == 0 ? "succeeded" : "failed"); | 626 | status == 0 ? "succeeded" : "failed"); |
617 | 627 | ||
618 | return status; | 628 | return status; |
619 | #else | 629 | #else |
... | @@ -625,11 +635,11 @@ static void | ... | @@ -625,11 +635,11 @@ static void |
625 | cram_md5 (char *secret, char *challenge, unsigned char *digest) | 635 | cram_md5 (char *secret, char *challenge, unsigned char *digest) |
626 | { | 636 | { |
627 | struct mu_md5_ctx context; | 637 | struct mu_md5_ctx context; |
628 | unsigned char ipad[64]; | 638 | unsigned char ipad[64]; |
629 | unsigned char opad[64]; | 639 | unsigned char opad[64]; |
630 | int secret_len; | 640 | int secret_len; |
631 | int challenge_len; | 641 | int challenge_len; |
632 | int i; | 642 | int i; |
633 | 643 | ||
634 | if (secret == 0 || challenge == 0) | 644 | if (secret == 0 || challenge == 0) |
635 | return; | 645 | return; |
... | @@ -642,7 +652,7 @@ cram_md5 (char *secret, char *challenge, unsigned char *digest) | ... | @@ -642,7 +652,7 @@ cram_md5 (char *secret, char *challenge, unsigned char *digest) |
642 | if (secret_len > 64) | 652 | if (secret_len > 64) |
643 | { | 653 | { |
644 | mu_md5_init_ctx (&context); | 654 | mu_md5_init_ctx (&context); |
645 | mu_md5_process_bytes ((unsigned char *)secret, secret_len, &context); | 655 | mu_md5_process_bytes ((unsigned char *) secret, secret_len, &context); |
646 | mu_md5_finish_ctx (&context, ipad); | 656 | mu_md5_finish_ctx (&context, ipad); |
647 | mu_md5_finish_ctx (&context, opad); | 657 | mu_md5_finish_ctx (&context, opad); |
648 | } | 658 | } |
... | @@ -660,7 +670,7 @@ cram_md5 (char *secret, char *challenge, unsigned char *digest) | ... | @@ -660,7 +670,7 @@ cram_md5 (char *secret, char *challenge, unsigned char *digest) |
660 | 670 | ||
661 | mu_md5_init_ctx (&context); | 671 | mu_md5_init_ctx (&context); |
662 | mu_md5_process_bytes (ipad, sizeof (ipad), &context); | 672 | mu_md5_process_bytes (ipad, sizeof (ipad), &context); |
663 | mu_md5_process_bytes ((unsigned char *)challenge, challenge_len, &context); | 673 | mu_md5_process_bytes ((unsigned char *) challenge, challenge_len, &context); |
664 | mu_md5_finish_ctx (&context, digest); | 674 | mu_md5_finish_ctx (&context, digest); |
665 | 675 | ||
666 | mu_md5_init_ctx (&context); | 676 | mu_md5_init_ctx (&context); |
... | @@ -672,11 +682,11 @@ cram_md5 (char *secret, char *challenge, unsigned char *digest) | ... | @@ -672,11 +682,11 @@ cram_md5 (char *secret, char *challenge, unsigned char *digest) |
672 | static int | 682 | static int |
673 | smtp_auth (smtp_t smtp) | 683 | smtp_auth (smtp_t smtp) |
674 | { | 684 | { |
675 | int status; | 685 | int status; |
676 | mu_mailer_t mailer = smtp->mailer; | 686 | mu_mailer_t mailer = smtp->mailer; |
677 | struct auth_mech_record *mechs = auth_mech_list; | 687 | struct auth_mech_record *mechs = auth_mech_list; |
678 | const char *chosen_mech_name = NULL; | 688 | const char *chosen_mech_name = NULL; |
679 | int chosen_mech_id = 0; | 689 | int chosen_mech_id = 0; |
680 | 690 | ||
681 | status = mu_url_sget_auth (mailer->url, &chosen_mech_name); | 691 | status = mu_url_sget_auth (mailer->url, &chosen_mech_name); |
682 | if (status != MU_ERR_NOENT) | 692 | if (status != MU_ERR_NOENT) |
... | @@ -716,15 +726,16 @@ smtp_auth (smtp_t smtp) | ... | @@ -716,15 +726,16 @@ smtp_auth (smtp_t smtp) |
716 | 726 | ||
717 | if (smtp->auth_mechs & AUTH_CRAM_MD5) | 727 | if (smtp->auth_mechs & AUTH_CRAM_MD5) |
718 | { | 728 | { |
719 | int i; | 729 | int i; |
720 | char *p, *buf = NULL; | 730 | char *p, *buf = NULL; |
721 | const char *user = NULL; | 731 | const char *user = NULL; |
722 | mu_secret_t secret; | 732 | mu_secret_t secret; |
723 | unsigned char *chl; | 733 | unsigned char *chl; |
724 | size_t chlen, buflen = 0, b64buflen = 0; | 734 | size_t chlen, buflen = 0, b64buflen = 0; |
725 | unsigned char *b64buf = NULL; | 735 | unsigned char *b64buf = NULL; |
726 | unsigned char digest[16]; | 736 | unsigned char digest[16]; |
727 | static char ascii_digest[33]; | 737 | static char ascii_digest[33]; |
738 | |||
728 | memset (digest, 0, 16); | 739 | memset (digest, 0, 16); |
729 | 740 | ||
730 | status = mu_url_sget_user (mailer->url, &user); | 741 | status = mu_url_sget_user (mailer->url, &user); |
... | @@ -757,7 +768,7 @@ smtp_auth (smtp_t smtp) | ... | @@ -757,7 +768,7 @@ smtp_auth (smtp_t smtp) |
757 | mu_rtrim_cset (p, "\r\n"); | 768 | mu_rtrim_cset (p, "\r\n"); |
758 | mu_base64_decode (p, strlen (p), &chl, &chlen); | 769 | mu_base64_decode (p, strlen (p), &chl, &chlen); |
759 | 770 | ||
760 | cram_md5 ((char *)mu_secret_password (secret), chl, digest); | 771 | cram_md5 ((char *) mu_secret_password (secret), chl, digest); |
761 | mu_secret_password_unref (secret); | 772 | mu_secret_password_unref (secret); |
762 | free (chl); | 773 | free (chl); |
763 | 774 | ||
... | @@ -780,12 +791,12 @@ smtp_auth (smtp_t smtp) | ... | @@ -780,12 +791,12 @@ smtp_auth (smtp_t smtp) |
780 | 791 | ||
781 | else if (smtp->auth_mechs & AUTH_PLAIN) | 792 | else if (smtp->auth_mechs & AUTH_PLAIN) |
782 | { | 793 | { |
783 | int c; | 794 | int c; |
784 | char *buf = NULL; | 795 | char *buf = NULL; |
785 | unsigned char *b64buf = NULL; | 796 | unsigned char *b64buf = NULL; |
786 | size_t buflen = 0, b64buflen = 0; | 797 | size_t buflen = 0, b64buflen = 0; |
787 | const char *user = NULL; | 798 | const char *user = NULL; |
788 | mu_secret_t secret; | 799 | mu_secret_t secret; |
789 | 800 | ||
790 | status = mu_url_sget_user (mailer->url, &user); | 801 | status = mu_url_sget_user (mailer->url, &user); |
791 | if (status == MU_ERR_NOENT) | 802 | if (status == MU_ERR_NOENT) |
... | @@ -825,10 +836,11 @@ smtp_auth (smtp_t smtp) | ... | @@ -825,10 +836,11 @@ smtp_auth (smtp_t smtp) |
825 | } | 836 | } |
826 | 837 | ||
827 | static int | 838 | static int |
828 | message_set_header_value (mu_message_t msg, const char *field, const char *value) | 839 | message_set_header_value (mu_message_t msg, const char *field, |
840 | const char *value) | ||
829 | { | 841 | { |
830 | int status = 0; | 842 | int status = 0; |
831 | mu_header_t hdr = NULL; | 843 | mu_header_t hdr = NULL; |
832 | 844 | ||
833 | if ((status = mu_message_get_header (msg, &hdr))) | 845 | if ((status = mu_message_get_header (msg, &hdr))) |
834 | return status; | 846 | return status; |
... | @@ -842,9 +854,9 @@ message_set_header_value (mu_message_t msg, const char *field, const char *value | ... | @@ -842,9 +854,9 @@ message_set_header_value (mu_message_t msg, const char *field, const char *value |
842 | static int | 854 | static int |
843 | message_has_bcc (mu_message_t msg) | 855 | message_has_bcc (mu_message_t msg) |
844 | { | 856 | { |
845 | int status; | 857 | int status; |
846 | mu_header_t header = NULL; | 858 | mu_header_t header = NULL; |
847 | size_t bccsz = 0; | 859 | size_t bccsz = 0; |
848 | 860 | ||
849 | if ((status = mu_message_get_header (msg, &header))) | 861 | if ((status = mu_message_get_header (msg, &header))) |
850 | return status; | 862 | return status; |
... | @@ -895,11 +907,11 @@ The correct algorithm is | ... | @@ -895,11 +907,11 @@ The correct algorithm is |
895 | */ | 907 | */ |
896 | 908 | ||
897 | static int | 909 | static int |
898 | smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom, | 910 | smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, |
899 | mu_address_t argto) | 911 | mu_address_t argfrom, mu_address_t argto) |
900 | { | 912 | { |
901 | smtp_t smtp = NULL; | 913 | smtp_t smtp = NULL; |
902 | int status; | 914 | int status; |
903 | 915 | ||
904 | if (mailer == NULL) | 916 | if (mailer == NULL) |
905 | return EINVAL; | 917 | return EINVAL; |
... | @@ -948,7 +960,7 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom | ... | @@ -948,7 +960,7 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom |
948 | case SMTP_ENV_FROM: | 960 | case SMTP_ENV_FROM: |
949 | ENV_FROM: | 961 | ENV_FROM: |
950 | { | 962 | { |
951 | size_t size; | 963 | size_t size; |
952 | 964 | ||
953 | if ((smtp->capa & CAPA_SIZE) | 965 | if ((smtp->capa & CAPA_SIZE) |
954 | && mu_message_size (smtp->msg, &size) == 0) | 966 | && mu_message_size (smtp->msg, &size) == 0) |
... | @@ -983,8 +995,8 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom | ... | @@ -983,8 +995,8 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom |
983 | case SMTP_ENV_RCPT: | 995 | case SMTP_ENV_RCPT: |
984 | ENV_RCPT: | 996 | ENV_RCPT: |
985 | { | 997 | { |
986 | mu_address_t addr = smtp->rcpt_to; | 998 | mu_address_t addr = smtp->rcpt_to; |
987 | const char *to = NULL; | 999 | const char *to = NULL; |
988 | 1000 | ||
989 | if (smtp->bccing) | 1001 | if (smtp->bccing) |
990 | addr = smtp->rcpt_bcc; | 1002 | addr = smtp->rcpt_bcc; |
... | @@ -1052,13 +1064,13 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom | ... | @@ -1052,13 +1064,13 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom |
1052 | 1064 | ||
1053 | case SMTP_SEND: | 1065 | case SMTP_SEND: |
1054 | { | 1066 | { |
1055 | mu_stream_t stream; | 1067 | mu_stream_t stream; |
1056 | size_t n = 0; | 1068 | size_t n = 0; |
1057 | char data[256] = ""; | 1069 | char data[256] = ""; |
1058 | mu_header_t hdr; | 1070 | mu_header_t hdr; |
1059 | mu_body_t body; | 1071 | mu_body_t body; |
1060 | int found_nl; | 1072 | int found_nl; |
1061 | 1073 | ||
1062 | /* We may be here after an EAGAIN so check if we have something | 1074 | /* We may be here after an EAGAIN so check if we have something |
1063 | in the buffer and flush it. */ | 1075 | in the buffer and flush it. */ |
1064 | status = smtp_write (smtp); | 1076 | status = smtp_write (smtp); |
... | @@ -1067,10 +1079,10 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom | ... | @@ -1067,10 +1079,10 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom |
1067 | mu_message_get_header (smtp->msg, &hdr); | 1079 | mu_message_get_header (smtp->msg, &hdr); |
1068 | mu_header_get_stream (hdr, &stream); | 1080 | mu_header_get_stream (hdr, &stream); |
1069 | while ((status = mu_stream_readline (stream, data, sizeof (data), | 1081 | while ((status = mu_stream_readline (stream, data, sizeof (data), |
1070 | smtp->offset, &n)) == 0 && n > 0) | 1082 | smtp->offset, &n)) == 0 && n > 0) |
1071 | { | 1083 | { |
1072 | int nl; | 1084 | int nl; |
1073 | 1085 | ||
1074 | found_nl = (n == 1 && data[0] == '\n'); | 1086 | found_nl = (n == 1 && data[0] == '\n'); |
1075 | if ((nl = (data[n - 1] == '\n'))) | 1087 | if ((nl = (data[n - 1] == '\n'))) |
1076 | data[n - 1] = '\0'; | 1088 | data[n - 1] = '\0'; |
... | @@ -1089,7 +1101,7 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom | ... | @@ -1089,7 +1101,7 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom |
1089 | } | 1101 | } |
1090 | else | 1102 | else |
1091 | nl = 0; | 1103 | nl = 0; |
1092 | 1104 | ||
1093 | if (nl) | 1105 | if (nl) |
1094 | { | 1106 | { |
1095 | status = smtp_writeline (smtp, "\r\n"); | 1107 | status = smtp_writeline (smtp, "\r\n"); |
... | @@ -1099,7 +1111,7 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom | ... | @@ -1099,7 +1111,7 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom |
1099 | } | 1111 | } |
1100 | smtp->offset += n; | 1112 | smtp->offset += n; |
1101 | } | 1113 | } |
1102 | 1114 | ||
1103 | if (!found_nl) | 1115 | if (!found_nl) |
1104 | { | 1116 | { |
1105 | status = smtp_writeline (smtp, "\r\n"); | 1117 | status = smtp_writeline (smtp, "\r\n"); |
... | @@ -1107,12 +1119,12 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom | ... | @@ -1107,12 +1119,12 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom |
1107 | status = smtp_write (smtp); | 1119 | status = smtp_write (smtp); |
1108 | CHECK_EAGAIN (smtp, status); | 1120 | CHECK_EAGAIN (smtp, status); |
1109 | } | 1121 | } |
1110 | 1122 | ||
1111 | mu_message_get_body (smtp->msg, &body); | 1123 | mu_message_get_body (smtp->msg, &body); |
1112 | mu_body_get_stream (body, &stream); | 1124 | mu_body_get_stream (body, &stream); |
1113 | smtp->offset = 0; | 1125 | smtp->offset = 0; |
1114 | while ((status = mu_stream_readline (stream, data, sizeof (data) - 1, | 1126 | while ((status = mu_stream_readline (stream, data, sizeof (data) - 1, |
1115 | smtp->offset, &n)) == 0 && n > 0) | 1127 | smtp->offset, &n)) == 0 && n > 0) |
1116 | { | 1128 | { |
1117 | if (data[n - 1] == '\n') | 1129 | if (data[n - 1] == '\n') |
1118 | data[n - 1] = '\0'; | 1130 | data[n - 1] = '\0'; |
... | @@ -1125,7 +1137,7 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom | ... | @@ -1125,7 +1137,7 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom |
1125 | CHECK_EAGAIN (smtp, status); | 1137 | CHECK_EAGAIN (smtp, status); |
1126 | smtp->offset += n; | 1138 | smtp->offset += n; |
1127 | } | 1139 | } |
1128 | 1140 | ||
1129 | smtp->offset = 0; | 1141 | smtp->offset = 0; |
1130 | status = smtp_writeline (smtp, ".\r\n"); | 1142 | status = smtp_writeline (smtp, ".\r\n"); |
1131 | CHECK_ERROR (smtp, status); | 1143 | CHECK_ERROR (smtp, status); |
... | @@ -1168,10 +1180,10 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom | ... | @@ -1168,10 +1180,10 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom |
1168 | } | 1180 | } |
1169 | 1181 | ||
1170 | int | 1182 | int |
1171 | smtp_address_add (mu_address_t *paddr, const char *value) | 1183 | smtp_address_add (mu_address_t * paddr, const char *value) |
1172 | { | 1184 | { |
1173 | mu_address_t addr = NULL; | 1185 | mu_address_t addr = NULL; |
1174 | int status; | 1186 | int status; |
1175 | 1187 | ||
1176 | status = mu_address_create (&addr, value); | 1188 | status = mu_address_create (&addr, value); |
1177 | if (status) | 1189 | if (status) |
... | @@ -1184,7 +1196,7 @@ smtp_address_add (mu_address_t *paddr, const char *value) | ... | @@ -1184,7 +1196,7 @@ smtp_address_add (mu_address_t *paddr, const char *value) |
1184 | static int | 1196 | static int |
1185 | _smtp_property_is_set (smtp_t smtp, const char *name) | 1197 | _smtp_property_is_set (smtp_t smtp, const char *name) |
1186 | { | 1198 | { |
1187 | mu_property_t property = NULL; | 1199 | mu_property_t property = NULL; |
1188 | 1200 | ||
1189 | mu_mailer_get_property (smtp->mailer, &property); | 1201 | mu_mailer_get_property (smtp->mailer, &property); |
1190 | return mu_property_is_set (property, name); | 1202 | return mu_property_is_set (property, name); |
... | @@ -1193,9 +1205,9 @@ _smtp_property_is_set (smtp_t smtp, const char *name) | ... | @@ -1193,9 +1205,9 @@ _smtp_property_is_set (smtp_t smtp, const char *name) |
1193 | static int | 1205 | static int |
1194 | _smtp_set_rcpt (smtp_t smtp, mu_message_t msg, mu_address_t to) | 1206 | _smtp_set_rcpt (smtp_t smtp, mu_message_t msg, mu_address_t to) |
1195 | { | 1207 | { |
1196 | int status = 0; | 1208 | int status = 0; |
1197 | mu_header_t header = NULL; | 1209 | mu_header_t header = NULL; |
1198 | char *value; | 1210 | char *value; |
1199 | 1211 | ||
1200 | /* Get RCPT_TO from TO, or the message. */ | 1212 | /* Get RCPT_TO from TO, or the message. */ |
1201 | 1213 | ||
... | @@ -1205,7 +1217,7 @@ _smtp_set_rcpt (smtp_t smtp, mu_message_t msg, mu_address_t to) | ... | @@ -1205,7 +1217,7 @@ _smtp_set_rcpt (smtp_t smtp, mu_message_t msg, mu_address_t to) |
1205 | if ((status = mu_mailer_check_to (to)) != 0) | 1217 | if ((status = mu_mailer_check_to (to)) != 0) |
1206 | { | 1218 | { |
1207 | MU_DEBUG (smtp->mailer->debug, MU_DEBUG_ERROR, | 1219 | MU_DEBUG (smtp->mailer->debug, MU_DEBUG_ERROR, |
1208 | "mu_mailer_send_message(): explicit to not valid\n"); | 1220 | "mu_mailer_send_message(): explicit to not valid\n"); |
1209 | return status; | 1221 | return status; |
1210 | } | 1222 | } |
1211 | smtp->rcpt_to = to; | 1223 | smtp->rcpt_to = to; |
... | @@ -1256,7 +1268,7 @@ _smtp_set_rcpt (smtp_t smtp, mu_message_t msg, mu_address_t to) | ... | @@ -1256,7 +1268,7 @@ _smtp_set_rcpt (smtp_t smtp, mu_message_t msg, mu_address_t to) |
1256 | if (smtp->rcpt_bcc && (status = mu_mailer_check_to (smtp->rcpt_bcc))) | 1268 | if (smtp->rcpt_bcc && (status = mu_mailer_check_to (smtp->rcpt_bcc))) |
1257 | goto end; | 1269 | goto end; |
1258 | } | 1270 | } |
1259 | 1271 | ||
1260 | end: | 1272 | end: |
1261 | 1273 | ||
1262 | if (status) | 1274 | if (status) |
... | @@ -1287,9 +1299,9 @@ end: | ... | @@ -1287,9 +1299,9 @@ end: |
1287 | static int | 1299 | static int |
1288 | smtp_writeline (smtp_t smtp, const char *format, ...) | 1300 | smtp_writeline (smtp_t smtp, const char *format, ...) |
1289 | { | 1301 | { |
1290 | int len; | 1302 | int len; |
1291 | va_list ap; | 1303 | va_list ap; |
1292 | int done = 1; | 1304 | int done = 1; |
1293 | 1305 | ||
1294 | va_start (ap, format); | 1306 | va_start (ap, format); |
1295 | do | 1307 | do |
... | @@ -1298,8 +1310,9 @@ smtp_writeline (smtp_t smtp, const char *format, ...) | ... | @@ -1298,8 +1310,9 @@ smtp_writeline (smtp_t smtp, const char *format, ...) |
1298 | if (len < 0 || (len >= (int) smtp->buflen) | 1310 | if (len < 0 || (len >= (int) smtp->buflen) |
1299 | || !memchr (smtp->buffer, '\0', len + 1)) | 1311 | || !memchr (smtp->buffer, '\0', len + 1)) |
1300 | { | 1312 | { |
1301 | char *buffer = NULL; | 1313 | char *buffer = NULL; |
1302 | size_t buflen = smtp->buflen * 2; | 1314 | size_t buflen = smtp->buflen * 2; |
1315 | |||
1303 | buffer = realloc (smtp->buffer, buflen); | 1316 | buffer = realloc (smtp->buffer, buflen); |
1304 | if (smtp->buffer == NULL) | 1317 | if (smtp->buffer == NULL) |
1305 | return ENOMEM; | 1318 | return ENOMEM; |
... | @@ -1324,20 +1337,21 @@ smtp_writeline (smtp_t smtp, const char *format, ...) | ... | @@ -1324,20 +1337,21 @@ smtp_writeline (smtp_t smtp, const char *format, ...) |
1324 | MU_DEBUG2 (smtp->mailer->debug, MU_DEBUG_PROT, "> %.*s\n", len, | 1337 | MU_DEBUG2 (smtp->mailer->debug, MU_DEBUG_PROT, "> %.*s\n", len, |
1325 | smtp->buffer); | 1338 | smtp->buffer); |
1326 | } | 1339 | } |
1327 | 1340 | ||
1328 | return 0; | 1341 | return 0; |
1329 | } | 1342 | } |
1330 | 1343 | ||
1331 | static int | 1344 | static int |
1332 | smtp_write (smtp_t smtp) | 1345 | smtp_write (smtp_t smtp) |
1333 | { | 1346 | { |
1334 | int status = 0; | 1347 | int status = 0; |
1335 | size_t len; | 1348 | size_t len; |
1349 | |||
1336 | if (smtp->ptr > smtp->buffer) | 1350 | if (smtp->ptr > smtp->buffer) |
1337 | { | 1351 | { |
1338 | len = smtp->ptr - smtp->buffer; | 1352 | len = smtp->ptr - smtp->buffer; |
1339 | status = mu_stream_write (smtp->mailer->stream, smtp->buffer, len, | 1353 | status = mu_stream_write (smtp->mailer->stream, smtp->buffer, len, |
1340 | 0, &len); | 1354 | 0, &len); |
1341 | if (status == 0) | 1355 | if (status == 0) |
1342 | { | 1356 | { |
1343 | memmove (smtp->buffer, smtp->buffer + len, len); | 1357 | memmove (smtp->buffer, smtp->buffer + len, len); |
... | @@ -1355,8 +1369,8 @@ smtp_write (smtp_t smtp) | ... | @@ -1355,8 +1369,8 @@ smtp_write (smtp_t smtp) |
1355 | static int | 1369 | static int |
1356 | smtp_read_ack (smtp_t smtp) | 1370 | smtp_read_ack (smtp_t smtp) |
1357 | { | 1371 | { |
1358 | int status; | 1372 | int status; |
1359 | int multi; | 1373 | int multi; |
1360 | 1374 | ||
1361 | do | 1375 | do |
1362 | { | 1376 | { |
... | @@ -1377,8 +1391,8 @@ smtp_read_ack (smtp_t smtp) | ... | @@ -1377,8 +1391,8 @@ smtp_read_ack (smtp_t smtp) |
1377 | static int | 1391 | static int |
1378 | smtp_parse_ehlo_ack (smtp_t smtp) | 1392 | smtp_parse_ehlo_ack (smtp_t smtp) |
1379 | { | 1393 | { |
1380 | int status; | 1394 | int status; |
1381 | int multi; | 1395 | int multi; |
1382 | 1396 | ||
1383 | do | 1397 | do |
1384 | { | 1398 | { |
... | @@ -1386,48 +1400,52 @@ smtp_parse_ehlo_ack (smtp_t smtp) | ... | @@ -1386,48 +1400,52 @@ smtp_parse_ehlo_ack (smtp_t smtp) |
1386 | status = smtp_readline (smtp); | 1400 | status = smtp_readline (smtp); |
1387 | if ((smtp->ptr - smtp->buffer) > 4 && smtp->buffer[3] == '-') | 1401 | if ((smtp->ptr - smtp->buffer) > 4 && smtp->buffer[3] == '-') |
1388 | multi = 1; | 1402 | multi = 1; |
1389 | if (status == 0) { | 1403 | if (status == 0) |
1390 | smtp->ptr = smtp->buffer; | 1404 | { |
1391 | 1405 | smtp->ptr = smtp->buffer; | |
1392 | if (!mu_c_strncasecmp (smtp->buffer, "250-STARTTLS", 12)) | ||
1393 | smtp->capa |= CAPA_STARTTLS; | ||
1394 | else if (!mu_c_strncasecmp (smtp->buffer, "250-SIZE", 8)) | ||
1395 | { | ||
1396 | smtp->capa |= CAPA_SIZE; | ||
1397 | if (smtp->buffer[8] == '=') | ||
1398 | { | ||
1399 | char *p; | ||
1400 | size_t n = strtoul (smtp->buffer + 9, &p, 10); | ||
1401 | if (*p != '\n') | ||
1402 | MU_DEBUG1 (smtp->mailer->debug, MU_DEBUG_ERROR, | ||
1403 | "suspicious size declaration: %s", | ||
1404 | smtp->buffer); | ||
1405 | else | ||
1406 | smtp->max_size = n; | ||
1407 | } | ||
1408 | } | ||
1409 | else if (!mu_c_strncasecmp (smtp->buffer, "250-AUTH", 8)) | ||
1410 | { | ||
1411 | char *name, *s; | ||
1412 | smtp->capa |= CAPA_AUTH; | ||
1413 | 1406 | ||
1414 | for (name = strtok_r (smtp->buffer + 8, " ", &s); name; | 1407 | if (!mu_c_strncasecmp (smtp->buffer, "250-STARTTLS", 12)) |
1415 | name = strtok_r (NULL, " ", &s)) | 1408 | smtp->capa |= CAPA_STARTTLS; |
1416 | { | 1409 | else if (!mu_c_strncasecmp (smtp->buffer, "250-SIZE", 8)) |
1417 | struct auth_mech_record *mechs = auth_mech_list; | 1410 | { |
1418 | for (; mechs->name; mechs++) | 1411 | smtp->capa |= CAPA_SIZE; |
1419 | { | 1412 | if (smtp->buffer[8] == '=') |
1420 | mu_rtrim_cset (name, "\r\n"); | 1413 | { |
1421 | if (!mu_c_strcasecmp (mechs->name, name)) | 1414 | char *p; |
1422 | { | 1415 | size_t n = strtoul (smtp->buffer + 9, &p, 10); |
1423 | smtp->auth_mechs |= mechs->id; | 1416 | |
1424 | break; | 1417 | if (*p != '\n') |
1425 | } | 1418 | MU_DEBUG1 (smtp->mailer->debug, MU_DEBUG_ERROR, |
1426 | } | 1419 | "suspicious size declaration: %s", |
1427 | } | 1420 | smtp->buffer); |
1428 | } | 1421 | else |
1422 | smtp->max_size = n; | ||
1423 | } | ||
1424 | } | ||
1425 | else if (!mu_c_strncasecmp (smtp->buffer, "250-AUTH", 8)) | ||
1426 | { | ||
1427 | char *name, *s; | ||
1428 | |||
1429 | smtp->capa |= CAPA_AUTH; | ||
1430 | |||
1431 | for (name = strtok_r (smtp->buffer + 8, " ", &s); name; | ||
1432 | name = strtok_r (NULL, " ", &s)) | ||
1433 | { | ||
1434 | struct auth_mech_record *mechs = auth_mech_list; | ||
1435 | |||
1436 | for (; mechs->name; mechs++) | ||
1437 | { | ||
1438 | mu_rtrim_cset (name, "\r\n"); | ||
1439 | if (!mu_c_strcasecmp (mechs->name, name)) | ||
1440 | { | ||
1441 | smtp->auth_mechs |= mechs->id; | ||
1442 | break; | ||
1443 | } | ||
1444 | } | ||
1445 | } | ||
1446 | } | ||
1429 | 1447 | ||
1430 | } | 1448 | } |
1431 | } | 1449 | } |
1432 | while (multi && status == 0); | 1450 | while (multi && status == 0); |
1433 | 1451 | ||
... | @@ -1441,15 +1459,15 @@ smtp_parse_ehlo_ack (smtp_t smtp) | ... | @@ -1441,15 +1459,15 @@ smtp_parse_ehlo_ack (smtp_t smtp) |
1441 | static int | 1459 | static int |
1442 | smtp_readline (smtp_t smtp) | 1460 | smtp_readline (smtp_t smtp) |
1443 | { | 1461 | { |
1444 | size_t n = 0; | 1462 | size_t n = 0; |
1445 | size_t total = smtp->ptr - smtp->buffer; | 1463 | size_t total = smtp->ptr - smtp->buffer; |
1446 | int status; | 1464 | int status; |
1447 | 1465 | ||
1448 | /* Must get a full line before bailing out. */ | 1466 | /* Must get a full line before bailing out. */ |
1449 | do | 1467 | do |
1450 | { | 1468 | { |
1451 | status = mu_stream_readline (smtp->mailer->stream, smtp->buffer + total, | 1469 | status = mu_stream_readline (smtp->mailer->stream, smtp->buffer + total, |
1452 | smtp->buflen - total, smtp->s_offset, &n); | 1470 | smtp->buflen - total, smtp->s_offset, &n); |
1453 | if (status != 0) | 1471 | if (status != 0) |
1454 | return status; | 1472 | return status; |
1455 | 1473 | ||
... | @@ -1491,6 +1509,6 @@ smtp_readline (smtp_t smtp) | ... | @@ -1491,6 +1509,6 @@ smtp_readline (smtp_t smtp) |
1491 | #else | 1509 | #else |
1492 | #include <stdio.h> | 1510 | #include <stdio.h> |
1493 | #include <registrar0.h> | 1511 | #include <registrar0.h> |
1494 | mu_record_t mu_smtp_record = NULL; | 1512 | mu_record_t mu_smtp_record = NULL; |
1495 | mu_record_t mu_remote_smtp_record = NULL; | 1513 | mu_record_t mu_remote_smtp_record = NULL; |
1496 | #endif | 1514 | #endif | ... | ... |
-
Please register or sign in to post a comment