In order to make courier-pythonfilter's greylist.py filter work with the
greylisting whitelist that's currently maintained at
http://greylisting.org/whitelisting.shtml, I have made a small patch to
this filter that checks ip/8, ip/16, and ip/24 addresses in the
_whitelistIPAddresses database, in addition to ip/32 addresses.

That patch is against version 0.18 of courier-pythonfilter, and I'm
enclosing it here.

Note that a text version of this greylisting whitelist can be downloaded
from here:

  
http://cvs.puremagic.com/viewcvs/*checkout*/greylisting/schema/whitelist_ip.txt

I have a cron job which periodically performs this download, extracts
the IP addresses from the file, and then loads them into the
_whitelistIPAddresses database.

Here's the patch to greylist.py:

--- greylist.py.orig    2007-02-05 07:31:11.000000000 -0500
+++ greylist.py 2007-02-05 07:33:12.000000000 -0500
@@ -66,5 +66,5 @@
     sys.exit(1)

-_IPv4Regex = re.compile('^(\d+\.\d+\.\d+)\.\d+$')
+_IPv4Regex = re.compile('^(\d+)(\.\d+)(\.\d+)\.\d+$')


@@ -75,5 +75,7 @@
 def _Debug(msg):
     if _doDebug:
-        sys.stderr.write(msg + '\n')
+        sys.stderr.write(msg)
+        if msg[-1] != '\n':
+            sys.stderr.write('\n')


@@ -99,13 +101,28 @@
         return ''

-    # Calculate the /24 network
+    # Calculate the /8, /16, and /24 networks
     IPv4Match = _IPv4Regex.match(sendersIP)
+    sendersIP8  = IPv4Match.group(1)
+    sendersIP16 = sendersIP8  + IPv4Match.group(2)
+    sendersIP24 = sendersIP16 + IPv4Match.group(3)
+    if _whitelistIPAddresses.has_key(sendersIP24):
+        _Debug('allowing message from whitelisted IP/24 address %s' %
+               sendersIP24)
+        return ''
+    elif _whitelistIPAddresses.has_key(sendersIP16):
+        _Debug('allowing message from whitelisted IP/16 address %s' %
+               sendersIP16)
+        return ''
+    elif _whitelistIPAddresses.has_key(sendersIP8):
+        _Debug('allowing message from whitelisted IP/8 address %s' %
+               sendersIP8)
+        return ''
     if(IPv4Match == None):
         # IPv6 network calculation isn't handled yet
         sendersIPNetwork = sendersIP
     else:
-       sendersIPNetwork = IPv4Match.group(1)
+        sendersIPNetwork = sendersIP24

-   # Grab the sender from the control files.
+    # Grab the sender from the control files.
     try:
         sender = courier.control.getSender(controlFileList)


-- 
 Lloyd Zusman
 [EMAIL PROTECTED]
 God bless you.


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
courier-users mailing list
[email protected]
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users

Reply via email to