Merge branch 'mdw/relayhosts'
[qmail] / qmail-smtpd.c
index 1e28c88..6f453ce 100644 (file)
@@ -93,6 +93,9 @@ void dohelo(arg) char *arg; {
 
 int liphostok = 0;
 stralloc liphost = {0};
+int relayhostsok = 0;
+stralloc relayhosts = {0};
+struct constmap maprelayhosts;
 int bmfok = 0;
 stralloc bmf = {0};
 struct constmap mapbmf;
@@ -116,6 +119,16 @@ void setup()
   if (bmfok == -1) die_control();
   if (bmfok)
     if (!constmap_init(&mapbmf,bmf.s,bmf.len,0)) die_nomem();
+
+  switch (control_readfile(&relayhosts, "control/relayhosts", 0)) {
+    case -1:
+      die_control();
+    case 1:
+      relayhostsok = 1;
+      if (!constmap_init(&maprelayhosts, relayhosts.s, relayhosts.len, 1))
+       die_nomem();
+  }
+
  
   if (control_readint(&databytes,"control/databytes") == -1) die_control();
   x = env_get("DATABYTES");
@@ -131,6 +144,18 @@ void setup()
   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);
 }