#!/bin/sh # Verify that tmpfiles leaves the mode and owner of an existing # directory alone when the entry does not give them, issue #523 set -eu TEST_DIR=$(dirname "$0") DIR=/tmp/perm CONF=/tmp/perm.conf # Run tmpfiles with entry $1, then check mode $2 and owner $3 of $DIR assert_perm() { run "echo '$1' > $CONF" run "/libexec/finit/tmpfiles --create $CONF" assert "Entry '$1' gives $2 $3" "$(texec stat -c '%a %U:%G' $DIR)" = "$2 $3" } test_teardown() { say "Running test teardown." run "rm -rf $DIR $CONF" } # shellcheck source=/dev/null . "$TEST_DIR/lib/setup.sh" sep say 'A new directory gets the default mode and owner' assert_perm "d $DIR" 755 root:root sep say 'An existing directory keeps what the entry does not give' run "chmod 1777 $DIR; chown daemon:daemon $DIR" assert_perm "d $DIR" 1777 daemon:daemon assert_perm "d $DIR - - -" 1777 daemon:daemon assert_perm "d $DIR 0750" 750 daemon:daemon assert_perm "d $DIR - bin" 750 bin:daemon assert_perm "d $DIR - - sys" 750 bin:sys assert_perm "e $DIR" 750 bin:sys assert_perm "d $DIR 1777 root root" 1777 root:root sep say 'An unknown user skips the entry, an unknown group only the group' run "cat > $CONF" < $DIR/file; chmod 600 $DIR/file" run "echo 'f $DIR/file 0644 bin sys - new' > $CONF; /libexec/finit/tmpfiles --create $CONF" assert "Mode and owner" "$(texec stat -c '%a %U:%G' $DIR/file)" = "644 bin:sys" assert "Content is kept" "$(texec cat $DIR/file)" = "keep" sep say 'Mode and owner of p, C, z, and Z entries' run "mkdir -p $DIR/tree/sub; touch $DIR/tree/sub/file" run "cat > $CONF" < $CONF; /libexec/finit/tmpfiles --create $CONF" assert "Not a fifo" "$(texec stat -c '%a %U:%G' $DIR/file)" = "600 sys:bin" sep say 'Setuid survives a change of owner, and ~ can take every bit' run "touch $DIR/suid $DIR/none; chmod 4755 $DIR/suid; chmod 111 $DIR/none" run "cat > $CONF" < $CONF" <