Commit Graph

214 Commits

Author SHA1 Message Date
Daan De Meyer
8857aa74e5 tree-wide: Clean up includes
This commit cleans up the includes for all the small tools across
the tree.

A few cases of returning EXIT_SUCCESS are replaced with returning
0 to avoid including <stdlib.h>.

Split out of #37344.
2025-05-14 22:34:02 +02: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
Daan De Meyer
6553db6063 strv: Reduce transitive includes 2025-05-07 22:04:46 +09:00
Daan De Meyer
76d62b63ef main-func: Reduce transitive includes
Let's move some logic from _DEFINE_MAIN_FUNCTION() and other places
in main-func.h into functions that we implement in main-func.c to
allow moving some included headers from the header to the .c file.
2025-05-06 10:07:27 +02:00
Lennart Poettering
743667e069 dissect-tool: expose image filtering via new --image-filter= parameter 2025-04-03 11:08:57 +02:00
Lennart Poettering
f1395724f6 dissect-image: add a concept for "filtering" partitions we dissect
DDIs may contain multiple versions of the same OS, or even multiple
OSes. Hence it makes sense to not just pick the "newest", whatever that
might be, but only partitions associated with specific images, or in a
specific version.

Let's a concept for such filtering: a per-designator glob expression
that can be applied to the partition label string, and can be used for
such filtering.

Usecase: when picking UKI belonging to OS image X in version Y, make
sure we only pick a /usr/ partition belonging to X in version Y, and a
root and home partition belonging to X in any version.

This only adds the basic infrastructure, but doesn't actually expose it
anywhere.
2025-04-03 11:08:57 +02:00
Lennart Poettering
e34c89897a dissect-image: guess verity root hash from the resources we found
When dissecting an image, let's make use of the Verity data even if we
got told no root hash explicitly: we can simply determine it by
concatenating the data partition uuid with the verity partition uuid.

Of course, on first thought this doesn't really add much: if the root
hash is not pinned from somewhere, this does not guarantee trust in
the image.

However, this is very useful for attestation: if we have the root hash
we can measure it before mounting things, even if we don't actually
authenticate it.

Hence, at best this helps us with attestation, at worst it doesn't improve
security but certainly doesn't hurt it.
2025-04-03 11:08:57 +02: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
c0cc01de8a meson: use install_symlink() where applicable
Now our baseline of meson is 0.62, hence install_symlink() can be used.

Note, install_symlink() implies install_emptydir() for specified
install_dir. Hence, this also drops several unnecessary
install_emptydir() calls.

Note, the function currently does not support 'relative' and 'force' flags,
so several 'ln -frsT' inline calls cannot be replaced.
2025-03-10 02:41:40 +09:00
Lennart Poettering
10b8d65f3f dissect: accept --usr-hash=… too, similar to --root-hash=…
This addresses an omission, given that we have both kinds of hashes
these days.
2025-03-06 23:35:31 +01:00
Yu Watanabe
5c9feb2d6e tree-wide: drop unnecessary break in default branch 2025-03-06 11:42:20 +01:00
Lennart Poettering
3568c47664 dissect: show basic image data even when can't enter the file systems 2025-03-05 21:21:36 +01:00
Lennart Poettering
172fadda65 dissect: add --quiet mode 2025-02-21 09:57:02 +01:00
Lennart Poettering
6b3fd03eac dissect: optionally derive loop-ref from image filename 2025-02-21 09:57:02 +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
Daan De Meyer
6309efbf31 dissect: Use COPY_MERGE
When copying a directory from or to an image, let's always merge
with existing directories instead of failing with "File Exists".

Fixes https://github.com/systemd/mkosi/issues/3342.
2025-01-14 11:13:25 +01:00
Lennart Poettering
55e4946f9c dissect: add new --shift command 2025-01-08 21:54:19 +01:00
Lennart Poettering
ec0c10fc9d user-classification: add new "foreign" UID range
This makes the UID range configurable via build time options, but of
course it really shouldn't be changed. The default range I picked is
outside even of IPAs current (ridiculously large) allocation ranges,
hence hopefully minimizes conflicts.
2025-01-08 21:41:03 +01:00
Lennart Poettering
bacc04bedc dissect: minor simplifications 2025-01-03 16:43:43 +01:00
Lennart Poettering
bd2fd85501 dissect: employ vpick also if we operate on a directory-based image 2025-01-03 10:14:20 +01:00
Lennart Poettering
8ef117ff4b dissect: add a bit of color to --discover table 2025-01-03 10:13:13 +01:00
Lennart Poettering
41c2a5b0b9 dissect: show all kinds of images in --discover
Given that systemd-dissect can nowadays operate on plain directories,
let's include directory images in the --discover output too.

Replace the filter with a filter for hidden images instead, as suddenly
the root fs image (which is a directory image ".host") otherwise shows up.
2025-01-03 10:12:23 +01:00
Lennart Poettering
1c0ade2e1f discover-image: introduce per-user image directories
We nowadays support unprivileged invocation of systemd-nspawn +
systemd-vmspawn, but there was no support for discovering suitable disk
images (i.e. no per-user counterpart of /var/lib/machines). Add this
now, and hook it up everywhere.

Instead of hardcoding machined's, importd's, portabled's, sysupdated's
image discovery to RUNTIME_SCOPE_SYSTEM I introduced a field that make
the scope variable, even if this field is always initialized to
RUNTIME_SCOPE_SYSTEM for now. I think these four services should
eventually be updated to support a per-user concept too, this is
preparation for that, even though it doesn't outright add support for
this.

This is for the largest part not user visible, except for in nspawn,
vmspawn and the dissect tool. For the latter I added a pair of
--user/--system switches to select the discovery scope.
2024-12-20 18:04:01 +01:00
Mike Yuan
e2f82f6151 various: check meson feature flag early
Prompted by https://github.com/systemd/systemd/pull/35110#discussion_r1835885340
2024-11-13 08:21:33 +09:00
Zbigniew Jędrzejewski-Szmek
23441a3d88 sd-json,tree-wide: add sd_json_format_enabled() and use it everwhere
We often used a pattern like if (!FLAGS_SET(flags, SD_JSON_FORMAT_OFF)),
which is rather verbose and also contains a double negative, which we try
to avoid. Add a little helper to avoid an explicit bit check.

This change clarifies an aditional thing: in some cases we treated
SD_JSON_FORMAT_OFF as a flag (flags & SD_JSON_FORMAT_OFF), while in other cases
we treated it as an independent enum value (flags == SD_JSON_FORMAT_OFF).
In the first form, flags like SD_JSON_FORMAT_SSE do _not_ turn the json
output on, while in the second form they do. Let's use the first form
everywhere.

No functional change intended.

Initially I wasn't sure if this helper should be made public or just internal,
but it seems such a common pattern that if we expose the flags, we might just
as well expose it too, to make life easier for any consumers.
2024-10-28 09:23:07 +01:00
Lennart Poettering
300b7e7620 tree-wide: use isatty_safe() more 2024-08-20 11:11:53 +02:00
Lennart Poettering
be5bee2a13 tree-wide: port over to new builder apis 2024-06-19 22:50:02 +02:00
Lennart Poettering
309a747fa6 libsystemd: turn json.[ch] into a public API
This is preparation for making our Varlink API a public API. Since our
Varlink API is built on top of our JSON API we need to make that public
first (it's a nice API, but JSON APIs there are already enough, this is
purely about the Varlink angle).

I made most of the json.h APIs public, and just placed them in
sd-json.h. Sometimes I wasn't so sure however, since the underlying data
structures would have to be made public too. If in doubt I didn#t risk
it, and moved the relevant API to src/libsystemd/sd-json/json-util.h
instead (without any sd_* symbol prefixes).

This is mostly a giant search/replace patch.
2024-06-12 18:42:22 +02:00
Lennart Poettering
fdec6d1560 dissect-tool: allow systemd-dissect to talk to mountfsd 2024-04-06 16:08:24 +02:00
Lennart Poettering
44e3097dff dissect-image: make dissected_image_acquire_metadata() operate within a userns if possible
This opens the door for making the call work without privileges: if we
pass in a userns fd and DissectedImage that has mount fds then we can
acquire all information without privs.
2024-04-06 16:08:23 +02:00
Antonio Alvarez Feijoo
dde1931b06 dissect: fix memory leak 2024-03-27 02:33:00 +09:00
Lennart Poettering
f4a63ce25f dissect-image: add flag for explicitly enabling userspace verity signature checking
let's make userspace verity signature checking optional. This adds a
dissection flag to enable the logic and patches through all our users to
enable it by default, thus effectively not changing anything from the
status quo ante. However, know we have a knob to turn this off in
certain scenarios.
2024-02-28 16:17:40 +01:00
Adrian Vovk
0bac442251 basic: Add some sha256 helper functions
Adds a util function to sha256 an open fd (moved from dissect). Also
adds functions to check if a string contains a valid sha256 hash, and
parse it into a sha256 array.
2024-02-13 13:59:27 -05:00
Lennart Poettering
b68f4cade4 dissect: add --make-archive option to convert DDI to tarball 2024-01-25 18:47:39 +01:00
Lennart Poettering
9603fd29f8 dissect: show image name separately from filename
If the image name is different from the filename then show it in the
output, since it's relevant for finding sysext/confext release files.

(Image name is typically the filename without the ".raw" suffix and
similar).
2024-01-24 01:33:48 +08:00
Antonio Alvarez Feijoo
08c0b6efd8 dissect: fix typo 2024-01-19 16:01:13 +01:00
Lennart Poettering
2d1e7d1937 dissect-image: introduce new get_common_dissect_directory() helper
So far, if some component mounts a DDI in some local mount namespace we
created a temporary mountpoint in /tmp/ for that. Let's instead use the
same directory inode in /run/ instead. This is safe, since if everything
runs in a local mount namespace (with propagation on /run/ off) then
they shouldn't fight for the inode. And it relieves us from having to
clean up the directory after use. Morever, it allows us to run without
/tmp/ mounted.

This only moves dissect-image.c and the dissec tool over. More stuff is
moved over later.
2024-01-18 01:30:10 +00:00
Zbigniew Jędrzejewski-Szmek
8e1ac16bc6 src/basic: rename uid-alloc-range.[ch] to uid-classification.[ch]
We had both uid-range.h and uid-alloc-range.h. The latter now contains helpers
like {uid,gid}_is_{system,dynamic,container}(), uid_for_system_journal(), so
the existing name is outdated. I think the uid-range.[ch] should stay separate
because it has a bunch of helpers for parsing and printing of uid ranges. So
let's rename as in $subject to better reflect the contents of the file and make
the two sets of files harder to confuse.
2024-01-09 11:15:00 +01:00
Mike Yuan
bdd2036e81 hexdecoct: make unbase64mem and unhexmem always use SIZE_MAX 2024-01-09 03:59:15 +09:00
Luca Boccassi
43108bf87a dissect: add assert to guide static analysis
CID#1533112
2024-01-04 14:30:20 +01:00
Lennart Poettering
d768856819 dissect: port to vpick for selecting image 2024-01-03 18:38:46 +01:00
Luca Boccassi
86b8b66675 Merge pull request #30591 from yuwata/device-util
device-util: introduce device_in_subsystem() and device_is_devtype() helper functions
2024-01-01 19:26:39 +01:00
Yu Watanabe
1d03d970a1 tree-wide: insert space after for and switch 2023-12-25 01:29:38 +09:00
Yu Watanabe
fb53ee0a64 tree-wide: use device_in_subsystem() and device_is_devtype() 2023-12-23 03:52:21 +09:00
Lennart Poettering
64cd3d13ea dissect-tool: hide device column if it's a short-lived loopback device
It's pointless showing info that isn#t going to survive the current
invocation, hence hide it.

The "partition number" column is more useful since it kinda shows the
same information, but without the device node name prefixed that is
local to the currentl invocation.
2023-12-13 17:41:18 +01:00
Lennart Poettering
5b1b37c86a dissect-tool: show sector/image size from DissectedImage object
The information is provided to us already in the structure now, hence
use it.
2023-12-13 17:35:22 +01:00
Lennart Poettering
748e87a791 dissect-tool: right-align the partition number
The right-alignment was applied to the wrong column, because neither
ee8e497d24 nor
1474d7ac2d updated the column count as
they should have.
2023-12-13 00:56:48 +00:00
Lennart Poettering
ba113008de dissect: set dash as ersatz string 2023-11-15 22:51:37 +01:00
Lennart Poettering
8f488d4634 dissect: right-align size column in --discover table 2023-11-15 22:51:37 +01:00
Lennart Poettering
b2466e05c7 dissect: move helpers for categorizing DDIs into generic code
These tests are already done at two places, let's unify them in one
place, and tweak them slightly (specifically: require for considering a
DDI bootable in UEFI we also need need an init system inside).
2023-10-11 15:56:08 +02:00