]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: fix group ownership when Group is set 1320/head
authorRonny Chevalier <chevalier.ronny@gmail.com>
Mon, 21 Sep 2015 13:45:51 +0000 (15:45 +0200)
committerRonny Chevalier <chevalier.ronny@gmail.com>
Mon, 21 Sep 2015 16:14:44 +0000 (18:14 +0200)
When Group is set in the unit, the runtime directories are owned by
this group and not the default group of the user (same for cgroup paths
and standard outputs)

Fix #1231

src/core/execute.c
src/test/test-execute.c
test/exec-runtimedirectory-owner.service [new file with mode: 0644]

index 3c308e3e3e69ee50b516636bbf57f251aa03e1b2..6e14848cd43d163ae83ac47a2181026bcf1ed84b 100644 (file)
@@ -629,15 +629,6 @@ static int enforce_groups(const ExecContext *context, const char *username, gid_
          * we avoid NSS lookups for gid=0. */
 
         if (context->group || username) {
-
-                if (context->group) {
-                        const char *g = context->group;
-
-                        r = get_group_creds(&g, &gid);
-                        if (r < 0)
-                                return r;
-                }
-
                 /* First step, initialize groups from /etc/groups */
                 if (username && gid != 0) {
                         if (initgroups(username, gid) < 0)
@@ -1414,6 +1405,17 @@ static int exec_child(
                 }
         }
 
+        if (context->group) {
+                const char *g = context->group;
+
+                r = get_group_creds(&g, &gid);
+                if (r < 0) {
+                        *exit_status = EXIT_GROUP;
+                        return r;
+                }
+        }
+
+
         /* If a socket is connected to STDIN/STDOUT/STDERR, we
          * must sure to drop O_NONBLOCK */
         if (socket_fd >= 0)
index 60540f8d285e88fba36a72a128446af860f8be0e..dd8ab7dcb8ad8e03f659667a608d7f8bf5b27f68 100644 (file)
@@ -140,6 +140,7 @@ static void test_exec_umask(Manager *m) {
 static void test_exec_runtimedirectory(Manager *m) {
         test(m, "exec-runtimedirectory.service", 0, CLD_EXITED);
         test(m, "exec-runtimedirectory-mode.service", 0, CLD_EXITED);
+        test(m, "exec-runtimedirectory-owner.service", 0, CLD_EXITED);
 }
 
 int main(int argc, char *argv[]) {
diff --git a/test/exec-runtimedirectory-owner.service b/test/exec-runtimedirectory-owner.service
new file mode 100644 (file)
index 0000000..077e08d
--- /dev/null
@@ -0,0 +1,9 @@
+[Unit]
+Description=Test for RuntimeDirectory owner (must not be the default group of the user if Group is set)
+
+[Service]
+ExecStart=/bin/sh -c 'f=/tmp/test-exec_runtimedirectory-owner;g=$(stat -c %G $f); echo "$g"; exit $(test $g = "nobody")'
+Type=oneshot
+Group=nobody
+User=root
+RuntimeDirectory=test-exec_runtimedirectory-owner