summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd
diff options
context:
space:
mode:
authorGilles Chehade <gilles@cvs.openbsd.org>2018-11-29 12:48:17 +0000
committerGilles Chehade <gilles@cvs.openbsd.org>2018-11-29 12:48:17 +0000
commit6c2c099fba08d99d1866375aeb855033282f4c8e (patch)
tree8a32bb90d9d14fb0cd392300b8b53c2c2afa6a26 /usr.sbin/smtpd
parentc819ba76542b74590d10eb1c619f8abbcca766e7 (diff)
introduce FILTER_COMMIT which will allow taking a decision at DATA commit
time, unusable yet but necessary for the upcoming serie of diffs. ok eric@
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r--usr.sbin/smtpd/lka_filter.c3
-rw-r--r--usr.sbin/smtpd/parse.y15
-rw-r--r--usr.sbin/smtpd/smtp_session.c32
-rw-r--r--usr.sbin/smtpd/smtpd.h3
4 files changed, 47 insertions, 6 deletions
diff --git a/usr.sbin/smtpd/lka_filter.c b/usr.sbin/smtpd/lka_filter.c
index 000cb94d72c..a80788aa929 100644
--- a/usr.sbin/smtpd/lka_filter.c
+++ b/usr.sbin/smtpd/lka_filter.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lka_filter.c,v 1.4 2018/11/03 20:45:48 gilles Exp $ */
+/* $OpenBSD: lka_filter.c,v 1.5 2018/11/29 12:48:16 gilles Exp $ */
/*
* Copyright (c) 2018 Gilles Chehade <gilles@poolp.org>
@@ -65,6 +65,7 @@ static struct filter_exec {
{ FILTER_QUIT, "quit", filter_exec_notimpl },
{ FILTER_RCPT_TO, "rcpt-to", filter_exec_rcpt_to },
{ FILTER_RSET, "rset", filter_exec_notimpl },
+ { FILTER_COMMIT, "commit", filter_exec_notimpl },
};
void
diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y
index 23f106781cc..98772c8a464 100644
--- a/usr.sbin/smtpd/parse.y
+++ b/usr.sbin/smtpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.230 2018/11/08 13:24:22 gilles Exp $ */
+/* $OpenBSD: parse.y,v 1.231 2018/11/29 12:48:16 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -173,7 +173,7 @@ typedef struct {
%token ACTION ALIAS ANY ARROW AUTH AUTH_OPTIONAL
%token BACKUP BOUNCE
-%token CA CERT CHROOT CIPHERS COMPRESSION CONNECT
+%token CA CERT CHROOT CIPHERS COMMIT COMPRESSION CONNECT
%token CHECK_RDNS CHECK_REGEX CHECK_TABLE
%token DATA DHE DISCONNECT DOMAIN
%token EHLO ENABLE ENCRYPTION ERROR EXPAND_ONLY
@@ -1266,6 +1266,15 @@ NOOP {
} filter_action_proc
;
+filter_phase_commit:
+COMMIT {
+ filter_rule->phase = FILTER_COMMIT;
+} filter_action_builtin
+| COMMIT {
+ filter_rule->phase = FILTER_COMMIT;
+} filter_action_proc
+;
+
filter_phase:
filter_phase_connect
@@ -1277,6 +1286,7 @@ filter_phase_connect
| filter_phase_quit
| filter_phase_noop
| filter_phase_rset
+| filter_phase_commit
;
filter:
@@ -1844,6 +1854,7 @@ lookup(char *s)
{ "check-table", CHECK_TABLE },
{ "chroot", CHROOT },
{ "ciphers", CIPHERS },
+ { "commit", COMMIT },
{ "compression", COMPRESSION },
{ "connect", CONNECT },
{ "data", DATA },
diff --git a/usr.sbin/smtpd/smtp_session.c b/usr.sbin/smtpd/smtp_session.c
index 5102a5fb7e8..de7836b7a8b 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.354 2018/11/29 08:30:27 eric Exp $ */
+/* $OpenBSD: smtp_session.c,v 1.355 2018/11/29 12:48:16 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -97,6 +97,7 @@ enum smtp_command {
CMD_HELP,
CMD_WIZ,
CMD_NOOP,
+ CMD_COMMIT,
};
struct smtp_rcpt {
@@ -219,6 +220,9 @@ static void smtp_proceed_noop(struct smtp_session *, const char *);
static void smtp_proceed_help(struct smtp_session *, const char *);
static void smtp_proceed_wiz(struct smtp_session *, const char *);
static void smtp_proceed_quit(struct smtp_session *, const char *);
+static void smtp_proceed_commit(struct smtp_session *, const char *);
+static void smtp_proceed_rollback(struct smtp_session *, const char *);
+
static struct {
int code;
@@ -240,6 +244,7 @@ static struct {
{ CMD_NOOP, FILTER_NOOP, "NOOP", smtp_check_noparam, smtp_proceed_noop },
{ CMD_HELP, FILTER_HELP, "HELP", smtp_check_noparam, smtp_proceed_help },
{ CMD_WIZ, FILTER_WIZ, "WIZ", smtp_check_noparam, smtp_proceed_wiz },
+ { CMD_COMMIT, FILTER_COMMIT, ".", smtp_check_noparam, smtp_proceed_commit },
{ -1, 0, NULL, NULL },
};
@@ -909,6 +914,8 @@ smtp_session_imsg(struct mproc *p, struct imsg *imsg)
if (filter_response == FILTER_DISCONNECT)
smtp_enter_state(s, STATE_QUIT);
+ else if (s->filter_phase == FILTER_COMMIT)
+ smtp_proceed_rollback(s, NULL);
break;
case FILTER_PROCEED:
@@ -1038,7 +1045,7 @@ smtp_io(struct io *io, int evt, void *arg)
}
if (eom) {
- smtp_message_end(s->tx);
+ smtp_filter_phase(FILTER_COMMIT, s, NULL);
io_set_write(io);
return;
}
@@ -1650,6 +1657,27 @@ smtp_proceed_wiz(struct smtp_session *s, const char *args)
}
static void
+smtp_proceed_commit(struct smtp_session *s, const char *args)
+{
+ smtp_message_end(s->tx);
+}
+
+static void
+smtp_proceed_rollback(struct smtp_session *s, const char *args)
+{
+ struct smtp_tx *tx;
+
+ tx = s->tx;
+
+ fclose(tx->ofile);
+ tx->ofile = NULL;
+
+ smtp_tx_rollback(tx);
+ smtp_tx_free(tx);
+ smtp_enter_state(s, STATE_HELO);
+}
+
+static void
smtp_rfc4954_auth_plain(struct smtp_session *s, char *arg)
{
char buf[1024], *user, *pass;
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index 7f58a998ab8..fcb29730a81 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.573 2018/11/08 13:21:00 gilles Exp $ */
+/* $OpenBSD: smtpd.h,v 1.574 2018/11/29 12:48:16 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -408,6 +408,7 @@ enum filter_phase {
FILTER_NOOP,
FILTER_HELP,
FILTER_WIZ,
+ FILTER_COMMIT,
FILTER_PHASES_COUNT /* must be last */
};