(pop_parse_capa): New function.
(pop_capa): Send CAPA, but don't parse the response, call pop_parse_capa() instead. (pop_reader, pop_writer, pop_stream_ctl): New static functions. (pop_stls): Uses now mu_tls_begin() from libmuauth.
Showing
1 changed file
with
68 additions
and
43 deletions
... | @@ -406,31 +406,16 @@ pop_destroy (mu_mailbox_t mbox) | ... | @@ -406,31 +406,16 @@ pop_destroy (mu_mailbox_t mbox) |
406 | */ | 406 | */ |
407 | 407 | ||
408 | static int | 408 | static int |
409 | pop_capa (mu_mailbox_t mbox) | 409 | pop_parse_capa (pop_data_t mpd) |
410 | { | 410 | { |
411 | pop_data_t mpd = mbox->data; | ||
412 | int status; | 411 | int status; |
413 | |||
414 | status = pop_writeline (mpd, "CAPA\r\n"); | ||
415 | CHECK_ERROR (mpd, status); | ||
416 | MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer); | ||
417 | |||
418 | status = pop_write (mpd); | ||
419 | CHECK_EAGAIN (mpd, status); | ||
420 | mpd->state = POP_CAPA_ACK; | ||
421 | |||
422 | /* POP_CAPA_ACK */ | ||
423 | status = pop_read_ack (mpd); | ||
424 | CHECK_EAGAIN (mpd, status); | ||
425 | MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer); | ||
426 | |||
427 | if (!strncasecmp (mpd->buffer, "+OK", 3)) | 412 | if (!strncasecmp (mpd->buffer, "+OK", 3)) |
428 | { | 413 | { |
429 | mpd->capa = 0; | 414 | mpd->capa = 0; |
430 | do | 415 | do |
431 | { | 416 | { |
432 | status = pop_read_ack (mpd); | 417 | status = pop_read_ack (mpd); |
433 | MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer); | 418 | MAILBOX_DEBUG0 (mpd->mbox, MU_DEBUG_PROT, mpd->buffer); |
434 | 419 | ||
435 | /* Here we check some common capabilities like TOP, USER, UIDL, | 420 | /* Here we check some common capabilities like TOP, USER, UIDL, |
436 | and STLS. The rest are ignored. Please note that some | 421 | and STLS. The rest are ignored. Please note that some |
... | @@ -462,6 +447,29 @@ pop_capa (mu_mailbox_t mbox) | ... | @@ -462,6 +447,29 @@ pop_capa (mu_mailbox_t mbox) |
462 | } | 447 | } |
463 | } | 448 | } |
464 | 449 | ||
450 | static int | ||
451 | pop_capa (mu_mailbox_t mbox) | ||
452 | { | ||
453 | pop_data_t mpd = mbox->data; | ||
454 | int status; | ||
455 | |||
456 | status = pop_writeline (mpd, "CAPA\r\n"); | ||
457 | CHECK_ERROR (mpd, status); | ||
458 | MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer); | ||
459 | |||
460 | status = pop_write (mpd); | ||
461 | CHECK_EAGAIN (mpd, status); | ||
462 | mpd->state = POP_CAPA_ACK; | ||
463 | |||
464 | /* POP_CAPA_ACK */ | ||
465 | status = pop_read_ack (mpd); | ||
466 | CHECK_EAGAIN (mpd, status); | ||
467 | MAILBOX_DEBUG0 (mpd->mbox, MU_DEBUG_PROT, mpd->buffer); | ||
468 | |||
469 | return pop_parse_capa (mpd); | ||
470 | } | ||
471 | |||
472 | |||
465 | /* Simple User/pass authentication for pop. We ask for the info | 473 | /* Simple User/pass authentication for pop. We ask for the info |
466 | from the standard input. */ | 474 | from the standard input. */ |
467 | int | 475 | int |
... | @@ -635,39 +643,58 @@ _pop_apop (mu_authority_t auth) | ... | @@ -635,39 +643,58 @@ _pop_apop (mu_authority_t auth) |
635 | */ | 643 | */ |
636 | 644 | ||
637 | static int | 645 | static int |
646 | pop_reader (void *iodata) | ||
647 | { | ||
648 | int status = 0; | ||
649 | pop_data_t iop = iodata; | ||
650 | status = pop_read_ack (iop); | ||
651 | CHECK_EAGAIN (iop, status); | ||
652 | MAILBOX_DEBUG0 (iop->mbox, MU_DEBUG_PROT, iop->buffer); | ||
653 | return status;//strncasecmp (iop->buffer, "+OK", 3) == 0; | ||
654 | } | ||
655 | |||
656 | static int | ||
657 | pop_writer (void *iodata, char *buf) | ||
658 | { | ||
659 | pop_data_t iop = iodata; | ||
660 | MAILBOX_DEBUG1 (iop->mbox, MU_DEBUG_PROT, "%s\n", buf); | ||
661 | int status = pop_writeline (iop, "%s\r\n", buf); | ||
662 | CHECK_ERROR (iop, status); | ||
663 | status = pop_write (iop); | ||
664 | CHECK_ERROR (iop, status); | ||
665 | return status; | ||
666 | } | ||
667 | |||
668 | static void | ||
669 | pop_stream_ctl (void *iodata, mu_stream_t *pold, mu_stream_t new) | ||
670 | { | ||
671 | pop_data_t iop = iodata; | ||
672 | if (pold) | ||
673 | *pold = iop->mbox->stream; | ||
674 | if (new) | ||
675 | iop->mbox->stream = new; | ||
676 | } | ||
677 | |||
678 | static int | ||
638 | pop_stls (mu_mailbox_t mbox) | 679 | pop_stls (mu_mailbox_t mbox) |
639 | { | 680 | { |
640 | #ifdef WITH_TLS | 681 | #ifdef WITH_TLS |
641 | pop_data_t mpd = mbox->data; | ||
642 | int status; | 682 | int status; |
643 | mu_stream_t str; | 683 | pop_data_t mpd = mbox->data; |
684 | char *keywords[] = { "STLS", "CAPA", NULL }; | ||
644 | 685 | ||
645 | if (!mu_tls_enable || !(mpd->capa & CAPA_STLS)) | 686 | if (!mu_tls_enable || !(mpd->capa & CAPA_STLS)) |
646 | return -1; | 687 | return -1; |
647 | 688 | ||
648 | status = pop_writeline (mpd, "STLS\r\n"); | 689 | status = mu_tls_begin (mpd, pop_reader, pop_writer, |
649 | CHECK_ERROR (mpd, status); | 690 | pop_stream_ctl, keywords); |
650 | MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer); | ||
651 | |||
652 | status = pop_write (mpd); | ||
653 | CHECK_EAGAIN (mpd, status); | ||
654 | mpd->state = POP_STLS_ACK; | ||
655 | |||
656 | /* POP_STLS_ACK */ | ||
657 | status = pop_read_ack (mpd); | ||
658 | CHECK_ERROR (mpd, status); | ||
659 | MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer); | ||
660 | |||
661 | if (strncasecmp (mpd->buffer, "+OK", 3) != 0) | ||
662 | return -1; | ||
663 | 691 | ||
664 | status = mu_tls_stream_create_client_from_tcp (&str, mbox->stream, 0); | ||
665 | CHECK_ERROR (mpd, status); | ||
666 | status = mu_stream_open (str); | ||
667 | if (status == 0) | ||
668 | mbox->stream = str; | ||
669 | MAILBOX_DEBUG1 (mbox, MU_DEBUG_PROT, "TLS negotiation %s\n", | 692 | MAILBOX_DEBUG1 (mbox, MU_DEBUG_PROT, "TLS negotiation %s\n", |
670 | status == 0 ? "succeeded" : "failed"); | 693 | status == 0 ? "succeeded" : "failed"); |
694 | |||
695 | if (status == 0) | ||
696 | pop_parse_capa (mpd); | ||
697 | |||
671 | return status; | 698 | return status; |
672 | #else | 699 | #else |
673 | return -1; | 700 | return -1; |
... | @@ -745,7 +772,7 @@ pop_open (mu_mailbox_t mbox, int flags) | ... | @@ -745,7 +772,7 @@ pop_open (mu_mailbox_t mbox, int flags) |
745 | 772 | ||
746 | case POP_OPEN_CONNECTION: | 773 | case POP_OPEN_CONNECTION: |
747 | /* Establish the connection. */ | 774 | /* Establish the connection. */ |
748 | MAILBOX_DEBUG2 (mbox, MU_DEBUG_PROT, "open (%s:%d)\n", host, port); | 775 | MAILBOX_DEBUG2 (mbox, MU_DEBUG_PROT, "open (%s:%ld)\n", host, port); |
749 | status = mu_stream_open (mbox->stream); | 776 | status = mu_stream_open (mbox->stream); |
750 | CHECK_EAGAIN (mpd, status); | 777 | CHECK_EAGAIN (mpd, status); |
751 | /* Can't recover bailout. */ | 778 | /* Can't recover bailout. */ |
... | @@ -779,9 +806,7 @@ pop_open (mu_mailbox_t mbox, int flags) | ... | @@ -779,9 +806,7 @@ pop_open (mu_mailbox_t mbox, int flags) |
779 | 806 | ||
780 | case POP_STLS: | 807 | case POP_STLS: |
781 | case POP_STLS_ACK: | 808 | case POP_STLS_ACK: |
782 | status = pop_stls (mbox); | 809 | pop_stls (mbox); |
783 | if (status == 0) | ||
784 | pop_capa (mbox); | ||
785 | mpd->state = POP_AUTH; | 810 | mpd->state = POP_AUTH; |
786 | 811 | ||
787 | case POP_AUTH: | 812 | case POP_AUTH: | ... | ... |
-
Please register or sign in to post a comment