diff options
-rw-r--r-- | usr.sbin/smtpd/bounce.c | 20 | ||||
-rw-r--r-- | usr.sbin/smtpd/makemap/Makefile | 3 | ||||
-rw-r--r-- | usr.sbin/smtpd/mta_session.c | 15 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtp.c | 5 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtp_session.c | 5 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpctl/Makefile | 3 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/util.c | 25 |
8 files changed, 50 insertions, 30 deletions
diff --git a/usr.sbin/smtpd/bounce.c b/usr.sbin/smtpd/bounce.c index c68e8bd431f..712de82a868 100644 --- a/usr.sbin/smtpd/bounce.c +++ b/usr.sbin/smtpd/bounce.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bounce.c,v 1.50 2012/10/03 16:43:19 chl Exp $ */ +/* $OpenBSD: bounce.c,v 1.51 2012/10/07 15:46:38 chl Exp $ */ /* * Copyright (c) 2009 Gilles Chehade <gilles@openbsd.org> @@ -166,8 +166,7 @@ bounce_run(uint64_t id, int fd) } bounce->state = BOUNCE_EHLO; - if (iobuf_init(&bounce->iobuf, 0, 0) == -1) - fatal("iobuf_init"); + iobuf_xinit(&bounce->iobuf, 0, 0, "bounce_run"); io_init(&bounce->io, fd, bounce, bounce_io, &bounce->iobuf); io_set_timeout(&bounce->io, 30000); io_set_read(&bounce->io); @@ -241,7 +240,7 @@ bounce_send(struct bounce *bounce, const char *fmt, ...) log_trace(TRACE_BOUNCE, "bounce: %p: >>> %s", bounce, p); - iobuf_fqueue(&bounce->iobuf, "%s\n", p); + iobuf_xfqueue(&bounce->iobuf, "bounce_send", "%s\n", p); free(p); } @@ -285,7 +284,7 @@ bounce_next(struct bounce *bounce) evp = TAILQ_FIRST(&bounce->envelopes); - iobuf_fqueue(&bounce->iobuf, + iobuf_xfqueue(&bounce->iobuf, "bounce_next: DATA_NOTICE", "Subject: Delivery status notification\n" "From: Mailer Daemon <MAILER-DAEMON@%s>\n" "To: %s@%s\n" @@ -304,13 +303,13 @@ bounce_next(struct bounce *bounce) line = evp->errorline; if (strlen(line) > 4 && (*line == '1' || *line == '6')) line += 4; - iobuf_fqueue(&bounce->iobuf, + iobuf_xfqueue(&bounce->iobuf, "bounce_next: DATA_NOTICE", "Recipient: %s@%s\n" "Reason: %s\n", evp->dest.user, evp->dest.domain, line); } - iobuf_fqueue(&bounce->iobuf, + iobuf_xfqueue(&bounce->iobuf, "bounce_next: DATA_NOTICE", "\n" "Below is a copy of the original message:\n" "\n"); @@ -330,10 +329,9 @@ bounce_next(struct bounce *bounce) if (line == NULL) break; line[len - 1] = '\0'; - if(len == 2 && line[0] == '.') - iobuf_queue(&bounce->iobuf, ".", 1); - iobuf_queue(&bounce->iobuf, line, len); - iobuf_queue(&bounce->iobuf, "\n", 1); + iobuf_xfqueue(&bounce->iobuf, + "bounce_next: DATA_MESSAGE", "%s%s\n", + (len == 2 && line[0] == '.') ? "." : "", line); } if (ferror(bounce->msgfp)) { diff --git a/usr.sbin/smtpd/makemap/Makefile b/usr.sbin/smtpd/makemap/Makefile index fa584c01019..9bbdefa84f8 100644 --- a/usr.sbin/smtpd/makemap/Makefile +++ b/usr.sbin/smtpd/makemap/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.14 2012/08/29 16:26:17 gilles Exp $ +# $OpenBSD: Makefile,v 1.15 2012/10/07 15:46:38 chl Exp $ .PATH: ${.CURDIR}/.. @@ -15,6 +15,7 @@ CFLAGS+= -Wall -Wstrict-prototypes -Wmissing-prototypes CFLAGS+= -Wmissing-declarations CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual CFLAGS+= -Wsign-compare -Wbounded +CFLAGS+= -DNO_IO SRCS= parse.y makemap.c aliases.c expand.c log.c util.c map.c \ map_static.c map_db.c map_stdio.c diff --git a/usr.sbin/smtpd/mta_session.c b/usr.sbin/smtpd/mta_session.c index 33eea42eb9b..fbaa86c6f1c 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.21 2012/10/03 16:43:19 chl Exp $ */ +/* $OpenBSD: mta_session.c,v 1.22 2012/10/07 15:46:38 chl Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -357,8 +357,7 @@ mta_enter_state(struct mta_session *s, int newstate) else sa_set_port(sa, 25); - if (iobuf_init(&s->iobuf, 0, 0) == -1) - fatal("iobuf_init"); + iobuf_xinit(&s->iobuf, 0, 0, "mta_enter_state"); io_init(&s->io, -1, s, mta_io, &s->iobuf); io_set_timeout(&s->io, 10000); if (io_connect(&s->io, sa) == -1) { @@ -775,7 +774,7 @@ mta_send(struct mta_session *s, char *fmt, ...) log_trace(TRACE_MTA, "mta: %p: >>> %s", s, p); - iobuf_fqueue(&s->iobuf, "%s\r\n", p); + iobuf_xfqueue(&s->iobuf, "mta_send", "%s\r\n", p); free(p); @@ -800,11 +799,9 @@ mta_queue_data(struct mta_session *s) if ((ln = fgetln(s->datafp, &len)) == NULL) break; if (ln[len - 1] == '\n') - len--; - if (*ln == '.') - iobuf_queue(&s->iobuf, ".", 1); - iobuf_queue(&s->iobuf, ln, len); - iobuf_queue(&s->iobuf, "\r\n", 2); + ln[len - 1] = '\0'; + iobuf_xfqueue(&s->iobuf, "mta_queue_data", "%s%s\r\n", + *ln == '.' ? "." : "", ln); } if (ferror(s->datafp)) { diff --git a/usr.sbin/smtpd/smtp.c b/usr.sbin/smtpd/smtp.c index 12107f81e59..461c5d89343 100644 --- a/usr.sbin/smtpd/smtp.c +++ b/usr.sbin/smtpd/smtp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtp.c,v 1.119 2012/10/03 16:43:19 chl Exp $ */ +/* $OpenBSD: smtp.c,v 1.120 2012/10/07 15:46:38 chl Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -508,8 +508,7 @@ smtp_new(struct listener *l) s->s_l = l; strlcpy(s->s_msg.tag, l->tag, sizeof(s->s_msg.tag)); - if (iobuf_init(&s->s_iobuf, MAX_LINE_SIZE, MAX_LINE_SIZE) == -1) - fatal("iobuf_init"); + iobuf_xinit(&s->s_iobuf, MAX_LINE_SIZE, MAX_LINE_SIZE, "smtp_new"); io_init(&s->s_io, -1, s, session_io, &s->s_iobuf); s->s_state = S_CONNECTED; diff --git a/usr.sbin/smtpd/smtp_session.c b/usr.sbin/smtpd/smtp_session.c index f5e782e2f6f..a7b0d304e43 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.169 2012/09/14 19:22:04 eric Exp $ */ +/* $OpenBSD: smtp_session.c,v 1.170 2012/10/07 15:46:38 chl Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -1088,8 +1088,7 @@ session_respond(struct session *s, char *fmt, ...) log_trace(TRACE_SMTP, "smtp: %p: >>> %s", s, buf); - iobuf_queue(&s->s_iobuf, buf, n); - iobuf_queue(&s->s_iobuf, "\r\n", 2); + iobuf_xfqueue(&s->s_iobuf, "session_respond", "%s\r\n", buf); /* * Log failures. Might be annoying in the long term, but it is a good diff --git a/usr.sbin/smtpd/smtpctl/Makefile b/usr.sbin/smtpd/smtpctl/Makefile index 5b14d630bc4..3c046ad1eb3 100644 --- a/usr.sbin/smtpd/smtpctl/Makefile +++ b/usr.sbin/smtpd/smtpctl/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.28 2012/09/01 16:09:15 gilles Exp $ +# $OpenBSD: Makefile,v 1.29 2012/10/07 15:46:38 chl Exp $ .PATH: ${.CURDIR}/.. @@ -15,6 +15,7 @@ CFLAGS+= -Wall -Wstrict-prototypes -Wmissing-prototypes CFLAGS+= -Wmissing-declarations CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual CFLAGS+= -Wsign-compare -Wbounded +CFLAGS+= -DNO_IO SRCS= enqueue.c parser.c log.c envelope.c SRCS+= queue_backend.c queue_fsqueue.c diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 1816f5f0151..0011942ed9a 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.378 2012/10/03 19:42:16 gilles Exp $ */ +/* $OpenBSD: smtpd.h,v 1.379 2012/10/07 15:46:38 chl Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -1164,6 +1164,8 @@ void *xmalloc(size_t, const char *); void *xcalloc(size_t, size_t, const char *); char *xstrdup(const char *, const char *); void *xmemdup(const void *, size_t, const char *); +void iobuf_xinit(struct iobuf *, size_t, size_t, const char *); +void iobuf_xfqueue(struct iobuf *, const char *, const char *, ...); void log_envelope(const struct envelope *, const char *, const char *); void session_socket_blockmode(int, enum blockmodes); void session_socket_no_linger(int); diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c index bfd9bd15515..54e1d575df0 100644 --- a/usr.sbin/smtpd/util.c +++ b/usr.sbin/smtpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.85 2012/10/04 12:17:09 todd Exp $ */ +/* $OpenBSD: util.c,v 1.86 2012/10/07 15:46:38 chl Exp $ */ /* * Copyright (c) 2000,2001 Markus Friedl. All rights reserved. @@ -101,6 +101,29 @@ xmemdup(const void *ptr, size_t size, const char *where) return (r); } +#if !defined(NO_IO) +void +iobuf_xinit(struct iobuf *io, size_t size, size_t max, const char *where) +{ + if (iobuf_init(io, size, max) == -1) + errx(1, "%s: iobuf_init(%p, %zu, %zu)", where, io, size, max); +} + +void +iobuf_xfqueue(struct iobuf *io, const char *where, const char *fmt, ...) +{ + va_list ap; + int len; + + va_start(ap, fmt); + len = iobuf_vfqueue(io, fmt, ap); + va_end(ap); + + if (len == -1) + errx(1, "%s: iobuf_xfqueue(%p, %s, ...)", where, io, fmt); +} +#endif + int bsnprintf(char *str, size_t size, const char *format, ...) { |