]> xenbits.xensource.com Git - people/aperard/emesinae.git/commitdiff
control.pl: Support blacklisting of addresses.
authorIan Campbell <ian.campbell@citrix.com>
Thu, 5 Sep 2013 09:12:14 +0000 (10:12 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Thu, 5 Sep 2013 09:12:14 +0000 (10:12 +0100)
Emesinae/Common.pm
TODO
config/emesinae.conf
config/examples/test/control.blacklist [new file with mode: 0644]
config/examples/test/emesinae.conf
config/examples/xen-bugs.xenproject.org/emesinae.conf
scripts/control.pl

index f5c58dd47b869a6d2d6709b137395163a36d2f97..b7cf161cb0d49897084d6ca36f134290c3173151 100644 (file)
@@ -43,6 +43,18 @@ sub readconfig () {
             chomp;
             push @{ $c{ControlAllow} }, $_;
         }
+        close(CA);
+    }
+
+    if ( $c{ControlBlacklistPath} ) {
+        open CB, "<" . $c{ControlBlacklistPath}
+          or die "unable to open " . $c{ControlBlacklistPath} . ": $!";
+        $c{ControBlacklist} = [];
+        while (<CB>) {
+            chomp;
+            push @{ $c{ControlBlacklist} }, $_;
+        }
+        close(CB);
     }
 }
 
diff --git a/TODO b/TODO
index a1ccc9978764936e78b3bc38306add9e9a1fcb87..0c2417b70f4778489a7f5225a9fadf9378cc96a2 100644 (file)
--- a/TODO
+++ b/TODO
@@ -7,8 +7,6 @@ control.pl:
     - bug-dist list is sufficient perhaps?
  - Enable Perl taint mode?
  - Strip common prefixes from title, e.g. [xen-devel], [PATCH] etc?
- - black-listing (e.g. from MAILER-DAEMON\@.* to avoid silly bounces or
-   specific addresses to avoid trolls).
 
 bugs:
  - components
index 06668e14a9fbae9ab5939bac150f8533918ed8e6..0aa1b3ffc5962d24b1f045dcfffeded7ab2ebd69 100644 (file)
@@ -69,6 +69,9 @@ $c{ControlAllowPath} = "/etc/emesinae/control.users";
 
 # Otherwise ControlAllow should be an array of email addresses
 #@{ $c{ControlAllow} } = qw/admin@example.com/;
+# ControlBlacklistPath should contain the path to a file with one email address
+# per line.
+$c{ControlBlacklistPath} = "/etc/emesinae/control.blacklist";
 
 # Severity levels, in decending order of criticality
 @{ $c{SeverityLevels} } = qw/blocker critical normal wishlist/;
diff --git a/config/examples/test/control.blacklist b/config/examples/test/control.blacklist
new file mode 100644 (file)
index 0000000..234eecc
--- /dev/null
@@ -0,0 +1,2 @@
+i.am.a.spammer@example.com
+
index e7e6977ea8136e4dd72f46c396f31f0055b76746..a7470c760280696d02c216f381236e941ee6b31c 100644 (file)
@@ -63,6 +63,9 @@ $c{ReportingURL} = "http://bugs.example.com/Howto_Report_Bugs.html";
 $c{ControlAllowPath} = "/srv/test/etc/control.users";
 # Otherwise ControlAllow should be an array of email addresses
 #@{ $c{ControlAllow} } = qw/admin@example.com/;
+# ControlBlacklistPath should contain the path to a file with one email address
+# per line.
+$c{ControlBlacklistPath} = "/srv/test/etc/control.blacklist";
 
 # Severity levels, in decending order of criticality
 @{ $c{SeverityLevels} } = qw/blocker critical normal wishlist/;
index 9c9d01136d93478e55f945ed0e103647f770fe8f..bf6fcf8762eec3e7bfedd019195e4d2e083fc4ca 100644 (file)
@@ -65,6 +65,9 @@ $c{ControlHelpURL} = "http://wiki.xen.org/wiki/Xen_Bug_Management_Interface";
 $c{ControlAllowPath} = "/srv/xen-devel-bugs/etc/control.users";
 # Otherwise ControlAllow should be an array of email addresses
 #@{ $c{ControlAllow} } = qw/admin@example.com/;
+# ControlBlacklistPath should contain the path to a file with one email address 
+# per line.
+$c{ControlBlacklistPath} = "/srv/xen-devel-bugs/etc/control.blacklist";
 
 # Severity levels, in decending order of criticality
 @{ $c{SeverityLevels} } = qw/blocker critical normal wishlist/;
index ef15f3176d33d18e1d5cc663aa4036e5076328ef..9c5e3ff99732e134f8be9bc484f34980fb4ebe6c 100755 (executable)
@@ -139,6 +139,24 @@ sub validate_one_header ($$) {
     $head->get($it) or push @{$err}, "Control message missing `$it' header";
 }
 
+sub check_from_blacklist($) {
+    my ($err) = @_;
+
+    return unless $head->get('from'); # validate_one_header already handled this.
+    return if not @{ $c{ControlBlacklist} };
+
+    my $addrhead = Mail::Field::AddrList->extract( 'from', $head );
+    my @addresses = map { lc } $addrhead->addresses;
+    my @blacklist = map { lc } @{ $c{ControlBlacklist} };
+
+    for my $addr (@addresses) {
+        if ( $addr ~~ @blacklist ) {
+            push @{$err}, "Blacklisted From address: $addr";
+            last;
+        }
+    }
+}
+
 sub validate_headers () {
     my @errors;
 
@@ -147,6 +165,7 @@ sub validate_headers () {
     # with such broken mail clients.
     validate_one_header( \@errors, 'From' );
     validate_one_header( \@errors, 'Message-ID' );
+    check_from_blacklist( \@errors );
     return @errors;
 }