diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2019-12-18 07:57:53 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2019-12-18 07:57:53 +0000 |
commit | 2e88cb97f29e38e0d01970277d524d40b650fa50 (patch) | |
tree | 13f4df34c93a885a9703dc1104d34a71d4158ccc | |
parent | 2ea7ae344c4d38ebb821b5aad4f1e3b185ff9108 (diff) |
teach relay action how to do domain-based relay host, this allows declaring
a single relay action with a mapping of relay hosts per domain.
ok eric@
-rw-r--r-- | usr.sbin/smtpd/lka.c | 9 | ||||
-rw-r--r-- | usr.sbin/smtpd/mta.c | 6 | ||||
-rw-r--r-- | usr.sbin/smtpd/parse.y | 23 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.conf.5 | 8 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 4 |
5 files changed, 43 insertions, 7 deletions
diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c index 0b3a9b69774..4a4ee7c7a74 100644 --- a/usr.sbin/smtpd/lka.c +++ b/usr.sbin/smtpd/lka.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka.c,v 1.241 2019/12/12 22:10:47 gilles Exp $ */ +/* $OpenBSD: lka.c,v 1.242 2019/12/18 07:57:51 gilles Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -275,6 +275,7 @@ lka_imsg(struct mproc *p, struct imsg *imsg) case IMSG_MTA_LOOKUP_SMARTHOST: m_msg(&m, imsg); m_get_id(&m, &reqid); + m_get_string(&m, &domain); m_get_string(&m, &tablename); m_end(&m); @@ -288,7 +289,11 @@ lka_imsg(struct mproc *p, struct imsg *imsg) m_add_int(p, LKA_TEMPFAIL); } else { - ret = table_fetch(table, K_RELAYHOST, &lk); + if (domain == NULL) + ret = table_fetch(table, K_RELAYHOST, &lk); + else + ret = table_lookup(table, K_RELAYHOST, domain, &lk); + if (ret == -1) m_add_int(p, LKA_TEMPFAIL); else if (ret == 0) diff --git a/usr.sbin/smtpd/mta.c b/usr.sbin/smtpd/mta.c index 6c817d00919..6fbff8e925d 100644 --- a/usr.sbin/smtpd/mta.c +++ b/usr.sbin/smtpd/mta.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mta.c,v 1.232 2019/09/20 17:46:05 gilles Exp $ */ +/* $OpenBSD: mta.c,v 1.233 2019/12/18 07:57:51 gilles Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -926,6 +926,10 @@ mta_query_smarthost(struct envelope *evp0) m_create(p_lka, IMSG_MTA_LOOKUP_SMARTHOST, 0, 0, -1); m_add_id(p_lka, evp->id); + if (dispatcher->u.remote.smarthost_domain) + m_add_string(p_lka, evp->dest.domain); + else + m_add_string(p_lka, NULL); m_add_string(p_lka, dispatcher->u.remote.smarthost); m_close(p_lka); diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y index 6b1b6b1de27..5b1546e2155 100644 --- a/usr.sbin/smtpd/parse.y +++ b/usr.sbin/smtpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.269 2019/12/14 16:24:52 gilles Exp $ */ +/* $OpenBSD: parse.y,v 1.270 2019/12/18 07:57:52 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -818,6 +818,27 @@ HELO STRING { dispatcher->u.remote.smarthost = strdup(t->t_name); } +| DOMAIN tables { + struct table *t = $2; + + if (dispatcher->u.remote.smarthost) { + yyerror("host mapping already specified for this dispatcher"); + YYERROR; + } + if (dispatcher->u.remote.backup) { + yyerror("backup and domain are mutually exclusive"); + YYERROR; + } + + if (!table_check_use(t, T_DYNAMIC|T_HASH, K_RELAYHOST)) { + yyerror("table \"%s\" may not be used for host lookups", + t->t_name); + YYERROR; + } + + dispatcher->u.remote.smarthost = strdup(t->t_name); + dispatcher->u.remote.smarthost_domain = 1; +} | TLS { if (dispatcher->u.remote.tls_required == 1) { yyerror("tls already specified for this dispatcher"); diff --git a/usr.sbin/smtpd/smtpd.conf.5 b/usr.sbin/smtpd/smtpd.conf.5 index cc79cc8ec03..37652b3648e 100644 --- a/usr.sbin/smtpd/smtpd.conf.5 +++ b/usr.sbin/smtpd/smtpd.conf.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: smtpd.conf.5,v 1.244 2019/12/17 10:30:20 jmc Exp $ +.\" $OpenBSD: smtpd.conf.5,v 1.245 2019/12/18 07:57:52 gilles 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: December 17 2019 $ +.Dd $Mdocdate: December 18 2019 $ .Dt SMTPD.CONF 5 .Os .Sh NAME @@ -228,6 +228,10 @@ Use the mapping .Ar table to look up a hostname matching the source address, to advertise during the HELO phase. +.It Cm domain Pf < Ar domains Ns > +Do not perform MX lookups but lookup destination domain in +.Ar domains +and use matching relay url as relay host. .It Cm host Ar relay-url Do not perform MX lookups but relay messages to the relay host described by .Ar relay-url . diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index c41efbac737..061b11f11c0 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.645 2019/12/14 16:24:52 gilles Exp $ */ +/* $OpenBSD: smtpd.h,v 1.646 2019/12/18 07:57:52 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -1169,6 +1169,8 @@ struct dispatcher_remote { char *mail_from; char *smarthost; + int smarthost_domain; + char *auth; int tls_required; int tls_noverify; |