#!/bin/sh # Verify tmpfiles --root, which runs on the system below a directory: # its tmpfiles.d files, its users, and its paths set -eu TEST_DIR=$(dirname "$0") ROOT=/tmp/root CONF=/tmp/root.conf assert_stat() { assert "$1 is $2" "$(texec stat -c '%a %u %g' "$ROOT$1")" = "$2" } test_teardown() { say "Running test teardown." run "rm -rf $ROOT $CONF" } # shellcheck source=/dev/null . "$TEST_DIR/lib/setup.sh" run "mkdir -p $ROOT/etc/tmpfiles.d $ROOT/usr/share/factory/etc" run "echo 'app:x:1:1::/:/bin/sh' > $ROOT/etc/passwd" run "echo 'grp:x:2:' > $ROOT/etc/group" run "echo factory > $ROOT/usr/share/factory/etc/issue" run "cat > $ROOT/etc/tmpfiles.d/root.conf" < $CONF" # The leak check of a sanitizer build needs /proc, the root has none tmpfiles() { run "ASAN_OPTIONS=detect_leaks=0 /libexec/finit/tmpfiles --create --root=$ROOT $*" } tmpfiles say 'The tmpfiles.d files, users, and groups are those below the root' assert_stat /var/lib/root-test "750 1 2" assert "File content" "$(texec cat $ROOT/var/lib/root-test/file)" = "inside" assert "No user daemon there" "$(texec sh -c "ls $ROOT | grep -c skipped")" = "0" sep say 'So are the paths, also what a link points to' assert_stat /var/lib/root-test/other "644 0 0" assert_stat /var/lib/root-test/through "640 0 0" assert "Copied from its factory" "$(texec cat $ROOT/etc/issue)" = "factory" assert "No copy from outside it" "$(texec sh -c "ls $ROOT/etc | grep -c outside")" = "0" assert "Nothing outside it" "$(texec sh -c "ls /var/lib | grep -c root-test")" = "0" sep say 'A file on the command line is not below the root' tmpfiles $CONF assert_stat /from/cmdline "711 0 0"