From: Mark Wooding Date: Tue, 14 Feb 2006 02:46:08 +0000 (+0000) Subject: qmail-smtpd: Read list of hosts allowed to relay from control/relayhosts X-Git-Tag: mdw/1.03-2~1^2 X-Git-Url: https://git.distorted.org.uk/~mdw/qmail/commitdiff_plain/10649f16bd53e42811fef2ffa9daf6914104c42b qmail-smtpd: Read list of hosts allowed to relay from control/relayhosts --- diff --git a/qmail-control.9 b/qmail-control.9 index 7474a33..7867100 100644 --- a/qmail-control.9 +++ b/qmail-control.9 @@ -57,6 +57,7 @@ control default used by .I plusdomain \fIme \fRqmail-inject .I queuelifetime \fR604800 \fRqmail-send .I rcpthosts \fR(none) \fRqmail-smtpd +.I relayhosts \fR(none) \fRqmail-smtpd .I recipientmap \fR(none) \fRqmail-send .I smtpgreeting \fIme \fRqmail-smtpd .I smtproutes \fR(none) \fRqmail-remote diff --git a/qmail-showctl.c b/qmail-showctl.c index 5134ebc..e06521e 100644 --- a/qmail-showctl.c +++ b/qmail-showctl.c @@ -185,6 +185,7 @@ void main() do_int("queuelifetime","604800","Message lifetime in the queue is "," seconds"); do_lst("rcpthosts","SMTP clients may send messages to any recipient.","SMTP clients may send messages to recipients at ","."); do_lst("recipientmap","No redirections.","Redirection: ",""); + do_lst("relayhosts","No relayhosts","Relay host: ",""); do_str("smtpgreeting",1,"smtpgreeting","SMTP greeting: 220 "); do_lst("smtproutes","No artificial SMTP routes.","SMTP route: ",""); do_int("timeoutconnect","60","SMTP client connection timeout is "," seconds"); @@ -217,6 +218,7 @@ void main() if (str_equal(d->d_name,"queuelifetime")) continue; if (str_equal(d->d_name,"rcpthosts")) continue; if (str_equal(d->d_name,"recipientmap")) continue; + if (str_equal(d->d_name,"relayhosts")) continue; if (str_equal(d->d_name,"smtpgreeting")) continue; if (str_equal(d->d_name,"smtproutes")) continue; if (str_equal(d->d_name,"timeoutconnect")) continue; diff --git a/qmail-smtpd.8 b/qmail-smtpd.8 index f1cb4a2..8430e6d 100644 --- a/qmail-smtpd.8 +++ b/qmail-smtpd.8 @@ -75,18 +75,11 @@ is supplied, .B qmail-smtpd will reject any envelope recipient address with a domain not listed in -.IR rcpthosts . - -Exception: -If the environment variable -.B RELAYCLIENT -is set, -.B qmail-smtpd -will ignore -.IR rcpthosts , -and will append the value of -.B RELAYCLIENT -to each incoming recipient address. +.I rcpthosts +unless the sending host is a designated relay client (see the +description of the +.I relayhosts +file beow). .I rcpthosts may include wildcards: @@ -99,6 +92,32 @@ may include wildcards: Envelope recipient addresses without @ signs are always allowed through. .TP 5 +.I relayhosts +Allowed relay clients. Each line is a host-suffix pair, separated by a +colon. If the client's hostname matches one of the hostnames in the +file, that client is permitted to send mail to any host (i.e., to use us +as a relay), and the corresponding suffix is appended to all recipient +addresses generated by the client. + +.I relayhosts +may include wildcards: + +.EX + heaven.af.mil: + .heaven.af.mil: + hell.irs.gov:.irs.virtdomain +.EE + +For historical reasons, the +.B RELAYCLIENT +environment variable overrides this table. If +.B RELAYCLIENT +is set, it has the same effect as there being a matching entry in the +.I relayhosts +file, using the value of +.B RELAYCLIENT +as the suffix. +.TP 5 .I smtpgreeting SMTP greeting message. Default: diff --git a/qmail-smtpd.c b/qmail-smtpd.c index 50cfc0a..f19dd62 100644 --- a/qmail-smtpd.c +++ b/qmail-smtpd.c @@ -56,6 +56,9 @@ stralloc rcpthosts = {0}; struct constmap maprcpthosts; int bmfok = 0; stralloc bmf = {0}; +int relayhostsok = 0; +stralloc relayhosts = {0}; +struct constmap maprelayhosts; struct constmap mapbmf; int flagbarf; /* defined if seenmail */ @@ -89,6 +92,18 @@ void getenvs() if (!remotehost) remotehost = "unknown"; remoteinfo = env_get("TCPREMOTEINFO"); relayclient = env_get("RELAYCLIENT"); + if (!relayclient && relayhostsok) { + int j; + int l = str_len(remotehost); + relayclient = constmap(&maprelayhosts, remotehost, l); + if (!relayclient) for (j = 0; j < l; ++j) { + if (remotehost[j] == '.' && + (relayclient = constmap(&maprelayhosts, + remotehost + j, + l - j)) != 0) + break; + } + } dohelo(remotehost); } @@ -416,6 +431,14 @@ void getcontrols() bmfok = 1; if (!constmap_init(&mapbmf,bmf.s,bmf.len,0)) die(); } + switch (control_readfile(&relayhosts, "control/relayhosts", 0)) { + case -1: + die(); + case 1: + relayhostsok = 1; + if (!constmap_init(&maprelayhosts, relayhosts.s, relayhosts.len, 1)) + die(); + } } void main()