Commit Graph

328 Commits

Author SHA1 Message Date
Davide Cavalca b75f0c69b3 shared: add %g, %G specifiers for group / gid (#10368) 2018-10-13 17:26:48 +09:00
Lennart Poettering db9a42545a chattr: optionally, return the old flags when updating them 2018-10-08 21:40:44 +02:00
William Douglas 6d7b543342 RFC tmpfiles: Allow configuration to ignore execution errors
This is an implementation that covers making errors encountered when writing
file content optionally fatal. If this is something that folks would want I'll
add handling of this for all the other directives. I'd appreciate suggestions
on how this might better be structured as well (use of a goto fail or such) as
I'm not super happy with the approach.
2018-09-25 23:30:30 +02:00
Yu Watanabe 93bab28895 tree-wide: use typesafe_qsort() 2018-09-19 08:02:52 +09:00
Franck Bui 4dc7bfdf4f tmpfiles: use fd_get_path() even less excessively
A follow-up for commit 9d874aec45.

This patch makes "path" parameter mandatory in fd_set_*() helpers removing the
need to use fd_get_path() when NULL was passed. The caller is supposed to pass
the fd anyway so assuming that it also knows the path should be safe.

Actually, the only case where this was useful (or used) was when we were
walking through directory trees (in item_do()). But even in those cases the
paths could be constructed trivially, which is still better than relying on
fd_get_path() (which is an ugly API).

A very succinct test case is also added for 'z/Z' operators so the code dealing
with recursive operators is tested minimally.
2018-08-21 19:48:08 +02:00
Zbigniew Jędrzejewski-Szmek 7692fed98b
Merge pull request #9783 from poettering/get-user-creds-flags
beef up get_user_creds() a bit and other improvements
2018-08-21 10:09:33 +02:00
Lennart Poettering fafff8f1ff user-util: rework get_user_creds()
Let's fold get_user_creds_clean() into get_user_creds(), and introduce a
flags argument for it to select "clean" behaviour. This flags parameter
also learns to other new flags:

- USER_CREDS_SYNTHESIZE_FALLBACK: in this mode the user records for
  root/nobody are only synthesized as fallback. Normally, the synthesized
  records take precedence over what is in the user database.  With this
  flag set this is reversed, and the user database takes precedence, and
  the synthesized records are only used if they are missing there. This
  flag should be set in cases where doing NSS is deemed safe, and where
  there's interest in knowing the correct shell, for example if the
  admin changed root's shell to zsh or suchlike.

- USER_CREDS_ALLOW_MISSING: if set, and a UID/GID is specified by
  numeric value, and there's no user/group record for it accept it
  anyway. This allows us to fix #9767

This then also ports all users to set the most appropriate flags.

Fixes: #9767

[zj: remove one isempty() call]
2018-08-20 15:58:21 +02:00
Zbigniew Jędrzejewski-Szmek 5664144bd3
Merge pull request #9809 from poettering/tmpfiles-cleanup
various tmpfiles fixes
2018-08-20 12:51:57 +02:00
Lennart Poettering 37ec0fdd34 tree-wide: add clickable man page link to all --help texts
This is a bit like the info link in most of GNU's --help texts, but we
don't do info but man pages, and we make them properly clickable on
terminal supporting that, because awesome.

I think it's generally advisable to link up our (brief) --help texts and
our (more comprehensive) man pages a bit, so this should be an easy and
straight-forward way to do it.
2018-08-20 11:33:04 +02:00
Franck Bui f17a8d6178 tmpfiles: don't adjust qgroups on existing subvolumes
The qgroup logic (types 'q' and 'Q') only has an effect if there's no previous
setup at all, and any explicitly configured subvolumes with their qgroups are
left entirely unmodified.

The idea is that if users want a different logic than the one we set up by
default, then by all means they should do that before hand, and tmpfiles won't
override their logic.
2018-08-08 12:37:35 +02:00
Lennart Poettering c3e03778d6 tmpfiles: return correct error variable after fd_reopen() 2018-08-08 11:59:39 +02:00
Lennart Poettering 713998cfc8 tmpfiles: reindent one comment less weirdly 2018-08-08 11:59:39 +02:00
Lennart Poettering a5df05ff20 tmpfiles: use correct error variable 2018-08-08 11:59:39 +02:00
Lennart Poettering 15b45fac87 tmpfiles: clarify that we ignore file attribute setting errors 2018-08-08 11:59:39 +02:00
Lennart Poettering 09f12798c9 tmpfiles: add log message where we previously failed silently 2018-08-08 11:59:39 +02:00
Lennart Poettering 9d874aec45 tmpfiles: use fd_get_path() less excessively
fd_get_path() is an ugly API, as it creates ambiguities related to the
" (deleted)" suffix /proc/$PID/fd/$FD shows. Let's use it a bit less
excessively, and whenever we have a good valid path already, let's
simply pass that along, instead of forgetting it in one stackframe and
reacquiring it in the next.
2018-08-08 11:59:39 +02:00
Franck Bui addc3e302d tmpfiles: don't follow unsafe transitions in path_set_*()
Since all path_set_*() helpers don't follow symlinks, it's possible to use
chase_symlinks(CHASE_NOFOLLOW) flag to both open the files specified by the
passed paths and check their validity (unlike their counterpart fd_set_*()
helpers).
2018-07-30 16:04:20 +02:00
Franck Bui 7ea5a87f92 tmpfiles: make create_fifo() safe 2018-07-30 15:54:03 +02:00
Franck Bui a2fc2f8dd3 tmpfiles: introduce create_fifo() 2018-07-30 15:54:03 +02:00
Franck Bui 5494602195 tmpfiles: introduce empty_directory() 2018-07-30 15:54:03 +02:00
Franck Bui 4c39d899ff tmpfiles: introduce create_directory() and create_subvolume() and make them safe 2018-07-30 15:54:03 +02:00
Franck Bui 4ad3684410 tmpfiles: introduce create_directory_or_subvolume()
No functional changes.
2018-07-30 15:54:03 +02:00
Franck Bui c7700a7748 tmpfiles: make create_device() safe 2018-07-30 15:54:03 +02:00
Franck Bui 074bd73fd3 tmpfiles: introduce create_device() 2018-07-30 15:54:03 +02:00
Franck Bui 16ba55adb1 tmpfiles: make copy_files() safe 2018-07-30 15:54:02 +02:00
Franck Bui b1f7b17f9a tmpfiles: introduce copy_files() routine
No functional changes.
2018-07-30 15:54:02 +02:00
Franck Bui 551470ecf2 tmpfiles: make write_one_file() safe 2018-07-30 15:54:02 +02:00
Franck Bui 14ab804e14 tmpfiles: make truncate_file() safe 2018-07-30 15:54:02 +02:00
Franck Bui 5ec9d06512 tmpfiles: introduce truncate_file() which deals with 'F' exclusively
TRUNCATE_FILE is now handled by a new dedicated function
truncate_file(). Indeed we have to take special care when truncating existing
file since the behavior is only specified for regular files.

Well that's not entirely true for fifo and terminal devices since O_TRUNC is
ignored in this case but even in for these types of file, truncating is
probably not the right thing to do.

It is worth noting that both truncate_file() and create_file() have been
modified so they use fstat(2) instead of stat(2) since both functions are not
supposed to follow symlinks.
2018-07-30 15:53:53 +02:00
Franck Bui 31c84ff11e tmpfiles: introduce create_file() which deals with 'f'/'F' exclusively
write_one_file() only deals with the 'w' command and 'f'/'F' are now handled by
a new function create_file().

This is primarly done because 'w' is allowed to operate on any kind of files,
not just regular ones.
2018-07-30 14:44:58 +02:00
Franck Bui b206ac8e54 tmpfiles: make the stat struct parameter in fd_set_*() optional
So every callers are not forced to stat() the passed file descriptor before
calling those functions.
2018-07-30 14:44:58 +02:00
Franck Bui 14f3480af1 tmpfiles: stat file in item_do() rather than in its callers
This a slight simplification since all callers of item_do()
(glob_item_recursively() and item_do() itself) stat the file descriptor only
for passing it to item_do().
2018-07-30 14:44:58 +02:00
remueller 2667385b0e tmpfiles: set only default acls to folders #9545 (#9599)
Check if the fd is a folder before setting default acls

Tested:

Ubuntu 18.04.

test.conf: A+ /tmp/test - - - - u:user2:rw,d:u:user1:rwx

The folder /tmp/test looks like

    /tmp/test/file1
    /tmp/test/folder2

start systemd-tmpfiles manually

Fixes: #9545
2018-07-16 16:56:01 +02:00
Yu Watanabe 545cdb90f3 tree-wide: use instead of #ifdef for HAVE_* 2018-06-29 11:40:15 +02:00
Zbigniew Jędrzejewski-Szmek d9b02e1697 tree-wide: drop copyright headers from frequent contributors
Fixes #9320.

for p in Shapovalov Chevalier Rozhkov Sievers Mack Herrmann Schmidt Rudenberg Sahani Landden Andersen Watanabe; do
  git grep -e 'Copyright.*'$p -l|xargs perl -i -0pe 's|/([*][*])?[*]\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\s*[*]([*][*])?/\n*|\n|gms; s|\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\n*|\n|gms'
done
2018-06-20 11:58:53 +02:00
Zbigniew Jędrzejewski-Szmek 0cd41d4dff Drop my copyright headers
perl -i -0pe 's/\s*Copyright © .... Zbigniew Jędrzejewski.*?\n/\n/gms' man/*xml
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/(#\n)?# +Copyright © [0-9, -]+ Zbigniew Jędrzejewski.*?\n//gms'
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s*\/\*\*\*\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*?\s*\*\*\*\/\s*/\n\n/gms'
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*//gms'
2018-06-14 13:03:20 +02:00
Lennart Poettering 96b2fb93c5 tree-wide: beautify remaining copyright statements
Let's unify an beautify our remaining copyright statements, with a
unicode ©. This means our copyright statements are now always formatted
the same way. Yay.
2018-06-14 10:20:21 +02:00
Lennart Poettering 0c69794138 tree-wide: remove Lennart's copyright lines
These lines are generally out-of-date, incomplete and unnecessary. With
SPDX and git repository much more accurate and fine grained information
about licensing and authorship is available, hence let's drop the
per-file copyright notice. Of course, removing copyright lines of others
is problematic, hence this commit only removes my own lines and leaves
all others untouched. It might be nicer if sooner or later those could
go away too, making git the only and accurate source of authorship
information.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Lennart Poettering dcd5c891cb binfmt,sysctl,sysuers,tmpfiles: add auto-paging for --cat-config commands
The output of these commands is really long, and already enriched with
color. Let's add auto-paging to make this easier to digest.
2018-06-13 14:20:03 +02:00
Yu Watanabe 858d36c1ec path-util: introduce path_simplify()
The function is similar to path_kill_slashes() but also removes
initial './', trailing '/.', and '/./' in the path.
When the second argument of path_simplify() is false, then it
behaves as the same as path_kill_slashes(). Hence, this also
replaces path_kill_slashes() with path_simplify().
2018-06-03 23:39:26 +09:00
Lennart Poettering 669fc4e5c5 tree-wide: some O_NDELAY → O_NONBLOCK fixes
Somehow the coccinelle script misses these, hence fix them manually.
2018-05-31 12:04:39 +02:00
Lennart Poettering b294e5943f core: introduce specifiers for /tmp and /var/tmp
This corresponds nicely with the specifiers we already pass for
/var/lib, /var/cache, /run and so on.

This is particular useful to update the test-path service files to
operate without guessable files, thus allowing multiple parallel
test-path invocations to pass without issues (the idea is to set $TMPDIR
early on in the test to some private directory, and then only use the
new %T or %V specifier to refer to it).
2018-05-29 11:39:15 +02:00
Lennart Poettering 6f8fa29465
Merge pull request #8981 from keszybz/ratelimit-and-dbus
Ratelimit renaming and dbus error message fix
2018-05-18 21:38:30 +02:00
Lennart Poettering a2d1fb882c tmpfiles: fix up and complain paths referring to /var/run (instead of /run) automatically
tmpfiles.d relies on merging lines for the same file paths, as well as
detecting conflicts between lines for the same file paths. /var/run is a
prominent case that is an alias for /run, any many tmpfiles snippets
refer to paths in /var/run rather than /run currently, which breaks the
conflict detection and merging.

We can't really fix this comprehensively, as doing so would require us
to resolve symlinks early on, but that's precisely not what we want to
do, as tmpfiles is usually run very early on where the paths might not
be fully available yet (in particular as we might likely create them
ourselves).

Hence, let's at least detect and fix this case for the most prominent
case of this ambiguity, and also log explicitly about this, asking users
to fix the snippets in question so that the merging and conflict
detection works properly again.
2018-05-18 10:26:29 +02:00
Zbigniew Jędrzejewski-Szmek 22dd8d350c Use STRLEN in two places 2018-05-13 22:07:37 +02:00
Lennart Poettering 4b93699d65 tmpfiles: remove newline that shouldn't be there
We should really keep "else" branches together with their "if", hence
drop the double newline here...
2018-05-11 08:15:33 +02:00
Lennart Poettering e4915c2797
Merge pull request #8953 from yuwata/bus-macro
core: simplify dbus properties
2018-05-10 22:51:17 -07:00
Yu Watanabe 945403e6ed path-util: introduce empty_to_root() and use it many places 2018-05-11 01:47:33 +09:00
Zbigniew Jędrzejewski-Szmek ceaaeb9bab tmpfiles: add --cat-config
This implements similar logic as conf_files_cat(), but with slightly different
file gathering logic. I also want to add support for replacement files later on,
so it seems better to keep those two file-gathering functions separate.
2018-04-27 10:06:24 +02:00