SUMMARY - Quotas on /var/spool/mail on DU 4.0D

From: Jerome M Berkman <jerry_at_uclink.berkeley.edu>
Date: Mon, 11 May 1998 11:40:30 -0700 (PDT)

A while ago I posed the following question:

        Subject: quotas on /var/spool/mail

        We upgraded last month from 4.0B to 4.0D. There was a fix in
        4.0B to make quotas work, even for mail.local, the local delivery
        agent. Without the fix, it just worked for other processes, but
        not mail.local. Our system programmer's can't figure out how to
        apply it or what an equivalent fix is on 4.0D, so now we have
        users with 100 MB mail spools and still receiving more mail.

I got the following answers from the list:

One person cited the fix from the archive which works on DU 4.0B
but is not applicable on DU 4.0D.

We reported it to DEC, and they said they were not updating the
patch to 4.0B because it broke other things.

Several people said to use procmail instead:
Martin Mokrejs <mmokrejs_at_prfdec.natur.cuni.cz>,
Paul A Sand <pas_at_unh.edu>, and
John P.Speno <speno_at_isc.upenn.edu> all

I ended up hacking mail.local to check for quotas. This works better than
relying on the kernel enforcement of quotas. If you are near your
quota and you receive mail which puts you over, with kernel enforcement,
your unused space is filled with a partial message and then the message
bounces. With my hack, the message is immediately bounced. This
means the user can usually still receive small mail messages.

If the user is already at the quota limit, with kernel enforcement,
the system tries to deliver the message. This fails, but it updates
the time stamp of the spool, so the spool is backed up on incremental
backups. With my hack, the spool is not touched so the spool is not
backed up on incrementals.

We also save cpu time and disk I/O by not trying to deliver a message
which can't be delivered.

        - Jerry Berkman, UC Berkeley

=======================================================================

Here is the patch to mail.local as distributed with sendmail-8.8.2:

333a334,338
> /* UCB patch - Jerry B - March, 1998 */
> /* quotas in kernel not working right so enforce here */
>
> if( quota_check( pw->pw_uid, pw->pw_name, fd ) ) return;
>
649c654
< (void) sprintf(fmtbuf, fmt, ap);
---
> 		(void) vsprintf(fmtbuf, fmt, ap);
922a928,995
> 
> 
> /*
>  * UCB addition - Jerry B - March, 1998
>  * quotas in kernel not working right so enforce here
>  *
>  * check if already over quota or message puts account over quota.
>  *	return 0 if ok, or error in checking, 1 if hit quota limit
>  */
> 
> #include <ufs/quota.h>
> 
> quota_check ( uid, logon, fd )
> int uid;
> char *logon;
> int fd;
> {
> 	struct dqblk results;
> 	struct stat stat_info;
> 	int hard;
> 	int cur;
> 	int tmp_blocks;
> 	char quota_err_msg[200];
> 
> 	if( quotactl( "/var/spool/mail",
> 			QCMD(Q_GETQUOTA,USRQUOTA), uid, &results ) ) {
> 		sprintf( quota_err_msg,
> 			"can't get quota info, ppid=%d, %s - quotactl fails, errno=%d",
> 			getppid(), logon, errno );
> 		warn( quota_err_msg );
> 		return(0);
> 	}
> 	hard = results.dqb_bhardlimit/2;
> 	cur = results.dqb_curblocks/2;
> 
> 	/* check if has quota */
> 	if( hard == 0 ) return 0;
> 
> 	/*  check if currently over, or within an allocation unit */
> 	if( cur >= hard - 10 ) {
> 		sprintf( quota_err_msg,
> 			"ppid=%d, %s over quota", getppid(), logon );
> 		eval = EX_UNAVAILABLE;
> 		err( quota_err_msg );
> 		return(1);
> 	}
> 
> 	/* check if message will put user over quota */
> 	if( fstat( fd, &stat_info ) != 0 ) {
> 		sprintf( quota_err_msg, "fstat failed, err=%d", errno );
> 		warn( quota_err_msg );
> 		return(0);
> 	}
> 
> 	/* blocks are 512, even though st_blksize says 8192 */
> 	/* allocation is weird, so use st_size/1024 to get KB instead */
> 	tmp_blocks = stat_info.st_size/1024;
> 
> 	if( cur + tmp_blocks >= hard ) {
> 		sprintf( quota_err_msg,
> 			"ppid=%d, %s: message of %d KB would hit quota",
> 			getppid(), logon, tmp_blocks );
> 		eval = EX_UNAVAILABLE;
> 		err( quota_err_msg );
> 		return(1);
> 	}
> 	return(0);
> }
Received on Mon May 11 1998 - 21:06:22 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:37 NZDT