Hi Juan,

Thanks for addressing the issue, also I would like to place a feature
request:

Is is posible to have a RCPT Counter limit type in the quotas module?,
same feature in the old policydv1.

I want to avoid users send few messages with 1000 recipients each. I
know that postfix features smtpd_recipient_limit, but does not have a
way to throttle in time frames like policyd does.

Could you try the attached patch and let us know how it goes?

Please also note that this will change the behaviour of the message size counters and the database will need to be modified.

The following commands should help you:

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);

Let us know if you run into any problems.

Robert
>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

_______________________________________________
Users mailing list
[email protected]
http://lists.policyd.org/mailman/listinfo/users

Reply via email to