All pastes #154889 Raw Edit

Miscellany

public text v1 · immutable
#154889 ·published 2006-08-30 17:58 UTC
rendered paste body
--- qmail-smtpd.c  2005-07-14 15:53:19.000000000 -0400
+++ qmail-smtpd.c       2006-07-14 11:23:21.000000000 -0400
@@ -52,6 +53,7 @@
 
 void err_bmf() { out("553 sorry, your envelope sender is in my badmailfrom list (#5.7.1)\r\n"); }
 void err_nogateway() { out("553 sorry, that domain isn't in my list of allowed rcpthosts (#5.7.1)\r\n"); }
+void err_norelay() { out("553 sorry we do not relay\r\n"); }
 void err_unimpl() { out("502 unimplemented (#5.5.1)\r\n"); }
 void err_syntax() { out("555 syntax error (#5.5.4)\r\n"); }
 void err_wantmail() { out("503 MAIL first (#5.5.1)\r\n"); }
@@ -81,6 +86,7 @@
 char *remoteinfo;
 char *local;
 char *relayclient;
+int blockrelayprobe = 0;
 
 stralloc helohost = {0};
 char *fakehelo; /* pointer into helohost, or 0 */
@@ -131,6 +145,7 @@
   if (!remotehost) remotehost = "unknown";
   remoteinfo = env_get("TCPREMOTEINFO");
   relayclient = env_get("RELAYCLIENT");
+  if (env_get("BLOCKRELAYPROBE")) blockrelayprobe = 1;
   dohelo(remotehost);
 }
 
@@ -216,7 +296,16 @@
   return r;
 }
 
-
+int relayprobe(void) /* relay probes trying stupid old sendwhale bugs */
+{
+ unsigned int j;
+  for (j = byte_rchr(addr.s, addr.len, '@'); j-- > 0; ) {
+    if (addr.s[j] == '@') return 1; /* double @ */
+    if (addr.s[j] == '%') return 1; /* percent relaying */
+    if (addr.s[j] == '!') return 1; /* UUCP bang path */
+  }
+  return 0;
+}
 int seenmail = 0;
 int flagbarf; /* defined if seenmail */
 stralloc mailfrom = {0};
@@ -251,6 +340,14 @@
   if (!seenmail) { err_wantmail(); return; }
   if (!addrparse(arg)) { err_syntax(); return; }
   if (flagbarf) { err_bmf(); return; }
+  /* block stupid and bogus sendwhale bug relay probing */
+  if (blockrelayprobe) /* don't enable this if you use percenthack */
+  {
+    if (relayprobe())
+    {
+       err_norelay(); return;
+    }
+  }
   if (relayclient) {
     --addr.len;
     if (!stralloc_cats(&addr,relayclient)) die_nomem();