Upstream posted the following patch, that works on the package. My work
around it is not necessary.

Changes radically what is stored in database, and affects quite a bit how
policyd is configured, now everything is in KBytes in database, limits too.

Regards

Juan.-
From e6e98822bb8c571f6c05272c884dcdae4858f770 Mon Sep 17 00:00:00 2001
From: Robert Anderson <[email protected]>
Date: Tue, 3 May 2011 08:35:28 +0000
Subject: [PATCH] Use size values as kbyte instead of byte

Convert bytes to kbytes on a new request
Updated UPGRADING file with details on how to modify the database to accommodate the changes to policyd

NOTE: This commit will change the behaviour of message size counters used in policyd!

The following changes will need to be made to your database:

UPDATE quotas_limits, quotas_tracking
               SET quotas_limits.CounterLimit = ceil(quotas_limits.CounterLimit / 1024),
               quotas_tracking.Counter = ceil(quotas_tracking.Counter / 1024)
               WHERE quotas_tracking.QuotasLimitsID = quotas_limits.ID
               AND quotas_limits.Type = "MessageCumulativeSize";

UPDATE session_tracking        SET Size = ceil(Size / 1024);
---
 UPGRADING       |   10 ++++++++++
 cbp/tracking.pm |   13 ++++++++++---
 2 files changed, 20 insertions(+), 3 deletions(-)
 create mode 100644 UPGRADING

diff --git a/UPGRADING b/UPGRADING
new file mode 100644
index 0000000..6e20cc6
--- /dev/null
+++ b/UPGRADING
@@ -0,0 +1,10 @@
+Updating database for 7ad3d831d7862d95d59a72ed19764264cc77c4b7
+--------------------------------------------------------------
+
+UPDATE quotas_limits, quotas_tracking
+               SET quotas_limits.CounterLimit = ceil(quotas_limits.CounterLimit / 1024),
+               quotas_tracking.Counter = ceil(quotas_tracking.Counter / 1024)
+               WHERE quotas_tracking.QuotasLimitsID = quotas_limits.ID
+               AND quotas_limits.Type = "MessageCumulativeSize";
+
+UPDATE session_tracking        SET Size = ceil(Size / 1024);
diff --git a/cbp/tracking.pm b/cbp/tracking.pm
index 8bfefc1..1d7a6fe 100644
--- a/cbp/tracking.pm
+++ b/cbp/tracking.pm
@@ -37,6 +37,7 @@ use cbp::dblayer;
 use cbp::logging;
 use cbp::policies;
 use cbp::system qw(parseCIDR);
+use POSIX qw( ceil );
 
 use Data::Dumper;
 
@@ -138,6 +139,12 @@ sub getSessionDataFromRequest
 			return -1;
 		}
 
+		# Change size to kbyte, we don't want to use bytes
+		my $requestSize;
+		if (defined($request->{'size'})) {
+			$requestSize = ceil($request->{'size'} / 1024);
+		}
+
 		my $row = $sth->fetchrow_hashref();
 				
 		# If no state information, create everything we need
@@ -176,7 +183,7 @@ sub getSessionDataFromRequest
 									".DBQuote($request->{'sasl_username'}).",
 							".DBQuote($request->{'helo_name'}).",
 							".DBQuote($request->{'sender'}).",
-							".DBQuote($request->{'size'})."
+							".DBQuote($requestSize)."
 						)
 				");
 				if (!$sth) {
@@ -203,7 +210,7 @@ sub getSessionDataFromRequest
 			$sessionData->{'SASLUsername'} = $request->{'sasl_username'};
 			$sessionData->{'Helo'} = $request->{'helo_name'};
 			$sessionData->{'Sender'} = $request->{'sender'};
-			$sessionData->{'Size'} = $request->{'size'};
+			$sessionData->{'Size'} = $requestSize;
 			$sessionData->{'RecipientData'} = "";
 		}
 	
@@ -232,7 +239,7 @@ sub getSessionDataFromRequest
 			$server->log(LOG_DEBUG,"[TRACKING] Decoded into: ".Dumper($sessionData->{'_Recipient_To_Policy'})) if ($log);
 
 			# This must be updated here ... we may of got actual size
-			$sessionData->{'Size'} = $request->{'size'};
+			$sessionData->{'Size'} = $requestSize;
 			# Only get a queue id once we have gotten the message
 			$sessionData->{'QueueID'} = $request->{'queue_id'};
 		}
-- 
1.7.3.4

Reply via email to