summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2016-11-21 13:00:44 +0000
committerEric Faurot <eric@cvs.openbsd.org>2016-11-21 13:00:44 +0000
commitd330bd7bd0c711fc07489e718a441b514c66232d (patch)
tree622bf179c86b2d1418ddb0c99681fde3b6b79aed /usr.sbin/smtpd
parentf93b9d7a816f35f591f05fa7b3575772f0d5f34f (diff)
replace calls to iobuf_*() functions with the corresponding io_*() wrappers.
ok sunil@ gilles@
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r--usr.sbin/smtpd/bounce.c57
-rw-r--r--usr.sbin/smtpd/filter.c8
-rw-r--r--usr.sbin/smtpd/mda.c21
-rw-r--r--usr.sbin/smtpd/mta_session.c21
-rw-r--r--usr.sbin/smtpd/smtp_session.c37
5 files changed, 67 insertions, 77 deletions
diff --git a/usr.sbin/smtpd/bounce.c b/usr.sbin/smtpd/bounce.c
index 05144e03b37..92fe56283be 100644
--- a/usr.sbin/smtpd/bounce.c
+++ b/usr.sbin/smtpd/bounce.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bounce.c,v 1.74 2016/11/20 08:43:36 eric Exp $ */
+/* $OpenBSD: bounce.c,v 1.75 2016/11/21 13:00:43 eric Exp $ */
/*
* Copyright (c) 2009 Gilles Chehade <gilles@poolp.org>
@@ -313,7 +313,7 @@ bounce_send(struct bounce_session *s, const char *fmt, ...)
log_trace(TRACE_BOUNCE, "bounce: %p: >>> %s", s, p);
- iobuf_xfqueue(&s->iobuf, "bounce_send", "%s\n", p);
+ io_xprintf(&s->io, "%s\n", p);
free(p);
}
@@ -452,7 +452,7 @@ bounce_next(struct bounce_session *s)
case BOUNCE_DATA_NOTICE:
/* Construct an appropriate notice. */
- iobuf_xfqueue(&s->iobuf, "bounce_next: HEADER",
+ io_xprintf(&s->io,
"Subject: Delivery status notification: %s\n"
"From: Mailer Daemon <MAILER-DAEMON@%s>\n"
"To: %s\n"
@@ -470,7 +470,7 @@ bounce_next(struct bounce_session *s)
s->boundary,
s->smtpname);
- iobuf_xfqueue(&s->iobuf, "bounce_next: BODY",
+ io_xprintf(&s->io,
"--%16" PRIu64 "/%s\n"
"Content-Description: Notification\n"
"Content-Type: text/plain; charset=us-ascii\n"
@@ -481,17 +481,14 @@ bounce_next(struct bounce_session *s)
switch (s->msg->bounce.type) {
case B_ERROR:
- iobuf_xfqueue(&s->iobuf, "bounce_next: BODY",
- notice_error);
+ io_xprint(&s->io, notice_error);
break;
case B_WARNING:
- iobuf_xfqueue(&s->iobuf, "bounce_next: BODY",
- notice_warning,
+ io_xprintf(&s->io, notice_warning,
bounce_duration(s->msg->bounce.delay));
break;
case B_DSN:
- iobuf_xfqueue(&s->iobuf, "bounce_next: BODY",
- s->msg->bounce.mta_without_dsn ?
+ io_xprint(&s->io, s->msg->bounce.mta_without_dsn ?
notice_relay : notice_success);
break;
default:
@@ -499,35 +496,32 @@ bounce_next(struct bounce_session *s)
}
TAILQ_FOREACH(evp, &s->msg->envelopes, entry) {
- iobuf_xfqueue(&s->iobuf,
- "bounce_next: DATA_NOTICE",
- "%s", evp->report);
+ io_xprint(&s->io, evp->report);
}
- iobuf_xfqueue(&s->iobuf, "bounce_next: DATA_NOTICE", "\n");
+ io_xprint(&s->io, "\n");
if (s->msg->bounce.type == B_WARNING)
- iobuf_xfqueue(&s->iobuf, "bounce_next: BODY",
- notice_warning2,
+ io_xprintf(&s->io, notice_warning2,
bounce_duration(s->msg->bounce.expire));
- iobuf_xfqueue(&s->iobuf, "bounce_next: DATA_NOTICE",
+ io_xprintf(&s->io,
" Below is a copy of the original message:\n"
"\n");
- iobuf_xfqueue(&s->iobuf, "bounce_next: BODY",
+ io_xprintf(&s->io,
"--%16" PRIu64 "/%s\n"
"Content-Description: Delivery Report\n"
"Content-Type: message/delivery-status\n"
"\n",
s->boundary, s->smtpname);
- iobuf_xfqueue(&s->iobuf, "bounce_next: BODY",
+ io_xprintf(&s->io,
"Reporting-MTA: dns; %s\n"
"\n",
s->smtpname);
TAILQ_FOREACH(evp, &s->msg->envelopes, entry) {
- iobuf_xfqueue(&s->iobuf, "bounce_next: BODY",
+ io_xprintf(&s->io,
"Final-Recipient: rfc822; %s@%s\n"
"Action: %s\n"
"Status: %s\n"
@@ -539,21 +533,21 @@ bounce_next(struct bounce_session *s)
}
log_trace(TRACE_BOUNCE, "bounce: %p: >>> [... %zu bytes ...]",
- s, iobuf_queued(&s->iobuf));
+ s, io_queued(&s->io));
s->state = BOUNCE_DATA_MESSAGE;
break;
case BOUNCE_DATA_MESSAGE:
- iobuf_xfqueue(&s->iobuf, "bounce_next: BODY",
+ io_xprintf(&s->io,
"--%16" PRIu64 "/%s\n"
"Content-Description: Message headers\n"
"Content-Type: text/rfc822-headers\n"
"\n",
s->boundary, s->smtpname);
- n = iobuf_queued(&s->iobuf);
- while (iobuf_queued(&s->iobuf) < BOUNCE_HIWAT) {
+ n = io_queued(&s->io);
+ while (io_queued(&s->io) < BOUNCE_HIWAT) {
if ((len = getline(&line, &sz, s->msgfp)) == -1)
break;
if (len == 1 && line[0] == '\n' && /* end of headers */
@@ -562,7 +556,7 @@ bounce_next(struct bounce_session *s)
free(line);
fclose(s->msgfp);
s->msgfp = NULL;
- iobuf_xfqueue(&s->iobuf, "bounce_next: BODY",
+ io_xprintf(&s->io,
"\n--%16" PRIu64 "/%s--\n", s->boundary,
s->smtpname);
bounce_send(s, ".");
@@ -570,8 +564,7 @@ bounce_next(struct bounce_session *s)
return (0);
}
line[len - 1] = '\0';
- iobuf_xfqueue(&s->iobuf,
- "bounce_next: DATA_MESSAGE", "%s%s\n",
+ io_xprintf(&s->io, "%s%s\n",
(len == 2 && line[0] == '.') ? "." : "", line);
}
free(line);
@@ -585,11 +578,11 @@ bounce_next(struct bounce_session *s)
return (-1);
}
- iobuf_xfqueue(&s->iobuf, "bounce_next: BODY",
+ io_xprintf(&s->io,
"\n--%16" PRIu64 "/%s--\n", s->boundary, s->smtpname);
log_trace(TRACE_BOUNCE, "bounce: %p: >>> [... %zu bytes ...]",
- s, iobuf_queued(&s->iobuf) - n);
+ s, io_queued(&s->io) - n);
if (feof(s->msgfp)) {
fclose(s->msgfp);
@@ -728,8 +721,8 @@ bounce_io(struct io *io, int evt, void *arg)
switch (evt) {
case IO_DATAIN:
nextline:
- line = iobuf_getline(&s->iobuf, &len);
- if (line == NULL && iobuf_len(&s->iobuf) >= LINE_MAX) {
+ line = io_getline(&s->io, &len);
+ if (line == NULL && io_datalen(&s->io) >= LINE_MAX) {
bounce_status(s, "Input too long");
bounce_free(s);
return;
@@ -776,7 +769,7 @@ bounce_io(struct io *io, int evt, void *arg)
bounce_free(s);
return;
}
- if (iobuf_queued(&s->iobuf) == 0)
+ if (io_queued(&s->io) == 0)
io_set_read(io);
break;
diff --git a/usr.sbin/smtpd/filter.c b/usr.sbin/smtpd/filter.c
index 516d378d8a6..f8682455e52 100644
--- a/usr.sbin/smtpd/filter.c
+++ b/usr.sbin/smtpd/filter.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: filter.c,v 1.21 2016/11/20 08:43:36 eric Exp $ */
+/* $OpenBSD: filter.c,v 1.22 2016/11/21 13:00:43 eric Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@poolp.org>
@@ -691,8 +691,8 @@ filter_tx_io(struct io *io, int evt, void *arg)
switch (evt) {
case IO_DATAIN:
- data = iobuf_data(&s->ibuf);
- len = iobuf_len(&s->ibuf);
+ data = io_data(&s->iev);
+ len = io_datalen(&s->iev);
log_trace(TRACE_FILTERS,
"filter: filter_tx_io: datain (%zu) for req %016"PRIx64"",
@@ -705,7 +705,7 @@ filter_tx_io(struct io *io, int evt, void *arg)
break;
}
s->idatalen += n;
- iobuf_drop(&s->ibuf, n);
+ io_drop(&s->iev, n);
iobuf_normalize(&s->ibuf);
return;
diff --git a/usr.sbin/smtpd/mda.c b/usr.sbin/smtpd/mda.c
index 946d9752d66..b7d704b3db0 100644
--- a/usr.sbin/smtpd/mda.c
+++ b/usr.sbin/smtpd/mda.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mda.c,v 1.122 2016/11/20 08:43:36 eric Exp $ */
+/* $OpenBSD: mda.c,v 1.123 2016/11/21 13:00:43 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -253,11 +253,10 @@ mda_imsg(struct mproc *p, struct imsg *imsg)
if (e->method == A_MDA || e->method == A_FILENAME) {
time(&now);
if (e->sender[0])
- n = iobuf_fqueue(&s->iobuf,
- "From %s %s", e->sender,
- ctime(&now));
+ n = io_printf(&s->io, "From %s %s",
+ e->sender, ctime(&now));
else
- n = iobuf_fqueue(&s->iobuf,
+ n = io_printf(&s->io,
"From MAILER-DAEMON@%s %s",
env->sc_hostname, ctime(&now));
}
@@ -268,13 +267,13 @@ mda_imsg(struct mproc *p, struct imsg *imsg)
* XXX: remove existing Return-Path,
* if any
*/
- n = iobuf_fqueue(&s->iobuf,
+ n = io_printf(&s->io,
"Return-Path: %s\n"
"Delivered-To: %s\n",
e->sender,
e->rcpt ? e->rcpt : e->dest);
else
- n = iobuf_fqueue(&s->iobuf,
+ n = io_printf(&s->io,
"Delivered-To: %s\n",
e->rcpt ? e->rcpt : e->dest);
}
@@ -457,7 +456,7 @@ mda_imsg(struct mproc *p, struct imsg *imsg)
*/
error = NULL;
if (strcmp(parent_error, "exited okay") == 0) {
- if (s->datafp || iobuf_queued(&s->iobuf))
+ if (s->datafp || io_queued(&s->io))
error = "mda exited prematurely";
} else
error = out[0] ? out : parent_error;
@@ -519,10 +518,10 @@ mda_io(struct io *io, int evt, void *arg)
return;
}
- while (iobuf_queued(&s->iobuf) < MDA_HIWAT) {
+ while (io_queued(&s->io) < MDA_HIWAT) {
if ((len = getline(&ln, &sz, s->datafp)) == -1)
break;
- if (iobuf_queue(&s->iobuf, ln, len) == -1) {
+ if (io_write(&s->io, ln, len) == -1) {
m_create(p_parent, IMSG_MDA_KILL,
0, 0, -1);
m_add_id(p_parent, s->id);
@@ -553,7 +552,7 @@ mda_io(struct io *io, int evt, void *arg)
s->id, s->evp->id);
fclose(s->datafp);
s->datafp = NULL;
- if (iobuf_queued(&s->iobuf) == 0)
+ if (io_queued(&s->io) == 0)
goto done;
}
return;
diff --git a/usr.sbin/smtpd/mta_session.c b/usr.sbin/smtpd/mta_session.c
index 98dbb47cfd0..0ea8a09e3c0 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.87 2016/11/20 08:43:36 eric Exp $ */
+/* $OpenBSD: mta_session.c,v 1.88 2016/11/21 13:00:43 eric Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -1177,9 +1177,9 @@ mta_io(struct io *io, int evt, void *arg)
case IO_DATAIN:
nextline:
- line = iobuf_getline(&s->iobuf, &len);
+ line = io_getline(&s->io, &len);
if (line == NULL) {
- if (iobuf_len(&s->iobuf) >= LINE_MAX) {
+ if (io_datalen(&s->io) >= LINE_MAX) {
mta_error(s, "Input too long");
mta_free(s);
return;
@@ -1266,7 +1266,7 @@ mta_io(struct io *io, int evt, void *arg)
iobuf_normalize(&s->iobuf);
- if (iobuf_len(&s->iobuf)) {
+ if (io_datalen(&s->io)) {
log_debug("debug: mta: remaining data in input buffer");
mta_error(s, "Remote host sent too much data");
if (s->flags & MTA_WAIT)
@@ -1285,7 +1285,7 @@ mta_io(struct io *io, int evt, void *arg)
}
}
- if (iobuf_queued(&s->iobuf) == 0)
+ if (io_queued(&s->io) == 0)
io_set_read(io);
break;
@@ -1366,7 +1366,7 @@ mta_send(struct mta_session *s, char *fmt, ...)
log_trace(TRACE_MTA, "mta: %p: >>> %s", s, p);
- iobuf_xfqueue(&s->iobuf, "mta_send", "%s\r\n", p);
+ io_xprintf(&s->io, "%s\r\n", p);
free(p);
}
@@ -1381,15 +1381,14 @@ mta_queue_data(struct mta_session *s)
size_t sz = 0, q;
ssize_t len;
- q = iobuf_queued(&s->iobuf);
+ q = io_queued(&s->io);
- while (iobuf_queued(&s->iobuf) < MTA_HIWAT) {
+ while (io_queued(&s->io) < MTA_HIWAT) {
if ((len = getline(&ln, &sz, s->datafp)) == -1)
break;
if (ln[len - 1] == '\n')
ln[len - 1] = '\0';
- iobuf_xfqueue(&s->iobuf, "mta_queue_data", "%s%s\r\n",
- *ln == '.' ? "." : "", ln);
+ io_xprintf(&s->io, "%s%s\r\n", *ln == '.' ? "." : "", ln);
}
free(ln);
@@ -1404,7 +1403,7 @@ mta_queue_data(struct mta_session *s)
s->datafp = NULL;
}
- return (iobuf_queued(&s->iobuf) - q);
+ return (io_queued(&s->io) - q);
}
static void
diff --git a/usr.sbin/smtpd/smtp_session.c b/usr.sbin/smtpd/smtp_session.c
index f1682c40742..f9cb5ee0f1e 100644
--- a/usr.sbin/smtpd/smtp_session.c
+++ b/usr.sbin/smtpd/smtp_session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtp_session.c,v 1.293 2016/11/20 08:43:36 eric Exp $ */
+/* $OpenBSD: smtp_session.c,v 1.294 2016/11/21 13:00:43 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -1208,14 +1208,14 @@ smtp_filter_fd(uint64_t id, int fd)
io_set_callback(&s->tx->oev, smtp_data_io, s);
io_set_fd(&s->tx->oev, fd);
- iobuf_fqueue(&s->tx->obuf, "Received: ");
+ io_print(&s->tx->oev, "Received: ");
if (!(s->listener->flags & F_MASK_SOURCE)) {
- iobuf_fqueue(&s->tx->obuf, "from %s (%s [%s])",
+ io_printf(&s->tx->oev, "from %s (%s [%s])",
s->helo,
s->hostname,
ss_to_text(&s->ss));
}
- iobuf_fqueue(&s->tx->obuf, "\n\tby %s (%s) with %sSMTP%s%s id %08x",
+ io_printf(&s->tx->oev, "\n\tby %s (%s) with %sSMTP%s%s id %08x",
s->smtpname,
SMTPD_NAME,
s->flags & SF_EHLO ? "E" : "",
@@ -1225,8 +1225,7 @@ smtp_filter_fd(uint64_t id, int fd)
if (s->flags & SF_SECURE) {
x = SSL_get_peer_certificate(s->io.ssl);
- iobuf_fqueue(&s->tx->obuf,
- " (%s:%s:%d:%s)",
+ io_printf(&s->tx->oev, " (%s:%s:%d:%s)",
SSL_get_version(s->io.ssl),
SSL_get_cipher_name(s->io.ssl),
SSL_get_cipher_bits(s->io.ssl, NULL),
@@ -1235,21 +1234,21 @@ smtp_filter_fd(uint64_t id, int fd)
X509_free(x);
if (s->listener->flags & F_RECEIVEDAUTH) {
- iobuf_fqueue(&s->tx->obuf, " auth=%s", s->username[0] ? "yes" : "no");
+ io_printf(&s->tx->oev, " auth=%s", s->username[0] ? "yes" : "no");
if (s->username[0])
- iobuf_fqueue(&s->tx->obuf, " user=%s", s->username);
+ io_printf(&s->tx->oev, " user=%s", s->username);
}
}
if (s->tx->rcptcount == 1) {
- iobuf_fqueue(&s->tx->obuf, "\n\tfor <%s@%s>",
+ io_printf(&s->tx->oev, "\n\tfor <%s@%s>",
s->tx->evp.rcpt.user,
s->tx->evp.rcpt.domain);
}
- iobuf_fqueue(&s->tx->obuf, ";\n\t%s\n", time_to_text(time(NULL)));
+ io_printf(&s->tx->oev, ";\n\t%s\n", time_to_text(time(NULL)));
- s->tx->odatalen = iobuf_queued(&s->tx->obuf);
+ s->tx->odatalen = io_queued(&s->tx->oev);
io_set_write(&s->tx->oev);
@@ -1299,8 +1298,8 @@ smtp_io(struct io *io, int evt, void *arg)
case IO_DATAIN:
nextline:
- line = iobuf_getline(&s->iobuf, &len);
- if ((line == NULL && iobuf_len(&s->iobuf) >= LINE_MAX) ||
+ line = io_getline(&s->io, &len);
+ if ((line == NULL && io_datalen(&s->io) >= LINE_MAX) ||
(line && len >= LINE_MAX)) {
s->flags |= SF_BADINPUT;
smtp_reply(s, "500 %s: Line too long",
@@ -1323,7 +1322,7 @@ smtp_io(struct io *io, int evt, void *arg)
}
/* Pipelining not supported */
- if (iobuf_len(&s->iobuf)) {
+ if (io_datalen(&s->io)) {
s->flags |= SF_BADINPUT;
smtp_reply(s, "500 %s %s: Pipelining not supported",
esc_code(ESC_STATUS_PERMFAIL, ESC_INVALID_COMMAND),
@@ -1343,7 +1342,7 @@ smtp_io(struct io *io, int evt, void *arg)
io_set_write(io);
s->tx->dataeom = 1;
- if (iobuf_queued(&s->tx->obuf) == 0)
+ if (io_queued(&s->tx->oev) == 0)
smtp_data_io_done(s);
else
io_reload(&s->tx->oev);
@@ -1507,7 +1506,7 @@ smtp_data_io(struct io *io, int evt, void *arg)
break;
case IO_LOWAT:
- if (s->tx->dataeom && iobuf_queued(&s->tx->obuf) == 0) {
+ if (s->tx->dataeom && io_queued(&s->tx->oev) == 0) {
smtp_data_io_done(s);
} else if (s->io.flags & IO_PAUSE_IN) {
log_debug("debug: smtp: %p: filter congestion over: resuming session", s);
@@ -2189,7 +2188,7 @@ smtp_message_printf(struct smtp_session *s, const char *fmt, ...)
return -1;
va_start(ap, fmt);
- len = iobuf_vfqueue(&s->tx->obuf, fmt, ap);
+ len = io_vprintf(&s->tx->oev, fmt, ap);
va_end(ap);
if (len < 0) {
@@ -2219,7 +2218,7 @@ smtp_reply(struct smtp_session *s, char *fmt, ...)
log_trace(TRACE_SMTP, "smtp: %p: >>> %s", s, buf);
- iobuf_xfqueue(&s->iobuf, "smtp_reply", "%s\r\n", buf);
+ io_xprintf(&s->io, "%s\r\n", buf);
switch (buf[0]) {
case '5':
@@ -2663,7 +2662,7 @@ smtp_filter_dataline(struct smtp_session *s, const char *line)
return;
}
- if (iobuf_queued(&s->tx->obuf) > DATA_HIWAT && !(s->io.flags & IO_PAUSE_IN)) {
+ if (io_queued(&s->tx->oev) > DATA_HIWAT && !(s->io.flags & IO_PAUSE_IN)) {
log_debug("debug: smtp: %p: filter congestion over: pausing session", s);
io_pause(&s->io, IO_PAUSE_IN);
}