Re: LMTP mods for quota handling
"Systems Group (Isaac)" <[email protected]> Wed, 9 Apr 2003 15:14:40 -0700 (PDT)
| Newsgroups | gmane.mail.procmail.devel |
|---|---|
| Message-ID | <Pine.LNX.4.53.0304091509590.9473@warmachine> |
Hi Johan: Are the users home on the same machine where the mail server is? FYI, you might have locking problems if they are over NFS since mbox locking really sucks with mboxes over NFS. On Wed, 9 Apr 2003, Johan Reinalda wrote: > Hello, > here at Thunderbird, the American Graduate School of International > Management, we have been using Procmail in LMTP mode for about 10 months to > handle local delivery of all our student email. Mailbox access is handled by > the UW imap/pop3 daemons. > > We have made some mods to change mailbox spool file location and add quota > management. The mods are explained below and attached with diffs relative to > the v3.22 source code. > > Feel free to use this as you wish, your mileage may vary :-) > > If you have questions, please send to me directly, as I do not subscribe to > this list. > > Sincerely, > > Johan Reinalda > Director, Network Engineering and Admin. > Thunderbird, the American Graduate School > Glendale, AZ > www.thunderbird.edu > > ---------------------------------- > Background: > We store both the spool file (typically /var/spool/mail/username or such) > and the > mbox file in the user's home directory, for simplicity and to ease quota > handling. Users have no shell level access, so the only things that can > exist in their home dir is mail related files. We also do not allow direct > imap access, > which simplifies things greatly. > > Procmail sources need to be modified to store new incoming in the > user's home directory, instead of the default spool directory. This allows > us to get around potential number of file limitations. (Note: This mod could > be done with a global /etc/procmailrc setting (DEFAULT=$HOME/$LOGNAME), but > this creates an empty file at the default mail spool dir /var/spool/mail for > each user :-( ) > > We also added some custom quota handling to the LMTP portion of procmail. We > use the LMTP interface for the sendmail LDA, since this allows for better > return notification then the system return value otherwize used. > > Where the mods are: > > * config.h - enable LMTP support; straight forward, see diff > > * src/authenticate.c - change routine that gets user mail spool file to > point to user home directory plus username; also straight forward, see diff > > * src/lmtp.c - add support for quotas in the RCPT handling. If a user is > over quota (ie. there is more space in use then allowed, the message is > denied with a hard error, ie a 500 level error code) > > Several functions in src/lmtp.c handle the quota: > > The function getuserquota(username) reads the file > /var/spool/mail/quotas.txt (this filename is set via a #define), and looks > for entries of the form <username>=<maxbytes>. There should be no spaces in > this format. Lines starting with # are ignored. The username _DEFAULT_ is > special, and defines the default quota for all users that are not explicitly > defined in the file. A quota value of 0 turns off quota checking. If > /var/spool/mail/quotas.txt does not exists, 0 is returned, in effect turning > off quotas for all users. Eg. a quotas.txt file could look like this: > > #this is the quota file > _DEFAULT_=7500000 > postmaster=0 > root=0 > johan=0 > specialuser=12500000 > > > The function bytesused(directory) recursively reads all normal files under > the given directory and returns the total byte count. Note that this can > cause problems if you have normal working files in a user's home directory > as well. We do not offer that service here. > > Also, if you have things like the UW pop3/imap daemons, they write temp > files in this same directory. > This leaves the possibility that you get a false over-quota, since the byte > count can include the mbox file twice! This is handled better in > bytesused2() as seen in lmtp.c.diff-no-recurse > Note that this assume the only two files that can exist in the home > directory are the spool file 'username' and > the mbox file produced by the pop3/imap daemon > > Also, note that the quota goes into effect *after* a message has been > delivered. Eg. We have a max msg size in sendmail of 5MB, and a default > mailbox quota of 7.5MB. If the user has 7.49MB, a new message of 5MB will be > accepted; any following message will be denied, since the mailbox size is > now 12.49MB. > -- Isaac Saldana Systems Administrator College of Engineering Department of Electrical Engineering University of California, Riverside