Commit Graph

6422 Commits

Author SHA1 Message Date
Simon McVittie
3393366877 common: Move flatpak_run_allocate_id() to flatpak-instance
This localizes knowledge of the internal structure of
$XDG_RUNTIME_DIR/.flatpak into the flatpak-instance module.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-06 11:53:23 +02:00
Jan Tojnar
495449daf6 portal: fix flatpak-spawn --clear-env on NixOS
Running Flatpak Chromium on NixOS fails with the following error:

> Error calling Spawn(): org.freedesktop.DBus.Error.FileNotFound: Failed to start command: Failed to execute child process “flatpak” (No such file or directory)

Presumably, Chromium calls portal’s `Spawn` method with `FLATPAK_SPAWN_FLAGS_CLEAR_ENV` flag, which also removes `PATH`.
Since NixOS does not install programs to global `/usr/bin` and relies solely on `PATH`, this is probably what prevents `flatpak` command itself from being found.

There is a relevant TODO note in the code about `LD_LIBRARY_PATH` but at least for `PATH`, we can solve the issue by hardcoding the path to the binary.
2021-04-06 11:06:14 +02:00
Simon McVittie
0b12aff826 build: Move submodules into subprojects directory
This is a step towards being able to build Flatpak using Meson, which
is becoming widely available even in LTS distributions. Meson's
built-in support for subprojects expects to find them in ./subprojects
at top level.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-06 10:21:29 +02:00
malbx
0a9253f7d9 history: Handle transaction log entry with empty REF field
This checks that the value of the REF field is not an empty string
before calling `flatpak_decomposed_new_from_ref`.  Attempting to
decompose an empty string leads to a validation error and prevents
any history from being printed.

Fixes https://github.com/flatpak/flatpak/issues/4121
2021-04-06 10:19:26 +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
Kalev Lember
b90d638601 OCI: Switch to pax format for tar archives
For reasons unknown, libarchive appears to generate broken gnutar format
tar archives when the archive contains files that are larger than 2 GB.
This commit switches to the pax format to work this around.

This should be a better default as it also removes 256 char filename
length limitation and matches what other libraries are doing, e.g.
Python 3.8 switched to the pax format by default as well.

See https://pagure.io/fedora-infrastructure/issue/9840
2021-04-06 10:08:27 +02:00
Yuri Chornoivan
8efd573ff0 Update Ukrainian translation 2021-04-06 10:06:38 +02:00
Phaedrus Leeds
f712758f5e Merge pull request #4193 from flatpak/create-usb-extra-data
create-usb: Skip copying extra-data flatpaks
2021-03-31 11:01:30 -07:00
Phaedrus Leeds
f874b25840 Merge pull request #4178 from pwithnall/interactive-parental-controls
flatpak-dir: Make parental controls polkit query interactive iff dir is
2021-03-23 17:00:49 -07:00
Phaedrus Leeds
0bf8cf9a08 create-usb: Skip copying extra-data flatpaks
Currently the create-usb command copies extra-data flatpaks such as the
org.freedesktop.Platform.openh264 runtime extension along with normal
non-extra-data content. This is an issue because on the computer
installing from the USB it will attempt to get the extra-data content
from the URI specified in the commit metadata, which will fail if the
URI is a resource on the Internet and the computer is offline.

Instead, have create-usb omit such refs. If it was specified explicitly
this is treated as a hard error and if it's a dependency it's treated as
a warning, so that e.g. org.freedesktop.Platform can still be copied to
a USB and installed/updated offline. On the receiving end the absence of
org.freedesktop.Platform.openh264 will correctly not be treated as fatal
to the installation of org.freedesktop.Platform.

This issue was affecting offline updates of Endless OS, since such OS
updates include flatpaks along with the OS content.

For the (legally questionable) topic of properly supporting extra-data
distribution offline, see https://github.com/flatpak/flatpak/issues/969
2021-03-23 15:16:17 -07:00
Alexander Larsson
c4a9025145 flatpak-progress: Empty the progress main context at the end
This is similar to the previous commmit, but for the main context
we add when forwarding the process callbacks.
2021-03-19 10:59:04 +01:00
Alexander Larsson
adfa816cd4 custom thread mainloop: finish pending sources when removing
We sometimes set a custom per-thread mainloop because and then spin it
manually to fake a sync call on a thread using async calls. Primarily
this happens with the soup streaming calls. In this case, eventually
we finish the main loop iteration (because, say, the download is done)
so we stop iterating the mainloop and return from the fake sync code.

However, that might not necessarily be the only thing queued on the
main context. I ran into a situation where it seems like libsoup did
some call to a thread-pool during the async call, and the next time i
used soup aync everything froze. It looks like there is some threaded
soup service that returned a response on the old context, and since
that never got handled (since that context is now dead) it now doesn't
work.

To solve this situation we're now iterating the main context until
there are no pending sources before killing the main context.
2021-03-19 10:59:04 +01:00
Alexander Larsson
1b130c5cc3 http utils: push custom thread local main context
We're calling async soup APIs with SOUP_SESSION_USE_THREAD_CONTEXT
set, which means that libsoup async APIs will run async callbacks on
the loop of the thread-default main context. We then manually spin
this main context, because we're supposed to look like a sync call and
the async stuff is just internally.

This is not really right, because normally there isn't any custom
mainloop context registred, which means we're spinning the main thread
context on some other thread, as well as queuing soup sorces on
it. This can't be any good!

Rather than doing this we actually create and push our own main
context that we then spin isolated from the default mainloop.
2021-03-19 10:59:04 +01: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
534cf643a6 Revert "Revert "flatpak-utils-http: Don’t use GMainLoop""
This reverts commit 14f062593f.
2021-03-19 10:59:04 +01:00
Simon McVittie
14f062593f Revert "flatpak-utils-http: Don’t use GMainLoop"
This reverts commit c1561b1ded,
which seems to trigger a hang in the
test-oci-registry@system.wrap test-case.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-03-17 15:35:34 +01:00
Philip Withnall
d26aa5aeb0 flatpak-dir: Make parental controls polkit query interactive iff dir is
Previously, the polkit query was always interactive, even if the
`FlatpakDir` was operating in non-interactive mode (for example, for a
background update in gnome-software). Make the interactivity match the
interactivity of the `FlatpakDir`.

Do the same for the `mct_manager_get_app_filter()` call, although this
is less important since under normal conditions it will never prompt the
user.

This should hopefully stop polkit prompts appearing periodically when
background updates are being done while logged in as a non-privileged
user with parental controls set to prevent application installation.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-03-16 18:29:19 +00:00
Simon McVittie
bb52aeb342 Merge pull request #4076 from pwithnall/no-main-loops
flatpak-utils-http: Don’t use GMainLoop
2021-03-12 12:44:22 +00:00
Simon McVittie
9e62824ae5 Merge pull request #4171 from a-wai/fix-test-webserver
Fix an issue with the test webserver cache
2021-03-12 12:42:16 +00:00
Phaedrus Leeds
bced1def31 Merge pull request #4155 from flatpak/wip/security-policy
Add an initial security policy
2021-03-11 09:06:45 -08:00
Arnaud Ferraris
6996580bb8 tests: web-server: fix an issue with the web server cache
On a decently fast system, some files may be fetched, modified and then
fetched again within the same second. In that case, the web server
replies with a code 304 ("Not modified") to the 2nd query, causing some
tests to fail.

This commit forces the web server to ignore `If-Modified-Since` HTTP
headers, effectively disabling caching in order to mitigate the problem.
2021-03-11 13:31:17 +01:00
Simon McVittie
653a9b82fa Add an initial security policy
If we can get people to report security issues privately, then we can do
coordinated disclosure instead of having to rush to fix issues that are
already known to the public.
2021-03-10 19:39:01 -08:00
Simon McVittie
46b3ede524 dir: Refuse to export .desktop files with suspicious uses of @@ tokens
This is either a malicious/compromised app trying to do an attack, or
a mistake that will break handling of %f, %u and so on. Either way,
if we refuse to export the .desktop file, resulting in installation
failing, then it makes the rejection more obvious than quietly
removing the magic tokens.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-03-10 10:45:30 +01:00
Simon McVittie
1e7e8fdb24 dir: Reserve the whole @@ prefix
If we add new features analogous to file forwarding later, we might
find that we need a different magic token. Let's reserve the whole
@@* namespace so we can call it @@something-else.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-03-10 10:45:30 +01:00
Ryan Gonzalez
652a28ffab Disallow @@ and @@u usage in desktop files
Fixes #4146.
2021-03-10 10:45:30 +01:00
Simon McVittie
ba381ae936 tests: Remove hard-coded references to x86_64
Distributions run these tests on other architectures, but hard-coding
x86_64 to look for in output dooms that to failure.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-03-10 10:35:18 +01:00
Bastien Nocera
19b11ade73 app: Fix deprecation warning
The "new way" is supported since at least 2010 (!).

app/parse-datetime.y:302.1-12: warning: deprecated directive: ‘%pure-parser’, use ‘%define api.pure’ [-Wdeprecated]
  302 | %pure-parser
      | ^~~~~~~~~~~~
      | %define api.pure
2021-03-10 10:33:51 +01:00
Bastien Nocera
1941ddbdba app: Use bison to build parse-datetime.y
As it uses directives that POSIX yacc doesn't support:
app/parse-datetime.y:302.1-12: warning: POSIX Yacc does not support %pure-parser [-Wyacc]
  302 | %pure-parser
      | ^~~~~~~~~~~~
app/parse-datetime.y:307.1-7: warning: POSIX Yacc does not support %expect [-Wyacc]
  307 | %expect 31
      | ^~~~~~~
2021-03-10 10:33:51 +01:00
Bastien Nocera
4ea46eb397 build: Add bison detection macro 2021-03-10 10:33:51 +01:00
Bastien Nocera
edf1e40bbb build: Fix warning during autogen.sh
The serial number is supposed to appear only once per file, at the top
of it. Add a serial that matches the highest serial and remove the
in-text serials.

acinclude.m4:113: warning: the serial number must appear before any macro definition
acinclude.m4:321: warning: the serial number must appear before any macro definition
2021-03-10 10:33:51 +01:00
Alicia Boya García
03369d3f47 Expose TERM to flatpak enter
This is necessary to be able to use ncurses-based programs, such as
nano or gdb TUI.
2021-03-10 10:32:29 +01:00
Alicia Boya García
f39287d47f Let child process handle SIGINT in flatpak enter
Otherwise when running software that handles SIGINT, such as gdb or
python, pressing ^C would kill flatpak-enter and return control to the
shell.
2021-03-10 10:28:52 +01:00
Phaedrus Leeds
79a91b5cf6 Make flatpak --help output use consistent verbiage
Use present tense consistently rather than gerunds for some headings in
"flatpak --help". Also tweak flatpak(1) to use similar wording but with
gerunds.
2021-03-10 10:27:31 +01:00
Gregor Simm
bcd7425597 Update dates in NEWS file
In the NEWS file, it says that versions 1.10.1 and 1.10.1 were released in 2020. Shouldn't that read 2021?
2021-02-23 14:56:01 +01:00
Bastien Nocera
e67847e253 common: Fix Spawn portal method not working with UTF-8 files
When the portal's Spawn method is used with the environment cleared,
it's very likely that the "flatpak run" that ends up being run will be
in an environment without UTF-8 support.

If one of the files or directories we try to expose to the sub-sandbox
contains UTF-8/non-ASCII characters, then "flatpak run" would fail with:
error: Invalid byte sequence in conversion input

This is caused by GOption trying to parse the --filesystem option for
flatpak, as, when using the G_OPTION_ARG_CALLBACK argument type, GOption
will split the option name from its value, and try to convert the value
to UTF-8. Which will fail because there's no UTF-8.

It won't however do that if we tell the option parser that the value is
a filename using G_OPTION_FLAG_FILENAME, so set it.
2021-02-23 14:18:57 +01:00
Phaedrus Leeds
c7bb35d323 Merge pull request #4134 from flatpak/trivial-configure-output
trivial: Fix formatting of configure output
2021-02-18 11:46:08 -08:00
Phaedrus Leeds
e2a2e38c6b Merge pull request #4130 from RyuzakiKK/xauthlocalhostname
run: Propagate X11 cookies with an address equals to XAUTHLOCALHOSTNAME
2021-02-18 11:45:50 -08:00
Phaedrus Leeds
af2b8ca236 Merge pull request #4133 from RyuzakiKK/unused_vars
Remove unused variables
2021-02-18 11:43:00 -08:00
Phaedrus Leeds
66c4ef8de9 trivial: Fix formatting of configure output 2021-02-18 11:31:10 -08:00
Ludovico de Nittis
0d27b27744 run: Remove unused GAsyncResult variable
Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
2021-02-18 11:39:45 +01:00
Ludovico de Nittis
8d9be910e5 dir: Remove unused AutoPolkitDetails variable
Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
2021-02-18 11:39:23 +01:00
Phaedrus Leeds
d192d1b43b Merge pull request #4119 from kalev/G_BEGIN_DECLS-G_END_DECLS
Add G_BEGIN_DECLS/G_END_DECLS to public headers
2021-02-17 10:32:30 -08:00
Ludovico de Nittis
fd6a3b79f4 run: Propagate X11 cookies with an address equals to XAUTHLOCALHOSTNAME
OpenSUSE inherits the hostname value from DHCP without updating its X11
authentication cookie, and it keeps the initial value in
`XAUTHLOCALHOSTNAME`.
To avoid breaking the X11 applications, OpenSUSE patches libxcb so that
it also considers the value in `XAUTHLOCALHOSTNAME` as another possible
hostname.

https://bugzilla.opensuse.org/show_bug.cgi?id=262309

To cope with that behavior we need to check `XAUTHLOCALHOSTNAME` too
and, if we have a cookie with that address, propagate it inside the
container adjusting its address to the canonical hostname
`unames.nodename`.

Fixes: #4043

Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
2021-02-17 18:03:00 +01:00
Kalev Lember
426284759c Add G_BEGIN_DECLS/G_END_DECLS to public headers
This ensures that we correctly specify C linkage when including flatpak
headers from C++ code.

This should fix fallout from glib's change to include C++ code in its
headers, see https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1935
for discussion.

Fixes https://github.com/flatpak/flatpak/issues/4117
2021-02-12 15:58:09 +01:00
Phaedrus Leeds
7224809bc1 testlibrary: Fix memory leaks 2021-02-10 09:17:53 +01:00
Phaedrus Leeds
2a111e5042 common: Add API for listing related refs of installed ref
Currently if a user of libflatpak wants to list the related refs (such
as extensions and plugins) of something, they have three options:
1. They can parse the metadata manually with e.g.
   flatpak_remote_ref_get_metadata() and then key-file operations, but
   this means re-implementing parts of libflatpak and using key file
   strings that are not actually public (FLATPAK_METADATA_KEY_...).
2. They can use flatpak_installation_list_installed_related_refs_sync()
   but this only works for installed related refs not remote ones.
3. They can use flatpak_installation_list_remote_related_refs_sync() but
   this lists all remotely available related refs, including ones that
   may not be compatible with the installed version of the main ref
   (because they don't match any of the values in the "versions"
   metadata key).

So since none of these provide a way to get the remote related refs
corresponding to an installed application, add new API for that. For the
motivation of this see
https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1132
2021-02-10 09:17:53 +01:00
Alexander Larsson
f85cbcfde2 Bump version to 1.11.1. 1.10.x is now on flatpak-1.10.x branch. 2021-02-10 09:16:10 +01:00
Phaedrus Leeds
bc39bb59c4 doc: Add info -l docs 2021-02-09 09:37:32 +01:00
Phaedrus Leeds
dbe81c90c2 common: Tweak error code docs
FLATPAK_ERROR_ALREADY_INSTALLED can be returned from, for example,
flatpak_installation_add_remote(), so document that it applies to
remotes not just apps and runtimes.
2021-02-09 09:36:59 +01:00
Phaedrus Leeds
0920e959b5 common: Update FlatpakRef docs with respect to uniqueness
See these links for context on this change:
- https://lists.freedesktop.org/archives/flatpak/2021-January/002087.html
- https://gitlab.gnome.org/GNOME/gnome-software/-/merge_requests/583#note_1006763
2021-02-09 09:34:47 +01:00