summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/tmpfiles/tmpfiles.c63
-rwxr-xr-xtest/units/testsuite-22.02.sh30
2 files changed, 64 insertions, 29 deletions
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 586a924cca..54db55ff1f 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -3334,34 +3334,6 @@ static int parse_line(
*invalid_config = true;
return log_syntax(NULL, LOG_ERR, fname, line, SYNTHETIC_ERRNO(EBADMSG), "base64 decoding not supported for copy sources.");
}
-
- if (!i.argument) {
- i.argument = path_join("/usr/share/factory", i.path);
- if (!i.argument)
- return log_oom();
- } else if (!path_is_absolute(i.argument)) {
- *invalid_config = true;
- return log_syntax(NULL, LOG_ERR, fname, line, SYNTHETIC_ERRNO(EBADMSG), "Source path '%s' is not absolute.", i.argument);
-
- }
-
- if (!empty_or_root(arg_root)) {
- char *p;
-
- p = path_join(arg_root, i.argument);
- if (!p)
- return log_oom();
- free_and_replace(i.argument, p);
- }
-
- path_simplify(i.argument);
-
- if (laccess(i.argument, F_OK) == -ENOENT) {
- /* Silently skip over lines where the source file is missing. */
- log_syntax(NULL, LOG_DEBUG, fname, line, 0, "Copy source path '%s' does not exist, skipping line.", i.argument);
- return 0;
- }
-
break;
case CREATE_CHAR_DEVICE:
@@ -3455,6 +3427,41 @@ static int parse_line(
}
}
+ switch (i.type) {
+ case COPY_FILES:
+ if (!i.argument) {
+ i.argument = path_join("/usr/share/factory", i.path);
+ if (!i.argument)
+ return log_oom();
+ } else if (!path_is_absolute(i.argument)) {
+ *invalid_config = true;
+ return log_syntax(NULL, LOG_ERR, fname, line, SYNTHETIC_ERRNO(EBADMSG), "Source path '%s' is not absolute.", i.argument);
+
+ }
+
+ if (!empty_or_root(arg_root)) {
+ char *p;
+
+ p = path_join(arg_root, i.argument);
+ if (!p)
+ return log_oom();
+ free_and_replace(i.argument, p);
+ }
+
+ path_simplify(i.argument);
+
+ if (laccess(i.argument, F_OK) == -ENOENT) {
+ /* Silently skip over lines where the source file is missing. */
+ log_syntax(NULL, LOG_DEBUG, fname, line, 0, "Copy source path '%s' does not exist, skipping line.", i.argument);
+ return 0;
+ }
+
+ break;
+
+ default:
+ break;
+ }
+
if (from_cred) {
if (!i.argument)
return log_syntax(NULL, LOG_ERR, fname, line, SYNTHETIC_ERRNO(EINVAL), "Reading from credential requested, but no credential name specified.");
diff --git a/test/units/testsuite-22.02.sh b/test/units/testsuite-22.02.sh
index 49c55f136b..de28fa7044 100755
--- a/test/units/testsuite-22.02.sh
+++ b/test/units/testsuite-22.02.sh
@@ -97,7 +97,7 @@ test "$(stat -c %U:%G:%a /tmp/e/3/f1)" = "root:root:644"
# 'C'
#
-mkdir /tmp/C/{1,2,3}-origin
+mkdir /tmp/C/{0,1,2,3}-origin
touch /tmp/C/{1,2,3}-origin/f1
chmod 755 /tmp/C/{1,2,3}-origin/f1
@@ -121,3 +121,31 @@ EOF
test "$(stat -c %U:%G:%a /tmp/C/3/f1)" = "root:root:644"
test ! -e /tmp/C/4
+
+# Check that %U expands to 0, both in the path and in the argument.
+home='/tmp/C'
+systemd-tmpfiles --create - <<EOF
+C $home/%U - - - - $home/%U-origin
+EOF
+
+test -d "$home/0"
+
+# Check that %h expands to $home, both in the path and in the argument.
+HOME="$home" \
+systemd-tmpfiles --create - <<EOF
+C %h/5 - - - - %h/3-origin
+EOF
+
+test -f "$home/5/f1"
+
+# Check that %h in the path is expanded, but
+# the result of this expansion is not expanded once again.
+root='/tmp/C/6'
+home='/%U'
+mkdir -p "$root/usr/share/factory$home"
+HOME="$home" \
+systemd-tmpfiles --create --root="$root" - <<EOF
+C %h - - - -
+EOF
+
+test -d "$root$home"