diff options
author | gilles <gilles@openbsd.org> | 2019-12-18 07:57:51 +0000 |
---|---|---|
committer | gilles <gilles@openbsd.org> | 2019-12-18 07:57:51 +0000 |
commit | bd1553c95cf692e1e9d5964ea747956d27ff18db (patch) | |
tree | f39df3a4ff221059fb9b866e249c4b35768afc61 | |
parent | avoid line wrap in the dkimsign filter line; (diff) | |
download | OpenSMTPD-bd1553c95cf692e1e9d5964ea747956d27ff18db.tar.xz OpenSMTPD-bd1553c95cf692e1e9d5964ea747956d27ff18db.zip |
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-- | lka.c | 9 | ||||
-rw-r--r-- | mta.c | 6 | ||||
-rw-r--r-- | parse.y | 23 | ||||
-rw-r--r-- | smtpd.conf.5 | 8 | ||||
-rw-r--r-- | smtpd.h | 4 |
5 files changed, 43 insertions, 7 deletions
@@ -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) @@ -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); @@ -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/smtpd.conf.5 b/smtpd.conf.5 index cc79cc8e..37652b36 100644 --- a/smtpd.conf.5 +++ b/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 . @@ -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; |