Re: env SMTPAUTHUSER (possible added to main patch)

2010-08-17 Thread Nicolas de Bari Embriz Garcia Rojas
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
felipe.w...@complexopequenoprincipe.org.br:
 -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 felipe.w...@complexopequenoprincipe.org.br
 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
 

[patch] LDIF-formatted schema file for OpenLDAP

2010-08-17 Thread Brian T Glenn
Qmail-LDAP List:

I have created a modification of the current qmail.schema file to 
support the cn=config or RTC method of configuring slapd in OpenLDAP. 
This feature was introduced in version 2.3 and has become the standard 
configuration method as of Ubuntu 10.04 LTS.

The file is simply the schema file formatted as LDIF with a particular 
statically defined DIT (cn=config). The usual schema files are 
pre-converted in the /etc/ldap/schema/ directory. The schema can be 
extended during runtime with the following command:

ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/qmail.ldif

Please review and let me know of issues or changes required. The only 
changes to the comments are the inclusion of another line of credit for 
the conversion work.

-- 
Brian T Glenn
http://www.delink.net/
#
# qmail-ldap (20030901) ldapv3 directory schema
#
# The offical qmail-ldap OID assigned by IANA is 7914
#
# Created by: David E. Storey d...@tamos.net
# Modified and included into qmail-ldap by Andre Oppermann o...@nrg4u.com
# Schema fixes by Mike Jackson m...@pp.fi
# Schema fixes by Christian Zoffoli (XMerlin) czoff...@xmerlin.org
# Schema conversion to LDIF format by Brian T Glenn (delink) 
brian-ql...@delink.net
#
#
# This schema depends on:
#   - core.schema
#   - cosine.schema
#   - nis.schema
#

dn: cn=qmail,cn=schema,cn=config
objectClass: olcSchemaConfig
cn: qmail
olcAttributeTypes: ( 1.3.6.1.4.1.7914.1.2.1.1 NAME 'qmailUID'  
 DESC 'UID of the user on the mailsystem' EQUALITY integerMatch 
 SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE )
olcAttributeTypes: ( 1.3.6.1.4.1.7914.1.2.1.2 NAME 'qmailGID' 
 DESC 'GID of the user on the mailsystem' EQUALITY integerMatch 
 SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE )
olcAttributeTypes: ( 1.3.6.1.4.1.7914.1.2.1.3 NAME 'mailMessageStore' 
 DESC 'Path to the maildir/mbox on the mail system' EQUALITY caseExactIA5Match 
 SUBSTR caseIgnoreIA5SubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{256} 
SINGLE-VALUE )
olcAttributeTypes: ( 1.3.6.1.4.1.7914.1.2.1.4 NAME 'mailAlternateAddress' 
 DESC 'Secondary (alias) mailaddresses for the same user' EQUALITY 
caseIgnoreIA5Match 
 SUBSTR caseIgnoreIA5SubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{256} )
olcAttributeTypes: ( 1.3.6.1.4.1.7914.1.2.1.6 NAME 'mailHost' 
 DESC 'On which qmail server the messagestore of this user is located.' 
EQUALITY caseIgnoreIA5Match 
 SUBSTR caseIgnoreIA5SubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{256} 
SINGLE-VALUE )
olcAttributeTypes: ( 1.3.6.1.4.1.7914.1.2.1.7 NAME 'mailForwardingAddress' 
 DESC 'Address(es) to forward all incoming messages to.' EQUALITY 
caseIgnoreIA5Match 
 SUBSTR caseIgnoreIA5SubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{256} )
olcAttributeTypes: ( 1.3.6.1.4.1.7914.1.2.1.8 NAME 'deliveryProgramPath' 
 DESC 'Program to execute for all incoming mails.' EQUALITY caseExactIA5Match 
 SUBSTR caseIgnoreIA5SubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{256} )
olcAttributeTypes: ( 1.3.6.1.4.1.7914.1.2.1.9 NAME 'qmailDotMode' 
 DESC 'Interpretation of .qmail files: both, dotonly, ldaponly, ldapwithprog' 
EQUALITY caseIgnoreIA5Match 
 SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{32} SINGLE-VALUE )
olcAttributeTypes: ( 1.3.6.1.4.1.7914.1.2.1.10 NAME 'deliveryMode' 
 DESC 'multi field entries of: nolocal, noforward, noprogram, reply' EQUALITY 
caseIgnoreIA5Match 
 SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{32} )
olcAttributeTypes: ( 1.3.6.1.4.1.7914.1.2.1.11 NAME 'mailReplyText' 
 DESC 'A reply text for every incoming message' EQUALITY caseIgnoreMatch 
 SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{4096} 
SINGLE-VALUE )
olcAttributeTypes: ( 1.3.6.1.4.1.7914.1.2.1.12 NAME 'accountStatus' 
 DESC 'The status of a user account: active, noaccess, disabled, deleted' 
EQUALITY caseIgnoreIA5Match 
 SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE )
olcAttributeTypes: ( 1.3.6.1.4.1.7914.1.2.1.14 NAME 'qmailAccountPurge' 
 DESC 'The earliest date when a mailMessageStore will be purged' EQUALITY 
numericStringMatch 
 SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 SINGLE-VALUE )
olcAttributeTypes: ( 1.3.6.1.4.1.7914.1.2.1.15 NAME 'mailQuotaSize' 
 DESC 'The size of space the user can have until further messages get bounced.' 
EQUALITY integerMatch 
 SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE )
olcAttributeTypes: ( 1.3.6.1.4.1.7914.1.2.1.16 NAME 'mailQuotaCount' 
 DESC 'The number of messages the user can have until further messages get 
bounced.' EQUALITY integerMatch 
 SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE )
olcAttributeTypes: ( 1.3.6.1.4.1.7914.1.2.1.17 NAME 'mailSizeMax' 
 DESC 'The maximum size of a single messages the user accepts.' EQUALITY 
integerMatch 
 SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE )
olcAttributeTypes: ( 1.3.6.1.4.1.7914.1.3.1.1 NAME 'dnmember' 
 DESC 'Group member specified as distinguished name.' EQUALITY 
distinguishedNameMatch 
 SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )
olcAttributeTypes: (