mirror of
https://github.com/troglobit/finit.git
synced 2026-11-23 20:11:44 +00:00
A mode with a prefix was not read as a number, so the entry was taken
to have no mode, and a user with one was looked up with the colon in
the name, which skipped the entry:
d /var/lib/app :0750 :app :app
With : the mode, user, or group is only set on a path the entry
creates, an existing one keeps what it has. With ~ the mode loses
read, write, or execute when no one has that on the existing path,
and setuid, setgid, and sticky when it is not a directory.
Mode and owner now go through perm_set() in tmpfiles, which knows the
entry created the path or not.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
66 lines
2.0 KiB
Bash
Executable File
66 lines
2.0 KiB
Bash
Executable File
#!/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" <<CONF
|
|
d $DIR/user 0755 nosuchuser
|
|
f $DIR/file 0644 nosuchuser
|
|
d $DIR/group 0750 bin nosuchgroup
|
|
CONF
|
|
run "/libexec/finit/tmpfiles --create $CONF"
|
|
assert "Only the entry with a known user is created" "$(texec ls $DIR)" = "group"
|
|
assert "With its mode and user" "$(texec stat -c '%a %U:%G' $DIR/group)" = "750 bin:root"
|
|
|
|
sep
|
|
say 'With : mode and owner are only for a path the entry creates'
|
|
run "rm -rf $DIR; mkdir $DIR; chmod 1777 $DIR"
|
|
assert_perm "d $DIR :0700 :bin :bin" 1777 root:root
|
|
run "rmdir $DIR"
|
|
assert_perm "d $DIR :0700 :bin :bin" 700 bin:bin
|
|
|
|
sep
|
|
say 'With ~ the mode loses what no one has on the path'
|
|
run "chmod 500 $DIR"
|
|
assert_perm "e $DIR ~0777" 555 bin:bin
|
|
assert_perm "e $DIR :~0700 :sys" 555 bin:bin
|