On 12/02/10 20:35, Edward Carraro wrote:
Here's my postfix, it's working though. It's just the counter issue, but
it eventually prevents the user from doing massive mails so that should
be acceptable

# postconf -n
alias_maps = hash:/etc/aliases
biff = no
broken_sasl_auth_clients = yes
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/lib/postfix
debug_peer_level = 2
default_destination_concurrency_limit = 2000
default_process_limit = 1000
defer_transports =
disable_dns_lookups = yes
header_checks = regexp:/etc/postfix/header_checks
html_directory = /usr/share/doc/packages/postfix/html
inet_interfaces = all
initial_destination_concurrency = 2000
local_recipient_maps =
mail_owner = postfix
mail_spool_directory = /var/mail
mailbox_size_limit = 0
mailbox_transport = lmtp:localhost
mailq_path = /usr/bin/mailq
manpage_directory = /usr/share/man
masquerade_classes = envelope_sender, header_sender, header_recipient
masquerade_domains =
masquerade_exceptions = root
max_use = 10
message_size_limit = 51200000
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mydomain = dev.nitido.com <http://dev.nitido.com>
myhostname = dev.domain.com <http://dev.domain.com>
mynetworks = 127.0.0.0/8 <http://127.0.0.0/8>
myorigin = $mydomain
newaliases_path = /usr/bin/newaliases
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/packages/postfix/README_FILES
recipient_delimiter = +
relay_domains = $mydestination, $mynetworks, dev.domain.com
<http://dev.domain.com>
relayhost = smtp.domain.com <http://smtp.domain.com>
sample_directory = /usr/share/doc/packages/postfix/samples
sendmail_path = /usr/sbin/sendmail
smtp_connection_cache_time_limit = 10s
smtp_sasl_auth_enable = no
smtp_use_tls = no
smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
smtpd_client_connection_count_limit = 1000
smtpd_client_restrictions =
smtpd_end_of_data_restrictions = check_policy_service
inet:127.0.0.1:10031 <http://127.0.0.1:10031>
smtpd_helo_required = no
smtpd_helo_restrictions =
smtpd_recipient_restrictions = check_policy_service inet:127.0.0.1:10031
<http://127.0.0.1:10031>, permit_sasl_authenticated, permit_mynetworks,
reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = private/auth
smtpd_sasl_type = dovecot
smtpd_sender_login_maps = ldap:/etc/postfix/login_maps.cf
<http://login_maps.cf>
smtpd_sender_restrictions = reject_sender_login_mismatch
smtpd_use_tls = no
soft_bounce = no
strict_rfc821_envelopes = yes
unknown_local_recipient_reject_code = 550
virtual_transport = lmtp:localhost

Hi Edward,

Could you please confirm that you have tried version v2.0.11RC1 with the attached patch to see if this fixes the problems you were having?

Robert
Index: cbp/modules/Quotas.pm
===================================================================
--- cbp/modules/Quotas.pm	(revision 517)
+++ cbp/modules/Quotas.pm	(working copy)
@@ -163,30 +163,32 @@
 						# Check if we have a queue tracking item
 						if (defined($qtrack)) {
 							my $elapsedTime = defined($qtrack->{'LastUpdate'}) ? ( $now - $qtrack->{'LastUpdate'} ) : $quota->{'Period'};
+							# If elapsed time is less than zero, its time diff between servers, meaning no time has elapsed
+							$elapsedTime = 0 if ($elapsedTime < 0);
 							
 							# Check if elapsedTime is longer than period, or negative (time diff between servers?)
 							my $currentCounter;
-							if ($elapsedTime > $quota->{'Period'} || $elapsedTime < 0) {
-								$qtrack->{'Counter'} = 0;
+							if ($elapsedTime > $quota->{'Period'}) {
+								$currentCounter = 0;
 	
 							# Calculate the % of the period we have, and multiply it with the counter ... this should give us a reasonably
 							# accurate counting
 							} else {
 								$currentCounter = ( 1 - ($elapsedTime / $quota->{'Period'}) ) * $qtrack->{'Counter'};
 							}
-								
-							# Make sure increment is at least 0
-							$newCounters{$qtrack->{'QuotasLimitsID'}} = defined($qtrack->{'Counter'}) ?
-									$qtrack->{'Counter'} - $currentCounter : $qtrack->{'Counter'}
-									if (!defined($newCounters{$qtrack->{'QuotasLimitsID'}}));
-	
+
+							# Work out the difference to the DB value, we ONLY DO THIS ONCE!!! so if its defined, leave it alone!
+							if (!defined($newCounters{$qtrack->{'QuotasLimitsID'}})) {
+								$newCounters{$qtrack->{'QuotasLimitsID'}} = $currentCounter - $qtrack->{'Counter'};
+							}
+
 							# Limit type
 							my $limitType = lc($limit->{'Type'});
 
 							# Make sure its the MessageCount counter
 							if ($limitType eq "messagecount") {
 								# Check for violation
-								if ($qtrack->{'Counter'} > $limit->{'CounterLimit'}) {
+								if ($currentCounter > $limit->{'CounterLimit'}) {
 									$hasExceeded = "Policy rejection; Message count quota exceeded";
 								}
 								# Bump up limit
@@ -195,7 +197,7 @@
 							# Check for cumulative size violation
 							} elsif ($limitType eq "messagecumulativesize") {
 								# Check for violation
-								if ($qtrack->{'Counter'} > $limit->{'CounterLimit'}) {
+								if ($currentCounter > $limit->{'CounterLimit'}) {
 									$hasExceeded = "Policy rejection; Cumulative message size quota exceeded";
 								}
 							}
@@ -206,9 +208,10 @@
 							$qtrack->{'Counter'} = 0;
 							$qtrack->{'LastUpdate'} = $now;
 								
-							# Make sure increment is at least 0
-							$newCounters{$qtrack->{'QuotasLimitsID'}} = $qtrack->{'Counter'} 
-									if (!defined($newCounters{$qtrack->{'QuotasLimitsID'}}));
+							# Work out the difference to the DB value, we ONLY DO THIS ONCE!!! so if its defined, leave it alone!
+							if (!defined($newCounters{$qtrack->{'QuotasLimitsID'}})) {
+								$newCounters{$qtrack->{'QuotasLimitsID'}} = $qtrack->{'Counter'};
+							}
 							
 							# Check if this is a message counter
 							if (lc($limit->{'Type'}) eq "messagecount") {
@@ -247,7 +250,7 @@
 			foreach my $qtrack (@trackingList) {
 					
 				# Percent used
-				my $pused =  sprintf('%.1f', ( ($newCounters{$qtrack->{'QuotasLimitsID'}} + $qtrack->{'QuotasLimitsID'}) / $qtrack->{'CounterLimit'} ) * 100);
+				my $pused =  sprintf('%.1f', ( ($newCounters{$qtrack->{'QuotasLimitsID'}} + $qtrack->{'Counter'}) / $qtrack->{'CounterLimit'} ) * 100);
 
 				# Update database
 				my $sth = DBDo("
@@ -296,7 +299,7 @@
 							$qtrack->{'LimitID'},
 							$qtrack->{'DBKey'},
 							$qtrack->{'LimitType'},
-							sprintf('%.0f',$newCounters{$qtrack->{'QuotasLimitsID'}} + $qtrack->{'QuotasLimitsID'}),
+							sprintf('%.2f',$newCounters{$qtrack->{'QuotasLimitsID'}} + $qtrack->{'Counter'}),
 							$qtrack->{'CounterLimit'},
 							$pused);
 
@@ -315,7 +318,7 @@
 							$qtrack->{'LimitID'},
 							$qtrack->{'DBKey'},
 							$qtrack->{'LimitType'},
-							sprintf('%.0f',$newCounters{$qtrack->{'QuotasLimitsID'}} + $qtrack->{'QuotasLimitsID'}),
+							sprintf('%.2f',$newCounters{$qtrack->{'QuotasLimitsID'}} + $qtrack->{'Counter'}),
 							$qtrack->{'CounterLimit'},
 							$pused);
 
@@ -329,7 +332,7 @@
 		# If we have exceeded, set verdict
 		} else {
 			# Percent used
-			my $pused =  sprintf('%.1f', ( ($newCounters{$exceededQtrack->{'QuotasLimitsID'}} + $exceededQtrack->{'QuotasLimitsID'}) / $exceededQtrack->{'CounterLimit'} ) * 100);
+			my $pused =  sprintf('%.1f', ( ($newCounters{$exceededQtrack->{'QuotasLimitsID'}} + $exceededQtrack->{'Counter'}) / $exceededQtrack->{'CounterLimit'} ) * 100);
 
 			# Log rejection to mail log
 			$server->maillog("module=Quotas, action=%s, host=%s, helo=%s, from=%s, to=%s, reason=quota_match, policy=%s, quota=%s, limit=%s, track=%s, "
@@ -344,10 +347,9 @@
 					$exceededQtrack->{'LimitID'},
 					$exceededQtrack->{'DBKey'},
 					$exceededQtrack->{'LimitType'},
-					sprintf('%.0f',$newCounters{$exceededQtrack->{'QuotasLimitsID'}} + $exceededQtrack->{'QuotasLimitsID'}),
+					sprintf('%.2f',$newCounters{$exceededQtrack->{'QuotasLimitsID'}} + $exceededQtrack->{'Counter'}),
 					$exceededQtrack->{'CounterLimit'},
 					$pused);
-
 			$verdict = $exceededQtrack->{'Verdict'};
 			$verdict_data = (defined($exceededQtrack->{'VerdictData'}) && $exceededQtrack->{'VerdictData'} ne "") 
 					? $exceededQtrack->{'VerdictData'} : $hasExceeded;
@@ -411,14 +413,14 @@
 							# Check if we're working with cumulative sizes
 							if (lc($limit->{'Type'}) eq "messagecumulativesize") {
 								# Bump up counter
-								$qtrack->{'Counter'} += $sessionData->{'Size'};
+								my $currentCounter = $qtrack->{'Counter'} + $sessionData->{'Size'};
 								
 								# Update database
 								my $sth = DBDo("
 									UPDATE 
 										quotas_tracking
 									SET
-										Counter = ".DBQuote($qtrack->{'Counter'}).",
+										Counter = Counter + ".DBQuote($sessionData->{'Size'}).",
 										LastUpdate = ".DBQuote($now)."
 									WHERE
 										QuotasLimitsID = ".DBQuote($qtrack->{'QuotasLimitsID'})."
@@ -430,7 +432,7 @@
 								}
 
 								# Percent used
-								my $pused =  sprintf('%.1f', ( $qtrack->{'Counter'} / $limit->{'CounterLimit'} ) * 100);
+								my $pused =  sprintf('%.1f', ( $currentCounter / $limit->{'CounterLimit'} ) * 100);
 
 								# Log update to mail log
 								$server->maillog("module=Quotas, mode=update, host=%s, helo=%s, from=%s, to=%s, reason=quota_update, policy=%s, "
@@ -444,7 +446,7 @@
 										$limit->{'ID'},
 										$key,
 										$limit->{'Type'},
-										sprintf('%.0f',$qtrack->{'Counter'}),
+										sprintf('%.2f',$currentCounter),
 										$limit->{'CounterLimit'},
 										$pused);
 							} # if (lc($limit->{'Type'}) eq "messagecumulativesize")
_______________________________________________
Users mailing list
[email protected]
http://lists.policyd.org/mailman/listinfo/users

Reply via email to