[systemd-commits] 5 commits - TODO man/tmpfiles.d.xml src/tmpfiles tmpfiles.d/systemd.conf tmpfiles.d/var.conf

Lennart Poettering lennart at kemper.freedesktop.org
Wed Jun 11 01:16:41 PDT 2014


 TODO                    |    5 ----
 man/tmpfiles.d.xml      |   16 +++++++++++++
 src/tmpfiles/tmpfiles.c |   55 ++++++++++++++++++++++++++++++------------------
 tmpfiles.d/systemd.conf |    4 +--
 tmpfiles.d/var.conf     |    2 +
 5 files changed, 55 insertions(+), 27 deletions(-)

New commits:
commit e90738c9bbf626be2d7f6a562ed427f4fc3ec238
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jun 11 10:15:51 2014 +0200

    update TODO

diff --git a/TODO b/TODO
index 1d7df40..9a88942 100644
--- a/TODO
+++ b/TODO
@@ -68,10 +68,6 @@ Features:
 
 * sd-event: generate a failure of a default event loop is executed out-of-thread
 
-* add "M" as recursive version of "m" to tmpfiles, then use it for
-  chowning /run/log/journal (but not /var/log/journal), so that we
-  adjust the perms of journal files created before tmpfiles ran.
-
 * expose "Locked" property on logind sesison objects
 
 * add bus api to query unit file's X fields.
@@ -452,7 +448,6 @@ Features:
 
 * nspawn:
   - bind mount read-only the cgroup tree higher than nspawn
-  - nspawn: make it work for dwalsh and shared /usr containers -- tmpfs mounts as command line parameters
   - refuses to boot containers without /etc/machine-id (OK?), and with empty /etc/machine-id (not OK).
   - support taking a btrfs snapshot at startup and dropping it afterwards
 

commit 1b77b581ebc0a9fa7e372930b88e02b28d40f146
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jun 11 10:15:07 2014 +0200

    tmpfiles: don't apply sgid and executable bit to journal files, only the directories they are contained in

diff --git a/tmpfiles.d/systemd.conf b/tmpfiles.d/systemd.conf
index 9554f38..b07d050 100644
--- a/tmpfiles.d/systemd.conf
+++ b/tmpfiles.d/systemd.conf
@@ -21,6 +21,6 @@ d /run/systemd/netif/links 0755 systemd-network systemd-network -
 d /run/systemd/netif/leases 0755 systemd-network systemd-network -
 
 z /var/log/journal 2755 root systemd-journal - -
-Z /var/log/journal/%m 2755 root systemd-journal - -
+Z /var/log/journal/%m ~2755 root systemd-journal - -
 z /run/log/journal 2755 root systemd-journal - -
-Z /run/log/journal/%m 2755 root systemd-journal - -
+Z /run/log/journal/%m ~2755 root systemd-journal - -

commit abef3f91ce5fa9eeffceead885d2d2cabd9f1c96
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jun 11 10:14:07 2014 +0200

    tmpfiles: add ability to mask access mode by pre-existing access mode on files/directories
    
    This way it makes a lot more sense to specify an access mode for "Z"
    lines.

diff --git a/man/tmpfiles.d.xml b/man/tmpfiles.d.xml
index 5d8c2b5..0081a67 100644
--- a/man/tmpfiles.d.xml
+++ b/man/tmpfiles.d.xml
@@ -368,6 +368,22 @@ r! /tmp/.X[0-9]*-lock</programlisting>
                         ignored for <varname>x</varname>,
                         <varname>r</varname>, <varname>R</varname>,
                         <varname>L</varname> lines.</para>
+
+                        <para>Optionally, if prefixed with
+                        <literal>~</literal> the access mode is masked
+                        based on the already set access bits for
+                        existing file or directories: if the existing
+                        file has all executable bits unset then all
+                        executable bits are removed from the new
+                        access mode, too. Similar, if all read bits
+                        are removed from the old access mode they will
+                        be removed from the new access mode too, and
+                        if all write bits are removed, they will be
+                        removed from the new access mode too. In
+                        addition the sticky/suid/gid bit is removed unless
+                        applied to a directory. This
+                        functionality is particularly useful in
+                        conjunction with <varname>Z</varname>.</para>
                 </refsect2>
 
                 <refsect2>
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index b80731d..bb12dd0 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -99,6 +99,7 @@ typedef struct Item {
         bool gid_set:1;
         bool mode_set:1;
         bool age_set:1;
+        bool mask_perms:1;
 
         bool keep_first_level:1;
 
@@ -454,11 +455,29 @@ static int item_set_perms(Item *i, const char *path) {
         assert(path);
 
         /* not using i->path directly because it may be a glob */
-        if (i->mode_set)
-                if (chmod(path, i->mode) < 0) {
+        if (i->mode_set) {
+                mode_t m = i->mode;
+
+                if (i->mask_perms) {
+                        struct stat st;
+
+                        if (stat(path, &st) >= 0) {
+                                if (!(st.st_mode & 0111))
+                                        m &= ~0111;
+                                if (!(st.st_mode & 0222))
+                                        m &= ~0222;
+                                if (!(st.st_mode & 0444))
+                                        m &= ~0444;
+                                if (!S_ISDIR(st.st_mode))
+                                        m &= ~07000; /* remove sticky/sgid/suid bit, unless directory */
+                        }
+                }
+
+                if (chmod(path, m) < 0) {
                         log_error("chmod(%s) failed: %m", path);
                         return -errno;
                 }
+        }
 
         if (i->uid_set || i->gid_set)
                 if (chown(path,
@@ -1056,15 +1075,13 @@ static bool item_equal(Item *a, Item *b) {
 static bool should_include_path(const char *path) {
         char **prefix;
 
-        STRV_FOREACH(prefix, arg_exclude_prefixes) {
+        STRV_FOREACH(prefix, arg_exclude_prefixes)
                 if (path_startswith(path, *prefix))
                         return false;
-        }
 
-        STRV_FOREACH(prefix, arg_include_prefixes) {
+        STRV_FOREACH(prefix, arg_include_prefixes)
                 if (path_startswith(path, *prefix))
                         return true;
-        }
 
         /* no matches, so we should include this path only if we
          * have no whitelist at all */
@@ -1249,9 +1266,15 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
         }
 
         if (mode && !streq(mode, "-")) {
+                const char *mm = mode;
                 unsigned m;
 
-                if (sscanf(mode, "%o", &m) != 1) {
+                if (*mm == '~') {
+                        i->mask_perms = true;
+                        mm++;
+                }
+
+                if (sscanf(mm, "%o", &m) != 1) {
                         log_error("[%s:%u] Invalid mode '%s'.", fname, line, mode);
                         return -ENOENT;
                 }

commit 1ebab2103d8f82822318e708363c0cc2b930289e
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jun 11 09:20:17 2014 +0200

    tmpfiles: if /var is mounted from tmpfs, we should adjust its access mode

diff --git a/tmpfiles.d/var.conf b/tmpfiles.d/var.conf
index 10d2e49..45822e4 100644
--- a/tmpfiles.d/var.conf
+++ b/tmpfiles.d/var.conf
@@ -7,6 +7,8 @@
 
 # See tmpfiles.d(5) for details
 
+d /var 0755 - - -
+
 L /var/run - - - - ../run
 
 d /var/log 0755 - - -

commit 9855d6c7a161a80084cf94faa42333c48cbeac56
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jun 11 09:19:57 2014 +0200

    tmpfiles: remove unnecessary function

diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index c6121bc..b80731d 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -449,17 +449,15 @@ finish:
         return r;
 }
 
-static int item_set_perms_full(Item *i, const char *path, bool ignore_enoent) {
+static int item_set_perms(Item *i, const char *path) {
         assert(i);
         assert(path);
 
         /* not using i->path directly because it may be a glob */
         if (i->mode_set)
                 if (chmod(path, i->mode) < 0) {
-                        if (errno != ENOENT || !ignore_enoent) {
-                                log_error("chmod(%s) failed: %m", path);
-                                return -errno;
-                        }
+                        log_error("chmod(%s) failed: %m", path);
+                        return -errno;
                 }
 
         if (i->uid_set || i->gid_set)
@@ -467,17 +465,11 @@ static int item_set_perms_full(Item *i, const char *path, bool ignore_enoent) {
                           i->uid_set ? i->uid : (uid_t) -1,
                           i->gid_set ? i->gid : (gid_t) -1) < 0) {
 
-                        if (errno != ENOENT || !ignore_enoent) {
-                                log_error("chown(%s) failed: %m", path);
-                                return -errno;
-                        }
+                        log_error("chown(%s) failed: %m", path);
+                        return -errno;
                 }
 
-        return label_fix(path, ignore_enoent, false);
-}
-
-static int item_set_perms(Item *i, const char *path) {
-        return item_set_perms_full(i, path, false);
+        return label_fix(path, false, false);
 }
 
 static int write_one_file(Item *i, const char *path) {



More information about the systemd-commits mailing list