Commit Graph

53310 Commits

Author SHA1 Message Date
Lennart Poettering
25ec3fdfd3 core: also check boot ID and product UUID in ConditionHost=
Sometimes it's interesting to condition units not just on the
installation but on the physical device. Let's make ConditionHost=
useful for that kind of checks, and while we are at it, also allow it to
be used for condition checks on the boot id.

Overloading like this is safe, since UUIDs are globally unique after
all, and hence there should be no conflicts between the namespace of
boot ids, machine ids and product ids.

Finally, relax rules on uuid checking: if the specified string parses
as uuid or id, also check it against the hostname, for setups where
people name hosts after uuids. I wouldn't know why anyone would do that,
but also, why not? shouldn'rt hurt allowing them and should not create
ambiguity conflicts.
2025-02-20 18:13:38 +01:00
Lennart Poettering
9ef8138946 homework: unify common error handling 2025-02-20 18:13:18 +01:00
Lennart Poettering
cfeeaebafe homed: explicitly set access mode of private/public signing key pair
So far we relied that the temporary file logic would create the key
files with 0600 mode, but let's set the access mode explicitly:

1. Tighten private key file access from 0600 to 0400, after all we never
   want to write it again, it's not a mutable file.

2. Relaxed public key file access mode from 0600 to 0444, after all it's
   a public key file, and people should be able to see it if they want
   This is useful for propagating the key onto other systems if needed.
2025-02-20 17:35:12 +01:00
Lennart Poettering
9df18e4bee tree-wide: initialize row/column explicitly before calling sd_json_parse_file()
The variables are error return parameters, i.e. only initialized on some errors,
not all. Let's hence always zero initialize them.
2025-02-20 17:34:36 +01:00
Lennart Poettering
2cf95e5178 homed: return the correct error if an image file is not present when we try to activate it
We already return BUS_ERROR_HOME_ABSENT when we detect the image being
absent before we fork off the homework worker. Let's also return the
same error if the homework process notices the same condition while
actually doing something.

This mostly fixes a race, that the same condition seen at different
points in time results in the same errors.
2025-02-20 17:34:02 +01:00
Lennart Poettering
6828cc112a resolve: cleanups for validating query flags and fix resolving service with record type filter (#36398)
Follow-up for 81ae2237c1.
Fixes
https://github.com/systemd/systemd/pull/36353#issuecomment-2659558382.
2025-02-20 17:31:19 +01:00
Lennart Poettering
b3adb7cd63 user-runtime-dir: use right accessor got get GID of account 2025-02-20 16:44:41 +01:00
Lennart Poettering
06d77db6fb homed: make "register" call more friendly
Let's accept full user records (including status and so on) and simply
eat up the parts we don't care about, instead of refusing the whole
record wholesale.

This makes it easier to just copy a user record from one machine and
registering it at another, without stripping the irrelevant parts first.
2025-02-20 16:44:10 +01:00
Pavithra Barithaya
6a12c90ca3 timedated: Send error when time set is past build date time
When the user/customer sets the time on the system which is prior
than that of the systemd build time, as systemd doesn't allow time
before it's build date after a reboot, systemd is resetting it but
there is no error or exception present in the setTime method due
to which user/customer is unaware of why the time is reset back to
the systemd-build time.

Added a condition check in the set_time() method to return an
error when tried to set time past the systemd build date.

Tested: Verified that it throws an error when we try to set the
time prior to systemd build date.

Change-Id: Ia6b58320bdb7234a21885a44af8fd3bda64c3789
2025-02-20 15:22:15 +01:00
Luca Boccassi
5dbc4f37c5 tree-wide: tweaks to mount point inode creation (#36308)
Some love for make_mount_point_inode_from_xyz() and ports PID 1 over to
it for mount units.

Alternative to #36290
2025-02-19 22:09:52 +00:00
Luca Boccassi
4225242149 repart: add parameter to attach offline verity signature (#36405)
Add --join-signature=hash:sig - when a verity signature partition
has been deferred in a previous run, this allows attaching a signature
that was created offline, for example on a build system like OBS where
the private key is not available to the build process.

Can be specified multiple times, the right partition to act upon will
be selected by matching the data+verity partitions UUIDs with the
provided roothash(es)
2025-02-19 18:12:19 +00:00
Luca Boccassi
09fd125059 repart: add parameter to attach offline verity signatures
Add --join-signature=hash:sig - when a verity signature partition
has been deferred in a previous run, this allows attaching a signature
that was created offline, for example on a build system like OBS where
the private key is not available to the build process.

Can be specified multiple times, the right partition to act upon will
be selected by matching the data+verity partitions UUIDs with the
provided roothash(es)
2025-02-19 16:26:05 +00:00
xinpeng wang
df1ff1c0a0 logind: save seat before applying acl
udev will trigger the uaccess program in 73-seat-late.rules, which
may modify the device's acl permissions. In some cases, udev triggers
the uaccess program when logind is started and active is being set.
At this time, 1) logind sets the user's acl permissions, 2) uaccess
obtains active and sets acl permissions; 3) logind updates seat's
stat_file and writes active. This situation will cause the device to
not have the correct acl permissions, resulting in abnormal situations
such as a black screen. Therefore, it is necessary to write active to
seat's stat file before setting acl.
2025-02-19 16:38:33 +01:00
Luca Boccassi
7b0403bef9 network: drop old kernel support (#36402) 2025-02-18 22:39:36 +00:00
Yu Watanabe
18f2d38d5f Journal-remote: modernize source_free() and fix memleak (#36430)
- modernize source_free().
- fix memleak introduced by cfaf78001c. Fixes CID#1591182.
2025-02-19 04:56:15 +09:00
Yu Watanabe
a6eb22968c terminal-util: fix possible NULL pointer dereference
Fixes a bug introduced by 94a2b1cd25.
Fixes CID#1591787.
2025-02-18 18:34:39 +01:00
Yu Watanabe
134bb7bfdf nspawn: unconditionally enable FUSE and use FOREACH_ARRAY() (#36407)
- FUSE is unconditionally enabled in the container, as our kernel base
line (v5.4) supports userns-safe FUSE, which is supported since v4.18.
- Create /dev/net/tun only when it is accessible.
- Replaces several loops with FOREACH_ARRAY().
2025-02-19 02:09:58 +09:00
Yu Watanabe
011a83e42b network: fix KeepConfiguration=yes (#36414)
Fixes a regression in dd6d53a8dc (v257).
Fixes #36411.
2025-02-19 02:09:09 +09:00
Steve Ramage
a4750ae156 network: doc and code typo fixes (#36422)
This fixes some typos in the documentation, both grammar as well as
incorrect field names.
It also changes the casing of CheckSum to Checksum in L2TP to match
other casings.
2025-02-19 02:08:16 +09:00
Yu Watanabe
54258df829 journal-remote: fix memleak
Fixes a bug introduced by cfaf78001c.
Fixes CID#1591182.
2025-02-19 01:00:20 +09:00
Yu Watanabe
ca25c8a5e2 journal-remote: modernize source_free()
- make it return NULL,
- suppress log message about reference counter of writer unless trace
  logging is enabled,
- introduce cleanup function for RemoteSource.
2025-02-19 00:58:24 +09:00
Luca Boccassi
b7a2f8715e dissect: add helper functions to use VeritySettings in hash/set 2025-02-18 14:44:51 +00:00
Yu Watanabe
114d191a17 nspawn: move the accessibility check for device nodes into copy_devnode_one() 2025-02-18 23:35:13 +09:00
Yu Watanabe
c51e472bd4 nspawn: drop unused argument for copy_devnode_one() 2025-02-18 23:24:20 +09:00
Yu Watanabe
9fff6bf59e nspawn: create /dev/net/tun only when it is accessible
Follow-up for 985ea98e7f.

When DevicePolicy= is enabled, but DeviceAllow= for /dev/net/tun is not
specified, bind-mounting the device node from the host system is
meaningless, as it cannot be used in the container anyway.

Let's check the device node is accessible before creating or
bind-mounting.
2025-02-18 23:24:20 +09:00
Yu Watanabe
3cc23a2c23 nspawn: enable FUSE unconditionally
FUSE is userns-safe since kernel v4.18 (da315f6e03988a7127680bbc26e1028991b899b8),
and now our kernel base line is 5.4. Let's drop the logic of checking
the version of FUSE, and unconditionally enable FUSE.
2025-02-18 23:24:20 +09:00
Yu Watanabe
1236f06c42 nspawn: use FOREACH_ARRAY() where applicable 2025-02-18 23:24:20 +09:00
Yu Watanabe
81f637630c network: introduce link_should_mark_config()
This split-out common logic from link_drop_routes() and friends.

This is mostly a refactoring, and not change behavior in most cases.
But slightly change behavior for how foreign nexthops and routing
policy rules are managed.

E.g. when KeepConfiguration=static, previously all foreign nexthops and
routing policy rules were kept, but now only foreign nexthops and rules
with RTPROT_STATIC are kept and others are dropped.

Similary, when KeepConfiguration=dynamic, previously all foreign nexthops
and rules were removed, but now foreign configs with a dynamic protocol
e.g. RTPROT_DHCP are kept, and still configs with RTPROT_STATIC are
dropped.

Currently, we do not set/get/manage protocol for neighbor entries.
Hence, the logic of managing foreign neighbor entries is unchanged.
2025-02-18 23:13:51 +09:00
Yu Watanabe
724faccf45 network/route: do not remove any foreign routes when KeepConfiguration=yes
Without this change, only foreign routes with RTPROT_KERNEL, RTPROT_STATIC,
RTPROT_DHCP, RTPROT_RA, and RTPROT_REDIRECT are kept, and foreign routes with
other protocol e.g. RTPROT_BOOT are removed even if KeepConfiguration=yes.

Fixes a regression in dd6d53a8dc (v257).
Fixes #36411.
2025-02-18 23:01:53 +09:00
Lennart Poettering
4e24796b5a mount-tool: add explicitly control of path canonicalization
With this the default canonicalization of paths can be turned off,
giving users explicit control on what shall happen if symlinks are
encountered within a path.
2025-02-18 13:49:24 +01:00
Lennart Poettering
61178346e6 mount-tool: modernize umount and make sure it works for bind mounted files
So far, "systemd-umount" executed on a bind mounted file would assume it
is supposed to unmount a loopback mounted file system. Let's address
that by instead checking if the file is a mount.
2025-02-18 13:49:24 +01:00
Lennart Poettering
66b5e7dfaa catalog: assign a proper message ID for mounts on symlinked paths
For some reason we reused the non-empty catalog entry so far, which is
plain wrong. Correct that.
2025-02-18 13:49:24 +01:00
Lennart Poettering
38c35970b1 core: port mount unit inode creation to make_mount_point_inode_from_mode() too
This also ports over things to use chase() to create/pin the underlying
to mount, and in particular checks that the path does not contain any
symlinks. That's crucial since we cannot allow mounts to be established
with that, since it would mean we couldn't recognize the entries in
/proc/self/mountinfo anymore.
2025-02-18 13:49:24 +01:00
Lennart Poettering
3075ea0bc9 mount-util: refactor make_mount_point_inode_from_xyz()
This replaces make_mount_point_inode_from_stat() by
make_mount_point_inode_from_mode() and makes it take a single mode_t
rather than a "struct stat". Moreover, at an "atfd" style directory
parameter.

Then port all users over to new feature, and in particular make use of
the directory fd: use chase() to create and pin parent directories first where
needed.
2025-02-18 13:49:24 +01:00
Lennart Poettering
8e0193aabf tree-wide: pass EBADF to fd params of namespace_fork() 2025-02-18 12:11:00 +01:00
Lennart Poettering
fff6dfc75e timedated: rework clock change overflow check
Let's use explicit language constructs to test for overflow, the
previous code was ultimately relying on undefined behaviour.
2025-02-18 11:22:34 +01:00
Lennart Poettering
787904d078 terminal-util: output newline at end of "Press any key to proceed" message
So far we'd leave the cursor at the end of the Press any key to proceed
message as long as the user didn't type in anything yet, and generated
the newline only after.

Let's switch this around: let's output the newline before.

This should make boot-time output nicer since it means concurrent output
while we wait will start at the beginning of line, and not in the middle.
2025-02-18 09:19:03 +01:00
Lennart Poettering
0e7dd5aa4d homectl: when asking for a user pw for an initial homed account at boot, don't insist on strong password
It's just very annoying during debugging, and also unnecessary.
2025-02-18 09:19:03 +01:00
Lennart Poettering
0680c7e5b4 homectl: don't show --enforce-password-policy= recommendation in first-boot invocation
The hint is not useful, since this is after all invoked as part of the
boot process, and not from an interactive shell, where the user could
directly retry with the changed switch. Hence let's simply suppress the
hint for those cases.
2025-02-18 09:19:03 +01:00
Luca Boccassi
cf4deeaf1e ukify: print all remaining log-like output to stderr
We want to be able to capture stdout for json and such, so convert
all remaining logging to stderr.
2025-02-17 22:20:32 +01:00
Lennart Poettering
0fe3b0e4e2 homectl: show full list of selected groups as they are added 2025-02-17 15:21:18 +01:00
Lennart Poettering
cfe16540c8 homectl: optionally force interactive firstboot query 2025-02-17 15:21:18 +01:00
Lennart Poettering
9e6fbb5a51 homectl: clarify that we pick the default shell if the prompt is skipped 2025-02-17 15:21:18 +01:00
Lennart Poettering
94a2b1cd25 firstboot: add auto-completion to various fields
This adds TAB-based auto-completion to various fields we query from the
user, such as locale, keymap, timezone, group membership.

It makes it a lot easier to quickly iterate through firstboot without
typing too much.
2025-02-17 15:21:18 +01:00
Lennart Poettering
b6478aa12f terminal-util: beef up show_menu()
This modernizes the function a bit, and adds some bits:

1. whether to show numbers before entries is now optional, and if they
   are shown they are displayed in grey.

2. a common prefix can now be grayed out (later useful for completion
   support)

3. some variables have been named to clarify their purpose

4. the table display dimensions can now be auto-sized (by specifying
   SIZE_MAX and number of columns and column width)
2025-02-17 15:21:13 +01:00
Lennart Poettering
8fcd85768b terminal-util: tweak any_key_to_proceed() a bit
1. Make the message a bit more visible, by adding ANSI color. This
   matters in particular during boot, where the message otherwise might
   be overprinted by other output

2. Let's turn off terminal echo so that whatever key is entered is not
   made visible on screen, and we can handle newline and other keys
   reasonably uniformly.
2025-02-17 15:07:38 +01:00
Lennart Poettering
4ba044ebd0 ask-password-api: refuse control characters in passwords
Just some extra safety
2025-02-17 15:05:18 +01:00
Lennart Poettering
104a6b8c39 utf8: add helper that determines length in bytes of last UTF-8 character in string 2025-02-17 15:05:18 +01:00
Lennart Poettering
428146dc89 strv-util: add strv_filter_prefix() helper 2025-02-17 15:00:00 +01:00
Lennart Poettering
f77f363c95 string-util: add str_common_prefix() helper that determines length of common prefix of two strings 2025-02-17 14:57:03 +01:00