Merge pull request #23021 from fbuihuu/tmpfiles-fix-precedence-with-plus-sign
Tmpfiles fix precedence with plus sign
This commit is contained in:
+1
-1
@@ -1869,7 +1869,7 @@ install_pam() {
|
||||
paths+=(/lib*/security)
|
||||
fi
|
||||
|
||||
for d in /etc/pam.d /etc/security /usr/{etc,lib}/pam.d; do
|
||||
for d in /etc/pam.d /{usr/,}etc/security /usr/{etc,lib}/pam.d; do
|
||||
[ -d "$d" ] && paths+=("$d")
|
||||
done
|
||||
|
||||
|
||||
@@ -186,6 +186,7 @@ test ! -e /tmp/F/daemon/unsafe-symlink/exploit
|
||||
# 'w'
|
||||
#
|
||||
touch /tmp/w/overwritten
|
||||
touch /tmp/w/appended
|
||||
|
||||
### nop if the target does not exist.
|
||||
systemd-tmpfiles --create - <<EOF
|
||||
@@ -205,13 +206,22 @@ EOF
|
||||
test -f /tmp/w/overwritten
|
||||
test "$(< /tmp/w/overwritten)" = "old content"
|
||||
|
||||
### new content is overwritten
|
||||
### old content is overwritten
|
||||
systemd-tmpfiles --create - <<EOF
|
||||
w /tmp/w/overwritten 0644 - - - new content
|
||||
EOF
|
||||
test -f /tmp/w/overwritten
|
||||
test "$(< /tmp/w/overwritten)" = "new content"
|
||||
|
||||
### append lines
|
||||
systemd-tmpfiles --create - <<EOF
|
||||
w+ /tmp/w/appended 0644 - - - 1
|
||||
w+ /tmp/w/appended 0644 - - - 2\n
|
||||
w+ /tmp/w/appended 0644 - - - 3
|
||||
EOF
|
||||
test -f /tmp/w/appended
|
||||
test "$(< /tmp/w/appended)" = "$(echo -ne '12\n3')"
|
||||
|
||||
### writing into an 'exotic' file should be allowed.
|
||||
systemd-tmpfiles --create - <<EOF
|
||||
w /dev/null - - - - new content
|
||||
|
||||
Executable
+75
@@ -0,0 +1,75 @@
|
||||
#!/bin/bash
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
#
|
||||
# Tests for configuration directory and file precedences
|
||||
#
|
||||
set -eux
|
||||
|
||||
rm -f /{usr/lib,etc}/tmpfiles.d/{L,w}-*.conf
|
||||
rm -fr /tmp/precedence/{L,w}
|
||||
|
||||
mkdir -p /{usr/lib,etc}/tmpfiles.d
|
||||
mkdir -p /tmp/precedence/{L,w}
|
||||
|
||||
#
|
||||
# 'L'
|
||||
#
|
||||
ln -s /dev/null /tmp/precedence/L
|
||||
|
||||
# Overwrite the existing symlink
|
||||
cat >/usr/lib/tmpfiles.d/L-z.conf<<EOF
|
||||
L+ /tmp/precedence/L - - - - /usr/lib/tmpfiles.d/L-z.conf
|
||||
EOF
|
||||
|
||||
systemd-tmpfiles --create
|
||||
test "$(readlink /tmp/precedence/L)" = "/usr/lib/tmpfiles.d/L-z.conf"
|
||||
|
||||
# Files in /etc should override those in /usr
|
||||
cat >/etc/tmpfiles.d/L-z.conf<<EOF
|
||||
L+ /tmp/precedence/L - - - - /etc/tmpfiles.d/L-z.conf
|
||||
EOF
|
||||
|
||||
systemd-tmpfiles --create
|
||||
test "$(readlink /tmp/precedence/L)" = "/etc/tmpfiles.d/L-z.conf"
|
||||
|
||||
# /usr/…/L-a.conf has higher prio than /etc/…/L-z.conf
|
||||
cat >/usr/lib/tmpfiles.d/L-a.conf<<EOF
|
||||
L+ /tmp/precedence/L - - - - /usr/lib/tmpfiles.d/L-a.conf
|
||||
EOF
|
||||
|
||||
systemd-tmpfiles --create
|
||||
test "$(readlink /tmp/precedence/L)" = "/usr/lib/tmpfiles.d/L-a.conf"
|
||||
|
||||
# Files in /etc should override those in /usr
|
||||
cat >/etc/tmpfiles.d/L-a.conf<<EOF
|
||||
L+ /tmp/precedence/L - - - - /etc/tmpfiles.d/L-a.conf
|
||||
EOF
|
||||
|
||||
systemd-tmpfiles --create
|
||||
test "$(readlink /tmp/precedence/L)" = "/etc/tmpfiles.d/L-a.conf"
|
||||
|
||||
#
|
||||
# 'w'
|
||||
#
|
||||
touch /tmp/precedence/w/f
|
||||
|
||||
# Multiple configuration files specifying 'w+' for the same path is allowed.
|
||||
for i in a c; do
|
||||
cat >/usr/lib/tmpfiles.d/w-$i.conf<<EOF
|
||||
w+ /tmp/precedence/w/f - - - - /usr/lib/tmpfiles.d/w-$i.conf\n
|
||||
EOF
|
||||
cat >/etc/tmpfiles.d/w-$i.conf<<EOF
|
||||
w+ /tmp/precedence/w/f - - - - /etc/tmpfiles.d/w-$i.conf\n
|
||||
EOF
|
||||
done
|
||||
|
||||
cat >/usr/lib/tmpfiles.d/w-b.conf<<EOF
|
||||
w+ /tmp/precedence/w/f - - - - /usr/lib/tmpfiles.d/w-b.conf\n
|
||||
EOF
|
||||
|
||||
systemd-tmpfiles --create
|
||||
cmp /tmp/precedence/w/f <<EOF
|
||||
/etc/tmpfiles.d/w-a.conf
|
||||
/usr/lib/tmpfiles.d/w-b.conf
|
||||
/etc/tmpfiles.d/w-c.conf
|
||||
EOF
|
||||
Reference in New Issue
Block a user