After trying for 2 days the 2.0.4 release and not going anywhere i
finally decided to switch database backend to mysql ( i was using pg 8.3
). Everything works on mysql, but on postgres i get lots of errors. I'm
pretty sure the errors are due to the capitals in the queries, since PG
converts all database names and fileds to lowercase. Here's the log :
Please test the attached patch.
I'd also appreciate the testers test each module aswell, if someone can
confirm with me that everything works ( I don't always trust myself),
then I'll commit this fix to stable aswell.
Regards
Nigel
Index: contrib/amavisd-new/amavisd-policyd.pm
===================================================================
--- contrib/amavisd-new/amavisd-policyd.pm (revision 305)
+++ contrib/amavisd-new/amavisd-policyd.pm (working copy)
@@ -717,6 +717,11 @@
my $row = $sth->fetchrow_hashref();
DBFreeRes($sth);
+ # Database compatibility, quick and dirty
+ if ($row) {
+ $row->{'ID'} = $row->{'id'};
+ }
+
return $row;
}
Index: cbp/policies.pm
===================================================================
--- cbp/policies.pm (revision 305)
+++ cbp/policies.pm (working copy)
@@ -108,13 +108,13 @@
my @policyMembers;
while (my $row = $sth->fetchrow_hashref()) {
# Log what we see
- if ($row->{'PolicyDisabled'} eq "1") {
- $server->log(LOG_DEBUG,"[POLICIES] Policy '".$row->{'Name'}."' is disabled") if ($log);
- } elsif ($row->{'MemberDisabled'} eq "1") {
- $server->log(LOG_DEBUG,"[POLICIES] Policy member item with ID '".$row->{'ID'}."' is disabled") if ($log);
+ if ($row->{'policydisabled'} eq "1") {
+ $server->log(LOG_DEBUG,"[POLICIES] Policy '".$row->{'name'}."' is disabled") if ($log);
+ } elsif ($row->{'memberdisabled'} eq "1") {
+ $server->log(LOG_DEBUG,"[POLICIES] Policy member item with ID '".$row->{'id'}."' is disabled") if ($log);
} else {
- $server->log(LOG_DEBUG,"[POLICIES] Found policy member with ID '".$row->{'ID'}."' in policy '".$row->{'Name'}."'") if ($log);
- push(@policyMembers,$row);
+ $server->log(LOG_DEBUG,"[POLICIES] Found policy member with ID '".$row->{'id'}."' in policy '".$row->{'name'}."'") if ($log);
+ push(@policyMembers,hashifyLCtoMC($row,qw(Name Priority PolicyDisabled ID PolicyID Source Destination MemberDisabled)));
}
}
@@ -241,18 +241,12 @@
return cbp::dblayer::Error();
}
# Pull in groups
- my @groupMembers = ();
+ my @groupMembers;
while (my $row = $sth->fetchrow_hashref()) {
- push(@groupMembers,$row);
+ push(@groupMembers,$row->{'member'});
}
- # Loop with results
- my @res;
- foreach my $item (@groupMembers) {
- push(@res,$item->{'Member'});
- }
-
- return [EMAIL PROTECTED];
+ return [EMAIL PROTECTED];
}
Index: cbp/dblayer.pm
===================================================================
--- cbp/dblayer.pm (revision 305)
+++ cbp/dblayer.pm (working copy)
@@ -39,6 +39,8 @@
DBFreeRes
DBSelectNumResults
+
+ hashifyLCtoMC
);
@@ -245,7 +247,28 @@
}
+# Convert a lower case array to mixed case
+sub hashifyLCtoMC
+{
+ my ($record,@entries) = @_;
+ # If we undefined, return
+ return undef if (!defined($record));
+
+ my $res;
+
+ # Loop with each item, assign from lowecase database record to our result
+ foreach my $entry (@entries) {
+ $res->{$entry} = $record->{lc($entry)};
+ }
+
+ return $res;
+}
+
+
+
+
+
1;
# vim: ts=4
Index: cbp/database/dbi.pm
===================================================================
--- cbp/database/dbi.pm (revision 305)
+++ cbp/database/dbi.pm (working copy)
@@ -1,215 +0,0 @@
-# Author: Nigel Kukard <[EMAIL PROTECTED]>
-# Date: 2007-06-08
-# Desc: DBI Lookup Database Type
-
-
-package cbp::database::dbi;
-
-use strict;
-use warnings;
-
-use cbp::logging;
-use cbp::modules;
-
-use DBI;
-use Data::Dumper;
-
-
-
-# User plugin info
-our $pluginInfo = {
- name => "DBI Lookup Database Type",
- type => "dbi",
- init => \&init,
- new => sub { cbp::database::dbi->new(@_) },
-};
-
-# Our config
-my %config;
-
-
-# Initialize
-sub init {
- my $server = shift;
- my $ini = $server->{'inifile'};
-
- return 0;
-}
-
-
-# Constructor
-sub new {
- my ($class,$server,$name) = @_;
- my $ini = $server->{'inifile'};
-
-
- my $self = {
- _dbh => undef,
- _dsn => undef,
- };
-
- # Database connection info
- $self->{'_dsn'} = $ini->val("database $name",'dsn');
- my $username = $ini->val("database $name",'username');
- my $password = $ini->val("database $name",'password');
-
- # Connect to database
- $self->{'_dbh'} = DBI->connect($self->{'_dsn'}, $username, $password, {
- 'AutoCommit' => 1,
- 'PrintError' => 0
- });
- # Check for error
- if (!$self->{'_dbh'}) {
- logger(LOG_ERR,"[DATABASE/DBI] Failed to connect to '".$self->{'_dsn'}."': $DBI::errstr");
- }
-
- bless $self, $class;
- return $self;
-}
-
-
-# Close down
-sub close {
- my $self = shift;
-
- $self->{'_dbh'}->disconnect();
- logger(LOG_ERR,"[DATABASE/DBI] Closing '".$self->{'_dsn'}."'");
-}
-
-
-
-# Function to see if we ok
-sub getStatus {
- my $self = shift;
-
-
- return $self->{'_dbh'} ? 0 : -1;
-}
-
-
-# Do a lookup
-sub lookup {
- my ($self,$query) = @_;
-
- # Prepare statement
- my $sth = $self->{'_dbh'}->prepare($query);
- if (!$sth) {
- logger(LOG_ERR,"[DATABASE/DBI] Failed to prepare statement '$query': ".$self->{'_dbh'}->errstr);
- return -1;
- }
-
- # Execute
- my $res = $sth->execute();
- if (!$res) {
- logger(LOG_ERR,"[DATABASE/DBI] Failed to execute statement: '$query': ".$self->{'_dbh'}->errstr);
- return -1;
- }
-
- # Setup results
- my @results;
- while (my $item = $sth->fetchrow_hashref()) {
- push(@results,$item);
- }
-
- # Finish off
- $sth->finish();
-
- logger(LOG_DEBUG,"[DATABASE/DBI] LOOKUP Results: ".Dumper([EMAIL PROTECTED]));
- return [EMAIL PROTECTED];
-}
-
-
-# Store something
-sub store {
- my ($self,$query) = @_;
-
-
- # Prepare statement
- my $sth = $self->{'_dbh'}->prepare($query);
- if (!$sth) {
- logger(LOG_ERR,"[DATABASE/DBI] Failed to prepare statement '$query': ".$self->{'_dbh'}->errstr);
- return -1;
- }
-
- # Execute
- my $res = $sth->execute();
- if (!$res) {
- logger(LOG_ERR,"[DATABASE/DBI] Failed to execute statement: '$query': ".$self->{'_dbh'}->errstr);
- return -1;
- }
-
- # Finish off
- $sth->finish();
-
- logger(LOG_DEBUG,"[DATABASE/DBI] STORE Results: $res");
-
- return $res;
-}
-
-
-# Update something
-sub update {
- my ($self,$query) = @_;
-
-
- # Prepare statement
- my $sth = $self->{'_dbh'}->prepare($query);
- if (!$sth) {
- logger(LOG_ERR,"[DATABASE/DBI] Failed to prepare statement '$query': ".$self->{'_dbh'}->errstr);
- return -1;
- }
-
- # Execute
- my $res = $sth->execute();
- if (!$res) {
- logger(LOG_ERR,"[DATABASE/DBI] Failed to execute statement: '$query': ".$self->{'_dbh'}->errstr);
- return -1;
- }
-
- # Finish off
- $sth->finish();
-
- logger(LOG_DEBUG,"[DATABASE/DBI] UPDATE Results: $res");
-
- return $res;
-}
-
-
-# Remove something
-sub remove {
- my ($self,$query) = @_;
-
-
- # Prepare statement
- my $sth = $self->{'_dbh'}->prepare($query);
- if (!$sth) {
- logger(LOG_ERR,"[DATABASE/DBI] Failed to prepare statement '$query': ".$self->{'_dbh'}->errstr);
- return -1;
- }
-
- # Execute
- my $res = $sth->execute();
- if (!$res) {
- logger(LOG_ERR,"[DATABASE/DBI] Failed to execute statement: '$query': ".$self->{'_dbh'}->errstr);
- return -1;
- }
-
- # Finish off
- $sth->finish();
-
- logger(LOG_DEBUG,"[DATABASE/DBI] REMOVE Results: $res");
-
- return $res;
-}
-
-
-# Quote something
-sub quote {
- my ($self,$string) = @_;
- return $self->{'_dbh'}->quote($string);
-}
-
-
-
-1;
-# vim: ts=4
Index: cbp/dbilayer.pm
===================================================================
--- cbp/dbilayer.pm (revision 305)
+++ cbp/dbilayer.pm (working copy)
@@ -117,7 +117,8 @@
$self->{_dbh} = DBI->connect($self->{_dsn}, $self->{_username}, $self->{_password}, {
'AutoCommit' => 1,
- 'PrintError' => 0
+ 'PrintError' => 0,
+ 'FetchHashKeyName' => 'NAME_lc'
});
# Connect to database if we have to, check if we ok
Index: cbp/modules/CheckHelo.pm
===================================================================
--- cbp/modules/CheckHelo.pm (revision 305)
+++ cbp/modules/CheckHelo.pm (working copy)
@@ -113,31 +113,31 @@
}
while (my $row = $sth->fetchrow_hashref()) {
# If defined, its to override
- if (defined($row->{'UseBlacklist'})) {
- $policy{'UseBlacklist'} = $row->{'UseBlacklist'};
+ if (defined($row->{'useblacklist'})) {
+ $policy{'UseBlacklist'} = $row->{'useblacklist'};
}
- if (defined($row->{'BlacklistPeriod'})) {
- $policy{'BlacklistPeriod'} = $row->{'BlacklistPeriod'};
+ if (defined($row->{'blacklistperiod'})) {
+ $policy{'BlacklistPeriod'} = $row->{'blacklistperiod'};
}
- if (defined($row->{'UseHRP'})) {
- $policy{'UseHRP'} = $row->{'UseHRP'};
+ if (defined($row->{'usehrp'})) {
+ $policy{'UseHRP'} = $row->{'usehrp'};
}
- if (defined($row->{'HRPPeriod'})) {
- $policy{'HRPPeriod'} = $row->{'HRPPeriod'};
+ if (defined($row->{'hrpperiod'})) {
+ $policy{'HRPPeriod'} = $row->{'hrpperiod'};
}
- if (defined($row->{'HRPLimit'})) {
- $policy{'HRPLimit'} = $row->{'HRPLimit'};
+ if (defined($row->{'hrplimit'})) {
+ $policy{'HRPLimit'} = $row->{'hrplimit'};
}
- if (defined($row->{'RejectInvalid'})) {
- $policy{'RejectInvalid'} = $row->{'RejectInvalid'};
+ if (defined($row->{'rejectinvalid'})) {
+ $policy{'RejectInvalid'} = $row->{'rejectinvalid'};
}
- if (defined($row->{'RejectIP'})) {
- $policy{'RejectIP'} = $row->{'RejectIP'};
+ if (defined($row->{'rejectip'})) {
+ $policy{'RejectIP'} = $row->{'rejectip'};
}
- if (defined($row->{'RejectUnresolvable'})) {
- $policy{'RejectUnresolvable'} = $row->{'RejectUnresolvable'};
+ if (defined($row->{'rejectunresolvable'})) {
+ $policy{'RejectUnresolvable'} = $row->{'rejectunresolvable'};
}
} # while (my $row = $sth->fetchrow_hashref())
} # foreach my $policyID (@{$sessionData->{'Policy'}->{$priority}})
@@ -204,7 +204,7 @@
# Loop with whitelist and calculate
while (my $row = $sth->fetchrow_hashref()) {
# Check format is SenderIP
- if ((my $address = $row->{'Source'}) =~ s/^SenderIP://i) {
+ if ((my $address = $row->{'source'}) =~ s/^SenderIP://i) {
# Parse CIDR into its various peices
my $parsedIP = parseCIDR($address);
@@ -228,7 +228,7 @@
}
} else {
- $server->log(LOG_ERR,"[CHECKHELO] Whitelist entry '".$row->{'Source'}."' is invalid.");
+ $server->log(LOG_ERR,"[CHECKHELO] Whitelist entry '".$row->{'source'}."' is invalid.");
DBFreeRes($sth);
return $server->protocol_response(PROTO_DATA_ERROR);
}
@@ -368,7 +368,7 @@
my $row = $sth->fetchrow_hashref();
# If count > 0 , then its blacklisted
- if ($row->{'Count'} > 0) {
+ if ($row->{'count'} > 0) {
$server->maillog("module=CheckHelo, action=reject, host=%s, helo=%s, from=%s, to=%s, reason=blacklisted",
$sessionData->{'ClientAddress'},
$sessionData->{'Helo'},
@@ -421,7 +421,7 @@
# If count > $limit , reject
- if ($row->{'Count'} > $policy{'HRPLimit'}) {
+ if ($row->{'count'} > $policy{'HRPLimit'}) {
$server->maillog("module=CheckHelo, action=reject, host=%s, helo=%s, from=%s, to=%s, reason=hrp_blacklisted",
$sessionData->{'ClientAddress'},
$sessionData->{'Helo'},
@@ -486,10 +486,10 @@
my $row = $sth->fetchrow_hashref();
# Check we have results
- return if (!defined($row->{'BlacklistPeriod'}) || !defined($row->{'HRPPeriod'}));
+ return if (!defined($row->{'blacklistperiod'}) || !defined($row->{'hrpperiod'}));
# Work out which one is largest
- my $period = $row->{'BlacklistPeriod'} > $row->{'HRPPeriod'} ? $row->{'BlacklistPeriod'} : $row->{'HRPPeriod'};
+ my $period = $row->{'blacklistperiod'} > $row->{'hrpperiod'} ? $row->{'blacklistperiod'} : $row->{'hrpperiod'};
# Bork if we didn't find anything of interest
return if (!($period > 0));
Index: cbp/modules/CheckSPF.pm
===================================================================
--- cbp/modules/CheckSPF.pm (revision 305)
+++ cbp/modules/CheckSPF.pm (working copy)
@@ -111,16 +111,16 @@
}
while (my $row = $sth->fetchrow_hashref()) {
# If defined, its to override
- if (defined($row->{'UseSPF'})) {
- $policy{'UseSPF'} = $row->{'UseSPF'};
+ if (defined($row->{'usespf'})) {
+ $policy{'UseSPF'} = $row->{'usespf'};
}
# If defined, its to override
- if (defined($row->{'RejectFailedSPF'})) {
- $policy{'RejectFailedSPF'} = $row->{'RejectFailedSPF'};
+ if (defined($row->{'rejectfailedspf'})) {
+ $policy{'RejectFailedSPF'} = $row->{'rejectfailedspf'};
}
# If defined, its to override
- if (defined($row->{'AddSPFHeader'})) {
- $policy{'AddSPFHeader'} = $row->{'AddSPFHeader'};
+ if (defined($row->{'addspfheader'})) {
+ $policy{'AddSPFHeader'} = $row->{'addspfheader'};
}
} # while (my $row = $sth->fetchrow_hashref())
} # foreach my $policyID (@{$sessionData->{'Policy'}->{$priority}})
Index: cbp/modules/Quotas.pm
===================================================================
--- cbp/modules/Quotas.pm (revision 306)
+++ cbp/modules/Quotas.pm (working copy)
@@ -580,7 +580,7 @@
return -1;
}
while (my $quota = $sth->fetchrow_hashref()) {
- push(@res,$quota);
+ push(@res,hashifyLCtoMC($quota,qw(ID Period Track Verdict Data)));
}
return [EMAIL PROTECTED];
@@ -684,10 +684,10 @@
$server->log(LOG_ERR,"[QUOTAS] Failed to query quotas_tracking: ".cbp::dblayer::Error());
return -1;
}
- my $qtrack = $sth->fetchrow_hashref();
+ my $row = $sth->fetchrow_hashref();
DBFreeRes($sth);
- return $qtrack;
+ return hashifyLCtoMC($row,qw(QuotasLimitsID TrackKey Counter LastUpdate));
}
@@ -713,7 +713,7 @@
}
my $list;
while (my $qtrack = $sth->fetchrow_hashref()) {
- push(@{$list},$qtrack);
+ push(@{$list},hashifyLCtoMC($qtrack,qw(ID Type CounterLimit)));
}
return $list;
Index: cbp/modules/Greylisting.pm
===================================================================
--- cbp/modules/Greylisting.pm (revision 305)
+++ cbp/modules/Greylisting.pm (working copy)
@@ -112,46 +112,46 @@
# Loop with rows and build end policy
while (my $row = $sth->fetchrow_hashref()) {
# If defined, its to override
- if (defined($row->{'UseGreylisting'})) {
- $policy{'UseGreylisting'} = $row->{'UseGreylisting'};
+ if (defined($row->{'usegreylisting'})) {
+ $policy{'UseGreylisting'} = $row->{'usegreylisting'};
}
- if (defined($row->{'GreylistPeriod'})) {
- $policy{'GreylistPeriod'} = $row->{'GreylistPeriod'};
+ if (defined($row->{'greylistperiod'})) {
+ $policy{'GreylistPeriod'} = $row->{'greylistperiod'};
}
- if (defined($row->{'Track'})) {
- $policy{'Track'} = $row->{'Track'};
+ if (defined($row->{'track'})) {
+ $policy{'Track'} = $row->{'track'};
}
- if (defined($row->{'GreylistAuthValidity'})) {
- $policy{'GreylistAuthValidity'} = $row->{'GreylistAuthValidity'};
+ if (defined($row->{'greylistauthvalidity'})) {
+ $policy{'GreylistAuthValidity'} = $row->{'greylistauthvalidity'};
}
- if (defined($row->{'GreylistUnAuthValidity'})) {
- $policy{'GreylistUnAuthValidity'} = $row->{'GreylistUnAuthValidity'};
+ if (defined($row->{'greylistunauthvalidity'})) {
+ $policy{'GreylistUnAuthValidity'} = $row->{'greylistunauthvalidity'};
}
- if (defined($row->{'UseAutoWhitelist'})) {
- $policy{'UseAutoWhitelist'} = $row->{'UseAutoWhitelist'};
+ if (defined($row->{'useautowhitelist'})) {
+ $policy{'UseAutoWhitelist'} = $row->{'useautowhitelist'};
}
- if (defined($row->{'AutoWhitelistPeriod'})) {
- $policy{'AutoWhitelistPeriod'} = $row->{'AutoWhitelistPeriod'};
+ if (defined($row->{'autowhitelistperiod'})) {
+ $policy{'AutoWhitelistPeriod'} = $row->{'autowhitelistperiod'};
}
- if (defined($row->{'AutoWhitelistCount'})) {
- $policy{'AutoWhitelistCount'} = $row->{'AutoWhitelistCount'};
+ if (defined($row->{'autowhitelistcount'})) {
+ $policy{'AutoWhitelistCount'} = $row->{'autowhitelistcount'};
}
- if (defined($row->{'AutoWhitelistPercentage'})) {
- $policy{'AutoWhitelistPercentage'} = $row->{'AutoWhitelistPercentage'};
+ if (defined($row->{'autowhitelistpercentage'})) {
+ $policy{'AutoWhitelistPercentage'} = $row->{'autowhitelistpercentage'};
}
- if (defined($row->{'UseAutoBlacklist'})) {
- $policy{'UseAutoBlacklist'} = $row->{'UseAutoBlacklist'};
+ if (defined($row->{'useautoblacklist'})) {
+ $policy{'UseAutoBlacklist'} = $row->{'useautoblacklist'};
}
- if (defined($row->{'AutoBlacklistPeriod'})) {
- $policy{'AutoBlacklistPeriod'} = $row->{'AutoBlacklistPeriod'};
+ if (defined($row->{'autoblacklistperiod'})) {
+ $policy{'AutoBlacklistPeriod'} = $row->{'autoblacklistperiod'};
}
- if (defined($row->{'AutoBlacklistCount'})) {
- $policy{'AutoBlacklistCount'} = $row->{'AutoBlacklistCount'};
+ if (defined($row->{'autoblacklistcount'})) {
+ $policy{'AutoBlacklistCount'} = $row->{'autoblacklistcount'};
}
- if (defined($row->{'AutoBlacklistPercentage'})) {
- $policy{'AutoBlacklistPercentage'} = $row->{'AutoBlacklistPercentage'};
+ if (defined($row->{'autoblacklistpercentage'})) {
+ $policy{'AutoBlacklistPercentage'} = $row->{'autoblacklistpercentage'};
}
} # while (my $row = $sth->fetchrow_hashref())
@@ -189,7 +189,7 @@
while (my $row = $sth->fetchrow_hashref()) {
# Check format is SenderIP
- if ((my $address = $row->{'Source'}) =~ s/^SenderIP://i) {
+ if ((my $address = $row->{'source'}) =~ s/^SenderIP://i) {
# Parse CIDR into its various peices
my $parsedIP = parseCIDR($address);
@@ -214,7 +214,7 @@
}
} else {
- $server->log(LOG_ERR,"[GREYLISTING] Whitelist entry '".$row->{'Source'}."' is invalid.");
+ $server->log(LOG_ERR,"[GREYLISTING] Whitelist entry '".$row->{'source'}."' is invalid.");
DBFreeRes($sth);
return $server->protocol_response(PROTO_DATA_ERROR);
}
@@ -256,7 +256,7 @@
if ($row) {
# Check if we're within the auto-whitelisting period
- if ($sessionData->{'Timestamp'} - $row->{'LastSeen'} <= $policy{'AutoWhitelistPeriod'}) {
+ if ($sessionData->{'Timestamp'} - $row->{'lastseen'} <= $policy{'AutoWhitelistPeriod'}) {
my $sth = DBDo("
UPDATE
@@ -311,7 +311,7 @@
if ((my $row = $sth->fetchrow_hashref())) {
# Check if we're within the auto-blacklisting period
- if ($sessionData->{'Timestamp'} - $row->{'Added'} <= $policy{'AutoBlacklistPeriod'}) {
+ if ($sessionData->{'Timestamp'} - $row->{'added'} <= $policy{'AutoBlacklistPeriod'}) {
$server->maillog("module=Greylisting, action=reject, host=%s, helo=%s, from=%s, to=%s, reason=auto-blacklisted",
$sessionData->{'ClientAddress'},
@@ -379,7 +379,7 @@
return $server->protocol_response(PROTO_DB_ERROR);
}
my $row = $sth->fetchrow_hashref();
- my $totalCount = defined($row->{'TotalCount'}) ? $row->{'TotalCount'} : 0;
+ my $totalCount = defined($row->{'totalcount'}) ? $row->{'totalcount'} : 0;
# If count exceeds or equals blacklist count, nail the server
@@ -402,7 +402,7 @@
return $server->protocol_response(PROTO_DB_ERROR);
}
$row = $sth->fetchrow_hashref();
- my $failCount = defined($row->{'FailCount'}) ? $row->{'FailCount'} : 0;
+ my $failCount = defined($row->{'failcount'}) ? $row->{'failcount'} : 0;
# Check if we should blacklist this host
if (defined($policy{'AutoBlacklistPercentage'}) && $policy{'AutoBlacklistPercentage'} > 0) {
@@ -525,7 +525,7 @@
}
# Check if we should greylist, or not
- my $timeElapsed = $row->{'LastUpdate'} - $row->{'FirstSeen'};
+ my $timeElapsed = $row->{'lastupdate'} - $row->{'firstseen'};
if ($timeElapsed < $policy{'GreylistPeriod'}) {
# Get time left, debug and return
my $timeLeft = $policy{'GreylistPeriod'} - $timeElapsed;
@@ -534,7 +534,7 @@
$sessionData->{'Helo'},
$sessionData->{'Sender'},
$sessionData->{'Recipient'},
- $row->{'Tries'} + 1);
+ $row->{'tries'} + 1);
# Update stats
my $sth = DBDo("
@@ -597,7 +597,7 @@
return $server->protocol_response(PROTO_DB_ERROR);
}
my $row = $sth->fetchrow_hashref();
- my $totalCount = defined($row->{'TotalCount'}) ? $row->{'TotalCount'} : 0;
+ my $totalCount = defined($row->{'totalcount'}) ? $row->{'totalcount'} : 0;
# If count exceeds or equals whitelist count, nail the server
if ($totalCount >= $policy{'AutoWhitelistCount'}) {
@@ -618,7 +618,7 @@
return $server->protocol_response(PROTO_DB_ERROR);
}
$row = $sth->fetchrow_hashref();
- my $passCount = defined($row->{'PassCount'}) ? $row->{'PassCount'} : 0;
+ my $passCount = defined($row->{'passcount'}) ? $row->{'passcount'} : 0;
# Check if we should whitelist this host
if (defined($policy{'AutoWhitelistPercentage'}) && $policy{'AutoWhitelistPercentage'} > 0) {
@@ -783,7 +783,7 @@
# Check if we have something...
my $AWLPeriod;
- if (($AWLPeriod = $row->{'Period'}) && $AWLPeriod > 0) {
+ if (($AWLPeriod = $row->{'period'}) && $AWLPeriod > 0) {
# Get start time
$AWLPeriod = $now - $AWLPeriod;
@@ -821,7 +821,7 @@
# Check if we have something...
my $ABLPeriod;
- if (($ABLPeriod = $row->{'Period'}) && $ABLPeriod > 0) {
+ if (($ABLPeriod = $row->{'period'}) && $ABLPeriod > 0) {
# Get start time
$ABLPeriod = $now - $ABLPeriod;
@@ -858,7 +858,7 @@
# Check if we have something...
my $AuthPeriod;
- if (($AuthPeriod = $row->{'Period'}) && $AuthPeriod > 0) {
+ if (($AuthPeriod = $row->{'period'}) && $AuthPeriod > 0) {
# Get start time
$AuthPeriod = $now - $AuthPeriod;
@@ -896,7 +896,7 @@
# Check if we have something...
my $UnAuthPeriod;
- if (($UnAuthPeriod = $row->{'Period'}) && $UnAuthPeriod > 0) {
+ if (($UnAuthPeriod = $row->{'period'}) && $UnAuthPeriod > 0) {
# Get start time
$UnAuthPeriod = $now - $UnAuthPeriod;
Index: cbp/modules/AccessControl.pm
===================================================================
--- cbp/modules/AccessControl.pm (revision 305)
+++ cbp/modules/AccessControl.pm (working copy)
@@ -106,7 +106,7 @@
next if (!$row);
# Setup result
- if (!defined($row->{'Verdict'})) {
+ if (!defined($row->{'verdict'})) {
$server->maillog("module=AccessControl, action=none, host=%s, helo=%s, from=%s, to=%s, reason=no_verdict",
$sessionData->{'ClientAddress'},
$sessionData->{'Helo'},
@@ -114,48 +114,48 @@
$sessionData->{'Recipient'});
next; # No verdict
- } elsif ($row->{'Verdict'} =~ /^hold$/i) {
+ } elsif ($row->{'verdict'} =~ /^hold$/i) {
$server->maillog("module=AccessControl, action=hold, host=%s, helo=%s, from=%s, to=%s, reason=verdict",
$sessionData->{'ClientAddress'},
$sessionData->{'Helo'},
$sessionData->{'Sender'},
$sessionData->{'Recipient'});
- return $server->protocol_response(PROTO_HOLD,$row->{'Data'});
+ return $server->protocol_response(PROTO_HOLD,$row->{'data'});
- } elsif ($row->{'Verdict'} =~ /^reject$/i) {
+ } elsif ($row->{'verdict'} =~ /^reject$/i) {
$server->maillog("module=AccessControl, action=reject, host=%s, helo=%s, from=%s, to=%s, reason=verdict",
$sessionData->{'ClientAddress'},
$sessionData->{'Helo'},
$sessionData->{'Sender'},
$sessionData->{'Recipient'});
- return $server->protocol_response(PROTO_REJECT,$row->{'Data'});
+ return $server->protocol_response(PROTO_REJECT,$row->{'data'});
- } elsif ($row->{'Verdict'} =~ /^discard$/i) {
+ } elsif ($row->{'verdict'} =~ /^discard$/i) {
$server->maillog("module=AccessControl, action=discard, host=%s, helo=%s, from=%s, to=%s, reason=verdict",
$sessionData->{'ClientAddress'},
$sessionData->{'Helo'},
$sessionData->{'Sender'},
$sessionData->{'Recipient'});
- return $server->protocol_response(PROTO_DISCARD,$row->{'Data'});
+ return $server->protocol_response(PROTO_DISCARD,$row->{'data'});
- } elsif ($row->{'Verdict'} =~ /^filter$/i) {
+ } elsif ($row->{'verdict'} =~ /^filter$/i) {
$server->maillog("module=AccessControl, action=filter, host=%s, helo=%s, from=%s, to=%s, reason=verdict",
$sessionData->{'ClientAddress'},
$sessionData->{'Helo'},
$sessionData->{'Sender'},
$sessionData->{'Recipient'});
- return $server->protocol_response(PROTO_FILTER,$row->{'Data'});
+ return $server->protocol_response(PROTO_FILTER,$row->{'data'});
- } elsif ($row->{'Verdict'} =~ /^redirect$/i) {
+ } elsif ($row->{'verdict'} =~ /^redirect$/i) {
$server->maillog("module=AccessControl, action=redirect, host=%s, helo=%s, from=%s, to=%s, reason=verdict",
$sessionData->{'ClientAddress'},
$sessionData->{'Helo'},
$sessionData->{'Sender'},
$sessionData->{'Recipient'});
- return $server->protocol_response(PROTO_REDIRECT,$row->{'Data'});
+ return $server->protocol_response(PROTO_REDIRECT,$row->{'data'});
} else {
- $server->log(LOG_ERR,"[ACCESSCONTROL] Unknown Verdict specification in access control '".$row->{'Verdict'}."'");
+ $server->log(LOG_ERR,"[ACCESSCONTROL] Unknown Verdict specification in access control '".$row->{'verdict'}."'");
$server->maillog("module=AccessControl, action=none, host=%s, helo=%s, from=%s, to=%s, reason=invalid_verdict",
$sessionData->{'ClientAddress'},
$sessionData->{'Helo'},
Index: cbp/tracking.pm
===================================================================
--- cbp/tracking.pm (revision 305)
+++ cbp/tracking.pm (working copy)
@@ -43,11 +43,13 @@
# Database handle
my $dbh = undef;
+
# Get session data from mail_id
sub getSessionDataFromQueueID
{
my ($server,$queueID,$clientAddress,$sender) = @_;
+
$server->log(LOG_DEBUG,"[TRACKING] Retreiving session data for triplet: $queueID/$clientAddress/$sender");
# Pull in session data
@@ -74,13 +76,17 @@
$server->log(LOG_ERR,"[TRACKING] Failed to select session tracking info: ".cbp::dblayer::Error());
return -1;
}
- my $sessionData = $sth->fetchrow_hashref();
-
- if (!$sessionData) {
+
+ # Fetch row
+ my $row = $sth->fetchrow_hashref();
+ if (!$row) {
$server->log(LOG_ERR,"[TRACKING] No session data");
return -1;
}
+ # Cleanup database record
+ my $sessionData = hashifyDBSessionData($row);
+
# Pull in decoded policy
$sessionData->{'_Recipient_To_Policy'} = decodePolicyData($sessionData->{'RecipientData'});
@@ -134,10 +140,11 @@
$server->log(LOG_ERR,"[TRACKING] Failed to select session tracking info: ".cbp::dblayer::Error());
return -1;
}
- $sessionData = $sth->fetchrow_hashref();
+
+ my $row = $sth->fetchrow_hashref();
# If no state information, create everything we need
- if (!$sessionData) {
+ if (!($sessionData = hashifyDBSessionData($row))) {
$server->log(LOG_DEBUG,"[TRACKING] No session tracking data exists for request: ".Dumper($request)) if ($log);
@@ -338,5 +345,27 @@
return 0;
}
+
+# Build a hash without all LC names
+sub hashifyDBSessionData
+{
+ my $record = shift;
+
+
+ return hashifyLCtoMC($record, qw(
+ Instance QueueID
+ Timestamp
+ ClientAddress ClientName ClientReverseName
+ Protocol
+ EncryptionProtocol EncryptionCipher EncryptionKeySize
+ SASLMethod SASLSender SASLUsername
+ Helo
+ Sender
+ Size
+ RecipientData
+ ));
+}
+
+
1;
# vim: ts=4
_______________________________________________
Users mailing list
[email protected]
http://lists.policyd.org/mailman/listinfo/users