On Tue, Apr 04, 2000 at 12:24:55PM +0100, Will Harris wrote:
> >However it doesn't explain how to do do what I want. I want to check
> >all incoming messages to see if they're on DUL, ORBS, RSS, RBL or
> >whatever and if so add a header to the message, say an
> >"X-Spam-Warning: DUL" or the like. I know this is a trivial one line
> >config option for Exim, but I haven't seen anything for qmail to do
> >this.
> I've written a system-wide mail filtering program I implemented that
> checks RBL, RSS, ORBS, and DUL.
<snip details>
> It also uses a small 4 line patch to qmail's received.c file to insert
> an X-Remote-IP header.
Ok, I've taken a look at what you've done and the flame antispam patch
and come up with the attached, which I think should do what I want.
Except it doesn't. Closer examination reveals it's failing on the test
to make sure we ip_scaned the entire string, but I can't see why.
Anyone any hints for debugging qmail patches?
J.
--
Is it real, or is it Mimozine?
diff -ruN qmail-1.02/Makefile qmail-1.02-new/Makefile
--- qmail-1.02/Makefile Fri May 1 05:23:28 1998
+++ qmail-1.02-new/Makefile Sat Apr 8 17:45:31 2000
@@ -1310,10 +1310,12 @@
qmail-qmqpd: \
load qmail-qmqpd.o received.o now.o date822fmt.o qmail.o auto_qmail.o \
-env.a substdio.a sig.a error.a wait.a fd.a str.a datetime.a fs.a
+env.a substdio.a sig.a error.a wait.a fd.a str.a datetime.a fs.a \
+stralloc.a alloc.a dns.o ip.o
./load qmail-qmqpd received.o now.o date822fmt.o qmail.o \
- auto_qmail.o env.a substdio.a sig.a error.a wait.a fd.a \
- str.a datetime.a fs.a
+ auto_qmail.o dns.o ip.o ipalloc.o env.a substdio.a sig.a \
+ error.a wait.a fd.a \
+ str.a datetime.a fs.a stralloc.a alloc.a `cat dns.lib`
qmail-qmqpd.0: \
qmail-qmqpd.8
@@ -1330,9 +1332,9 @@
getln.a sig.a case.a env.a stralloc.a alloc.a substdio.a error.a \
str.a fs.a auto_qmail.o
./load qmail-qmtpd rcpthosts.o control.o constmap.o \
- received.o date822fmt.o now.o qmail.o cdb.a fd.a wait.a \
+ received.o date822fmt.o now.o qmail.o ipalloc.o cdb.a fd.a wait.a \
datetime.a open.a getln.a sig.a case.a env.a stralloc.a \
- alloc.a substdio.a error.a str.a fs.a auto_qmail.o
+ alloc.a substdio.a error.a str.a fs.a auto_qmail.o dns.o ip.o `cat dns.lib`
qmail-qmtpd.0: \
qmail-qmtpd.8
@@ -1496,7 +1498,7 @@
timeoutwrite.o ip.o ipme.o ipalloc.o control.o constmap.o \
received.o date822fmt.o now.o qmail.o cdb.a fd.a wait.a \
datetime.a getln.a open.a sig.a case.a env.a stralloc.a \
- alloc.a substdio.a error.a str.a fs.a auto_qmail.o `cat \
+ alloc.a substdio.a error.a str.a fs.a auto_qmail.o dns.o `cat dns.lib` `cat \
socket.lib`
qmail-smtpd.0: \
diff -ruN qmail-1.02/dns.c qmail-1.02-new/dns.c
--- qmail-1.02/dns.c Fri May 1 05:23:28 1998
+++ qmail-1.02-new/dns.c Sat Apr 8 13:52:38 2000
@@ -219,9 +219,10 @@
#define FMT_IAA 40
-static int iaafmt(s,ip)
+static int iaafmt(s,ip,dom)
char *s;
struct ip_address *ip;
+const char *dom;
{
unsigned int i;
unsigned int len;
@@ -233,7 +234,7 @@
i = fmt_ulong(s,(unsigned long) ip->d[1]); len += i; if (s) s += i;
i = fmt_str(s,"."); len += i; if (s) s += i;
i = fmt_ulong(s,(unsigned long) ip->d[0]); len += i; if (s) s += i;
- i = fmt_str(s,".in-addr.arpa."); len += i; if (s) s += i;
+ i = fmt_str(s,dom); len += i; if (s) s += i;
return len;
}
@@ -243,8 +244,8 @@
{
int r;
- if (!stralloc_ready(sa,iaafmt((char *) 0,ip))) return DNS_MEM;
- sa->len = iaafmt(sa->s,ip);
+ if (!stralloc_ready(sa,iaafmt((char *) 0,ip,".in-addr.arpa."))) return DNS_MEM;
+ sa->len = iaafmt(sa->s,ip,".in-addr.arpa.");
switch(resolve(sa,T_PTR))
{
case DNS_MEM: return DNS_MEM;
@@ -260,6 +261,34 @@
return 0;
}
}
+ return DNS_HARD;
+}
+
+int dns_maps(ip,suffix)
+struct ip_address *ip;
+char *suffix;
+{
+ int r;
+ stralloc *sa;
+
+ /*
+ * Ok, look for a CNAME or A record.
+ */
+ if (!stralloc_ready(sa, iaafmt(NULL, ip, suffix)))
+ return DNS_MEM;
+ sa->len = iaafmt(sa->s, ip, suffix);
+ switch(resolve(sa, T_A)) {
+ case DNS_MEM: return DNS_MEM;
+ case DNS_SOFT: return DNS_SOFT;
+ case DNS_HARD: return DNS_HARD;
+ }
+ while ((r = findip(T_A)) !=2) {
+ if (r == DNS_SOFT)
+ return DNS_SOFT;
+ if (r == 1)
+ return 0;
+ }
+
return DNS_HARD;
}
diff -ruN qmail-1.02/received.c qmail-1.02-new/received.c
--- qmail-1.02/received.c Fri May 1 05:23:28 1998
+++ qmail-1.02-new/received.c Sat Apr 8 13:55:29 2000
@@ -3,6 +3,8 @@
#include "now.h"
#include "datetime.h"
#include "date822fmt.h"
+#include "dns.h"
+#include "ip.h"
#include "received.h"
static int issafe(ch) char ch;
@@ -47,6 +49,20 @@
char *helo;
{
struct datetime dt;
+ struct ip_address ip;
+
+ if (!remotehost[ip_scan(remotehost, &ip)]) {
+ switch(dns_maps(&ip,".rbl.maps.vix.com.")) {
+ case 0:
+ qmail_puts(qqt,"X-Spam-Warning: ");
+ safeput(qqt, remotehost);
+ qmail_puts(qqt, " is on the RBL\n");
+/*
+ safeput(qqt, map);
+ qmail_puts(qqt, "\n");
+*/
+ }
+ }
qmail_puts(qqt,"Received: from ");
safeput(qqt,remotehost);