tmpfiles: set the owner before the mode

An entry that sets both setuid or setgid and another owner lost the
bit again:

    f /usr/libexec/helper 4755 app app

The mode was set first, and a change of owner drops setuid and setgid
from a file.  A second run put it back, the owner was right by then.

Change the owner first.  A mode that is not in the entry is put back
the same way.  Also, a mode that ~ masks down to 0 is now set, 0 was
taken for no mode.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-11-20 18:03:31 +01:00
1 parent 777ecd77c8
commit 74da582488
2 files changed
+34 -13

No files matched your search

+13
View File
@@ -90,3 +90,16 @@ sep
say 'A p entry leaves a path that is not a fifo alone'
run "echo 'p $DIR/file 0644 root root' > $CONF; /libexec/finit/tmpfiles --create $CONF"
assert "Not a fifo" "$(texec stat -c '%a %U:%G' $DIR/file)" = "600 sys:bin"
sep
say 'Setuid survives a change of owner, and ~ can take every bit'
run "touch $DIR/suid $DIR/none; chmod 4755 $DIR/suid; chmod 111 $DIR/none"
run "cat > $CONF" <<CONF
f $DIR/suid 4755 bin sys
f $DIR/keep - sys bin
f $DIR/none ~0600
CONF
run "touch $DIR/keep; chmod 2755 $DIR/keep; /libexec/finit/tmpfiles --create $CONF"
assert "Mode given" "$(texec stat -c '%a %U:%G' $DIR/suid)" = "4755 bin:sys"
assert "Mode not given" "$(texec stat -c '%a %U:%G' $DIR/keep)" = "2755 sys:bin"
assert "Masked to 0" "$(texec stat -c '%a' $DIR/none)" = "0"