Commit Graph
54689 Commits
Author SHA1 Message Date
Yu Watanabe f78e89b018 validatefs: split out validating gpt label and type
No functional change, just refactoring.
This addresses https://github.com/systemd/systemd/pull/37434#discussion_r2088950725.
2025-05-15 02:58:05 +09:00
Yu Watanabe e4db2c9b83 validatefs: drop unnecessary empty lines 2025-05-15 02:57:57 +09:00
Daan De Meyer 7305347221 discover-image: Move some logic to the implementation file
This will allow removing the string-util.h and path-util.h includes
as part of #37344.
2025-05-14 19:55:56 +02:00
Daan De Meyer d802d40e86 forward: Add forward declaration for LockFile (#37445) 2025-05-14 19:55:18 +02:00
Daan De Meyer e03e45aef2 Cleanup up includes #1 (#37438) 2025-05-14 19:55:03 +02:00
Daan De Meyer ba6d1f9aca forward: Add forward declaration for LockFile 2025-05-14 19:20:00 +02:00
Lennart Poettering 4fefc10c0d validatefs: fix checks on file systems backed by multiple devices (i.e. verity) (#37434)
Fixes #37157
2025-05-14 17:53:06 +02:00
Daan De Meyer e2165e01bd vmspawn: Clean up includes
Split out of #37344
2025-05-14 17:21:37 +02:00
Daan De Meyer 5a94aaaf5d xdg-autostart-generator: Clean up includes
Split out of #37344
2025-05-14 17:21:37 +02:00
Daan De Meyer 905ebf6b79 sd-bus: Make sure sd_bus_error and sd_bus_error_map structs are named
Otherwise we can't forward declare them.

Split out of #37344
2025-05-14 17:21:37 +02:00
Daan De Meyer 5f7b80b4e5 hashmap: Make sure Iterator struct is named
Otherwise we can't forward declare it.

Split out of #37344
2025-05-14 17:21:37 +02:00
Daan De Meyer 02b6ac3a50 static-destruct: Move static_destruct() logic to implementation file
This will allow us to remove the memory-util.h include from
static-destruct.h as part of #37344.
2025-05-14 16:56:41 +02:00
Daan De Meyer bdcd47a269 blockdev-util: Remove dependency on string-util.h
Let's insist on a string literal in SYS_BLOCK_PATH_MAX() so that
we don't accidentally allocate VLAs and let's inline strempty() in
xsprintf_sys_block_path() so we don't need to include string-util.h
in blockdev-util.h

We'll remove the actual string-util.h include as part of #37344.
2025-05-14 16:56:05 +02:00
Daan De Meyer 5f3b558b99 Introduce forward.h header with forward declarations (#37428)
In preparation for adopting forward declarations to reduce unnecessary
transitive includes across the tree, let's introduce a forward.h header
with forward declarations for all libc, libsystemd, basic and shared
types.

Additionally, this header exports all basic integer types and errno
constants, as well as all macros including assertions macros. These
header files contain types often used in headers and are always included
in every source file one way or another anyway.

To avoid having to include memory-util.h and alloc-util.h in forward.h,
we split off the parts we need from both into cleanup-util.h and only
include cleanup-util.h in forward.h.

To keep this commit self-contained, we include cleanup-fundamental.h and
cleanup-util.h from the headers that originally contained the same
macros. We'll remove these again in a later commit that optimizes the
includes in src/basic and src/fundamental.

Split out of #37364
2025-05-14 16:51:10 +02:00
Daan De Meyer b23c1cf55e boot: Use DEFINE_TRIVIAL_CLEANUP_FUNC() to define strv_freep() 2025-05-14 16:22:54 +02:00
Lennart Poettering 02347d24e4 repart: initialize validatefs xattrs to list *all* verity subordinate partitions
Now that we can actually list multiple gpt labels/type uuids in xattrs,
let's start doing so.

Fixes: #37157
2025-05-14 15:44:54 +02:00
Lennart Poettering f7d3262844 validatefs: properly authenticate all subordinate devices of DM devices
Previously, we'd only authenticate "one" of the subordinate devices of a
DM device, and which one was somewhat undefined, it would be what we
find in slaves/ first. This is in particular a problem with dm-verity
which generally has two subordinate devices: the data device and the
hash device.

Let's fix this properly. This means two things:

1. iterate through *all* subordinate devices of a DM device (i.e.
   iterate through the sysfs slaves/ subdir), not just
   one

2. permit configuring a list of gpt labels and gpt type uuids in the
   xattrs of mount points, so that all valid combinations can be listed.

This only updates the validation like this. The generation of xattrs
that carry multiple type uuids/labels in systemd-repart will follow in a
later commit.

This extends the syntax of the two gpt-related xattrs, to allow lists of
things. This is a true extension, without breaking compat (but even if
it was, it wouldn't matter given that validatefs was added post v257,
i.e. is not included in a stable release.

Fixes: #37157
2025-05-14 15:44:54 +02:00
Daan De Meyer 686bbf1e7f Introduce forward.h header with forward declarations
In preparation for adopting forward declarations to reduce unnecessary
transitive includes across the tree, let's introduce a forward.h header
with forward declarations for all libc, libsystemd, basic and shared types.

Additionally, this header exports all basic integer types and errno constants,
as well as all macros including assertions macros. These header files contain
types often used in headers and are always included in every source file one
way or another anyway.

To avoid having to include memory-util.h and alloc-util.h in forward.h, we
split off the parts we need from both into cleanup-util.h and only include
cleanup-util.h in forward.h.

To keep this commit self-contained, we include cleanup-fundamental.h and
cleanup-util.h from the headers that originally contained the same macros.
We'll remove these again in a later commit that optimizes the includes in
src/basic and src/fundamental.

Split out of #37364
2025-05-14 15:44:17 +02:00
Lennart Poettering 510e966677 validatefs: split out validate_fields_check() into three functions
Just some basic refactoring, no actual code changes
2025-05-14 13:04:20 +02:00
Lennart Poettering 798d140cac avoid race between systemd-logind and systemd-udevd in setting ACLs (#36444)
Follow-up for #36408.
Hopefully fixes #24026, #28512, and/or #23547.
2025-05-14 13:03:46 +02:00
Lennart Poettering 86bb6f4052 fork-journal: some follow-ups (#37423) 2025-05-14 13:02:46 +02:00
Lennart Poettering c55f87062d journald: rename primary object from "Server" to "Manager"
In all our daemons the primary entrypoint object is called "Manager".
But so far there was one exception: in journald it was called "Server".
Let's normalize that, and stick to the same nomenclature everywhere, to
make journald less special.

No real code change, just some search&replace.
2025-05-14 13:02:26 +02:00
Mike Yuan b431092675 Update description and uid checks when invoking pager (#37419) 2025-05-14 03:01:41 +02:00
Mike Yuan 38e3f79d52 fork-journal: drop unneeded cast 2025-05-13 23:11:34 +02:00
Mike Yuan b86b1ca22f fork-journal: use char* const* for strv input param
This is compatible with char** and is what I originally
asked for in
https://github.com/systemd/systemd/pull/36858#discussion_r2086792739
Someone needs to read better ;-)
2025-05-13 23:01:23 +02:00
Mike Yuan c49c2477a4 journalctl-show: report VARLINKERROR=
Who knows, maybe one day we'd support spawning journalctl
as varlink socket-activatable service, where this bit of
info would help.
2025-05-13 22:57:29 +02:00
Mike Yuan df3c049fa5 journalctl-show: check Context.has_cursor rather than arg_* 2025-05-13 22:55:15 +02:00
Mike Yuan 2627c8e79e journal: do not clear individual fields if the struct won't be reused
Especially that only some of the fields are cleared currently.
2025-05-13 22:54:10 +02:00
Yu Watanabe 5884fafcd7 systemctl: make systemctl clean --what= values more discoverable (#37418) 2025-05-14 02:16:47 +09:00
Yu Watanabe 003c6faff4 acl-util: make acl_find_uid() static 2025-05-14 02:06:02 +09:00
Yu Watanabe 1abb592f2f udev: move devnoce_acl() to udev-builtin-uaccess.c
As it is now only used by udev-builtin-uaccess.c.

This also makes devnode_acl() use fd rather than path to device node.
2025-05-14 02:06:02 +09:00
Yu Watanabe c960ca2be1 login,udev: avoid race between systemd-logind and systemd-udevd in setting ACLs
Previously, both udevd and logind modifies ACLs of a device node. Hence,
there exists a race something like the following:
1. udevd reads an old state file,
2. logind updates the state file, and apply new ACLs,
3. udevd applies ACLs based on the old state file.

This makes logind not update ACLs but trigger uevents for relevant
devices to make ACLs updated by udevd.
2025-05-14 02:06:02 +09:00
Yu Watanabe 26a675dd56 login: do not call manager_process_seat_device() more than once per event
When udevd broadcasts an event for e.g. a graphics device with master-of-seat
tag, then previously manager_process_seat_device() was called twice for
the event.

With this commit, the function is called only once even for an event for
such device.
2025-05-14 02:06:02 +09:00
Yu Watanabe 3400abf3ca login: use FOREACH_STRING() at one more place 2025-05-14 02:06:02 +09:00
Yu Watanabe 2012d6d74e device-util: introduce device_get_seat() helper function 2025-05-14 02:06:02 +09:00
Yu Watanabe ab1bd9daed device-util: introduce several more helper functions
This also makes device_in_subsystem() and device_is_devtype() return
negative error on critical error
2025-05-14 02:06:02 +09:00
Yu Watanabe b7d60b2966 backlight: replace recursion with for loop 2025-05-14 02:06:02 +09:00
Yu Watanabe 25151ca2b8 backlight: use device_get_sysattr_unsigned() at one more place 2025-05-14 02:06:02 +09:00
Daan De Meyer 8ebe9f1da2 Prepare for reducing transitive includes in tests.h (#37414) 2025-05-13 19:02:12 +02:00
Zbigniew Jędrzejewski-Szmek cd93478af8 pager: also check for $SUDO_UID
This returns to the original approach proposed in
https://github.com/systemd/systemd/pull/17270. After review, the approach was
changed to use sd_pid_get_owner_uid() instead. Back then, when running in a
typical graphical session, sd_pid_get_owner_uid() would usually return the user
UID, and when running under sudo, geteuid() would return 0, so we'd trigger the
secure path.

sudo may allocate a new session if is invoked outside of a session (depending
on the PAM config). Since nowadays desktop environments usually start the user
shell through user units, the typical shell in a terminal emulator is not part
of a session, and when sudo is invoked, a new session is allocated, and
sd_pid_get_owner_uid() returns 0 too. Technically, the code still works as
documented in the man page, but in the common case, it doesn't do the expected
thing.

$ build/test-sd-login |& rg 'get_(owner_uid|cgroup|session)'
sd_pid_get_session(0) → No data available
sd_pid_get_owner_uid(0) → 1000
sd_pid_get_cgroup(0) → /user.slice/user-1000.slice/user@1000.service/app.slice/app-ghostty-transient-5088.scope/surfaces/556FAF50BA40.scope

$ sudo build/test-sd-login |& rg 'get_(owner_uid|cgroup|session)'
sd_pid_get_session(0) → c289
sd_pid_get_owner_uid(0) → 0
sd_pid_get_cgroup(0) → /user.slice/user-0.slice/session-c289.scope

I think it's worth checking for sudo because it is a common case used by users.
There obviously are other mechanims, so the man page is extended to say that
only some common mechanisms are supported, and to (again) recommend setting
SYSTEMD_LESSSECURE explicitly. The other option would be to set "secure mode"
by default. But this would create an inconvenience for users doing the right
thing, running systemctl and other tools directly, because then they can't run
privileged commands from the pager, e.g. to save the output to a file. (Or the
user would need to explicitly set SYSTEMD_LESSSECURE. One option would be to
set it always in the environment and to rely on sudo and other tools stripping
it from the environment before running privileged code. But that is also fairly
fragile and it obviously relies on the user doing a complicated setup to
support a fairly common use case. I think this decreases usability of the
system quite a bit. I don't think we should build solutions that work in
priniciple, but are painfully inconvenient in common cases.)

Fixes https://yeswehack.com/vulnerability-center/reports/346802.

Also see https://github.com/polkit-org/polkit/pull/562, which adds support for
$SUDO_UID/$SUDO_GID to pkexec.
2025-05-13 18:08:49 +02:00
Jörg Behrmann 68b6289a9e systemct: show all in output of systemctl clean --what=help 2025-05-13 17:21:02 +02:00
Jörg Behrmann 028de7292d man, systemctl: document --what=help 2025-05-13 17:19:39 +02:00
Lennart Poettering 559795fa46 compress: deal with zstd decoder issues gracefully
If zstd frames are corrupted the initial size returned for the current
frame might be wrong. Don#t assert() on that, but handle it gracefully,
as EBADMSG
2025-05-13 15:39:57 +02:00
Lennart Poettering 6427d0fbed logs-show: use memory_startswith() rather than startswith()
Let's be strict here: this data is conceptually not NUL terminated,
hence use memory_startswith() rather than startswith() (which implies
NUL termination). All other similar cases in logs-show.c got this right.
Fix the remaining three, too.
2025-05-13 15:39:57 +02:00
Lennart Poettering 010e2562dd logs-show: handle bad messages like EOF
Similar to the previous commit, but for logs-show.c
2025-05-13 15:39:57 +02:00
Lennart Poettering 3a8d562a21 logs-show: drop unused function parameter 2025-05-13 15:39:57 +02:00
Lennart Poettering cf2d660f2f journal-upload-journal: handle partially written fields gracefully
With the more efficient sync semantics it's more likely that
journal-upload-journal will try to read a partially written message.
Previously we'd fail then. Let's instead treat this gracefully,
expecting that this is either the end or will be fixed shortly (and
we'll get notified via inotify about it and recheck).
2025-05-13 15:39:57 +02:00
Lennart Poettering 3017ddfcc8 journal-upload-journal: reduce indentation a bit 2025-05-13 15:39:57 +02:00
Lennart Poettering 6f77c31f63 journal-remote: destroy event sources before MHD context
The MHD context owns the fd we watch via our event source, hence when we
destroy the context before the event source the event source might still
reference the fd that is now invalid. Hence swap the order.
2025-05-13 15:39:57 +02:00
Lennart Poettering 6e9deb8f7b run: rework final status output to be based on format-table.h APIs 2025-05-13 15:39:57 +02:00