Files
finit/test/tmpfiles-acl.sh
T
Joachim Wiberg ce5a08e866 tmpfiles: handle an ACL of any size
An a or A entry for a path with an ACL of more than 32 entries, or one
that would get more, left the path as it was with a warning.  The ACL
was kept in a fixed array.  It is now allocated to the size it needs.

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

89 lines
2.2 KiB
Bash
Executable File

#!/bin/sh
# Verify the a and A entries of tmpfiles, POSIX ACLs. The sysroot has
# no getfacl, so this looks at what an ACL does to the mode: the group
# bits show the mask, and a default ACL replaces the umask for what is
# created in the directory.
set -eu
TEST_DIR=$(dirname "$0")
DIR=/tmp/acl
CONF=/tmp/acl.conf
tmpfiles()
{
run "cat > $CONF"
run "/libexec/finit/tmpfiles --create $CONF"
}
assert_mode()
{
assert "Mode of $1 is $2" "$(texec stat -c %a "$1")" = "$2"
}
test_teardown()
{
say "Running test teardown."
run "rm -rf $DIR $CONF"
}
# shellcheck source=/dev/null
. "$TEST_DIR/lib/setup.sh"
sep
say 'Default ACL on a directory, as in tpm2-tss-fapi.conf'
tmpfiles <<CONF
#Type Path Mode User Group Age Argument
d $DIR/keystore 2775 daemon daemon - -
a+ $DIR/keystore - - - - default:group:daemon:rwx
d $DIR/plain 2775 daemon daemon - -
CONF
run "umask 077; mkdir $DIR/keystore/sub $DIR/plain/sub; touch $DIR/keystore/file"
assert_mode $DIR/plain/sub 2700
assert_mode $DIR/keystore/sub 2775
assert_mode $DIR/keystore/file 664
sep
say 'a+ adds to the ACL of a file, a replaces it'
run "touch $DIR/file; chmod 600 $DIR/file"
tmpfiles <<CONF
a+ $DIR/file - - - - user:daemon:r--
CONF
assert_mode $DIR/file 640
tmpfiles <<CONF
a+ $DIR/file - - - - g:bin:rw-
CONF
assert_mode $DIR/file 660
tmpfiles <<CONF
a $DIR/file - - - - u:sys:--x
CONF
assert_mode $DIR/file 610
tmpfiles <<CONF
a+ $DIR/file - - - - m::r
CONF
assert_mode $DIR/file 640
sep
say 'An ACL can have many entries'
run "touch $DIR/many; chmod 600 $DIR/many"
tmpfiles <<CONF
a $DIR/many - - - - $(seq -s, -f 'u:%g:r' 2000 2039)
CONF
assert_mode $DIR/many 640
tmpfiles <<CONF
a+ $DIR/many - - - - u:2040:-w-
CONF
assert_mode $DIR/many 660
sep
say 'A is recursive, and X is x only for a directory or an executable'
run "mkdir -p $DIR/tree/sub; touch $DIR/tree/sub/file $DIR/tree/sub/prog"
run "chmod 700 $DIR/tree $DIR/tree/sub $DIR/tree/sub/prog; chmod 600 $DIR/tree/sub/file"
tmpfiles <<CONF
A $DIR/tree - - - - u:daemon:rwX
CONF
assert_mode $DIR/tree 770
assert_mode $DIR/tree/sub 770
assert_mode $DIR/tree/sub/prog 770
assert_mode $DIR/tree/sub/file 660