From 5c1feaf572129655ab9afee7e68d6d1c44c08c9c Mon Sep 17 00:00:00 2001 From: Eric Faurot Date: Fri, 4 Apr 2014 16:10:43 +0000 Subject: Merge the mda, mta and smtp processes into a single unprivileged process managing message reception, delivery and transfer. Mostly mechanical, but very intrusive as it required to rewamp all IMSG to fix ambiguities. with and ok gilles@ --- usr.sbin/smtpd/mta_session.c | 59 +++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 28 deletions(-) (limited to 'usr.sbin/smtpd/mta_session.c') diff --git a/usr.sbin/smtpd/mta_session.c b/usr.sbin/smtpd/mta_session.c index 60cef17c941..8f304cad319 100644 --- a/usr.sbin/smtpd/mta_session.c +++ b/usr.sbin/smtpd/mta_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mta_session.c,v 1.57 2014/03/02 21:19:36 gilles Exp $ */ +/* $OpenBSD: mta_session.c,v 1.58 2014/04/04 16:10:42 eric Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard @@ -231,7 +231,10 @@ mta_session(struct mta_relay *relay, struct mta_route *route) evtimer_set(&s->io.ev, mta_start, s); evtimer_add(&s->io.ev, &tv); } else if (waitq_wait(&route->dst->ptrname, mta_on_ptr, s)) { - dns_query_ptr(s->id, s->route->dst->sa); + m_create(p_lka, IMSG_MTA_DNS_PTR, 0, 0, -1); + m_add_id(p_lka, s->id); + m_add_sockaddr(p_lka, s->route->dst->sa); + m_close(p_lka); tree_xset(&wait_ptr, s->id, s); s->flags |= MTA_WAIT; } @@ -252,7 +255,7 @@ mta_session_imsg(struct mproc *p, struct imsg *imsg) switch (imsg->hdr.type) { - case IMSG_QUEUE_MESSAGE_FD: + case IMSG_MTA_OPEN_MESSAGE: m_msg(&m, imsg); m_get_id(&m, &reqid); m_end(&m); @@ -266,7 +269,7 @@ mta_session_imsg(struct mproc *p, struct imsg *imsg) if (imsg->fd == -1) { log_debug("debug: mta: failed to obtain msg fd"); - mta_flush_task(s, IMSG_DELIVERY_TEMPFAIL, + mta_flush_task(s, IMSG_MTA_DELIVERY_TEMPFAIL, "Could not get message fd", 0, 0); mta_enter_state(s, MTA_READY); io_reload(&s->io); @@ -281,7 +284,7 @@ mta_session_imsg(struct mproc *p, struct imsg *imsg) log_debug("debug: mta: loop detected"); fclose(s->datafp); s->datafp = NULL; - mta_flush_task(s, IMSG_DELIVERY_LOOP, + mta_flush_task(s, IMSG_MTA_DELIVERY_LOOP, "Loop detected", 0, 0); mta_enter_state(s, MTA_READY); } else { @@ -290,7 +293,7 @@ mta_session_imsg(struct mproc *p, struct imsg *imsg) io_reload(&s->io); return; - case IMSG_DNS_PTR: + case IMSG_MTA_DNS_PTR: m_msg(&m, imsg); m_get_id(&m, &reqid); m_get_int(&m, &dnserror); @@ -310,7 +313,7 @@ mta_session_imsg(struct mproc *p, struct imsg *imsg) waitq_run(&h->ptrname, h->ptrname); return; - case IMSG_LKA_SSL_INIT: + case IMSG_MTA_SSL_INIT: resp_ca_cert = imsg->data; s = mta_tree_pop(&wait_ssl_init, resp_ca_cert->reqid); if (s == NULL) @@ -351,7 +354,7 @@ mta_session_imsg(struct mproc *p, struct imsg *imsg) free(resp_ca_cert); return; - case IMSG_LKA_SSL_VERIFY: + case IMSG_MTA_SSL_VERIFY: resp_ca_vrfy = imsg->data; s = mta_tree_pop(&wait_ssl_verify, resp_ca_vrfy->reqid); if (s == NULL) @@ -371,7 +374,7 @@ mta_session_imsg(struct mproc *p, struct imsg *imsg) io_reload(&s->io); return; - case IMSG_LKA_HELO: + case IMSG_MTA_LOOKUP_HELO: m_msg(&m, imsg); m_get_id(&m, &reqid); m_get_int(&m, &status); @@ -488,7 +491,7 @@ mta_connect(struct mta_session *s) if (s->helo == NULL) { if (s->relay->helotable && s->route->src->sa) { - m_create(p_lka, IMSG_LKA_HELO, 0, 0, -1); + m_create(p_lka, IMSG_MTA_LOOKUP_HELO, 0, 0, -1); m_add_id(p_lka, s->id); m_add_string(p_lka, s->relay->helotable); m_add_sockaddr(p_lka, s->route->src->sa); @@ -754,7 +757,7 @@ mta_enter_state(struct mta_session *s, int newstate) stat_increment("mta.task.running", 1); - m_create(p_queue, IMSG_QUEUE_MESSAGE_FD, 0, 0, -1); + m_create(p_queue, IMSG_MTA_OPEN_MESSAGE, 0, 0, -1); m_add_id(p_queue, s->id); m_add_msgid(p_queue, s->task->msgid); m_close(p_queue); @@ -963,9 +966,9 @@ mta_response(struct mta_session *s, char *line) case MTA_MAIL: if (line[0] != '2') { if (line[0] == '5') - delivery = IMSG_DELIVERY_PERMFAIL; + delivery = IMSG_MTA_DELIVERY_PERMFAIL; else - delivery = IMSG_DELIVERY_TEMPFAIL; + delivery = IMSG_MTA_DELIVERY_TEMPFAIL; mta_flush_task(s, delivery, line, 0, 0); mta_enter_state(s, MTA_RSET); return; @@ -994,9 +997,9 @@ mta_response(struct mta_session *s, char *line) } else { if (line[0] == '5') - delivery = IMSG_DELIVERY_PERMFAIL; + delivery = IMSG_MTA_DELIVERY_PERMFAIL; else - delivery = IMSG_DELIVERY_TEMPFAIL; + delivery = IMSG_MTA_DELIVERY_TEMPFAIL; s->failures++; /* remove failed envelope from task list */ @@ -1027,7 +1030,7 @@ mta_response(struct mta_session *s, char *line) if (s->relay->limits->max_failures_per_session && s->failures == s->relay->limits->max_failures_per_session) { - mta_flush_task(s, IMSG_DELIVERY_TEMPFAIL, + mta_flush_task(s, IMSG_MTA_DELIVERY_TEMPFAIL, "Too many consecutive errors, closing connection", 0, 1); mta_enter_state(s, MTA_QUIT); break; @@ -1037,7 +1040,7 @@ mta_response(struct mta_session *s, char *line) * if no more envelopes, flush failed queue */ if (TAILQ_EMPTY(&s->task->envelopes)) { - mta_flush_task(s, IMSG_DELIVERY_OK, + mta_flush_task(s, IMSG_MTA_DELIVERY_OK, "No envelope", 0, 0); mta_enter_state(s, MTA_RSET); break; @@ -1056,9 +1059,9 @@ mta_response(struct mta_session *s, char *line) break; } if (line[0] == '5') - delivery = IMSG_DELIVERY_PERMFAIL; + delivery = IMSG_MTA_DELIVERY_PERMFAIL; else - delivery = IMSG_DELIVERY_TEMPFAIL; + delivery = IMSG_MTA_DELIVERY_TEMPFAIL; mta_flush_task(s, delivery, line, 0, 0); mta_enter_state(s, MTA_RSET); break; @@ -1066,14 +1069,14 @@ mta_response(struct mta_session *s, char *line) case MTA_LMTP_EOM: case MTA_EOM: if (line[0] == '2') { - delivery = IMSG_DELIVERY_OK; + delivery = IMSG_MTA_DELIVERY_OK; s->msgtried = 0; s->msgcount++; } else if (line[0] == '5') - delivery = IMSG_DELIVERY_PERMFAIL; + delivery = IMSG_MTA_DELIVERY_PERMFAIL; else - delivery = IMSG_DELIVERY_TEMPFAIL; + delivery = IMSG_MTA_DELIVERY_TEMPFAIL; mta_flush_task(s, delivery, line, (s->flags & MTA_LMTP) ? 1 : 0, 0); if (s->task) { s->rcptcount--; @@ -1325,7 +1328,7 @@ mta_queue_data(struct mta_session *s) } if (ferror(s->datafp)) { - mta_flush_task(s, IMSG_DELIVERY_TEMPFAIL, + mta_flush_task(s, IMSG_MTA_DELIVERY_TEMPFAIL, "Error reading content file", 0, 0); return (-1); } @@ -1438,7 +1441,7 @@ mta_error(struct mta_session *s, const char *fmt, ...) mta_route_error(s->relay, s->route); if (s->task) - mta_flush_task(s, IMSG_DELIVERY_TEMPFAIL, error, 0, 0); + mta_flush_task(s, IMSG_MTA_DELIVERY_TEMPFAIL, error, 0, 0); free(error); } @@ -1498,7 +1501,7 @@ mta_start_tls(struct mta_session *s) req_ca_cert.reqid = s->id; strlcpy(req_ca_cert.name, certname, sizeof req_ca_cert.name); - m_compose(p_lka, IMSG_LKA_SSL_INIT, 0, 0, -1, + m_compose(p_lka, IMSG_MTA_SSL_INIT, 0, 0, -1, &req_ca_cert, sizeof(req_ca_cert)); tree_xset(&wait_ssl_init, s->id, s); s->flags |= MTA_WAIT; @@ -1549,7 +1552,7 @@ mta_verify_certificate(struct mta_session *s) iov[0].iov_len = sizeof(req_ca_vrfy); iov[1].iov_base = req_ca_vrfy.cert; iov[1].iov_len = req_ca_vrfy.cert_len; - m_composev(p_lka, IMSG_LKA_SSL_VERIFY_CERT, 0, 0, -1, + m_composev(p_lka, IMSG_MTA_SSL_VERIFY_CERT, 0, 0, -1, iov, nitems(iov)); free(req_ca_vrfy.cert); X509_free(x); @@ -1565,7 +1568,7 @@ mta_verify_certificate(struct mta_session *s) iov[0].iov_len = sizeof(req_ca_vrfy); iov[1].iov_base = req_ca_vrfy.cert; iov[1].iov_len = req_ca_vrfy.cert_len; - m_composev(p_lka, IMSG_LKA_SSL_VERIFY_CHAIN, 0, 0, -1, + m_composev(p_lka, IMSG_MTA_SSL_VERIFY_CHAIN, 0, 0, -1, iov, nitems(iov)); free(req_ca_vrfy.cert); } @@ -1574,7 +1577,7 @@ mta_verify_certificate(struct mta_session *s) /* Tell lookup process that it can start verifying, we're done */ memset(&req_ca_vrfy, 0, sizeof req_ca_vrfy); req_ca_vrfy.reqid = s->id; - m_compose(p_lka, IMSG_LKA_SSL_VERIFY, 0, 0, -1, + m_compose(p_lka, IMSG_MTA_SSL_VERIFY, 0, 0, -1, &req_ca_vrfy, sizeof req_ca_vrfy); return 1; -- cgit v1.2.3