# HG changeset patch # User markus schnalke # Date 1338363518 -7200 # Node ID f373844708553ebc3c0143575cd5aa487b04678d # Parent 09da6e72cd3037aa7ceb47eeec27f68289af58db 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. diff -r 09da6e72cd30 -r f37384470855 INSTALL --- a/INSTALL Tue May 29 22:15:55 2012 +0200 +++ b/INSTALL Wed May 30 09:38:38 2012 +0200 @@ -66,9 +66,13 @@ prefer another location than /etc/masqmail/. --with-piddir=PIDDIR -sets the default directory for the pid file of the daemon. The usual +sets the directory for the pid file of the daemon. The default and usual location is /var/run, but some GNU/Linux distributions have converted -to /run. +to /run. It gets created on program startup if missing. + +--with-lockdir=LOCKDIR +sets the default directory for lock file for spooled messages. Default +is /var/lock/masqmail. It gets created on program startup if missing. --disable-resolver @@ -102,10 +106,9 @@ drwxr-xr-x 2 mail mail 4096 May 10 12:34 /var/log/masqmail drwxr-xr-x 5 mail mail 4096 May 10 12:34 /var/spool/masqmail drwxr-xr-x 2 mail mail 4096 May 10 12:34 /var/spool/masqmail/input - drwxr-xr-x 2 mail mail 4096 May 10 12:34 /var/spool/masqmail/lock Important are the set-user-id bit for /usr/local/sbin/masqmail and -the permissions of all files. +the ownership of the directories. diff -r 09da6e72cd30 -r f37384470855 Makefile.am --- a/Makefile.am Tue May 29 22:15:55 2012 +0200 +++ b/Makefile.am Wed May 30 09:38:38 2012 +0200 @@ -2,9 +2,9 @@ SUBDIRS = src man -install-data-local: log_dir spool_dir uid_bit conf_dir tpl_dir pid_dir doc_dir rmail +install-data-local: log_dir spool_dir uid_bit conf_dir tpl_dir doc_dir rmail -uninstall-local: rm-rmail rm-doc_dir rm-tpl_dir rm-conf_dir rm-pid_dir rm-spool_dir rm-log_dir +uninstall-local: rm-rmail rm-doc_dir rm-tpl_dir rm-conf_dir rm-spool_dir rm-log_dir conf_dir: @@ -37,13 +37,6 @@ rmdir $(DESTDIR)@docdir@ -pid_dir: - install -d $(DESTDIR)@with_piddir@ - -rm-pid_dir: - rm -rf $(DESTDIR)@with_piddir@ - - log_dir: install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_logdir@ @@ -53,13 +46,11 @@ spool_dir: install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_spooldir@ - install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_spooldir@/lock install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_spooldir@/input rm-spool_dir: : # removal fails if the dirs are non-empty : # this prevents losing spooled files - rmdir $(DESTDIR)@with_spooldir@/lock rmdir $(DESTDIR)@with_spooldir@/input rmdir $(DESTDIR)@with_spooldir@ diff -r 09da6e72cd30 -r f37384470855 Makefile.in --- a/Makefile.in Tue May 29 22:15:55 2012 +0200 +++ b/Makefile.in Wed May 30 09:38:38 2012 +0200 @@ -199,6 +199,7 @@ top_srcdir = @top_srcdir@ with_confdir = @with_confdir@ with_group = @with_group@ +with_lockdir = @with_lockdir@ with_logdir = @with_logdir@ with_piddir = @with_piddir@ with_spooldir = @with_spooldir@ @@ -690,9 +691,9 @@ uninstall uninstall-am uninstall-local -install-data-local: log_dir spool_dir uid_bit conf_dir tpl_dir pid_dir doc_dir rmail +install-data-local: log_dir spool_dir uid_bit conf_dir tpl_dir doc_dir rmail -uninstall-local: rm-rmail rm-doc_dir rm-tpl_dir rm-conf_dir rm-pid_dir rm-spool_dir rm-log_dir +uninstall-local: rm-rmail rm-doc_dir rm-tpl_dir rm-conf_dir rm-spool_dir rm-log_dir conf_dir: install -d $(DESTDIR)@with_confdir@ @@ -721,12 +722,6 @@ ) rmdir $(DESTDIR)@docdir@ -pid_dir: - install -d $(DESTDIR)@with_piddir@ - -rm-pid_dir: - rm -rf $(DESTDIR)@with_piddir@ - log_dir: install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_logdir@ @@ -735,13 +730,11 @@ spool_dir: install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_spooldir@ - install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_spooldir@/lock install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_spooldir@/input rm-spool_dir: : # removal fails if the dirs are non-empty : # this prevents losing spooled files - rmdir $(DESTDIR)@with_spooldir@/lock rmdir $(DESTDIR)@with_spooldir@/input rmdir $(DESTDIR)@with_spooldir@ diff -r 09da6e72cd30 -r f37384470855 config.h.in --- a/config.h.in Tue May 29 22:15:55 2012 +0200 +++ b/config.h.in Wed May 30 09:38:38 2012 +0200 @@ -104,6 +104,9 @@ /* Define to 1 if you have the `vprintf' function. */ #undef HAVE_VPRINTF +/* The lock file location */ +#undef LOCK_DIR + /* The log directory */ #undef LOG_DIR diff -r 09da6e72cd30 -r f37384470855 configure --- a/configure Tue May 29 22:15:55 2012 +0200 +++ b/configure Wed May 30 09:38:38 2012 +0200 @@ -606,6 +606,7 @@ am__EXEEXT_TRUE LTLIBOBJS LIBOBJS +with_lockdir with_piddir with_confdir with_spooldir @@ -717,6 +718,7 @@ with_spooldir with_confdir with_piddir +with_lockdir ' ac_precious_vars='build_alias host_alias @@ -1364,6 +1366,7 @@ --with-spooldir=DIR set spool directory /var/spool/masqmail --with-confdir=DIR directory for configuration /etc/masqmail --with-piddir=DIR directory for pid files /var/run + --with-lockdir=DIR directory for lock files /var/lock/masqmail Some influential environment variables: CC C compiler command @@ -5310,6 +5313,22 @@ + +# Check whether --with-lockdir was given. +if test "${with_lockdir+set}" = set; then : + withval=$with_lockdir; +else + with_lockdir='/var/lock/masqmail' + +fi + + +cat >>confdefs.h <<_ACEOF +#define LOCK_DIR "${with_lockdir}" +_ACEOF + + + test "x$prefix" = xNONE && prefix="$ac_default_prefix" diff -r 09da6e72cd30 -r f37384470855 configure.ac --- a/configure.ac Tue May 29 22:15:55 2012 +0200 +++ b/configure.ac Wed May 30 09:38:38 2012 +0200 @@ -197,6 +197,15 @@ AC_DEFINE_UNQUOTED(PID_DIR, "${with_piddir}", [The pid file location]) AC_SUBST(with_piddir) +dnl dir for lock files +AC_ARG_WITH(lockdir, + [ --with-lockdir=DIR directory for lock files [/var/lock/masqmail]], + , + with_lockdir='/var/lock/masqmail' + ) +AC_DEFINE_UNQUOTED(LOCK_DIR, "${with_lockdir}", [The lock file location]) +AC_SUBST(with_lockdir) + test "x$prefix" = xNONE && prefix="$ac_default_prefix" dnl well, /me/ thought that autoconf should make things _easy_ ... -- oku diff -r 09da6e72cd30 -r f37384470855 man/Makefile.in --- a/man/Makefile.in Tue May 29 22:15:55 2012 +0200 +++ b/man/Makefile.in Wed May 30 09:38:38 2012 +0200 @@ -171,6 +171,7 @@ top_srcdir = @top_srcdir@ with_confdir = @with_confdir@ with_group = @with_group@ +with_lockdir = @with_lockdir@ with_logdir = @with_logdir@ with_piddir = @with_piddir@ with_spooldir = @with_spooldir@ diff -r 09da6e72cd30 -r f37384470855 man/masqmail.conf.5 --- a/man/masqmail.conf.5 Tue May 29 22:15:55 2012 +0200 +++ b/man/masqmail.conf.5 Wed May 30 09:38:38 2012 +0200 @@ -92,7 +92,7 @@ \fBspool_dir = \fIfile\fR The directory where masqmail stores its spool files -(and later also other stuff). +(and lock files if \fIrun_as_user\fP). It must have a subdirectory \fIinput\fR. Masqmail needs read and write permissions for this directory. \fIfile\fR must be an absolute path. @@ -104,8 +104,12 @@ The directory where masqmail stores its lock files. Masqmail needs read and write permissions for this directory. -By default it is a directory ``lock'' inside of \fIspool_dir\fP. +The default is \fI/var/lock/masqmail\fR for normal operation. \fIfile\fR must be an absolute path. +The directory is created on startup if yet missing. + +If \fIrun_as_user\fP then lock files are stored in the \fIspool_dir\fP +directly and the \fBlock_dir\fP setting is ignored. .TP \fBhost_name = \fIstring\fR diff -r 09da6e72cd30 -r f37384470855 src/Makefile.in --- a/src/Makefile.in Tue May 29 22:15:55 2012 +0200 +++ b/src/Makefile.in Wed May 30 09:38:38 2012 +0200 @@ -230,6 +230,7 @@ top_srcdir = @top_srcdir@ with_confdir = @with_confdir@ with_group = @with_group@ +with_lockdir = @with_lockdir@ with_logdir = @with_logdir@ with_piddir = @with_piddir@ with_spooldir = @with_spooldir@ diff -r 09da6e72cd30 -r f37384470855 src/base64/Makefile.in --- a/src/base64/Makefile.in Tue May 29 22:15:55 2012 +0200 +++ b/src/base64/Makefile.in Wed May 30 09:38:38 2012 +0200 @@ -172,6 +172,7 @@ top_srcdir = @top_srcdir@ with_confdir = @with_confdir@ with_group = @with_group@ +with_lockdir = @with_lockdir@ with_logdir = @with_logdir@ with_piddir = @with_piddir@ with_spooldir = @with_spooldir@ diff -r 09da6e72cd30 -r f37384470855 src/conf.c --- a/src/conf.c Tue May 29 22:15:55 2012 +0200 +++ b/src/conf.c Wed May 30 09:38:38 2012 +0200 @@ -405,6 +405,7 @@ conf.localpartcmp = strcmp; conf.max_defer_time = 86400 * 4; /* 4 days */ conf.max_msg_size = 0; /* no limit on msg size */ + conf.lock_dir = LOCK_DIR; conf.spool_dir = SPOOL_DIR; conf.mail_dir = "/var/mail"; @@ -538,9 +539,6 @@ if (!conf.warnmsg_file) { conf.warnmsg_file = g_strdup(DATA_DIR "/tpl/warnmsg.tpl"); } - if (!conf.lock_dir) { - conf.lock_dir = g_strdup_printf("%s/lock/", conf.spool_dir); - } if (!conf.mbox_default) { conf.mbox_default = g_strdup("mbox"); } diff -r 09da6e72cd30 -r f37384470855 src/masqmail.c --- a/src/masqmail.c Tue May 29 22:15:55 2012 +0200 +++ b/src/masqmail.c Wed May 30 09:38:38 2012 +0200 @@ -104,6 +104,43 @@ return NULL; } +/* +** Create any missing directory in pathname `dir'. (Like `mkdir -p'.) +** The code is taken from nmh. +*/ +gboolean +makedir_rec(char *dir, int perms) +{ + char path[PATH_MAX]; + char *cp, *c; + int had_an_error = 0; + + c = strncpy(path, dir, sizeof(path)); + + while (!had_an_error && (c = strchr(c+1, '/'))) { + *c = '\0'; + /* Create an outer directory. */ + if (mkdir(path, perms) == -1 && errno != EEXIST) { + fprintf(stderr, "unable to create `%s': %s\n", + path, strerror(errno)); + had_an_error = 1; + } + *c = '/'; + } + + /* + ** Create the innermost nested subdirectory of the + ** path we're being asked to create. + */ + if (!had_an_error && mkdir(dir, perms)==-1 && errno != EEXIST) { + fprintf(stderr, "unable to create `%s': %s\n", + dir, strerror(errno)); + had_an_error = 1; + } + + return (had_an_error) ? 0 : 1; +} + gboolean write_pidfile(gchar *name) { @@ -146,6 +183,7 @@ } signal(SIGTERM, sigterm_handler); + makedir_rec(PID_DIR, 0755); write_pidfile(PID_DIR "/masqmail.pid"); conf.do_verbose = FALSE; @@ -655,6 +693,7 @@ ** breaking security. */ if ((strcmp(conf_file, CONF_FILE) != 0) && (conf.orig_uid != 0)) { + logwrite(LOG_NOTICE, "Changing to run_as_user.\n"); conf.run_as_user = TRUE; set_euidgid(conf.orig_uid, conf.orig_gid, NULL, NULL); if (setgid(conf.orig_gid)) { @@ -715,6 +754,18 @@ } } + if (conf.run_as_user) { + logwrite(LOG_NOTICE, "Using spool directory `%s' for " + "lock files.\n", conf.spool_dir); + conf.lock_dir = conf.spool_dir; + } else { + int olduid, oldgid; + + set_euidgid(conf.mail_uid, conf.mail_gid, &olduid, &oldgid); + makedir_rec(conf.lock_dir, 0775); + set_euidgid(olduid, oldgid, NULL, NULL); + } + if (!logopen()) { fprintf(stderr, "could not open log file\n"); exit(1); diff -r 09da6e72cd30 -r f37384470855 src/md5/Makefile.in --- a/src/md5/Makefile.in Tue May 29 22:15:55 2012 +0200 +++ b/src/md5/Makefile.in Wed May 30 09:38:38 2012 +0200 @@ -168,6 +168,7 @@ top_srcdir = @top_srcdir@ with_confdir = @with_confdir@ with_group = @with_group@ +with_lockdir = @with_lockdir@ with_logdir = @with_logdir@ with_piddir = @with_piddir@ with_spooldir = @with_spooldir@