Commit Graph

181 Commits

Author SHA1 Message Date
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
Lennart Poettering
a81fe93e95 dissect: allow confext/sysext to be in the same image
This reworks the image discovery logic, and conceptually allows DDIs
that are both confext and sysext to exist. Previously we'd only extract
one type of exension data from a DDI, with this we allow to extract both
if both exist.

This doesn't add support for true "multi-modal" DDIs, that qualify as
various things at once, it just lays some ground work that ensures we at
least can dissect such images.

This reworks 484d26dac1 quite a bit.

This changes systemd-dissect's JSON output, but given the
version with the fields it changes/dops has never been released (as the
above patch was merged post-v254) this shouldn't be an issue.
2023-10-11 15:56:08 +02:00
Lennart Poettering
1c5cc6c552 dissect: image size can be unset, suppres in JSON output then
The ioctl() failure we handle gracefully, hence also reflect that in the
JSON output.

(While we are at it, bring JSON output into same order as textual
output, i.e. move uuid down a bit.)
2023-10-11 15:56:08 +02:00
Lennart Poettering
6e0b5cd36b dissect: show architecture in JSON output too
We show it in the human readable output, and we should include the same
data in the JSON output too.
2023-10-11 15:56:08 +02:00
Lennart Poettering
e83d902bce dissect: port to new JSON_BUILD_STRV_ENV_PAIR() 2023-10-11 15:56:08 +02:00
Lennart Poettering
66cd3537f9 dissect: don't show non-JSON arch + sector size in JSON mode 2023-10-10 21:44:20 +02:00
Lennart Poettering
8d9a1d5979 dissect-image: optionally allow mounting via new kernel mount API in two steps
This adds support for the new fsmount() logic of the kernel: we'll first
create an unattached fsmount fd, and then in a second step attach this
to some real file system inode – as opposed to attaching file system
directly. The benefit of this is that we can pass the open fsmount fds
over some sockets if need be, to isolate the mounting code from the
attaching code.
2023-10-02 14:02:32 +01:00
Daan De Meyer
47838b55c8 dissect: Set SYSTEMD_DISSECT_DEVICE to path of loop device
For some use cases we want to operate on the loop device that
systemd-dissect has attached the loop device to, so let's make that
easily accessible.
2023-08-17 20:36:51 +02:00
Daan De Meyer
ad6fae7ffc copy: Add support for creating subvolumes to copy_tree_at()
The subvolumes set is a set of source inodes similar to how the
denylist hashmap contains source inodes as keys. It indicates
directories in the source tree that should become subvolumes in
the target tree.
2023-08-14 18:46:08 +02:00
Yu Watanabe
9289e093ae meson: use install_emptydir() and drop meson-make-symlink.sh
The script is mostly equivalent to 'mkdir -p' and 'ln -sfr'.
Let's replace it with install_emptydir() builtin function and
inline meson call.
2023-08-08 22:11:34 +01:00
Yu Watanabe
ec57a4ea49 meson: move declarations of dissect and friends 2023-08-01 02:31:36 +09:00
Maanya Goenka
484d26dac1 confext: add dissect tool support for confext images
Allow image wide systemd tool support for confext images by adding dissect
tool support for these images
2023-07-14 16:59:34 +00:00
Daan De Meyer
a1af83728f device-util: Declare iterator variables inline 2023-07-12 20:05:18 +02:00
Lennart Poettering
d8def0f312 dissect: add new verbs to brief version of cmline in --help 2023-07-07 17:13:32 +01:00
Daan De Meyer
12d58b6c74 dissect: Add --mtree-hash= option
Let's make including hashes in the mtree output configurable to allow
speeding up the --mtree command in cases where file hashes are not
required.
2023-07-06 12:11:45 +02:00
Daan De Meyer
2292fa1e31 dissect: Allow a few verbs to operate on directories as well as image files
--copy-to, --copy-from, --list and --mtree are useful for image directories
as well as image files, so for those verbs, let's check if we were passed
a directory and skip all the image file setup if that's the case.
2023-07-06 12:11:42 +02:00
Zbigniew Jędrzejewski-Szmek
da89046643 tree-wide: "<n>bit" → "<n>-bit"
In some places, "<n> bits" is used when more appropriate.
2023-07-02 11:10:12 +01:00
Daan De Meyer
f9f70e062d copy: Merge copy_directory() and copy_directory_fd() into copy_directory_at()
Let's merge these two into a single function that can handle both
variants and more.
2023-06-06 14:42:03 +02:00
Yu Watanabe
5d2a48da12 tree-wide: use _cleanup_set_free_ and friends
Instead of _cleanup_(set_freep) or so.
2023-06-01 06:47:48 +09:00
Zbigniew Jędrzejewski-Szmek
5fdec39796 dissect: use pager for --help
This output is already too long to fit on an normal terminal, and the
interesting parts are towards the top.
2023-05-30 16:04:13 +02:00
Frantisek Sumsal
94d82b5980 tree-wide: code spelling fixes
As reported by Fossies.
2023-04-20 21:54:59 +02:00
Yu Watanabe
06e78680e3 image-policy: introduce parse_image_policy_argument() helper
Addresses
84be0c710d (r1060130312),
84be0c710d (r1067927293), and
84be0c710d (r1067926416).

Follow-up for 84be0c710d.
2023-04-13 11:17:28 +02:00
Lennart Poettering
598fd4da1c dissect: disallow empty partition tables
If we don't find a single useful partition table, refusing dissection.

(Except in systemd-dissect, when we are supposed to show DDI
information, in that case allow this to run and show general DDI
information, i.e. size, UUID and name at least)
2023-04-05 20:49:48 +02:00
Lennart Poettering
dee4a6237a dissect: add new --validate command
This allows unprivileged validation of DDIs. Only superficial structure,
i.e. not mounting or so. This becomes particularly handy in the
integration tests, and to validate image policies.
2023-04-05 20:49:06 +02:00
Lennart Poettering
84be0c710d tree-wide: hook up image dissection policy logic everywhere 2023-04-05 20:45:30 +02:00
Daan De Meyer
f461a28da7 chase-symlinks: Rename chase_symlinks() to chase()
Chasing symlinks is a core function that's used in a lot of places
so it deservers a less verbose names so let's rename it to chase()
and chaseat().

We also slightly change the pattern used for the chaseat() helpers
so we get chase_and_openat() and similar.
2023-03-24 13:43:51 +01:00
Lennart Poettering
a3c3386eac dissect: make all paths we operation on absolute
Let's avoid any ambiguities around paths, and make them absolute when
accepting them, like we do in most our tools now. This makes us
independent of the current working directory and allows us to change it
without issues or pass around the paths elsewhere if need be.
2023-03-14 23:04:18 +01:00
Lennart Poettering
12c0f4ff52 dissect: mark UID/GIDs that are surprising in DDIs with colors
DDIs should not contain files owned by dynamic users or the nobody
users. Let's subtly highlight those entries in mtree output.
2023-03-14 23:03:16 +01:00
Lennart Poettering
b7df862213 dissect: use a switch statements where appropriate 2023-03-10 11:36:34 +01:00
Lennart Poettering
94abea2abf dissect: share dissected_image_decrypt_interactively() invocation between actions
Let's invoke dissected_image_decrypt_interactively() at once place only,
instead of in each function separately.

No actual changes, just some minor refactoring.
2023-03-10 11:36:34 +01:00
Lennart Poettering
6f5ef9e4c7 dissect: shorten code a bit 2023-03-09 16:41:26 +01:00
Lennart Poettering
236d1fa210 dissect: allow setting "lo_file_name" field of loopback block devices
When attaching a loopback file this allows us to set an explicit name
for it. This is useful since it allows a caller to pre-select a string
that is directly attached to the loopback file. Via udev rules we'l
later make the device accessible through this name.

Note that "lo_file_name" is supposed to carry a file name of the backing
file, but the kernel actually does not care or enforce any of that, it
just stores the filename and returns it later. This makes it so useful,
as userspace has total control of that field.

"lo_file_name" should not be confused with the sysattr
"loop/backing_file" which is actually maintained by the kernel itself,
and always shows the file to the backing inode without userspace having
direct control over the returned string. Because the sysattr is
generated by the kernel it is subject to file system namespacing and
everything, while "lo_file_name" is not, it's really just a string
passed through the kernel.
2023-03-09 16:41:23 +01:00
Lennart Poettering
07d6072e0e dissect: add commands for attaching/detaching loopback devices
Sometimes it is useful attaching DDIs without mounting them. We could
use "losetup" for that, but doing this in systemd-dissect has various
benefits:

1. we superficially validate the DDI first
2. we set the sector size depending on what we determine
3. we synchronously create the per-partition block devices
2023-03-09 16:40:55 +01:00
Lennart Poettering
a164d9d5aa dissect: implement external helper plugin interface for /bin/mount
With this change we'll install a symlink /sbin/mount.ddi →
systemd-dissect. If invoked that way we'll do the equivalent of
systemd-dissect --mount.

This makes DDIs mountable directly via the "mount" command, by
specifying the "-t ddi" pseudo file system type. Moreover you can now
mount DDIs directly via /etc/fstab, by specifying "ddi" in the file
system column (3rd column).
2023-03-06 22:52:20 +01:00