Commit graph

416 commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek 165bda37ba
Merge pull request #15718 from poettering/tmpfiles-offline
tmpfiles: read /etc/passwd + /etc/group with fgetpwent()/fgetgrent() if --root= is specified
2020-05-08 11:22:19 +02:00
Zbigniew Jędrzejewski-Szmek e97708fa3e Add %l as specifier for the hostname without any domain component
As described in #15603, it is a fairly common setup to use a fqdn as the
configured hostname. But it is often convenient to use just the actual
hostname, i.e. until the first dot. This adds support in tmpfiles, sysusers,
and unit files for %l which expands to that.

Fixes #15603.
2020-05-07 17:36:44 +02:00
Lennart Poettering 7dc6477dc9 sysusers/tmpfiles: use --root=/ as way to force offline operation (i.e. without NSS) 2020-05-07 16:35:20 +02:00
Lennart Poettering a3451c2c4c tmpfiles: optionally, read /etc/passwd + /etc/group without NSS
There are two libc APIs for accessing the user database: NSS/getpwuid(),
and fgetpwent(). if we run in --root= mode (i.e. "offline" mode), let's
use the latter. Otherwise the former. This means tmpfiles can use the
database included in the root environment for chowning, which is a lot
more appropriate.

Fixes: #14806
2020-05-07 16:35:20 +02:00
Frantisek Sumsal e83ef04d97
Merge pull request #15626 from poettering/more-specifiers
tmpfiles,sysusers,pid1: add a bunch of more specifiers
2020-04-29 10:07:12 +02:00
Lennart Poettering dfe01841e6 tmpfiles: remove unnecessary assert
if we parse an xattr line that has no valid assignment, we might end up
with an empty ->xattr list. Don't hit assert on that, just go on.

Fixes: #15610
2020-04-29 00:23:28 +02:00
Lennart Poettering d02933fded tmpfiles: use log_syntax() for all parse errors 2020-04-29 00:23:28 +02:00
Lennart Poettering 268f5a5463 tree-wide: support a bunch of additional specifiers 2020-04-28 22:47:21 +02:00
Lennart Poettering f8606626ed tmpfiles: if we get ENOENT when opening /proc/self/fd/, check if /proc is mounted
let's return ENOSYS in that case, to make things a bit less confusng.

Previously we'd just propagate ENOENT, which people might mistake as
applying to the object being modified rather than /proc/ just not being
there.

Let's return ENOSYS instead, i.e. an error clearly indicating that some
kernel API is not available. This hopefully should put people on a
better track.

Note that we only do the procfs check in the error path, which hopefully
means it's the less likely path.

We probably can add similar bits to more suitable codepaths dealing with
/proc/self/fd, but for now, let's pick to the ones noticed in #14745.

Fixes: #14745
2020-04-23 14:52:10 +02:00
Lennart Poettering 0f7e4b2888 sysusers,tmpfiles: always mention error when failing to replace specifiers 2020-04-23 14:50:07 +02:00
Zbigniew Jędrzejewski-Szmek 51327bcc74 sd-path: rename the two functions
I think the two names were both pretty bad. They did not give a proper hint
what the difference between the two functions is, and sd_path_home sounds like
it is somehow related to /home or home directories or whatever, when in fact
both functions return the same set of paths as either a colon-delimited string
or a strv. "_strv" suffix is used by various functions in sd-bus, so let's
reuse that.

Those functions are not public yet, so let's rename.
2020-03-27 20:12:44 +01:00
Christian Göttsche 80e7c84081 tmpfiles: create with correct MAC label on option C
Closes: #10855
2019-11-28 12:18:04 +01:00
Zbigniew Jędrzejewski-Szmek 9e9dd3e329
Merge pull request #13862 from zachsmith/systemd-tmpfiles-deprecate-for-force
systemd-tmpfiles: deprecate F for f+
2019-11-12 10:28:59 +01:00
Yu Watanabe 1405cb653a tree-wide: drop stdio.h when stdio-util.h is included 2019-11-04 00:30:32 +09:00
Yu Watanabe e30e8b5073 tree-wide: drop stat.h or statfs.h when stat-util.h is included 2019-11-04 00:30:32 +09:00
Yu Watanabe 99e0d09731 tree-wide: drop glob.h when glob-util.h is included 2019-11-04 00:30:32 +09:00
Yu Watanabe 455fa9610c tree-wide: drop string.h when string-util.h or friends are included 2019-11-04 00:30:32 +09:00
Zach Smith eccebf4b0d systemd-tmpfiles: deprecate F for f+ 2019-10-31 22:27:56 -07:00
Yu Watanabe f5947a5e92 tree-wide: drop missing.h 2019-10-31 17:57:03 +09:00
Zbigniew Jędrzejewski-Szmek a5648b8094 basic/fs-util: change CHASE_OPEN flag into a separate output parameter
chase_symlinks() would return negative on error, and either a non-negative status
or a non-negative fd when CHASE_OPEN was given. This made the interface quite
complicated, because dependning on the flags used, we would get two different
"types" of return object. Coverity was always confused by this, and flagged
every use of chase_symlinks() without CHASE_OPEN as a resource leak (because it
would this that an fd is returned). This patch uses a saparate output parameter,
so there is no confusion.

(I think it is OK to have functions which return either an error or an fd. It's
only returning *either* an fd or a non-fd that is confusing.)
2019-10-24 22:44:24 +09:00
Zach Smith d0ea5c5e39 systemd-tmpfiles: allow appending content to file
Adds support to append to files with w+ type.

 w /tmp/13291.out - - - - first line\n
 w+ /tmp/13291.out - - - - second line\n
2019-10-03 18:28:15 -07:00
Zach Smith c55ac24825 systemd-tmpfiles: rename force to append_or_force
The force field of the Item struct is used to indicate
force creation or appending in different context. This
change renames the field to append_or_force to improve
readability.
2019-10-03 18:09:35 -07:00
Lennart Poettering b910cc72c0 tree-wide: get rid of strappend()
It's a special case of strjoin(), so no need to keep both. In particular
as typing strjoin() is even shoert than strappend().
2019-07-12 14:31:12 +09:00
Lennart Poettering a345cf448d tmpfiles: use path_join() where it makes sense 2019-07-11 18:42:26 +02:00
Lennart Poettering d34cd5711d tmpfiles: fix build
After I merged #12750 we don't build anymore, since the merged PR (which
passed CI) uses prefix_root() which doesn't exist anymore. Let's fix
that.
2019-07-11 18:41:14 +02:00
Lennart Poettering 6c75f78e94
Merge pull request #12750 from keszybz/tmpfiles-c-copy
Make tmpfiles C use --root
2019-07-11 18:13:19 +02:00
Lennart Poettering afb7e1ceb9 tmpfiles: use log_syntax() for complaining about configuration file errors
In the light of #12926 I needed some log messages for testing. This
tmpfiles one came to mind, since it's frequently seen on typical Fedora
systems. Alas, they didn't actually use log_syntax, and thus weren't
recognizable by the new config file urlifaction code. Let's fix that.
2019-07-10 16:20:08 +02:00
Zbigniew Jędrzejewski-Szmek 4ec8514142 Rename EXTRACT_QUOTES to EXTRACT_UNQUOTE
Whenever I see EXTRACT_QUOTES, I'm always confused whether it means to
leave the quotes in or to take them out. Let's say "unquote", like we
say "cunescape".
2019-06-28 11:35:05 +02:00
Yu Watanabe 2d9b74ba87 tree-wide: replace strjoin() with path_join() 2019-06-24 23:59:38 +09:00
Lennart Poettering c6134d3e2f path-util: get rid of prefix_root()
prefix_root() is equivalent to path_join() in almost all ways, hence
let's remove it.

There are subtle differences though: prefix_root() will try shorten
multiple "/" before and after the prefix. path_join() doesn't do that.
This means prefix_root() might return a string shorter than both its
inputs combined, while path_join() never does that. I like the
path_join() semantics better, hence I think dropping prefix_root() is
totally OK. In the end the strings generated by both functon should
always be identical in terms of path_equal() if not streq().

This leaves prefix_roota() in place. Ideally we'd have path_joina(), but
I don't think we can reasonably implement that as a macro. or maybe we
can? (if so, sounds like something for a later PR)

Also add in a few missing OOM checks
2019-06-21 08:42:55 +09:00
Lennart Poettering 60bdc0ca22 tmpfiles: use common fd_is_mount_point() implementation in tmpfiles.c
No need to have a private reimplementation here. Let's just use the
common one, which supports "fdinfo" as fallback.
2019-06-18 12:42:30 +02:00
Lennart Poettering 20b6bb9560 tmpfiles: merge two nested if checks into one 2019-06-18 12:41:31 +02:00
Lennart Poettering 113ed3be37 tmpfiles: use path_join() where we can 2019-06-18 12:41:02 +02:00
Zbigniew Jędrzejewski-Szmek 626f8d1672 tmpfiles: also prefix C source paths with --root
This makes the code match the docs for --root ("all paths will be prefixed").
I think this is reasonable, because --root also works for config paths, and
any configuration inside --root must refer to paths under --root. If we allowed
C to go "outside of root" in this way, the effect of calling systemd-tmpfiles --root=...
and chrooting first and then calling systemd-tmpfiles second would be quite different.
I think it's better to keep things simple and consistent.

Fixes #12467.
2019-06-05 15:56:45 +02:00
Zbigniew Jędrzejewski-Szmek 9e099c9fd8
Merge pull request #12431 from poettering/tmpfiles-chmod-chown-order
tmpfiles: run chown() before chmod()
2019-05-22 17:23:28 +02:00
Lennart Poettering a9f55d0e7e tmpfiles: be more careful when adjusting chmod() + chown()
chown() might drop the suid/sgid bit from files. hence let's chmod()
after chown().

But also, let's tighten the transition a bit: before issuing chown()
let's set the file mask to the minimum of the old and new access
bitmask, so that at no point in time additional privs are available on
the file with a non-matching ownership.

Fixes: #12354
2019-04-30 09:18:23 +02:00
Lennart Poettering 8b364a3823 tmpfiles: split out ~ mode handling into a helper function
No change of behaviour, just some minor refactoring.
2019-04-30 09:18:23 +02:00
Frantisek Sumsal 4e361acc06 tree-wide: replace explicit NULL checks with their shorter variants
Done by coccinelle/equals-null.cocci
2019-04-28 14:28:49 +02:00
Lennart Poettering e7b88b7bc1 tree-wide: introduce empty_or_dash() helper
At quite a few places we check isempty() || streq(…, "-"), let's add a
helper to simplify that, and replace that by a single function call.
2019-04-08 12:03:33 +02:00
Lennart Poettering d629ba7045 tmpfiles: move full chattr flag set to chattr-util.h
It's a pretty generic concept and fits will there, hence let's move it.
2019-03-28 18:43:05 +01:00
Lennart Poettering 75006470ce tmpfiles: support the FS_PROJINHERIT_FL chattr flag 2019-03-28 18:43:04 +01:00
Lennart Poettering b82f71c7ff tree-wide: constify a few static string tables 2019-03-25 14:04:34 +01:00
Lennart Poettering 760877e90c util: split out sorting related calls to new sort-util.[ch] 2019-03-13 12:16:43 +01:00
David Michael c3aa4adcaf tmpfiles: pass arg_root to chase_symlinks as the root prefix
This informs chase_symlinks that symlinks should be treated as if
the path given by --root= is the root of their file system.

With the parent commit, this allows tmpfiles to create files as the
root user under a prefix that may be owned by an unprivileged user.
In particular, this fixes the case where tmpfiles generates initial
files in a staging root directory for packaging under a directory
owned by the unprivileged packager user (e.g. in Gentoo).
2019-02-28 13:06:07 -05:00
Lennart Poettering e5358401b5 tmpfiles: let's bump RLIMIT_NOFILE for tmpfiles
We potentially might descent into quite deep directory trees. Let's
hence make sure we can allocate a lot of fds.

(This reflects the fact that glibc nftw() and friends have some logic in
place to reduce fd usage while descending into directory trees. Doing so
is a bit nasty I think, and given that fds are basically free now, if we
ask for them, lte's just protect ourselves and make use of that)

(No, I am not aware of a real-world case where this was necessary, but
let's better be safe than sorry)
2019-02-15 17:16:54 +01:00
Lennart Poettering 52b32b2aac tmpfiles: while aging, take a BSD file lock on each directory we descent into
Let's add a fully safe way to exclude certain directories from aging, by
taking a BSD file lock on them before aging them. This is useful for
clients that untar tarballs into /tmp or /var/tmp, which might have
really old timestamps, and to which the aging logic would be very harsh:
they can simply take a BSD file lock on any directory they like and thus
exclude it from automatic aging, and thus need not to be afraid of
untarring stuff below it.

Previously, similar functionality was already available through the
sticky bit on non-directories, but it's problematic, since as soon as
the bit is set no clean-up is done for it at all anymore, forever. Also,
it is not suitable for untarring stuff, since the sticky bit after all
is a concept denoted in the tarball itself.  BSD file locking semantics
are much much nicer there, as they are automatically released when the
application that has them dies, and they are entirely orthogonal to data
encoded in tarballs.

This patch takes BSD file locks only on *directories* while descending
down the tree, not on regular files. Moreover, it will do so in
non-blocking mode only, i.e. if anyone else has a lock the aging for a
dir and everything below it is immediately skipped for the current
clean-up iteration.

Of course applications might take BSD file locks for other reasons than
just prevent aging (i.e for their own reasons), but that should be
entirely OK, as in that case tmpfiles should step away from those files
anyway too: it's a good idea to stay away from any such locked file
anyway since it's apparently curretnly being manipulated.

This allows us to fix bugs like this:

https://github.com/systemd/mkosi/issues/252
2019-02-15 17:16:54 +01:00
Lennart Poettering 781bc44e83 tmpfiles: make some log messages a tiny bit less cryptic for mere mortals 2019-02-15 17:16:54 +01:00
Lennart Poettering a23fabc697 tmpfiles: break comment blocks according to our current editor settings 2019-02-15 17:16:54 +01:00
Lennart Poettering 76e15a9cab tmpfiles: clean up restoring of access times after aging a bit
Let's minimize file scope, use compund literals and only use LOG_WARN
for errors we ignore.
2019-02-15 17:16:54 +01:00
Lennart Poettering 6e9417f5b4 tree-wide: use newa() instead of alloca() wherever we can
Typesafety is nice. And this way we can take benefit of the new size
assert() the previous commit added.
2019-01-26 16:17:04 +01:00