diff options
-rw-r--r-- | smtpd/bounce.c | 67 | ||||
-rw-r--r-- | smtpd/ca.c | 4 | ||||
-rw-r--r-- | smtpd/control.c | 29 | ||||
-rw-r--r-- | smtpd/filter.c | 31 | ||||
-rw-r--r-- | smtpd/ioev.c | 91 | ||||
-rw-r--r-- | smtpd/ioev.h | 32 | ||||
-rw-r--r-- | smtpd/lka.c | 6 | ||||
-rw-r--r-- | smtpd/log.c | 146 | ||||
-rw-r--r-- | smtpd/log.h | 46 | ||||
-rw-r--r-- | smtpd/makemap.c | 4 | ||||
-rw-r--r-- | smtpd/mda.c | 50 | ||||
-rw-r--r-- | smtpd/mta.c | 4 | ||||
-rw-r--r-- | smtpd/mta_session.c | 73 | ||||
-rw-r--r-- | smtpd/parse.y | 15 | ||||
-rw-r--r-- | smtpd/pony.c | 5 | ||||
-rw-r--r-- | smtpd/queue.c | 4 | ||||
-rw-r--r-- | smtpd/rfc2822.c | 8 | ||||
-rw-r--r-- | smtpd/scheduler.c | 4 | ||||
-rw-r--r-- | smtpd/scheduler_ramqueue.c | 8 | ||||
-rw-r--r-- | smtpd/smtp_session.c | 129 | ||||
-rw-r--r-- | smtpd/smtpctl.c | 4 | ||||
-rw-r--r-- | smtpd/smtpctl/CVS/Entries | 2 | ||||
-rw-r--r-- | smtpd/smtpd.8 | 7 | ||||
-rw-r--r-- | smtpd/smtpd.c | 49 | ||||
-rw-r--r-- | smtpd/smtpd.conf.5 | 7 | ||||
-rw-r--r-- | smtpd/smtpd.h | 10 | ||||
-rw-r--r-- | smtpd/smtpd/CVS/Entries | 2 | ||||
-rw-r--r-- | smtpd/table.5 | 8 | ||||
-rw-r--r-- | smtpd/util.c | 51 |
29 files changed, 457 insertions, 439 deletions
diff --git a/smtpd/bounce.c b/smtpd/bounce.c index 152e1500..dba407a3 100644 --- a/smtpd/bounce.c +++ b/smtpd/bounce.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bounce.c,v 1.76 2016/11/22 07:28:42 eric Exp $ */ +/* $OpenBSD: bounce.c,v 1.77 2016/11/30 11:52:48 eric Exp $ */ /* * Copyright (c) 2009 Gilles Chehade <gilles@poolp.org> @@ -80,8 +80,7 @@ struct bounce_session { struct bounce_message *msg; FILE *msgfp; int state; - struct iobuf iobuf; - struct io io; + struct io *io; uint64_t boundary; }; @@ -229,12 +228,11 @@ bounce_fd(int fd) s = xcalloc(1, sizeof(*s), "bounce_fd"); s->smtpname = xstrdup(msg->smtpname, "bounce_fd"); s->state = BOUNCE_EHLO; - iobuf_xinit(&s->iobuf, 0, 0, "bounce_run"); - io_init(&s->io, &s->iobuf); - io_set_callback(&s->io, bounce_io, s); - io_set_fd(&s->io, fd); - io_set_timeout(&s->io, 30000); - io_set_read(&s->io); + s->io = io_new(); + io_set_callback(s->io, bounce_io, s); + io_set_fd(s->io, fd); + io_set_timeout(s->io, 30000); + io_set_read(s->io); s->boundary = generate_uid(); log_debug("debug: bounce: new session %p", s); @@ -313,7 +311,7 @@ bounce_send(struct bounce_session *s, const char *fmt, ...) log_trace(TRACE_BOUNCE, "bounce: %p: >>> %s", s, p); - io_xprintf(&s->io, "%s\n", p); + io_xprintf(s->io, "%s\n", p); free(p); } @@ -452,7 +450,7 @@ bounce_next(struct bounce_session *s) case BOUNCE_DATA_NOTICE: /* Construct an appropriate notice. */ - io_xprintf(&s->io, + io_xprintf(s->io, "Subject: Delivery status notification: %s\n" "From: Mailer Daemon <MAILER-DAEMON@%s>\n" "To: %s\n" @@ -470,7 +468,7 @@ bounce_next(struct bounce_session *s) s->boundary, s->smtpname); - io_xprintf(&s->io, + io_xprintf(s->io, "--%16" PRIu64 "/%s\n" "Content-Description: Notification\n" "Content-Type: text/plain; charset=us-ascii\n" @@ -481,14 +479,14 @@ bounce_next(struct bounce_session *s) switch (s->msg->bounce.type) { case B_ERROR: - io_xprint(&s->io, notice_error); + io_xprint(s->io, notice_error); break; case B_WARNING: - io_xprintf(&s->io, notice_warning, + io_xprintf(s->io, notice_warning, bounce_duration(s->msg->bounce.delay)); break; case B_DSN: - io_xprint(&s->io, s->msg->bounce.mta_without_dsn ? + io_xprint(s->io, s->msg->bounce.mta_without_dsn ? notice_relay : notice_success); break; default: @@ -496,32 +494,32 @@ bounce_next(struct bounce_session *s) } TAILQ_FOREACH(evp, &s->msg->envelopes, entry) { - io_xprint(&s->io, evp->report); + io_xprint(s->io, evp->report); } - io_xprint(&s->io, "\n"); + io_xprint(s->io, "\n"); if (s->msg->bounce.type == B_WARNING) - io_xprintf(&s->io, notice_warning2, + io_xprintf(s->io, notice_warning2, bounce_duration(s->msg->bounce.expire)); - io_xprintf(&s->io, + io_xprintf(s->io, " Below is a copy of the original message:\n" "\n"); - io_xprintf(&s->io, + io_xprintf(s->io, "--%16" PRIu64 "/%s\n" "Content-Description: Delivery Report\n" "Content-Type: message/delivery-status\n" "\n", s->boundary, s->smtpname); - io_xprintf(&s->io, + io_xprintf(s->io, "Reporting-MTA: dns; %s\n" "\n", s->smtpname); TAILQ_FOREACH(evp, &s->msg->envelopes, entry) { - io_xprintf(&s->io, + io_xprintf(s->io, "Final-Recipient: rfc822; %s@%s\n" "Action: %s\n" "Status: %s\n" @@ -533,21 +531,21 @@ bounce_next(struct bounce_session *s) } log_trace(TRACE_BOUNCE, "bounce: %p: >>> [... %zu bytes ...]", - s, io_queued(&s->io)); + s, io_queued(s->io)); s->state = BOUNCE_DATA_MESSAGE; break; case BOUNCE_DATA_MESSAGE: - io_xprintf(&s->io, + 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 = io_queued(&s->io); - while (io_queued(&s->io) < 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 */ @@ -556,7 +554,7 @@ bounce_next(struct bounce_session *s) free(line); fclose(s->msgfp); s->msgfp = NULL; - io_xprintf(&s->io, + io_xprintf(s->io, "\n--%16" PRIu64 "/%s--\n", s->boundary, s->smtpname); bounce_send(s, "."); @@ -564,7 +562,7 @@ bounce_next(struct bounce_session *s) return (0); } line[len - 1] = '\0'; - io_xprintf(&s->io, "%s%s\n", + io_xprintf(s->io, "%s%s\n", (len == 2 && line[0] == '.') ? "." : "", line); } free(line); @@ -578,11 +576,11 @@ bounce_next(struct bounce_session *s) return (-1); } - io_xprintf(&s->io, + io_xprintf(s->io, "\n--%16" PRIu64 "/%s--\n", s->boundary, s->smtpname); log_trace(TRACE_BOUNCE, "bounce: %p: >>> [... %zu bytes ...]", - s, io_queued(&s->io) - n); + s, io_queued(s->io) - n); if (feof(s->msgfp)) { fclose(s->msgfp); @@ -695,8 +693,7 @@ bounce_free(struct bounce_session *s) { log_debug("debug: bounce: %p: deleting session", s); - iobuf_clear(&s->iobuf); - io_clear(&s->io); + io_free(s->io); free(s->smtpname); free(s); @@ -721,8 +718,8 @@ bounce_io(struct io *io, int evt, void *arg) switch (evt) { case IO_DATAIN: nextline: - line = io_getline(&s->io, &len); - if (line == NULL && io_datalen(&s->io) >= 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; @@ -767,7 +764,7 @@ bounce_io(struct io *io, int evt, void *arg) bounce_free(s); return; } - if (io_queued(&s->io) == 0) + if (io_queued(s->io) == 0) io_set_read(io); break; @@ -1,4 +1,4 @@ -/* $OpenBSD: ca.c,v 1.25 2016/09/08 12:06:43 eric Exp $ */ +/* $OpenBSD: ca.c,v 1.26 2017/01/09 09:53:23 reyk Exp $ */ /* * Copyright (c) 2014 Reyk Floeter <reyk@openbsd.org> @@ -248,7 +248,7 @@ ca_imsg(struct mproc *p, struct imsg *imsg) m_msg(&m, imsg); m_get_int(&m, &v); m_end(&m); - log_verbose(v); + log_trace_verbose(v); return; case IMSG_CTL_PROFILE: m_msg(&m, imsg); diff --git a/smtpd/control.c b/smtpd/control.c index f5ea8296..6e4c6e98 100644 --- a/smtpd/control.c +++ b/smtpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.117 2016/09/08 12:06:43 eric Exp $ */ +/* $OpenBSD: control.c,v 1.118 2017/01/09 09:53:23 reyk Exp $ */ /* * Copyright (c) 2012 Gilles Chehade <gilles@poolp.org> @@ -504,14 +504,13 @@ control_dispatch_ext(struct mproc *p, struct imsg *imsg) if (c->euid) goto badcred; - if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(verbose)) + if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(v)) goto badcred; memcpy(&v, imsg->data, sizeof(v)); - verbose = v; - log_verbose(verbose); + log_trace_verbose(v); - control_broadcast_verbose(IMSG_CTL_VERBOSE, verbose); + control_broadcast_verbose(IMSG_CTL_VERBOSE, v); m_compose(p, IMSG_CTL_OK, 0, 0, -1, NULL, 0); return; @@ -520,14 +519,14 @@ control_dispatch_ext(struct mproc *p, struct imsg *imsg) if (c->euid) goto badcred; - if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(verbose)) + if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(v)) goto badcred; memcpy(&v, imsg->data, sizeof(v)); - verbose |= v; - log_verbose(verbose); + tracing |= v; + log_trace_verbose(tracing); - control_broadcast_verbose(IMSG_CTL_VERBOSE, verbose); + control_broadcast_verbose(IMSG_CTL_VERBOSE, tracing); m_compose(p, IMSG_CTL_OK, 0, 0, -1, NULL, 0); return; @@ -536,14 +535,14 @@ control_dispatch_ext(struct mproc *p, struct imsg *imsg) if (c->euid) goto badcred; - if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(verbose)) + if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(v)) goto badcred; memcpy(&v, imsg->data, sizeof(v)); - verbose &= ~v; - log_verbose(verbose); + tracing &= ~v; + log_trace_verbose(tracing); - control_broadcast_verbose(IMSG_CTL_VERBOSE, verbose); + control_broadcast_verbose(IMSG_CTL_VERBOSE, tracing); m_compose(p, IMSG_CTL_OK, 0, 0, -1, NULL, 0); return; @@ -552,7 +551,7 @@ control_dispatch_ext(struct mproc *p, struct imsg *imsg) if (c->euid) goto badcred; - if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(verbose)) + if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(v)) goto badcred; memcpy(&v, imsg->data, sizeof(v)); @@ -567,7 +566,7 @@ control_dispatch_ext(struct mproc *p, struct imsg *imsg) if (c->euid) goto badcred; - if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(verbose)) + if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(v)) goto badcred; memcpy(&v, imsg->data, sizeof(v)); diff --git a/smtpd/filter.c b/smtpd/filter.c index 4fb1a20a..fcbdaec7 100644 --- a/smtpd/filter.c +++ b/smtpd/filter.c @@ -1,4 +1,4 @@ -/* $OpenBSD: filter.c,v 1.23 2016/11/22 07:28:42 eric Exp $ */ +/* $OpenBSD: filter.c,v 1.25 2017/01/09 09:53:23 reyk Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@poolp.org> @@ -70,8 +70,7 @@ struct filter_session { struct filter *fcurr; int error; - struct io iev; - struct iobuf ibuf; + struct io *iev; size_t idatalen; FILE *ofile; @@ -198,7 +197,7 @@ filter_postfork(void) p->proc = PROC_FILTER; p->name = xstrdup(filter->name, "filter_postfork"); p->data = proc; - if (verbose & TRACE_DEBUG) + if (tracing & TRACE_DEBUG) filter_add_arg(filter, "-v"); if (foreground_log) filter_add_arg(filter, "-d"); @@ -295,8 +294,8 @@ filter_event(uint64_t id, int event) filter_post_event(id, event, TAILQ_FIRST(s->filters), NULL); if (event == EVENT_DISCONNECT) { - io_clear(&s->iev); - iobuf_clear(&s->ibuf); + if (s->iev) + io_free(s->iev); if (s->ofile) fclose(s->ofile); free(s); @@ -315,7 +314,6 @@ filter_connect(uint64_t id, const struct sockaddr *local, if (filter == NULL) filter = "<no-filter>"; s->filters = dict_xget(&chains, filter); - io_init(&s->iev, NULL); tree_xset(&sessions, s->id, s); filter_event(id, EVENT_CONNECT); @@ -670,11 +668,10 @@ filter_tx(struct filter_session *s, int sink) io_set_nonblocking(sp[0]); io_set_nonblocking(sp[1]); - iobuf_init(&s->ibuf, 0, 0); - io_init(&s->iev, &s->ibuf); - io_set_callback(&s->iev, filter_tx_io, s); - io_set_fd(&s->iev, sp[0]); - io_set_read(&s->iev); + s->iev = io_new(); + io_set_callback(s->iev, filter_tx_io, s); + io_set_fd(s->iev, sp[0]); + io_set_read(s->iev); return (sp[1]); } @@ -691,8 +688,8 @@ filter_tx_io(struct io *io, int evt, void *arg) switch (evt) { case IO_DATAIN: - data = io_data(&s->iev); - len = io_datalen(&s->iev); + 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 +702,7 @@ filter_tx_io(struct io *io, int evt, void *arg) break; } s->idatalen += n; - io_drop(&s->iev, n); + io_drop(s->iev, n); return; case IO_DISCONNECTED: @@ -721,8 +718,8 @@ filter_tx_io(struct io *io, int evt, void *arg) break; } - io_clear(&s->iev); - iobuf_clear(&s->ibuf); + io_free(s->iev); + s->iev = NULL; fclose(s->ofile); s->ofile = NULL; diff --git a/smtpd/ioev.c b/smtpd/ioev.c index 6bb06fd0..f31f84fd 100644 --- a/smtpd/ioev.c +++ b/smtpd/ioev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ioev.c,v 1.37 2016/11/25 16:17:41 eric Exp $ */ +/* $OpenBSD: ioev.c,v 1.40 2016/12/03 15:46:33 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -21,6 +21,7 @@ #include <err.h> #include <errno.h> +#include <event.h> #include <fcntl.h> #include <inttypes.h> #include <stdlib.h> @@ -46,6 +47,28 @@ enum { IO_STATE_MAX, }; +#define IO_PAUSE_IN IO_IN +#define IO_PAUSE_OUT IO_OUT +#define IO_READ 0x04 +#define IO_WRITE 0x08 +#define IO_RW (IO_READ | IO_WRITE) +#define IO_RESET 0x10 /* internal */ +#define IO_HELD 0x20 /* internal */ + +struct io { + int sock; + void *arg; + void (*cb)(struct io*, int, void *); + struct iobuf iobuf; + size_t lowat; + int timeout; + int flags; + int state; + struct event ev; + void *ssl; + const char *error; /* only valid immediately on callback */ +}; + const char* io_strflags(int); const char* io_evstr(short); @@ -95,15 +118,10 @@ io_strio(struct io *io) } #endif - if (io->iobuf == NULL) - (void)snprintf(buf, sizeof buf, - "<io:%p fd=%d to=%d fl=%s%s>", - io, io->sock, io->timeout, io_strflags(io->flags), ssl); - else - (void)snprintf(buf, sizeof buf, - "<io:%p fd=%d to=%d fl=%s%s ib=%zu ob=%zu>", - io, io->sock, io->timeout, io_strflags(io->flags), ssl, - io_pending(io), io_queued(io)); + (void)snprintf(buf, sizeof buf, + "<io:%p fd=%d to=%d fl=%s%s ib=%zu ob=%zu>", + io, io->sock, io->timeout, io_strflags(io->flags), ssl, + io_pending(io), io_queued(io)); return (buf); } @@ -223,20 +241,29 @@ _io_init() _io_debug = getenv("IO_DEBUG") != NULL; } -void -io_init(struct io *io, struct iobuf *iobuf) +struct io * +io_new(void) { + struct io *io; + _io_init(); - memset(io, 0, sizeof *io); + if ((io = calloc(1, sizeof(*io))) == NULL) + return NULL; io->sock = -1; io->timeout = -1; - io->iobuf = iobuf; + + if (iobuf_init(&io->iobuf, 0, 0) == -1) { + free(io); + return NULL; + } + + return io; } void -io_clear(struct io *io) +io_free(struct io *io) { io_debug("io_clear(%p)\n", io); @@ -257,6 +284,9 @@ io_clear(struct io *io) close(io->sock); io->sock = -1; } + + iobuf_clear(&io->iobuf); + free(io); } void @@ -396,7 +426,7 @@ io_write(struct io *io, const void *buf, size_t len) { int r; - r = iobuf_queue(io->iobuf, buf, len); + r = iobuf_queue(&io->iobuf, buf, len); io_reload(io); @@ -408,7 +438,7 @@ io_writev(struct io *io, const struct iovec *iov, int iovcount) { int r; - r = iobuf_queuev(io->iobuf, iov, iovcount); + r = iobuf_queuev(&io->iobuf, iov, iovcount); io_reload(io); @@ -453,7 +483,7 @@ io_vprintf(struct io *io, const char *fmt, va_list ap) size_t io_queued(struct io *io) { - return iobuf_queued(io->iobuf); + return iobuf_queued(&io->iobuf); } /* @@ -463,25 +493,25 @@ io_queued(struct io *io) void * io_data(struct io *io) { - return iobuf_data(io->iobuf); + return iobuf_data(&io->iobuf); } size_t io_datalen(struct io *io) { - return iobuf_len(io->iobuf); + return iobuf_len(&io->iobuf); } char * io_getline(struct io *io, size_t *sz) { - return iobuf_getline(io->iobuf, sz); + return iobuf_getline(&io->iobuf, sz); } void io_drop(struct io *io, size_t sz) { - return iobuf_drop(io->iobuf, sz); + return iobuf_drop(&io->iobuf, sz); } @@ -501,8 +531,7 @@ io_reload(struct io *io) if (io->flags & IO_HELD) return; - if (io->iobuf) - iobuf_normalize(io->iobuf); + iobuf_normalize(&io->iobuf); #ifdef IO_SSL if (io->ssl) { @@ -561,7 +590,7 @@ io_reset(struct io *io, short events, void (*dispatch)(int, short, void*)) size_t io_pending(struct io *io) { - return iobuf_len(io->iobuf); + return iobuf_len(&io->iobuf); } const char* @@ -666,7 +695,7 @@ io_dispatch(int fd, short ev, void *humppa) } if (ev & EV_WRITE && (w = io_queued(io))) { - if ((n = iobuf_write(io->iobuf, io->sock)) < 0) { + if ((n = iobuf_write(&io->iobuf, io->sock)) < 0) { if (n == IOBUF_WANT_WRITE) /* kqueue bug? */ goto read; if (n == IOBUF_CLOSED) @@ -685,8 +714,8 @@ io_dispatch(int fd, short ev, void *humppa) read: if (ev & EV_READ) { - iobuf_normalize(io->iobuf); - if ((n = iobuf_read(io->iobuf, io->sock)) < 0) { + iobuf_normalize(&io->iobuf); + if ((n = iobuf_read(&io->iobuf, io->sock)) < 0) { if (n == IOBUF_CLOSED) io_callback(io, IO_DISCONNECTED); else { @@ -915,8 +944,8 @@ io_dispatch_read_ssl(int fd, short event, void *humppa) } again: - iobuf_normalize(io->iobuf); - switch ((n = iobuf_read_ssl(io->iobuf, (SSL*)io->ssl))) { + iobuf_normalize(&io->iobuf); + switch ((n = iobuf_read_ssl(&io->iobuf, (SSL*)io->ssl))) { case IOBUF_WANT_READ: io_reset(io, EV_READ, io_dispatch_read_ssl); break; @@ -963,7 +992,7 @@ io_dispatch_write_ssl(int fd, short event, void *humppa) } w = io_queued(io); - switch ((n = iobuf_write_ssl(io->iobuf, (SSL*)io->ssl))) { + switch ((n = iobuf_write_ssl(&io->iobuf, (SSL*)io->ssl))) { case IOBUF_WANT_READ: io_reset(io, EV_READ, io_dispatch_write_ssl); break; diff --git a/smtpd/ioev.h b/smtpd/ioev.h index 859a1089..f1c39848 100644 --- a/smtpd/ioev.h +++ b/smtpd/ioev.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ioev.h,v 1.14 2016/11/24 21:25:21 eric Exp $ */ +/* $OpenBSD: ioev.h,v 1.16 2016/11/30 17:43:32 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -15,8 +15,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <event.h> - enum { IO_CONNECTED = 0, /* connection successful */ IO_TLSREADY, /* TLS started successfully */ @@ -28,34 +26,16 @@ enum { IO_ERROR, /* details? */ }; -#define IO_READ 0x01 -#define IO_WRITE 0x02 -#define IO_RW (IO_READ | IO_WRITE) -#define IO_PAUSE_IN 0x04 -#define IO_PAUSE_OUT 0x08 -#define IO_RESET 0x10 /* internal */ -#define IO_HELD 0x20 /* internal */ +#define IO_IN 0x01 +#define IO_OUT 0x02 -struct iobuf; -struct io { - int sock; - void *arg; - void (*cb)(struct io*, int, void *); - struct iobuf *iobuf; - size_t lowat; - int timeout; - int flags; - int state; - struct event ev; - void *ssl; - const char *error; /* only valid immediately on callback */ -}; +struct io; void io_set_nonblocking(int); void io_set_nolinger(int); -void io_init(struct io*, struct iobuf*); -void io_clear(struct io*); +struct io *io_new(void); +void io_free(struct io *); void io_set_read(struct io *); void io_set_write(struct io *); void io_set_fd(struct io *, int); diff --git a/smtpd/lka.c b/smtpd/lka.c index 4c553fd9..db9d42ae 100644 --- a/smtpd/lka.c +++ b/smtpd/lka.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka.c,v 1.197 2016/09/08 12:06:43 eric Exp $ */ +/* $OpenBSD: lka.c,v 1.198 2017/01/09 09:53:23 reyk Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -321,7 +321,7 @@ lka_imsg(struct mproc *p, struct imsg *imsg) return; case IMSG_CONF_END: - if (verbose & TRACE_TABLES) + if (tracing & TRACE_TABLES) table_dump_all(); /* fork & exec tables that need it */ @@ -354,7 +354,7 @@ lka_imsg(struct mproc *p, struct imsg *imsg) m_msg(&m, imsg); m_get_int(&m, &v); m_end(&m); - log_verbose(v); + log_trace_verbose(v); return; case IMSG_CTL_PROFILE: diff --git a/smtpd/log.c b/smtpd/log.c index ec30321d..d2761937 100644 --- a/smtpd/log.c +++ b/smtpd/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.17 2015/12/28 22:08:30 jung Exp $ */ +/* $OpenBSD: log.c,v 1.19 2017/01/09 14:49:22 reyk Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -11,55 +11,78 @@ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <sys/types.h> -#include <sys/queue.h> -#include <sys/tree.h> -#include <sys/socket.h> - -#include <errno.h> -#include <pwd.h> -#include <stdarg.h> #include <stdio.h> #include <stdlib.h> +#include <stdarg.h> #include <string.h> #include <syslog.h> +#include <errno.h> #include <time.h> -#include "log.h" - -#define TRACE_DEBUG 0x1 - -static int foreground; +static int debug; static int verbose; - -void vlog(int, const char *, va_list); -void logit(int, const char *, ...) - __attribute__((format (printf, 2, 3))); - +const char *log_procname; + +void log_init(int, int); +void log_procinit(const char *); +void log_setverbose(int); +int log_getverbose(void); +void log_warn(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void log_warnx(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void log_info(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void log_debug(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void logit(int, const char *, ...) + __attribute__((__format__ (printf, 2, 3))); +void vlog(int, const char *, va_list) + __attribute__((__format__ (printf, 2, 0))); +__dead void fatal(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +__dead void fatalx(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); void -log_init(int n_foreground) +log_init(int n_debug, int facility) { extern char *__progname; - foreground = n_foreground; - if (!foreground) - openlog(__progname, LOG_PID | LOG_NDELAY, LOG_MAIL); + debug = n_debug; + verbose = n_debug; + log_procinit(__progname); + + if (!debug) + openlog(__progname, LOG_PID | LOG_NDELAY, facility); tzset(); } void -log_verbose(int v) +log_procinit(const char *procname) +{ + if (procname != NULL) + log_procname = procname; +} + +void +log_setverbose(int v) { verbose = v; } +int +log_getverbose(void) +{ + return (verbose); +} + void logit(int pri, const char *fmt, ...) { @@ -74,8 +97,9 @@ void vlog(int pri, const char *fmt, va_list ap) { char *nfmt; + int saved_errno = errno; - if (foreground) { + if (debug) { /* best effort in out of mem situations */ if (asprintf(&nfmt, "%s\n", fmt) == -1) { vfprintf(stderr, fmt, ap); @@ -87,31 +111,36 @@ vlog(int pri, const char *fmt, va_list ap) fflush(stderr); } else vsyslog(pri, fmt, ap); -} + errno = saved_errno; +} void log_warn(const char *emsg, ...) { - char *nfmt; - va_list ap; + char *nfmt; + va_list ap; + int saved_errno = errno; /* best effort to even work in out of memory situations */ if (emsg == NULL) - logit(LOG_CRIT, "%s", strerror(errno)); + logit(LOG_CRIT, "%s", strerror(saved_errno)); else { va_start(ap, emsg); - if (asprintf(&nfmt, "%s: %s", emsg, strerror(errno)) == -1) { + if (asprintf(&nfmt, "%s: %s", emsg, + strerror(saved_errno)) == -1) { /* we tried it... */ vlog(LOG_CRIT, emsg, ap); - logit(LOG_CRIT, "%s", strerror(errno)); + logit(LOG_CRIT, "%s", strerror(saved_errno)); } else { vlog(LOG_CRIT, nfmt, ap); free(nfmt); } va_end(ap); } + + errno = saved_errno; } void @@ -139,19 +168,7 @@ log_debug(const char *emsg, ...) { va_list ap; - if (verbose & TRACE_DEBUG) { - va_start(ap, emsg); - vlog(LOG_DEBUG, emsg, ap); - va_end(ap); - } -} - -void -log_trace(int mask, const char *emsg, ...) -{ - va_list ap; - - if (verbose & mask) { + if (verbose > 1) { va_start(ap, emsg); vlog(LOG_DEBUG, emsg, ap); va_end(ap); @@ -159,23 +176,23 @@ log_trace(int mask, const char *emsg, ...) } static void -fatal_arg(const char *emsg, va_list ap) +vfatalc(int code, const char *emsg, va_list ap) { -#define FATALBUFSIZE 1024 - static char ebuffer[FATALBUFSIZE]; - - if (emsg == NULL) - (void)strlcpy(ebuffer, strerror(errno), sizeof ebuffer); - else { - if (errno) { - (void)vsnprintf(ebuffer, sizeof ebuffer, emsg, ap); - (void)strlcat(ebuffer, ": ", sizeof ebuffer); - (void)strlcat(ebuffer, strerror(errno), sizeof ebuffer); - } - else - (void)vsnprintf(ebuffer, sizeof ebuffer, emsg, ap); + static char s[BUFSIZ]; + const char *sep; + + if (emsg != NULL) { + (void)vsnprintf(s, sizeof(s), emsg, ap); + sep = ": "; + } else { + s[0] = '\0'; + sep = ""; } - logit(LOG_CRIT, "fatal: %s", ebuffer); + if (code) + logit(LOG_CRIT, "%s: %s%s%s", + log_procname, s, sep, strerror(code)); + else + logit(LOG_CRIT, "%s%s%s", log_procname, sep, s); } void @@ -184,7 +201,7 @@ fatal(const char *emsg, ...) va_list ap; va_start(ap, emsg); - fatal_arg(emsg, ap); + vfatalc(errno, emsg, ap); va_end(ap); exit(1); } @@ -194,9 +211,8 @@ fatalx(const char *emsg, ...) { va_list ap; - errno = 0; va_start(ap, emsg); - fatal_arg(emsg, ap); + vfatalc(0, emsg, ap); va_end(ap); exit(1); } diff --git a/smtpd/log.h b/smtpd/log.h index 6009af27..8120653c 100644 --- a/smtpd/log.h +++ b/smtpd/log.h @@ -1,4 +1,4 @@ -/* $OpenBSD: log.h,v 1.5 2014/07/08 10:30:52 eric Exp $ */ +/* $OpenBSD: log.h,v 1.7 2017/01/09 14:49:22 reyk Exp $ */ /* * Copyright (c) 2010 Gilles Chehade <gilles@poolp.org> @@ -16,19 +16,31 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -void log_init(int); -void log_verbose(int); -void log_warn(const char *, ...) - __attribute__((format (printf, 1, 2))); -void log_warnx(const char *, ...) - __attribute__((format (printf, 1, 2))); -void log_info(const char *, ...) - __attribute__((format (printf, 1, 2))); -void log_debug(const char *, ...) - __attribute__((format (printf, 1, 2))); -void log_trace(int, const char *, ...) - __attribute__((format (printf, 2, 3))); -__dead void fatal(const char *, ...) - __attribute__((format (printf, 1, 2))); -__dead void fatalx(const char *, ...) - __attribute__((format (printf, 1, 2))); +#include <syslog.h> + +/* log.c */ +void log_init(int, int); +void log_procinit(const char *); +void log_setverbose(int); +int log_getverbose(void); +void log_warn(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void log_warnx(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void log_info(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void log_debug(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void logit(int, const char *, ...) + __attribute__((__format__ (printf, 2, 3))); +void vlog(int, const char *, va_list) + __attribute__((__format__ (printf, 2, 0))); +__dead void fatal(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +__dead void fatalx(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); + +/* util.c */ +void log_trace_verbose(int); +void log_trace(int, const char *, ...) + __attribute__((format (printf, 2, 3))); diff --git a/smtpd/makemap.c b/smtpd/makemap.c index 408b2f70..af24a8c0 100644 --- a/smtpd/makemap.c +++ b/smtpd/makemap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: makemap.c,v 1.65 2016/03/17 19:40:43 krw Exp $ */ +/* $OpenBSD: makemap.c,v 1.66 2017/01/09 09:53:23 reyk Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -96,7 +96,7 @@ makemap(int argc, char *argv[]) char *p; int fd = -1; - log_init(1); + log_init(1, LOG_MAIL); mode = strcmp(__progname, "newaliases") ? P_MAKEMAP : P_NEWALIASES; conf = CONF_FILE; diff --git a/smtpd/mda.c b/smtpd/mda.c index a433ea70..ef6b6f8e 100644 --- a/smtpd/mda.c +++ b/smtpd/mda.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mda.c,v 1.124 2016/11/24 12:58:27 eric Exp $ */ +/* $OpenBSD: mda.c,v 1.126 2016/11/30 17:43:32 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -79,8 +79,7 @@ struct mda_session { uint64_t id; struct mda_user *user; struct mda_envelope *evp; - struct io io; - struct iobuf iobuf; + struct io *io; FILE *datafp; }; @@ -253,10 +252,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 = io_printf(&s->io, "From %s %s", + n = io_printf(s->io, "From %s %s", e->sender, ctime(&now)); else - n = io_printf(&s->io, + n = io_printf(s->io, "From MAILER-DAEMON@%s %s", env->sc_hostname, ctime(&now)); } @@ -267,13 +266,13 @@ mda_imsg(struct mproc *p, struct imsg *imsg) * XXX: remove existing Return-Path, * if any */ - n = io_printf(&s->io, + n = io_printf(s->io, "Return-Path: %s\n" "Delivered-To: %s\n", e->sender, e->rcpt ? e->rcpt : e->dest); else - n = io_printf(&s->io, + n = io_printf(s->io, "Delivered-To: %s\n", e->rcpt ? e->rcpt : e->dest); } @@ -431,8 +430,8 @@ mda_imsg(struct mproc *p, struct imsg *imsg) imsg->fd, s->id, s->evp->id); io_set_nonblocking(imsg->fd); - io_set_fd(&s->io, imsg->fd); - io_set_write(&s->io); + io_set_fd(s->io, imsg->fd); + io_set_write(s->io); return; case IMSG_MDA_DONE: @@ -456,7 +455,7 @@ mda_imsg(struct mproc *p, struct imsg *imsg) */ error = NULL; if (strcmp(parent_error, "exited okay") == 0) { - if (s->datafp || io_queued(&s->io)) + if (s->datafp || (s->io && io_queued(s->io))) error = "mda exited prematurely"; } else error = out[0] ? out : parent_error; @@ -514,20 +513,21 @@ mda_io(struct io *io, int evt, void *arg) log_debug("debug: mda: all data sent for session" " %016"PRIx64 " evpid %016"PRIx64, s->id, s->evp->id); - io_clear(io); + io_free(io); + s->io = NULL; return; } - while (io_queued(&s->io) < MDA_HIWAT) { + while (io_queued(s->io) < MDA_HIWAT) { if ((len = getline(&ln, &sz, s->datafp)) == -1) break; - if (io_write(&s->io, 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); m_add_string(p_parent, "Out of memory"); m_close(p_parent); - io_pause(io, IO_PAUSE_OUT); + io_pause(io, IO_OUT); free(ln); return; } @@ -542,7 +542,7 @@ mda_io(struct io *io, int evt, void *arg) m_add_id(p_parent, s->id); m_add_string(p_parent, "Error reading body"); m_close(p_parent); - io_pause(io, IO_PAUSE_OUT); + io_pause(io, IO_OUT); return; } @@ -552,32 +552,32 @@ mda_io(struct io *io, int evt, void *arg) s->id, s->evp->id); fclose(s->datafp); s->datafp = NULL; - if (io_queued(&s->io) == 0) + if (io_queued(s->io) == 0) goto done; } return; case IO_TIMEOUT: log_debug("debug: mda: timeout on session %016"PRIx64, s->id); - io_pause(io, IO_PAUSE_OUT); + io_pause(io, IO_OUT); return; case IO_ERROR: log_debug("debug: mda: io error on session %016"PRIx64": %s", s->id, io_error(io)); - io_pause(io, IO_PAUSE_OUT); + io_pause(io, IO_OUT); return; case IO_DISCONNECTED: log_debug("debug: mda: io disconnected on session %016"PRIx64, s->id); - io_pause(io, IO_PAUSE_OUT); + io_pause(io, IO_OUT); return; default: log_debug("debug: mda: unexpected event on session %016"PRIx64, s->id); - io_pause(io, IO_PAUSE_OUT); + io_pause(io, IO_OUT); return; } } @@ -747,8 +747,8 @@ mda_done(struct mda_session *s) if (s->datafp) fclose(s->datafp); - io_clear(&s->io); - iobuf_clear(&s->iobuf); + if (s->io) + io_free(s->io); free(s); @@ -954,10 +954,8 @@ mda_session(struct mda_user * u) s = xcalloc(1, sizeof *s, "mda_session"); s->id = generate_uid(); s->user = u; - if (iobuf_init(&s->iobuf, 0, 0) == -1) - fatal("mda_session"); - io_init(&s->io, &s->iobuf); - io_set_callback(&s->io, mda_io, s); + s->io = io_new(); + io_set_callback(s->io, mda_io, s); tree_xset(&sessions, s->id, s); diff --git a/smtpd/mta.c b/smtpd/mta.c index ba3a4cef..08630cc6 100644 --- a/smtpd/mta.c +++ b/smtpd/mta.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mta.c,v 1.202 2016/09/03 22:59:06 giovanni Exp $ */ +/* $OpenBSD: mta.c,v 1.203 2017/01/09 09:53:23 reyk Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -400,7 +400,7 @@ mta_imsg(struct mproc *p, struct imsg *imsg) m_msg(&m, imsg); m_get_int(&m, &v); m_end(&m); - log_verbose(v); + log_trace_verbose(v); return; case IMSG_CTL_PROFILE: diff --git a/smtpd/mta_session.c b/smtpd/mta_session.c index 8b407bfa..84038e5f 100644 --- a/smtpd/mta_session.c +++ b/smtpd/mta_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mta_session.c,v 1.94 2016/11/25 11:43:55 eric Exp $ */ +/* $OpenBSD: mta_session.c,v 1.96 2016/11/30 17:43:32 eric Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -115,8 +115,7 @@ struct mta_session { int ready; struct event ev; - struct iobuf iobuf; - struct io io; + struct io *io; int ext; size_t msgtried; @@ -196,7 +195,6 @@ mta_session(struct mta_relay *relay, struct mta_route *route) s->id = generate_uid(); s->relay = relay; s->route = route; - io_init(&s->io, NULL); if (relay->flags & RELAY_SSL && relay->flags & RELAY_AUTH) s->flags |= MTA_USE_AUTH; @@ -329,7 +327,7 @@ mta_session_imsg(struct mproc *p, struct imsg *imsg) ssl = ssl_mta_init(NULL, NULL, 0, env->sc_tls_ciphers); if (ssl == NULL) fatal("mta: ssl_mta_init"); - io_start_tls(&s->io, ssl); + io_start_tls(s->io, ssl); return; } } @@ -341,7 +339,7 @@ mta_session_imsg(struct mproc *p, struct imsg *imsg) resp_ca_cert->cert, resp_ca_cert->cert_len, env->sc_tls_ciphers); if (ssl == NULL) fatal("mta: ssl_mta_init"); - io_start_tls(&s->io, ssl); + io_start_tls(s->io, ssl); explicit_bzero(resp_ca_cert->cert, resp_ca_cert->cert_len); free(resp_ca_cert->cert); @@ -364,7 +362,7 @@ mta_session_imsg(struct mproc *p, struct imsg *imsg) } mta_tls_verified(s); - io_resume(&s->io, IO_PAUSE_IN); + io_resume(s->io, IO_IN); return; case IMSG_MTA_LOOKUP_HELO: @@ -427,8 +425,8 @@ mta_free(struct mta_session *s) runq_cancel(hangon, NULL, s); } - io_clear(&s->io); - iobuf_clear(&s->iobuf); + if (s->io) + io_free(s->io); if (s->task) fatalx("current task should have been deleted already"); @@ -497,8 +495,10 @@ mta_connect(struct mta_session *s) s->helo = xstrdup(env->sc_hostname, "mta_connect"); } - io_clear(&s->io); - iobuf_clear(&s->iobuf); + if (s->io) { + io_free(s->io); + s->io = NULL; + } s->use_smtps = s->use_starttls = s->use_smtp_tls = 0; @@ -556,20 +556,19 @@ mta_connect(struct mta_session *s) portno, s->route->dst->ptrname); mta_enter_state(s, MTA_INIT); - iobuf_xinit(&s->iobuf, 0, 0, "mta_connect"); - io_init(&s->io, &s->iobuf); - io_set_callback(&s->io, mta_io, s); - io_set_timeout(&s->io, 300000); - if (io_connect(&s->io, sa, s->route->src->sa) == -1) { + s->io = io_new(); + io_set_callback(s->io, mta_io, s); + io_set_timeout(s->io, 300000); + if (io_connect(s->io, sa, s->route->src->sa) == -1) { /* * This error is most likely a "no route", * so there is no need to try again. */ - log_debug("debug: mta: io_connect failed: %s", io_error(&s->io)); + log_debug("debug: mta: io_connect failed: %s", io_error(s->io)); if (errno == EADDRNOTAVAIL) - mta_source_error(s->relay, s->route, io_error(&s->io)); + mta_source_error(s->relay, s->route, io_error(s->io)); else - mta_error(s, "Connection failed: %s", io_error(&s->io)); + mta_error(s, "Connection failed: %s", io_error(s->io)); mta_free(s); } } @@ -842,7 +841,7 @@ mta_enter_state(struct mta_session *s, int newstate) case MTA_LMTP_EOM: /* LMTP reports status of each delivery, so enable read */ - io_set_read(&s->io); + io_set_read(s->io); break; case MTA_RSET: @@ -1033,7 +1032,7 @@ mta_response(struct mta_session *s, char *line) */ sa_len = sizeof(ss); sa = (struct sockaddr *)&ss; - if (getsockname(io_fileno(&s->io), sa, &sa_len) < 0) + if (getsockname(io_fileno(s->io), sa, &sa_len) < 0) mta_delivery_log(e, NULL, buf, delivery, line); else mta_delivery_log(e, sa_to_text(sa), @@ -1161,11 +1160,11 @@ mta_io(struct io *io, int evt, void *arg) case IO_TLSREADY: log_info("%016"PRIx64" mta event=starttls ciphers=%s", - s->id, ssl_to_text(io_ssl(&s->io))); + s->id, ssl_to_text(io_ssl(s->io))); s->flags |= MTA_TLS; if (mta_verify_certificate(s)) { - io_pause(&s->io, IO_PAUSE_IN); + io_pause(s->io, IO_IN); break; } @@ -1174,9 +1173,9 @@ mta_io(struct io *io, int evt, void *arg) case IO_DATAIN: nextline: - line = io_getline(&s->io, &len); + line = io_getline(s->io, &len); if (line == NULL) { - if (io_datalen(&s->io) >= LINE_MAX) { + if (io_datalen(s->io) >= LINE_MAX) { mta_error(s, "Input too long"); mta_free(s); } @@ -1259,7 +1258,7 @@ mta_io(struct io *io, int evt, void *arg) return; } - if (io_datalen(&s->io)) { + 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) @@ -1278,7 +1277,7 @@ mta_io(struct io *io, int evt, void *arg) } } - if (io_queued(&s->io) == 0) + if (io_queued(s->io) == 0) io_set_read(io); break; @@ -1359,7 +1358,7 @@ mta_send(struct mta_session *s, char *fmt, ...) log_trace(TRACE_MTA, "mta: %p: >>> %s", s, p); - io_xprintf(&s->io, "%s\r\n", p); + io_xprintf(s->io, "%s\r\n", p); free(p); } @@ -1374,14 +1373,14 @@ mta_queue_data(struct mta_session *s) size_t sz = 0, q; ssize_t len; - q = io_queued(&s->io); + q = io_queued(s->io); - while (io_queued(&s->io) < 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'; - io_xprintf(&s->io, "%s%s\r\n", *ln == '.' ? "." : "", ln); + io_xprintf(s->io, "%s%s\r\n", *ln == '.' ? "." : "", ln); } free(ln); @@ -1396,7 +1395,7 @@ mta_queue_data(struct mta_session *s) s->datafp = NULL; } - return (io_queued(&s->io) - q); + return (io_queued(s->io) - q); } static void @@ -1433,7 +1432,7 @@ mta_flush_task(struct mta_session *s, int delivery, const char *error, size_t co */ sa = (struct sockaddr *)&ss; sa_len = sizeof(ss); - if (getsockname(io_fileno(&s->io), sa, &sa_len) < 0) + if (getsockname(io_fileno(s->io), sa, &sa_len) < 0) mta_delivery_log(e, NULL, relay, delivery, error); else mta_delivery_log(e, sa_to_text(sa), @@ -1560,10 +1559,10 @@ mta_verify_certificate(struct mta_session *s) >= sizeof req_ca_vrfy.name) return 0; - x = SSL_get_peer_certificate(io_ssl(&s->io)); + x = SSL_get_peer_certificate(io_ssl(s->io)); if (x == NULL) return 0; - xchain = SSL_get_peer_cert_chain(io_ssl(&s->io)); + xchain = SSL_get_peer_cert_chain(io_ssl(s->io)); /* * Client provided a certificate and possibly a certificate chain. @@ -1657,7 +1656,7 @@ mta_tls_verified(struct mta_session *s) { X509 *x; - x = SSL_get_peer_certificate(io_ssl(&s->io)); + x = SSL_get_peer_certificate(io_ssl(s->io)); if (x) { log_info("smtp-out: Server certificate verification %s " "on session %016"PRIx64, @@ -1668,7 +1667,7 @@ mta_tls_verified(struct mta_session *s) if (s->use_smtps) { mta_enter_state(s, MTA_BANNER); - io_set_read(&s->io); + io_set_read(s->io); } else mta_enter_state(s, MTA_EHLO); diff --git a/smtpd/parse.y b/smtpd/parse.y index 0bc65098..0257a464 100644 --- a/smtpd/parse.y +++ b/smtpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.191 2016/11/25 09:21:21 gilles Exp $ */ +/* $OpenBSD: parse.y,v 1.193 2017/01/05 13:53:09 krw Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -2011,8 +2011,7 @@ parse_config(struct smtpd *x_conf, const char *filename, int opts) } /* Free macros and check which have not been used. */ - for (sym = TAILQ_FIRST(&symhead); sym != NULL; sym = next) { - next = TAILQ_NEXT(sym, entry); + TAILQ_FOREACH_SAFE(sym, &symhead, entry, next) { if ((conf->sc_opts & SMTPD_OPT_VERBOSE) && !sym->used) fprintf(stderr, "warning: macro '%s' not " "used\n", sym->nam); @@ -2042,9 +2041,10 @@ symset(const char *nam, const char *val, int persist) { struct sym *sym; - for (sym = TAILQ_FIRST(&symhead); sym && strcmp(nam, sym->nam); - sym = TAILQ_NEXT(sym, entry)) - ; /* nothing */ + TAILQ_FOREACH(sym, &symhead, entry) { + if (strcmp(nam, sym->nam) == 0) + break; + } if (sym != NULL) { if (sym->persist == 1) @@ -2103,11 +2103,12 @@ symget(const char *nam) { struct sym *sym; - TAILQ_FOREACH(sym, &symhead, entry) + TAILQ_FOREACH(sym, &symhead, entry) { if (strcmp(nam, sym->nam) == 0) { sym->used = 1; return (sym->val); } + } return (NULL); } diff --git a/smtpd/pony.c b/smtpd/pony.c index 38170743..c057a6df 100644 --- a/smtpd/pony.c +++ b/smtpd/pony.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pony.c,v 1.16 2016/09/08 12:06:43 eric Exp $ */ +/* $OpenBSD: pony.c,v 1.17 2017/01/09 09:53:23 reyk Exp $ */ /* * Copyright (c) 2014 Gilles Chehade <gilles@poolp.org> @@ -66,7 +66,7 @@ pony_imsg(struct mproc *p, struct imsg *imsg) m_msg(&m, imsg); m_get_int(&m, &v); m_end(&m); - log_verbose(v); + log_trace_verbose(v); return; case IMSG_CTL_PROFILE: m_msg(&m, imsg); @@ -170,7 +170,6 @@ pony(void) setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid)) fatal("pony: cannot drop privileges"); - imsg_callback = pony_imsg; event_init(); diff --git a/smtpd/queue.c b/smtpd/queue.c index 0fdf346a..b826523f 100644 --- a/smtpd/queue.c +++ b/smtpd/queue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue.c,v 1.182 2016/09/08 12:06:43 eric Exp $ */ +/* $OpenBSD: queue.c,v 1.183 2017/01/09 09:53:23 reyk Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -491,7 +491,7 @@ queue_imsg(struct mproc *p, struct imsg *imsg) m_msg(&m, imsg); m_get_int(&m, &v); m_end(&m); - log_verbose(v); + log_trace_verbose(v); return; case IMSG_CTL_PROFILE: diff --git a/smtpd/rfc2822.c b/smtpd/rfc2822.c index ba6e5262..9aa3c2bd 100644 --- a/smtpd/rfc2822.c +++ b/smtpd/rfc2822.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rfc2822.c,v 1.9 2016/10/13 15:47:32 gilles Exp $ */ +/* $OpenBSD: rfc2822.c,v 1.10 2017/02/04 19:25:24 guenther Exp $ */ /* * Copyright (c) 2014 Gilles Chehade <gilles@poolp.org> @@ -97,13 +97,13 @@ parser_feed_header(struct rfc2822_parser *rp, char *line) char *pos; /* new header */ - if (!isspace(*line) && *line != '\0') { + if (!isspace((unsigned char)*line) && *line != '\0') { rp->in_hdr = 1; if ((pos = strchr(line, ':')) == NULL) return 0; memset(rp->header.name, 0, sizeof rp->header.name); (void)memcpy(rp->header.name, line, pos - line); - if (isspace(*(pos + 1))) + if (isspace((unsigned char)pos[1])) return parser_feed_header(rp, pos + 1); else { *pos = ' '; @@ -185,7 +185,7 @@ rfc2822_parser_feed(struct rfc2822_parser *rp, const char *line) char buffer[RFC2822_MAX_LINE_SIZE+1]; /* in header and line is not a continuation, execute callback */ - if (rp->in_hdr && (*line == '\0' || !isspace(*line))) + if (rp->in_hdr && (*line == '\0' || !isspace((unsigned char)*line))) header_callback(rp); /* no longer in headers */ diff --git a/smtpd/scheduler.c b/smtpd/scheduler.c index f8516f2d..f6c11de8 100644 --- a/smtpd/scheduler.c +++ b/smtpd/scheduler.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scheduler.c,v 1.55 2016/09/08 12:06:43 eric Exp $ */ +/* $OpenBSD: scheduler.c,v 1.56 2017/01/09 14:49:22 reyk Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -306,7 +306,7 @@ scheduler_imsg(struct mproc *p, struct imsg *imsg) m_msg(&m, imsg); m_get_int(&m, &v); m_end(&m); - log_verbose(v); + log_setverbose(v); return; case IMSG_CTL_PROFILE: diff --git a/smtpd/scheduler_ramqueue.c b/smtpd/scheduler_ramqueue.c index d8d7c05e..ffc0b3e6 100644 --- a/smtpd/scheduler_ramqueue.c +++ b/smtpd/scheduler_ramqueue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scheduler_ramqueue.c,v 1.42 2015/10/29 10:25:36 sunil Exp $ */ +/* $OpenBSD: scheduler_ramqueue.c,v 1.43 2017/01/09 09:53:23 reyk Exp $ */ /* * Copyright (c) 2012 Gilles Chehade <gilles@poolp.org> @@ -255,12 +255,12 @@ scheduler_ram_commit(uint32_t msgid) update = tree_xpop(&updates, msgid); r = update->evpcount; - if (verbose & TRACE_SCHEDULER) + if (tracing & TRACE_SCHEDULER) rq_queue_dump(update, "update to commit"); rq_queue_merge(&ramqueue, update); - if (verbose & TRACE_SCHEDULER) + if (tracing & TRACE_SCHEDULER) rq_queue_dump(&ramqueue, "resulting queue"); rq_queue_schedule(&ramqueue); @@ -481,7 +481,7 @@ scheduler_ram_batch(int mask, int *delay, size_t *count, uint64_t *evpids, int * currtime = time(NULL); rq_queue_schedule(&ramqueue); - if (verbose & TRACE_SCHEDULER) + if (tracing & TRACE_SCHEDULER) rq_queue_dump(&ramqueue, "scheduler_ram_batch()"); i = 0; diff --git a/smtpd/smtp_session.c b/smtpd/smtp_session.c index ed20610d..c4c0ac9d 100644 --- a/smtpd/smtp_session.c +++ b/smtpd/smtp_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtp_session.c,v 1.300 2016/11/24 21:25:21 eric Exp $ */ +/* $OpenBSD: smtp_session.c,v 1.302 2016/11/30 17:43:32 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -116,8 +116,7 @@ struct smtp_tx { size_t datain; size_t odatalen; - struct iobuf obuf; - struct io oev; + struct io *oev; int hdrdone; int rcvcount; int dataeom; @@ -131,8 +130,7 @@ struct smtp_tx { struct smtp_session { uint64_t id; - struct iobuf iobuf; - struct io io; + struct io *io; struct listener *listener; void *ssl_ctx; struct sockaddr_storage ss; @@ -642,19 +640,14 @@ smtp_session(struct listener *listener, int sock, if ((s = calloc(1, sizeof(*s))) == NULL) return (-1); - if (iobuf_init(&s->iobuf, LINE_MAX, LINE_MAX) == -1) { - free(s); - return (-1); - } - s->id = generate_uid(); s->listener = listener; memmove(&s->ss, ss, sizeof(*ss)); - io_init(&s->io, &s->iobuf); - io_set_callback(&s->io, smtp_io, s); - io_set_fd(&s->io, sock); - io_set_timeout(&s->io, SMTPD_SESSION_TIMEOUT * 1000); - io_set_write(&s->io); + s->io = io_new(); + io_set_callback(s->io, smtp_io, s); + io_set_fd(s->io, sock); + io_set_timeout(s->io, SMTPD_SESSION_TIMEOUT * 1000); + io_set_write(s->io); s->state = STATE_NEW; @@ -966,8 +959,8 @@ smtp_session_imsg(struct mproc *p, struct imsg *imsg) sizeof *resp_ca_cert, "smtp:ca_cert"); ssl_ctx = dict_get(env->sc_ssl_dict, resp_ca_cert->name); ssl = ssl_smtp_init(ssl_ctx, s->listener->flags & F_TLS_VERIFY); - io_set_read(&s->io); - io_start_tls(&s->io, ssl); + io_set_read(s->io); + io_start_tls(s->io, ssl); explicit_bzero(resp_ca_cert->cert, resp_ca_cert->cert_len); free(resp_ca_cert->cert); @@ -988,7 +981,7 @@ smtp_session_imsg(struct mproc *p, struct imsg *imsg) return; } smtp_tls_verified(s); - io_resume(&s->io, IO_PAUSE_IN); + io_resume(s->io, IO_IN); return; } @@ -1002,7 +995,7 @@ smtp_tls_verified(struct smtp_session *s) { X509 *x; - x = SSL_get_peer_certificate(io_ssl(&s->io)); + x = SSL_get_peer_certificate(io_ssl(s->io)); if (x) { log_info("%016"PRIx64" smtp " "event=client-cert-check address=%s host=%s result=\"%s\"", @@ -1013,7 +1006,7 @@ smtp_tls_verified(struct smtp_session *s) if (s->listener->flags & F_SMTPS) { stat_increment("smtp.smtps", 1); - io_set_write(&s->io); + io_set_write(s->io); smtp_send_banner(s); } else { @@ -1185,20 +1178,19 @@ smtp_filter_fd(uint64_t id, int fd) return; } - iobuf_init(&s->tx->obuf, 0, 0); io_set_nonblocking(fd); - io_init(&s->tx->oev, &s->tx->obuf); - io_set_callback(&s->tx->oev, smtp_data_io, s); - io_set_fd(&s->tx->oev, fd); + s->tx->oev = io_new(); + io_set_callback(s->tx->oev, smtp_data_io, s); + io_set_fd(s->tx->oev, fd); - io_print(&s->tx->oev, "Received: "); + io_print(s->tx->oev, "Received: "); if (!(s->listener->flags & F_MASK_SOURCE)) { - io_printf(&s->tx->oev, "from %s (%s [%s])", + io_printf(s->tx->oev, "from %s (%s [%s])", s->helo, s->hostname, ss_to_text(&s->ss)); } - io_printf(&s->tx->oev, "\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" : "", @@ -1207,33 +1199,33 @@ smtp_filter_fd(uint64_t id, int fd) s->tx->msgid); if (s->flags & SF_SECURE) { - x = SSL_get_peer_certificate(io_ssl(&s->io)); - io_printf(&s->tx->oev, " (%s:%s:%d:%s)", - SSL_get_version(io_ssl(&s->io)), - SSL_get_cipher_name(io_ssl(&s->io)), - SSL_get_cipher_bits(io_ssl(&s->io), NULL), + x = SSL_get_peer_certificate(io_ssl(s->io)); + io_printf(s->tx->oev, " (%s:%s:%d:%s)", + SSL_get_version(io_ssl(s->io)), + SSL_get_cipher_name(io_ssl(s->io)), + SSL_get_cipher_bits(io_ssl(s->io), NULL), (s->flags & SF_VERIFIED) ? "YES" : (x ? "FAIL" : "NO")); if (x) X509_free(x); if (s->listener->flags & F_RECEIVEDAUTH) { - io_printf(&s->tx->oev, " auth=%s", s->username[0] ? "yes" : "no"); + io_printf(s->tx->oev, " auth=%s", s->username[0] ? "yes" : "no"); if (s->username[0]) - io_printf(&s->tx->oev, " user=%s", s->username); + io_printf(s->tx->oev, " user=%s", s->username); } } if (s->tx->rcptcount == 1) { - io_printf(&s->tx->oev, "\n\tfor <%s@%s>", + io_printf(s->tx->oev, "\n\tfor <%s@%s>", s->tx->evp.rcpt.user, s->tx->evp.rcpt.domain); } - io_printf(&s->tx->oev, ";\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 = io_queued(&s->tx->oev); + s->tx->odatalen = io_queued(s->tx->oev); - io_set_write(&s->tx->oev); + io_set_write(s->tx->oev); smtp_enter_state(s, STATE_BODY); smtp_reply(s, "354 Enter mail, end with \".\"" @@ -1257,13 +1249,13 @@ smtp_io(struct io *io, int evt, void *arg) case IO_TLSREADY: log_info("%016"PRIx64" smtp event=starttls address=%s host=%s ciphers=\"%s\"", - s->id, ss_to_text(&s->ss), s->hostname, ssl_to_text(io_ssl(&s->io))); + s->id, ss_to_text(&s->ss), s->hostname, ssl_to_text(io_ssl(s->io))); s->flags |= SF_SECURE; s->helo[0] = '\0'; if (smtp_verify_certificate(s)) { - io_pause(&s->io, IO_PAUSE_IN); + io_pause(s->io, IO_IN); break; } @@ -1280,8 +1272,8 @@ smtp_io(struct io *io, int evt, void *arg) case IO_DATAIN: nextline: - line = io_getline(&s->io, &len); - if ((line == NULL && io_datalen(&s->io) >= 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", @@ -1302,7 +1294,7 @@ smtp_io(struct io *io, int evt, void *arg) } /* Pipelining not supported */ - if (io_datalen(&s->io)) { + 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), @@ -1321,7 +1313,7 @@ smtp_io(struct io *io, int evt, void *arg) io_set_write(io); s->tx->dataeom = 1; - if (io_queued(&s->tx->oev) == 0) + if (io_queued(s->tx->oev) == 0) smtp_data_io_done(s); return; } @@ -1400,7 +1392,6 @@ smtp_tx(struct smtp_session *s) return 0; TAILQ_INIT(&tx->rcpts); - io_init(&tx->oev, NULL); s->tx = tx; tx->session = s; @@ -1454,6 +1445,9 @@ smtp_tx_free(struct smtp_tx *tx) free(rcpt); } + if (tx->oev) + io_free(tx->oev); + tx->session->tx = NULL; free(tx); @@ -1472,21 +1466,21 @@ smtp_data_io(struct io *io, int evt, void *arg) case IO_DISCONNECTED: case IO_ERROR: log_debug("debug: smtp: %p: io error on mfa", s); - io_clear(&s->tx->oev); - iobuf_clear(&s->tx->obuf); + io_free(s->tx->oev); + s->tx->oev = NULL; s->tx->msgflags |= MF_ERROR_IO; - if (io_paused(&s->io, IO_PAUSE_IN)) { + if (io_paused(s->io, IO_IN)) { log_debug("debug: smtp: %p: resuming session after mfa error", s); - io_resume(&s->io, IO_PAUSE_IN); + io_resume(s->io, IO_IN); } break; case IO_LOWAT: - if (s->tx->dataeom && io_queued(&s->tx->oev) == 0) { + if (s->tx->dataeom && io_queued(s->tx->oev) == 0) { smtp_data_io_done(s); - } else if (io_paused(&s->io, IO_PAUSE_IN)) { + } else if (io_paused(s->io, IO_IN)) { log_debug("debug: smtp: %p: filter congestion over: resuming session", s); - io_resume(&s->io, IO_PAUSE_IN); + io_resume(s->io, IO_IN); } break; @@ -1499,8 +1493,11 @@ static void smtp_data_io_done(struct smtp_session *s) { log_debug("debug: smtp: %p: data io done (%zu bytes)", s, s->tx->odatalen); - io_clear(&s->tx->oev); - iobuf_clear(&s->tx->obuf); + + if (s->tx->oev) { + io_free(s->tx->oev); + s->tx->oev = NULL; + } if (s->tx->msgflags & MF_ERROR) { @@ -2075,7 +2072,7 @@ smtp_lookup_servername(struct smtp_session *s) if (s->listener->hostnametable[0]) { sa_len = sizeof(ss); sa = (struct sockaddr *)&ss; - if (getsockname(io_fileno(&s->io), sa, &sa_len) == -1) { + if (getsockname(io_fileno(s->io), sa, &sa_len) == -1) { log_warn("warn: getsockname()"); } else { @@ -2103,7 +2100,7 @@ smtp_connected(struct smtp_session *s) s->id, ss_to_text(&s->ss), s->hostname); sl = sizeof(ss); - if (getsockname(io_fileno(&s->io), (struct sockaddr*)&ss, &sl) == -1) { + if (getsockname(io_fileno(s->io), (struct sockaddr*)&ss, &sl) == -1) { smtp_free(s, strerror(errno)); return; } @@ -2162,7 +2159,7 @@ smtp_message_printf(struct smtp_session *s, const char *fmt, ...) return -1; va_start(ap, fmt); - len = io_vprintf(&s->tx->oev, fmt, ap); + len = io_vprintf(s->tx->oev, fmt, ap); va_end(ap); if (len < 0) { @@ -2192,7 +2189,7 @@ smtp_reply(struct smtp_session *s, char *fmt, ...) log_trace(TRACE_SMTP, "smtp: %p: >>> %s", s, buf); - io_xprintf(&s->io, "%s\r\n", buf); + io_xprintf(s->io, "%s\r\n", buf); switch (buf[0]) { case '5': @@ -2239,11 +2236,8 @@ smtp_free(struct smtp_session *s, const char * reason) tree_pop(&wait_filter_data, s->id); if (s->tx) { - if (s->tx->msgid) { + if (s->tx->msgid) smtp_queue_rollback(s); - io_clear(&s->tx->oev); - iobuf_clear(&s->tx->obuf); - } smtp_filter_tx_rollback(s); smtp_tx_free(s->tx); } @@ -2256,8 +2250,7 @@ smtp_free(struct smtp_session *s, const char * reason) if (s->flags & SF_SECURE && s->listener->flags & F_STARTTLS) stat_decrement("smtp.tls", 1); - io_clear(&s->io); - iobuf_clear(&s->iobuf); + io_free(s->io); free(s); smtp_collect(); @@ -2346,10 +2339,10 @@ smtp_verify_certificate(struct smtp_session *s) >= sizeof req_ca_vrfy.name) return 0; - x = SSL_get_peer_certificate(io_ssl(&s->io)); + x = SSL_get_peer_certificate(io_ssl(s->io)); if (x == NULL) return 0; - xchain = SSL_get_peer_cert_chain(io_ssl(&s->io)); + xchain = SSL_get_peer_cert_chain(io_ssl(s->io)); /* * Client provided a certificate and possibly a certificate chain. @@ -2635,9 +2628,9 @@ smtp_filter_dataline(struct smtp_session *s, const char *line) return; } - if (io_queued(&s->tx->oev) > DATA_HIWAT && !io_paused(&s->io, IO_PAUSE_IN)) { + if (io_queued(s->tx->oev) > DATA_HIWAT && !io_paused(s->io, IO_IN)) { log_debug("debug: smtp: %p: filter congestion: pausing session", s); - io_pause(&s->io, IO_PAUSE_IN); + io_pause(s->io, IO_IN); } } diff --git a/smtpd/smtpctl.c b/smtpd/smtpctl.c index 526b128b..412aebd6 100644 --- a/smtpd/smtpctl.c +++ b/smtpd/smtpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpctl.c,v 1.151 2016/09/04 09:33:49 eric Exp $ */ +/* $OpenBSD: smtpctl.c,v 1.152 2017/01/09 09:53:23 reyk Exp $ */ /* * Copyright (c) 2013 Eric Faurot <eric@openbsd.org> @@ -730,7 +730,7 @@ do_show_queue(int argc, struct parameter *argv) now = time(NULL); if (!srv_connect()) { - log_init(1); + log_init(1, LOG_MAIL); queue_init("fs", 0); if (chroot(PATH_SPOOL) == -1 || chdir("/") == -1) err(1, "%s", PATH_SPOOL); diff --git a/smtpd/smtpctl/CVS/Entries b/smtpd/smtpctl/CVS/Entries index 87a68f06..8214dd8b 100644 --- a/smtpd/smtpctl/CVS/Entries +++ b/smtpd/smtpctl/CVS/Entries @@ -1,2 +1,2 @@ -/Makefile/1.44/Sun Jul 3 14:53:32 2016// +/Makefile/1.44/Wed Mar 30 06:38:46 2016// D diff --git a/smtpd/smtpd.8 b/smtpd/smtpd.8 index 1ae5363c..e3429f07 100644 --- a/smtpd/smtpd.8 +++ b/smtpd/smtpd.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: smtpd.8,v 1.31 2016/10/19 10:06:30 gilles Exp $ +.\" $OpenBSD: smtpd.8,v 1.32 2017/01/03 22:11:39 jmc Exp $ .\" .\" Copyright (c) 2012, Eric Faurot <eric@openbsd.org> .\" Copyright (c) 2008, Gilles Chehade <gilles@poolp.org> @@ -16,7 +16,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: October 19 2016 $ +.Dd $Mdocdate: January 3 2017 $ .Dt SMTPD 8 .Os .Sh NAME @@ -145,8 +145,11 @@ socket used for communication with .Xr smtpctl 8 . .It Pa /var/spool/smtpd/ Spool directories for mail during processing. +.It Pa ~/.forward +User email forwarding information. .El .Sh SEE ALSO +.Xr forward 5 , .Xr smtpd.conf 5 , .Xr mailwrapper 8 , .Xr smtpctl 8 diff --git a/smtpd/smtpd.c b/smtpd/smtpd.c index d428db9d..533cd70e 100644 --- a/smtpd/smtpd.c +++ b/smtpd/smtpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.c,v 1.287 2016/10/19 14:06:07 jmc Exp $ */ +/* $OpenBSD: smtpd.c,v 1.288 2017/01/09 09:53:23 reyk Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -139,10 +139,8 @@ const char *backend_scheduler = "ramqueue"; const char *backend_stat = "ram"; int profiling = 0; -int verbose = 0; int debug = 0; int foreground = 0; -int foreground_log = 0; int control_socket = -1; struct tree children; @@ -248,7 +246,7 @@ parent_imsg(struct mproc *p, struct imsg *imsg) m_msg(&m, imsg); m_get_int(&m, &v); m_end(&m); - log_verbose(v); + log_trace_verbose(v); return; case IMSG_CTL_PROFILE: @@ -456,9 +454,9 @@ main(int argc, char *argv[]) flags = 0; opts = 0; debug = 0; - verbose = 0; + tracing = 0; - log_init(1); + log_init(1, LOG_MAIL); TAILQ_INIT(&offline_q); @@ -503,41 +501,41 @@ main(int argc, char *argv[]) case 'T': if (!strcmp(optarg, "imsg")) - verbose |= TRACE_IMSG; + tracing |= TRACE_IMSG; else if (!strcmp(optarg, "io")) - verbose |= TRACE_IO; + tracing |= TRACE_IO; else if (!strcmp(optarg, "smtp")) - verbose |= TRACE_SMTP; + tracing |= TRACE_SMTP; else if (!strcmp(optarg, "mfa") || !strcmp(optarg, "filter") || !strcmp(optarg, "filters")) - verbose |= TRACE_FILTERS; + tracing |= TRACE_FILTERS; else if (!strcmp(optarg, "mta") || !strcmp(optarg, "transfer")) - verbose |= TRACE_MTA; + tracing |= TRACE_MTA; else if (!strcmp(optarg, "bounce") || !strcmp(optarg, "bounces")) - verbose |= TRACE_BOUNCE; + tracing |= TRACE_BOUNCE; else if (!strcmp(optarg, "scheduler")) - verbose |= TRACE_SCHEDULER; + tracing |= TRACE_SCHEDULER; else if (!strcmp(optarg, "lookup")) - verbose |= TRACE_LOOKUP; + tracing |= TRACE_LOOKUP; else if (!strcmp(optarg, "stat") || !strcmp(optarg, "stats")) - verbose |= TRACE_STAT; + tracing |= TRACE_STAT; else if (!strcmp(optarg, "rules")) - verbose |= TRACE_RULES; + tracing |= TRACE_RULES; else if (!strcmp(optarg, "mproc")) - verbose |= TRACE_MPROC; + tracing |= TRACE_MPROC; else if (!strcmp(optarg, "expand")) - verbose |= TRACE_EXPAND; + tracing |= TRACE_EXPAND; else if (!strcmp(optarg, "table") || !strcmp(optarg, "tables")) - verbose |= TRACE_TABLES; + tracing |= TRACE_TABLES; else if (!strcmp(optarg, "queue")) - verbose |= TRACE_QUEUE; + tracing |= TRACE_QUEUE; else if (!strcmp(optarg, "all")) - verbose |= ~TRACE_DEBUG; + tracing |= ~TRACE_DEBUG; else if (!strcmp(optarg, "profstat")) profiling |= PROFILE_TOSTAT; else if (!strcmp(optarg, "profile-imsg")) @@ -557,7 +555,7 @@ main(int argc, char *argv[]) flags |= SMTPD_MDA_PAUSED; break; case 'v': - verbose |= TRACE_DEBUG; + tracing |= TRACE_DEBUG; break; case 'x': rexec = optarg; @@ -601,9 +599,8 @@ main(int argc, char *argv[]) if (geteuid()) errx(1, "need root privileges"); - log_init(foreground_log); - log_verbose(verbose); - + log_init(foreground_log, LOG_MAIL); + log_trace_verbose(tracing); load_pki_tree(); load_pki_keys(); @@ -874,6 +871,8 @@ setup_proc(void) struct imsg imsg; int setup = 1; + log_procinit(proc_title(smtpd_process)); + p_parent = calloc(1, sizeof(*p_parent)); if (p_parent == NULL) fatal("calloc"); diff --git a/smtpd/smtpd.conf.5 b/smtpd/smtpd.conf.5 index 2914f2c3..4ea67179 100644 --- a/smtpd/smtpd.conf.5 +++ b/smtpd/smtpd.conf.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: smtpd.conf.5,v 1.166 2016/09/11 10:56:45 gilles Exp $ +.\" $OpenBSD: smtpd.conf.5,v 1.167 2017/01/08 01:38:31 schwarze Exp $ .\" .\" Copyright (c) 2008 Janne Johansson <jj@openbsd.org> .\" Copyright (c) 2009 Jacek Masiulaniec <jacekm@dobremiasto.net> @@ -17,7 +17,7 @@ .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" .\" -.Dd $Mdocdate: September 11 2016 $ +.Dd $Mdocdate: January 8 2017 $ .Dt SMTPD.CONF 5 .Os .Sh NAME @@ -88,9 +88,6 @@ decision comes the matching of optional session related properties: If specified, the rule will only be matched if the client session was authenticated either by requesting authentication over the network or because the message was submitted over the local enqueuer. -.El -.Pp -.Bl -tag -width Ds .It Xo .Ic tagged .Op Ic \&! diff --git a/smtpd/smtpd.h b/smtpd/smtpd.h index 46819c5e..e1872f43 100644 --- a/smtpd/smtpd.h +++ b/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.525 2016/11/25 09:21:21 gilles Exp $ */ +/* $OpenBSD: smtpd.h,v 1.529 2017/02/03 08:23:46 guenther Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -22,10 +22,12 @@ #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) #endif +#include <netinet/in.h> +#include <event.h> + #include "smtpd-defines.h" #include "smtpd-api.h" #include "ioev.h" -#include "iobuf.h" #include "rfc2822.h" @@ -1017,7 +1019,7 @@ struct msg { extern enum smtp_proc_type smtpd_process; -extern int verbose; +extern int tracing; extern int foreground_log; extern int profiling; @@ -1493,8 +1495,6 @@ void *xcalloc(size_t, size_t, const char *); char *xstrdup(const char *, const char *); void *xmemdup(const void *, size_t, const char *); char *strip(char *); -void iobuf_xinit(struct iobuf *, size_t, size_t, const char *); -void iobuf_xfqueue(struct iobuf *, const char *, const char *, ...); int io_xprint(struct io *, const char *); int io_xprintf(struct io *, const char *, ...); void log_envelope(const struct envelope *, const char *, const char *, diff --git a/smtpd/smtpd/CVS/Entries b/smtpd/smtpd/CVS/Entries index 5ff3f2a2..bd198cee 100644 --- a/smtpd/smtpd/CVS/Entries +++ b/smtpd/smtpd/CVS/Entries @@ -1,2 +1,2 @@ -/Makefile/1.85/Sun Jul 3 14:53:32 2016// +/Makefile/1.85/Sat Jan 9 09:48:03 2016// D diff --git a/smtpd/table.5 b/smtpd/table.5 index e76d356a..f44c0a6b 100644 --- a/smtpd/table.5 +++ b/smtpd/table.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: table.5,v 1.5 2015/11/30 17:03:05 jmc Exp $ +.\" $OpenBSD: table.5,v 1.6 2017/02/06 06:27:01 tb Exp $ .\" .\" Copyright (c) 2013 Eric Faurot <eric@openbsd.org> .\" Copyright (c) 2013 Gilles Chehade <gilles@poolp.org> @@ -16,7 +16,7 @@ .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" .\" -.Dd $Mdocdate: November 30 2015 $ +.Dd $Mdocdate: February 6 2017 $ .Dt TABLE 5 .Os .Sh NAME @@ -127,8 +127,8 @@ accept for any relay tls+auth://label@host auth <credentials> In a listener context, the credentials are a mapping of username and encrypted passwords: .Bd -literal -offset indent -user1 $2a$06$hIJ4QfMcp.90nJwKqGbKM.MybArjHOTpEtoTV.DgLYAiThuoYmTSe -user2 $2a$06$bwSmUOBGcZGamIfRuXGTvuTo3VLbPG9k5yeKNMBtULBhksV5KdGsK +user1 $2b$10$hIJ4QfMcp.90nJwKqGbKM.MybArjHOTpEtoTV.DgLYAiThuoYmTSe +user2 $2b$10$bwSmUOBGcZGamIfRuXGTvuTo3VLbPG9k5yeKNMBtULBhksV5KdGsK .Ed .Pp The passwords are to be encrypted using the diff --git a/smtpd/util.c b/smtpd/util.c index 7c87019d..4a509ed4 100644 --- a/smtpd/util.c +++ b/smtpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.129 2016/11/17 17:34:55 eric Exp $ */ +/* $OpenBSD: util.c,v 1.132 2017/01/09 14:49:22 reyk Exp $ */ /* * Copyright (c) 2000,2001 Markus Friedl. All rights reserved. @@ -55,6 +55,9 @@ const char *log_in6addr(const struct in6_addr *); const char *log_sockaddr(struct sockaddr *); static int parse_mailname_file(char *, size_t); +int tracing = 0; +int foreground_log = 0; + void * xmalloc(size_t size, const char *where) { @@ -109,31 +112,6 @@ xmemdup(const void *ptr, size_t size, const char *where) } #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) { - log_warnx("%s: iobuf_init(%p, %zu, %zu)", where, io, size, max); - fatalx("exiting"); - } -} - -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) { - log_warnx("%s: iobuf_xfqueue(%p, %s, ...)", where, io, fmt); - fatalx("exiting"); - } -} - int io_xprintf(struct io *io, const char *fmt, ...) { @@ -815,3 +793,24 @@ base64_decode(char const *src, unsigned char *dest, size_t destsize) { return __b64_pton(src, dest, destsize); } + +void +log_trace(int mask, const char *emsg, ...) +{ + va_list ap; + + if (tracing & mask) { + va_start(ap, emsg); + vlog(LOG_DEBUG, emsg, ap); + va_end(ap); + } +} + +void +log_trace_verbose(int v) +{ + tracing = v; + + /* Set debug logging in log.c */ + log_setverbose(v & TRACE_DEBUG ? 2 : foreground_log); +} |