richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
594167
From 87df0601074b024ab591534e0e78b2d1e7013a8d Mon Sep 17 00:00:00 2001
594167
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
594167
Date: Wed, 9 Mar 2022 22:29:19 +0100
594167
Subject: [PATCH] shared/specifier: fix %u/%U/%g/%G when called as unprivileged
594167
 user
594167
MIME-Version: 1.0
594167
Content-Type: text/plain; charset=UTF-8
594167
Content-Transfer-Encoding: 8bit
594167
594167
We would resolve those specifiers to the calling user/group. This is mostly OK
594167
when done in the manager, because the manager generally operates as root
594167
in system mode, and a non-root in user mode. It would still be wrong if
594167
called with --test though. But in systemctl, this would be generally wrong,
594167
since we can call 'systemctl --system' as a normal user, either for testing
594167
or even for actual operation with '--root=…'.
594167
594167
When operating in --global mode, %u/%U/%g/%G should return an error.
594167
594167
The information whether we're operating in system mode, user mode, or global
594167
mode is passed as the data pointer to specifier_group_name(), specifier_user_name(),
594167
specifier_group_id(), specifier_user_id(). We can't use userdata, because
594167
it's already used for other things.
594167
594167
(cherry picked from commit 172e9cc3ee3dcca288d04c744984a9a3b2a0d008)
594167
594167
Related: #2082131
594167
---
594167
 src/core/unit-printf.c        |   4 +-
594167
 src/shared/install-printf.c   |   9 ++-
594167
 src/shared/install-printf.h   |   7 ++-
594167
 src/shared/install.c          |   9 +--
594167
 src/shared/specifier.c        |  52 ++++++++++++++---
594167
 src/shared/specifier.h        |  10 ++--
594167
 src/test/test-load-fragment.c | 101 +++++++++++++++++++---------------
594167
 src/test/test-specifier.c     |   3 +-
594167
 src/tmpfiles/tmpfiles.c       |  53 +++++++++---------
594167
 test/test-systemctl-enable.sh |  11 ++--
594167
 test/test-systemd-tmpfiles.py |   8 +--
594167
 11 files changed, 163 insertions(+), 104 deletions(-)
594167
594167
diff --git a/src/core/unit-printf.c b/src/core/unit-printf.c
594167
index 46c383b841..3086356419 100644
594167
--- a/src/core/unit-printf.c
594167
+++ b/src/core/unit-printf.c
594167
@@ -190,7 +190,7 @@ int unit_name_printf(const Unit *u, const char* format, char **ret) {
594167
 
594167
                 COMMON_SYSTEM_SPECIFIERS,
594167
 
594167
-                COMMON_CREDS_SPECIFIERS,
594167
+                COMMON_CREDS_SPECIFIERS(u->manager->unit_file_scope),
594167
                 {}
594167
         };
594167
 
594167
@@ -256,7 +256,7 @@ int unit_full_printf_full(const Unit *u, const char *format, size_t max_length,
594167
 
594167
                 COMMON_SYSTEM_SPECIFIERS,
594167
 
594167
-                COMMON_CREDS_SPECIFIERS,
594167
+                COMMON_CREDS_SPECIFIERS(u->manager->unit_file_scope),
594167
 
594167
                 COMMON_TMP_SPECIFIERS,
594167
                 {}
594167
diff --git a/src/shared/install-printf.c b/src/shared/install-printf.c
594167
index 6ff4198ac9..963102674b 100644
594167
--- a/src/shared/install-printf.c
594167
+++ b/src/shared/install-printf.c
594167
@@ -103,7 +103,12 @@ static int specifier_last_component(char specifier, const void *data, const char
594167
         return 0;
594167
 }
594167
 
594167
-int install_name_printf(const UnitFileInstallInfo *i, const char *format, const char *root, char **ret) {
594167
+int install_name_printf(
594167
+                UnitFileScope scope,
594167
+                const UnitFileInstallInfo *i,
594167
+                const char *format,
594167
+                const char *root,
594167
+                char **ret) {
594167
         /* This is similar to unit_name_printf() */
594167
 
594167
         const Specifier table[] = {
594167
@@ -115,7 +120,7 @@ int install_name_printf(const UnitFileInstallInfo *i, const char *format, const
594167
 
594167
                 COMMON_SYSTEM_SPECIFIERS,
594167
 
594167
-                COMMON_CREDS_SPECIFIERS,
594167
+                COMMON_CREDS_SPECIFIERS(scope),
594167
                 {}
594167
         };
594167
 
594167
diff --git a/src/shared/install-printf.h b/src/shared/install-printf.h
594167
index 5ca9406797..d2cccdf66d 100644
594167
--- a/src/shared/install-printf.h
594167
+++ b/src/shared/install-printf.h
594167
@@ -4,4 +4,9 @@
594167
 #include "install.h"
594167
 #include "unit-name.h"
594167
 
594167
-int install_name_printf(const UnitFileInstallInfo *i, const char *format, const char *root, char **ret);
594167
+int install_name_printf(
594167
+                UnitFileScope scope,
594167
+                const UnitFileInstallInfo *i,
594167
+                const char *format,
594167
+                const char *root,
594167
+                char **ret);
594167
diff --git a/src/shared/install.c b/src/shared/install.c
594167
index bfdeee48bf..8d82cb6b16 100644
594167
--- a/src/shared/install.c
594167
+++ b/src/shared/install.c
594167
@@ -1160,7 +1160,7 @@ static int config_parse_also(
594167
                 if (r == 0)
594167
                         break;
594167
 
594167
-                r = install_name_printf(info, word, info->root, &printed);
594167
+                r = install_name_printf(ctx->scope, info, word, info->root, &printed);
594167
                 if (r < 0)
594167
                         return log_syntax(unit, LOG_WARNING, filename, line, r,
594167
                                           "Failed to resolve unit name in Also=\"%s\": %m", word);
594167
@@ -1191,6 +1191,7 @@ static int config_parse_default_instance(
594167
                 void *data,
594167
                 void *userdata) {
594167
 
594167
+        InstallContext *ctx = ASSERT_PTR(data);
594167
         UnitFileInstallInfo *info = ASSERT_PTR(userdata);
594167
         _cleanup_free_ char *printed = NULL;
594167
         int r;
594167
@@ -1208,7 +1209,7 @@ static int config_parse_default_instance(
594167
                 return log_syntax(unit, LOG_WARNING, filename, line, 0,
594167
                                   "DefaultInstance= only makes sense for template units, ignoring.");
594167
 
594167
-        r = install_name_printf(info, rvalue, info->root, &printed);
594167
+        r = install_name_printf(ctx->scope, info, rvalue, info->root, &printed);
594167
         if (r < 0)
594167
                 return log_syntax(unit, LOG_WARNING, filename, line, r,
594167
                                   "Failed to resolve instance name in DefaultInstance=\"%s\": %m", rvalue);
594167
@@ -1780,7 +1781,7 @@ static int install_info_symlink_alias(
594167
         STRV_FOREACH(s, info->aliases) {
594167
                 _cleanup_free_ char *alias_path = NULL, *dst = NULL, *dst_updated = NULL;
594167
 
594167
-                q = install_name_printf(info, *s, info->root, &dst);
594167
+                q = install_name_printf(scope, info, *s, info->root, &dst);
594167
                 if (q < 0) {
594167
                         unit_file_changes_add(changes, n_changes, q, *s, NULL);
594167
                         return q;
594167
@@ -1867,7 +1868,7 @@ static int install_info_symlink_wants(
594167
         STRV_FOREACH(s, list) {
594167
                 _cleanup_free_ char *path = NULL, *dst = NULL;
594167
 
594167
-                q = install_name_printf(info, *s, info->root, &dst);
594167
+                q = install_name_printf(scope, info, *s, info->root, &dst);
594167
                 if (q < 0) {
594167
                         unit_file_changes_add(changes, n_changes, q, *s, NULL);
594167
                         return q;
594167
diff --git a/src/shared/specifier.c b/src/shared/specifier.c
594167
index a917378427..ac353a651c 100644
594167
--- a/src/shared/specifier.c
594167
+++ b/src/shared/specifier.c
594167
@@ -21,6 +21,7 @@
594167
 #include "specifier.h"
594167
 #include "string-util.h"
594167
 #include "strv.h"
594167
+#include "unit-file.h"
594167
 #include "user-util.h"
594167
 
594167
 /*
594167
@@ -253,9 +254,15 @@ int specifier_os_image_version(char specifier, const void *data, const char *roo
594167
 }
594167
 
594167
 int specifier_group_name(char specifier, const void *data, const char *root, const void *userdata, char **ret) {
594167
+        UnitFileScope scope = PTR_TO_INT(data);
594167
         char *t;
594167
 
594167
-        t = gid_to_name(getgid());
594167
+        assert(ret);
594167
+
594167
+        if (scope == UNIT_FILE_GLOBAL)
594167
+                return -EINVAL;
594167
+
594167
+        t = gid_to_name(scope == UNIT_FILE_USER ? getgid() : 0);
594167
         if (!t)
594167
                 return -ENOMEM;
594167
 
594167
@@ -264,23 +271,42 @@ int specifier_group_name(char specifier, const void *data, const char *root, con
594167
 }
594167
 
594167
 int specifier_group_id(char specifier, const void *data, const char *root, const void *userdata, char **ret) {
594167
-        if (asprintf(ret, UID_FMT, getgid()) < 0)
594167
+        UnitFileScope scope = PTR_TO_INT(data);
594167
+        gid_t gid;
594167
+
594167
+        assert(ret);
594167
+
594167
+        if (scope == UNIT_FILE_GLOBAL)
594167
+                return -EINVAL;
594167
+
594167
+        gid = scope == UNIT_FILE_USER ? getgid() : 0;
594167
+
594167
+        if (asprintf(ret, UID_FMT, gid) < 0)
594167
                 return -ENOMEM;
594167
 
594167
         return 0;
594167
 }
594167
 
594167
 int specifier_user_name(char specifier, const void *data, const char *root, const void *userdata, char **ret) {
594167
+        UnitFileScope scope = PTR_TO_INT(data);
594167
+        uid_t uid;
594167
         char *t;
594167
 
594167
-        /* If we are UID 0 (root), this will not result in NSS, otherwise it might. This is good, as we want to be able
594167
-         * to run this in PID 1, where our user ID is 0, but where NSS lookups are not allowed.
594167
+        assert(ret);
594167
 
594167
-         * We don't use getusername_malloc() here, because we don't want to look at $USER, to remain consistent with
594167
-         * specifer_user_id() below.
594167
+        if (scope == UNIT_FILE_GLOBAL)
594167
+                return -EINVAL;
594167
+
594167
+        uid = scope == UNIT_FILE_USER ? getuid() : 0;
594167
+
594167
+        /* If we are UID 0 (root), this will not result in NSS, otherwise it might. This is good, as we want
594167
+         * to be able to run this in PID 1, where our user ID is 0, but where NSS lookups are not allowed.
594167
+
594167
+         * We don't use getusername_malloc() here, because we don't want to look at $USER, to remain
594167
+         * consistent with specifer_user_id() below.
594167
          */
594167
 
594167
-        t = uid_to_name(getuid());
594167
+        t = uid_to_name(uid);
594167
         if (!t)
594167
                 return -ENOMEM;
594167
 
594167
@@ -289,7 +315,17 @@ int specifier_user_name(char specifier, const void *data, const char *root, cons
594167
 }
594167
 
594167
 int specifier_user_id(char specifier, const void *data, const char *root, const void *userdata, char **ret) {
594167
-        if (asprintf(ret, UID_FMT, getuid()) < 0)
594167
+        UnitFileScope scope = PTR_TO_INT(data);
594167
+        uid_t uid;
594167
+
594167
+        assert(ret);
594167
+
594167
+        if (scope == UNIT_FILE_GLOBAL)
594167
+                return -EINVAL;
594167
+
594167
+        uid = scope == UNIT_FILE_USER ? getuid() : 0;
594167
+
594167
+        if (asprintf(ret, UID_FMT, uid) < 0)
594167
                 return -ENOMEM;
594167
 
594167
         return 0;
594167
diff --git a/src/shared/specifier.h b/src/shared/specifier.h
594167
index c433ee2d63..3c619a6c8f 100644
594167
--- a/src/shared/specifier.h
594167
+++ b/src/shared/specifier.h
594167
@@ -80,11 +80,11 @@ int specifier_var_tmp_dir(char specifier, const void *data, const char *root, co
594167
         { 'w', specifier_os_version_id,   NULL }, \
594167
         { 'W', specifier_os_variant_id,   NULL }
594167
 
594167
-#define COMMON_CREDS_SPECIFIERS                   \
594167
-        { 'g', specifier_group_name,      NULL }, \
594167
-        { 'G', specifier_group_id,        NULL }, \
594167
-        { 'u', specifier_user_name,       NULL }, \
594167
-        { 'U', specifier_user_id,         NULL }
594167
+#define COMMON_CREDS_SPECIFIERS(scope)                          \
594167
+        { 'g', specifier_group_name,      INT_TO_PTR(scope) },  \
594167
+        { 'G', specifier_group_id,        INT_TO_PTR(scope) },  \
594167
+        { 'u', specifier_user_name,       INT_TO_PTR(scope) },  \
594167
+        { 'U', specifier_user_id,         INT_TO_PTR(scope) }
594167
 
594167
 #define COMMON_TMP_SPECIFIERS                     \
594167
         { 'T', specifier_tmp_dir,         NULL }, \
594167
diff --git a/src/test/test-load-fragment.c b/src/test/test-load-fragment.c
594167
index c579be4150..9df53cec2b 100644
594167
--- a/src/test/test-load-fragment.c
594167
+++ b/src/test/test-load-fragment.c
594167
@@ -526,59 +526,74 @@ TEST(install_printf, .sd_booted = true) {
594167
         assert_se(user = uid_to_name(getuid()));
594167
         assert_se(asprintf(&uid, UID_FMT, getuid()) >= 0);
594167
 
594167
-#define expect(src, pattern, result)                                    \
594167
+#define expect(scope, src, pattern, result)                             \
594167
         do {                                                            \
594167
-                _cleanup_free_ char *t = NULL;                          \
594167
-                _cleanup_free_ char                                     \
594167
-                        *d1 = strdup(i.name),                           \
594167
-                        *d2 = strdup(i.path);                           \
594167
-                assert_se(install_name_printf(&src, pattern, NULL, &t) >= 0 || !result); \
594167
+                _cleanup_free_ char *t = NULL,                          \
594167
+                        *d1 = ASSERT_PTR(strdup(i.name)),               \
594167
+                        *d2 = ASSERT_PTR(strdup(i.path));               \
594167
+                int r = install_name_printf(scope, &src, pattern, NULL, &t); \
594167
+                assert_se(result ? r >= 0 : r < 0);                     \
594167
                 memzero(i.name, strlen(i.name));                        \
594167
                 memzero(i.path, strlen(i.path));                        \
594167
-                assert_se(d1 && d2);                                    \
594167
                 if (result) {                                           \
594167
                         printf("%s\n", t);                              \
594167
                         assert_se(streq(t, result));                    \
594167
-                } else assert_se(t == NULL);                            \
594167
+                } else                                                  \
594167
+                        assert_se(!t);                                  \
594167
                 strcpy(i.name, d1);                                     \
594167
                 strcpy(i.path, d2);                                     \
594167
         } while (false)
594167
 
594167
-        expect(i, "%n", "name.service");
594167
-        expect(i, "%N", "name");
594167
-        expect(i, "%p", "name");
594167
-        expect(i, "%i", "");
594167
-        expect(i, "%j", "name");
594167
-        expect(i, "%g", group);
594167
-        expect(i, "%G", gid);
594167
-        expect(i, "%u", user);
594167
-        expect(i, "%U", uid);
594167
-
594167
-        expect(i, "%m", mid);
594167
-        expect(i, "%b", bid);
594167
-        expect(i, "%H", host);
594167
-
594167
-        expect(i2, "%g", group);
594167
-        expect(i2, "%G", gid);
594167
-        expect(i2, "%u", user);
594167
-        expect(i2, "%U", uid);
594167
-
594167
-        expect(i3, "%n", "name@inst.service");
594167
-        expect(i3, "%N", "name@inst");
594167
-        expect(i3, "%p", "name");
594167
-        expect(i3, "%g", group);
594167
-        expect(i3, "%G", gid);
594167
-        expect(i3, "%u", user);
594167
-        expect(i3, "%U", uid);
594167
-
594167
-        expect(i3, "%m", mid);
594167
-        expect(i3, "%b", bid);
594167
-        expect(i3, "%H", host);
594167
-
594167
-        expect(i4, "%g", group);
594167
-        expect(i4, "%G", gid);
594167
-        expect(i4, "%u", user);
594167
-        expect(i4, "%U", uid);
594167
+        expect(UNIT_FILE_SYSTEM, i, "%n", "name.service");
594167
+        expect(UNIT_FILE_SYSTEM, i, "%N", "name");
594167
+        expect(UNIT_FILE_SYSTEM, i, "%p", "name");
594167
+        expect(UNIT_FILE_SYSTEM, i, "%i", "");
594167
+        expect(UNIT_FILE_SYSTEM, i, "%j", "name");
594167
+        expect(UNIT_FILE_SYSTEM, i, "%g", "root");
594167
+        expect(UNIT_FILE_SYSTEM, i, "%G", "0");
594167
+        expect(UNIT_FILE_SYSTEM, i, "%u", "root");
594167
+        expect(UNIT_FILE_SYSTEM, i, "%U", "0");
594167
+
594167
+        expect(UNIT_FILE_SYSTEM, i, "%m", mid);
594167
+        expect(UNIT_FILE_SYSTEM, i, "%b", bid);
594167
+        expect(UNIT_FILE_SYSTEM, i, "%H", host);
594167
+
594167
+        expect(UNIT_FILE_SYSTEM, i2, "%g", "root");
594167
+        expect(UNIT_FILE_SYSTEM, i2, "%G", "0");
594167
+        expect(UNIT_FILE_SYSTEM, i2, "%u", "root");
594167
+        expect(UNIT_FILE_SYSTEM, i2, "%U", "0");
594167
+
594167
+        expect(UNIT_FILE_USER, i2, "%g", group);
594167
+        expect(UNIT_FILE_USER, i2, "%G", gid);
594167
+        expect(UNIT_FILE_USER, i2, "%u", user);
594167
+        expect(UNIT_FILE_USER, i2, "%U", uid);
594167
+
594167
+        /* gcc-12.0.1-0.9.fc36.x86_64 insist that streq(…, NULL) is called,
594167
+         * even though the call is inside of a conditional where the pointer is checked. :( */
594167
+#pragma GCC diagnostic push
594167
+#pragma GCC diagnostic ignored "-Wnonnull"
594167
+        expect(UNIT_FILE_GLOBAL, i2, "%g", NULL);
594167
+        expect(UNIT_FILE_GLOBAL, i2, "%G", NULL);
594167
+        expect(UNIT_FILE_GLOBAL, i2, "%u", NULL);
594167
+        expect(UNIT_FILE_GLOBAL, i2, "%U", NULL);
594167
+#pragma GCC diagnostic pop
594167
+
594167
+        expect(UNIT_FILE_SYSTEM, i3, "%n", "name@inst.service");
594167
+        expect(UNIT_FILE_SYSTEM, i3, "%N", "name@inst");
594167
+        expect(UNIT_FILE_SYSTEM, i3, "%p", "name");
594167
+        expect(UNIT_FILE_USER, i3, "%g", group);
594167
+        expect(UNIT_FILE_USER, i3, "%G", gid);
594167
+        expect(UNIT_FILE_USER, i3, "%u", user);
594167
+        expect(UNIT_FILE_USER, i3, "%U", uid);
594167
+
594167
+        expect(UNIT_FILE_SYSTEM, i3, "%m", mid);
594167
+        expect(UNIT_FILE_SYSTEM, i3, "%b", bid);
594167
+        expect(UNIT_FILE_SYSTEM, i3, "%H", host);
594167
+
594167
+        expect(UNIT_FILE_USER, i4, "%g", group);
594167
+        expect(UNIT_FILE_USER, i4, "%G", gid);
594167
+        expect(UNIT_FILE_USER, i4, "%u", user);
594167
+        expect(UNIT_FILE_USER, i4, "%U", uid);
594167
 }
594167
 
594167
 static uint64_t make_cap(int cap) {
594167
diff --git a/src/test/test-specifier.c b/src/test/test-specifier.c
594167
index a45d1bd0b9..dd47f0285e 100644
594167
--- a/src/test/test-specifier.c
594167
+++ b/src/test/test-specifier.c
594167
@@ -7,6 +7,7 @@
594167
 #include "string-util.h"
594167
 #include "strv.h"
594167
 #include "tests.h"
594167
+#include "unit-file.h"
594167
 
594167
 static void test_specifier_escape_one(const char *a, const char *b) {
594167
         _cleanup_free_ char *x = NULL;
594167
@@ -45,7 +46,7 @@ TEST(specifier_escape_strv) {
594167
 static const Specifier specifier_table[] = {
594167
         COMMON_SYSTEM_SPECIFIERS,
594167
 
594167
-        COMMON_CREDS_SPECIFIERS,
594167
+        COMMON_CREDS_SPECIFIERS(UNIT_FILE_USER),
594167
         { 'h', specifier_user_home,       NULL },
594167
 
594167
         COMMON_TMP_SPECIFIERS,
594167
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
594167
index fcab51c208..aa7ff73a36 100644
594167
--- a/src/tmpfiles/tmpfiles.c
594167
+++ b/src/tmpfiles/tmpfiles.c
594167
@@ -204,31 +204,6 @@ STATIC_DESTRUCTOR_REGISTER(arg_image, freep);
594167
 static int specifier_machine_id_safe(char specifier, const void *data, const char *root, const void *userdata, char **ret);
594167
 static int specifier_directory(char specifier, const void *data, const char *root, const void *userdata, char **ret);
594167
 
594167
-static const Specifier specifier_table[] = {
594167
-        { 'a', specifier_architecture,    NULL },
594167
-        { 'b', specifier_boot_id,         NULL },
594167
-        { 'B', specifier_os_build_id,     NULL },
594167
-        { 'H', specifier_host_name,       NULL },
594167
-        { 'l', specifier_short_host_name, NULL },
594167
-        { 'm', specifier_machine_id_safe, NULL },
594167
-        { 'o', specifier_os_id,           NULL },
594167
-        { 'v', specifier_kernel_release,  NULL },
594167
-        { 'w', specifier_os_version_id,   NULL },
594167
-        { 'W', specifier_os_variant_id,   NULL },
594167
-
594167
-        { 'h', specifier_user_home,       NULL },
594167
-
594167
-        { 'C', specifier_directory,       UINT_TO_PTR(DIRECTORY_CACHE) },
594167
-        { 'L', specifier_directory,       UINT_TO_PTR(DIRECTORY_LOGS) },
594167
-        { 'S', specifier_directory,       UINT_TO_PTR(DIRECTORY_STATE) },
594167
-        { 't', specifier_directory,       UINT_TO_PTR(DIRECTORY_RUNTIME) },
594167
-
594167
-        COMMON_CREDS_SPECIFIERS,
594167
-
594167
-        COMMON_TMP_SPECIFIERS,
594167
-        {}
594167
-};
594167
-
594167
 static int specifier_machine_id_safe(char specifier, const void *data, const char *root, const void *userdata, char **ret) {
594167
         int r;
594167
 
594167
@@ -2743,7 +2718,7 @@ static bool should_include_path(const char *path) {
594167
         return false;
594167
 }
594167
 
594167
-static int specifier_expansion_from_arg(Item *i) {
594167
+static int specifier_expansion_from_arg(const Specifier *specifier_table, Item *i) {
594167
         int r;
594167
 
594167
         assert(i);
594167
@@ -2951,6 +2926,30 @@ static int parse_line(
594167
         assert(line >= 1);
594167
         assert(buffer);
594167
 
594167
+        const Specifier specifier_table[] = {
594167
+                { 'a', specifier_architecture,    NULL },
594167
+                { 'b', specifier_boot_id,         NULL },
594167
+                { 'B', specifier_os_build_id,     NULL },
594167
+                { 'H', specifier_host_name,       NULL },
594167
+                { 'l', specifier_short_host_name, NULL },
594167
+                { 'm', specifier_machine_id_safe, NULL },
594167
+                { 'o', specifier_os_id,           NULL },
594167
+                { 'v', specifier_kernel_release,  NULL },
594167
+                { 'w', specifier_os_version_id,   NULL },
594167
+                { 'W', specifier_os_variant_id,   NULL },
594167
+
594167
+                { 'h', specifier_user_home,       NULL },
594167
+
594167
+                { 'C', specifier_directory,       UINT_TO_PTR(DIRECTORY_CACHE)   },
594167
+                { 'L', specifier_directory,       UINT_TO_PTR(DIRECTORY_LOGS)    },
594167
+                { 'S', specifier_directory,       UINT_TO_PTR(DIRECTORY_STATE)   },
594167
+                { 't', specifier_directory,       UINT_TO_PTR(DIRECTORY_RUNTIME) },
594167
+
594167
+                COMMON_CREDS_SPECIFIERS(arg_user ? UNIT_FILE_USER : UNIT_FILE_SYSTEM),
594167
+                COMMON_TMP_SPECIFIERS,
594167
+                {}
594167
+        };
594167
+
594167
         r = extract_many_words(
594167
                         &buffer,
594167
                         NULL,
594167
@@ -3155,7 +3154,7 @@ static int parse_line(
594167
         if (!should_include_path(i.path))
594167
                 return 0;
594167
 
594167
-        r = specifier_expansion_from_arg(&i);
594167
+        r = specifier_expansion_from_arg(specifier_table, &i);
594167
         if (r == -ENXIO)
594167
                 return log_unresolvable_specifier(fname, line);
594167
         if (r < 0) {
594167
diff --git a/test/test-systemctl-enable.sh b/test/test-systemctl-enable.sh
594167
index da1fffe944..8ac1342b91 100644
594167
--- a/test/test-systemctl-enable.sh
594167
+++ b/test/test-systemctl-enable.sh
594167
@@ -500,9 +500,10 @@ check_alias t '' && { echo "Expected failure" >&2; exit 1; }
594167
 check_alias T '' && { echo "Expected failure" >&2; exit 1; }
594167
 check_alias V '' && { echo "Expected failure" >&2; exit 1; }
594167
 
594167
-# FIXME: we use the calling user instead of root :(
594167
-check_alias g root || :
594167
-check_alias G 0 || :
594167
+check_alias g root
594167
+check_alias G 0
594167
+check_alias u root
594167
+check_alias U 0
594167
 
594167
 check_alias i ""
594167
 
594167
@@ -521,10 +522,6 @@ check_alias N 'some-some-link6@'
594167
 
594167
 check_alias p 'some-some-link6'
594167
 
594167
-# FIXME: we use the calling user instead of root :(
594167
-check_alias u root || :
594167
-check_alias U 0 || :
594167
-
594167
 check_alias v "$(uname -r)"
594167
 
594167
 check_alias % '%' && { echo "Expected failure because % is not legal in unit name" >&2; exit 1; }
594167
diff --git a/test/test-systemd-tmpfiles.py b/test/test-systemd-tmpfiles.py
594167
index 3376029463..ba42b3fa37 100755
594167
--- a/test/test-systemd-tmpfiles.py
594167
+++ b/test/test-systemd-tmpfiles.py
594167
@@ -98,13 +98,13 @@ def test_valid_specifiers(*, user):
594167
         test_content('f {} - - - - %b', '{}'.format(id128.get_boot().hex), user=user)
594167
     test_content('f {} - - - - %H', '{}'.format(socket.gethostname()), user=user)
594167
     test_content('f {} - - - - %v', '{}'.format(os.uname().release), user=user)
594167
-    test_content('f {} - - - - %U', '{}'.format(os.getuid()), user=user)
594167
-    test_content('f {} - - - - %G', '{}'.format(os.getgid()), user=user)
594167
+    test_content('f {} - - - - %U', '{}'.format(os.getuid() if user else 0), user=user)
594167
+    test_content('f {} - - - - %G', '{}'.format(os.getgid() if user else 0), user=user)
594167
 
594167
-    puser = pwd.getpwuid(os.getuid())
594167
+    puser = pwd.getpwuid(os.getuid() if user else 0)
594167
     test_content('f {} - - - - %u', '{}'.format(puser.pw_name), user=user)
594167
 
594167
-    pgroup = grp.getgrgid(os.getgid())
594167
+    pgroup = grp.getgrgid(os.getgid() if user else 0)
594167
     test_content('f {} - - - - %g', '{}'.format(pgroup.gr_name), user=user)
594167
 
594167
     # Note that %h is the only specifier in which we look the environment,