summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGilles Chehade <gilles@cvs.openbsd.org>2019-08-11 16:35:11 +0000
committerGilles Chehade <gilles@cvs.openbsd.org>2019-08-11 16:35:11 +0000
commitc71946aa0250051f291ec514bf4ab5d9a5155543 (patch)
treeaa455850dbc82ce201402658604a9414679f9493
parent7650f9e93bacdfd19f002c97dd10c58b45e7760d (diff)
fix rewrite action on filtering of MAIL FROM phase
basically the transaction must be created in the proceed function for the mail from phase, not in the checking function, otherwise the second pass in the check function will fail due to the tx already existing. reported by Niklas Hallqvist <niklas@appli.se>
-rw-r--r--usr.sbin/smtpd/parse.y6
-rw-r--r--usr.sbin/smtpd/smtp_session.c36
2 files changed, 30 insertions, 12 deletions
diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y
index b74a1e4af34..f958c711091 100644
--- a/usr.sbin/smtpd/parse.y
+++ b/usr.sbin/smtpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.255 2019/08/11 12:17:06 gilles Exp $ */
+/* $OpenBSD: parse.y,v 1.256 2019/08/11 16:35:10 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -1288,6 +1288,9 @@ REJECT STRING {
| DISCONNECT STRING {
filter_config->disconnect = $2;
}
+| REWRITE STRING {
+ filter_config->rewrite = $2;
+}
;
filter_phase_check_fcrdns:
@@ -2321,6 +2324,7 @@ lookup(char *s)
{ "regex", REGEX },
{ "reject", REJECT },
{ "relay", RELAY },
+ { "rewrite", REWRITE },
{ "rset", RSET },
{ "scheduler", SCHEDULER },
{ "senders", SENDERS },
diff --git a/usr.sbin/smtpd/smtp_session.c b/usr.sbin/smtpd/smtp_session.c
index 3bc45e2753c..54ab3040fd0 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.404 2019/08/10 16:07:01 gilles Exp $ */
+/* $OpenBSD: smtp_session.c,v 1.405 2019/08/11 16:35:10 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -1497,6 +1497,7 @@ smtp_check_mail_from(struct smtp_session *s, const char *args)
{
char *copy;
char tmp[SMTP_LINE_MAX];
+ struct mailaddr sender;
(void)strlcpy(tmp, args, sizeof tmp);
copy = tmp;
@@ -1534,18 +1535,10 @@ smtp_check_mail_from(struct smtp_session *s, const char *args)
return 0;
}
- if (!smtp_tx(s)) {
- smtp_reply(s, "421 %s Temporary Error",
- esc_code(ESC_STATUS_TEMPFAIL, ESC_OTHER_MAIL_SYSTEM_STATUS));
- smtp_enter_state(s, STATE_QUIT);
- return 0;
- }
-
- if (smtp_mailaddr(&s->tx->evp.sender, copy, 1, &copy,
- s->tx->session->smtpname) == 0) {
+ if (smtp_mailaddr(&sender, copy, 1, &copy,
+ s->smtpname) == 0) {
smtp_reply(s, "553 %s Sender address syntax error",
esc_code(ESC_STATUS_PERMFAIL, ESC_OTHER_ADDRESS_STATUS));
- smtp_tx_free(s->tx);
return 0;
}
@@ -1806,6 +1799,27 @@ smtp_proceed_starttls(struct smtp_session *s, const char *args)
static void
smtp_proceed_mail_from(struct smtp_session *s, const char *args)
{
+ char *copy;
+ char tmp[SMTP_LINE_MAX];
+
+ (void)strlcpy(tmp, args, sizeof tmp);
+ copy = tmp;
+
+ if (!smtp_tx(s)) {
+ smtp_reply(s, "421 %s Temporary Error",
+ esc_code(ESC_STATUS_TEMPFAIL, ESC_OTHER_MAIL_SYSTEM_STATUS));
+ smtp_enter_state(s, STATE_QUIT);
+ return;
+ }
+
+ if (smtp_mailaddr(&s->tx->evp.sender, copy, 1, &copy,
+ s->smtpname) == 0) {
+ smtp_reply(s, "553 %s Sender address syntax error",
+ esc_code(ESC_STATUS_PERMFAIL, ESC_OTHER_ADDRESS_STATUS));
+ smtp_tx_free(s->tx);
+ return;
+ }
+
smtp_tx_mail_from(s->tx, args);
}