From 9421168466f066866b051490c7c8a1144a077dfb Mon Sep 17 00:00:00 2001 From: Gilles Chehade Date: Wed, 20 Feb 2019 12:59:08 +0100 Subject: sync --- smtpd/lka_filter.c | 8 ++++---- smtpd/mail.lmtp.c | 7 +++++-- smtpd/parse.y | 6 +++--- smtpd/smtp_session.c | 21 ++++++++++++++++---- smtpd/smtpctl.c | 11 ++++++++++- smtpd/smtpd.c | 2 +- smtpd/smtpd.h | 2 +- smtpd/table.c | 56 +++++++++++++++++++++++++++------------------------- smtpd/util.c | 2 +- 9 files changed, 71 insertions(+), 44 deletions(-) diff --git a/smtpd/lka_filter.c b/smtpd/lka_filter.c index eeba23e2..a10d9cbe 100644 --- a/smtpd/lka_filter.c +++ b/smtpd/lka_filter.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka_filter.c,v 1.33 2018/12/26 15:55:09 eric Exp $ */ +/* $OpenBSD: lka_filter.c,v 1.34 2019/01/15 04:49:50 sunil Exp $ */ /* * Copyright (c) 2018 Gilles Chehade @@ -729,13 +729,13 @@ filter_protocol_query(struct filter *filter, uint64_t token, uint64_t reqid, con "filter|%d|%zd|smtp-in|%s|%016"PRIx64"|%016"PRIx64"|%s|%s\n", PROTOCOL_VERSION, tm, - phase, token, reqid, fs->rdns, param); + phase, reqid, token, fs->rdns, param); else n = io_printf(lka_proc_get_io(filter->proc), "filter|%d|%zd|smtp-in|%s|%016"PRIx64"|%016"PRIx64"|%s\n", PROTOCOL_VERSION, tm, - phase, token, reqid, param); + phase, reqid, token, param); if (n == -1) fatalx("failed to write to processor"); } @@ -751,7 +751,7 @@ filter_data_query(struct filter *filter, uint64_t token, uint64_t reqid, const c "filter|%d|%zd|smtp-in|data-line|" "%016"PRIx64"|%016"PRIx64"|%s\n", PROTOCOL_VERSION, - tm, token, reqid, line); + tm, reqid, token, line); if (n == -1) fatalx("failed to write to processor"); } diff --git a/smtpd/mail.lmtp.c b/smtpd/mail.lmtp.c index d831ca2f..6f35f7f0 100644 --- a/smtpd/mail.lmtp.c +++ b/smtpd/mail.lmtp.c @@ -214,9 +214,11 @@ lmtp_engine(FILE *conn, struct session *session) enum phase phase = PHASE_BANNER; do { + fflush(conn); if ((linelen = getline(&line, &linesize, conn)) == -1) err(1, "getline"); line[strcspn(line, "\n")] = '\0'; + line[strcspn(line, "\r")] = '\0'; if (linelen < 4 || !isdigit(line[0]) || @@ -271,9 +273,10 @@ lmtp_engine(FILE *conn, struct session *session) case PHASE_QUIT: exit(0); } - if (ferror(stdin)) - err(1, "getline"); } while (1); + + if (ferror(conn)) + err(1, "getline"); } static void diff --git a/smtpd/parse.y b/smtpd/parse.y index 33159dec..88f2c0b5 100644 --- a/smtpd/parse.y +++ b/smtpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.250 2018/12/28 14:21:02 eric Exp $ */ +/* $OpenBSD: parse.y,v 1.251 2019/02/13 22:57:08 deraadt Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -2545,7 +2545,7 @@ top: if (c == '-' || isdigit(c)) { do { *p++ = c; - if ((unsigned)(p-buf) >= sizeof(buf)) { + if ((size_t)(p-buf) >= sizeof(buf)) { yyerror("string too long"); return (findeol()); } @@ -2591,7 +2591,7 @@ nodigits: if (isalnum(c) || c == ':' || c == '_') { do { *p++ = c; - if ((unsigned)(p-buf) >= sizeof(buf)) { + if ((size_t)(p-buf) >= sizeof(buf)) { yyerror("string too long"); return (findeol()); } diff --git a/smtpd/smtp_session.c b/smtpd/smtp_session.c index d9f2dd56..1fc67d77 100644 --- a/smtpd/smtp_session.c +++ b/smtpd/smtp_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtp_session.c,v 1.387 2019/01/05 09:43:39 gilles Exp $ */ +/* $OpenBSD: smtp_session.c,v 1.389 2019/02/20 11:56:27 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -686,6 +686,7 @@ smtp_session_imsg(struct mproc *p, struct imsg *imsg) struct smtp_session *s; struct smtp_rcpt *rcpt; char user[LOGIN_NAME_MAX]; + char tmp[SMTP_LINE_MAX]; struct msg m; const char *line, *helo; uint64_t reqid, evpid; @@ -727,14 +728,26 @@ smtp_session_imsg(struct mproc *p, struct imsg *imsg) m_get_string(&m, &line); m_end(&m); s = tree_xpop(&wait_lka_rcpt, reqid); + + tmp[0] = '\0'; + if (s->tx->evp.rcpt.user[0]) { + (void)strlcpy(tmp, s->tx->evp.rcpt.user, sizeof tmp); + if (s->tx->evp.rcpt.domain[0]) { + (void)strlcat(tmp, "@", sizeof tmp); + (void)strlcat(tmp, s->tx->evp.rcpt.domain, + sizeof tmp); + } + } + switch (status) { case LKA_OK: fatalx("unexpected ok"); case LKA_PERMFAIL: - smtp_reply(s, "%s", line); + smtp_reply(s, "%s: <%s>", line, tmp); break; case LKA_TEMPFAIL: - smtp_reply(s, "%s", line); + smtp_reply(s, "%s: <%s>", line, tmp); + break; } return; @@ -1963,7 +1976,7 @@ smtp_lookup_servername(struct smtp_session *s) m_create(p_lka, IMSG_SMTP_LOOKUP_HELO, 0, 0, -1); m_add_id(p_lka, s->id); m_add_string(p_lka, s->listener->hostnametable); - m_add_sockaddr(p_lka, (struct sockaddr*)&s->ss); + m_add_sockaddr(p_lka, (struct sockaddr*)&s->listener->ss); m_close(p_lka); tree_xset(&wait_lka_helo, s->id, s); return; diff --git a/smtpd/smtpctl.c b/smtpd/smtpctl.c index a78c26fa..4b44d9dd 100644 --- a/smtpd/smtpctl.c +++ b/smtpd/smtpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpctl.c,v 1.162 2018/05/31 21:06:12 gilles Exp $ */ +/* $OpenBSD: smtpctl.c,v 1.163 2019/01/14 09:37:40 eric Exp $ */ /* * Copyright (c) 2013 Eric Faurot @@ -248,6 +248,15 @@ srv_get_string(const char **s) if (rlen == 0) errx(1, "message too short"); + rlen -= 1; + if (*rdata++ == '\0') { + *s = NULL; + return; + } + + if (rlen == 0) + errx(1, "bogus string"); + end = memchr(rdata, 0, rlen); if (end == NULL) errx(1, "unterminated string"); diff --git a/smtpd/smtpd.c b/smtpd/smtpd.c index 87344b53..66022264 100644 --- a/smtpd/smtpd.c +++ b/smtpd/smtpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.c,v 1.315 2018/12/23 16:37:53 eric Exp $ */ +/* $OpenBSD: smtpd.c,v 1.317 2019/01/30 21:31:48 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade diff --git a/smtpd/smtpd.h b/smtpd/smtpd.h index 019d402a..10420526 100644 --- a/smtpd/smtpd.h +++ b/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.617 2019/01/05 09:48:32 gilles Exp $ */ +/* $OpenBSD: smtpd.h,v 1.619 2019/01/30 21:31:48 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade diff --git a/smtpd/table.c b/smtpd/table.c index 7b1fcd2a..b79451ca 100644 --- a/smtpd/table.c +++ b/smtpd/table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table.c,v 1.47 2018/12/28 15:09:28 eric Exp $ */ +/* $OpenBSD: table.c,v 1.48 2019/01/10 07:40:52 eric Exp $ */ /* * Copyright (c) 2013 Eric Faurot @@ -27,14 +27,11 @@ #include #include -#include -#include #include #include #include #include #include -#include #include #include #include @@ -95,8 +92,10 @@ table_service_name(enum table_service s) case K_ADDRNAME: return "ADDRNAME"; case K_MAILADDRMAP: return "MAILADDRMAP"; case K_RELAYHOST: return "RELAYHOST"; - default: return "???"; + case K_STRING: return "STRING"; + case K_REGEX: return "REGEX"; } + return "???"; } struct table * @@ -115,40 +114,41 @@ int table_lookup(struct table *table, enum table_service kind, const char *key, union lookup *lk) { - int r; - char lkey[1024], *buf = NULL; + char lkey[1024], *buf = NULL; + int r; + r = -1; if (table->t_backend->lookup == NULL) - return (-1); - - if (!lowercase(lkey, key, sizeof lkey)) { + errno = ENOTSUP; + else if (!lowercase(lkey, key, sizeof lkey)) { log_warnx("warn: lookup key too long: %s", key); - return -1; + errno = EINVAL; } - - r = table->t_backend->lookup(table, kind, lkey, lk ? &buf : NULL); + else + r = table->t_backend->lookup(table, kind, lkey, lk ? &buf : NULL); if (r == 1) { log_trace(TRACE_LOOKUP, "lookup: %s \"%s\" as %s in table %s:%s -> %s%s%s", - lk ? "lookup" : "check", - lkey, + lk ? "lookup" : "match", + key, table_service_name(kind), table->t_backend->name, table->t_name, lk ? "\"" : "", - (lk) ? buf : "found", + lk ? buf : "true", lk ? "\"" : ""); if (buf) r = table_parse_lookup(kind, lkey, buf, lk); } else - log_trace(TRACE_LOOKUP, "lookup: %s \"%s\" as %s in table %s:%s -> %d", - lk ? "lookup" : "check", - lkey, + log_trace(TRACE_LOOKUP, "lookup: %s \"%s\" as %s in table %s:%s -> %s%s", + lk ? "lookup" : "match", + key, table_service_name(kind), table->t_backend->name, table->t_name, - r); + (r == -1) ? "error: " : (lk ? "none" : "false"), + (r == -1) ? strerror(errno) : ""); free(buf); @@ -158,13 +158,14 @@ table_lookup(struct table *table, enum table_service kind, const char *key, int table_fetch(struct table *table, enum table_service kind, union lookup *lk) { - int r; - char *buf = NULL; + char *buf = NULL; + int r; + r = -1; if (table->t_backend->fetch == NULL) - return (-1); - - r = table->t_backend->fetch(table, kind, &buf); + errno = ENOTSUP; + else + r = table->t_backend->fetch(table, kind, &buf); if (r == 1) { log_trace(TRACE_LOOKUP, "lookup: fetch %s from table %s:%s -> \"%s\"", @@ -175,11 +176,12 @@ table_fetch(struct table *table, enum table_service kind, union lookup *lk) r = table_parse_lookup(kind, NULL, buf, lk); } else - log_trace(TRACE_LOOKUP, "lookup: fetch %s from table %s:%s -> %d", + log_trace(TRACE_LOOKUP, "lookup: fetch %s from table %s:%s -> %s%s", table_service_name(kind), table->t_backend->name, table->t_name, - r); + (r == -1) ? "error: " : "none", + (r == -1) ? strerror(errno) : ""); free(buf); diff --git a/smtpd/util.c b/smtpd/util.c index df7fabad..2d962848 100644 --- a/smtpd/util.c +++ b/smtpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.138 2018/10/31 16:32:12 gilles Exp $ */ +/* $OpenBSD: util.c,v 1.140 2019/01/30 21:33:34 gilles Exp $ */ /* * Copyright (c) 2000,2001 Markus Friedl. All rights reserved. -- cgit v1.2.3-59-g8ed1b