Re: env SMTPAUTHUSER (possible added to main patch)
Nicolas de Bari Embriz Garcia Rojas <[email protected]> Tue, 17 Aug 2010 00:49:22 +0100
| Newsgroups | gmane.mail.qmail.ldap |
|---|---|
| Message-ID | <[email protected]> |
Hi, the installation is very simple, a normal qmail-ldap setup with
QMAILQUEUE support. but just before compiling modify the file
qmail-smtpd.c and put this:
env_put2("SMTPAUTHUSER", remoteinfo);
after line 1598
in here:
case '2':
flagauthok = 1;
remoteinfo = line.s; out(status);
logline2(2,"authentication success, user ", remoteinfo);
env_put2("SMTPAUTHUSER", remoteinfo);
break; case '4
later just install qmail-qfilter on FreeBSD (/usr/ports/mail/qmail-qfilter)
after that modify your qmail-smtpd.rules and set the QMAILQUEUE to
something like this:
:allow,SMTP550DISCONNECT="Yes",SANITYCHECK="",BLOCKRELAYPROBE="",RETURNMXCHECK="",RCPTCHECK="",SENDERCHECK="",LOGLEVEL="3",REJECTEXEC="",NOBOUNCE="",SMTPAUTH="",NOPBS="",QMAILQUEUE="/var/qmail/bin/qmail-smtpd-filter.sh"
where "/var/qmail/bin/qmail-smtpd-filter.sh" as:
--
#!/bin/sh
exec /usr/local/bin/qmail-qfilter /var/qmail/filter/smtpthrottle.pl
--
and smtpthrottle.pl is:
--
#!/usr/bin/perl
$from = $ENV{SMTPAUTHUSER};
$db_file ='/var/qmail/control/smtpThrottle.db';
######################################################################
use DB_File;
tie (%db, 'DB_File', "$db_file", O_CREAT|O_RDWR, 0664, $DB_HASH) ||
die ("Can't open DB File, $!\n");
$cmd ="ldapsearch -h 172.16.13.2 -b
'ou=vusers,dc=pegaso,dc=unixmexico,dc=orgt' -LLL
\"(&(objectclass=qmailuser)(uid=$from))\" smtpThrottle | grep
smtpThrottle | awk '{print \$2}'";chomp($limit =qx!$cmd!);
$today = (localtime(time))[3];
if ($limit eq '') {
$limit = 10;
}
if($limit == 0) {
if ($db{$from}) {
($day,$msgs) = split(/:/, $db{$from});
$msgs = $msgs + 1;
$db{$from} = join(":", $today, $msgs, $limit);
untie (%db);
exit 0;
}
}
if ($db{$from}) {
($day,$msgs) = split(/:/, $db{$from});
if ($msgs <= $limit && $day == $today) {
$msgs = $msgs + 1;
$db{$from} = join(":", $day, $msgs, $limit);
untie (%db);
exit 0;
} elsif ($day != $today) {
$db{$from} = join(":", $today, 2, $limit);
untie (%db);
exit 0;
} else {
print STDERR "Outgoing mail quota exceeded\n"; exit (31);
}
} else {
$db{$from} = join(":", $today, 2, $limit);
}
untie (%db);
--
I also created a query-throttle.pl: (i can see the emails sent by users)
--
#!/usr/bin/perl
$db_file ='/var/qmail/control/smtpThrottle.db';
######################################################################
use DB_File;
tie (%db, 'DB_File', "$db_file", O_RDWR, 0640, $DB_HASH) || die
("Can't open DB File, $!\n");
while (($k,$v) = each %db) {
print "$k -> $v\n"
}
untie (%db);
--
I am not an expert on 'perl' maybe has some bugs but currently working fine.
now you also have to modify your qmail.schema, just add this:
attributetype ( 1.3.6.1.4.1.7914.1.2.1.18 NAME 'smtpThrottle'
DESC 'The number of message the user is allowed to send'
EQUALITY integerMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE )
and
objectclass ( 1.3.6.1.4.1.7914.1.2.2.1 NAME 'qmailUser'
DESC 'QMail-LDAP User'
SUP top
AUXILIARY
MUST ( mail )
MAY ( uid $ mailMessageStore $ homeDirectory $ userPassword $
mailAlternateAddress $ qmailUID $ qmailGID $
mailHost $ mailForwardingAddress $ deliveryProgramPath $
qmailDotMode $ deliveryMode $ mailReplyText $
accountStatus $ qmailAccountPurge $
mailQuotaSize $ mailQuotaCount $ mailSizeMax $ smtpThrottle ) )
and to your users add this new param:
smtpThrottle: 5 (only sent 5 emails per day)
if you set smtpThrottle: 0 they will have no limit
Thats all, hope this can help some one.
2010/8/16 Felipe Augusto van de Wiel
<[email protected]>:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA512
>
> On 31-07-2010 10:10, Nicolas de Bari Embriz Garcia Rojas wrote:
> [...]
>> this is the filter I am using for doing the smtp throttle currently working
>
> How did you setup your environment to run the script and implement
> the SMTP throttle?
>
> [...]
>> Hope this can help someone.
>
> This seems very nice, perhaps you could add this to the qmail-ldap
> wiki page, including the patch and configuration procedures?
>
> Kind regards,
> - --
> Felipe Augusto van de Wiel <[email protected]>
> Tecnologia da Informação (TI) - Complexo Pequeno Príncipe
> http://www.pequenoprincipe.org.br/ T: +55 41 3310 1747
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iQIcBAEBCgAGBQJMacCtAAoJECCPPxLgxLxP5rkP/i/JN9+OZfBzX1qV0GuOfSP1
> JeV7DjPmoYfGwtRbtJTWzF5sq/zyZT9yhU1xBAVXosaSu6uFfkxnsDPIwqEy3gX/
> m2DDJNv2Px1hN21M+Omwtch2R5kZ32wB10tJzKVXe1xZLPpklPTta+NYPJ+8T7f1
> q3G4V7k/FTg7qMV4vCCHN7H2ru4/3AQZ4liJDn0PTW8tPOvpGxUlVCI64HZyIMZS
> GghKfF6DRf1dtOHmtKkgwEsDiZnIiMeN+tfnfzeevY/3TCDm9VZMnAJPKyteQ1Cn
> aRfXGvA70Zln10NESi55rITgZ80KwS2DC+LWenkfUxe7c3/J+TA6i9KKd7FijAEL
> qCqyKzY3u0MIQMLhRxCQ3+769H+8AXtcQb1htXmqRebsMvMTLU/KGJ2vcYvg0Khl
> 2dBrgRdwdeQgrbIP3ykROVNnG1EUNmU0+m2x7iU65i+LRmlr14dK30Zs9yV8JoKU
> qodRm+iZ0RQqYrnmBZ2cT0Sz8yQafpfaKptNDsVojxKUP+m2N2q/wdASau3W/SNG
> XRR9kMVbabi7JXGIBf3mpZQ9AMHOQsW/nt5IWoKY5fTFJU5JQx5JVocNVxZ4Dtjz
> wOUuvmxhTufKgGOwM542x5SGEl6JwBZkrY44DjaWk/KSW5PRBqOkM9IAgG7NkipM
> rAy4py87ewGN1ghgNtMS
> =jhQW
> -----END PGP SIGNATURE-----
>
--
> nbari.tel