Commit Graph

212 Commits

Author SHA1 Message Date
Simon McVittie
2fc71b1f80 Fix missing declaration for g_fdwalk_set_cloexec() with GLib 2.80.x
With older GLib, it's provided by libglnx, but with newer GLib, we need
to include the correct header.

Fixes: 7b1cd206 "Replace flatpak_close_fds_workaround() with g_fdwalk_set_cloexec()"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-03-21 20:20:15 +00:00
Simon McVittie
8e63eda867 Remove Autotools build system
As discussed in #5695, I think we're reaching a point where removing
Autotools is preferable to fixing it.

1.14.x continues to use Autotools, so platforms whose Meson version is
too old can stay on that branch until it becomes unsupported. We have
a very conservative Meson dependency (Ubuntu 20.04).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-16 19:30:32 +00:00
Simon McVittie
7b1cd20696 Replace flatpak_close_fds_workaround() with g_fdwalk_set_cloexec()
flatpak_close_fds_workaround() wasn't technically async-signal-safe,
because the requirement for sysconf() to be async-signal-safe was
removed in POSIX.1-2008.

It could also leave high fds open in some cases: in practice
sysconf(_SC_OPEN_MAX) returns the soft resource limit, but if our
resource limit has been reduced by an ancestor process, we could
conceivably still have fds open and inherited above that number.

We can fix this by using g_fdwalk_set_cloexec() with GLib >= 2.79.2,
or the backport in libglnx with older GLib. This uses close_range()
if possible, falling back to rummaging in /proc with async-signal-safe
syscalls.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-15 16:06:41 +00:00
Simon McVittie
a607246519 system-helper: Don't leak the GCancellable for each OngoingPull
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-15 11:06:30 +00:00
Hubert Figuière
6e3cc82af3 Fix memory leaks
Build with address sanitizer and run the tests

Signed-off-by: Hubert Figuière <hub@figuiere.net>
2024-02-13 08:20:57 -06:00
Simon McVittie
ae2579637a app: Move terminal-related utility functions from common into app
These functions are to do with being an interactive, terminal-oriented
CLI/TUI, so it would be inappropriate for library code in libflatpak
to call them, and it would also be inappropriate for daemons like the
session and system helpers to call them.

In fact all calls to these were already isolated to app/, so we can
easily move the terminal-related utilities themselves into app/.

As well as shrinking libflatpak, this makes it obvious that the system
helper does not actually need to call flatpak_disable_fancy_output():
it does not link any code that would be affected by that API call.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-07-03 20:19:00 +02:00
Simon McVittie
c2c034733e common: Make flatpak_debug2() use the same domain as g_debug()
Now that we are logging `flatpak -v` messages with log level INFO,
and printing INFO messages in the same way as DEBUG, we can reserve
log level DEBUG for `flatpak -v -v` messages. This means we no longer
need a weird secondary debug domain.

There is a very small behaviour change here: G_MESSAGES_DEBUG=flatpak
is now similar to `flatpak -v -v` (previously `flatpak -v`), and
G_MESSAGES_DEBUG=flatpak2 no longer has any effect. This seems more in
line with what would be expected from a GLib-based application.

In flatpak(1) and the system helper, this does not change behaviour
other than that: the same messages are logged by `-v` and by `-v -v`
as before.

In daemons that do not implement `-v -v` (the OCI authenticator, portal
and session helper), it continues to be necessary to use
G_MESSAGES_DEBUG to see flatpak_debug2() messages.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-15 16:45:35 +00:00
Simon McVittie
86c9d7d4c7 daemons, etc.: Use g_info() for messages that are enabled by -v
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-15 16:45:35 +00:00
Simon McVittie
ea584acf20 daemons: Treat g_info() as equivalent to g_debug()
Same as the previous commit, but for anything that runs in the
background.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-14 20:02:35 +00:00
Simon McVittie
9eb824f863 Add a Meson build system
Resolves: https://github.com/flatpak/flatpak/issues/2241
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-24 16:12:14 +01:00
Phaedrus Leeds
600e18567c Add a vim modeline and .editorconfig
To make indentation work with less effort. The modeline was copied from
libostree with minor modification and the .editorconfig from GLib.

The advantage of having both a modeline and an editorconfig is we can
work out of the box on more editor setups, and the modeline allows us to
specify the style with a lot more fine grained control.
2022-08-22 19:48:10 -07:00
Philip Withnall
9c059def69 app: Port to libappstream
libappstream-glib is mostly unmaintained, and libappstream is more
actively developed (and up to date with the AppStream specification).

Port from libappstream-glib to libappstream. Handily, a lot of the APIs
are exactly the same. The main changes are:
 * `AsApp` → `AsComponent`
 * `AsStore` → `AsMetadata`

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

(Mostly done by Philip, then Phaedrus finished this)
2022-02-17 08:29:20 -06:00
Phaedrus Leeds
6f5bb3597e Change how automatic pinning is implemented
This commit re-works how we automatically "pin" runtimes that are
explicitly installed, to prevent them from being removed automatically.
In this implementation we do the update to the config as part of the
deploy, which has the following advantages:
(1) It ensures that there's never a confusing polkit prompt about
configuring the software installation when the user asked for a runtime
to be installed (https://github.com/flatpak/flatpak/issues/4200)
(2) It means we don't have to rely on the code on the error path of
flatpak_transaction_real_run() to un-pin the runtime in case something
went wrong with the installation, since we pin it almost atomically with
the deploy.

Fixes #4200
2021-11-15 11:10:27 -08:00
Simon McVittie
f508cf1767 system-helper: Move D-Bus names and paths to a header file
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-15 18:05:16 +02:00
Philip Withnall
0a07d2122b system-helper: Set interactivity on the FlatpakDir from D-Bus call flags
The system helper was already correctly using the `NO_INTERACTION` flag
in the D-Bus call flags to determine whether polkit calls from
`flatpak_authorize_method_handler()` should allow interactivity.

However, the system helper was not setting the no-interaction property
on the `FlatpakDir` used in the subsequent operation. When parental
controls are enabled, this sometimes results in polkit allowing
interaction when prompting for the `override-parental-controls` action,
even if the D-Bus call which activated the system helper specified the
`NO_INTERACTION` flag.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-04-06 10:18:45 +02:00
Alexander Larsson
49e8bfcea5 system-helper: Fix deploys of local remotes
For updates in remotes with a local (file:) uri we just do a deploy
with a LOCAL_PULL flag set and an empty arg_repo_path. However, our
arg_repo_path checking at some point seemed to stop properly handling
the case where it is empty. I got it to report "No such file" wich
broke the tests.
2021-03-19 10:59:04 +01:00
Alexander Larsson
b8d8e5bf04 Fix nonliteral string warning in flatpak_invocation_return_error()
We're only forwarding a format string, which we can tell gcc by
adding a G_GNUC_PRINTF marker.
2021-01-14 12:43:46 +01:00
Alexander Larsson
dad9a9c20d Pass AM_CFLAGS to system-helper build (for warnings) 2021-01-14 12:43:46 +01:00
Alexander Larsson
50ee8293cc Fix shadowed variable "error" 2021-01-14 12:43:46 +01:00
Simon McVittie
86dd000dd1 system-helper: Return G_DBUS_METHOD_INVOCATION_HANDLED where appropriate
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-12-09 08:34:19 +01:00
Alexander Larsson
5496c4e4ef appstream: Pull the right branch if the remote has a subset configured 2020-11-13 10:32:19 +01:00
Alexander Larsson
7ab62ac3fb decomposed: Convert some more FlatpakDir apis to FlatpakDecomposed 2020-11-10 14:32:13 +01:00
Alexander Larsson
674cc1a60a decomposed: Convert more FlatpakDir APIs to use FlatpakDecomposed 2020-11-10 14:32:13 +01:00
Alexander Larsson
c5b2c60609 decompose: Convert more FlatpakDir functions to use FlatpakDecomposed 2020-11-10 14:32:13 +01:00
Alexander Larsson
a3a2dcb2c5 decomposed: Remove _decomposed prefix on functions
We now converted most of these and removed the non-prefixed functions,
so rename them back.
2020-11-10 14:32:13 +01:00
Alexander Larsson
97767f1a69 decomposed: Pass decomposed to flatpak_dir_deploy_install/update 2020-11-10 14:32:13 +01:00
Alexander Larsson
d61721022d Change the last user of flatpak_dir_list_all_remote_refs to use _decomposed
This will let us remove the non-decomposed one.
2020-11-03 12:57:37 +01:00
Phaedrus Leeds
2486961014 system-helper: Check for errors getting installation
I don't think this error code path will really be hit in practice,
except perhaps for a maliciously crafted D-Bus message trying to get the
system helper to crash.
2020-11-02 09:23:49 +01:00
Phaedrus Leeds
c9cb2752ee system-helper: Make uninstall auth message friendlier
Currently when a polkit prompt is created for an app uninstallation, the
message is something like "Authentication is required to uninstall
app/us.zoom.Zoom/x86_64/stable" which is not very friendly for
non-technical users. Change it to "Authentication is required to
uninstall Zoom".

For many of the other polkit actions used by the system-helper, we just
say "software" rather than specifying the app/runtime, since we use the
authorization from one action for others via imply annotations, so the
user is really authorizing several things at once in some cases. In the
case of app-uninstall actions, the only implied action is
runtime-uninstall, and runtimes aren't something users should generally
have to worry about anyway, so it seems alright to specify the app. I
presume that was why commit 21f845c1a didn't remove the ref from the
app-uninstall action message.
2020-11-02 09:23:49 +01:00
Alexander Larsson
57954e2efc summary: Enable use of indexed summaries in the client
We first try to download the index, then fall back to the old format.
2020-10-29 15:30:35 +01:00
Matthew Leeds
d2d5397cc1 Add pin command to keep unused runtimes
As discussed here [1], we want a way to mark runtimes to be kept even
when they are unused by any apps and we are removing such runtimes.
Currently this is a command that can be run manually; a subsequent
commit will pin runtimes automatically if they are installed
independently of any app.

A unit test is included.

[1] https://github.com/flatpak/flatpak/issues/2639#issuecomment-662311756
2020-08-31 16:29:03 +02:00
Matthew Leeds
73644b00c9 system-helper: Support setting 'masked' config key
This fixes the following error when the "flatpak mask" command is used
with the system-helper: "error: Unsupported key: masked"
2020-08-10 15:25:55 +02:00
Matthew Leeds
9caf664fab Add systemd units to sideload from hotplugged USBs
Currently with the sideload implementation of offline updates you have
to manually create a symlink to your USB drive to sideload from it,
which is a regression compared to the previous implementation which
scanned all mounted filesystems in OstreeRepoFinderMount in libostree.
So this commit adds a few systemd units and a bash script so that any
time a USB drive is plugged in and automatically mounted by udisks, a
symlink to it is created in /run/flatpak/sideload-repos. When the drive
is unplugged the symlink is removed.

However this solution still has a lot of moving parts, so we may want to
instead have libflatpak use GVolumeMonitor and find the mounted
filesystems itself; see https://github.com/flatpak/flatpak/issues/3705

Fixes https://github.com/flatpak/flatpak/issues/3490
2020-06-23 09:37:10 +02:00
Alexander Larsson
b042abc71c oci: Handle io.github.containers.DeltaUrl in index
If the magical io.github.containers.DeltaUrl label is set in the
index, then try to download this to use as the delta manifest for the
image. This allows servers to store deltas outside the registry
itself. The label is propagated to the xa.delta-url metadata in the
generated "fake summary" for the remote, and read back on pull.

Note that the delta manifest layers descriptor will need to have a
"urls" key where it references the blobs if the blobs are also not
stored on the registry.

If the specified manifest doesn't exist or doesn't apply to the target
image we fall back to resolving via the _deltaindex tag.
2020-06-05 09:35:30 +02:00
Alexander Larsson
47daa077c2 OCI: Support (and use) alternative urls specified in OCI descriptors 2020-06-05 09:35:30 +02:00
Alexander Larsson
0fce4c6d7f oci: Pass FlatpakPullFlags to pull_from_oci()
We want to handle FLATPAK_PULL_FLAGS_NO_STATIC_DELTAS
2020-06-05 09:35:30 +02:00
Valentin David
4df019063b Add sysusers.d configuration file
This will make systemd create the system-helper user if it is missing.
2020-04-23 09:58:34 +02:00
Alexander Larsson
b28271bb5e Merge pull request #3498 from alexlarsson/use-symlinks-for-sideload-config
Use symlinks instead of xa.sideload-repos config option
2020-03-30 16:03:54 +02:00
Alexander Larsson
4ef12c5bc9 FlatpakProgress: No need to allocate FlatpakMainContext
We store it on the stack instead and free with
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC.
2020-03-27 14:44:00 +01:00
Abderrahim Kitouni
192d31d315 Add a FlatpakProgress object
To avoid the complexities of passing (and chaining) OstreeAsyncProgress
objects around, we only create one just before calling to ostree.
The rest of flatpak only ever uses the new FlatpakProgress object.

Co-authored by: Philip Chimento <philip@endlessm.com>
2020-03-26 21:09:19 +01:00
Alexander Larsson
76be5db46d Revert "config: Support setting sideload-repos option"
This reverts commit 1d1819840e.
2020-03-26 10:10:45 +01:00
Alexander Larsson
9208913664 Migrate config: Always enable gpg-verify-summary if collection id is set
This used to not be set for collection-id remotes as we used the
ostree-metadata branch for resolving. However, we now use the summary
always when doing a remote install (and not ostree-metadata for local
sideloads), so we still want to verify summary.

The signature on the summary is a nice security feature, but it is also
a very efficient small file to download to verify that no new summary
needs to be downloaded in the no-op update case.
2020-03-23 17:58:04 +01:00
Alexander Larsson
1d1819840e config: Support setting sideload-repos option 2020-03-23 17:58:04 +01:00
Alexander Larsson
124b0be92e Drop more collection_id use
Most code that looks for a regular collection id set on the remote is
removed, as these should never happen in flatpak repo setups now.

Some is replaces with looking at xa.sideload-collection-id:
 * The libflatpak FlatpakRef::collection-id property now comes comes from the sideload id
 * Various CLI commands showing or changing the collection-id for a remote now uses the sideload id
 * Collection id deploy in update now sets the sideload-collection-id instead
 * Setting the collection id for a remote in libflatpak now sets the sideload id

Additionally we now delete the code that allows unsigned summaries
when there is a collection id (because there is none).

create-usb now uses the sideload id as as collection id source when exporting.

The direct repo operations (export, bundle, commit-from) still support
collection ids, because on the server we do want to set it so that we
can sideload.
2020-03-23 17:58:04 +01:00
Alexander Larsson
336a127f55 Support sideloaded repos
This adds a xa.sideload-collection-id option to the remote
configuration and a global xa.sideload-repos option (which is a list
of paths to local repos).

When resolving or listing refs, if we fail to download the real remote
summary (i.e. we're offline) then we instead look into the configured
sideloaded repos for refs that match ref and the sideloaded collection
id for the remote.

For the transaction to resolve the ref we need more metadata. In the
regular summary case we use the metadata from the summary, but that
is not available in the (partial) summary in the sideload repo, so
there we load the actual commit object and use the data from there.
(The ostree-metadata branch is not used/needed.)

This actually also fixes a longstanding issue when you "flatpak update
--checksum=XYZ" because we now handle this correctly by downloading
the commit object from the remote. Before we used the metadata in the
summary which is not right for non-HEAD commits.

To handle the sideloading we record the path to the sideload repo
when sideloading and pass the url to the repo as the remote name
when pulling, which will do a direct local pull.

We avoid using sideloaded refs when offline if the timestamp in the
commits is older than what is already installed locally.
2020-03-23 17:58:04 +01:00
Alexander Larsson
116a8b8487 transaction: Ensure the metadata in the pulled commit matches what we resolved
We're using the metadata from the summary, ostree-metadata or available
commit when making security sensitive decisions, so lets verify this
matches what we get in the actual commit we pulled.

We already did check that this then actually also matches what gets deployed,
so the new check shares code with that.

Note, we don't do this for OCI installs, because it seems the current
fedora flatpaks don't have this set, and we don't want to break
existing remotes.
2020-03-23 17:58:04 +01:00
Alexander Larsson
7c4fd8891e Convert deploy data to use variant schemas 2020-02-17 16:10:50 +01:00
Alexander Larsson
087ba2d23f system-helper: Support -vv and --ostree-verbose 2020-02-13 14:47:00 +01:00
Alexander Larsson
30636a508d system-helper: Change debug prefix from F to FH
This makes it easier to see what message comes from where.
2020-02-13 14:47:00 +01:00
Alexander Larsson
c322cbdbb6 Add and use OstreeAsyncProgressFinish helper
This is a g_autoptr version of OstreeAsyncProgress that also
calls ostree_async_progress_finish() before being freed.

This should be used in all "leaf" functions that creates an asyncprogress
to avoid leaking any idle change idle sources. Using a auto* means
some code can be cleaned up to avoid goto out style handling for this.

Also, this adds a missing finish() in
_flatpak_dir_fetch_remote_state_metadata_branch().
2019-12-17 14:55:13 +01:00