postfix-cluebringer (2.0.10-1) 03_fix_db_queries.patch

Summary

 cbp/modules/AccessControl.pm |   30 +++++------
 cbp/modules/CheckHelo.pm     |   57 +++++++++++---------
 cbp/modules/CheckSPF.pm      |   14 ++---
 cbp/modules/Greylisting.pm   |  117 ++++++++++++++++++++++---------------------
 cbp/modules/Quotas.pm        |   12 ++--
 cbp/policies.pm              |   21 ++++---
 6 files changed, 132 insertions(+), 119 deletions(-)

    
download this patch

Patch contents

--- a/cbp/modules/AccessControl.pm
+++ b/cbp/modules/AccessControl.pm
@@ -100,14 +100,14 @@
 				$server->log(LOG_ERR,"Database query failed: ".cbp::dblayer::Error());
 				return $server->protocol_response(PROTO_DB_ERROR);
 			}
-			my $row = $sth->fetchrow_hashref();
+			my $row = hashifyLCtoMC($sth->fetchrow_hashref(), qw( Verdict Data ));
 			DBFreeRes($sth);
 
 			# If no result, next
 			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'},
@@ -115,56 +115,56 @@
 						$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'});
 
-			} elsif ($row->{'verdict'} =~ /^ok$/i) {
+			} elsif ($row->{'Verdict'} =~ /^ok$/i) {
 				$server->maillog("module=AccessControl, action=ok, host=%s, helo=%s, from=%s, to=%s, reason=verdict",
 						$sessionData->{'ClientAddress'},
 						$sessionData->{'Helo'},
 						$sessionData->{'Sender'},
 						$sessionData->{'Recipient'});
-				return $server->protocol_response(PROTO_OK,$row->{'data'});
+				return $server->protocol_response(PROTO_OK,$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'},
--- a/cbp/modules/CheckHelo.pm
+++ b/cbp/modules/CheckHelo.pm
@@ -112,33 +112,36 @@
 				$server->log(LOG_ERR,"[CHECKHELO] Database query failed: ".cbp::dblayer::Error());
 				return $server->protocol_response(PROTO_DB_ERROR);
 			}
-			while (my $row = $sth->fetchrow_hashref()) {
+			while (my $row = hashifyLCtoMC($sth->fetchrow_hashref(),
+					qw( UseBlacklist BlacklistPeriod UseHRP HRPPeriod HRPLimit RejectInvalid RejectIP RejectUnresolvable )
+			)) {
+
 				# 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}})
@@ -203,9 +206,9 @@
 		return $server->protocol_response(PROTO_DB_ERROR);
 	}
 	# Loop with whitelist and calculate
-	while (my $row = $sth->fetchrow_hashref()) {
+	while (my $row = hashifyLCtoMC($sth->fetchrow_hashref(), qw( Source ))) {
 		# 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);
@@ -229,7 +232,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);
 		}
@@ -366,10 +369,10 @@
 			$server->log(LOG_ERR,"Database query failed: ".cbp::dblayer::Error());
 			return $server->protocol_response(PROTO_DB_ERROR);
 		}
-		my $row = $sth->fetchrow_hashref();
+		my $row = hashifyLCtoMC($sth->fetchrow_hashref(), qw( Count ));
 
 		# 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'},
@@ -418,11 +421,11 @@
 							$server->log(LOG_ERR,"Database query failed: ".cbp::dblayer::Error());
 							return $server->protocol_response(PROTO_DB_ERROR);
 						}
-						my $row = $sth->fetchrow_hashref();
+						my $row = hashifyLCtoMC($sth->fetchrow_hashref(), qw( Count ));
 
 
 						# 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'},
@@ -484,13 +487,13 @@
 		$server->log(LOG_ERR,"[CHECKHELO] Failed to query maximum periods: ".cbp::dblayer::Error());
 		return -1;
 	}
-	my $row = $sth->fetchrow_hashref();
+	my $row = hashifyLCtoMC($sth->fetchrow_hashref(), qw( BlacklistPeriod HRPPeriod));
 
 	# 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));
--- a/cbp/modules/CheckSPF.pm
+++ b/cbp/modules/CheckSPF.pm
@@ -110,18 +110,18 @@
 				$server->log(LOG_ERR,"[CHECKSPF] Database query failed: ".cbp::dblayer::Error());
 				return $server->protocol_response(PROTO_DB_ERROR);
 			}
-			while (my $row = $sth->fetchrow_hashref()) {
+			while (my $row = hashifyLCtoMC($sth->fetchrow_hashref(), qw( UseSPF RejectFailedSPF AddSPFHeader ))) {
 				# 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}})
--- a/cbp/modules/Greylisting.pm
+++ b/cbp/modules/Greylisting.pm
@@ -111,48 +111,56 @@
 				return $server->protocol_response(PROTO_DB_ERROR);
 			}
 			# Loop with rows and build end policy
-			while (my $row = $sth->fetchrow_hashref()) {
+			while (my $row = hashifyLCtoMC($sth->fetchrow_hashref(),
+					qw(
+						UseGreylisting GreylistPeriod Track GreylistAuthValidity
+						GreylistUnAuthValidity UseAutoWhitelist AutoWhitelistPeriod
+						AutoWhitelistCount AutoWhitelistPercentage UseAutoBlacklist
+						AutoBlacklistPeriod AutoBlacklistCount AutoBlacklistPercentage
+					)
+			)) {
+
 				# 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())
@@ -187,10 +195,10 @@
 		return $server->protocol_response(PROTO_DB_ERROR);
 	}
 	# Loop with whitelist and calculate
-	while (my $row = $sth->fetchrow_hashref()) {
+	while (my $row = hashifyLCtoMC($sth->fetchrow_hashref(), qw( Source ))) {
 		
 		# 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);
@@ -213,7 +221,7 @@
 			}
 
 		} else {
-			$server->log(LOG_WARN,"[GREYLISTING] Skipping invalid whitelist entry '".$row->{'source'}."'.");
+			$server->log(LOG_WARN,"[GREYLISTING] Skipping invalid whitelist entry '".$row->{'Source'}."'.");
 		}
 	}
 	DBFreeRes($sth);
@@ -251,13 +259,13 @@
 				$server->log(LOG_ERR,"[GREYLISTING] Database query failed: ".cbp::dblayer::Error());
 				return $server->protocol_response(PROTO_DB_ERROR);
 			}
-			my $row = $sth->fetchrow_hashref();
+			my $row = hashifyLCtoMC($sth->fetchrow_hashref(), qw( ID LastSeen ));
 
 			# Pull off first row
 			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,13 +319,13 @@
 				$server->log(LOG_ERR,"[GREYLISTING] Database query failed: ".cbp::dblayer::Error());
 				return $server->protocol_response(PROTO_DB_ERROR);
 			}
-			my $row = $sth->fetchrow_hashref();
+			my $row = hashifyLCtoMC($sth->fetchrow_hashref(), qw( ID Added ));
 
 			# Pull off first row
 			if ($row) {
 
 				# 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'},
@@ -386,8 +394,8 @@
 						$server->log(LOG_ERR,"[GREYLISTING] Database query failed: ".cbp::dblayer::Error());
 						return $server->protocol_response(PROTO_DB_ERROR);
 					}
-					my $row = $sth->fetchrow_hashref();
-					my $totalCount = defined($row->{'totalcount'}) ? $row->{'totalcount'} : 0;
+					my $row = hashifyLCtoMC($sth->fetchrow_hashref(), qw( TotalCount ));
+					my $totalCount = defined($row->{'TotalCount'}) ? $row->{'TotalCount'} : 0;
 
 
 					# If count exceeds or equals blacklist count, nail the server
@@ -409,8 +417,8 @@
 							$server->log(LOG_ERR,"[GREYLISTING] Database query failed: ".cbp::dblayer::Error());
 							return $server->protocol_response(PROTO_DB_ERROR);
 						}
-						$row = $sth->fetchrow_hashref();
-						my $failCount = defined($row->{'failcount'}) ? $row->{'failcount'} : 0;
+						$row = hashifyLCtoMC($sth->fetchrow_hashref(), qw( FailCount ));
+						my $failCount = defined($row->{'FailCount'}) ? $row->{'FailCount'} : 0;
 
 						# Check if we should blacklist this host
 						if (defined($policy{'AutoBlacklistPercentage'}) && $policy{'AutoBlacklistPercentage'} > 0) {
@@ -531,8 +539,7 @@
 		SELECT
 			FirstSeen,
 			LastUpdate,
-			Tries,
-			Count
+			Tries
 
 		FROM
 			greylisting_tracking
@@ -546,14 +553,14 @@
 		$server->log(LOG_ERR,"[GREYLISTING] Database query failed: ".cbp::dblayer::Error());
 		return $server->protocol_response(PROTO_DB_ERROR);
 	}
-	my $row = $sth->fetchrow_hashref();
+	my $row = hashifyLCtoMC($sth->fetchrow_hashref(), qw( FirstSeen LastUpdate Tries ));
 	if (!$row) {
 		$server->log(LOG_ERR,"[GREYLISTING] Failed to find triplet in database");
 		return $server->protocol_response(PROTO_DB_ERROR);
 	}
 
 	# 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;
@@ -562,7 +569,7 @@
 				$sessionData->{'Helo'},
 				$sessionData->{'Sender'},
 				$sessionData->{'Recipient'},
-				$row->{'tries'} + 1);
+				$row->{'Tries'} + 1);
 
 		# Update stats
 		my $sth = DBDo("
@@ -624,8 +631,8 @@
 						$server->log(LOG_ERR,"[GREYLISTING] Database query failed: ".cbp::dblayer::Error());
 						return $server->protocol_response(PROTO_DB_ERROR);
 					}
-					my $row = $sth->fetchrow_hashref();
-					my $totalCount = defined($row->{'totalcount'}) ? $row->{'totalcount'} : 0;
+					my $row = hashifyLCtoMC($sth->fetchrow_hashref(), qw( TotalCount ));
+					my $totalCount = defined($row->{'TotalCount'}) ? $row->{'TotalCount'} : 0;
 
 					# If count exceeds or equals whitelist count, nail the server
 					if ($totalCount >= $policy{'AutoWhitelistCount'}) {
@@ -645,8 +652,8 @@
 							$server->log(LOG_ERR,"[GREYLISTING] Database query failed: ".cbp::dblayer::Error());
 							return $server->protocol_response(PROTO_DB_ERROR);
 						}
-						$row = $sth->fetchrow_hashref();
-						my $passCount = defined($row->{'passcount'}) ? $row->{'passcount'} : 0;
+						$row = hashifyLCtoMC($sth->fetchrow_hashref(), qw( PassCount ));
+						my $passCount = defined($row->{'PassCount'}) ? $row->{'PassCount'} : 0;
 				
 						# Check if we should whitelist this host
 						if (defined($policy{'AutoWhitelistPercentage'}) && $policy{'AutoWhitelistPercentage'} > 0) {
@@ -828,11 +835,11 @@
 		$server->log(LOG_ERR,"[GREYLISTING] Failed to query AutoWhitelistPeriod: ".cbp::dblayer::Error());
 		return -1;
 	}
-	my $row = $sth->fetchrow_hashref();
+	my $row = hashifyLCtoMC($sth->fetchrow_hashref(), qw( Period ));
 
 	# 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;
 
@@ -866,11 +873,11 @@
 		$server->log(LOG_ERR,"[GREYLISTING] Failed to query AutoBlacklistPeriod: ".cbp::dblayer::Error());
 		return -1;
 	}
-	$row = $sth->fetchrow_hashref();
+	$row = hashifyLCtoMC($sth->fetchrow_hashref(), qw( Period ));
 
 	# 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;
 	
@@ -903,11 +910,11 @@
 		$server->log(LOG_ERR,"[GREYLISTING] Failed to query GreylistAuthValidity: ".cbp::dblayer::Error());
 		return -1;
 	}
-	$row = $sth->fetchrow_hashref();
+	$row = hashifyLCtoMC($sth->fetchrow_hashref(), qw( Period ));
 	
 	# 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;
 	
@@ -941,11 +948,11 @@
 		$server->log(LOG_ERR,"[GREYLISTING] Failed to query GreylistUnAuthValidity: ".cbp::dblayer::Error());
 		return -1;
 	}
-	$row = $sth->fetchrow_hashref();
+	$row = hashifyLCtoMC($sth->fetchrow_hashref(), qw( Period ));
 
 	# 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;
 	
--- a/cbp/modules/Quotas.pm
+++ b/cbp/modules/Quotas.pm
@@ -569,8 +569,8 @@
 		$server->log(LOG_ERR,"Failed to get quota data: ".cbp::dblayer::Error());
 		return -1;
 	}
-	while (my $quota = $sth->fetchrow_hashref()) {
-		push(@res,hashifyLCtoMC($quota,qw(ID Period Track Verdict Data)));
+	while (my $quota = hashifyLCtoMC($sth->fetchrow_hashref(), qw( ID Period Track Verdict Data ))) {
+		push(@res,$quota);
 	}
 
 	return \@res;
@@ -667,10 +667,10 @@
 		$server->log(LOG_ERR,"[QUOTAS] Failed to query quotas_tracking: ".cbp::dblayer::Error());
 		return -1;
 	}
-	my $row = $sth->fetchrow_hashref(); 
+	my $row = hashifyLCtoMC($sth->fetchrow_hashref(),qw( QuotasLimitsID TrackKey Counter LastUpdate )); 
 	DBFreeRes($sth);
 
-	return hashifyLCtoMC($row,qw(QuotasLimitsID TrackKey Counter LastUpdate));
+	return $row;
 }
 
 
@@ -695,8 +695,8 @@
 		return -1;
 	}
 	my $list = [];
-	while (my $qtrack = $sth->fetchrow_hashref()) {
-		push(@{$list},hashifyLCtoMC($qtrack,qw(ID Type CounterLimit)));
+	while (my $qtrack = hashifyLCtoMC($sth->fetchrow_hashref(), qw( ID Type CounterLimit ))) {
+		push(@{$list},$qtrack);
 	}
 
 	return $list;
--- a/cbp/policies.pm
+++ b/cbp/policies.pm
@@ -107,15 +107,18 @@
 	}
 	# Loop with results
 	my @policyMembers;
-	while (my $row = $sth->fetchrow_hashref()) {
+	while (my $row = hashifyLCtoMC($sth->fetchrow_hashref(),
+			qw( Name Priority PolicyDisabled ID PolicyID Source Destination MemberDisabled )
+	)) {
+
 		# 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,hashifyLCtoMC($row,qw(Name Priority PolicyDisabled ID PolicyID Source Destination MemberDisabled)));
+			$server->log(LOG_DEBUG,"[POLICIES] Found policy member with ID '".$row->{'ID'}."' in policy '".$row->{'Name'}."'") if ($log);
+			push(@policyMembers,$row);
 		}
 	}
 
@@ -243,8 +246,8 @@
 	}
 	# Pull in groups
 	my @groupMembers;
-	while (my $row = $sth->fetchrow_hashref()) {
-		push(@groupMembers,$row->{'member'});
+	while (my $row = hashifyLCtoMC($sth->fetchrow_hashref(), qw( Member ))) {
+		push(@groupMembers,$row->{'Member'});
 	}
 
 	return \@groupMembers;