Commit Graph

3994 Commits

Author SHA1 Message Date
Lennart Poettering
0c69a67294 varlink: fix IDL for errno error 2025-02-13 18:15:52 +01:00
Daan De Meyer
b000e16798 ptyfwd: Forward various signals to forked process
We want systemd-pty-forward to be something that can be dropped in
somewhere without too much thought. To enable this, let's make sure
we forward various signals to the forked process. This makes sure that
any signals are delivered to the actual child process regardless of whether
it's running within systemd-pty-forward or not.
2025-02-13 10:21:00 +01:00
Mike Yuan
baca3581ea xattr-util: modernize getcrtime_at() and friends
- Drop fd_ prefix for openat()-like function
- Make fd_setcrtime() accept O_PATH fds too
- Use statx_timestamp_load()
2025-02-09 14:51:03 +01:00
Yu Watanabe
52e9bc2deb journal-remote,journal-upload: added compression support (#34822) 2025-02-09 13:33:33 +09:00
Yu Watanabe
7543ae05e3 sd-device: introduce device_get_sysnum_unsigned() 2025-02-08 01:38:02 +09:00
Andrii Chubatiuk
91d6f1ee53 basic: expose compression level argument in compress_blob functions 2025-02-07 07:05:02 +02:00
Lennart Poettering
2824946d33 json-util: add generic json_dispatch_filename() dispatch helper 2025-02-06 09:23:49 +01:00
Yu Watanabe
be73f6e35b udevadm: several cleanups around parse_device_action()
- drop unnecessary one line function dump_device_action_table(),
- make parse_device_action() log about invalid action string,
- rename output argument of parse_device_action().
2025-02-02 15:55:01 +09:00
Nick Rosbrook
5dc89b327f tree-wide: remove some spurious newlines
Specifically, remove double newlines, and newlines before '}'.
2025-01-29 16:17:46 +00:00
Yu Watanabe
d90c01d02c network: bridge: add support for configuring locked ports (#36150)
"Recently" (as of 5.18) the Linux kernel gained the ability of locking
bridge ports to restrict network access to authenticated hosts only.

This is implemented by disabling automated learning and dropping
incoming traffic from unknown hosts. User space is then expected to add
fdb entries for authenticated hosts. Once a fdb entry exist, traffic for
that host will be forwarded as expected.

This was later extended with "Mac Authentication Bypass", where the
locking was extended to fdb entries. In this mode the kernel adds fdb
entries again automatically, but they are locked by default.

To properly configure this, add two network options and one netdev
option:

* `LinkLocalLearning=` to prevent the kernel from creating unlocked
entries based on link-local traffic, which would bypass any
authentication. Needed when enabling learning on a locked port.
* `Locked=` to allow setting a bridge port to locked.
* `MACAuthenticationBypass=` to allow enabling Mac Authentication
 Bypass on a port. Requires learning to be enabled on the port as well
 (and consequently `LinkLocalLearning` disabled on the bridge).

An authenticator (e.g. hostapd) is still needed to do the actual
authentication, the kernel only provides the access control.
2025-01-29 04:16:20 +09:00
Jonas Gorski
08a26ecc47 network: bridge: add support for IFLA_BRPORT_MAB
Since linux commit a35ec8e38cdd1766f29924ca391a01de20163931 ("bridge:
Add MAC Authentication Bypass (MAB) support"), included since v6.2, it
is possible to enable MAC Authentication Bypass for bridge ports. In
this mode the locked port learns again, but the learned fdb entries are
locked, allowing user space to unlock hosts based seen MAC addresses.

This requires learning to be enabled on the port, and link-local
learning disabled for the bridge.

Add support to systemd-network for setting the new attribute for bridge
ports.
2025-01-28 12:22:26 +01:00
Jonas Gorski
a434de6056 network: bridge: add support for IFLA_BRPORT_LOCKED
Since linux commit a21d9a670d81103db7f788de1a4a4a6e4b891a0b ("net:
bridge: Add support for bridge port in locked mode"), included since
v5.18,  it is possible to set bridge ports to locked.

Locked ports do not learn automatically, and discard any traffic from
unknown source MACs. To allow traffic, the userspace authenticator is
expected to create fdb entries for authenticated hosts.

Add support to systemd-network for setting the new attribute for bridge
ports.
2025-01-28 10:38:01 +01:00
Nick Rosbrook
428c99997d varlink-util: add varlink_many_notify
We already have varlink_many_notifyb. Just re-factor it slightly and add
a plain varlink_many_notify.
2025-01-27 09:32:24 -05:00
Yu Watanabe
9b3715d529 sd-json: silence false positive warning by coverity
An object json is a set of key and value pair, hence has its number of
element is multiple of two, and we know at least two elements there.

Follow-up for b6a2df6307.
Fixes CID#1590724
2025-01-25 05:31:41 +09:00
Yu Watanabe
06c172342e udev-rules: use sd_device_set_sysattr_value() to write sysfs attribute (#36142)
Then, we can avoid that files outside of sysfs are written by udev ATTR
key.
2025-01-25 05:30:21 +09:00
Yu Watanabe
d7306348b2 tree-wide: insert a space at the end of comments 2025-01-25 05:24:23 +09:00
Yu Watanabe
2b3d4e3d94 sd-device: move the check if sysattr entry should be cached into device_cache_sysattr_value()
No functional change. Preparation for the next commit.
2025-01-24 23:59:42 +09:00
Yu Watanabe
8a41f6e105 sd-device: make device_get_cached_sysattr_value() static 2025-01-24 23:59:42 +09:00
Yu Watanabe
6430761685 sd-device: fix typo
Follow-up for 8d89667aba.
2025-01-24 22:13:03 +09:00
Lennart Poettering
25c24619db sd-varlink: add sd_varlink_get_description() call 2025-01-23 21:28:02 +01:00
Lennart Poettering
b6a2df6307 sd-json: add new sd_json_variant_unset_field() call 2025-01-23 21:27:39 +01:00
Yu Watanabe
1fe5b06363 sd-device: use device_in_subsystem() at more places 2025-01-23 22:54:11 +09:00
Yu Watanabe
640f8e9c4d sd-device: use specific setters for read entries from uevent file
Previously, if e.g. DRIVER=foo is specified in uevent file, the value is
only saved as property, but was not set to sd_device.driver.
That was inconsistent to the case when a device is created through
netlink uevent.

Let's always set when we get e.g. sd_device.driver when DRIVER=foo
from both uevent file and netlink uevent.
2025-01-23 22:54:11 +09:00
Yu Watanabe
17dc9ec4b6 sd-device: use sd_device_get_sysattr_value() to read uevent file
This also replaces the custom parser with strv_split_newlines_full().
No functional change, just refactoring.
2025-01-23 22:54:11 +09:00
Yu Watanabe
6ebbdcc0dd sd-device: use sd_device_get_sysattr_value() to read special symlinks
Then, cached result may be used. No functional change, just refactoring.
2025-01-23 22:54:11 +09:00
Yu Watanabe
8d89667aba sd-device: chase sysattr and refuse to read/write files outside of sysfs
This makes sd_device_get_sysattr_value()/sd_device_set_sysattr_value()
refuse to read/write files outside of sysfs for safety.

Also this makes
- use chase() to resolve and open the symlink in path to sysfs attribute,
- use delete_trailing_chars(),
- include error code in cache entry, so we can cache more error cases,
- refuse caching value written to uevent file of any devices, i.e.
  sd_device_set_sysattr_value(dev, "../uevent", "add") will also not
  cache the value "add".
2025-01-23 22:54:11 +09:00
Yu Watanabe
938a6b49bd sd-journal: use hash ops with destructor 2025-01-23 18:19:28 +09:00
Yu Watanabe
2d23cadd19 journal-file: use hash ops with destructor
This also makes JournalFile.chain_cache allocated when necessary.
2025-01-23 18:19:28 +09:00
Yu Watanabe
b87501ea3c sd-bus: use hash ops with destructor
This also makes vtable_methods and vtable_properties managed by Set,
as the key and value of each entry are equivalent.
2025-01-23 18:19:28 +09:00
Yu Watanabe
852c05c94f catalog: modernize code
- set destructors to catalog_hash_ops,
- acquire OrderedHashmap when necessary,
- gracefully handle NULL catalog directories and output stream,
- rename function output arguments,
- add many many assertions,
- use RET_GATHER().
2025-01-23 18:19:28 +09:00
Luca Boccassi
62e7b478ad pkg-config: add Requires.private: libcap
The two shared libraries for now link against libcap,
so add it to the Requires.private as it's a dependency

Fixes https://github.com/systemd/systemd/issues/36117
2025-01-23 10:28:47 +09:00
Yu Watanabe
a8fe005209 tree-wide: drop merely used _cleanup_ macros, and introduce several new ones (#36071) 2025-01-21 03:41:27 +09:00
Yu Watanabe
901bfcd8c1 tree-wide: rely on sd_varlink_dispatch() for validating zero-argument method calls, too
Follow-ups for a7cc7038ac.
2025-01-20 00:21:31 +09:00
Lennart Poettering
adb556abd9 tree-wide: use log_level_is_valid() more 2025-01-18 23:24:29 +01:00
Lennart Poettering
fa3137f9d0 json-util: fine tune json_dispatch_log_level()
Let's give the user control on how to handle JSON "null" assignments of
the log level. As one of three cases: as failure, as LOG_NULL (i.e. to
turn off logging) or as LOG_INFO (as our usual default log level).

Let's then use that in the generic SetLogLevel() call, so that callers
can use it to explicitly turn off logging in a service.

Note that this was (probably accidentally) already implemented, except
that the introspection enforcement blocked it. Let's clean this up and
make this officially a thing, since it's generally useful to turn off
logging I think.
2025-01-18 23:24:29 +01:00
Yu Watanabe
fe5a1afb67 tree-wide: use _cleanup_hashmap_free_ and friends 2025-01-19 03:48:15 +09:00
Lennart Poettering
9ef559a036 tree-wide: drop support for kernels without pidfd_open() and pidfd_send_signal() (#35971) 2025-01-16 11:37:17 +01:00
Mike Yuan
70923ed358 meson: enable -Wzero-as-null-pointer-constant
Support for C added in gcc 15:
236c0829ee
2025-01-16 02:26:56 +01:00
Mike Yuan
347eb8fbe3 tree-wide: remove unnecessary gcc >= 7 version check
Our baseline is gcc 8.4.
2025-01-16 02:26:56 +01:00
Mike Yuan
6e14c46bac tree-wide: drop support for kernels without pidfd_open() and pidfd_send_signal()
Our baseline is v5.4 now.
2025-01-12 00:01:07 +01:00
Mike Yuan
a342c71d36 sd-event: assign pid to event source at last also in sd_event_add_child_pidfd()
I.e. apply 54988a27b9 to
sd_event_add_child_pidfd() too.
2025-01-11 23:47:52 +01:00
Lennart Poettering
f249cc7618 varlink: tweak what we include in "system error" messages
We so far only included the numeric Linux errno. That's pretty Linux
specific however. Hence, let's improve things and include an origin
string, that clearly marks Linux as origin. Also, include the string
name of the error.

Take these two fields into account when translating back, too. So that
we prefer going by symbolic name rather than by numeric id.
2025-01-10 14:05:29 +01:00
Lennart Poettering
14533598bd sd-json: make it safe to call sd_json_dispatch_full() with a NULL table
This is useful for generating good errors when dispatching varlink
methods that take no parameters, as we'll still generate precise errors
in that case, taking a NULL table as equivalent as one with no
entries.
2025-01-10 14:03:21 +01:00
Yu Watanabe
cdd53cb74b sd-device: make sd_device_new_from_path() accept relative path to device node
Even though udevadm accepts relative syspath, previously, udevadm
could not use relative path to device node:
===
$ cd /dev
$ udevadm info sda
Bad argument "sda", expected an absolute path in /dev/ or /sys/ or a unit name: Invalid argument
$ udevadm info /usr/../dev/sda
Unknown device "/usr/../dev/sda": No such device
===
With this change, both the above cases work fine.

Note, still sd_device_new_from_devname() requires absolute path starts
with /dev/, for safety.
2025-01-09 09:57:19 +01:00
Yu Watanabe
0f6d800b9f sd-varlink: add flag for sd_varlink_server for creating connections w… (#35841)
…ith fd passing enabled

Let's add a simple flag that enables fd passing for all connections of a
server. It's much easier to use this than to install a connect handler
which manually enables this for each connection.
2025-01-06 22:13:50 +09:00
Luca Boccassi
807db92ab4 sd-device: fix validation for devices under /sys/firmware/ in sd_device_new_from_subsystem_sysname() (#35863)
Devices under /sys/firmware/ do not have subsystems. Hence, the
validation in sd_device_new_from_subsystem_sysname() ->
device_new_from_path_join() always failed.

Fixes a bug introduced by cd7c71154c
(v257).
Fixes #35861.
2025-01-06 11:06:23 +00:00
Lennart Poettering
336acebc77 basic: port various pidfd/pidref helpers to PIDFD_GET_INFO and PIDFD_GET_*_NAMESPACE (#35242)
Supersedes #35308 (cherry-picked one commit and replaced the rest)

(I left a few comments that's folded by GitHub. Please make sure to
check them too.)
2025-01-06 11:23:08 +01:00
Lennart Poettering
1740d3e04b sd-login: make use of getpeerpidref() and cg_pidref_get_*() 2025-01-06 09:54:41 +01:00
Lennart Poettering
6d4778f14f sd-varlink: add flag for sd_varlink_server for creating connections with fd passing enabled
Let's add a simple flag that enables fd passing for all connections of a
server. It's much easier to use this than to install a connect handler
which manually enables this for each connection.
2025-01-06 09:28:19 +01:00
Yu Watanabe
3328d1e181 sd-device: fix validation for devices under /sys/firmware/ in sd_device_new_from_subsystem_sysname()
Devices under /sys/firmware/ do not have subsystems. Hence, the
validation in sd_device_new_from_subsystem_sysname() ->
device_new_from_path_join() always failed.

Fixes a bug introduced by cd7c71154c (v257).
Fixes #35861.
2025-01-05 03:52:05 +09:00