masqmail

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 diff
     1.1 --- a/INSTALL	Wed May 30 11:24:33 2012 +0200
     1.2 +++ b/INSTALL	Wed May 30 11:38:03 2012 +0200
     1.3 @@ -55,15 +55,17 @@
     1.4  
     1.5  --with-logdir=LOGDIR
     1.6  sets the directory where masqmail stores its log files. It will be
     1.7 -created if it does not exist. Default is /var/log/masqmail/.
     1.8 +created on program startup if it does not exist. Default is
     1.9 +/var/log/masqmail.
    1.10  
    1.11  --with-spooldir=SPOOLDIR
    1.12  sets the directory where masqmail stores its spool files. It will be
    1.13 -created if it does not exist. Default is /var/spool/masqmail/.
    1.14 +created on program startup if it does not exist. Default is
    1.15 +/var/spool/masqmail.
    1.16  
    1.17  --with-confdir=CONFDIR
    1.18  sets the default configuration directory to CONFDIR, in case you
    1.19 -prefer another location than /etc/masqmail/.
    1.20 +prefer another location than /etc/masqmail.
    1.21  
    1.22  --with-piddir=PIDDIR
    1.23  sets the directory for the pid file of the daemon. The default and usual
     2.1 --- a/Makefile.am	Wed May 30 11:24:33 2012 +0200
     2.2 +++ b/Makefile.am	Wed May 30 11:38:03 2012 +0200
     2.3 @@ -2,18 +2,13 @@
     2.4  
     2.5  SUBDIRS = src man
     2.6  
     2.7 -install-data-local: log_dir spool_dir uid_bit conf_dir tpl_dir doc_dir rmail
     2.8 +install-data-local: uid_bit tpl_dir doc_dir rmail conf_dir
     2.9  
    2.10 -uninstall-local: rm-rmail rm-doc_dir rm-tpl_dir rm-conf_dir rm-spool_dir rm-log_dir
    2.11 -
    2.12 +uninstall-local: rm-rmail rm-doc_dir rm-tpl_dir rm-dirs
    2.13  
    2.14  conf_dir:
    2.15  	install -d $(DESTDIR)@with_confdir@
    2.16  
    2.17 -rm-conf_dir:
    2.18 -	rmdir $(DESTDIR)@with_confdir@  # removes only if empty
    2.19 -
    2.20 -
    2.21  tpl_dir:
    2.22  	install -d $(DESTDIR)@datadir@/masqmail/tpl
    2.23  	cp tpl/* $(DESTDIR)@datadir@/masqmail/tpl
    2.24 @@ -22,7 +17,6 @@
    2.25  rm-tpl_dir:
    2.26  	rm -rf $(DESTDIR)@datadir@/masqmail/
    2.27  
    2.28 -
    2.29  doc_dir:
    2.30  	install -d $(DESTDIR)@docdir@
    2.31  	cp -r docs $(DESTDIR)@docdir@
    2.32 @@ -36,20 +30,10 @@
    2.33  	)
    2.34  	rmdir $(DESTDIR)@docdir@
    2.35  
    2.36 -
    2.37 -log_dir:
    2.38 -	install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_logdir@
    2.39 -
    2.40 -rm-log_dir:
    2.41 -	rmdir $(DESTDIR)@with_logdir@  # removes only if empty
    2.42 -
    2.43 -
    2.44 -spool_dir:
    2.45 -	install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_spooldir@
    2.46 -
    2.47 -rm-spool_dir:
    2.48 -	: # removal fails if the dirs are non-empty
    2.49 -	: # this prevents losing spooled files
    2.50 +rm-dirs:
    2.51 +	: # removes only if empty
    2.52 +	rmdir $(DESTDIR)@with_confdir@
    2.53 +	rmdir $(DESTDIR)@with_logdir@
    2.54  	rmdir $(DESTDIR)@with_spooldir@
    2.55  
    2.56  rmail:
     3.1 --- a/Makefile.in	Wed May 30 11:24:33 2012 +0200
     3.2 +++ b/Makefile.in	Wed May 30 11:38:03 2012 +0200
     3.3 @@ -691,16 +691,13 @@
     3.4  	uninstall uninstall-am uninstall-local
     3.5  
     3.6  
     3.7 -install-data-local: log_dir spool_dir uid_bit conf_dir tpl_dir doc_dir rmail
     3.8 +install-data-local: uid_bit tpl_dir doc_dir rmail conf_dir
     3.9  
    3.10 -uninstall-local: rm-rmail rm-doc_dir rm-tpl_dir rm-conf_dir rm-spool_dir rm-log_dir
    3.11 +uninstall-local: rm-rmail rm-doc_dir rm-tpl_dir rm-dirs
    3.12  
    3.13  conf_dir:
    3.14  	install -d $(DESTDIR)@with_confdir@
    3.15  
    3.16 -rm-conf_dir:
    3.17 -	rmdir $(DESTDIR)@with_confdir@  # removes only if empty
    3.18 -
    3.19  tpl_dir:
    3.20  	install -d $(DESTDIR)@datadir@/masqmail/tpl
    3.21  	cp tpl/* $(DESTDIR)@datadir@/masqmail/tpl
    3.22 @@ -722,18 +719,10 @@
    3.23  	)
    3.24  	rmdir $(DESTDIR)@docdir@
    3.25  
    3.26 -log_dir:
    3.27 -	install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_logdir@
    3.28 -
    3.29 -rm-log_dir:
    3.30 -	rmdir $(DESTDIR)@with_logdir@  # removes only if empty
    3.31 -
    3.32 -spool_dir:
    3.33 -	install -d -o @with_user@ -g @with_group@ $(DESTDIR)@with_spooldir@
    3.34 -
    3.35 -rm-spool_dir:
    3.36 -	: # removal fails if the dirs are non-empty
    3.37 -	: # this prevents losing spooled files
    3.38 +rm-dirs:
    3.39 +	: # removes only if empty
    3.40 +	rmdir $(DESTDIR)@with_confdir@
    3.41 +	rmdir $(DESTDIR)@with_logdir@
    3.42  	rmdir $(DESTDIR)@with_spooldir@
    3.43  
    3.44  rmail:
     4.1 --- a/src/masqmail.c	Wed May 30 11:24:33 2012 +0200
     4.2 +++ b/src/masqmail.c	Wed May 30 11:38:03 2012 +0200
     4.3 @@ -114,9 +114,12 @@
     4.4  	char path[PATH_MAX];
     4.5  	char *cp, *c;
     4.6  	int had_an_error = 0;
     4.7 +	mode_t savedmask;
     4.8  
     4.9  	c = strncpy(path, dir, sizeof(path));
    4.10  
    4.11 +	savedmask = umask(0);
    4.12 +
    4.13  	while (!had_an_error && (c = strchr(c+1, '/'))) {
    4.14  		*c = '\0';
    4.15  		/* Create an outer directory. */
    4.16 @@ -126,7 +129,7 @@
    4.17  			had_an_error = 1;
    4.18  		}
    4.19  		*c = '/';
    4.20 -	}      
    4.21 +	}
    4.22  
    4.23  	/*
    4.24  	** Create the innermost nested subdirectory of the
    4.25 @@ -136,7 +139,8 @@
    4.26  		fprintf(stderr, "unable to create `%s': %s\n",
    4.27  				dir, strerror(errno));
    4.28  		had_an_error = 1;
    4.29 -	}      
    4.30 +	}
    4.31 +	umask(savedmask);
    4.32  
    4.33  	return (had_an_error) ? 0 : 1;
    4.34  }
    4.35 @@ -758,12 +762,15 @@
    4.36  		logwrite(LOG_NOTICE, "Using spool directory `%s' for "
    4.37  				"lock files.\n", conf.spool_dir);
    4.38  		conf.lock_dir = conf.spool_dir;
    4.39 +		makedir_rec(conf.spool_dir, 0755);
    4.40 +		makedir_rec(conf.log_dir, 0755);
    4.41  	} else {
    4.42 -		int olduid, oldgid;
    4.43 -
    4.44 -		set_euidgid(conf.mail_uid, conf.mail_gid, &olduid, &oldgid);
    4.45  		makedir_rec(conf.lock_dir, 0775);
    4.46 -		set_euidgid(olduid, oldgid, NULL, NULL);
    4.47 +		chown(conf.lock_dir, conf.mail_uid, conf.mail_gid);
    4.48 +		makedir_rec(conf.spool_dir, 0755);
    4.49 +		chown(conf.spool_dir, conf.mail_uid, conf.mail_gid);
    4.50 +		makedir_rec(conf.log_dir, 0755);
    4.51 +		chown(conf.log_dir, conf.mail_uid, conf.mail_gid);
    4.52  	}
    4.53  
    4.54  	if (!logopen()) {