--- qmail-smtpd.c-bak Sun Jun 8 15:53:59 1997 +++ qmail-smtpd.c Fri Jul 11 16:00:18 1997 @@ -79,6 +79,9 @@ struct constmap mapbadrcptto; stralloc helohost = {0}; stralloc mailfrom = {0}; stralloc rcptto = {0}; +stralloc relayclients = {0}; +stralloc relaydomains = {0}; +struct constmap maprelayclients, maprelaydomains; int seenmail = 0; stralloc addr = {0}; /* will be 0-terminated, if addrparse returns 1 */ @@ -100,6 +103,9 @@ void dohelo(arg) char *arg; void getenvs() { + unsigned short int error = 0; + unsigned int i, len; + remoteip = env_get("TCPREMOTEIP"); if (!remoteip) remoteip = "unknown"; local = env_get("TCPLOCALHOST"); @@ -109,6 +115,67 @@ void getenvs() if (!remotehost) remotehost = "unknown"; remoteinfo = env_get("TCPREMOTEINFO"); relayclient = env_get("RELAYCLIENT"); + if (! relayclient) + { + /* Attempt to lookup the IP number in control/relayclients. */ + switch (control_readfile (&relayclients, "control/relayclients", 0)) + { + case -1: + if (errno == error_nomem) + outofmem (); + /* Fall through. */ + + case 0: + error = 1; + break; + + case 1: + if (!constmap_init (&maprelayclients, relayclients.s, relayclients.len, 1)) + outofmem (); + break; + } + + if (! error) + { + for (i = len = str_len (remoteip); i > 0; i --) + if ((i == len) || (remoteip[i - 1] == '.')) + if ((relayclient = constmap (&maprelayclients, remoteip, i))) + break; + constmap_free (&maprelayclients); + } + } + + error = 0; + if (! relayclient) + { + /* Attempt to lookup the host name in control/relaydomains. */ + switch (control_readfile (&relaydomains, "control/relaydomains", 0)) + { + case -1: + if (errno == error_nomem) + outofmem (); + /* Fall through. */ + + case 0: + error = 1; + break; + + case 1: + if (!constmap_init (&maprelaydomains, relaydomains.s, relaydomains.len, 1)) + outofmem (); + break; + } + + if (! error) + { + for (i = 0, len = str_len (remotehost); i <= len; i ++) + if ((i == 0) || (i == len) || (remotehost[i] == '.')) + if ((relayclient = constmap (&maprelaydomains, remotehost + i, len - i))) + break; + constmap_free (&maprelaydomains); + } + } + dohelo(remotehost); #ifdef DENYSPAM denymail = env_get("DENYMAIL");