Files
finit/test/tmpfiles-perm.sh
T
Joachim Wiberg 513f47813e tmpfiles: keep the mode of an existing directory when none is given
A d entry without a mode reset an existing directory to 0755.  On
finix a bare "d /tmp" line took the sticky bit and the write
permission for others off the /tmp mount, so nobody but root could
create files there:

    mkdir -p /tmp/t && chmod 1777 /tmp/t
    echo 'd /tmp/t' > t.conf
    tmpfiles --create t.conf
    stat -c %a /tmp/t

This gave 755.  Commit 3a72d126 made the chmod of an existing
directory work, and it used the 0755 default for a new directory as
the mode to set.

The default is now only for creating the directory.  With no mode in
the entry, dirperm() leaves the mode alone.

Fixes #523

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
(cherry picked from commit 94bdccd2002d8847736743cb31e9b7bd56bdcada)
2026-11-20 17:51:40 +01:00

40 lines
1.0 KiB
Bash
Executable File

#!/bin/sh
# Verify that tmpfiles leaves the mode of an existing directory alone
# when the entry does not give one, 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 its mode when the entry gives none'
run "chmod 1777 $DIR"
assert_perm "d $DIR" 1777 root:root
assert_perm "d $DIR - - -" 1777 root:root
assert_perm "d $DIR 0750" 750 root:root
assert_perm "e $DIR" 750 root:root
assert_perm "d $DIR 1777 root root" 1777 root:root