aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--smtpd/lka_filter.c8
-rw-r--r--smtpd/mail.lmtp.c7
-rw-r--r--smtpd/parse.y6
-rw-r--r--smtpd/smtp_session.c21
-rw-r--r--smtpd/smtpctl.c11
-rw-r--r--smtpd/smtpd.c2
-rw-r--r--smtpd/smtpd.h2
-rw-r--r--smtpd/table.c56
-rw-r--r--smtpd/util.c2
9 files changed, 71 insertions, 44 deletions
diff --git a/smtpd/lka_filter.c b/smtpd/lka_filter.c
index 4135de19..6ac692fc 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 <gilles@poolp.org>
@@ -731,13 +731,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");
}
@@ -753,7 +753,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 685ec504..e6e4fa14 100644
--- a/smtpd/mail.lmtp.c
+++ b/smtpd/mail.lmtp.c
@@ -216,9 +216,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]) ||
@@ -273,9 +275,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 d6cf8466..8f331315 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 <gilles@poolp.org>
@@ -2551,7 +2551,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());
}
@@ -2597,7 +2597,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 707e32cb..5fc2c796 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 <gilles@poolp.org>
@@ -692,6 +692,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;
@@ -733,14 +734,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;
@@ -1969,7 +1982,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 6e91ac29..42c018b9 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 <eric@openbsd.org>
@@ -269,6 +269,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 2347afa4..1052ca52 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 <gilles@poolp.org>
diff --git a/smtpd/smtpd.h b/smtpd/smtpd.h
index eaf8a62b..986bfeea 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 <gilles@poolp.org>
diff --git a/smtpd/table.c b/smtpd/table.c
index 12f2e0e6..469eeee1 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 <eric@openbsd.org>
@@ -29,14 +29,11 @@
#include <arpa/inet.h>
#include <net/if.h>
-#include <ctype.h>
-#include <err.h>
#include <errno.h>
#include <event.h>
#include <imsg.h>
#include <stdio.h>
#include <stdlib.h>
-#include <netdb.h>
#include <regex.h>
#include <limits.h>
#include <string.h>
@@ -101,8 +98,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 *
@@ -121,40 +120,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);
@@ -164,13 +164,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\"",
@@ -181,11 +182,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 dbcea86e..fd80b69a 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.