patch for reading domains from an sql database hi, i've modified dkfilter.out to read the list of domains from an sql database for which to sign emails for. see the patch for details. an example call for starting the server is: /usr/local/dkfilter/bin/dkfilter.out --keyfile=/usr/local/dkfilter/private.key --selector=selector1 --domain="dbi:mysql:database=mail;host=##" --sqlstmt="SELECT domain from domain" --method=nofws --headers 127.0.0.1:10027 127.0.0.1:10028 the list of domains is refreshed for every mail, so it is not neccecary to restart the dkfilter server if someone is going to add an new domain to the database. Greets Sven s.klose@traviangames.com Index: dkfilter/scripts/dkfilter.out =================================================================== --- dkfilter.orig/scripts/dkfilter.out +++ dkfilter/scripts/dkfilter.out @@ -26,6 +26,7 @@ use Getopt::Long; use Pod::Usage; use IO::File; use Sys::Syslog; +use DBI; use DKMessage; use MySmtpServer; @@ -46,6 +47,7 @@ my $daemonize; my $pidfile; my $debug; my $help; +my $sqlStmt; GetOptions( "reject-fail" => \$reject_fail, "reject-error" => \$reject_error, @@ -60,6 +62,7 @@ GetOptions( "daemonize" => \$daemonize, "pidfile=s" => \$pidfile, "debug" => \$debug, + "sqlstmt=s" => \$sqlStmt, "help|?" => \$help) or pod2usage(2); pod2usage(1) if $help; @@ -89,7 +92,21 @@ unless (defined $domain_arg) { pod2usage("Error: domain not specified"); } -my @domains = split(/,\s*/, $domain_arg); + +my @domains = (); +my $dbh; + +if ($domain_arg =~ /^dbi:/) +{ + my ($dbs, $dbu, $dbp) = split(/#/,$domain_arg); + $dbh = DBI->connect($dbs, $dbu, $dbp) || die("DBI->connect(): ".DBI->errstr."\n"); + reread_domains(); +} +else +{ + @domains = split(/,\s*/, $domain_arg); +} + unless (@domains) { pod2usage("Error: domain not specified"); @@ -110,6 +127,13 @@ main->run( pid_file => $pidfile, ); +sub reread_domains +{ + my $result = $dbh->selectcol_arrayref($sqlStmt); + die "reread_domains(): ",DBI->errstr,"\n" if DBI->errstr; + @domains = @$result; +} + sub setup_client_socket { # create an object for sending the outgoing SMTP commands @@ -161,6 +185,10 @@ sub handle_end_of_data $mess = DKMessage->new_from_handle($fh); # determine what domain to use + if ($domain_arg =~ /^dbi:/) + { + reread_domains(); + } my $domain; if ($domain = lc $mess->senderdomain) {