Commit Graph
6617 Commits
Author SHA1 Message Date
Lennart Poettering 0783d8da50 xattr-util: use at_flags_normalize_nofollow() at one more place 2025-01-22 17:46:06 +01:00
Mike Yuan 6cab0df904 mountpoint-util: port path_is_mount_point() to chase_and_open_parent() 2025-01-22 01:37:32 +01:00
Mike Yuan 7ce2c1bb5f mountpoint-util: rename fd_is_mount_point() to is_mount_point_at()
fd_* functions in our codebase usually mean fd-specific operations,
while this one actually takes openat()-style params. Rename it
accordingly hence.
2025-01-22 01:37:31 +01:00
Mike Yuan e2f97c790e mountpoint-util: some tweaks for fd_is_mount_point()
- Drop fstat() fallback path now that we assume fdinfo
  is available
- Use at_flags_normalize_nofollow()
- Accept empty path the same way as NULL
- Accept fd being AT_FDCWD and filename being "."
2025-01-22 01:37:09 +01:00
Mike Yuan e5a3127339 mountpoint-util: our baseline includes fdinfo and mnt_id now 2025-01-22 01:12:55 +01:00
Mike Yuan 229429a799 mountpoint-util: check >= 0 for success 2025-01-22 01:12:54 +01:00
Mike Yuan c3b7f0240f mountpoint-util: update comment in is_name_to_handle_at_fatal_error()
We can now assume name_to_handle_at() syscall is available,
however the underlying fs can still lack support for it.
2025-01-22 01:12:10 +01:00
Mike Yuan 6981203f3a fs-util: introduce at_flags_normalize_nofollow() helper 2025-01-22 00:52:34 +01:00
Lennart Poettering 5072f4268b strv: add strv_equal_ignore_order() helper 2025-01-21 09:56:53 +01:00
Lennart Poettering 36a2be13c4 random-util: include pidfdid in fallback RNG buffer
This doesn't make the RNG cryptographic strength, but if we have it
easily accessible, why not include the pidfd id. It is after all not
vulnerable to reuse.
2025-01-20 21:51:40 +01:00
Lennart Poettering 4ace93da8c pidref: now that we have the cached pidfdid of our own process, use it
Note that this drops a lot of "const" qualifiers on PidRef arguments.
That's because pidref_is_self() suddenly might end changing the PidRef
because it acquires the pidfd ID.

We had this previously already with pidfd_equal(), but this amplifies
the problem.

I guess we C's "const" doesn't really work for stuff that contains
caches, that is just conceptually constant, but not actually.
2025-01-20 21:51:40 +01:00
Lennart Poettering afede53ae9 pidfd-util: add helper for getting our own pidfdid
let's start caching our own pidfd id, since it's somewhat involved to
get but a much better identifier for things than the classic PID is.
2025-01-20 21:51:29 +01:00
Lennart Poettering 5dc9d5b4ea pidfd-util: dont open a new pidfd unnecessarily in pidfd_check_pidfs() 2025-01-20 21:49:38 +01:00
Lennart Poettering c66a7ca6e5 machine-id-setup: move code to use chase() (#35979)
I just wanted to switch the machine id setup code to use chase() or its
changes, given it supports --root=/--image= operation. That turned out
to be a rabbit hole, and became much bigger...
2025-01-20 21:18:24 +01: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
Lennart Poettering 3351c0a510 chase: move appending of trailing slash out of loop
let's move final processing of the filename out of the loop, and apply
it in all cases, uniformly, even if we are asked to only return the
final filename.
2025-01-20 11:35:04 +01:00
Lennart Poettering 90b9f7a07e chase: introduce flags that verify that chased inode is regular file or dir
This also implies the new CHASE_MUST_BE_DIRECTORY flag in case the
specified path ends in a slash. This makes the rules stricter, it means
we'll be closer to how this is handled in kernel: if a path ends in a
slash it can never refer to a non-directory.
2025-01-20 11:35:03 +01:00
Lennart Poettering b0afd29f7d chase: use streq() not path_equal() to compare filenames 2025-01-20 11:31:55 +01:00
Lennart Poettering e49e76d64d chase: allow using chase() as mkdir_p() replacement
This allows using CHASE_MKDIR_0755 without CHASE_NONEXISTENT or
CHASE_PARENT, so that it will create the final component of the path
too should it be missing.

This is really useful as a mkdir_p() replacement that returns an fd to
the final component, and knows how to operate relative to a root fs.

Kinda reverts 4ea0bcb922 (which only
refused the flags combination which didn't work, instead of making it
work, which is what this commit does.)

This also corrects behaviour if CHASE_MKDIR_0755 is used in one more
way: we'll now always open the dir as O_PATH. This is generally the
better idea, but matters in particular once with allow using
CHASE_MKDIR_0755 to create the final component: we should uniformly
return an O_PATH dir that must be converted to a proper fd first before
using it.
2025-01-20 11:31:55 +01:00
Yu Watanabe 2cf9635511 capability-util: rename output argument of capability_gain_cap_setpcap() 2025-01-19 14:00:16 +00: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 f0159e2b5b process-util: fix typo
Also rebreak comment.

Follow-up for 03b89cf213.
2025-01-19 04:24:08 +09:00
Yu Watanabe 43e95ddbf4 capability-util: drop _cleanup_cap_free_charp_
Also moves cap_free_charpp() to test-cap-list.c, as it is used only
there.
2025-01-19 04:04:47 +09:00
Yu Watanabe fe5a1afb67 tree-wide: use _cleanup_hashmap_free_ and friends 2025-01-19 03:48:15 +09:00
Lennart Poettering ea844c49c3 escape: make 'bad' parameter optional
Treat a NULL bad parameter just like an empty one: do not escape any
additional characters except for the CC chars.
2025-01-17 19:47:43 +00:00
Mike Yuan 9cd064aa9f meson: bump C std to gnu17
GCC 8.4 (our baseline) defaults to gnu17 already.
2025-01-17 19:46:37 +00:00
Lennart Poettering ce2ef96c2b hexdump: if size is SIZE_MAX, use strlen()
Similar how we do this as various places: if SIZE_MAX is specified as
size determine the size automatically via strlen().
2025-01-17 17:02:07 +01:00
Lennart Poettering 1d5f0a88e0 fundamental: unify gcc warning pragmas at one place
This also drops HAVE_WSTRINGOP_TRUNCATION as the corresponding option
was introduced in GCC 8, and our baseline is GCC 8.4.
2025-01-17 04:08:58 +09:00
Lennart Poettering 277255e814 process-util: slightly update comment in freeze() 2025-01-16 11:55:21 +01:00
Lennart Poettering d6267b9b18 process-util: port pid_from_same_root_fs() to pidref, and port three places over to it 2025-01-16 11:55:21 +01:00
Lennart Poettering 6eeeef9f66 process-util: introduce new FORK_FREEZE flag for safe_fork()
Often we want to fork off a process that just hangs until we kill it,
let's add a simple flag to create one of this type, and use it at
various places.
2025-01-16 11:55:21 +01:00
Lennart Poettering 8110b34b64 pidref: various shortcuts to pidref_equal()
This adds some shortcuts to pidref_equal(), so that we don't have to
query the pidfs id if there's no need.
2025-01-16 11:55:21 +01: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
Lennart Poettering 39706728e1 namespace-util: don't reset UID/GIDs in namespace_enter() unless we enter a userns
The reset of UID/GID only really makes sense if we enter a userns, hence
let#s restrict it to that.
2025-01-16 11:26:57 +01:00
Mike Yuan 70923ed358 meson: enable -Wzero-as-null-pointer-constant
Support for C added in gcc 15:
https://github.com/gcc-mirror/gcc/commit/236c0829ee21a179c81b83f0d7f112ca23c47a4d
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
hanjinpeng 7e91a68b2f log: check isempty for object_field and extra_field 2025-01-15 22:36:58 +00:00
Lennart Poettering 2ca0f3ed2e pty_open_peer() follow-up (#36027) 2025-01-15 21:05:59 +01:00
Yu Watanabe e722fe74ca random-util: fix compilation error
Fixes the following error:
```
../src/basic/random-util.c: In function "fallback_random_bytes":
../src/basic/random-util.c:45:26: error: initializer-string for array of "char" is too long [-Werror=unterminated-string-initialization]
   45 |                 .label = "systemd fallback random bytes v1",
      |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
```
2025-01-15 20:24:30 +01:00
Mike Yuan d693ba5f8e terminal-util: drop unused open_terminal_in_namespace()
With our baseline including TIOCGPTPEER we now systematically
open pty peer through ioctl(), i.e. this sits unused
since 1d522f1a86. Kill it!
2025-01-15 17:46:10 +01:00
wrvsrx 6013dee98d efivars: deal with uncommitted efi variables
Unfortunately kernel reports EOF if there's an inconsistency between efivarfs var list
and what's actually stored in firmware, c.f. #34304. A zero size env var is not allowed in
efi and hence the variable doesn't really exist in the backing store as long as it is zero
sized, and the kernel calls this "uncommitted". Hence we translate EOF back to ENOENT here,
as with kernel behavior before
https://github.com/torvalds/linux/commit/3fab70c165795431f00ddf9be8b84ddd07bd1f8f

If the kernel changes behaviour (to flush dentries on resume), we can drop
this at some point in the future. But note that the commit is 11
years old at this point so we'll need to deal with the current behaviour for
a long time.

Fix #34304.
2025-01-15 16:53:21 +01:00
Lennart Poettering b5a6f4c05b string-util: make strjoin() just a special case of strextend() (#36011)
This is split out of #36010, but makes a ton of sense on its own.
2025-01-15 13:25:08 +01:00
Lennart Poettering 7adafb0832 missing: add quotactl_fd() wrapper 2025-01-15 13:24:04 +01:00
Lennart Poettering fd3b7cf772 string-util: add a mechanism for strextend_with_separator() for specifying "ignore" arguments
in strv_new() we have STRV_IGNORE for skipping over an argument in the
argument list. Let's add the same to strextend_with_separator():

strextend_with_separator(&x, "foo", POINTER_MAX, "bar");

will result in "foobar" being appended to "x". (POINTER_MAX Which is
different from NULL, which terminates the argument list).

This is useful for ternary op situations.

(We should probably get rid of STRV_IGNORE and just use POINTER_MAX
everywhere directly, but that's for another time.)
2025-01-15 10:52:38 +01:00
Lennart Poettering 34467ffa3c string-util: make strjoin() just a special case of strextend()
The functions are very similar, let's make them the same. If the first
argument to strextend() is NULL instead of extending a string we'll
allocate a fresh one and return that.
2025-01-15 10:51:53 +01:00
Lennart Poettering 1d522f1a86 terminal-util: drop support for pre-TIOCGPTPEER kernels
Our minimum baseline is now far beyond 4.13, hence let's drop these
fallback paths.
2025-01-15 10:39:04 +01:00
Zbigniew Jędrzejewski-Szmek 69c9629da7 sysusers: emit audit events for user and group creation (#35957)
Background: Fedora/RHEL are switching to sysusers.d metadata for
creation of users and groups for system users defined by packages
(https://fedoraproject.org/wiki/Changes/RPMSuportForSystemdSysusers).
Packages carry sysusers files. During package installation, rpm calls an
program to execute on this config. This program may either be
/usr/lib/rpm/sysusers.sh which calls useradd/groupadd, or
/usr/bin/systemd-sysusers. To match the functionality provided by
useradd/groupadd from the shadow-utils project, systemd-sysusers must
emit audit events so that it provides a drop-in replacement.

systemd-sysuers will emit audit events AUDIT_ADD_USER/AUDIT_ADD_GROUP
when adding users and groups. The operation "names" are copied from
shadow-utils, so the format of the events that is generated on success
should be identical. On failure, things are more complicated. We write
the whole file at once, once, so we first generate "success" messages
for each entry, then we try to write the files, and if things fail, we
generate failure messages to all entries that we failed to write.
2025-01-15 10:36:07 +01:00
Zbigniew Jędrzejewski-Szmek 9c6afab6b6 sysusers: emit audit events for user and group creation
Background: Fedora/RHEL are switching to sysusers.d metadata for creation of
users and groups for system users defined by packages
(https://fedoraproject.org/wiki/Changes/RPMSuportForSystemdSysusers).
Packages carry sysusers files. During package installation, rpm calls an
program to execute on this config. This program may either be
/usr/lib/rpm/sysusers.sh which calls useradd/groupadd, or
/usr/bin/systemd-sysusers. To match the functionality provided by
useradd/groupadd from the shadow-utils project, systemd-sysusers must emit
audit events so that it provides a drop-in replacement.

systemd-sysuers will emit audit events AUDIT_ADD_USER/AUDIT_ADD_GROUP when
adding users and groups. The operation "names" are copied from shadow-utils in
Fedora (which has a patch to change them from the upstream version), so the
format of the events that is generated on success should be identical.

The helper code is shared between sysusers and utmp-wtmp. I changed the
audit_fd variable to be unconditional. This way we can avoid ugly iffdefery
every time the variable would be used. The cost is that 4 bytes of unused
storage might be present. This is negligible, and the compiler might even be
able to optimize that away if it inlines things.
2025-01-15 10:35:28 +01:00
Yu Watanabe 132a164d97 Follow-ups for recent namespace PRs (#35923) 2025-01-15 14:10:21 +09:00