masqmail
diff src/masqmail.c @ 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 | d209b4846f2b |
children | a19e47ebbb33 |
line diff
1.1 --- a/src/masqmail.c Tue May 29 22:15:55 2012 +0200 1.2 +++ b/src/masqmail.c Wed May 30 09:38:38 2012 +0200 1.3 @@ -104,6 +104,43 @@ 1.4 return NULL; 1.5 } 1.6 1.7 +/* 1.8 +** Create any missing directory in pathname `dir'. (Like `mkdir -p'.) 1.9 +** The code is taken from nmh. 1.10 +*/ 1.11 +gboolean 1.12 +makedir_rec(char *dir, int perms) 1.13 +{ 1.14 + char path[PATH_MAX]; 1.15 + char *cp, *c; 1.16 + int had_an_error = 0; 1.17 + 1.18 + c = strncpy(path, dir, sizeof(path)); 1.19 + 1.20 + while (!had_an_error && (c = strchr(c+1, '/'))) { 1.21 + *c = '\0'; 1.22 + /* Create an outer directory. */ 1.23 + if (mkdir(path, perms) == -1 && errno != EEXIST) { 1.24 + fprintf(stderr, "unable to create `%s': %s\n", 1.25 + path, strerror(errno)); 1.26 + had_an_error = 1; 1.27 + } 1.28 + *c = '/'; 1.29 + } 1.30 + 1.31 + /* 1.32 + ** Create the innermost nested subdirectory of the 1.33 + ** path we're being asked to create. 1.34 + */ 1.35 + if (!had_an_error && mkdir(dir, perms)==-1 && errno != EEXIST) { 1.36 + fprintf(stderr, "unable to create `%s': %s\n", 1.37 + dir, strerror(errno)); 1.38 + had_an_error = 1; 1.39 + } 1.40 + 1.41 + return (had_an_error) ? 0 : 1; 1.42 +} 1.43 + 1.44 gboolean 1.45 write_pidfile(gchar *name) 1.46 { 1.47 @@ -146,6 +183,7 @@ 1.48 } 1.49 1.50 signal(SIGTERM, sigterm_handler); 1.51 + makedir_rec(PID_DIR, 0755); 1.52 write_pidfile(PID_DIR "/masqmail.pid"); 1.53 1.54 conf.do_verbose = FALSE; 1.55 @@ -655,6 +693,7 @@ 1.56 ** breaking security. 1.57 */ 1.58 if ((strcmp(conf_file, CONF_FILE) != 0) && (conf.orig_uid != 0)) { 1.59 + logwrite(LOG_NOTICE, "Changing to run_as_user.\n"); 1.60 conf.run_as_user = TRUE; 1.61 set_euidgid(conf.orig_uid, conf.orig_gid, NULL, NULL); 1.62 if (setgid(conf.orig_gid)) { 1.63 @@ -715,6 +754,18 @@ 1.64 } 1.65 } 1.66 1.67 + if (conf.run_as_user) { 1.68 + logwrite(LOG_NOTICE, "Using spool directory `%s' for " 1.69 + "lock files.\n", conf.spool_dir); 1.70 + conf.lock_dir = conf.spool_dir; 1.71 + } else { 1.72 + int olduid, oldgid; 1.73 + 1.74 + set_euidgid(conf.mail_uid, conf.mail_gid, &olduid, &oldgid); 1.75 + makedir_rec(conf.lock_dir, 0775); 1.76 + set_euidgid(olduid, oldgid, NULL, NULL); 1.77 + } 1.78 + 1.79 if (!logopen()) { 1.80 fprintf(stderr, "could not open log file\n"); 1.81 exit(1);