Subject: bin/13729: Home directory delivery patch for mail.local
To: None <gnats-bugs@gnats.netbsd.org>
From: None <cjep@fawlty.net>
List: netbsd-bugs
Date: 08/16/2001 09:52:55
>Number: 13729
>Category: bin
>Synopsis: Home directory delivery patch for mail.local
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Thu Aug 16 01:52:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Chris Pinnock
>Release: NetBSD 1.5.1
>Organization:
Nil
>Environment:
System: NetBSD chris 1.5.1 NetBSD 1.5.1 (ARMADA) #3: Sat Jul 21 10:38:50 BST 2001 cjep@chris:/home/sources/src-1.5/sys/arch/i386/compile/ARMADA i386
>Description:
The attached patch enables home directory delivery (e.g. to
~user/Mailbox rather than /var/mail/user) in mail.local. The
patch includes documentation to get sendmail working with the
new switch added to mail.local. I've also attached a sendmail
prototype file which could be added to src/gnu/usr.sbin/sendmail/cf/cf
as an example. The patch is against 1.5.1 sources.
>How-To-Repeat:
>Fix:
Index: mail.local.8
===================================================================
RCS file: /cvsroot/basesrc/libexec/mail.local/mail.local.8,v
retrieving revision 1.9
diff -u -r1.9 mail.local.8
--- mail.local.8 1998/04/29 08:33:12 1.9
+++ mail.local.8 2001/08/16 08:45:51
@@ -43,6 +43,7 @@
.Nm
.Op Fl l
.Op Fl f Ar from
+.Op Fl h Ar filename
.Ar user ...
.Sh DESCRIPTION
.Nm
@@ -58,9 +59,13 @@
.Bl -tag -width xxxxxxx
.It Fl f Ar from
Specify the sender's name.
+.It Fl h Ar filename
+Specify a filename for home directory delivery (see
+.Sx HOME DIRECTORY DELIVERY
+below).
.It Fl l
Request that
-.Nm username.lock
+.Nm .lock
files be used for locking.
.El
.Pp
@@ -75,8 +80,10 @@
If the
.Op Fl l
flag is specified mailbox locking is done with
+.Nm .lock
+files (for example, with
.Nm username.lock
-files.
+if delivering in the /var/mail directory).
Otherwise, the mailbox is exclusively locked with
.Xr flock 2
while mail is appended.
@@ -88,6 +95,25 @@
The
.Nm
utility exits 0 on success, and >0 if an error occurs.
+.Sh HOME DIRECTORY DELIVERY
+.Pp
+There are circumstances where mail delivery in a user's home
+directory is a better solution to delivery in the /var/mail directory.
+One case is when an administrator requires users' mail files to fall under
+a quota policy in place on home directories.
+The
+.Op Fl h
+flag allows the Mail Transport Agent to specify a file in the user's
+home directory for mail delivery.
+.Pp
+For example, to deliver mail to the file Mailbox in each user's
+homedirectory, you could use the following in your sendmail.mc file
+(before the MAILER(local) declaration):
+.Pp
+.Bd -unfilled -offset indent -compact
+define(`LOCAL_MAILER_PATH', /usr/libexec/mail.local)dnl
+define(`LOCAL_MAILER_ARGS', `mail -h Mailbox $u')dnl
+.Ed
.Sh ENVIRONMENT
.Bl -tag -width indent
.It Ev TZ
Index: mail.local.c
===================================================================
RCS file: /cvsroot/basesrc/libexec/mail.local/mail.local.c,v
retrieving revision 1.16.10.1
diff -u -r1.16.10.1 mail.local.c
--- mail.local.c 2000/10/17 22:41:49 1.16.10.1
+++ mail.local.c 2001/08/16 08:45:52
@@ -66,7 +66,7 @@
#define FATAL 1
#define NOTFATAL 0
-int deliver __P((int, char *, int));
+int deliver __P((int, char *, int, char *));
void err __P((int, const char *, ...))
__attribute__((__format__(__printf__, 2, 3)));
void notifybiff __P((char *));
@@ -82,15 +82,16 @@
struct passwd *pw;
int ch, fd, eval, lockfile = 0;
uid_t uid;
- const char *from;
+ const char *from;
+ char *homefile;
/* use a reasonable umask */
(void) umask(0077);
openlog("mail.local", LOG_PERROR, LOG_MAIL);
- from = NULL;
- while ((ch = getopt(argc, argv, "ldf:r:")) != -1)
+ from = homefile = NULL;
+ while ((ch = getopt(argc, argv, "ldf:r:h:")) != -1)
switch (ch) {
case 'd': /* backward compatible */
break;
@@ -103,6 +104,11 @@
case 'l':
lockfile++;
break;
+ case 'h':
+ if (homefile)
+ err(FATAL, "multiple -h options");
+ homefile = optarg;
+ break;
case '?':
default:
usage();
@@ -125,7 +131,7 @@
fd = store(from);
for (eval = 0; *argv; ++argv)
- eval |= deliver(fd, *argv, lockfile);
+ eval |= deliver(fd, *argv, lockfile, homefile);
exit (eval);
}
@@ -174,10 +180,11 @@
}
int
-deliver(fd, name, lockfile)
+deliver(fd, name, lockfile, homefile)
int fd;
char *name;
int lockfile;
+ char *homefile;
{
struct stat sb;
struct passwd *pw;
@@ -193,12 +200,26 @@
err(NOTFATAL, "unknown name: %s", name);
return(1);
}
+
+ /*
+ * If homefile is non-NULL, we want to deliver to homefile in
+ * the user's home directory.
+ */
- (void)snprintf(path, sizeof path, "%s/%s", _PATH_MAILDIR, name);
+ if (homefile)
+ (void)snprintf(path, sizeof path, "%s/%s", pw->pw_dir,
+ homefile);
+ else
+ (void)snprintf(path, sizeof path, "%s/%s", _PATH_MAILDIR,
+ name);
if (lockfile) {
- (void)snprintf(lpath, sizeof lpath, "%s/%s.lock",
- _PATH_MAILDIR, name);
+ if (homefile)
+ (void)snprintf(lpath, sizeof lpath, "%s/%s.lock",
+ pw->pw_dir, homefile);
+ else
+ (void)snprintf(lpath, sizeof lpath, "%s/%s.lock",
+ _PATH_MAILDIR, name);
if((lfd = open(lpath, O_CREAT|O_WRONLY|O_EXCL,
S_IRUSR|S_IWUSR)) < 0) {
@@ -302,7 +323,7 @@
void
usage()
{
- err(FATAL, "usage: mail.local [-f from] user ...");
+ err(FATAL, "usage: mail.local [-f from] [-h filename] [-l] user ...");
}
#if __STDC__
==========END OF PATCH=======================
netbsd-proto-homedelivery.mc
# $NetBSD: netbsd-proto.mc,v 1.4.2.3 2001/03/09 18:02:13 he Exp $
divert(-1)
#
# Copyright (c) 1994 Adam Glass
# Copyright (c) 1983 Eric P. Allman
# Copyright (c) 1988, 1993
# The Regents of the University of California. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the University of
# California, Berkeley and its contributors.
# 4. Neither the name of the University nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# This is the prototype file for a configuration that supports SMTP
# connections via TCP and some commonly required features. With this
# prototype file, local mail is delivered to ~user/Mailbox rather than
# /var/mail/user.
#
include(`../m4/cf.m4')
VERSIONID(`@(#)netbsd-proto.mc $Revision: 1.4.2.3 $')
OSTYPE(bsd4.4)dnl
define(`LOCAL_MAILER_PATH', /usr/libexec/mail.local)dnl
define(`LOCAL_MAILER_FLAGS', `mail -h Mailbox $u')dnl
MAILER(local)dnl
MAILER(smtp)dnl
define(`confAUTO_REBUILD', True)dnl
FEATURE(genericstable,DATABASE_MAP_TYPE` -o 'MAIL_SETTINGS_DIR`genericstable')
FEATURE(mailertable, DATABASE_MAP_TYPE` -o 'MAIL_SETTINGS_DIR`mailertable')
FEATURE(virtusertable,DATABASE_MAP_TYPE` -o 'MAIL_SETTINGS_DIR`virtusertable')
FEATURE(domaintable, DATABASE_MAP_TYPE` -o 'MAIL_SETTINGS_DIR`domaintable')
FEATURE(access_db, DATABASE_MAP_TYPE` -o 'MAIL_SETTINGS_DIR`access')
FEATURE(`redirect')
# Enable IPv6. IPv6 is marked as optional so the configuration file
# can be used on IPV4-only kernel as well.
DAEMON_OPTIONS(`Family=inet, address=0.0.0.0, Name=MTA')dnl
DAEMON_OPTIONS(`Family=inet6, address=::, Name=MTA6, Modifiers=O')dnl
>Release-Note:
>Audit-Trail:
>Unformatted: