diff options
Diffstat (limited to 'pop3d/extra.c')
-rw-r--r-- | pop3d/extra.c | 111 |
1 files changed, 54 insertions, 57 deletions
diff --git a/pop3d/extra.c b/pop3d/extra.c index c2d5f2cd4..608e67040 100644 --- a/pop3d/extra.c +++ b/pop3d/extra.c @@ -1,5 +1,5 @@ /* GNU Mailutils -- a suite of utilities for electronic mail - Copyright (C) 1999-2019 Free Software Foundation, Inc. + Copyright (C) 1999-2024 Free Software Foundation, Inc. GNU Mailutils is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -74,6 +74,7 @@ pop3d_abquit (int reason) case ERR_TIMEOUT: code = EX_TEMPFAIL; + mu_stream_clearerr (iostream); pop3d_outf ("-ERR %s\n", pop3d_error_string (reason)); if (state == TRANSACTION) mu_diag_output (MU_DIAG_INFO, _("session timed out for user: %s"), @@ -111,8 +112,7 @@ pop3d_abquit (int reason) mu_diag_output (MU_DIAG_ERROR, _("mailbox was updated by other party: %s"), username); - pop3d_outf - ("-ERR [OUT-SYNC] Mailbox updated by other party or corrupt\n"); + pop3d_outf ("-ERR [OUT-SYNC] Mailbox updated by other party or corrupted\n"); break; default: @@ -160,50 +160,54 @@ void pop3d_setio (int ifd, int ofd, struct mu_tls_config *tls_conf) { mu_stream_t str, istream, ostream; + int rc; if (ifd == -1) pop3d_abquit (ERR_NO_IFILE); if (ofd == -1) pop3d_abquit (ERR_NO_OFILE); - if (mu_stdio_stream_create (&istream, ifd, MU_STREAM_READ)) - pop3d_abquit (ERR_NO_IFILE); - mu_stream_set_buffer (istream, mu_buffer_line, 0); - - if (mu_stdio_stream_create (&ostream, ofd, MU_STREAM_WRITE)) - pop3d_abquit (ERR_NO_OFILE); - - /* Combine the two streams into an I/O one. */ if (tls_conf) { - int rc = mu_tls_stream_create (&str, istream, ostream, - tls_conf, - MU_TLS_SERVER, - 0); + rc = mu_tlsfd_stream_create (&str, ifd, ofd, tls_conf, MU_TLS_SERVER); if (rc) { - mu_stream_unref (istream); - mu_stream_unref (ostream); mu_error (_("failed to create TLS stream: %s"), mu_strerror (rc)); pop3d_abquit (ERR_FILE); } log_cipher (str); } - else if (mu_iostream_create (&str, istream, ostream)) - pop3d_abquit (ERR_FILE); + else + { + if (mu_stdio_stream_create (&istream, ifd, MU_STREAM_READ)) + pop3d_abquit (ERR_FILE); + mu_stream_set_buffer (istream, mu_buffer_line, 0); + + if (mu_stdio_stream_create (&ostream, ofd, MU_STREAM_WRITE)) + pop3d_abquit (ERR_FILE); + mu_stream_set_buffer (ostream, mu_buffer_line, 0); + + /* Combine the two streams into an I/O one. */ + if (mu_iostream_create (&str, istream, ostream)) + pop3d_abquit (ERR_FILE); + mu_stream_unref (istream); + mu_stream_unref (ostream); + } + /* Convert all writes to CRLF form. There is no need to convert reads, as the code ignores extra \r anyway. */ - if (mu_filter_create (&iostream, str, "CRLF", MU_FILTER_ENCODE, - MU_STREAM_WRITE | MU_STREAM_RDTHRU)) - pop3d_abquit (ERR_NO_IFILE); + rc = mu_filter_create (&iostream, str, "CRLF", MU_FILTER_ENCODE, + MU_STREAM_WRITE | MU_STREAM_RDTHRU); + mu_stream_unref (str); + if (rc) + pop3d_abquit (ERR_FILE); /* Change buffering scheme: filter streams are fully buffered by default. */ mu_stream_set_buffer (iostream, mu_buffer_line, 0); if (pop3d_transcript) { - int rc; mu_stream_t dstr, xstr; rc = mu_dbgstream_create (&dstr, MU_DIAG_DEBUG); @@ -229,43 +233,22 @@ pop3d_setio (int ifd, int ofd, struct mu_tls_config *tls_conf) int pop3d_init_tls_server (struct mu_tls_config *tls_conf) { - mu_stream_t tlsstream, stream[2]; int rc; - - rc = mu_stream_ioctl (iostream, MU_IOCTL_SUBSTREAM, MU_IOCTL_OP_GET, stream); - if (rc) - { - mu_error (_("%s failed: %s"), "MU_IOCTL_GET_STREAM", - mu_stream_strerror (iostream, rc)); - return 1; - } - rc = mu_tls_stream_create (&tlsstream, stream[0], stream[1], - tls_conf, - MU_TLS_SERVER, - 0); - mu_stream_unref (stream[0]); - mu_stream_unref (stream[1]); - if (rc) - return 1; - - log_cipher (tlsstream); - - stream[0] = stream[1] = tlsstream; - rc = mu_stream_ioctl (iostream, MU_IOCTL_SUBSTREAM, MU_IOCTL_OP_SET, stream); - mu_stream_unref (stream[0]); - mu_stream_unref (stream[1]); - if (rc) + rc = mu_starttls (&iostream, tls_conf, MU_TLS_SERVER); + if (rc == 0) + log_cipher (iostream); + else { - mu_error (_("%s failed: %s"), "MU_IOCTL_SET_STREAM", - mu_stream_strerror (iostream, rc)); - pop3d_abquit (ERR_IO); + mu_diag_funcall (MU_DIAG_ERROR, "mu_starttls", NULL, rc); + if (rc == MU_ERR_TRANSPORT_SET) + pop3d_abquit (ERR_FILE); } - return 0; + return rc; } void -pop3d_bye () +pop3d_bye (void) { mu_stream_close (iostream); mu_stream_destroy (&iostream); @@ -306,12 +289,26 @@ pop3d_readline (char *buffer, size_t size) { int rc; size_t nbytes; + struct timeval tv, *to; + + if (idle_timeout) + { + tv.tv_sec = idle_timeout; + tv.tv_usec = 0; + to = &tv; + } + else + to = NULL; - alarm (idle_timeout); - rc = mu_stream_readline (iostream, buffer, size, &nbytes); - alarm (0); + rc = mu_stream_timed_readline (iostream, buffer, size, to, &nbytes); - if (rc) + if (rc == MU_ERR_TIMEOUT) + { + mu_diag_output (MU_DIAG_ERROR, "%s", _("Read time out")); + mu_stream_clearerr (iostream); + pop3d_abquit (ERR_TIMEOUT); + } + else if (rc) { mu_diag_output (MU_DIAG_ERROR, _("Read failed: %s"), mu_stream_strerror (iostream, rc)); |