2020-03-04 09:35:06 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-10-17 16:13:06 +00:00
|
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
2021-04-09 17:39:41 +00:00
|
|
|
set -eux
|
2019-06-25 08:40:16 +00:00
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
systemd-analyze log-level debug
|
|
|
|
|
2021-07-14 17:22:21 +00:00
|
|
|
function test_directory() {
|
|
|
|
local directory="$1"
|
|
|
|
local path="$2"
|
2019-06-25 08:40:16 +00:00
|
|
|
|
2021-07-14 17:22:21 +00:00
|
|
|
# Set everything up without DynamicUser=1
|
2019-06-25 08:40:16 +00:00
|
|
|
|
2021-07-14 17:22:21 +00:00
|
|
|
systemd-run --wait -p RuntimeDirectoryPreserve=yes -p DynamicUser=0 -p "${directory}"=zzz touch "${path}"/zzz/test
|
|
|
|
systemd-run --wait -p RuntimeDirectoryPreserve=yes -p DynamicUser=0 -p "${directory}"=zzz test -f "${path}"/zzz/test
|
|
|
|
systemd-run --wait -p RuntimeDirectoryPreserve=yes -p DynamicUser=0 -p "${directory}"=zzz -p TemporaryFileSystem="${path}" test -f "${path}"/zzz/test
|
|
|
|
systemd-run --wait -p RuntimeDirectoryPreserve=yes -p DynamicUser=0 -p "${directory}"=zzz:yyy test -f "${path}"/yyy/test
|
|
|
|
systemd-run --wait -p RuntimeDirectoryPreserve=yes -p DynamicUser=0 -p "${directory}"=zzz:xxx -p TemporaryFileSystem="${path}" test -f "${path}"/xxx/test
|
|
|
|
systemd-run --wait -p RuntimeDirectoryPreserve=yes -p DynamicUser=0 -p "${directory}"=zzz:xxx -p TemporaryFileSystem="${path}":ro test -f "${path}"/xxx/test
|
|
|
|
systemd-run --wait -p RuntimeDirectoryPreserve=yes -p DynamicUser=0 -p "${directory}"=zzz test -f "${path}"/zzz/test-missing \
|
|
|
|
&& { echo 'unexpected success'; exit 1; }
|
2019-06-25 08:40:16 +00:00
|
|
|
|
2021-07-14 17:22:21 +00:00
|
|
|
test -d "${path}"/zzz
|
|
|
|
test ! -L "${path}"/zzz
|
|
|
|
test ! -e "${path}"/private/zzz
|
|
|
|
test -f "${path}"/zzz/test
|
|
|
|
test ! -f "${path}"/zzz/test-missing
|
2019-06-25 08:40:16 +00:00
|
|
|
|
2021-07-14 17:22:21 +00:00
|
|
|
# Convert to DynamicUser=1
|
2019-06-25 08:40:16 +00:00
|
|
|
|
2021-07-14 17:22:21 +00:00
|
|
|
systemd-run --wait -p RuntimeDirectoryPreserve=yes -p DynamicUser=1 -p "${directory}"=zzz test -f "${path}"/zzz/test
|
|
|
|
systemd-run --wait -p RuntimeDirectoryPreserve=yes -p DynamicUser=1 -p "${directory}"=zzz -p TemporaryFileSystem="${path}" test -f "${path}"/zzz/test
|
|
|
|
systemd-run --wait -p RuntimeDirectoryPreserve=yes -p DynamicUser=1 -p "${directory}"=zzz:yyy test -f "${path}"/yyy/test
|
|
|
|
systemd-run --wait -p RuntimeDirectoryPreserve=yes -p DynamicUser=1 -p "${directory}"=zzz:xxx -p TemporaryFileSystem="${path}" test -f "${path}"/xxx/test
|
|
|
|
systemd-run --wait -p RuntimeDirectoryPreserve=yes -p DynamicUser=1 -p "${directory}"=zzz:xxx -p TemporaryFileSystem="${path}":ro test -f "${path}"/xxx/test
|
|
|
|
systemd-run --wait -p RuntimeDirectoryPreserve=yes -p DynamicUser=1 -p "${directory}"=zzz test -f "${path}"/zzz/test-missing \
|
|
|
|
&& { echo 'unexpected success'; exit 1; }
|
2019-06-25 08:40:16 +00:00
|
|
|
|
2021-07-14 17:22:21 +00:00
|
|
|
test -L "${path}"/zzz
|
|
|
|
test -L "${path}"/yyy
|
|
|
|
test -d "${path}"/private/zzz
|
|
|
|
test ! -L "${path}"/private/xxx
|
|
|
|
test ! -L "${path}"/xxx
|
2019-06-25 08:40:16 +00:00
|
|
|
|
2021-07-14 17:22:21 +00:00
|
|
|
test -f "${path}"/zzz/test
|
|
|
|
test ! -f "${path}"/zzz/test-missing
|
2019-06-25 08:40:16 +00:00
|
|
|
|
2021-07-14 17:22:21 +00:00
|
|
|
# Convert back
|
2019-06-25 08:40:16 +00:00
|
|
|
|
2021-07-14 17:22:21 +00:00
|
|
|
systemd-run --wait -p RuntimeDirectoryPreserve=yes -p DynamicUser=0 -p "${directory}"=zzz test -f "${path}"/zzz/test
|
|
|
|
systemd-run --wait -p RuntimeDirectoryPreserve=yes -p DynamicUser=0 -p "${directory}"=zzz -p TemporaryFileSystem="${path}" test -f "${path}"/zzz/test
|
|
|
|
systemd-run --wait -p RuntimeDirectoryPreserve=yes -p DynamicUser=0 -p "${directory}"=zzz:yyy test -f "${path}"/yyy/test
|
|
|
|
systemd-run --wait -p RuntimeDirectoryPreserve=yes -p DynamicUser=0 -p "${directory}"=zzz:xxx -p TemporaryFileSystem="${path}" test -f "${path}"/xxx/test
|
|
|
|
systemd-run --wait -p RuntimeDirectoryPreserve=yes -p DynamicUser=0 -p "${directory}=zzz:xxx zzz:xxx2" -p TemporaryFileSystem="${path}" bash -c "test -f ${path}/xxx/test && test -f ${path}/xxx2/test"
|
|
|
|
systemd-run --wait -p RuntimeDirectoryPreserve=yes -p DynamicUser=0 -p "${directory}"=zzz:xxx -p TemporaryFileSystem="${path}":ro test -f "${path}"/xxx/test
|
|
|
|
systemd-run --wait -p RuntimeDirectoryPreserve=yes -p DynamicUser=0 -p "${directory}"=zzz test -f "${path}"/zzz/test-missing \
|
|
|
|
&& { echo 'unexpected success'; exit 1; }
|
|
|
|
|
|
|
|
# Exercise the unit parsing paths too
|
|
|
|
cat >/run/systemd/system/testservice-34.service <<EOF
|
|
|
|
[Service]
|
|
|
|
Type=oneshot
|
|
|
|
TemporaryFileSystem=${path}
|
|
|
|
RuntimeDirectoryPreserve=yes
|
|
|
|
${directory}=zzz:x\:yz zzz:x\:yz2
|
|
|
|
ExecStart=test -f ${path}/x:yz2/test
|
|
|
|
ExecStart=test -f ${path}/x:yz/test
|
|
|
|
ExecStart=test -f ${path}/zzz/test
|
|
|
|
EOF
|
|
|
|
systemctl daemon-reload
|
|
|
|
systemctl start --wait testservice-34.service
|
|
|
|
|
|
|
|
test -d "${path}"/zzz
|
|
|
|
test ! -L "${path}"/xxx
|
|
|
|
test ! -L "${path}"/xxx2
|
|
|
|
test ! -L "${path}"/private/xxx
|
|
|
|
test ! -L "${path}"/private/xxx2
|
|
|
|
test -L "${path}"/yyy
|
|
|
|
test ! -L "${path}"/zzz
|
|
|
|
test ! -e "${path}"/private/zzz
|
|
|
|
test -f "${path}"/zzz/test
|
|
|
|
test ! -f "${path}"/zzz/test-missing
|
|
|
|
test ! -L "${path}"/x:yz
|
|
|
|
test ! -L "${path}"/x:yz2
|
|
|
|
}
|
|
|
|
|
|
|
|
test_directory "StateDirectory" "/var/lib"
|
|
|
|
test_directory "RuntimeDirectory" "/run"
|
|
|
|
test_directory "CacheDirectory" "/var/cache"
|
|
|
|
test_directory "LogsDirectory" "/var/log"
|
2019-06-25 08:40:16 +00:00
|
|
|
|
|
|
|
systemd-analyze log-level info
|
|
|
|
|
2021-04-07 22:09:55 +00:00
|
|
|
echo OK >/testok
|
2019-06-25 08:40:16 +00:00
|
|
|
|
|
|
|
exit 0
|