qmail-smtpd: Read list of hosts allowed to relay from control/relayhosts
[qmail] / qmail-smtpd.c
index 50cfc0a..f19dd62 100644 (file)
@@ -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()