]> git.ipfire.org Git - thirdparty/systemd.git/log
thirdparty/systemd.git
3 years agogetty-generator: use extract_first_word()
Zbigniew Jędrzejewski-Szmek [Fri, 31 Jul 2020 09:47:03 +0000 (11:47 +0200)] 
getty-generator: use extract_first_word()

3 years agosd-journal: use extract_first_word()
Zbigniew Jędrzejewski-Szmek [Fri, 31 Jul 2020 09:38:08 +0000 (11:38 +0200)] 
sd-journal: use extract_first_word()

3 years agodelta: use extract_first_word()
Zbigniew Jędrzejewski-Szmek [Fri, 31 Jul 2020 09:28:11 +0000 (11:28 +0200)] 
delta: use extract_first_word()

3 years agocryptsetup: use extract_first_word()
Zbigniew Jędrzejewski-Szmek [Fri, 31 Jul 2020 09:23:44 +0000 (11:23 +0200)] 
cryptsetup: use extract_first_word()

3 years agocore/load-fragment: use extract_first_word()
Zbigniew Jędrzejewski-Szmek [Fri, 31 Jul 2020 09:19:25 +0000 (11:19 +0200)] 
core/load-fragment: use extract_first_word()

This is much nicer, and also fixes a potential overflow when we used
'word' in log_error() as if it was a NUL-terminated string.

3 years agoLet sd_machine_get_ifindices() omit the output param too
Zbigniew Jędrzejewski-Szmek [Thu, 30 Jul 2020 11:08:52 +0000 (13:08 +0200)] 
Let sd_machine_get_ifindices() omit the output param too

Nowadays we do that almost everywhere, let's also do it here.

3 years agoRewrite sd_machine_get_ifindices() to avoid FOREACH_WORD()
Zbigniew Jędrzejewski-Szmek [Thu, 30 Jul 2020 10:56:51 +0000 (12:56 +0200)] 
Rewrite sd_machine_get_ifindices() to avoid FOREACH_WORD()

If we fail to parse the index, the failure is propogated as -EUNCLEAN.
(-EINVAL would be confused with invalid args to the function itself.)

3 years agoFix output value of sd_seat_get_sessions() and drop FOREACH_WORD use
Zbigniew Jędrzejewski-Szmek [Thu, 30 Jul 2020 10:43:07 +0000 (12:43 +0200)] 
Fix output value of sd_seat_get_sessions() and drop FOREACH_WORD use

sd_seat_get_sessions() would return 0 in the 'n_uids' (now 'ret_n_uids') output
parameter when 'uid' (now 'ret_uids') was passed as NULL.

While at it, drop FOREACH_WORD() use.

Also use any whitespace as separator. In practice this shouldn't matter, since
logind always uses spaces, but it seems nicer to not specify this explicitly,
and the default is more flexible.

3 years agosd-device: use extract_first_word()
Zbigniew Jędrzejewski-Szmek [Wed, 29 Jul 2020 10:09:08 +0000 (12:09 +0200)] 
sd-device: use extract_first_word()

3 years agobasic/cgroup-util: port over to string_contains_word()
Zbigniew Jędrzejewski-Szmek [Wed, 29 Jul 2020 10:01:21 +0000 (12:01 +0200)] 
basic/cgroup-util: port over to string_contains_word()

3 years agologind: use extract_first_word()
Zbigniew Jędrzejewski-Szmek [Wed, 29 Jul 2020 09:47:38 +0000 (11:47 +0200)] 
logind: use extract_first_word()

3 years agoshared/sleep-config: more logging and port to extract_first_word()
Zbigniew Jędrzejewski-Szmek [Wed, 29 Jul 2020 09:34:10 +0000 (11:34 +0200)] 
shared/sleep-config: more logging and port to extract_first_word()

3 years agoAdd string_contains_word_strv()
Zbigniew Jędrzejewski-Szmek [Thu, 30 Jul 2020 08:34:44 +0000 (10:34 +0200)] 
Add string_contains_word_strv()

I had to move STRV_MAKE to macro.h. There is a circular dependency between
extract-word.h, strv.h, and string-util.h that makes it hard to define the
inline function otherwise.

3 years agosd-login: use string_contains_word()
Zbigniew Jędrzejewski-Szmek [Wed, 29 Jul 2020 14:05:45 +0000 (16:05 +0200)] 
sd-login: use string_contains_word()

3 years agobasic: add string_contains_word()
Zbigniew Jędrzejewski-Szmek [Wed, 29 Jul 2020 12:06:26 +0000 (14:06 +0200)] 
basic: add string_contains_word()

This wraps the common pattern of using extract_first_word() in a loop
to look for a matching word.

3 years agotest-string-util,test-extract-word: add log headers
Zbigniew Jędrzejewski-Szmek [Thu, 30 Jul 2020 09:31:03 +0000 (11:31 +0200)] 
test-string-util,test-extract-word: add log headers

3 years agoMerge pull request #16881 from yuwata/network-routing-policy-rule-cleanups
Zbigniew Jędrzejewski-Szmek [Fri, 4 Sep 2020 10:57:20 +0000 (12:57 +0200)] 
Merge pull request #16881 from yuwata/network-routing-policy-rule-cleanups

network: routing policy rule cleanups

3 years agoMerge pull request #16952 from yuwata/resolvectl-log-level-follow-ups
Zbigniew Jędrzejewski-Szmek [Fri, 4 Sep 2020 10:21:15 +0000 (12:21 +0200)] 
Merge pull request #16952 from yuwata/resolvectl-log-level-follow-ups

resolvectl: update help message

3 years agonetwork: fixes gateway assignment through DHCPv4
Yu Watanabe [Wed, 26 Aug 2020 13:31:01 +0000 (22:31 +0900)] 
network: fixes gateway assignment through DHCPv4

This fixes the following issue:
- If a DHCP lease does not contains router option, then routes with
`Gateway=_dhcp` setting introduce unexpected results.

This also makes several failure paths critical. And adjust warnings when
classless routes are provided.

3 years agobash-completion: resolvectl: support 'log-level' command 16952/head
Yu Watanabe [Fri, 4 Sep 2020 08:03:28 +0000 (17:03 +0900)] 
bash-completion: resolvectl: support 'log-level' command

3 years agoresolvectl: add 'log-level' to help message
Yu Watanabe [Fri, 4 Sep 2020 07:58:32 +0000 (16:58 +0900)] 
resolvectl: add 'log-level' to help message

Follow-up for df9578498f3f566409fcb71229d9fc99e4ab0568.

3 years agoresolved: ttl/hopcount sockopt is not a boolean
Lennart Poettering [Thu, 3 Sep 2020 21:52:27 +0000 (23:52 +0200)] 
resolved: ttl/hopcount sockopt is not a boolean

These are integer values, hence specify them as integers, not as
booleans.

3 years agonetwork: logs about unknown key 16881/head
Yu Watanabe [Fri, 28 Aug 2020 04:00:25 +0000 (13:00 +0900)] 
network: logs about unknown key

3 years agonetwork: honor already specified family when parsing from= or to= in serialized rule
Yu Watanabe [Fri, 28 Aug 2020 03:58:49 +0000 (12:58 +0900)] 
network: honor already specified family when parsing from= or to= in serialized rule

3 years agonetwork: do not reallocate buffer
Yu Watanabe [Fri, 28 Aug 2020 03:53:08 +0000 (12:53 +0900)] 
network: do not reallocate buffer

3 years agonetwork: serialize InvertRule= in [RoutingPolicyRule]
Yu Watanabe [Fri, 28 Aug 2020 03:47:44 +0000 (12:47 +0900)] 
network: serialize InvertRule= in [RoutingPolicyRule]

3 years agonetwork: add whitespace after family= and priority= in serialized routing policy...
Yu Watanabe [Fri, 28 Aug 2020 03:34:36 +0000 (12:34 +0900)] 
network: add whitespace after family= and priority= in serialized routing policy rule

This also makes priority= serialized only when its value is non-zero.

3 years agonetwork: downgrade error level when the error is ignored
Yu Watanabe [Thu, 3 Sep 2020 23:44:14 +0000 (08:44 +0900)] 
network: downgrade error level when the error is ignored

3 years agonetwork: move routing_policy_rule_read_full_file()
Yu Watanabe [Fri, 28 Aug 2020 03:27:32 +0000 (12:27 +0900)] 
network: move routing_policy_rule_read_full_file()

3 years agoMerge pull request #16044 from ssahani/resolved-interface
Zbigniew Jędrzejewski-Szmek [Thu, 3 Sep 2020 17:06:05 +0000 (19:06 +0200)] 
Merge pull request #16044 from ssahani/resolved-interface

systemd-resolved: allow configurable bind address

3 years agoMerge pull request #16945 from poettering/udev-test-selinux
Lennart Poettering [Thu, 3 Sep 2020 16:39:28 +0000 (18:39 +0200)] 
Merge pull request #16945 from poettering/udev-test-selinux

fix udev-test when used with selinux

3 years agoudev-test: don't mix alloca() and regular C stack allocation in one expression 16945/head
Lennart Poettering [Thu, 3 Sep 2020 14:56:47 +0000 (16:56 +0200)] 
udev-test: don't mix alloca() and regular C stack allocation in one expression

3 years agoudev-test: use SYNTHETIC_ERRNO() where useful
Lennart Poettering [Thu, 3 Sep 2020 14:56:30 +0000 (16:56 +0200)] 
udev-test: use SYNTHETIC_ERRNO() where useful

3 years agoudev-test: use mount_verbose() instead of mount(), to make debugging easier
Lennart Poettering [Thu, 3 Sep 2020 14:56:07 +0000 (16:56 +0200)] 
udev-test: use mount_verbose() instead of mount(), to make debugging easier

3 years agoudev-test: make sure we run udev tests with selinux assumed off
Lennart Poettering [Thu, 3 Sep 2020 14:53:22 +0000 (16:53 +0200)] 
udev-test: make sure we run udev tests with selinux assumed off

This is cleaner that way given that we create our own half-virtualizes
device tree, and really shouldn't pull selinux labelling and access
control into that, we can only lose, in particular as our overmounted
/sys/ actually lacks /sys/fs/selinux.

(This fixes udev test woes introduced by #16821 where suddenly the test
would fail because libselinux assumed selinux was on, but selinuxfs
wasn't actually available)

3 years agoMerge pull request #16915 from poettering/cryptsetup-dlopen
Lennart Poettering [Thu, 3 Sep 2020 12:57:29 +0000 (14:57 +0200)] 
Merge pull request #16915 from poettering/cryptsetup-dlopen

pid1,repart,growfs: make libcryptsetup a dlopen() style dep

3 years agoMerge pull request #16821 from cgzones/selinux_status
Lennart Poettering [Thu, 3 Sep 2020 12:55:08 +0000 (14:55 +0200)] 
Merge pull request #16821 from cgzones/selinux_status

 selinux: use SELinux status page

3 years agoMerge pull request #16940 from keszybz/socket-enotconn-cleanup
Lennart Poettering [Thu, 3 Sep 2020 12:51:02 +0000 (14:51 +0200)] 
Merge pull request #16940 from keszybz/socket-enotconn-cleanup

Cleanup socket enotconn handling

3 years agoresolve: allow configurable bind address 16044/head
Susant Sahani [Sat, 29 Aug 2020 07:12:10 +0000 (07:12 +0000)] 
resolve: allow configurable bind address

3 years agohwdb: Add Adesso AKB-805MAC keyboard, mfd by Ortek
Glen Whitney [Thu, 3 Sep 2020 00:38:38 +0000 (17:38 -0700)] 
hwdb: Add Adesso AKB-805MAC keyboard, mfd by Ortek

3 years agofirstboot: don't create/modify passwd and shadow if not asked
afg [Tue, 1 Sep 2020 21:47:49 +0000 (05:47 +0800)] 
firstboot: don't create/modify passwd and shadow if not asked

3 years agocore/socket: use _cleanup_ to close the connection fd 16940/head
Zbigniew Jędrzejewski-Szmek [Wed, 2 Sep 2020 16:17:14 +0000 (18:17 +0200)] 
core/socket: use _cleanup_ to close the connection fd

Removing the gotos would lead to a lot of duplicated code, so I left them
as they were.

3 years agocore/socket: fold socket_instantiate_service() into socket_enter_running()
Zbigniew Jędrzejewski-Szmek [Wed, 2 Sep 2020 16:04:10 +0000 (18:04 +0200)] 
core/socket: fold socket_instantiate_service() into socket_enter_running()

socket_instantiate_service() was doing unit_ref_set(), and the caller was
immediately doing unit_ref_unset(). After we get rid of this, it doesn't seem
worth it to have two functions.

3 years agocore/socket: we may get ENOTCONN from socket_instantiate_service()
Zbigniew Jędrzejewski-Szmek [Tue, 1 Sep 2020 21:50:01 +0000 (23:50 +0200)] 
core/socket: we may get ENOTCONN from socket_instantiate_service()

This means that the connection was aborted before we even got to figure out
what the service name will be. Let's treat this as a non-event and close the
connection fd without any further messages.

Code last changed in 934ef6a5.
Reported-by: Thiago Macieira <thiago.macieira@intel.com>
With the patch:
systemd[1]: foobar.socket: Incoming traffic
systemd[1]: foobar.socket: Got ENOTCONN on incoming socket, assuming aborted connection attempt, ignoring.
...

Also, when we get ENOMEM, don't give the hint about missing unit.

3 years agohomed: remember the secret even when the for_state is FIXATING_FOR_ACQUIRE
Gibeom Gwon [Wed, 26 Aug 2020 13:56:01 +0000 (22:56 +0900)] 
homed: remember the secret even when the for_state is FIXATING_FOR_ACQUIRE

Remember the secret if the for_state is FIXATING_FOR_ACTIVATION or
FIXATING_FOR_ACQUIRE. This fixes login failures when logging in
to an unfixated user.

3 years agoupdate TODO 16915/head
Lennart Poettering [Mon, 31 Aug 2020 16:22:54 +0000 (18:22 +0200)] 
update TODO

3 years agoshared: make libcryptsetup dep dlopen
Lennart Poettering [Fri, 28 Aug 2020 19:27:45 +0000 (21:27 +0200)] 
shared: make libcryptsetup dep dlopen

Let's make libcryptsetup a dlopen() style dep for PID 1 (i.e. for
RootImage= and stuff), systemd-growfs and systemd-repart. (But leave to
be a regulra dep in systemd-cryptsetup, systemd-veritysetup and
systemd-homed since for them the libcryptsetup support is not auxiliary
but pretty much at the core of what they do.)

This should be useful for container images that want systemd in the
payload but don't care for the cryptsetup logic since dm-crypt and stuff
isn't available in containers anyway.

Fixes: #8249
3 years agoshared: rename crypt-util.c → cryptsetup-util.c
Lennart Poettering [Fri, 28 Aug 2020 19:26:33 +0000 (21:26 +0200)] 
shared: rename crypt-util.c → cryptsetup-util.c

"crypt-util.c" is such a generic name, let's avoid that, in particular
as libc's/libcrypt's crypt() function is so generically named too that
one might thing this is about that. Let's hence be more precise, and
make clear that this is about cryptsetup, and nothing else.

We already had cryptsetup-util.[ch] in src/cryptsetup/ doing keyfile
management. To avoid the needless confusion, let's rename that file to
cryptsetup-keyfile.[ch].

3 years agoselinux/systemctl: create unit file with default context on edit
Christian Göttsche [Tue, 1 Sep 2020 15:45:11 +0000 (17:45 +0200)] 
selinux/systemctl: create unit file with default context on edit

3 years agoimport: make sure gnu tar complains on tar files with trailing garbage
Lennart Poettering [Tue, 1 Sep 2020 18:08:49 +0000 (20:08 +0200)] 
import: make sure gnu tar complains on tar files with trailing garbage

By default GNU tar will only read the first archive if multiple archives
are concatenated and ignore the rest. If an archive contains trailing
garbage this will hence not be recognized by tar as error, it simply
stops reading when the first archive is done (which might escalate to
SIGPIPE when invoked via a pipe).

Let's add --ignore-zeros to the tar command line when extracting. This
means:

1) if a tar archive was concatenated (i.e. generated with tar -A) we'll
   process it correctly.

2) if a tar archive contains trailing garbage tar will now generate an
   error message about it, instead of just throwing EPIPE, which makes
   things easier to debug as broken files are not silently processed.

I think it's OK for gnu tar to ignore trailing garbage when dealing with
classic tapes drives, i.e. mediums that do not have a size limit
built-in. However, this is not what we are dealing with: we are dealing
with OS images here, that hopefully someone generated with a clean build
system, that were signed and validated and hence should not contain
trailing garbage.  Hence it's better to refuse and complain thant to
silently eat up like for classic tape drives.

Fixes: #16605
3 years agonspawn: let's make LinkJournal an extended boolean
Lennart Poettering [Tue, 1 Sep 2020 21:26:50 +0000 (23:26 +0200)] 
nspawn: let's make LinkJournal an extended boolean

Let's accept the usual boolean parameters for LinkJournal. It's
confusing otherwise.

Previously we'd accept "no" but not the other values we typically accept
for "false". We'd not accept any values for "true".

With this change we'll accept all true and false values and will do
something somewhat reasonable: any false value is treated like "no"
previously was reated. And any true value is now treated like "auto".

We don't document the new values, since this logic is mostly redundant,
and it's probably better if people consider this an enum rather than a
bool.

Fixes: #16888
3 years agoMerge pull request #16882 from weblate/weblate-systemd-master
Zbigniew Jędrzejewski-Szmek [Wed, 2 Sep 2020 06:55:40 +0000 (08:55 +0200)] 
Merge pull request #16882 from weblate/weblate-systemd-master

Translations update from Weblate

3 years agoMerge pull request #16853 from poettering/udev-current-tag2
Zbigniew Jędrzejewski-Szmek [Wed, 2 Sep 2020 06:12:56 +0000 (08:12 +0200)] 
Merge pull request #16853 from poettering/udev-current-tag2

udev: make uevents "sticky"

3 years agocoredump: don't convert s → µs twice
Lennart Poettering [Tue, 1 Sep 2020 18:29:28 +0000 (20:29 +0200)] 
coredump: don't convert s → µs twice

We already append 000000 early on when parsing the cmdline args, let's
not do that a second time.

Fixes: #16919
3 years agofirstboot: fill empty color if ansi_color unavailable from os-release
afg [Tue, 1 Sep 2020 21:20:25 +0000 (05:20 +0800)] 
firstboot: fill empty color if ansi_color unavailable from os-release

3 years agoshared: Introduce socket_addr_port_from_string_auto
Susant Sahani [Fri, 28 Aug 2020 10:39:40 +0000 (10:39 +0000)] 
shared: Introduce socket_addr_port_from_string_auto

3 years agoMerge pull request #16925 from cgzones/selinux_create_label
Zbigniew Jędrzejewski-Szmek [Tue, 1 Sep 2020 20:19:52 +0000 (22:19 +0200)] 
Merge pull request #16925 from cgzones/selinux_create_label

selinux/core: create several file objects with default SELinux context

3 years agoMerge pull request #16911 from keszybz/userdb-json-invalid-utf8
Lennart Poettering [Tue, 1 Sep 2020 18:34:22 +0000 (20:34 +0200)] 
Merge pull request #16911 from keszybz/userdb-json-invalid-utf8

Deal properly with invalid utf-8 in userdb entries

3 years agoMerge pull request #16922 from keszybz/ordered-set-ensure-allocated
Zbigniew Jędrzejewski-Szmek [Tue, 1 Sep 2020 17:44:28 +0000 (19:44 +0200)] 
Merge pull request #16922 from keszybz/ordered-set-ensure-allocated

Ordered set ensure allocated

3 years agoman: document the new libudev APIs 16853/head
Lennart Poettering [Wed, 26 Aug 2020 16:30:52 +0000 (18:30 +0200)] 
man: document the new libudev APIs

3 years agoNEWS: explain the "bind"/"unbind" situation a bit
Lennart Poettering [Thu, 13 Dec 2018 18:13:59 +0000 (19:13 +0100)] 
NEWS: explain the "bind"/"unbind" situation a bit

3 years agologind: always check current tag list before using a device
Lennart Poettering [Thu, 13 Dec 2018 17:36:57 +0000 (18:36 +0100)] 
logind: always check current tag list before using a device

3 years agologind: only apply ACLs for device currently tagged with "uaccess"
Lennart Poettering [Thu, 13 Dec 2018 17:35:06 +0000 (18:35 +0100)] 
logind: only apply ACLs for device currently tagged with "uaccess"

This is about security, hence let's be particularly careful here: only
devices currenlty tagged with "uaccess" will get ACL management, and
it's not sufficient if they once were (though that is used for
filtering).

3 years agocore: make sure to recheck current udev tag "systemd" before considering a device...
Lennart Poettering [Thu, 13 Dec 2018 17:32:03 +0000 (18:32 +0100)] 
core: make sure to recheck current udev tag "systemd" before considering a device ready

Let's ensure that a device once tagged can become active/inactive simply
by toggling the current tag.

Note that this means that a device once tagged with "systemd" will
always have a matching .device unit. However, the active/inactive state
of the unit reflects whether it is currently tagged that way (and
doesn't have SYSTEMD_READY=0 set).

Fixes: #7587
3 years agotest: add test for new "sticky" tags logic
Lennart Poettering [Thu, 13 Dec 2018 16:22:01 +0000 (17:22 +0100)] 
test: add test for new "sticky" tags logic

3 years agolibudev: also expose API to check for current tags in libudev
Lennart Poettering [Thu, 13 Dec 2018 17:08:45 +0000 (18:08 +0100)] 
libudev: also expose API to check for current tags in libudev

3 years agoudev: make tags "sticky"
Lennart Poettering [Thu, 13 Dec 2018 16:55:14 +0000 (17:55 +0100)] 
udev: make tags "sticky"

This tries to address the "bind"/"unbind" uevent kernel API breakage, by
changing the semantics of device tags.

Previously, tags would be applied on uevents (and the database entries
they result in) only depending on the immediate context. This means that
if one uevent causes the tag to be set and the next to be unset, this
would immediately effect what apps would see and the database entries
would contain each time. This is problematic however, as tags are a
filtering concept, and if tags vanish then clients won't hence notice
when a device stops being relevant to them since not only the tags
disappear but immediately also the uevents for it are filtered including
the one necessary for the app to notice that the device lost its tag and
hence relevance.

With this change tags become "sticky". If a tag is applied is once
applied to a device it will stay in place forever, until the device is
removed. Tags can never be removed again. This means that an app
watching a specific set of devices by filtering for a tag is guaranteed
to not only see the events where the tag is set but also all follow-up
events where the tags might be removed again.

This change of behaviour is unfortunate, but is required due to the
kernel introducing new "bind" and "unbind" uevents that generally have
the effect that tags and properties disappear and apps hence don't
notice when a device looses relevance to it. "bind"/"unbind" events were
introduced in kernel 4.12, and are now used in more and more subsystems.
The introduction broke userspace widely, and this commit is an attempt
to provide a way for apps to deal with it.

While tags are now "sticky" a new automatic device property
CURRENT_TAGS is introduced (matching the existing TAGS property) that
always reflects the precise set of tags applied on the most recent
events. Thus, when subscribing to devices through tags, all devices that
ever had the tag put on them will be be seen, and by CURRENT_TAGS it may
be checked whether the device right at the moment matches the tag
requirements.

See: #7587 #7018 #8221

3 years agotest-functions: make sure we test our own libudev instead of the host libudev
Lennart Poettering [Wed, 26 Aug 2020 16:47:11 +0000 (18:47 +0200)] 
test-functions: make sure we test our own libudev instead of the host libudev

When invoking "ldd" to find dependency libraries we already set
$LD_LIBRARY_PATH to point to our own build tree, so that our libraries
are checked, not the host libraries. This is not sufficient howeever, as
libudev is built in a subdir. Add that, too.

3 years agoMerge pull request #16727 from wusto/core-fix-securebits
Lennart Poettering [Tue, 1 Sep 2020 15:21:48 +0000 (17:21 +0200)] 
Merge pull request #16727 from wusto/core-fix-securebits

core: fix securebits setting

3 years agosocket: New option 'FlushPending' (boolean) to flush socket before entering listening...
Renaud Métrich [Thu, 20 Aug 2020 11:00:37 +0000 (13:00 +0200)] 
socket: New option 'FlushPending' (boolean) to flush socket before entering listening state

Disabled by default. When Enabled, before listening on the socket, flush the content.
Applies when Accept=no only.

3 years agoTODO: add entry 16911/head
Zbigniew Jędrzejewski-Szmek [Mon, 31 Aug 2020 11:01:23 +0000 (13:01 +0200)] 
TODO: add entry

3 years agouser-record-nss: check if strings from pwd/spwd/grp/sgrp are valid utf-8
Zbigniew Jędrzejewski-Szmek [Sun, 30 Aug 2020 18:34:12 +0000 (20:34 +0200)] 
user-record-nss: check if strings from pwd/spwd/grp/sgrp are valid utf-8

strv_extend_strv_utf8_only() uses a temporary buffer to make the implementation
conscise. Otherwise we'd have to rewrite all of strv_extend_strv() which didn't
seem worth the trouble for this one use outside of a hot path.

If the data is not serializable, we just pretend it doesn't exists.
This fixes #16683 and https://bugs.gentoo.org/735072 in a second way.

3 years agoshared: merge {user,group}-record-nss.{c,h}
Zbigniew Jędrzejewski-Szmek [Sun, 30 Aug 2020 19:25:12 +0000 (21:25 +0200)] 
shared: merge {user,group}-record-nss.{c,h}

They both are both short and contain similar parts and various helper will be
shared between both parts of the code so it's easier to use a single file.

3 years agotest-json: add function headers
Zbigniew Jędrzejewski-Szmek [Tue, 1 Sep 2020 07:29:13 +0000 (09:29 +0200)] 
test-json: add function headers

3 years agoshared/json: reject non-utf-8 strings
Zbigniew Jędrzejewski-Szmek [Sun, 30 Aug 2020 17:52:10 +0000 (19:52 +0200)] 
shared/json: reject non-utf-8 strings

JSON strings must be utf-8-clean. We also verify this in json_parse_string()
so we would reject a message with invalid utf-8 anyway.

It would probably be slightly cheaper to detect non-conformaning strings in
serialization, but then we'd have to fail serialization. By doing this early,
we give the caller a chance to handle the error nicely.

The test is adjusted to contain a valid utf-8 string after decoding of the
utf-32 encoding in json ("विवेकख्यातिरविप्लवा हानोपायः।", something about the
cessation of ignorance).

3 years agoshared/utf8: add utf8_is_valid_n()
Zbigniew Jędrzejewski-Szmek [Tue, 1 Sep 2020 08:43:21 +0000 (10:43 +0200)] 
shared/utf8: add utf8_is_valid_n()

Sometimes we need to check strings without the terminating NUL. Add a variant
that does that.

3 years agoMerge pull request #16877 from poettering/tmpfiles-statx
Zbigniew Jędrzejewski-Szmek [Tue, 1 Sep 2020 14:32:50 +0000 (16:32 +0200)] 
Merge pull request #16877 from poettering/tmpfiles-statx

tmpfiles: use statx()

3 years agoselinux: create /run/systemd/userdb directory and sockets with default SELinux context 16925/head
Christian Göttsche [Tue, 1 Sep 2020 13:49:44 +0000 (15:49 +0200)] 
selinux: create /run/systemd/userdb directory and sockets with default SELinux context

3 years agoselinux: create systemd/notify socket with default SELinux context
Christian Göttsche [Tue, 1 Sep 2020 13:49:20 +0000 (15:49 +0200)] 
selinux: create systemd/notify socket with default SELinux context

3 years agodoc: cross link sd_listen_fd() docs a bit
Lennart Poettering [Mon, 31 Aug 2020 21:41:30 +0000 (23:41 +0200)] 
doc: cross link sd_listen_fd() docs a bit

Let's make sure the sd_listen_fd() docs are really found from the
.socket file documentation as well as the FileDescriptorStoreMax=
documentation.

Let's also emphasize that that's where the order in which the fds are
passed are documented.

Fixes: #16647
3 years agoselinux: create unit invocation links with default SELinux context
Christian Göttsche [Tue, 1 Sep 2020 13:48:53 +0000 (15:48 +0200)] 
selinux: create unit invocation links with default SELinux context

3 years agobasic/hashmap,set: move pointer symbol adjactent to the returned value 16922/head
Zbigniew Jędrzejewski-Szmek [Tue, 1 Sep 2020 11:22:14 +0000 (13:22 +0200)] 
basic/hashmap,set: move pointer symbol adjactent to the returned value

I think this is nicer in general, and here in particular we have a lot
of code like:
 static inline IteratedCache* hashmap_iterated_cache_new(Hashmap *h) {
         return (IteratedCache*) _hashmap_iterated_cache_new(HASHMAP_BASE(h));
 }
and it's visually appealing to use the same whitespace in the function
signature and the cast in the body of the function.

3 years agobasic/hashmap,set: inline trivial set_iterate() wrapper
Zbigniew Jędrzejewski-Szmek [Tue, 1 Sep 2020 11:18:56 +0000 (13:18 +0200)] 
basic/hashmap,set: inline trivial set_iterate() wrapper

The compiler would do this to, esp. with LTO, but we can short-circuit the
whole process and make everything a bit simpler by avoiding the separate
definition.

(It would be nice to do the same for _set_new(), _set_ensure_allocated()
and other similar functions which are one-line trivial wrappers too. Unfortunately
that would require enum HashmapType to be made public, which we don't want
to do.)

3 years agobasic: pass allocation info for ordered_set_new() and introduce ordered_set_ensure_put()
Zbigniew Jędrzejewski-Szmek [Tue, 1 Sep 2020 10:42:35 +0000 (12:42 +0200)] 
basic: pass allocation info for ordered_set_new() and introduce ordered_set_ensure_put()

3 years agobasic: Introduce ordered_hashmap_ensure_put
Susant Sahani [Fri, 28 Aug 2020 10:38:18 +0000 (10:38 +0000)] 
basic: Introduce ordered_hashmap_ensure_put

3 years agocore: fix securebits setting 16727/head
Tobias Kaufmann [Mon, 31 Aug 2020 11:48:31 +0000 (13:48 +0200)] 
core: fix securebits setting

Desired functionality:
Set securebits for services started as non-root user.

Failure:
The starting of the service fails if no ambient capability shall be
raised.
... systemd[217941]: ...: Failed to set process secure bits: Operation
not permitted
... systemd[217941]: ...: Failed at step SECUREBITS spawning
/usr/bin/abc.service: Operation not permitted
... systemd[1]: abc.service: Failed with result 'exit-code'.

Reason:
For setting securebits the capability CAP_SETPCAP is required. However
the securebits (if no ambient capability shall be raised) are set after
setresuid.
When setresuid is invoked all capabilities are dropped from the
permitted, effective and ambient capability set. If the securebit
SECBIT_KEEP_CAPS is set the permitted capability set is retained, but
the effective and the ambient set are cleared.

If ambient capabilities shall be set, the securebit SECBIT_KEEP_CAPS is
added to the securebits configured in the service file and set together
with the securebits from the service file before setresuid is executed
(in enforce_user).
Before setresuid is executed the capabilities are the same as for pid1.
This means that all capabilities in the effective, permitted and
bounding set are set. Thus the capability CAP_SETPCAP is in the
effective set and the prctl(PR_SET_SECUREBITS, ...) succeeds.
However, if the secure bits aren't set before setresuid is invoked they
shall be set shortly after the uid change in enforce_user.
This fails as SECBIT_KEEP_CAPS wasn't set before setresuid and in
consequence the effective and permitted set was cleared, hence
CAP_SETPCAP is not set in the effective set (and cannot be raised any
longer) and prctl(PR_SET_SECUREBITS, ...) failes with EPERM.

Proposed solution:
The proposed solution consists of three parts
1. Check in enforce_user, if securebits are configured in the service
   file. If securebits are configured, set SECBIT_KEEP_CAPS
   before invoking setresuid.
2. Don't set any other securebits than SECBIT_KEEP_CAPS in enforce_user,
   but set all requested ones after enforce_user.
   This has the advantage that securebits are set at the same place for
   root and non-root services.
3. Raise CAP_SETPCAP to the effective set (if not already set) before
   setting the securebits to avoid EPERM during the prctl syscall.

For gaining CAP_SETPCAP the function capability_bounding_set_drop is
splitted into two functions:
- The first one raises CAP_SETPCAP (required for dropping bounding
  capabilities)
- The second drops the bounding capabilities

Why are ambient capabilities not affected by this change?
Ambient capabilities get cleared during setresuid, no matter if
SECBIT_KEEP_CAPS is set or not.
For raising ambient capabilities for a user different to root, the
requested capability has to be raised in the inheritable set first. Then
the SECBIT_KEEP_CAPS securebit needs to be set before setresuid is
invoked. Afterwards the ambient capability can be raised, because it is
in the inheritable and permitted set.

Security considerations:
Although the manpage is ambiguous SECBIT_KEEP_CAPS is cleared during
execve no matter if SECBIT_KEEP_CAPS_LOCKED is set or not. If both are
set only SECBIT_KEEP_CAPS_LOCKED is set after execve.
Setting SECBIT_KEEP_CAPS in enforce_user for being able to set
securebits is no security risk, as the effective and permitted set are
set to the value of the ambient set during execve (if the executed file
has no file capabilities. For details check man 7 capabilities).

Remark:
In capability-util.c is a comment complaining about the missing
capability CAP_SETPCAP in the effective set, after the kernel executed
/sbin/init. Thus it is checked there if this capability has to be raised
in the effective set before dropping capabilities from the bounding set.
If this were true all the time, ambient capabilities couldn't be set
without dropping at least one capability from the bounding set, as the
capability CAP_SETPCAP would miss and setting SECBIT_KEEP_CAPS would
fail with EPERM.

3 years agocapability-util: add new function for raising setpcap
Tobias Kaufmann [Mon, 31 Aug 2020 10:50:25 +0000 (12:50 +0200)] 
capability-util: add new function for raising setpcap

Up to now the capability CAP_SETPCAP was raised implicitly in the
function capability_bounding_set_drop.

This functionality is moved into a new function
(capability_gain_cap_setpcap).

The new function optionally provides the capability set as it was
before raisining CAP_SETPCAP.

3 years agojson: split out string formatting to a separate function
Zbigniew Jędrzejewski-Szmek [Fri, 28 Aug 2020 17:47:19 +0000 (19:47 +0200)] 
json: split out string formatting to a separate function

It's complicated enough to deserve it's own function.

No functional change.

3 years agovarlink: do not parse invalid messages twice
Zbigniew Jędrzejewski-Szmek [Fri, 28 Aug 2020 17:22:20 +0000 (19:22 +0200)] 
varlink: do not parse invalid messages twice

Upon reception of a message which fails in json_parse(), we would proceed to
parse it again from a deferred callback and hang. Once we have realized that
the message is invalid, let's move the pointer in the buffer even if the
message is invalid. We don't want to look at this data again.

(before) $ build-rawhide/userdbctl --output=json user test.user
n/a: varlink: setting state idle-client
/run/systemd/userdb/io.systemd.Multiplexer: Sending message: {"method":"io.systemd.UserDatabase.GetUserRecord","parameters":{"userName":"test.user","service":"io.systemd.Multiplexer"}}
/run/systemd/userdb/io.systemd.Multiplexer: varlink: changing state idle-client → awaiting-reply
/run/systemd/userdb/io.systemd.Multiplexer: New incoming message: {...}
/run/systemd/userdb/io.systemd.Multiplexer: varlink: changing state awaiting-reply → pending-disconnect
/run/systemd/userdb/io.systemd.Multiplexer: New incoming message: {...}
/run/systemd/userdb/io.systemd.Multiplexer: varlink: changing state pending-disconnect → disconnected
^C

(after) $ n/a: varlink: setting state idle-client
/run/systemd/userdb/io.systemd.Multiplexer: Sending message: {"method":"io.systemd.UserDatabase.GetUserRecord","parameters":{"userName":"test.user","service":"io.systemd.Multiplexer"}}
/run/systemd/userdb/io.systemd.Multiplexer: varlink: changing state idle-client → awaiting-reply
/run/systemd/userdb/io.systemd.Multiplexer: New incoming message: {...}
/run/systemd/userdb/io.systemd.Multiplexer: Failed to parse JSON: Invalid argument
/run/systemd/userdb/io.systemd.Multiplexer: varlink: changing state awaiting-reply → pending-disconnect
/run/systemd/userdb/io.systemd.Multiplexer: varlink: changing state pending-disconnect → processing-disconnect
Got lookup error: io.systemd.Disconnected
/run/systemd/userdb/io.systemd.Multiplexer: varlink: changing state processing-disconnect → disconnected
Failed to find user test.user: Input/output error

This should fix #16683 and https://bugs.gentoo.org/735072.

3 years agoman: add hint how to show password strings with userdbctl
Zbigniew Jędrzejewski-Szmek [Fri, 28 Aug 2020 16:21:33 +0000 (18:21 +0200)] 
man: add hint how to show password strings with userdbctl

I started working on a command-line switch to show passwords also in
"pretty" mode. I can submit that code for review if anyone thinks that
woul be useful, but after writing the man page I realized that it's a
fairly niche case, and the hint in the man page is a sufficient
replacement.

3 years agouserdb: fix typo
Zbigniew Jędrzejewski-Szmek [Fri, 28 Aug 2020 16:11:48 +0000 (18:11 +0200)] 
userdb: fix typo

3 years agouserdbctl: add forgotten --output mode in help
Zbigniew Jędrzejewski-Szmek [Fri, 28 Aug 2020 15:25:14 +0000 (17:25 +0200)] 
userdbctl: add forgotten --output mode in help

3 years agoshared: merge {user,group}-record-show.[ch]
Zbigniew Jędrzejewski-Szmek [Fri, 28 Aug 2020 15:11:46 +0000 (17:11 +0200)] 
shared: merge {user,group}-record-show.[ch]

It is natural to include both, and in total they declared three
functions. Let's merge them for simplicity.

3 years agoMerge pull request #16885 from keszybz/rework-cache-timestamps
Anita Zhang [Tue, 1 Sep 2020 06:21:12 +0000 (23:21 -0700)] 
Merge pull request #16885 from keszybz/rework-cache-timestamps

Rework cache timestamps

3 years agoMerge pull request #16917 from poettering/contrib-rfe
Anita Zhang [Tue, 1 Sep 2020 00:25:36 +0000 (17:25 -0700)] 
Merge pull request #16917 from poettering/contrib-rfe

CONTRIBUTING: be clearer about versions and RFE process

3 years agoCONTRIBUTING: be clearer about versions and RFE process 16917/head
Lennart Poettering [Mon, 31 Aug 2020 21:23:29 +0000 (23:23 +0200)] 
CONTRIBUTING: be clearer about versions and RFE process

Fixes: #16550
3 years agodissect-image: generate nice error when we can't detect any file system
Lennart Poettering [Mon, 31 Aug 2020 17:01:49 +0000 (19:01 +0200)] 
dissect-image: generate nice error when we can't detect any file system

3 years agobasic/escape: use consistent location for "*" in function declarations
Zbigniew Jędrzejewski-Szmek [Fri, 28 Aug 2020 14:37:09 +0000 (16:37 +0200)] 
basic/escape: use consistent location for "*" in function declarations

I think it's nicer to move it to the left, since the function
is already a pointer by itself, and it just happens to return a pointer,
and the two concepts are completely separate.

3 years agoshared/{user,group}-record-nss: adjust filtering of "valid" passwords
Zbigniew Jędrzejewski-Szmek [Fri, 28 Aug 2020 14:23:16 +0000 (16:23 +0200)] 
shared/{user,group}-record-nss: adjust filtering of "valid" passwords

We would reject various passwords that glibc accepts, for example ""
or any descrypted password. Accounts with empty password are definitely
useful, for example for testing or in scenarios where a password is not
needed. Also, using weak encryption methods is probably not a good idea,
it's not the job of our nss helpers to decide that: they should just
faithfully forward whatever data is there.

Also rename the function to make it more obvious that the returned answer
is not in any way certain.

3 years agoRework how we cache mtime to figure out if units changed 16885/head
Zbigniew Jędrzejewski-Szmek [Fri, 28 Aug 2020 10:21:48 +0000 (12:21 +0200)] 
Rework how we cache mtime to figure out if units changed

Instead of assuming that more-recently modified directories have higher mtime,
just look for any mtime changes, up or down. Since we don't want to remember
individual mtimes, hash them to obtain a single value.

This should help us behave properly in the case when the time jumps backwards
during boot: various files might have mtimes that in the future, but we won't
care. This fixes the following scenario:

We have /etc/systemd/system with T1. T1 is initially far in the past.
We have /run/systemd/generator with time T2.
The time is adjusted backwards, so T2 will be always in the future for a while.
Now the user writes new files to /etc/systemd/system, and T1 is updated to T1'.
Nevertheless, T1 < T1' << T2.
We would consider our cache to be up-to-date, falsely.