Re: Postfix quota integration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Omni Flux wrote:
> I've been using a postfix policy daemon to integrate with the current
> smmapd to perform quota checks. It has a few shortcomings: it does not
> support virtual domains as is, but I think that would be a minor
> modification, and IIRC, postfix does not pass the final username to the
> policy daemon if alias expansion occurs, however, for my uses, this
> catches nearly all cases of over quota mail.
[...]
> # Most recent version is available at http://www.omniflux.com/devel/

Attached patch to Omni's script introduces the ability for the policy
daemon to look up aliases from the file /etc/postfix/quota_aliases.

The alias appears on the left, with the email address to look up on the
right.  First match wins.

Eg:

alias@xxxxxxxxxxx	user1@xxxxxxxxxxx
@alias.example.com	user2@xxxxxxxxxxx
@alias.example.org	@alias.example.com

Comments are not currently recognised.  It's my first attempt at perl,
so please be gentle! :-)

Ben
--- Desktop/cyrquota-pf_policy.pl	2007-06-11 04:23:24.389169827 +0100
+++ cyrquota-pf_policy.pl	2007-06-11 04:22:54.035764203 +0100
@@ -5,6 +5,9 @@
 # Author: Omni Flux
 # Most recent version is available at http://www.omniflux.com/devel/
 #
+# Edited by Benjamin Donnachie <benjamin@xxxxxxxxxxxxx> to add 
+#  initial support for aliases.
+#
 # Policy Daemon code based on postfix-policyd-spf by Meng Weng Wong
 #  available at http://www.openspf.org/
 
@@ -155,9 +158,11 @@
 
 	my $action = $default_response;
 
-	if (lc(rhs ($attr{'recipient'})) eq lc($mydomain))
+	my $recipient = checkaliases($attr{'recipient'});
+
+	if (lc(rhs ($recipient)) eq lc($mydomain))
 	{
-		print $sock netstring_encode ("0 " . lhs ($attr{'recipient'}));
+		print $sock netstring_encode ("0 " . lhs ($recipient));
 		my $result = netstring_read ($sock);
 		if (!$result) {
 			syslog (warning => "query error");
@@ -179,7 +184,7 @@
 	}
 	else
 	{
-		syslog (debug => "Skipping external domain: %s", rhs ($attr{'recipient'})) if $verbose;
+		syslog (debug => "Skipping external domain: %s", rhs ($recipient)) if $verbose;
 	}
 
 	print STDOUT "action=$action\n\n";
@@ -213,3 +218,38 @@
 	}
 	return $string;
 }
+
+sub checkaliases {
+
+        my $key = "";
+        my $value = "";
+
+        open(FILE, "</etc/postfix/quota_aliases");
+
+        while (<FILE>) {
+                chomp;
+                my ($key, $value) = split (/\s+/, $_);
+
+                if ($key eq $_[0]) {
+                        close(FILE);
+                        return $value;
+                }
+                elsif ($key =~ /^\@.*/) {
+                        if (($key =~ /\@(.*)/) eq ($_[0] =~ /.*\@(.*)/)) {
+                                if ($value =~ /^\@.*/) {
+                                        close (FILE);
+                                        return lhs($_[0]).$value;
+                                }
+                                else {
+                                        close (FILE);
+                                        return $value;
+                                }
+                        }
+                }
+
+        }
+
+        close (FILE);
+        return $_[0];
+
+}
----
Cyrus Home Page: http://cyrusimap.web.cmu.edu/
Cyrus Wiki/FAQ: http://cyrusimap.web.cmu.edu/twiki
List Archives/Info: http://asg.web.cmu.edu/cyrus/mailing-list.html

[Index of Archives]     [Cyrus SASL]     [Squirrel Mail]     [Asterisk PBX]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [KDE]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux