Commit Graph

663 Commits

Author SHA1 Message Date
Yu Watanabe
298fc56641 import: fix NULL pointer dereference
Follow-up for a9f6ba0496.
Fixes CID#1645106.
2026-02-20 16:12:36 +09:00
Yu Watanabe
5d01b27ffc import: fix typo
Follow-up for a9f6ba0496.
2026-02-20 01:13:02 +09:00
Lennart Poettering
68ed4f3c66 mountfsd,nsresource: allow recycling mountfsd/nsresourced client connections
So far we opened a new Varlink connection for every mountfsd/nsresourced
method call. Given each tool only does a very small number of calls
(usually 1…5) on them and the connections are cheap this is not too
wasteful. Nonetheless, let's do something about it, and allow reusing
the connection for multiple calls.

This not only makes things a bit more efficient, but has one more
important benefit: Varlink connections pin the security context of the
client when connecting. This means that varlink method calls done with a
connection established while some code was privileged will still operate
as privieged once privs are dropped, until the connection is closed.
This pinning effect is really nice, as it gives us behaviour in a
"capability system" like scheme. Later code is going to use that to
continue doing certain priv userns ops even after unsharing userns and
becoming fully unpriv.
2026-02-19 15:08:19 +01:00
Lennart Poettering
fbaf05bfeb importctl: add 'pull-oci' client API 2026-02-19 15:05:15 +01:00
Lennart Poettering
9628a5ced4 importd: add bus/varlink api for downloading OCIs 2026-02-19 15:05:15 +01:00
Lennart Poettering
116394f7ce tree-wide: move logging from varlink clients in nsresource.c/dissect-image.c into callers
These calls are "library-like", hence better should only debug log on
their own, not more.
2026-02-19 15:05:15 +01:00
Lennart Poettering
a9f6ba0496 pull: add OCI support 2026-02-19 15:05:15 +01:00
Lennart Poettering
d66e3cc79a pull-job: make sure pull_job_restart() can be used to fetch the same resource again, just with new headers
Let's flush out all response state from the job, but let's keep the
request data previously configured, in particular the headers set. This
is useful to re-request a resource, just with a slightly modified or
identical URL.
2026-02-19 15:05:15 +01:00
Lennart Poettering
93915ec17a pull-job: add helpers to detect requests for authentication, and accept bearer tokens 2026-02-19 15:05:14 +01:00
Lennart Poettering
1f593d2b5e pull-job: add 'description' field to PullJob
This is shown in the output in place of the URL if non-NULL. This is
useful for OCI's hash-based URLs, which alone are very opaque to read.
2026-02-19 15:05:14 +01:00
Lennart Poettering
98b714e0cb pull-job: optionally free userdata when we destroy a PullJob 2026-02-19 15:05:14 +01:00
Lennart Poettering
4a886d9ab4 pull-job: add interface for controlling Accept: header sent to http server 2026-02-19 15:05:14 +01:00
Lennart Poettering
41b0c68760 pull-job: keep track of content type reported by server 2026-02-19 15:05:14 +01:00
Mike Yuan
09388a6b9e tree-wide: drop redundant check for SD_VARLINK_METHOD_MORE flag
If the IDL declares the method requires 'more' yet the call doesn't
have it set, varlink_idl_validate_method_call() should have rejected
it and the callback shouldn't be reached.
2026-02-16 09:44:54 +01:00
Yu Watanabe
da86da21e9 Fixes for option parsing (#40641)
Preparatory work split out of #40624.
2026-02-14 04:58:50 +09:00
DaanDeMeyer
ba37ed9634 dissect: Introduce --copy-ownership= to configure chown behavior
Currently, if we're copying a file, we won't copy the owner UID/GID
from the source. If we're copying a directory, we will copy the owner
UID/GID from the source. Let's give users a bit more control over this
behavior by introducing --copy-ownership= which will default to the
current behavior but allows users to explicitly enable/disable copying
of ownership.
2026-02-12 09:45:13 +01:00
Daan De Meyer
4f5d44ef53 tree-wide: Migrate to varlink_set_sentinel() 2026-02-11 14:25:36 +01:00
Zbigniew Jędrzejewski-Szmek
84f6967558 importctl: fix confusion in --help
See parent commit for explanation.
2026-02-11 11:46:38 +01:00
Antonio Alvarez Feijoo
2f76b10b94 import-generator: fix sysext/confext ordering in initrd
In the initrd, order the generated `systemd-import@.service` units before the
initrd-specific sysext/confext units.
2026-02-03 08:18:41 +09:00
Daan De Meyer
ec1ab07605 dissect-image: Generalize foreign tree logic from import 2026-01-21 12:03:07 +01:00
Yu Watanabe
776c3d7f90 import: update comment: implementor -> implementer
Both implementor and implementer are correct, but we use implementer at
other places.
2026-01-06 08:43:05 +09:00
Daan De Meyer
ce2c72daa1 tree-wide: Migrate to pidref_safe_fork() (#40170) 2026-01-02 21:12:31 +01:00
Daan De Meyer
52ecf376fa tree-wide: Migrate to pidref_safe_fork()
Let's migrate all remaining callers of safe_fork()
to pidref_safe_fork() and get rid of safe_fork().
2026-01-02 20:08:41 +01:00
Daan De Meyer
e6703a9aa4 process-util: Use ret as output parameter name
There's only one output parameter for all these
functions, so let's just name it ret following the
coding style.
2026-01-02 19:44:18 +01:00
DaanDeMeyer
8b4278d12e pull-tar: Insist on foreign UID when copying
If we're doing foreign UID range copying, we're going to be joining
a private user namespace before doing the copy. copy_tree() insists
on keeping all UIDs/GIDs the same when copying. Hence, all the
UIDs/GIDs of the files we're copying should be in the private UID
range, which means they need to be owned by the foreign UID range
and we always need to call mountfsd_mount_directory_fd(). So there's
no point in having a fallback path if the source directory is not
foreign UID range owned, we'd simply fail to copy it later. Hence,
insist on the source directory being foreign UID range owned.
2026-01-02 15:21:53 +01:00
Daan De Meyer
aec52c1e6e string-table: Introduce DECLARE_STRING_TABLE_LOOKUP() and friends
Let's introduce these for the following two reasons:
- Using them makes sure the parameter names match between declaration
  and definition (if both use the corresponding macros).
- They make sure developers can't forget the _const_ and _pure_
  attributes for the declarations.

This commit also includes some include sorting fixes
2026-01-02 04:05:45 +09:00
Lennart Poettering
b7d1d17b9c dissect-image: teach mountfsd_make_directory() the new access mode parameter 2025-12-21 07:04:42 +01:00
Daan De Meyer
29d1df4b03 tree-wide: Remove unnecessary SIGCHLD blocking
Now that sd-event doesn't insist on blocking
SIGCHLD anymore when watching for process exit,
let's stop blocking SIGCHLD tree-wide where not
required anymore.
2025-12-20 15:50:47 +01:00
Daan De Meyer
fbd276cb86 tree-wide: Use pidref_wait_for_terminate_and_check()
Let's use the pidref variants for waiting and
checking a process everywhere and get rid of the
non pidref variants.
2025-12-20 15:50:47 +01:00
Zbigniew Jędrzejewski-Szmek
9e104bd3aa meson: put src/import source lists directly in templates
The indirection through variables doesn't seem that useful here:
OTOH, the lists are short, and OTOH, there is a bunch of different
programs with similar names. Overall, it's all easier to follow if
the lists are inline.
2025-12-19 13:12:35 +01:00
Yu Watanabe
93378148d4 tree-wide: normalize comment style 2025-12-15 08:50:13 +09:00
Daan De Meyer
1075316a4b machine: Fix hardcoded /var/lib/machines paths 2025-12-08 14:56:39 +01:00
q66
c39238bdc8 import: include unistd.h for pipe2
This is needed for e.g. pipe2 and unlinkat and a build failure
is reproducible when libarchive support is disabled.
2025-12-08 08:33:56 +09:00
Daan De Meyer
6a9f0641cd tree-wide: Fix declaration/definition parameter name mismatches 2025-11-26 19:02:31 +09:00
Yu Watanabe
caf7cb2737 SD_JSON_BUILD_PAIR() conversions with coccinelle script (#39858) 2025-11-26 16:35:35 +09:00
Daan De Meyer
9ad1d56f82 import: Make naming consistent
Always abbreviate import/pull/export structs with their first letter
instead of only doing it in some places and using the wrong letter in
other places.
2025-11-26 16:23:13 +09:00
Daan De Meyer
9a6a8f35eb tree-wide: Small fixes for various clang-tidy warnings 2025-11-26 16:22:00 +09:00
Jelle van der Waa
c12966c14f treewide: prefer using SD_JSON_BUILD_PAIR_* over SD_JSON_BUILD_PAIR()
Include a coccinelle script that patches this automatically.
2025-11-24 21:05:10 +01:00
Daan De Meyer
87fbd33372 clang-tidy: Fix all remaining misc-include-cleaner violations
- Remove unused includes
- Add common false positive headers to misc-include-cleaner.IgnoreHeaders
- Add IWYU pragma keep for uncommon false positive headers
2025-11-22 10:19:41 +01:00
Zbigniew Jędrzejewski-Szmek
5220bb8c3f meson: automatically add 'extract' to 'sources'
In all cases, everything that we list in 'extract', we also list in
'sources'. We can simplify things by automatically appending the first
list to the second.

In the listings, move 'extract' key right below 'sources', since now
they are both "sources", just with slightly different meanings.
2025-11-20 10:03:48 +09:00
Lennart Poettering
f5452477d4 tree-wide: fix lseek() parameter order
The offset must be specified first, 'whence' second. Fix that.

Except for one case this fix doesn't actually fix any real bug, since
SEEK_SET is defined as 0 anyway, hence the swapped arguments have no
effect.

The one exception is the MTD smartmedia code, which I guess indicates
that noone has been using that hw anymore in a long time?
2025-11-13 14:19:29 +01:00
Yu Watanabe
242088e98b meson: drop redundant HAVE_ZLIB check
ENABLE_IMPORTD requires HAVE_ZLIB, and it is already checked at the very
beginning of the file.
2025-11-09 05:42:21 +09:00
Lennart Poettering
729e1f24c5 pull-job: port .payload field to struct iovec
struct iovec is really how we should encode any form of arbitrary blob
data
2025-11-08 09:28:50 +01:00
Lennart Poettering
33f49312f8 pull-job: use http_status_etag_exists() at a second place 2025-11-08 09:28:50 +01:00
Lennart Poettering
f56531c25c pull: there's no need to keep the downloaded image in memory, except for the sha256sums/gpg file
This seems to be a mistake, in place since the first commit: we only
want the downloaded data in memory if this is a sha256sums or gpg file,
which we need to prorcess ourselves.
2025-11-08 09:28:50 +01:00
Lennart Poettering
7aa847933f pull: use ASSERT_PTR() to shorten code a tiny bit 2025-11-08 09:28:50 +01:00
Lennart Poettering
5bba33f5e9 pull: now that PullJob can verify expected digests, let's rely on it for tar/raw pulling
Instead of authenticating the downloaded image explicity in the tar and
in the raw downloader, we can now rely on the checksum checking in the
generic PullJob code. Hence do so: drop tep the checksum field from
TarPull and RawPull, and just initialized the ->expected_checksum in the
relevant PullJob instead.
2025-11-08 09:28:50 +01:00
Lennart Poettering
6f16ab4893 pull-job: optionally store an expected checksum in PullJob object 2025-11-08 09:28:50 +01:00
Lennart Poettering
e825635af6 import: rework pull logic to store download digests in binary form rather than string
We generally want to store data in parsed form, not formatted form,
hence let's follow our own rules on this, and store the message digest
as "struct iovec" rather than as string. This is generally more
efficient and safer, simply because of case issues.
2025-11-08 09:28:50 +01:00
Lennart Poettering
cb1caab98e pull-job: optionally take expected content length and compare it with what we are downloading 2025-11-08 09:27:46 +01:00