Commit Graph
9490 Commits
Author SHA1 Message Date
Yu Watanabe db4b4e0cd3 core: Make DelegateNamespaces= work for user managers with CAP_SYS_ADMIN (#36771)
Currently DelegateNamespaces= only works for services spawned by the
system manager. User managers will always unshare the user namespace
first even if they're running with CAP_SYS_ADMIN.

Let's add support for DelegateNamespaces= for user managers if they're
running with CAP_SYS_ADMIN. By default, we'll still delegate all
namespaces
for user managers, but this can now be overridden by explicitly passing
DelegateNamespaces=.

If a user manager is running without CAP_SYS_ADMIN, the user manager is
still always unshared first just like before.
2025-03-20 06:28:18 +09:00
Lennart Poettering b0fe8df5a9 Several fixlets for Coverity (#36791) 2025-03-19 22:27:00 +01:00
Yu Watanabe bb8c74d7f2 Introduce ConditionVersion (#36468)
Add a new condition which can check against systemd version.

        $ systemctl --version
        systemd 258 (258~devel-g53ca5f6)

        $ systemd-analyze condition 'ConditionVersion=systemd>255'
        test.service: ConditionVersion=>255 succeeded.

        $ systemd-analyze condition 'ConditionVersion=systemd>260'
        test.service: ConditionVersion=>260 failed.

        $ systemd-analyze condition 'ConditionVersion=systemd>=258'
        test.service: ConditionVersion=>=258 succeeded.

        $ systemd-analyze condition 'ConditionVersion=systemd>=257.1'
        test.service: ConditionVersion=>=257.1 succeeded.

        $ uname -r
        6.12.13-200.fc41.aarch64

        $ systemd-analyze condition 'ConditionVersion=kernel > 4.4'
        test.service: ConditionVersion=kernel > 4.4 succeeded.

        $ systemd-analyze condition 'ConditionVersion=kernel > 6.20'
        test.service: ConditionVersion=kernel > 6.20 failed.

        $ systemd-analyze condition 'ConditionVersion=kernel < 9.0'
        test.service: ConditionVersion=kernel < 9.0 succeeded.
2025-03-20 06:15:35 +09:00
Lennart Poettering 0015502168 tpm2-util: return better errors if we try to unlock a tpm key on the wrong tpm
Let's improve error handling in case one tries to unlock a TPM2 locked
volume on a different machine via TPM than it was originally enrolled
on. Let's recognize this case and print a clearer error message.
2025-03-19 21:27:54 +01:00
Lennart Poettering f21090d217 generator: skip fsck early for non-blockdev file systems, or file systems that are always read-only 2025-03-19 18:18:43 +01:00
Daan De Meyer ad9b5d4732 bus-unit-util: Fix DelegateNamespaces= parser
Similarly to the config file parse method, let's fix the systemd-run
parser as well.

Follow up for 11b982053b
2025-03-19 10:00:45 +01:00
Yu Watanabe 707bea6a48 ptyfwd: use usec_add()
Fixes CID#1548038.
2025-03-19 11:41:25 +09:00
Yu Watanabe 11065c598c logs-show: comment out dead code
Follow-up for 280e85224e.
Fixes CID#1548921 and CID#1548922.
2025-03-19 11:41:12 +09:00
Yu Watanabe 6a6cc56125 bus-unit-procs: add one more assertion for Coverity
Hopefully fixes CID#1562447.
2025-03-19 10:41:29 +09:00
Daan De Meyer fe0342edf4 userdb: Add userdb.user.* and userdb.group.* credentials
Let's allow providing extra userdb users and groups via credentials.
Similarly to systemd-udev-load-credentials.service, we ship
systemd-userdb-load-credentials.service which transform the JSON
user/group records provided via the corresponding credentials to static
userdb dropins in /etc/userdb.

Replaces #33811
2025-03-18 22:46:10 +01:00
Yu Watanabe b8d5303733 nspawn: make failure in sd_listen_fds() critical
Also, drop doubled call of sd_listen_fds().
2025-03-19 02:09:40 +09:00
Matteo Croce c154bb65ad condition: introduce ConditionVersion=/AssertVersion=
Add a new condition wich checks against systemd version.
Change condition_test_kernel_version() into a generic condition_test_version()
so most of the code can be reused.

    $ systemctl --version
    systemd 258 (258~devel-g53ca5f6)

    $ systemd-analyze condition 'ConditionVersion=systemd>255'
    test.service: ConditionVersion=>255 succeeded.

    $ systemd-analyze condition 'ConditionVersion=systemd>260'
    test.service: ConditionVersion=>260 failed.

    $ systemd-analyze condition 'ConditionVersion=systemd>=258'
    test.service: ConditionVersion=>=258 succeeded.

    $ systemd-analyze condition 'ConditionVersion=systemd>=257.1'
    test.service: ConditionVersion=>=257.1 succeeded.

    $ uname -r
    6.12.13-200.fc41.aarch64

    $ systemd-analyze condition 'ConditionVersion=kernel > 4.4'
    test.service: ConditionVersion=kernel > 4.4 succeeded.

    $ systemd-analyze condition 'ConditionVersion=kernel > 6.20'
    test.service: ConditionVersion=kernel > 6.20 failed.

    $ systemd-analyze condition 'ConditionVersion=kernel < 9.0'
    test.service: ConditionVersion=kernel < 9.0 succeeded.
2025-03-18 18:36:59 +09:00
Yu Watanabe f91273f4fc condition: align string table 2025-03-18 18:36:59 +09:00
Lennart Poettering 33cbda04eb xattr-util: rework getxattr_at_malloc()
Let's return the size in a return parameter instead of the return value.
And if NULL is specified this tells us the caller doesn't care about the
size and expects a NUL terminated string. In that case look for an
embedded NUL byte, and refuse in that case.

This should lock things down a bit, as we'll systematically refuse
embedded NUL strings now when we expect strings.
2025-03-18 07:17:10 +01:00
Yu Watanabe c9c2679a62 some user record fixes (#36776)
Fixes: https://github.com/systemd/systemd/issues/36775
2025-03-18 09:24:05 +09:00
Lennart Poettering ca4560f6a8 tree-wide: go via user_record_gid() accessor for UserRecord's .gid field
Sometimes we went for the field directly, where we really should go via
the accessor. Fix it.
2025-03-17 22:21:58 +01:00
Lennart Poettering 6e09c46a51 nsresource: turn feature absence error into EOPNOTSUPP
Let's make it easy for local clients to treat feature absence as a
simple EOPNOTSUPP check.
2025-03-17 16:03:18 +01:00
Lennart Poettering 3b6d1fb49f varlink: add full introspection comments for io.systemd.NamespaceResource 2025-03-17 16:03:18 +01:00
Lennart Poettering b2c43674a7 nsresourced: put a limit on delegated network interfaces too 2025-03-17 16:03:18 +01:00
Lennart Poettering 716bf93c4b nsresource: add client-side wrapper for creating tap links 2025-03-17 16:03:18 +01:00
Lennart Poettering 1365034727 nsresourced: add ability to delegate tap device 2025-03-17 16:03:18 +01:00
Lennart Poettering 6431c34b8a namespace-util: make "setgroups" users property writable via userns_acquire()
Unprivileged namespaces are only allowed if the "setgroups" file is set
to "deny" for processes. And we need to write it before writing the
gidmap. Hence add a parameter for that.

Then, also patch all current users to actually enable this. The usecase
generally don't need it (because they don't care about unprivileged
userns), but it doesn't hurt to enable the concept anyway in all current
users (none of them actually runs complex userspace in them, but they
mostly use userns_acquire() for idmapped mounts and similar).

Let's anyway make this option explicit in the function call, to indicate
that the concept exists and is applied.
2025-03-17 16:03:18 +01:00
Luca Boccassi 3d278519fa build: add C23 support (#35085)
To support C23, this introduces UTF8() macro to define UTF-8 literals,
as C23 changed char8_t from char to unsigned char.
This also makes pointer signedness warning critical, and updates C
standards table for tests.
2025-03-17 11:29:33 +00:00
Daan De Meyer 8065d02e26 copy: Fix error handling in fd_copy_directory() 2025-03-17 10:42:04 +01:00
Mike Yuan b66fd12135 cgroup-util: drop is_cgroup_fs()
No need to bother with any cgroup v1 stuff anymore.
2025-03-16 18:02:08 +01:00
Mike Yuan 2b61489e5a core/main: refuse bootup with legacy cgroup hierarchy
First step towards a unified-only future (rework of internals
coming soon (TM))
2025-03-16 15:30:39 +01:00
Mike Yuan 8d538d3fbb cgroup-setup: drop hierarchy detection, always use v2 2025-03-16 15:30:39 +01:00
Mike Yuan 36dad381a2 mount-setup: remove cgroup v1 hierarchy mounting 2025-03-16 15:30:38 +01:00
Mike Yuan 64db06c421 mount-setup: generalize cgroupfs_recursiveprot_supported() 2025-03-16 15:22:13 +01:00
Yu Watanabe e193378d32 macro: Introduce UTF8() macro to define UTF-8 string literal
C23 changed char8_t from char to unsigned char, hence assigning a u8 literal
to const char* emits pointer sign warning, e.g.
========
../src/shared/qrcode-util.c: In function ‘print_border’:
../src/shared/qrcode-util.c:16:34: warning: pointer targets in passing argument 1 of ‘fputs’ differ in signedness [-Wpointer-sign]
   16 | #define UNICODE_FULL_BLOCK       u8"█"
      |                                  ^~~~~
      |                                  |
      |                                  const unsigned char *
../src/shared/qrcode-util.c:65:39: note: in expansion of macro ‘UNICODE_FULL_BLOCK’
   65 |                                 fputs(UNICODE_FULL_BLOCK, output);
      |                                       ^~~~~~~~~~~~~~~~~~
========

This introduces UTF8() macro, which define u8 literal and casts to consth char*,
then rewrites all u8 literal definitions with the macro.
With this change, we can build systemd with C23.
2025-03-16 10:15:24 +09:00
Zbigniew Jędrzejewski-Szmek 1ae9b0cfa8 basic/glyph-util: rename "special glyph" to just "glyph"
Admittedly, some of our glyphs _are_ special, e.g. "O=" for SPECIAL_GLYPH_TOUCH ;)
But we don't need this in the name. The very long names make some invocations
very wordy, e.g. special_glyph(SPECIAL_GLYPH_SLIGHTLY_UNHAPPY_SMILEY).
Also, I want to add GLYPH_SPACE, which is not special at all.
2025-03-15 14:40:39 +01:00
Yu Watanabe 83340eb1fa tests: replace ASSERT_OK() and friends with coverity firendy function
We already have done the same for assert_se() since
d9fb7afb48.

Hopefully this makes coverity silent about the false-positive side-effect
warnings.
2025-03-15 08:56:38 +09:00
Daan De Meyer 3ed45e7fd3 copy: Bubble up ENOSPC immediately in fd_copy_directory()
It doesn't really make sense to continue once we start getting ENOSPC.
2025-03-13 07:53:06 +09:00
Yu Watanabe 36a9e47a0d nsresource: fix error handling 2025-03-13 05:27:50 +09:00
Yu Watanabe f0ebc0c5bf tests: introduce ASSERT_PTR_EQ() 2025-03-13 01:48:50 +09:00
Yu Watanabe b15053de89 udev/net: fix assignment of ID_NET_NAME=
E.g. sd_device object of network interface 'hoge!foo' has sysname 'hoge/foo'.
So, previously udevd assigned 'hoge/foo' rather than 'hoge!foo' to ID_NET_NAME,
hence even when renaming is not requested, such interface was renamed to 'hoge_foo'
(note '/' cannot be used in network interface name, hence escaped to underbar).
2025-03-13 01:48:33 +09:00
Yu Watanabe 32b0e689d6 test: do not pass return value to log_error_errno() on success 2025-03-13 01:08:57 +09:00
Yu Watanabe 35d5defc4e hostname-setup: use strchr() to find wildcard character
Addresses https://github.com/systemd/systemd/pull/36647#discussion_r1990048751.
2025-03-12 06:48:57 +09:00
Yu Watanabe ced634a62d resolve question marks in /etc/hostname to characters hashed from machine ID (#36647)
So I have a bunch of particle os instances around, that I frequently
factory reset. and it's confusing, since they all have the same name.
Let's do something about this, and extend the hostname setup logic a bit
to deal better with "cattle" rather than "pet" deployments.
Specifically: if a hostname in /etc/hostname contains a bunch of
question marks we'll replace it with hex chars hashed from the machine
id.

This allows us to do something like this:

hostnamectl set-hostname --static 'funky-????-????-???'

and we'll end up with a hostname like `funky-baf4-b653-e230`
2025-03-12 04:50:33 +09:00
Lennart Poettering 0ecfcc9790 mountfsd: also return suggested mount point paths for the returned partitions
When mounting a disk image we return a bunch of mount fds referencing
the various partitions in the disk, along with some metadata about them.
One key metadata field is the "designator" which is supposed to tell
clients what is what, and where to mount it.

Let's make this more explicit: let's also include the literal relative
path where each mount shall be placed, to simplify implementations of
clients that do not care about the concept of designators.
2025-03-11 18:20:31 +01:00
Lennart Poettering 00c17ad5cf mountfsd: complete varlink introspection comments 2025-03-11 18:20:31 +01:00
Lennart Poettering af9c45d5b6 hostname: support that /etc/hostname contains ??? as wildcards to be replaced by hash value from /etc/machine-id 2025-03-11 18:01:42 +01:00
Lennart Poettering 98b7c5e2f2 basic: move gethostname_full() from basic/hostname-util.c → shared/hostname-setup.c
In one of the next commits we'd like to introduce a concept of
optionally hashing the hostname from the machine ID. For that we we need
to optionally back gethostname_full() by code involving sd-id128, hence
let's move it from src/basic/ to src/shared/, since only there we are
allowed to use our public APIs.
2025-03-11 17:54:44 +01:00
David Tardon 536c18e5c3 bus-polkit: shortcut auth. after first denial
A D-Bus/Varlink method can issue PolicyKit auth. requests for multiple
actions; in this case the method is expected to fail on the first one
that is not allowed. This is enforced by asserts in
async_polkit_read_reply(), but that's a wrong place for the check for
two reasons:

1. it doesn't allow to get a meaningful stack trace;
2. sending the query to polkit is already a pointless exercise.

Let's do the check in *_verify_polkit_async_full() and don't send
anything to PolicyKit in that case.

Inspired by https://bugzilla.redhat.com/show_bug.cgi?id=2349594 .
2025-03-11 17:18:12 +01:00
Lennart Poettering a9178dbdd9 cgroup-util: Handle capsule@ paths like user@ paths (#36664)
The capsule instances are related to user instances, so treat them
equally to user@.service when handling cgroup paths. This also saves us
from polluting public libsystemd API with variant for capsules too.

Fix: https://github.com/systemd/systemd/issues/36098
2025-03-11 12:03:57 +01:00
Yu Watanabe a5ede71f49 mount-setup: two trivial cleanups (#36668) 2025-03-09 09:42:41 +09:00
Mike Yuan b05c495eed mount-setup: tune down log level if usrquota is not supported, apply usrquota when smack is in use too
Follow-up for 8f5131fb9e
2025-03-08 19:16:17 +01:00
Mike Yuan 80b7f60d2e mount-setup: drop outdated comment 2025-03-08 19:16:17 +01:00
Lennart Poettering ce94761deb user-record: add a concept of inverting per-host matching sections in user record
Sometimes it is useful to apply options on all hosts except some. Add a
simple concept for that.
2025-03-07 18:14:20 +01:00
Lennart Poettering 6a2097dd78 openssl-util: add helper for converting EVP_PKEY to PEM string
And also give the rverse a bit of love.
2025-03-07 18:13:16 +01:00