[2035] in Moira

home help back first fref pref prev next nref lref last post

access service for outgoing mailers

daemon@ATHENA.MIT.EDU (Mark Silis)
Mon Oct 20 14:29:29 2003

Message-Id: <200310201829.h9KITQx5026955@I-fear-reorgs.mit.edu>
To: moiradev@MIT.EDU
cc: mark@MIT.EDU
Date: Mon, 20 Oct 2003 14:29:26 -0400
From: Mark Silis <mark@MIT.EDU>


As a result of AOL blacklisting us, we need to very quickly begin to tighten 
the controls of how we accept e-mail for sending into the MIT mail system. 
We've opted to require all users sending mail through the outgoing mailers
to use a valid sender (ie either a user e-mail address or list e-mail address)
instead of simply ending in @*MIT.EDU. This will hopefully prevent the case
of dwx12345@MIT.EDU being used to relay mail through the outgoing mailers
and upsetting other ISPs such as AOL. I have submitted below changes for an
access service to generate the sendmail access file which will be used to
further restrict relaying. We'd like to get these changes into production
as quickly as possible.

Cheers,

-- Mark

--- /dev/null	Mon Oct 20 13:37:22 2003
+++ access.gen	Mon Oct 20 14:22:18 2003
@@ -0,0 +1,50 @@
+#!/moira/bin/perl -Tw
+
+# $Id$
+
+use DBI;
+
+# The following exit codes are defined and MUST BE CONSISTENT withh the
+# error codes the library uses:
+$MR_DBMS_ERR = 47836421;
+$MR_OCONFIG = 47836460;
+%users = ();
+
+$outfile = '/moira/dcm/access.out';
+
+$dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
+    || exit $MR_DBMS_ERR;
+
+# Get the list of valid MIT.EDU user e-mail addresses
+$sth = $dbh->prepare("SELECT login FROM users WHERE status != 3");
+
+$sth->execute;
+
+umask 022;
+open(OUT, ">$outfile") || exit $MR_OCONFIG;
+
+while(($login) = $sth->fetchrow_array) {
+    $login =~ s/\0//g;
+    $users{$login} = $login;
+    
+    print OUT "From:$login\@MIT.EDU RELAY\n";
+}
+
+# Get all the valid MIT.EDU mailing list addresses
+$sth = $dbh->prepare("SELECT name FROM list WHERE active !=0 " .
+		     "AND maillist = 1");
+
+$sth->execute;
+
+while(($name) = $sth->fetchrow_array) {
+    $name =~ s/\0//g;
+    
+    # Ensure we do not re-print an entry that may be a personal user group
+    # and was already handled by the user e-mail addresses
+    if(!$users{$name}) { 
+	print OUT "From:$name\@MIT.EDU RELAY\n";
+    }
+}
+
+close(OUT);
+exit;

--- /dev/null	Mon Oct 20 13:37:22 2003
+++ access.sh	Mon Oct 20 14:20:44 2003
@@ -0,0 +1,72 @@
+#!/bin/sh
+#
+# $Header$
+
+PATH=/sbin:/bin:/usr/sbin:/usr/bin:/etc:/usr/etc:/usr/athena/bin:/usr/local/bin
+export PATH
+
+if [ -d /var/athena ] && [ -w /var/athena ]; then
+    exec >/var/athena/moira_update.log 2>&1
+else
+    exec >/tmp/moira_update.log 2>&1
+fi
+
+# The following exit codes are defined and MUST BE CONSISTENT with
+# error codes the library uses:
+MR_MKCRED=47836474
+MR_MISSINGFILE=47836473
+MR_NOCRED=47836470
+
+root=/usr/local/sendmail
+
+if [ -r $root/etc/access.new ]; then
+    cp /dev/null $root/etc/access.tmp
+    
+    if [ -f $root/etc/efl-access ]; then
+	cat $root/etc/efl-access >> $root/etc/access.tmp
+    fi
+
+    cat $root/etc/access.new >> $root/etc/access.tmp
+    mv $root/etc/access.tmp $root/etc/access.new
+    chmod 644 $root/etc/access.new
+else
+    exit $MR_MISSINGFILE
+fi
+
+if [ ! -r $root/etc/access ]; then
+    logger -p mail.error -t access.sh "No current access file, aborting."
+    exit $MR_NOCRED
+fi
+
+# Play it safe and be sure we have reasonable data
+olines=`wc -l $root/etc/access |  awk '{print $1}'`
+nlines=`wc -l $root/etc/access.new | awk '{print $1}'`
+diff=`expr $nlines - $olines`
+thresh=`expr $olines / 10`
+
+# Catch the zero case
+if [ $nlines -eq 0 ]; then
+    logger -p mail.error -t access.sh "Recieved empty access file, aborting."
+    exit $MR_MISSINGFILE
+fi
+
+# If its a greater than 10% shift bomb out to be safe
+if [ $diff -gt $thresh ]; then
+    logger -p mail.error -t access.sh "Access changes threshold exceeded, aborting."
+    exit $MR_NOCRED
+fi
+
+cp /dev/null $root/etc/access.new.db
+
+$root/sbin/makemap btree $root/etc/access.new < $root/etc/access.new
+if [ $? != 0 ]; then
+    exit $MR_MKCRED
+fi
+
+mv $root/etc/access $root/etc/access.old
+mv $root/etc/access.db $root/etc/access.old.db
+mv $root/etc/access.new $root/etc/access
+mv $root/etc/access.new.db $root/etc/access.db
+
+rm -f $0
+exit 0

home help back first fref pref prev next nref lref last post