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>
Several types read the mode and owner of an entry and did nothing
with them. An f entry was skipped when the file was there:
f /var/log/app.log 0640 app adm
This left a file with another mode or owner as it was. The owner of
p, b, and c entries was never set, and their mode was cut by the
umask. C, z, and Z entries had neither applied.
Set them for all of these, Z for everything below the path. Fifos
and device nodes are opened with O_PATH, so nothing is opened for
real. A path that is not what the entry makes, like a directory
where a p entry wants a fifo, is left alone.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
A mode with a prefix was not read as a number, so the entry was taken
to have no mode, and a user with one was looked up with the colon in
the name, which skipped the entry:
d /var/lib/app :0750 :app :app
With : the mode, user, or group is only set on a path the entry
creates, an existing one keeps what it has. With ~ the mode loses
read, write, or execute when no one has that on the existing path,
and setuid, setgid, and sticky when it is not a directory.
Mode and owner now go through perm_set() in tmpfiles, which knows the
entry created the path or not.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
What an unknown user in an entry did depended on the type. A d entry
was skipped, but this one made a file owned by root:
f /run/frr/state 0640 frr frr
The user was looked up in each type on its own, and only d checked
the result.
Look it up once for the entry, and skip the entry when the user is
not known. An unknown group leaves the group of the path as it is,
for a new path that is the group of root, as before. Both are only
reported with --debug, Finit's own files have entries for services
that may not be installed.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
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>
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 9bfbdc6b 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>