Commit Graph

449 Commits

Author SHA1 Message Date
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
Franck Bui 939ca21363 tmpfiles: 'e' is supposed to accept shell-style globs 2018-04-24 12:24:38 +02:00
Franck Bui d460ba18e7 tmpfiles: 'e' is supposed to operate on directory only 2018-04-24 12:23:29 +02:00
Franck Bui 4dfaa528d4 fs-util: introduce fchmod_opath()
fchmod(2) still doesn't take file descriptors opened with O_PATH.
2018-04-24 11:57:48 +02:00
Franck Bui 7b887f2284 tmpfiles: remove spurious curly braces in create_item() 2018-04-24 11:57:48 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +02:00
Lennart Poettering 6064de2de8
Merge pull request #8617 from keszybz/tmpfiles-relax
Do not exit with error when systemd-tmpfiles --boot fails
2018-04-05 11:54:02 +02:00
Zbigniew Jędrzejewski-Szmek bb9947be2f tmpfiles: add a new return code for "operational failure" when processing
Things can fail, and we have no control over it:
- file system issues (immutable bits, file system errors, MAC refusals, etc)
- kernel refusing certain arguments when writing to /proc/sys or /sys
Let's add a new code for the case where we parsed configuration but failed
to execute it because of external errors.
2018-04-05 08:13:53 +02:00
Zbigniew Jędrzejewski-Szmek c0f9017c11
Merge pull request #8605 from poettering/drop-in-name-fix
Fix validation of unit file drop-in naming in install.c.
2018-04-04 11:52:14 +02:00
Ricardo Salveti de Araujo 2ef5de1bd9 tmpfiles: fix directory removal with force symlink (#8619)
symlink_atomic returns -EISDIR when the target symlink path is a
directory.

Fixes #7447

Signed-off-by: Ricardo Salveti <ricardo@opensourcefoundries.com>
2018-04-03 15:05:11 +02:00
Lennart Poettering f2324783ce fd-util: introduce fd_reopen() helper for reopening an fd
We have the same code for this in place at various locations, let's
unify that. Also, let's repurpose test-fs-util.c as a test for this new
helper cal..
2018-03-29 15:33:12 +02:00
Lennart Poettering 08c849815c label: rework label_fix() implementations (#8583)
This reworks the SELinux and SMACK label fixing calls in a number of
ways:

1. The two separate boolean arguments of these functions are converted
   into a flags type LabelFixFlags.

2. The operations are now implemented based on O_PATH. This should
   resolve TTOCTTOU races between determining the label for the file
   system object and applying it, as it it allows to pin the object
   while we are operating on it.

3. When changing a label fails we'll query the label previously set, and
   if matches what we want to set anyway we'll suppress the error.

Also, all calls to label_fix() are now (void)ified, when we ignore the
return values.

Fixes: #8566
2018-03-27 07:38:26 +02:00
Lennart Poettering 34d267776a coccinelle: run const-strlen.cocci again 2018-03-23 15:46:12 +01:00
Lennart Poettering ae2a15bc14 macro: introduce TAKE_PTR() macro
This macro will read a pointer of any type, return it, and set the
pointer to NULL. This is useful as an explicit concept of passing
ownership of a memory area between pointers.

This takes inspiration from Rust:

https://doc.rust-lang.org/std/option/enum.Option.html#method.take

and was suggested by Alan Jenkins (@sourcejedi).

It drops ~160 lines of code from our codebase, which makes me like it.
Also, I think it clarifies passing of ownership, and thus helps
readability a bit (at least for the initiated who know the new macro)
2018-03-22 20:21:42 +01:00
Franck Bui 936f6bdb80 tmpfiles: don't resolve pathnames when traversing recursively through directory trees
Otherwise we can be fooled if one path component is replaced underneath us.

The patch achieves that by always operating at file descriptor level (by using
*at() helpers) and by making sure we do not any path resolution when traversing
direcotry trees.

However this is not always possible, for instance when listing the content of a
directory or some operations don't provide the *at() helpers or others (such as
fchmodat()) don't have the AT_EMPTY_PATH flag. In such cases we operate on
/proc/self/fd/%i pseudo-symlink instead, which works the same for all kinds of
objects and requires no checking of type beforehand.

Also O_PATH flag is used when opening file objects in order to prevent
undesired behaviors: device nodes from reacting, automounts from
triggering, etc...

Fixes: #7986
Fixes: CVE-2018-6954
2018-03-05 19:00:11 +01:00
Franck Bui 56114d45d0 tmpfiles: fstat() works with fd opened with O_PATH since Linux 3.6 2018-03-05 19:00:11 +01:00
Franck Bui 774f79b570 tmpfiles: make hardlink_vulnerable() argument constant 2018-03-05 19:00:11 +01:00
Zbigniew Jędrzejewski-Szmek 04a5236233
Merge pull request #8144 from poettering/journal-inotify-fixes
various journal fixes
2018-02-14 13:52:17 +01:00
itsbill a083b4875e tmpfiles: age root-owned read-only files, by default (#7917)
[zj: The note in NEWS was added in 82c8e3e650
and released as part of systemd-237.]
2018-02-12 15:47:08 +01:00
Lennart Poettering 548f69375e tree-wide: use path_hash_ops instead of string_hash_ops whenever we key by a path
Let's make use of our new hash_ops!
2018-02-12 11:07:55 +01:00
Zbigniew Jędrzejewski-Szmek a6d8474f39 tmpfiles: allow admin/runtime overrides to runtime config
This is very similar to d16a1c1bb6. For tmpfiles this is much less useful
compared to sysusers, but let's add this anyway for consistency.
2018-02-05 15:04:52 +01:00
Lennart Poettering 49e87292dc tmpfiles: make "f" lines behaviour match what the documentation says
CHANGE OF BEHAVIOUR — with this commit "f" line's behaviour is altered
to match what the documentation says: if an "argument" string is
specified it is written to the file only when the file didn't exist
before. Previously, it would be appended to the file each time
systemd-tmpfiles was invoked — which is not a particularly useful
behaviour as the tool is not idempotent then and the indicated files
grow without bounds each time the tool is invoked.

I did some spelunking whether this change in behaviour would break
things, but afaics nothing relies on the previous O_APPEND behaviour of
this line type, hence I think it's relatively safe to make "f" lines
work the way the docs say, rather than adding a new modifier for it or
so.

Triggered by:

https://lists.freedesktop.org/archives/systemd-devel/2018-January/040171.html
2018-01-24 10:54:10 +01:00
Lennart Poettering 7fa1074831 tmpfiles: create parent directories if they are missing for more line types
Currently, we create leading directories implicitly for all lines that
create directory or directory-like nodes.

With this, we also do the same for a number of other lines: f/F, C, p,
L, c/b (that is regular files, pipes, symlinks, device nodes as well as
file trees we copy).

The leading directories are created with te default access mode of 0755.
If something else is desired, users should simply declare appropriate
"d" lines.

Fixes: #7853
2018-01-23 21:19:00 +01:00
Lennart Poettering 5579f85663 tmpfiles: refuse to chown()/chmod() files which are hardlinked, unless protected_hardlinks sysctl is on
Let's add some extra safety.

Fixes: #7736
2018-01-23 21:19:00 +01:00
Lennart Poettering dc2335669a tmpfiles: fix check for figuring out whether to call chmod()
No need to call chown() if everything matches already.
2018-01-23 21:19:00 +01:00
Lennart Poettering 59793c8f2e tmpfiles: shortcut path_set_perms() if there's nothing to do
No need to open() anything in that case, hence don't.
2018-01-23 21:19:00 +01:00
Lennart Poettering 51207ca134 tmpfiles: change ownership of symlinks too
Ownership is supported for symlinks, too, only file modes are not.
Support that too.

Fixes: #7509
2018-01-23 21:19:00 +01:00
Lennart Poettering 79c91cecc7 tmpfiles: use the DEBUG_LOGGING macro where applicable 2018-01-22 15:33:13 +01:00
Lennart Poettering 07982ed1ef tmpfiles: add missing OOM check 2018-01-22 15:32:57 +01:00
Lennart Poettering 201be4265f tmpfiles: avoid using wrong type for strlen() result
The result of strlen is size_t, hence let's not store it in an "int"
just to pass it on as as size_t right-away. In fact let's not store it
at all…
2018-01-22 15:31:50 +01:00
Lennart Poettering 920ce82852 tmpfiles: in dir_cleanup() take benefit that log_error_errno() returns the error code passed in 2018-01-22 15:31:24 +01:00
Lennart Poettering ecc1709c2c tmpfiles: fold five lines into two
log_full_errno() has all these nice benefits, let's make use of them to
shorten five lines into two.
2018-01-22 15:30:05 +01:00
Franck Bui d8dab75789 tmpfiles: consider /etc uninitialized also when /etc/machine-id is present but empty (#7849) 2018-01-10 23:28:44 +01:00
Lennart Poettering f1ff734fad tmpfiles: modernize load_unix_sockets() a bit
Let's log in case of error.

Let's use read_line() instead of a fixed-size buffer

Let's make use of set_free_free()'s return value.
2018-01-10 17:29:15 +01:00
Lennart Poettering fbd0b64f44
tree-wide: make use of new STRLEN() macro everywhere (#7639)
Let's employ coccinelle to do this for us.

Follow-up for #7625.
2017-12-14 19:02:29 +01:00
Zbigniew Jędrzejewski-Szmek 5a8575ef01 tmpfiles: also add %t/%S/%C/%L specifiers
sd_path_home() returns ENXIO when a variable (such as $XDG_RUNTIME_DIR) is not
defined. Previously we used ENOKEY for unresolvable specifiers. To avoid having
two codes, or translating ENXIO to ENOKEY, I replaced ENOKEY use with ENXIO.

v2:
- use sd_path_home and change to ENXIO everywhere
2017-12-06 10:30:26 +01:00
Zbigniew Jędrzejewski-Szmek f2b5ca0e4e tmpfiles: add --user switch 2017-12-06 10:19:29 +01:00
ayekat ca23eeb54c tmpfiles: Add specifiers to allow running as user instance
This commit adds specifiers %U, %u and %h for the user UID, name and
home directory, respectively.

[zj: drop untrue copy-pasted comments and move the next text
     to the new "Specifiers" section.
     Now that #7444 has been merged, also drop the specifier functions.]
2017-12-06 10:19:22 +01:00
Zbigniew Jędrzejewski-Szmek 65241c1485 tmpfiles: "e" takes globs
Fixes #7369.
2017-12-06 10:17:58 +01:00
Zbigniew Jędrzejewski-Szmek 79a1b18711 tmpfiles: fix typo in error message
Fixes #4097.

As of current master, systemd-tmpfiles behaves correctly, apart from a trivial
typo. So let's tell github to close the bug.

With current git:

$ sudo SYSTEMD_LOG_LEVEL=debug build/systemd-tmpfiles --create `pwd`/test/tmpfiles.d/link-loop.conf
Successfully loaded SELinux database in 2.385ms, size on heap is 321K.
Reading config file "/home/zbyszek/src/systemd-work/test/tmpfiles.d/link-loop.conf".
Running create action for entry D /run/hello2
Found existing directory "/run/hello2".
"/run/hello2" has right mode 41777
Running create action for entry f /run/hello2/hello2.test
"/run/hello2/hello2.test" has been created.
"/run/hello2/hello2.test" has right mode 101777
chown "/run/hello2/hello2.test" to 0.84
Running create action for entry L /run/hello2/hello2.link
Found existing symlink "/run/hello2/hello2.link".
Running create action for entry z /run/hello2/hello2.test
"/run/hello2/hello2.test" has right mode 101777
chown "/run/hello2/hello2.test" to 0.0
Running create action for entry z /run/hello2/hello2.link
Skipping mode an owner fix for symlink /run/hello2/hello2.link.

and the permissions are:
$ ls -dl /run/hello2/ /run/hello2/*
drwxrwxrwt. 2 foo   bar    80 Nov 22 14:40 /run/hello2/
lrwxrwxrwx. 1 root  root   23 Nov 22 14:40 /run/hello2/hello2.link -> /run/hello2/hello2.test
-rwxrwxrwt. 1 root  root    0 Nov 22 14:40 /run/hello2/hello2.test

Everything seems correct.
2017-12-06 10:17:52 +01:00
Zbigniew Jędrzejewski-Szmek e286dbaf9b tmpfiles: downgrade warning about duplicate line
This happens occasionally, especially when moving lines between configuration files
in different packages, and usually is not a big deal.
2017-12-06 10:17:45 +01:00
Zbigniew Jędrzejewski-Szmek 751223fecf Fail on unknown (alphanumerical) specifiers
The code intentionally ignored unknown specifiers, treating them as text. This
needs to change because otherwise we can never add a new specifier in a backwards
compatible way. So just treat an unknown (potential) specifier as an error.

In principle this is a break of backwards compatibility, but the previous
behaviour was pretty much useless, since the expanded value could change every
time we add new specifiers, which we do all the time.

As a compromise for backwards compatibility, only fail on alphanumerical
characters. This should cover the most cases where an unescaped percent
character is used, like size=5% and such, which behave the same as before with
this patch. OTOH, this means that we will not be able to use non-alphanumerical
specifiers without breaking backwards compatibility again. I think that's an
acceptable compromise.

v2:
- add NEWS entry

v3:
- only fail on alphanumerical
2017-12-06 10:17:37 +01:00
Zbigniew Jędrzejewski-Szmek d9daae55d5 tmpfiles: add a special return code for syntax failures
In this way, individual errors in files can be treated differently than a
failure of the whole service.

A test is added to check that the expected value is returned.
Some parts are commented out, because it is not. This will be fixed in
a subsequent commit.
2017-12-01 18:58:54 +01:00
Lennart Poettering 7b943bb7e3 tree-wide: use strv_isempty() instead of strv_length() == 0
It's a lot faster in many cases, since it's O(1) rather than O(n).
2017-11-29 12:41:08 +01:00
Zbigniew Jędrzejewski-Szmek 224b0e7ad0 Add set/hashmap helpers for non-trivial freeing and use where straighforward
A macro is needed because otherwise we couldn't ensure type safety.
Some simple tests are included.
No functional change intended.
2017-11-28 21:30:30 +01:00
Lukasz Rubaszewski 3d22bc8636 tmpfiles: check if not too many symbolic links. (#7423)
Some filesystems do not set d_type value when
readdir is called, so entry type is unknown.
Therefore check if accessing entry does not
return ELOOP error.
2017-11-24 22:28:14 +01:00
Zbigniew Jędrzejewski-Szmek a217a4bcc5
Merge pull request #7395 from poettering/nametohandleat-loop
name_to_handle_at() EOVERFLOW handling
2017-11-22 08:20:36 +01:00
Lennart Poettering cbfb8679dd mount-util: add name_to_handle_at_loop() wrapper around name_to_handle_at()
As it turns out MAX_HANDLE_SZ is a lie, the handle buffer we pass into
name_to_handle_at() might need to be larger than MAX_HANDLE_SZ, and we
thus need to invoke name_to_handle_at() in a loop, growing the buffer as
needed.

This adds a new wrapper name_to_handle_at_loop() around
name_to_handle_at() that does the necessary looping, and ports over all
users.

Fixes: #7082
2017-11-21 11:37:12 +01:00
Shawn Landden 4831981d89 tree-wide: adjust fall through comments so that gcc is happy
Distcc removes comments, making the comment silencing
not work.

I know there was a decision against a macro in commit
ec251fe7d5
2017-11-20 13:06:25 -08:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Franck Bui 4cef192357 tmpfiles: when /etc is not fully initialized, some specifiers are expected to be unresolvable (#6860)
In chroot environments, /etc might not be fully initialized: /etc/machine-id
can be missing for example. This makes the expansions of affected specifiers
impossible at that time.

These cases should not be considered as errors and such failures shouldn't be
logged at an error level therefore this patch downgrades the level used to
LOG_NOTICE in such cases.

Also this is logged at LOG_NOTICE only the first time and then downgrade to
LOG_DEBUG for the rest. That way, if debugging is enabled we get the full
output, but otherwise we only see only one message.

The expansion of specifiers is now self contained in a dedicated function
instead of being spread all over the place.
2017-11-16 11:27:29 +01:00
Lennart Poettering 4aa1d31c89 Merge pull request #6974 from keszybz/clean-up-defines
Clean up define definitions
2017-10-04 19:25:30 +02:00
Yu Watanabe 4c70109600 tree-wide: use IN_SET macro (#6977) 2017-10-04 16:01:32 +02:00
Zbigniew Jędrzejewski-Szmek 349cc4a507 build-sys: use #if Y instead of #ifdef Y everywhere
The advantage is that is the name is mispellt, cpp will warn us.

$ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/"
$ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;'
$ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g'
$ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g'
+ manual changes to meson.build

squash! build-sys: use #if Y instead of #ifdef Y everywhere

v2:
- fix incorrect setting of HAVE_LIBIDN2
2017-10-04 12:09:29 +02:00
Andreas Rammhold 3742095b27
tree-wide: use IN_SET where possible
In addition to the changes from #6933 this handles cases that could be
matched with the included cocci file.
2017-10-02 13:09:54 +02:00
Lennart Poettering b50846055e exec-util,conf-files: skip non-executable files in execute_directories()
Fixes: #6787
2017-09-13 11:42:31 +02:00
NeilBrown 655f2da079 tmpfiles: silently ignore any path that passes through autofs (#6506)
If a path passes though an autofs filesystem, then accessing
the path might trigger and automount.  As systemd-tmpfiles is run before
the network is up, and as automounts are often used for networked
filesystems, this can cause a deadlock.

So chase_symlinks is enhance to accept a new flag which tells it
to check for autofs, and return -EREMOTE if autofs is found.

tmpfiles is changed to check just before acting on a path so that it
can avoid autofs even if a symlink was created earlier by tmpfiles
that would send this path through an autofs.

This fixes a deadlock that happens when /home is listed in /etc/fstab as
x-systemd.automount for an NFS directory.
2017-09-04 15:35:07 +02:00
Michal Sekletar 780e2ee187 tmpfiles: with "e" don't attempt to set permissions when file doesn't exist (#6682)
tmpfiles.d option "e" when run through systemd-tmpfiles --create should
apply configured permissions (uid,gid) only to already existing
files. When file doesn't exist we bail out with error. Instead we should
silently ignore non-existing files.

$ useradd test
$ cat /etc/tmpfiles.d/foobar.conf
e /tmp/test - test test 1d
$ ls -l /tmp/test
ls: cannot access '/tmp/test': No such file or directory

Before:
$ systemd-tmpfiles --create /etc/tmpfiles.d/foobar.conf
Adjusting owner and mode for /tmp/test failed: No such file or directory
$ echo $?
1

After:
$ systemd-tmpfiles --create /etc/tmpfiles.d/foobar.conf
$ echo $?
0
2017-08-31 12:45:25 +02:00
William Douglas b3f5897f6e tmpfiles: Allow create symlink on directories (#6039)
Currently if tmpfiles is run with force on symlink creation but there already
exists a directory at that location, the creation will fail. This change
updates the behavior to remove the directory with rm_fr and then attempts to
create the symlink again.
2017-08-09 17:53:03 +02:00
Zbigniew Jędrzejewski-Szmek 25f027c5ef tree-wide: when %m is used in log_*, always specify errno explicitly
All those uses were correct, but I think it's better to be explicit.
Using implicit errno is too error prone, and with this change we can require
(in the sense of a style guideline) that the code is always specified.

Helpful query: git grep -n -P 'log_[^s][a-z]+\(.*%m'
2017-05-19 14:24:03 -04:00
Zbigniew Jędrzejewski-Szmek 84e72b5ef4 tmpfiles: use safe_glob()
This filters out "." and ".." from glob results. Fixes #5655 and #5644.

Any judgements on whether the path is "safe" are removed. We will not remove
"/" under any name (including "/../" and such), but we will remove stuff that
is specified using paths that include "//", "/./" and "/../". Such paths can be
created when joining strings automatically, or for other reasons, and people
generally know what ".." and "." is.

Tests are added to make sure that the helper functions behave as expected.
2017-04-27 13:20:30 -04:00
Yu Watanabe c258349f1a tmpfiles: downgrade error message when operation is not supported (#5692)
Fixes #5607
2017-04-10 13:22:18 +02:00
AsciiWolf 13e785f7a0 Fix missing space in comments (#5439) 2017-02-24 18:14:02 +01:00
Lennart Poettering d01cd40196 machined: when copying files from/to userns containers chown to root
This changes the file copy logic of machined to set the UID/GID of all
copied files to 0 if the host and container do not share the same user
namespace.

Fixes: #4078
2017-02-17 10:22:28 +01:00
Lennart Poettering 1c876927e4 copy: change the various copy_xyz() calls to take a unified flags parameter
This adds a unified "copy_flags" parameter to all copy_xyz() function
calls, replacing the various boolean flags so far used. This should make
many invocations more readable as it is clear what behaviour is
precisely requested. This also prepares ground for adding support for
more modes later on.
2017-02-17 10:22:28 +01:00
Lennart Poettering 49bfc8774b fs-util: unify code we use to check if dirent's d_name is "." or ".."
We use different idioms at different places. Let's replace this is the
one true new idiom, that is even a bit faster...
2017-02-02 00:06:18 +01:00
Lennart Poettering e0bc1d70d9 tmpfiles: improve error message for chown()/chmod() failures (#4969)
Let's make the error message less confusing here.

Fixes: #4954
2016-12-29 11:00:55 +01:00
Reverend Homer 8fb3f00997 tree-wide: replace all readdir cycles with FOREACH_DIRENT{,_ALL} (#4853) 2016-12-09 10:04:30 +01:00
Zbigniew Jędrzejewski-Szmek f97b34a629 Rename formats-util.h to format-util.h
We don't have plural in the name of any other -util files and this
inconsistency trips me up every time I try to type this file name
from memory. "formats-util" is even hard to pronounce.
2016-11-07 10:15:08 -05:00
Zbigniew Jędrzejewski-Szmek 605405c6cc tree-wide: drop NULL sentinel from strjoin
This makes strjoin and strjoina more similar and avoids the useless final
argument.

spatch -I . -I ./src -I ./src/basic -I ./src/basic -I ./src/shared -I ./src/shared -I ./src/network -I ./src/locale -I ./src/login -I ./src/journal -I ./src/journal -I ./src/timedate -I ./src/timesync -I ./src/nspawn -I ./src/resolve -I ./src/resolve -I ./src/systemd -I ./src/core -I ./src/core -I ./src/libudev -I ./src/udev -I ./src/udev/net -I ./src/udev -I ./src/libsystemd/sd-bus -I ./src/libsystemd/sd-event -I ./src/libsystemd/sd-login -I ./src/libsystemd/sd-netlink -I ./src/libsystemd/sd-network -I ./src/libsystemd/sd-hwdb -I ./src/libsystemd/sd-device -I ./src/libsystemd/sd-id128 -I ./src/libsystemd-network --sp-file coccinelle/strjoin.cocci --in-place $(git ls-files src/*.c)

git grep -e '\bstrjoin\b.*NULL' -l|xargs sed -i -r 's/strjoin\((.*), NULL\)/strjoin(\1)/'

This might have missed a few cases (spatch has a really hard time dealing
with _cleanup_ macros), but that's no big issue, they can always be fixed
later.
2016-10-23 11:43:27 -04:00
Zbigniew Jędrzejewski-Szmek d710aaf7a5 Use "return log_error_errno" in more places" 2016-07-22 21:25:09 -04:00
Lennart Poettering 4e68ec1866 tmpfiles: make sure to always initialize "r" correctly. 2016-06-21 14:15:23 +02:00
kpengboy 8c35b2ca15 Fix FS_EXTENT_FL description (#3381) 2016-05-29 11:31:14 -04:00
Zbigniew Jędrzejewski-Szmek df8dee85da tmpfiles: add new 'e' action which cleans up a dir without creating it
I wanted to add a config line that would empty a directory
without creating it if doesn't exist. Existing actions don't allow
this.

v2: properly add 'e' to needs_glob() and takes_ownership()
2016-04-20 09:00:39 -04:00
Zbigniew Jędrzejewski-Szmek 022ffe4cca tmpfiles: shorten some long error messages
Also don't print %m when the message already contains all the info.
2016-04-20 09:00:39 -04:00
Zbigniew Jędrzejewski-Szmek f7ac1ed2ca tmpfiles: interpret "-" as stdin 2016-04-20 09:00:39 -04:00
Alexander Kuleshov 5883ff6017 tree-wide: use SET_FLAG() macro to make code more clear 2016-03-05 18:26:01 +06:00
Lennart Poettering 04c760d2fe Merge pull request #2781 from keszybz/selinux-and-warnings
Selinux loading fix and warning cleanups
2016-03-03 17:46:56 +01:00
Zbigniew Jędrzejewski-Szmek c3dacc8bbf selinux: always try to load the full selinux db
https://github.com/systemd/systemd/pull/2508#issuecomment-190901170
Maybe fixes https://bugzilla.redhat.com/show_bug.cgi?id=1308771.
2016-03-01 20:39:30 -05:00
Alexander Kuleshov c4b6915670 tree-wide: no need to pass excess flags to open()/openat() if O_PATH is passed
As described in the documentation:

When O_PATH is specified in flags, flag bits other than O_CLOEXEC,
O_DIRECTORY, and O_NOFOLLOW are ignored.

So, we can remove unnecessary flags in a case when O_PATH is passed
to the open() or openat().
2016-03-02 00:42:49 +06:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Evgeny Vereshchagin 114a17d2ad tmpfiles: don't skip path_set_perms on error
fixes #2196
2016-02-01 10:55:50 +00:00
Zbigniew Jędrzejewski-Szmek b326715278 tree-wide: check if errno is greater than zero (2)
Compare errno with zero in a way that tells gcc that
(if the condition is true) errno is positive.
2016-01-13 15:10:17 -05:00
Lennart Poettering 2904e949f2 tmpfiles: create subvolumes for "v", "q", and "Q" only if / is a subvolume
It's not a good idea to create subvolumes for parts of the OS tree (such
as /home, or /var) if the root directory is not a subvolume too. We
shouldn't assume control of "heavier" objects such as subvolumes, if the
originating object (the root directory) is a "light-weight" object, i.e.
a plain directory.

Effectively this means that chroot() environments that are run on a
plain directory do not have to deal with problems around systemd
creating subvolumes that cannot be removed with a simple "rm" anymore.
However, if the chroot manager creates a proper subvolume for such an
environment it will also get further subvolumes placed in there, under
the assumption that the manager understands the concept of subvolumes in
that case.
2015-11-16 15:25:42 +01:00
Lennart Poettering be6d467c1f tmpfiles: don't consider it a problem if quota is not enabled on btrfs
If quota is not enabled on a btrfs file system, accept that, and only
log a debug message, but do not consider this a reason for failure.

Fixes: #1809
2015-11-10 21:41:22 +01:00
Lennart Poettering 75eb615480 defs: rework CONF_DIRS_NULSTR() macro
The macro is generically useful for putting together search paths, hence
let's make it truly generic, by dropping the implicit ".d" appending it
does, and leave that to the caller. Also rename it from
CONF_DIRS_NULSTR() to CONF_PATHS_NULSTR(), since it's not strictly about
dirs that way, but any kind of file system path.

Also, mark CONF_DIR_SPLIT_USR() as internal macro by renaming it to
_CONF_PATHS_SPLIT_USR() so that the leading underscore indicates that
it's internal.
2015-11-10 17:31:31 +01:00
Lennart Poettering a0f29c767a util-lib: move CONF_DIRS_NULSTR definition to def.h
After all, this is not some compiler or C magic, but something very
specific to how systemd works, hence let's move it into def.h, and out
of macro.h
2015-11-03 17:45:11 +01:00
Lennart Poettering 4e036b7a96 mount-util: move fstype_is_network() and name_to_handle_at() definitions over 2015-10-27 13:45:53 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering 7d50b32a12 util-lib: split out globbing related calls into glob-util.[ch] 2015-10-27 13:25:58 +01:00
Lennart Poettering 15a5e95075 util-lib: split out printf() helpers to stdio-util.h 2015-10-27 13:25:57 +01:00
Lennart Poettering 430f0182b7 src/basic: rename audit.[ch] → audit-util.[ch] and capability.[ch] → capability-util.[ch]
The files are named too generically, so that they might conflict with
the upstream project headers. Hence, let's add a "-util" suffix, to
clarify that this are just our utility headers and not any official
upstream headers.
2015-10-27 13:25:57 +01:00
Lennart Poettering affb60b1ef util-lib: split out umask-related code to umask-util.h 2015-10-27 13:25:56 +01:00
Lennart Poettering 8b43440b7e util-lib: move string table stuff into its own string-table.[ch] 2015-10-27 13:25:56 +01:00
Lennart Poettering 8fcde01280 util-lib: split stat()/statfs()/stavfs() related calls into stat-util.[ch] 2015-10-27 13:25:56 +01:00
Lennart Poettering f4f15635ec util-lib: move a number of fs operations into fs-util.[ch] 2015-10-27 13:25:56 +01:00
Lennart Poettering c8b3094de5 util-lib: split out file attribute calls to chattr-util.[ch] 2015-10-27 13:25:56 +01:00
Lennart Poettering 0d39fa9c69 util-lib: move more file I/O related calls into fileio.[ch] 2015-10-27 13:25:55 +01:00
Lennart Poettering 6bedfcbb29 util-lib: split string parsing related calls from util.[ch] into parse-util.[ch] 2015-10-27 13:25:55 +01:00
Lennart Poettering b1d4f8e154 util-lib: split out user/group/uid/gid calls into user-util.[ch] 2015-10-26 01:24:38 +01:00
Lennart Poettering c004493cde util-lib: split out IO related calls to io-util.[ch] 2015-10-26 01:24:38 +01:00
Lennart Poettering 3ffd4af220 util-lib: split out fd-related operations into fd-util.[ch]
There are more than enough to deserve their own .c file, hence move them
over.
2015-10-25 13:19:18 +01:00
Lennart Poettering 07630cea1f util-lib: split our string related calls from util.[ch] into its own file string-util.[ch]
There are more than enough calls doing string manipulations to deserve
its own files, hence do something about it.

This patch also sorts the #include blocks of all files that needed to be
updated, according to the sorting suggestions from CODING_STYLE. Since
pretty much every file needs our string manipulation functions this
effectively means that most files have sorted #include blocks now.

Also touches a few unrelated include files.
2015-10-24 23:05:02 +02:00
Lennart Poettering 4f5dd3943b util: split out escaping code into escape.[ch]
This really deserves its own file, given how much code this is now.
2015-10-24 23:04:42 +02:00
Lennart Poettering 0f03c2a4c0 path-util: unify how we process paths specified on the command line
Let's introduce a common function that makes relative paths absolute and
warns about any errors while doing so.
2015-10-24 23:03:49 +02:00
Lennart Poettering 0f47436510 util-lib: get_current_dir_name() can return errors other than ENOMEM
get_current_dir_name() can return a variety of errors, not just ENOMEM,
hence don't blindly turn its errors to ENOMEM, but return correct errors
in path_make_absolute_cwd().

This trickles down into a couple of other functions, some of which
receive unrelated minor fixes too with this commit.
2015-10-24 23:03:49 +02:00
Thomas Hindoe Paaboel Andersen 2bb158c1ce tmpfiles: simplify mountpoint detection
No functional change. Just a simplification. A || (!A && B) is
the same as A || B

Introduced in 78a92a5a23
2015-10-23 22:35:03 +02:00
Lennart Poettering 5fb13eb51b tmpfiles: introduce "q" and "Q" for creating quota-enabled btrfs subvolumes
This allows us to set up the quota group hierarchy in a reasonable way
on btrfs file systems.
2015-10-22 01:59:25 +02:00
Lennart Poettering 3f6fd1ba65 util: introduce common version() implementation and use it everywhere
This also allows us to drop build.h from a ton of files, hence do so.
Since we touched the #includes of those files, let's order them properly
according to CODING_STYLE.
2015-09-29 21:08:37 +02:00
Richard Maw 12ba2c44dd util: Don't interpret quotes by default in extract_first_word
This adds an EXTRACT_QUOTES option to allow the previous behaviour, of
not interpreting any character inside ' or " quotes as separators.
2015-08-07 15:50:42 +00:00
Richard Maw 6868560773 util: change unquote_*_word to extract_*_word
It now takes a separators argument, which defaults to WHITESPACE if NULL
is passed.
2015-08-07 15:50:42 +00:00
Thomas Hindoe Paaboel Andersen 7d6884b65e tree-wide: fix indentation 2015-08-06 00:44:19 +02:00
Lennart Poettering ad75a97f7d tmpfiles: downgrade errors when a file system does not support file attributes
This downgrades errors from setting file attributes via tmpfiles to
warnings and makes them non-fatal.

Also, as a special case, if a file system does not support file
attributes at all, then the message is downgraded to debug, so that it
is not seen at all.

With this change reiserfs should not see any messages at all anymore
(since it apparently does not implement file attributes at all), but XFS
will still get a warning but no failure. The warning is something the
XFS kernel folks should fix though, by adjusting their file attributes
behaviour to be identical to ext234's.

Fixes #560.
2015-07-22 22:02:14 +02:00
Zbigniew Jędrzejewski-Szmek 1542c01b1d tmpfiles: only root-owned aquota.* files are special
Fixes #188.
2015-06-17 15:46:32 +02:00
Lennart Poettering 1b26f09eb0 tmpfiles: make sure "R" lines also remove subvolumes 2015-06-15 19:28:55 +02:00
Lennart Poettering a542c4dc43 tmpfiles: use lstat() instead of stat() when checking whether a file system object already exists 2015-05-15 21:48:20 +02:00
Lennart Poettering 7b135a7399 tmpfiles: don't fail if we cannot create a subvolume because a file system is read-only but a dir already exists anyway
https://bugs.freedesktop.org/show_bug.cgi?id=90281
2015-05-15 21:47:22 +02:00
Lennart Poettering 1d13f648d0 util: add generic calls for prefixing a root directory to a path
So far a number of utilities implemented their own calls for this, unify
them in prefix_root() and prefix_roota(). The former uses heap memory,
the latter allocates from the stack via alloca().

Port over most users of a --root= logic.
2015-05-13 17:42:10 +02:00
Michael Olbrich f44b28fda0 tmpfiles: try to handle read-only file systems gracefully
On read-only filesystems trying to create the target will not fail with
EEXIST but with EROFS. Handle EROFS by checking if the target already
exists, and if empty when truncating.
This avoids reporting errors if tmpfiles doesn't actually needs to do
anything.

[zj: revert condition to whitelist rather then blacklisting, and add goto
to avoid stat'ting twice.]
2015-05-06 00:10:40 -04:00
Lennart Poettering ef43a39176 tmpfiles: use an ordered hashmap for the tmpfiles items
We should try to execute them in the same order they appear in the
configuration files, as it is documented. Hence move to an ordered
hashmap.

(Note though, that this still doesn't execute them completely in order:
we will still apply non-glob lines before glob-lines, and reorder lines
prefixing each other and that apply to the same paths).

http://lists.freedesktop.org/archives/systemd-devel/2015-March/029055.html
2015-04-22 18:20:27 +02:00
Lennart Poettering aa5f6817bc tmpfiles: consider an argument of "-" as non-specified 2015-04-21 01:10:19 +02:00
Lennart Poettering 48b8aaa827 tmpfiles: don't follow symlinks when adjusting ACLs, fille attributes, access modes or ownership 2015-04-13 15:23:52 +02:00
Zbigniew Jędrzejewski-Szmek dd449aca61 tmpfiles: use qsort_safe 2015-04-12 10:20:24 -04:00
Ronny Chevalier 6482f6269c shared: add formats-util.h 2015-04-10 23:54:48 +02:00
Thomas Hindoe Paaboel Andersen 75c2a9fd13 tmpfiles: fix build with clang
Clang is not happy about using the cleanup attribute in switches
2015-04-10 23:28:08 +02:00
Lennart Poettering 5c5ccf12b6 tmpfiles: add specifier expansion for L and C lines, too 2015-04-10 18:07:04 +02:00
Lennart Poettering 17493fa5d1 tmpfiles: enforce ordering when executing lines
Always create files first, and then adjust their ACLs, xattrs, file
attributes, never the opposite. Previously the order was not
deterministic, thus possibly first adjusting ACLs/xattrs/file
attributes before actually creating the items.
2015-04-10 16:23:47 +02:00
Lennart Poettering 90937fe3d3 tmpfiles: eat up empty columns 2015-04-10 16:23:46 +02:00
Lennart Poettering bd550f78eb tmpfiles: substitute % specifiers in arguments for writing files and xattrs 2015-04-10 16:23:46 +02:00
Lennart Poettering c82500c6fb tmpfiles: warn if we get an argument on lines that don't take any 2015-04-10 16:23:46 +02:00
Lennart Poettering 3ea40b7810 tmpfiles: mostly revert 71044f609b
Add a comment why returning a positive error is OK and intended in this
case.

(It's still a nasty hack to do this though!)
2015-04-10 16:23:46 +02:00
Lennart Poettering 2ff7b0a542 util: unify how we parse mode_t strings 2015-04-10 16:23:46 +02:00
Lennart Poettering 71044f609b tmpfiles: properly return error code from path_set_acl() 2015-04-09 13:13:07 +02:00
Lennart Poettering 34f6453603 tmpfiles: add file attribute calls to list of glob needing commands 2015-04-09 13:13:07 +02:00
Lennart Poettering 88ec4dfa28 tmpfiles: rework file attribute code
- Stick to one type for the flags field: unsigned. This appears to be
  what the kernel uses, and there's no point in using something else.

- compress the flags array by avoiding sparse entries

- extend some error messages to not use abbreviated words

- avoid TTOCTTOU issues by invoking fstat() after open() when applying
  file flags

- add explanation why we need to check the file type with fstat().

- don't needlessly abbreviate "attribute" as "attrib", in particually as
  "chattr" abbreviates it as "attr" rather than "attrib".
2015-04-08 22:35:52 +02:00
Lennart Poettering 1ed8f8c16d util: merge change_attr_fd() and chattr_fd() 2015-04-08 20:47:35 +02:00
Lennart Poettering 527b7a421f util: rework cunescape(), improve error handling
Change cunescape() to return a normal error code, so that we can
distuingish OOM errors from parse errors.

This also adds a flags parameter to control whether "relaxed" or normal
parsing shall be done. If set no parse failures are generated, and the
only reason why cunescape() can fail is OOM.
2015-04-07 15:42:25 +02:00
Lennart Poettering c687863750 util: rework rm_rf() logic
- Move to its own file rm-rf.c

- Change parameters into a single flags parameter

- Remove "honour sticky" logic, it's unused these days
2015-04-06 10:57:53 +02:00
Lennart Poettering 4034a06ddb util: rework word parsing and c unescaping code
When parsing words from input files, optionally automatically unescape
the passed strings, controllable via a new flags parameter.

Make use of this in tmpfiles, and port everything else over, too.

This improves parsing quite a bit, since we no longer have to process the
same string multiple times with different calls, where an earlier call
might corrupt the input for a later call.
2015-03-26 11:56:22 +01:00
Lennart Poettering 1532227a19 tmpfiles: minor simplification 2015-03-26 11:56:22 +01:00
Thomas Hindoe Paaboel Andersen a4135d3234 tmpfiles: avoid out of bounds read
Otherwise this will go wrong for 'v'.
2015-03-24 23:53:09 +01:00
Goffredo Baroncelli 22c3a6cadb Allow systemd-tmpfiles to set the file/directory attributes
Allow systemd-tmpfiles to set the file/directory attributes, like
chattr(1) does. Two more commands are added: 'H' and 'h' to set the
attributes, recursively and not.
2015-03-19 22:20:12 -04:00
Zbigniew Jędrzejewski-Szmek 51bfdaf66c tmpfiles: remove redundant debug message
Mar 13 19:48:30 adam.happyassassin.net systemd-tmpfiles[970]: "/var/lib/machines" has right mode 40700
Mar 13 19:48:30 adam.happyassassin.net systemd-tmpfiles[970]: /var/lib/machines created successfully.
2015-03-14 23:03:21 -04:00
David Herrmann 15411c0cb1 tree-wide: there is no ENOTSUP on linux
Replace ENOTSUP by EOPNOTSUPP as this is what linux actually uses.
2015-03-13 14:10:39 +01:00
daurnimator 657cf7f4f8 tmpfiles: port to unquote_many_words() 2015-03-10 16:08:20 +01:00
Martin Pitt 6487ada88d tmpfiles: Fix handling of duplicate lines
Commit 3f93da987 accidentally dropped the "return 0" after detection of a
duplicate line. Put it back, to get back the documented and intended "first
match wins" behaviour.

https://launchpad.net/bugs/1428540
2015-03-05 16:14:07 +01:00
Hans-Peter Deifel d873e8778c tmpfiles: quietly ignore ACLs on unsupported filesystems
A warning is printed if ACLs cannot be retrieved for any reason other
than -ENOSYS. For -ENOSYS, debug log is printed.
2015-03-03 10:17:17 -05:00
Thomas Hindoe Paaboel Andersen 2eec67acbb remove unused includes
This patch removes includes that are not used. The removals were found with
include-what-you-use which checks if any of the symbols from a header is
in use.
2015-02-23 23:53:42 +01:00
Martin Pitt 484adfd914 tmpfiles: Fix parse_acl error message
parse_acl() returns the error instead of setting errno.
2015-02-17 12:47:51 +01:00
Zbigniew Jędrzejewski-Szmek 35888b67f7 tmpfiles: fix compilation without acl support 2015-02-03 21:28:46 -05:00
Thomas Hindoe Paaboel Andersen 4cd552bc50 partial revert of fed6df8
This one was acutally used to free xattr
2015-02-03 21:40:30 +01:00
Thomas Hindoe Paaboel Andersen fed6df828d remove unused variables 2015-02-02 22:58:06 +01:00
Lennart Poettering 7a7d5db71f tmpfiles: let's always use DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING() instead of defining our own string tables 2015-02-02 21:34:09 +01:00
Zbigniew Jędrzejewski-Szmek 294929f891 tmpfiles: accurately report creation results 2015-02-01 12:44:04 -05:00
Zbigniew Jędrzejewski-Szmek 612532206c tmpfiles: remove dead branch
In the test, p is a path to a directory, always absolute. dent->d_name
is a single path component, so they cannot be equal. The comparison
was wrong also for other reasons: D type supports globs, so direct
comparisons using streq are not enough.
2015-02-01 12:44:04 -05:00
Zbigniew Jędrzejewski-Szmek 79ca888f5a tmpfiles: fix help text
The help text, apart from being too long, did not describe what the options
really do.
2015-01-27 21:48:12 -05:00
Zbigniew Jędrzejewski-Szmek ebf31a1f58 tmpfiles: use casts instead of warning suppression
This warning got its own name only in gcc5, so the suppression does
not work in gcc4, and generates a warning of its own. Use a cast,
which is ugly too, but less so.
2015-01-26 10:39:03 -05:00
Zbigniew Jędrzejewski-Szmek df99a9ef5b tmpfiles: do not bump access times of directories we are cleaning up
Both plain opendir() and glob() will bump access time. Privileged
option O_NOATIME can be used to prevent the access time from being
updated. We already used it for subdirectories of the directories
which we were cleaning up. But for the directories specified directly
in the config files, we wouldn't do that. This means that,
paradoxically, our own temporary directories for PrivateTmp would stay
around forever, as long as one let systemd-tmpfiles-clean.service run
regularly, because they had their own glob patterns specified.

https://bugzilla.redhat.com/show_bug.cgi?id=1183684
2015-01-24 23:38:59 -05:00
Zbigniew Jędrzejewski-Szmek 582deb8446 tmpfiles: add debug statements for all actions
systemd-tmpfiles can be used by users, but it can be quite hard to
figure out the logic it follows, especially since the logic is in some
places rather torturous. Hopefuly this will make it easier for users
to understand what is happening.
2015-01-24 23:38:44 -05:00
Zbigniew Jędrzejewski-Szmek 7fcb4b9b17 tmpfiles: minor simplification 2015-01-23 00:12:52 -05:00
Zbigniew Jędrzejewski-Szmek dd4105b0a9 shared/acl-util: add mask only when needed, always add base ACLs
For ACLs to be valid, a set of entries for user, group, and other
must be always present. Always add those entries.

While at it, only add the mask ACL if it is actually required, i.e.
when at least on ACL for non-owner group or user exists.
2015-01-22 01:14:53 -05:00
Zbigniew Jędrzejewski-Szmek 50d9e46dbb tmpfiles: implement augmenting of existing ACLs
This is much more useful in practice (equivalent to setfacl -m).
2015-01-22 01:14:53 -05:00
Zbigniew Jędrzejewski-Szmek b705ab6a83 tmpfiles: make t and a globby, add their recursive versions T and A
For types which adapt existing files it is generally more useful to accept
globs.

In analogy to z and Z, add recursive versions using uppercase letters.

Technically, making a accept globs is backwards incompatible, but in
practice it probably isn't yet widely used and we can assume that most
people don't create files with wildcards in names.

Functions which are used as callbacks, but not directly on items, are
renamed not to have "item_" prefix.
2015-01-22 01:14:53 -05:00
Zbigniew Jędrzejewski-Szmek 081043cf06 tmpfiles: make recursive operation generic 2015-01-22 01:14:53 -05:00
Zbigniew Jędrzejewski-Szmek f8eeeaf9b7 tmpfiles: add 'a' type to set ACLs 2015-01-22 01:14:53 -05:00
Zbigniew Jędrzejewski-Szmek 3f93da9879 tmpfiles: attach an array of items to each path
The data structure used by tmpfiles is changed: instead of hashmaps
mapping {path → Item*} we now have hashmaps containing
{path -> ItemArray}, where ItemArray contains a pointer
to an array of Items.

For current code it doesn't matter much, but when we add new types it
is easier to simply add a new Item for a given path, then to coalesce
multiple lines into one Item.

In the future, this change will also make it possible to remember the
file and line where each Item originates, and use that in reporting
errors. Currently this is not possible, since each Item can be created
from multiple lines.
2015-01-22 01:14:53 -05:00
Zbigniew Jędrzejewski-Szmek 222c47f476 tmpfiles: make sure not to concatenate non-absolute path
If the path is absolute was only checked later.
Also do not check if path if absolute if we just
specified it starting with a slash.
2015-01-22 01:14:52 -05:00
Zbigniew Jędrzejewski-Szmek 5f255144ae tmpfiles: detect all combinations of + and !
The same algorithm as with - and @ in ExecStart= is used.
2015-01-22 01:14:52 -05:00
Zbigniew Jędrzejewski-Szmek 505ef0e36c tmpfiles: simplification
Certain conditions were checked more than once. Warning message
is improved.
2015-01-22 01:14:52 -05:00
Zbigniew Jędrzejewski-Szmek 2695c5c44e Add initialization helper for file_handle_union 2015-01-18 19:06:48 -05:00
Lennart Poettering 1e95893a89 tmpfiles: make gcc shut up 2015-01-06 20:33:46 +01:00
Zbigniew Jędrzejewski-Szmek 1db50423ba tmpfiles: finish with EXIT_FAILURE if anything failed
Return value is successful only if everything succeeded.
2015-01-06 09:57:40 -05:00
Lennart Poettering 65d6d8e32b tmpfiles: fix 'D' lines
https://bugs.freedesktop.org/show_bug.cgi?id=87953
2015-01-05 16:32:59 +01:00
Lennart Poettering d7b8eec7dc tmpfiles: add new line type 'v' for creating btrfs subvolumes 2014-12-28 02:08:40 +01:00
Filipe Brandenburger 2395eb17eb tmpfiles: remove spurious include of <sys/capability.h>
It does not use any functions from libcap directly. The CAP_MKNOD constant in
use by this file comes from <linux/capability.h> imported through "missing.h".

Tested that "systemd-tmpfiles" builds cleanly and works after this change.
2014-12-25 10:56:21 -05:00
Maciej Wereski ebf4e8013b tmpfiles, man: Add xattr support to tmpfiles
This patch makes it possible to set extended attributes on files created
by tmpfiles. This can be especially used to set SMACK security labels on
volatile files and directories.

It is done by adding new line of type "t". Such line should contain
attributes in Argument field, using following format:

name=value

All other fields are ignored.

If value contains spaces, then it must be surrounded by quotation marks.
User can also put quotation mark in value by escaping it with backslash.

Example:
D /var/run/cups - - - -
t /var/run/cups - - - - security.SMACK64=printing
2014-12-04 20:21:45 +01:00
Lennart Poettering fed1e721fd treewide: introduce UID_INVALID (and friends) as macro for (uid_t) -1 2014-11-28 20:55:04 +01:00
Michal Schmidt 4a62c710b6 treewide: another round of simplifications
Using the same scripts as in f647962d64 "treewide: yet more log_*_errno
+ return simplifications".
2014-11-28 19:57:32 +01:00
Michal Schmidt 56f64d9576 treewide: use log_*_errno whenever %m is in the format string
If the format string contains %m, clearly errno must have a meaningful
value, so we might as well use log_*_errno to have ERRNO= logged.

Using:
find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\((".*%m.*")/log_\1_errno(errno, \2/'

Plus some whitespace, linewrap, and indent adjustments.
2014-11-28 19:49:27 +01:00
Michal Schmidt 8d3d7072e6 treewide: a few more log_*_errno + return simplifications
The one in tmpfiles.c:create_item() even looks like it fixes a bug.
2014-11-28 19:17:24 +01:00