masqmail

changeset 421:f37384470855

Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup. Moved the lockdir out of the spool dir. (When /var/lock is a ramdisk we do well to have the lock files there.) Added the new configure option --with-lockdir to change that location. Nontheless, if we run_as_user, then lock files are always stored in the spool dir directly. Instead of installing the lockdir and piddir at installation time, we create them on startup time now if they are missing. This is necessary if lockdir or piddir are a tmpfs.
author markus schnalke <meillo@marmaro.de>
date Wed, 30 May 2012 09:38:38 +0200
parents 09da6e72cd30
children bdbedce60247
files INSTALL Makefile.am Makefile.in config.h.in configure configure.ac man/Makefile.in man/masqmail.conf.5 src/Makefile.in src/base64/Makefile.in src/conf.c src/masqmail.c src/md5/Makefile.in
diffstat 13 files changed, 105 insertions(+), 30 deletions(-) [+]
line diff
     1.1 --- a/INSTALL	Tue May 29 22:15:55 2012 +0200
     1.2 +++ b/INSTALL	Wed May 30 09:38:38 2012 +0200
     1.3 @@ -66,9 +66,13 @@
     1.4  prefer another location than /etc/masqmail/.
     1.5  
     1.6  --with-piddir=PIDDIR
     1.7 -sets the default directory for the pid file of the daemon. The usual
     1.8 +sets the directory for the pid file of the daemon. The default and usual
     1.9  location is /var/run, but some GNU/Linux distributions have converted
    1.10 -to /run.
    1.11 +to /run. It gets created on program startup if missing.
    1.12 +
    1.13 +--with-lockdir=LOCKDIR
    1.14 +sets the default directory for lock file for spooled messages. Default
    1.15 +is /var/lock/masqmail. It gets created on program startup if missing.
    1.16  
    1.17  
    1.18  --disable-resolver
    1.19 @@ -102,10 +106,9 @@
    1.20  	drwxr-xr-x 2 mail mail      4096 May 10 12:34 /var/log/masqmail
    1.21  	drwxr-xr-x 5 mail mail      4096 May 10 12:34 /var/spool/masqmail
    1.22  	drwxr-xr-x 2 mail mail      4096 May 10 12:34 /var/spool/masqmail/input
    1.23 -	drwxr-xr-x 2 mail mail      4096 May 10 12:34 /var/spool/masqmail/lock
    1.24  
    1.25  Important are the set-user-id bit for /usr/local/sbin/masqmail and
    1.26 -the permissions of all files.
    1.27 +the ownership of the directories.
    1.28  
    1.29  
    1.30  
     2.1 --- a/Makefile.am	Tue May 29 22:15:55 2012 +0200
     2.2 +++ b/Makefile.am	Wed May 30 09:38:38 2012 +0200
     2.3 @@ -2,9 +2,9 @@
     2.4  
     2.5  SUBDIRS = src man
     2.6  
     2.7 -install-data-local: log_dir spool_dir uid_bit conf_dir tpl_dir pid_dir doc_dir rmail
     2.8 +install-data-local: log_dir spool_dir uid_bit conf_dir tpl_dir doc_dir rmail
     2.9  
    2.10 -uninstall-local: rm-rmail rm-doc_dir rm-tpl_dir rm-conf_dir rm-pid_dir rm-spool_dir rm-log_dir
    2.11 +uninstall-local: rm-rmail rm-doc_dir rm-tpl_dir rm-conf_dir rm-spool_dir rm-log_dir
    2.12  
    2.13  
    2.14  conf_dir:
    2.15 @@ -37,13 +37,6 @@
    2.16  	rmdir $(DESTDIR)@docdir@
    2.17  
    2.18  
    2.19 -pid_dir:
    2.20 -	install -d $(DESTDIR)@with_piddir@
    2.21 -
    2.22 -rm-pid_dir:
    2.23 -	rm -rf $(DESTDIR)@with_piddir@
    2.24 -
    2.25 -
    2.26  log_dir:
    2.27  	install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_logdir@
    2.28  
    2.29 @@ -53,13 +46,11 @@
    2.30  
    2.31  spool_dir:
    2.32  	install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_spooldir@
    2.33 -	install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_spooldir@/lock
    2.34  	install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_spooldir@/input
    2.35  
    2.36  rm-spool_dir:
    2.37  	: # removal fails if the dirs are non-empty
    2.38  	: # this prevents losing spooled files
    2.39 -	rmdir $(DESTDIR)@with_spooldir@/lock
    2.40  	rmdir $(DESTDIR)@with_spooldir@/input
    2.41  	rmdir $(DESTDIR)@with_spooldir@
    2.42  
     3.1 --- a/Makefile.in	Tue May 29 22:15:55 2012 +0200
     3.2 +++ b/Makefile.in	Wed May 30 09:38:38 2012 +0200
     3.3 @@ -199,6 +199,7 @@
     3.4  top_srcdir = @top_srcdir@
     3.5  with_confdir = @with_confdir@
     3.6  with_group = @with_group@
     3.7 +with_lockdir = @with_lockdir@
     3.8  with_logdir = @with_logdir@
     3.9  with_piddir = @with_piddir@
    3.10  with_spooldir = @with_spooldir@
    3.11 @@ -690,9 +691,9 @@
    3.12  	uninstall uninstall-am uninstall-local
    3.13  
    3.14  
    3.15 -install-data-local: log_dir spool_dir uid_bit conf_dir tpl_dir pid_dir doc_dir rmail
    3.16 +install-data-local: log_dir spool_dir uid_bit conf_dir tpl_dir doc_dir rmail
    3.17  
    3.18 -uninstall-local: rm-rmail rm-doc_dir rm-tpl_dir rm-conf_dir rm-pid_dir rm-spool_dir rm-log_dir
    3.19 +uninstall-local: rm-rmail rm-doc_dir rm-tpl_dir rm-conf_dir rm-spool_dir rm-log_dir
    3.20  
    3.21  conf_dir:
    3.22  	install -d $(DESTDIR)@with_confdir@
    3.23 @@ -721,12 +722,6 @@
    3.24  	)
    3.25  	rmdir $(DESTDIR)@docdir@
    3.26  
    3.27 -pid_dir:
    3.28 -	install -d $(DESTDIR)@with_piddir@
    3.29 -
    3.30 -rm-pid_dir:
    3.31 -	rm -rf $(DESTDIR)@with_piddir@
    3.32 -
    3.33  log_dir:
    3.34  	install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_logdir@
    3.35  
    3.36 @@ -735,13 +730,11 @@
    3.37  
    3.38  spool_dir:
    3.39  	install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_spooldir@
    3.40 -	install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_spooldir@/lock
    3.41  	install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_spooldir@/input
    3.42  
    3.43  rm-spool_dir:
    3.44  	: # removal fails if the dirs are non-empty
    3.45  	: # this prevents losing spooled files
    3.46 -	rmdir $(DESTDIR)@with_spooldir@/lock
    3.47  	rmdir $(DESTDIR)@with_spooldir@/input
    3.48  	rmdir $(DESTDIR)@with_spooldir@
    3.49  
     4.1 --- a/config.h.in	Tue May 29 22:15:55 2012 +0200
     4.2 +++ b/config.h.in	Wed May 30 09:38:38 2012 +0200
     4.3 @@ -104,6 +104,9 @@
     4.4  /* Define to 1 if you have the `vprintf' function. */
     4.5  #undef HAVE_VPRINTF
     4.6  
     4.7 +/* The lock file location */
     4.8 +#undef LOCK_DIR
     4.9 +
    4.10  /* The log directory */
    4.11  #undef LOG_DIR
    4.12  
     5.1 --- a/configure	Tue May 29 22:15:55 2012 +0200
     5.2 +++ b/configure	Wed May 30 09:38:38 2012 +0200
     5.3 @@ -606,6 +606,7 @@
     5.4  am__EXEEXT_TRUE
     5.5  LTLIBOBJS
     5.6  LIBOBJS
     5.7 +with_lockdir
     5.8  with_piddir
     5.9  with_confdir
    5.10  with_spooldir
    5.11 @@ -717,6 +718,7 @@
    5.12  with_spooldir
    5.13  with_confdir
    5.14  with_piddir
    5.15 +with_lockdir
    5.16  '
    5.17        ac_precious_vars='build_alias
    5.18  host_alias
    5.19 @@ -1364,6 +1366,7 @@
    5.20    --with-spooldir=DIR     set spool directory /var/spool/masqmail
    5.21    --with-confdir=DIR      directory for configuration /etc/masqmail
    5.22    --with-piddir=DIR       directory for pid files /var/run
    5.23 +  --with-lockdir=DIR      directory for lock files /var/lock/masqmail
    5.24  
    5.25  Some influential environment variables:
    5.26    CC          C compiler command
    5.27 @@ -5310,6 +5313,22 @@
    5.28  
    5.29  
    5.30  
    5.31 +
    5.32 +# Check whether --with-lockdir was given.
    5.33 +if test "${with_lockdir+set}" = set; then :
    5.34 +  withval=$with_lockdir;
    5.35 +else
    5.36 +  with_lockdir='/var/lock/masqmail'
    5.37 +
    5.38 +fi
    5.39 +
    5.40 +
    5.41 +cat >>confdefs.h <<_ACEOF
    5.42 +#define LOCK_DIR "${with_lockdir}"
    5.43 +_ACEOF
    5.44 +
    5.45 +
    5.46 +
    5.47  test "x$prefix" = xNONE && prefix="$ac_default_prefix"
    5.48  
    5.49  
     6.1 --- a/configure.ac	Tue May 29 22:15:55 2012 +0200
     6.2 +++ b/configure.ac	Wed May 30 09:38:38 2012 +0200
     6.3 @@ -197,6 +197,15 @@
     6.4  AC_DEFINE_UNQUOTED(PID_DIR, "${with_piddir}", [The pid file location])
     6.5  AC_SUBST(with_piddir)
     6.6  
     6.7 +dnl dir for lock files
     6.8 +AC_ARG_WITH(lockdir,
     6.9 +	[  --with-lockdir=DIR      directory for lock files [/var/lock/masqmail]],
    6.10 +	,
    6.11 +	with_lockdir='/var/lock/masqmail'
    6.12 +	)
    6.13 +AC_DEFINE_UNQUOTED(LOCK_DIR, "${with_lockdir}", [The lock file location])
    6.14 +AC_SUBST(with_lockdir)
    6.15 +
    6.16  test "x$prefix" = xNONE && prefix="$ac_default_prefix"
    6.17  
    6.18  dnl well, /me/ thought that autoconf should make things _easy_ ... -- oku
     7.1 --- a/man/Makefile.in	Tue May 29 22:15:55 2012 +0200
     7.2 +++ b/man/Makefile.in	Wed May 30 09:38:38 2012 +0200
     7.3 @@ -171,6 +171,7 @@
     7.4  top_srcdir = @top_srcdir@
     7.5  with_confdir = @with_confdir@
     7.6  with_group = @with_group@
     7.7 +with_lockdir = @with_lockdir@
     7.8  with_logdir = @with_logdir@
     7.9  with_piddir = @with_piddir@
    7.10  with_spooldir = @with_spooldir@
     8.1 --- a/man/masqmail.conf.5	Tue May 29 22:15:55 2012 +0200
     8.2 +++ b/man/masqmail.conf.5	Wed May 30 09:38:38 2012 +0200
     8.3 @@ -92,7 +92,7 @@
     8.4  \fBspool_dir = \fIfile\fR
     8.5  
     8.6  The directory where masqmail stores its spool files
     8.7 -(and later also other stuff).
     8.8 +(and lock files if \fIrun_as_user\fP).
     8.9  It must have a subdirectory \fIinput\fR.
    8.10  Masqmail needs read and write permissions for this directory.
    8.11  \fIfile\fR must be an absolute path.
    8.12 @@ -104,8 +104,12 @@
    8.13  
    8.14  The directory where masqmail stores its lock files.
    8.15  Masqmail needs read and write permissions for this directory.
    8.16 -By default it is a directory ``lock'' inside of \fIspool_dir\fP.
    8.17 +The default is \fI/var/lock/masqmail\fR for normal operation.
    8.18  \fIfile\fR must be an absolute path.
    8.19 +The directory is created on startup if yet missing.
    8.20 +
    8.21 +If \fIrun_as_user\fP then lock files are stored in the \fIspool_dir\fP
    8.22 +directly and the \fBlock_dir\fP setting is ignored.
    8.23  
    8.24  .TP
    8.25  \fBhost_name = \fIstring\fR
     9.1 --- a/src/Makefile.in	Tue May 29 22:15:55 2012 +0200
     9.2 +++ b/src/Makefile.in	Wed May 30 09:38:38 2012 +0200
     9.3 @@ -230,6 +230,7 @@
     9.4  top_srcdir = @top_srcdir@
     9.5  with_confdir = @with_confdir@
     9.6  with_group = @with_group@
     9.7 +with_lockdir = @with_lockdir@
     9.8  with_logdir = @with_logdir@
     9.9  with_piddir = @with_piddir@
    9.10  with_spooldir = @with_spooldir@
    10.1 --- a/src/base64/Makefile.in	Tue May 29 22:15:55 2012 +0200
    10.2 +++ b/src/base64/Makefile.in	Wed May 30 09:38:38 2012 +0200
    10.3 @@ -172,6 +172,7 @@
    10.4  top_srcdir = @top_srcdir@
    10.5  with_confdir = @with_confdir@
    10.6  with_group = @with_group@
    10.7 +with_lockdir = @with_lockdir@
    10.8  with_logdir = @with_logdir@
    10.9  with_piddir = @with_piddir@
   10.10  with_spooldir = @with_spooldir@
    11.1 --- a/src/conf.c	Tue May 29 22:15:55 2012 +0200
    11.2 +++ b/src/conf.c	Wed May 30 09:38:38 2012 +0200
    11.3 @@ -405,6 +405,7 @@
    11.4  	conf.localpartcmp = strcmp;
    11.5  	conf.max_defer_time = 86400 * 4;  /* 4 days */
    11.6  	conf.max_msg_size = 0; /* no limit on msg size */
    11.7 +	conf.lock_dir = LOCK_DIR;
    11.8  	conf.spool_dir = SPOOL_DIR;
    11.9  	conf.mail_dir = "/var/mail";
   11.10  
   11.11 @@ -538,9 +539,6 @@
   11.12  	if (!conf.warnmsg_file) {
   11.13  		conf.warnmsg_file = g_strdup(DATA_DIR "/tpl/warnmsg.tpl");
   11.14  	}
   11.15 -	if (!conf.lock_dir) {
   11.16 -		conf.lock_dir = g_strdup_printf("%s/lock/", conf.spool_dir);
   11.17 -	}
   11.18  	if (!conf.mbox_default) {
   11.19  		conf.mbox_default = g_strdup("mbox");
   11.20  	}
    12.1 --- a/src/masqmail.c	Tue May 29 22:15:55 2012 +0200
    12.2 +++ b/src/masqmail.c	Wed May 30 09:38:38 2012 +0200
    12.3 @@ -104,6 +104,43 @@
    12.4  	return NULL;
    12.5  }
    12.6  
    12.7 +/*
    12.8 +** Create any missing directory in pathname `dir'. (Like `mkdir -p'.)
    12.9 +** The code is taken from nmh.
   12.10 +*/
   12.11 +gboolean
   12.12 +makedir_rec(char *dir, int perms)
   12.13 +{
   12.14 +	char path[PATH_MAX];
   12.15 +	char *cp, *c;
   12.16 +	int had_an_error = 0;
   12.17 +
   12.18 +	c = strncpy(path, dir, sizeof(path));
   12.19 +
   12.20 +	while (!had_an_error && (c = strchr(c+1, '/'))) {
   12.21 +		*c = '\0';
   12.22 +		/* Create an outer directory. */
   12.23 +		if (mkdir(path, perms) == -1 && errno != EEXIST) {
   12.24 +			fprintf(stderr, "unable to create `%s': %s\n",
   12.25 +					path, strerror(errno));
   12.26 +			had_an_error = 1;
   12.27 +		}
   12.28 +		*c = '/';
   12.29 +	}      
   12.30 +
   12.31 +	/*
   12.32 +	** Create the innermost nested subdirectory of the
   12.33 +	** path we're being asked to create.
   12.34 +	*/
   12.35 +	if (!had_an_error && mkdir(dir, perms)==-1 && errno != EEXIST) {
   12.36 +		fprintf(stderr, "unable to create `%s': %s\n",
   12.37 +				dir, strerror(errno));
   12.38 +		had_an_error = 1;
   12.39 +	}      
   12.40 +
   12.41 +	return (had_an_error) ? 0 : 1;
   12.42 +}
   12.43 +
   12.44  gboolean
   12.45  write_pidfile(gchar *name)
   12.46  {
   12.47 @@ -146,6 +183,7 @@
   12.48  	}
   12.49  
   12.50  	signal(SIGTERM, sigterm_handler);
   12.51 +	makedir_rec(PID_DIR, 0755);
   12.52  	write_pidfile(PID_DIR "/masqmail.pid");
   12.53  
   12.54  	conf.do_verbose = FALSE;
   12.55 @@ -655,6 +693,7 @@
   12.56  	**  breaking security.
   12.57  	*/
   12.58  	if ((strcmp(conf_file, CONF_FILE) != 0) && (conf.orig_uid != 0)) {
   12.59 +		logwrite(LOG_NOTICE, "Changing to run_as_user.\n");
   12.60  		conf.run_as_user = TRUE;
   12.61  		set_euidgid(conf.orig_uid, conf.orig_gid, NULL, NULL);
   12.62  		if (setgid(conf.orig_gid)) {
   12.63 @@ -715,6 +754,18 @@
   12.64  		}
   12.65  	}
   12.66  
   12.67 +	if (conf.run_as_user) {
   12.68 +		logwrite(LOG_NOTICE, "Using spool directory `%s' for "
   12.69 +				"lock files.\n", conf.spool_dir);
   12.70 +		conf.lock_dir = conf.spool_dir;
   12.71 +	} else {
   12.72 +		int olduid, oldgid;
   12.73 +
   12.74 +		set_euidgid(conf.mail_uid, conf.mail_gid, &olduid, &oldgid);
   12.75 +		makedir_rec(conf.lock_dir, 0775);
   12.76 +		set_euidgid(olduid, oldgid, NULL, NULL);
   12.77 +	}
   12.78 +
   12.79  	if (!logopen()) {
   12.80  		fprintf(stderr, "could not open log file\n");
   12.81  		exit(1);
    13.1 --- a/src/md5/Makefile.in	Tue May 29 22:15:55 2012 +0200
    13.2 +++ b/src/md5/Makefile.in	Wed May 30 09:38:38 2012 +0200
    13.3 @@ -168,6 +168,7 @@
    13.4  top_srcdir = @top_srcdir@
    13.5  with_confdir = @with_confdir@
    13.6  with_group = @with_group@
    13.7 +with_lockdir = @with_lockdir@
    13.8  with_logdir = @with_logdir@
    13.9  with_piddir = @with_piddir@
   13.10  with_spooldir = @with_spooldir@