Files
finit/test/tmpfiles-perm.sh
T
Joachim Wiberg f95db7e6df tmpfiles: keep the owner of an existing path when none is given
An entry without a user or group, or with "-", made root the owner of
an existing directory or file:

    mkdir -p /tmp/t && chown daemon:daemon /tmp/t
    echo 'd /tmp/t' > t.conf
    tmpfiles --create t.conf
    stat -c %U:%G /tmp/t

This gave root:root.  A missing field was read as "root" when parsing
the entry, the same as if it had been written out.  tmpfiles.d(5)
only adjusts the owner when the entry gives one.

A missing user or group is now -1, and fdperm() looks at the two ids
separately, so "d /tmp/t - - sys" changes the group and keeps the
owner.  mksubsys() and the service directories used uid -1 to skip
the chown altogether, they now pass -1 for the group as well.

Issue #523

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 11:23:36 +01:00

42 lines
1.1 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