Commit Graph

1570 Commits

Author SHA1 Message Date
Simon McVittie
97cddd6e48 utils: Move more repository functionality to repo-utils
This further reduces circular dependencies: utils no longer has a
circular dependency with repo-utils or xml-utils.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-07-09 17:12:55 -03:00
Simon McVittie
06970e015f utils: Move more repository functionality into repo-utils
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-07-09 17:12:55 -03:00
Simon McVittie
c98a7c024f utils: Move OstreeRepo configuration accessors to a new translation unit
This is a step towards removing the libostree dependency from
flatpak-utils, which should be one of the lowest-level components.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-07-09 17:12:55 -03:00
Simon McVittie
14db9d48cf common: Break out the parts of flatpak-utils that deal with FlatpakDir
This breaks the circular dependency between flatpak-utils and flatpak-dir.
There is still a circular dependency between flatpak-dir and
flatpak-dir-utils, but I don't want to make flatpak-dir even larger.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-07-09 17:12:55 -03:00
Simon McVittie
3c82620bab repo-utils: New header for some implementation details of a repository
This will reduce circular dependencies involving FlatpakDir.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-07-09 17:12:55 -03:00
Hubert Figuière
92d7f9ec49 flatpak-permissions: Fix a memory leak
This occur by just running flatpak permission <SOME APP>

Signed-off-by: Hubert Figuière <hub@figuiere.net>
2024-06-27 20:55:50 -04:00
Hubert Figuière
ef575a40da Fix a memory leak in flatpak-update
Close https://github.com/flatpak/flatpak/issues/5816

Signed-off-by: Hubert Figuière <hub@figuiere.net>
2024-05-23 22:47:04 -05:00
Simon McVittie
6e81bc6f28 common: Move functions for dealing with AppStream XML to their own file
This seems like an obvious set of functionality to be grouped together
in service of the wider goal of making flatpak-utils smaller and more
manageable.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-03 13:21:29 +01:00
Simon McVittie
a01371ce02 common: Move flatpak_context_get_allowed_exports to FlatpakContext
This allows us to break a circular dependency between utils and context.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-03 13:21:29 +01:00
Alexander Larsson
bbab7ed1e6 When starting non-static command using bwrap use "--"
This ensures that the command is not taken to be a bwrap option.

Resolves: CVE-2024-32462
Resolves: GHSA-phv6-cpc2-2fgj
Signed-off-by: Alexander Larsson <alexl@redhat.com>
[smcv: Fix DISABLE_SANDBOXED_TRIGGERS code path]
[smcv: Make flatpak_run_maybe_start_dbus_proxy() more obviously correct]
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-04-17 18:10:31 +01:00
Sebastian Wick
0450c16fdb cli-transaction: Do not double free transaction ops
The transaction ops are a g_autolist(FlatpakTransactionOperation) which
means the list gets freed automatically. Calling g_list_free_full
without clearing the variable to NULL results in a double-free.

Closes: https://github.com/flatpak/flatpak/issues/5763
Fixes: 6e3cc82a ("Fix memory leaks")
Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
2024-04-04 14:49:34 -03:00
Chris Williams
ff820e3106 app: Simplify table printing
These commands no longer need to use flatpak_table_printer_print_full().
2024-03-27 14:26:28 +00:00
Chris Williams
2aebcb117a table-printer: Ellipsize by terminal width by default
This fixes the display of ellipsized columns in `flatpak remotes -d`
with wide terminals.
2024-03-27 14:26:28 +00:00
Chris Williams
cf76cb61ba ps: Add gnome to background portal backend list
This is used for the active and background columns.
2024-03-20 19:42:33 +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
2a363d7569 build: Consistently put libglnx.la last in lists of dependencies
It needs to be able to satisfy dependencies of higher-level Flatpak
static libraries.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-15 16:06:41 +00:00
Simon McVittie
2350ef1111 main: Return from flatpak_run() instead of calling exit()
This allows g_autoptr destructors to run, avoiding memory leaks being
reported by AddressSanitizer; they would be harmless, since we're about
to exit anyway, but AddressSanitizer can't tell the difference between
an O(n) problem and an O(1) harmless "leak".

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-15 11:06:30 +00:00
Simon McVittie
07ad6af5ac main: Use g_autoptr for the GOptionContext
No functional change, but it will make it easier to avoid leaking it.

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
Chris Williams
4cb1ca834c info: display extensions found in other installations
Flatpak looks for extensions in all installations, but `flatpak info -e`
would display an error when an extension isn't present in the same
installation as the ref.

Also display the installation name for each extension.
2024-02-06 18:14:42 -06:00
Patrick Griffis
8c26798991 update: Make autopruned refs automatically removed
In order to maintain a system over time update automatically removes any EOL runtimes that are unused.

This extends it to also remove any autopruned refs. In practice this means removing no longer used driver versions as the system is updated.

Closes #5261
2024-01-07 18:51:46 -06:00
Dor Askayo
c262e5ff0b run: Save flatpak-run environment
Save the environment in which flatpak-run was executed in the private
instance directory.

The environment is saved in "env -0" format.
2023-10-27 17:09:52 +01:00
Dor Askayo
c5a4ec0fa9 instance: Create private instance directory
Unlike the instance directory, whose directory structure is
considered public API and is mounted in the sandbox, the private
instance directory is meant to hold private data or metadata about
an instance for use by internal components.

The private instance directory is not meant to be shared with any
external component, and provides no guarantees about its structure
or contents.

While the public instance directory is named "<instance-id>", the
private instance directory is named "<instance-id>-private". Both the
public and private instance directories share the same parent
directory.

The private instance directory relies on the same lock file as the
public instance directory, and both are garbage-collected together.
2023-10-27 17:09:52 +01:00
Matthias Klumpp
c0c466f269 Adjust to AppStream 1.0 API changes 2023-10-24 14:17:48 +01:00
Timo Eisenmann
02bef871c0 remote-info: Fix call to flatpak_dir_load_appstream_store()
Use architecture instead of id in call to
flatpak_dir_load_appstream_store ().

Without this, remote-info does not show AppStream metadata.

Fixes: adb3b61f "decomposed: Return FlatpakDecomposed from flatpak_dir_find_remote_ref()"
2023-09-18 19:42:13 -05:00
Simon Ser
f0e626a4b6 common: add support for Wayland security context
This exposes a reliable way for Wayland compositors to get
identifying information about a client. Compositors can then
apply security policies if desirable.

See: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/68
2023-08-24 12:17:53 +02:00
Simon McVittie
7a55b7c49f app: Use AS_FORMAT_STYLE_CATALOG if available
AS_FORMAT_STYLE_COLLECTION is a deprecated alias for ..._CATALOG, and
was removed entirely in appstream git main (presumably version 0.17
or 1.0).

Resolves: https://github.com/flatpak/flatpak/issues/5472
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-07-11 13:34:41 +01:00
Simon McVittie
556984e1c1 app: Provide a stub implementation of AS_CHECK_VERSION if needed
Our only code that is conditional on the libappstream version wants
version 0.14.0, which conveniently is exactly the version that
introduced AS_CHECK_VERSION.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-07-11 13:34:41 +01: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
bf8e91cedc common: Stop including utils-http in utils
utils-http is conceptually larger than utils.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-07-03 20:07:57 +02:00
Philip Withnall
9a2d0413f5 app: Port transaction subclasses to use add_rebase_and_uninstall()
This fixes the possible situation where an eol-rebase app can be
uninstalled and the new version not correctly installed (due to, for
example, the install op failing due to a lack of disk space).

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

Fixes: #3991
2023-03-30 14:54:18 +02:00
Simon McVittie
0e3e646839 run: Make it clearer that rest_argv_start is not used uninitialized
rest_argv_start is initialized whenever rest_argc != 0, so the previous
code was in fact safe; but this wasn't obvious to either a human reader
or the compiler, and some gcc versions warn here.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-03-20 12:19:15 +00:00
Simon McVittie
409e34187d cli-transaction: Escape any special characters in the EOL reason
CVE-2023-28101, GHSA-h43h-fwqx-mpp8

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-03-16 09:54:14 +00:00
Ryan Gonzalez
6cac99dafe Ensure special characters in permissions and metadata are escaped
This prevents someone from placing special characters in order to
manipulate the appearance of the permissions list.

CVE-2023-28101, GHSA-h43h-fwqx-mpp8

Signed-off-by: Ryan Gonzalez <ryan.gonzalez@collabora.com>
2023-03-16 09:54:14 +00:00
Simon McVittie
628750d2de list: Show a warning if we can't load the current version
Conceptually similar to the previous commit, except it didn't crash
before, just didn't display anything.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-02-08 21:14:17 +00:00
Simon McVittie
5e2e771ece list: Handle error in flatpak_dir_load_deployed()
flatpak_dir_load_deployed() can fail and return NULL. If that happens,
there is a semi-installed but broken app, and we should show a warning
rather than crashing.

Resolves: https://github.com/flatpak/flatpak/issues/5293
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-02-08 21:14:17 +00:00
Patrick Griffis
bb730ef8b8 Revert "Add support for files generated by appstreamcli compose (#5277)"
This reverts commit 88f7ecd000.
2023-02-04 12:30:15 -06:00
Luna
88f7ecd000 Add support for files generated by appstreamcli compose (#5277)
Co-authored-by: Bartłomiej Piotrowski <b@bpiotrowski.pl>
Co-authored-by: Jamie Murphy <hello@itsjamie.dev>
2023-02-04 10:40:07 -06:00
Phaedrus Leeds
523cedc275 trivial: Trim some long lines, etc. 2023-01-02 20:45:19 -06:00
Phaedrus Leeds
8ca1604a94 repair: Fix off-by-one error in fancy output
Fixes https://github.com/flatpak/flatpak/issues/5204
2023-01-02 20:45:19 -06: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
522a933bc9 app: Use g_info() for messages that will be shown by flatpak -v
This brings us one step closer to being able to stop using the flatpak2
log domain for messages that are exclusive to `flatpak -v -v`.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-15 16:45:35 +00:00
Simon McVittie
ac4e322629 main: Treat g_info() as equivalent to g_debug()
This makes us consistent with the default behaviour of GLib, and
its behaviour with G_MESSAGES_DEBUG=all. g_debug() and g_info() are
the two lowest priority levels, and GLib normally silences them by
default.

At the moment, Flatpak uses G_LOG_LEVEL_DEBUG in the flatpak2 domain
as its lowest-priority log level (only shown with flatpak -v -v), and
G_LOG_LEVEL_DEBUG in the flatpak domain as its second-lowest
(shown with flatpak -v or higher). I want to move towards using
G_LOG_LEVEL_INFO for flatpak -v messages, and G_LOG_LEVEL_DEBUG for
flapak -v -v, so that we don't need a second log domain: this is a
policy I've used successfully in Flatpak-derived Steam Runtime code.

This change does not fully implement that policy, but gives us a
migration path towards it, by allowing us to start using g_info() for
flatpak -v messages.

Helps: https://github.com/flatpak/flatpak/issues/5001
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-14 20:02:35 +00:00
Simon McVittie
1eed25617c Replace calls to g_memdup() with g_memdup2()
g_memdup() is subject to an integer overflow on 64-bit machines if the
object being copied is larger than UINT_MAX bytes. I suspect none of
these objects can actually be that large in practice, but it's easier
to replace all the calls than it is to assess whether we need to
replace them.

A backport in libglnx is used on systems where GLib is older than 2.68.x.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-12 19:15:52 +00:00
Jan Alexander Steffens (heftig)
d83b262ded app/meson.build: Add missing dep
Since we include the base private headers, we need the common base
sources to be generated.
2022-11-03 15:27:58 -05: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
Robert Ancell
b204ed2466 app: Fix warning when listing a document with no permissions.
(flatpak documents:2965757): GLib-CRITICAL **: 11:27:35.128: g_variant_iter_next_value: must not be called again after NULL has already been returned.

This is due to the applications iterator being checked twice even though it is empty.
2022-09-06 13:18:09 +02: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
Phaedrus Leeds
ff8490a91e app: Add -u alias for --user
Save folks a few keystrokes. There is a command which already has a '-u'
option, document-export, but it doesn't support --user so there should
be no conflict. However '-s' is used by the info command among others,
so we can't use that for --system.
2022-08-16 10:50:29 +02:00
Simon McVittie
a03111a3d1 enter: Don't overwrite the DISPLAY
Now that we're using the same display number in the sandbox as on the
host, we can forget about overwriting it with :99.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-08-16 10:45:08 +02:00