Skip to content

Commit

Permalink
CONTRIB: Fix trusteddomainproject#59: Allow database name, userid and…
Browse files Browse the repository at this point in the history
… password to be specified on

the command line rather than hard-coding them.  Problem noted by
Scott Kitterman.
  • Loading branch information
Murray S. Kucherawy committed Dec 30, 2013
1 parent d669854 commit 1336af6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 23 additions & 8 deletions contrib/rddmarc/dmarcfail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
19 changes: 15 additions & 4 deletions contrib/rddmarc/rddmarc
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1336af6

Please sign in to comment.