]>
git.ipfire.org Git - thirdparty/systemd.git/blob - test/units/testsuite-22.03.sh
3 # Basic tests for types creating/writing files
11 touch /tmp
/file-owned-by-root
16 systemd-tmpfiles
--create - <<EOF
17 f /tmp/f/1 0644 - - - -
18 f /tmp/f/2 0644 - - - This string should be written
21 ### '1' should exist and be empty
22 test -f /tmp
/f
/1; ! test -s /tmp
/f
/1
23 test $
(stat
-c %U
:%G
:%a
/tmp
/f
/1) = "root:root:644"
25 test $
(stat
-c %U
:%G
:%a
/tmp
/f
/2) = "root:root:644"
26 test "$(< /tmp/f/2)" = "This string should be written"
28 ### The perms are supposed to be updated even if the file already exists.
29 systemd-tmpfiles
--create - <<EOF
30 f /tmp/f/1 0666 daemon daemon - This string should not be written
33 # file should be empty
35 test $
(stat
-c %U
:%G
:%a
/tmp
/f
/1) = "daemon:daemon:666"
37 ### But we shouldn't try to set perms on an existing file which is not a
42 ! systemd-tmpfiles
--create - <<EOF
43 f /tmp/f/fifo 0666 daemon daemon - This string should not be written
47 test $
(stat
-c %U
:%G
:%a
/tmp
/f
/fifo
) = "root:root:644"
49 ### 'f' should not follow symlinks.
50 ln -s missing
/tmp
/f
/dangling
51 ln -s /tmp
/file-owned-by-root
/tmp
/f
/symlink
53 ! systemd-tmpfiles
--create - <<EOF
54 f /tmp/f/dangling 0644 daemon daemon - -
55 f /tmp/f/symlink 0644 daemon daemon - -
57 ! test -e /tmp
/f
/missing
58 test $
(stat
-c %U
:%G
:%a
/tmp
/file-owned-by-root
) = "root:root:644"
60 ### Handle read-only filesystem gracefully: we shouldn't fail if the target
61 ### already exists and have the correct perms.
65 touch /tmp
/f
/rw-fs
/foo
66 chmod 644 /tmp
/f
/rw-fs
/foo
68 mount
-o bind,ro
/tmp
/f
/rw-fs
/tmp
/f
/ro-fs
70 systemd-tmpfiles
--create - <<EOF
71 f /tmp/f/ro-fs/foo 0644 - - - - This string should not be written
73 test -f /tmp
/f
/ro-fs
/foo
; ! test -s /tmp
/f
/ro-fs
/foo
75 ! systemd-tmpfiles
--create - <<EOF
76 f /tmp/f/ro-fs/foo 0666 - - - -
78 test $
(stat
-c %U
:%G
:%a
/tmp
/f
/fifo
) = "root:root:644"
80 ! systemd-tmpfiles
--create - <<EOF
81 f /tmp/f/ro-fs/bar 0644 - - - -
83 ! test -e /tmp
/f
/ro-fs
/bar
85 ### 'f' shouldn't follow unsafe paths.
87 ln -s /root
/tmp
/f
/daemon
/unsafe-symlink
88 chown
-R --no-dereference daemon
:daemon
/tmp
/f
/daemon
90 ! systemd-tmpfiles
--create - <<EOF
91 f /tmp/f/daemon/unsafe-symlink/exploit 0644 daemon daemon - -
93 ! test -e /tmp
/f
/daemon
/unsafe-symlink
/exploit
98 echo "This should be truncated" >/tmp
/F
/truncated
99 echo "This should be truncated" >/tmp
/F
/truncated-with-content
101 systemd-tmpfiles
--create - <<EOF
102 F /tmp/F/created 0644 - - - -
103 F /tmp/F/created-with-content 0644 - - - new content
104 F /tmp/F/truncated 0666 daemon daemon - -
105 F /tmp/F/truncated-with-content 0666 daemon daemon - new content
108 test -f /tmp
/F
/created
; ! test -s /tmp
/F
/created
109 test -f /tmp
/F
/created-with-content
110 test "$(< /tmp/F/created-with-content)" = "new content"
111 test -f /tmp
/F
/truncated
; ! test -s /tmp
/F
/truncated
112 test $
(stat
-c %U
:%G
:%a
/tmp
/F
/truncated
) = "daemon:daemon:666"
113 test -s /tmp
/F
/truncated-with-content
114 test $
(stat
-c %U
:%G
:%a
/tmp
/F
/truncated-with-content
) = "daemon:daemon:666"
116 ### We shouldn't try to truncate anything but regular files since the behavior is
117 ### unspecified in the other cases.
120 ! systemd-tmpfiles
--create - <<EOF
121 F /tmp/F/fifo 0644 - - - -
126 ### 'F' should not follow symlinks.
127 ln -s missing
/tmp
/F
/dangling
128 ln -s /tmp
/file-owned-by-root
/tmp
/F
/symlink
130 ! systemd-tmpfiles
--create - <<EOF
131 f /tmp/F/dangling 0644 daemon daemon - -
132 f /tmp/F/symlink 0644 daemon daemon - -
134 ! test -e /tmp
/F
/missing
135 test $
(stat
-c %U
:%G
:%a
/tmp
/file-owned-by-root
) = "root:root:644"
137 ### Handle read-only filesystem gracefully: we shouldn't fail if the target
138 ### already exists and is empty.
142 touch /tmp
/F
/rw-fs
/foo
143 chmod 644 /tmp
/F
/rw-fs
/foo
145 mount
-o bind,ro
/tmp
/F
/rw-fs
/tmp
/F
/ro-fs
147 systemd-tmpfiles
--create - <<EOF
148 F /tmp/F/ro-fs/foo 0644 - - - -
150 test -f /tmp
/F
/ro-fs
/foo
; ! test -s /tmp
/F
/ro-fs
/foo
152 echo "truncating is not allowed anymore" >/tmp
/F
/rw-fs
/foo
153 ! systemd-tmpfiles
--create - <<EOF
154 F /tmp/F/ro-fs/foo 0644 - - - -
157 ! systemd-tmpfiles
--create - <<EOF
158 F /tmp/F/ro-fs/foo 0644 - - - - This string should not be written
160 test -f /tmp
/F
/ro-fs
/foo
; ! test -s /tmp
/F
/ro-fs
/foo
162 # Trying to change the perms should fail.
164 ! systemd-tmpfiles
--create - <<EOF
165 F /tmp/F/ro-fs/foo 0666 - - - -
167 test $
(stat
-c %U
:%G
:%a
/tmp
/F
/ro-fs
/foo
) = "root:root:644"
169 ### Try to create a new file.
170 ! systemd-tmpfiles
--create - <<EOF
171 F /tmp/F/ro-fs/bar 0644 - - - -
173 ! test -e /tmp
/F
/ro-fs
/bar
175 ### 'F' shouldn't follow unsafe paths.
177 ln -s /root
/tmp
/F
/daemon
/unsafe-symlink
178 chown
-R --no-dereference daemon
:daemon
/tmp
/F
/daemon
180 ! systemd-tmpfiles
--create - <<EOF
181 F /tmp/F/daemon/unsafe-symlink/exploit 0644 daemon daemon - -
183 ! test -e /tmp
/F
/daemon
/unsafe-symlink
/exploit
188 touch /tmp
/w
/overwritten
190 ### nop if the target does not exist.
191 systemd-tmpfiles
--create - <<EOF
192 w /tmp/w/unexistent 0644 - - - new content
194 ! test -e /tmp
/w
/unexistent
196 ### no argument given -> fails.
197 ! systemd-tmpfiles
--create - <<EOF
198 w /tmp/w/unexistent 0644 - - - -
201 ### write into an empty file.
202 systemd-tmpfiles
--create - <<EOF
203 w /tmp/w/overwritten 0644 - - - old content
205 test -f /tmp
/w
/overwritten
206 test "$(< /tmp/w/overwritten)" = "old content"
208 ### new content is overwritten
209 systemd-tmpfiles
--create - <<EOF
210 w /tmp/w/overwritten 0644 - - - new content
212 test -f /tmp
/w
/overwritten
213 test "$(< /tmp/w/overwritten)" = "new content"
215 ### writing into an 'exotic' file should be allowed.
216 systemd-tmpfiles
--create - <<EOF
217 w /dev/null - - - - new content
220 ### 'w' follows symlinks
221 ln -s .
/overwritten
/tmp
/w
/symlink
222 systemd-tmpfiles
--create - <<EOF
223 w /tmp/w/symlink - - - - $(readlink -e /tmp/w/symlink)
225 readlink
-e /tmp
/w
/symlink
226 test "$(< /tmp/w/overwritten)" = "/tmp/w/overwritten"
228 ### 'w' shouldn't follow unsafe paths.
230 ln -s /root
/tmp
/w
/daemon
/unsafe-symlink
231 chown
-R --no-dereference daemon
:daemon
/tmp
/w
/daemon
233 ! systemd-tmpfiles
--create - <<EOF
234 f /tmp/w/daemon/unsafe-symlink/exploit 0644 daemon daemon - -
236 ! test -e /tmp
/w
/daemon
/unsafe-symlink
/exploit