aboutsummaryrefslogtreecommitdiffstats
path: root/Mailman/Utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'Mailman/Utils.py')
-rw-r--r--Mailman/Utils.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/Mailman/Utils.py b/Mailman/Utils.py
index 6038667b..d504ecce 100644
--- a/Mailman/Utils.py
+++ b/Mailman/Utils.py
@@ -111,7 +111,12 @@ def list_exists(listname):
# But first ensure the list name doesn't contain a path traversal
# attack.
if len(re.sub(mm_cfg.ACCEPTABLE_LISTNAME_CHARACTERS, '', listname)) > 0:
- syslog('mischief', 'Hostile listname: %s', listname)
+ remote = os.environ.get('HTTP_FORWARDED_FOR',
+ os.environ.get('HTTP_X_FORWARDED_FOR',
+ os.environ.get('REMOTE_ADDR',
+ 'unidentified origin')))
+ syslog('mischief',
+ 'Hostile listname: listname=%s: remote=%s', listname, remote)
return False
basepath = Site.get_listpath(listname)
for ext in ('.pck', '.pck.last', '.db', '.db.last'):
@@ -1530,3 +1535,25 @@ def banned_ip(ip):
if re.search(r'127\.0\.0\.[2-7]$', text, re.MULTILINE):
return True
return False
+
+def banned_domain(email):
+ if not dns_resolver:
+ return False
+
+ email = email.lower()
+ user, domain = ParseEmail(email)
+
+ lookup = '%s.zen.spamhaus.org' % (domain)
+
+ resolver = dns.resolver.Resolver()
+ try:
+ ans = resolver.query(lookup, dns.rdatatype.A)
+ except DNSException:
+ return False
+ if not ans:
+ return False
+ text = ans.rrset.to_text()
+ if re.search(r'127\.0\.1\.\d{1,3}$', text, re.MULTILINE):
+ if not re.search(r'127\.0\.1\.255$', text, re.MULTILINE):
+ return True
+ return False