Files
finit/test/conf-groups.sh
T
Joachim Wiberg de73b06415 service: lift the limit of four supplementary groups
A service listing more than four supplementary groups, in extra-groups
or as @user:group,sup1,sup2,..., got only the first four:

    too many supplementary groups, max 4

The names were stored in a fixed array of four.  It was also only
reset when the new configuration listed groups, so groups dropped from
a service lingered until reboot.

Store the list as one string, split when the service starts, and set
it on every (re)registration.  A list longer than 511 characters drops
the name it cuts off, which may otherwise match another group.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-17 06:21:24 +01:00

51 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
# Verify extra-groups sets every listed group on the service, and that
# dropping the setting drops the groups.
set -eu
TEST_DIR=$(dirname "$0")
# Optional argument is the extra-groups list
write_conf()
{
run "echo 'service grp {' > $FINIT_CONF"
run "echo ' group = \"root\"' >> $FINIT_CONF"
if [ -n "${1:-}" ]; then
run "echo ' extra-groups = { $1 }' >> $FINIT_CONF"
fi
run "echo ' command = \"serv -np -i grp\"' >> $FINIT_CONF"
run "echo '}' >> $FINIT_CONF"
}
# Kernel sorts the list, so it compares as a plain string.
assert_groups()
{
pid=$(texec initctl -j status grp | jq .pid)
assert "Service groups == $1" \
"$(texec cat "/proc/$pid/status" | sed -n 's/^Groups:[[:space:]]*//p' | xargs)" = "$1"
}
test_teardown()
{
say "Running test teardown."
run "rm -f $FINIT_CONF"
}
# shellcheck source=/dev/null
. "$TEST_DIR/lib/setup.sh"
say 'Seven extra groups'
write_conf '"daemon", "bin", "sys", "adm", "tty", "disk", "dialout"'
run "initctl reload"
retry 'assert_num_children 1 serv'
retry 'assert_groups "0 1 2 3 4 5 6 20"'
# The running process keeps its groups, the next start drops them
say 'Dropping extra-groups drops the groups'
write_conf
run "initctl reload"
run "initctl restart grp"
retry 'assert_groups "0"'