env SMTPAUTHUSER (possible added to main patch)
Nicolas de Bari Embriz Garcia Rojas <[email protected]> Sat, 31 Jul 2010 14:10:53 +0100
| Newsgroups | gmane.mail.qmail.ldap |
|---|---|
| Message-ID | <[email protected]> |
Hi, after patching I added one line to the qmail-smtpd.c so that I could get
the user that makes the authentication on the environment var, instead of
the 'from user' so I can later use any filter (smtp throttle in my case)
based on the sender.
the file that was edited was the qmail-smtpd.c
and just added this line after patching: 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
Maybe this is a tmp solution but if it works do you thing can be added to
the main patch? it wont hurt much and help allot, or is there is a simple
solution for getting this info please let me know.
this is the filter I am using for doing the smtp throttle currently working
-----
#!/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 192.168.1.1 -b
'ou=vusers,dc=pegaso,dc=unixmexico,dc=net' -LLL
\"(&(objectclass=qmailuser)(uid=$from))\" smtpThrottle | grep smtpThrottle |
awk '{print \$2}'";
chomp($limit =qx!$cmd!);
# if no smtpTrhottle value found limit default to 10 per day
if (!$limit) {
$limit = 10;
}
$today = (localtime(time))[3];
if ($db{$from}) {
($day,$msgs) = split(/:/, $db{$from});
if ($msgs <= $limit && $day == $today) {
$msgs = $msgs + 1;
$db{$from} = join(":", $day, $msgs);
exit 0;
} elsif ($day != $today) {
$db{$from} = join(":", $today, 2);
exit 0;
} else {
print STDERR "Outgoing mail quota exceeded\n"; exit (31);
}
} else {
$db{$from} = join(":", $today, 2);
}
untie (%db);
-----
the qmail.scheme has this extra lines:
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 )
...
# Object Class Definitions
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 $ spamassassin $ AlternateEmailAddress $
YourSecretQuestion $ YourAnswer) )
---
Hope this can help someone.
regards.