summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-09-05 12:38:20 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2010-09-05 12:38:20 +0300
commit084fa368c2e22216c5fcca8afeb2ee145948caaa (patch)
treee4a5b9f56f0d5c624b768dc3b431d1013887becf
parenta08bf28c50373eb68b18f7537d8eac8746da4097 (diff)
downloadmailutils-084fa368c2e22216c5fcca8afeb2ee145948caaa.tar.gz
mailutils-084fa368c2e22216c5fcca8afeb2ee145948caaa.tar.bz2
Fix TLS support in smtp.
* include/mailutils/tls.h (mu_tls_readline_fn) (mu_tls_writeline_fn, mu_tls_stream_ctl_fn): Remove typedefs. (mu_tls_begin): Remove prototype. * libmu_auth/tls.c (mu_tls_begin): Remove function. * libproto/mailer/smtp.c: Revamp STARTTLS support.
-rw-r--r--include/mailutils/tls.h13
-rw-r--r--libmu_auth/tls.c88
-rw-r--r--libproto/mailer/smtp.c62
3 files changed, 18 insertions, 145 deletions
diff --git a/include/mailutils/tls.h b/include/mailutils/tls.h
index 41a5234f4..dc630a20e 100644
--- a/include/mailutils/tls.h
+++ b/include/mailutils/tls.h
@@ -47,19 +47,6 @@ extern int mu_check_tls_environment (void);
extern int mu_init_tls_libs (void);
extern void mu_deinit_tls_libs (void);
-typedef int (*mu_tls_readline_fn) (void *iodata, int n);
-typedef int (*mu_tls_writeline_fn) (void *iodata, char *buf);
-
-#define MU_TLS_SESS_GET_STREAMS 0
-#define MU_TLS_SESS_SET_STREAMS 1
-typedef int (*mu_tls_stream_ctl_fn) (void *iodata, int __op,
- mu_stream_t *pstr);
-
-extern int mu_tls_begin (void *iodata, mu_tls_readline_fn reader,
- mu_tls_writeline_fn writer,
- mu_tls_stream_ctl_fn stream_ctl,
- char *keywords[]);
-
extern int mu_tls_enable;
#ifdef __cplusplus
diff --git a/libmu_auth/tls.c b/libmu_auth/tls.c
index 3b89baca1..2d3bd817a 100644
--- a/libmu_auth/tls.c
+++ b/libmu_auth/tls.c
@@ -164,94 +164,6 @@ initialize_tls_session (void)
return session;
}
-int
-mu_tls_begin (void *iodata,
- mu_tls_readline_fn reader,
- mu_tls_writeline_fn writer,
- mu_tls_stream_ctl_fn stream_ctl,
- char *keywords[])
-{
- int i = 0;
- int status;
- mu_stream_t streams[2], newstr;
-
- if (keywords == NULL)
- return EINVAL;
-
- for (i = 0; keywords[i]; i++)
- {
- switch (i)
- {
- case 0:
- /*
- * Send STLS/STARTTLS
- */
- status = writer (iodata, keywords[i]);
- if (status != 0)
- {
- mu_error ("mu_tls_begin: writer (0): %s", mu_strerror (status));
- return status;
- }
-
- status = reader (iodata, i);
- if (status != 0)
- {
- mu_error ("mu_tls_begin: reader (0): %s", mu_strerror (status));
- return status;
- }
-
- status = stream_ctl (iodata, MU_TLS_SESS_GET_STREAMS, streams);
- if (status)
- return status;
- status = mu_tls_client_stream_create (&newstr,
- streams[0], streams[1], 0);
- if (status != 0)
- {
- mu_error ("mu_tls_begin: mu_tls_client_stream_create(0): %s",
- mu_strerror (status));
- stream_ctl (iodata, MU_TLS_SESS_SET_STREAMS, streams);
- return status;
- }
-
- status = mu_stream_open (newstr);
- if (status != 0)
- {
- mu_error ("mu_tls_begin: mu_stream_open (0): %s",
- mu_strerror (status));
- stream_ctl (iodata, MU_TLS_SESS_SET_STREAMS, streams);
- return status;
- }
-
- streams[0] = streams[1] = newstr;
- stream_ctl (iodata, MU_TLS_SESS_SET_STREAMS, streams);
- /* FIXME: Unref newstr */
- break;
-
- case 1:
- /*
- * Send CAPABILITIES request
- */
- status = writer (iodata, keywords[i]);
- if (status != 0)
- {
- mu_error ("mu_tls_begin: writer (1): %s", mu_strerror (status));
- return status;
- }
-
- status = reader (iodata, i);
- if (status != 0)
- {
- mu_error ("mu_tls_begin: reader (1): %s", mu_strerror (status));
- return status;
- }
- break;
-
- default:
- return 1;
- }
- }
- return 0;
-}
/* ************************* TLS Stream Support **************************** */
diff --git a/libproto/mailer/smtp.c b/libproto/mailer/smtp.c
index 5fb70f903..31b725f3f 100644
--- a/libproto/mailer/smtp.c
+++ b/libproto/mailer/smtp.c
@@ -554,68 +554,40 @@ smtp_close (mu_mailer_t mailer)
return mu_stream_close (mailer->stream);
}
-#ifdef WITH_TLS
/*
Client side STARTTLS support.
*/
static int
-smtp_reader (void *iodata)
-{
- int status = 0;
- smtp_t iop = iodata;
-
- status = smtp_read_ack (iop);
- CHECK_EAGAIN (iop, status);
- return status;
-}
-
-static int
-smtp_writer (void *iodata, char *buf)
-{
- smtp_t iop = iodata;
- int status;
-
- if (mu_c_strncasecmp (buf, "EHLO", 4) == 0)
- status = smtp_writeline (iop, "%s %s\r\n", buf, iop->localhost);
- else
- status = smtp_writeline (iop, "%s\r\n", buf);
- CHECK_ERROR (iop, status);
- status = smtp_write (iop);
- CHECK_EAGAIN (iop, status);
- return status;
-}
-
-static void
-smtp_stream_ctl (void *iodata, mu_stream_t * pold, mu_stream_t new)
-{
- smtp_t iop = iodata;
-
- if (pold)
- *pold = iop->mailer->stream;
- if (new)
- iop->mailer->stream = new;
-}
-#endif
-
-static int
smtp_starttls (smtp_t smtp)
{
#ifdef WITH_TLS
int status;
mu_mailer_t mailer = smtp->mailer;
- char *keywords[] = { "STARTTLS", NULL };
-
+ mu_stream_t newstr;
+
if (!mu_tls_enable || !(smtp->capa & CAPA_STARTTLS))
return -1;
smtp->capa = 0;
smtp->auth_mechs = 0;
- status = mu_tls_begin (smtp, smtp_reader, smtp_writer,
- smtp_stream_ctl, keywords);
+ status = smtp_writeline (smtp, "STARTTLS\r\n");
+ CHECK_ERROR (smtp, status);
+ status = smtp_write (smtp);
+ CHECK_EAGAIN (smtp, status);
+ status = smtp_read_ack (smtp);
+ CHECK_ERROR (smtp, status);
+ mu_stream_flush (mailer->stream);
+ status = mu_tls_client_stream_create (&newstr, mailer->stream,
+ mailer->stream, 0);
+ CHECK_ERROR (smtp, status);
+ status = mu_stream_open (newstr);
MU_DEBUG1 (mailer->debug, MU_DEBUG_PROT, "TLS negotiation %s\n",
status == 0 ? "succeeded" : "failed");
+ CHECK_ERROR (smtp, status);
+
+ mailer->stream = newstr;
return status;
#else
@@ -1399,6 +1371,8 @@ smtp_parse_ehlo_ack (smtp_t smtp)
int status;
int multi;
+ smtp->ptr = smtp->buffer;
+
do
{
multi = 0;

Return to:

Send suggestions and report system problems to the System administrator.