]> git.ipfire.org Git - people/ms/dma.git/commitdiff
flushspool: use O_TRUNC instead of utimes(2)
authorSimon Schubert <2@0x2c.org>
Thu, 25 Jul 2013 21:22:24 +0000 (23:22 +0200)
committerSimon Schubert <2@0x2c.org>
Thu, 25 Jul 2013 21:22:24 +0000 (23:22 +0200)
utimes(2) only works if the file is owned by the current user.  Use
open(..., O_TRUNC|...) instead, together with a group writable flush
file.

Makefile
spool.c

index 02627180c197ea17f233655eec3b43c0d4325b6e..aed2ef7246cf834231a2fa517fa2b1063c002ea0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -67,6 +67,7 @@ install-spool-dirs:
 permissions:
        -${CHGRP} mail ${DESTDIR}${VARMAIL}/*
        -${CHMOD} g+w ${DESTDIR}${VARMAIL}/*
+       -${CHMOD} 660 ${DESTDIR}${DMASPOOL}/flush
 
 install-etc:
        ${INSTALL} -d ${DESTDIR}${CONFDIR}
diff --git a/spool.c b/spool.c
index fa4265401fb6e0fa760848e658071a68697806aa..416b5fa8f0eebeac422623358f00c498674bb4e8 100644 (file)
--- a/spool.c
+++ b/spool.c
@@ -429,18 +429,12 @@ flushqueue_signal(void)
 
         if (asprintf(&flushfn, "%s/%s", config.spooldir, SPOOL_FLUSHFILE) < 0)
                return (-1);
-       fd = open(flushfn, O_CREAT|O_RDONLY, 0440);
+       fd = open(flushfn, O_CREAT|O_WRONLY|O_TRUNC, 0660);
+       free(flushfn);
        if (fd < 0) {
                syslog(LOG_ERR, "could not open flush file: %m");
-               free(flushfn);
                return (-1);
        }
         close(fd);
-        if (utimes(flushfn, NULL) < 0) {
-               syslog(LOG_ERR, "could not touch flush file: %m");
-               free(flushfn);
-               return (-1);
-       }
-       free (flushfn);
        return (0);
 }