diff --git a/RELEASE_NOTES b/RELEASE_NOTES index a14104d2..ce5badbb 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -9,6 +9,9 @@ release, and a summary of the changes in that release. OpenDKIM does. Suggested by Robbert Klarenbeek. Log the host portion of ignored Authentication-Results fields at "debug" level. + CONTRIB: Fix #59: Allow database name, userid and password to be + specified on the command line rather than hard-coding them. + Problem noted by Scott Kitterman. 1.1.3 2013/04/13 Fix reporting of nonexistent SPF results. Problem noted by diff --git a/contrib/rddmarc/dmarcfail.py b/contrib/rddmarc/dmarcfail.py index 41f7770e..96df270f 100644 --- a/contrib/rddmarc/dmarcfail.py +++ b/contrib/rddmarc/dmarcfail.py @@ -35,10 +35,7 @@ import time import MySQLdb -db = MySQLdb.connect(user='dmarc',passwd='xxx',db='dmarc', use_unicode=True) -MySQLdb.paramstyle='format' - -def dmfail(h,f): +def dmfail(db,h,f): e = email.message_from_file(h) if(e.get_content_type() != "multipart/report"): print f,"is not a report" @@ -76,11 +73,29 @@ def dmfail(h,f): ################################################################################################# if __name__ == "__main__": import sys + import argparse + + parser = argparse.ArgumentParser(description="process DMARC failures") + parser.add_argument("-n", "--dbname", dest="dbname", action="store", + type="string", help="database name", + default="opendmarc") + parser.add_argument("-p", "--dbpasswd", dest="dbpasswd", action="store", + type="string", help="database password", + default="opendmarc") + parser.add_argument("-u", "--dbuser", dest="dbuser", action="store", + type="string", help="database user", + default="opendmarc") + parser.add_argument("file", nargs="*") + args = parser.parse_args() - if(len(sys.argv) < 2): - dmfail(sys.stdin,"stdin"); + db = MySQLdb.connect(user=args.dbuser, passwd=args.dbpasswd, + db=args.dbname, use_unicode=True) + MySQLdb.paramstyle='format' + + if(len(args.file) == 0): + dmfail(db,sys.stdin,"stdin"); else: - for f in sys.argv[1:]: + for f in args.file: h = open(f) - dmfail(h, f) + dmfail(db,h,f) h.close() diff --git a/contrib/rddmarc/rddmarc b/contrib/rddmarc/rddmarc index 194bc151..8ee8c6bf 100644 --- a/contrib/rddmarc/rddmarc +++ b/contrib/rddmarc/rddmarc @@ -9,6 +9,9 @@ # -d print debug info # -x read XML files rather than mail messages # -r replace existing report rather than failing +# -u database user +# -p database password +# -n database name # Copyright 2012-2013, Taughannock Networks. All rights reserved. @@ -45,12 +48,20 @@ use DBI; use Socket qw{:addrinfo inet_ntop inet_pton AF_INET6 AF_INET}; use PerlIO::gzip; -use vars qw{$opt_d $opt_r $opt_x}; +use vars qw{$opt_d $opt_r $opt_x $opt_u $opt_p $opt_n}; -getopts('drx'); +getopts('drxu:p:n:'); +if (!defined($opt_u)) { + $opt_u = "opendmarc"; +} +if (!defined($opt_p)) { + $opt_p = "opendmarc"; +} +if (!defined($opt_n)) { + $opt_n = "opendmarc"; +} -my $dbh = DBI->connect("DBI:mysql:database=dmarc", - "xxx", "xxx") +my $dbh = DBI->connect("DBI:mysql:database=$opt_n", $opt_u, $opt_p) or die "Cannot connect to database\n"; foreach my $i (@ARGV) {