changeset 425:a19e47ebbb33

Create the spool and log dirs on program startup if missing. They are not anymore created during installation.
author markus schnalke <meillo@marmaro.de>
date Wed, 30 May 2012 11:38:03 +0200
parents 19be3b27df6f
children d48d3622b64f
files INSTALL Makefile.am Makefile.in src/masqmail.c
diffstat 4 files changed, 30 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/INSTALL	Wed May 30 11:24:33 2012 +0200
+++ b/INSTALL	Wed May 30 11:38:03 2012 +0200
@@ -55,15 +55,17 @@
 
 --with-logdir=LOGDIR
 sets the directory where masqmail stores its log files. It will be
-created if it does not exist. Default is /var/log/masqmail/.
+created on program startup if it does not exist. Default is
+/var/log/masqmail.
 
 --with-spooldir=SPOOLDIR
 sets the directory where masqmail stores its spool files. It will be
-created if it does not exist. Default is /var/spool/masqmail/.
+created on program startup if it does not exist. Default is
+/var/spool/masqmail.
 
 --with-confdir=CONFDIR
 sets the default configuration directory to CONFDIR, in case you
-prefer another location than /etc/masqmail/.
+prefer another location than /etc/masqmail.
 
 --with-piddir=PIDDIR
 sets the directory for the pid file of the daemon. The default and usual
--- a/Makefile.am	Wed May 30 11:24:33 2012 +0200
+++ b/Makefile.am	Wed May 30 11:38:03 2012 +0200
@@ -2,18 +2,13 @@
 
 SUBDIRS = src man
 
-install-data-local: log_dir spool_dir uid_bit conf_dir tpl_dir doc_dir rmail
+install-data-local: uid_bit tpl_dir doc_dir rmail conf_dir
 
-uninstall-local: rm-rmail rm-doc_dir rm-tpl_dir rm-conf_dir rm-spool_dir rm-log_dir
-
+uninstall-local: rm-rmail rm-doc_dir rm-tpl_dir rm-dirs
 
 conf_dir:
 	install -d $(DESTDIR)@with_confdir@
 
-rm-conf_dir:
-	rmdir $(DESTDIR)@with_confdir@  # removes only if empty
-
-
 tpl_dir:
 	install -d $(DESTDIR)@datadir@/masqmail/tpl
 	cp tpl/* $(DESTDIR)@datadir@/masqmail/tpl
@@ -22,7 +17,6 @@
 rm-tpl_dir:
 	rm -rf $(DESTDIR)@datadir@/masqmail/
 
-
 doc_dir:
 	install -d $(DESTDIR)@docdir@
 	cp -r docs $(DESTDIR)@docdir@
@@ -36,20 +30,10 @@
 	)
 	rmdir $(DESTDIR)@docdir@
 
-
-log_dir:
-	install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_logdir@
-
-rm-log_dir:
-	rmdir $(DESTDIR)@with_logdir@  # removes only if empty
-
-
-spool_dir:
-	install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_spooldir@
-
-rm-spool_dir:
-	: # removal fails if the dirs are non-empty
-	: # this prevents losing spooled files
+rm-dirs:
+	: # removes only if empty
+	rmdir $(DESTDIR)@with_confdir@
+	rmdir $(DESTDIR)@with_logdir@
 	rmdir $(DESTDIR)@with_spooldir@
 
 rmail:
--- a/Makefile.in	Wed May 30 11:24:33 2012 +0200
+++ b/Makefile.in	Wed May 30 11:38:03 2012 +0200
@@ -691,16 +691,13 @@
 	uninstall uninstall-am uninstall-local
 
 
-install-data-local: log_dir spool_dir uid_bit conf_dir tpl_dir doc_dir rmail
+install-data-local: uid_bit tpl_dir doc_dir rmail conf_dir
 
-uninstall-local: rm-rmail rm-doc_dir rm-tpl_dir rm-conf_dir rm-spool_dir rm-log_dir
+uninstall-local: rm-rmail rm-doc_dir rm-tpl_dir rm-dirs
 
 conf_dir:
 	install -d $(DESTDIR)@with_confdir@
 
-rm-conf_dir:
-	rmdir $(DESTDIR)@with_confdir@  # removes only if empty
-
 tpl_dir:
 	install -d $(DESTDIR)@datadir@/masqmail/tpl
 	cp tpl/* $(DESTDIR)@datadir@/masqmail/tpl
@@ -722,18 +719,10 @@
 	)
 	rmdir $(DESTDIR)@docdir@
 
-log_dir:
-	install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_logdir@
-
-rm-log_dir:
-	rmdir $(DESTDIR)@with_logdir@  # removes only if empty
-
-spool_dir:
-	install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_spooldir@
-
-rm-spool_dir:
-	: # removal fails if the dirs are non-empty
-	: # this prevents losing spooled files
+rm-dirs:
+	: # removes only if empty
+	rmdir $(DESTDIR)@with_confdir@
+	rmdir $(DESTDIR)@with_logdir@
 	rmdir $(DESTDIR)@with_spooldir@
 
 rmail:
--- a/src/masqmail.c	Wed May 30 11:24:33 2012 +0200
+++ b/src/masqmail.c	Wed May 30 11:38:03 2012 +0200
@@ -114,9 +114,12 @@
 	char path[PATH_MAX];
 	char *cp, *c;
 	int had_an_error = 0;
+	mode_t savedmask;
 
 	c = strncpy(path, dir, sizeof(path));
 
+	savedmask = umask(0);
+
 	while (!had_an_error && (c = strchr(c+1, '/'))) {
 		*c = '\0';
 		/* Create an outer directory. */
@@ -126,7 +129,7 @@
 			had_an_error = 1;
 		}
 		*c = '/';
-	}      
+	}
 
 	/*
 	** Create the innermost nested subdirectory of the
@@ -136,7 +139,8 @@
 		fprintf(stderr, "unable to create `%s': %s\n",
 				dir, strerror(errno));
 		had_an_error = 1;
-	}      
+	}
+	umask(savedmask);
 
 	return (had_an_error) ? 0 : 1;
 }
@@ -758,12 +762,15 @@
 		logwrite(LOG_NOTICE, "Using spool directory `%s' for "
 				"lock files.\n", conf.spool_dir);
 		conf.lock_dir = conf.spool_dir;
+		makedir_rec(conf.spool_dir, 0755);
+		makedir_rec(conf.log_dir, 0755);
 	} 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);
+		chown(conf.lock_dir, conf.mail_uid, conf.mail_gid);
+		makedir_rec(conf.spool_dir, 0755);
+		chown(conf.spool_dir, conf.mail_uid, conf.mail_gid);
+		makedir_rec(conf.log_dir, 0755);
+		chown(conf.log_dir, conf.mail_uid, conf.mail_gid);
 	}
 
 	if (!logopen()) {