Commit Graph

49 Commits

Author SHA1 Message Date
Matthew Leeds
5a94edaef3 portal: Add g_autoptr() defines for old GLib versions
We don't need to check for GLib 2.44 (the first release with g_autoptr()
support) since Flatpak requires that version in configure.ac.

Fixes https://github.com/flatpak/flatpak/issues/3403
2020-02-12 16:43:18 +01:00
Alexander Larsson
d46483f578 Sandbox: Allow share-gpu also if caller has device=all
This fixes https://github.com/flatpak/flatpak/issues/3330
2020-01-15 08:57:15 +01:00
Matthias Clasen
6e45ff6d0f portal: Don't poll for updates on metered networks
Stop polling for updates on metered networks. Allow
overriding this with the new --poll-when-metered
option.

Fixes: https://github.com/flatpak/flatpak/issues/3286
2019-12-20 11:32:40 +01:00
Alexander Larsson
3666eb0950 portal: Make sure we inherit the passed thought fds in Spawn()
In the start of child_setup_func we set CLOEXEC on everything > 3, so
we need to undo this for the things we actually want to pass in.
2019-12-12 17:02:02 +01:00
Alexander Larsson
849f448732 portal: Allow the ALLOW_A11Y flag
This was accidentally left out of the FLAGS_ALL define so it was denied.
2019-12-04 13:41:20 +01:00
Alexander Larsson
38fecb08d3 portal: Add supports flag and set a bit if EXPOSE_PIDS is supported
We can only support this if the host bwrap is not setuid (at least for
now). This allows callers to detect this case ahead of time. We also
detect this case when called and return a better error code that
can be detected.
2019-11-27 14:21:25 +01:00
Alexander Larsson
ae50843851 portal: Add EXPOSE_PIDS flag
This uses the new bwrap feature via flatpak run --parent-expose-pids to
make new new sandbox pid namespace be a child of the callers sandbox.

Pretty obvious, the only weird thing is that we can't get the peer pid
directly from the caller (as it goes via the dbus proxy) so we have
to look that up from the instance data.
2019-11-27 14:21:25 +01:00
Alexander Larsson
834c23edc6 portal: Add sandbox-expose-fd[-ro] options that allow you to share any path
I you can open(O_PATH) any path in your sandbox you can now share that
with the sub-sandbox.
2019-11-26 09:52:07 +01:00
Alexander Larsson
7dad37f1b3 portal: Spawn clean up handling of file descriptors
We were using i instead of handle to index the file descriptors, which
is likely to be the same (due to ordering) but not really
correct. Also rename the variables to make this code easier to read.

Also, add some bounds check on the handles wrt the fd list.
2019-11-26 09:52:07 +01:00
Alexander Larsson
080a5c07a1 portal: Add sandbox flags for allowing ally/ and session bus access 2019-11-26 09:52:07 +01:00
Alexander Larsson
fa1bc8ca16 portal: Add flags for sharing display/sound/gpu when spawning sandboxed
This allows you to open up things (if the calling app has access) for
the sandboxed child.

Rather than duplicating all possible sandboxing technical details we
specify things at a higher level. We just assume you want the same
access as the caller (i.e. x11[-fallback] and/or wayland), as this is
easier to use for the caller and more flexible for us to later add new
technical details as needed.
2019-11-26 09:52:07 +01:00
Alexander Larsson
7071c38acf portal: Bump portal version to 3 (to signal new flag supported) 2019-11-26 09:52:07 +01:00
Alexander Larsson
05df609e75 update portal: Don't allow self-updates if new permissions are needed
In this case we report a NotSupported error (not permission denied, because
that is used for other things).
2019-10-02 14:57:11 +02:00
Alexander Larsson
1eb68628ba update-portal: Don't report updates for masked refs 2019-10-02 14:57:11 +02:00
Alexander Larsson
a95cf667a1 update-portal: Clean up details in progress reporting
Always report op/n_ops as their last values.
Ensure we never send op >= n_ops
Ensure we always send one and only one 100% running status (== op done)
2019-10-02 14:57:11 +02:00
Alexander Larsson
00921c2dba update-portal: Don't send weird glib encoded errors
If we don't have a registred dbus error, just send a generic
org.freedesktop.DBus.Error.Failed.
2019-10-02 14:57:11 +02:00
Alexander Larsson
a87aaac4b1 update-portal: Allow overriding portals directory
Allow overriding $datadir/xdg-desktop-portal/portals using the
$XDG_DESKTOP_PORTAL_DIR env var. We will need this in the test suite when
we want to pass in our own (faked) portal implementation.
2019-10-02 14:57:11 +02:00
Alexander Larsson
21bc4fc29b update-portal: Use error_message, not error-message
All other places use underscores instead of dashes.
2019-10-02 14:57:11 +02:00
Alexander Larsson
6cb11631c5 update-portal: Don't fail if permission store not available
This downgrades g_warning to g_info, so that we don't fail if the
permission store is not available, which will happen in the test-suite.
2019-10-02 14:57:11 +02:00
Alexander Larsson
a36f33d8ee update-portal: Ensure we close any stray fds when forking update child 2019-10-02 14:57:11 +02:00
Alexander Larsson
930919d7b1 update-portal: Emit progress on right interface and object path 2019-10-02 14:57:11 +02:00
Alexander Larsson
c15c1946ff test: Add test for update-portal monitoring
We add socat to the test runtime, and then we use that to run a
test app outside the sandbox as if it was inside.

The testcase connects creates a monitor and ensure we properly get signals
for updates.
2019-10-02 14:57:11 +02:00
Alexander Larsson
82328bee85 portal: Add option for poll frequency
We want to use these to get a quick turnaround in the tests.
2019-10-02 14:57:11 +02:00
Alexander Larsson
a4b2068bbc portal: Support application self-updates
This allows an application to request it to be updated to the latest version.

The updates are done out-of-process by re-spawning the portal (via
/proc/self/exe) and proxying the relevant events over a socket pair, in
order to avoid any long term stability or memory requirements from
running the update operation.
2019-10-02 14:57:11 +02:00
Alexander Larsson
e719463adf Bump the version of the flatpak portal interface to 2
Also mention this in the create monitor docs.
2019-10-02 14:57:11 +02:00
Matthias Clasen
fe0b8aa860 portal: Add updates monitoring
Add update monitoring to the flatpak portal.
No support yet for triggering updates.
2019-10-02 14:57:11 +02:00
Matthias Clasen
8ca4addc73 Find portal implementations properly
Share the portal implementation loading code
from xdg-desktop-portal, so we can select the
Access backend propertly.
2019-10-02 14:57:11 +02:00
Alexander Larsson
d91660fe2a Work around deadlocks in g_spawn by manually clo-exec:ing fds
As per https://gitlab.gnome.org/GNOME/glib/merge_requests/490
there is a bug in glib < 2.60 where g_spawn_* can sometimes deadlock
due to using malloc in the child func to close fds.

We work around this in places where the code is (potentially) threaded
by passing glib flags to leave fds alone and then do a very naive
(but safe) fd cloexec loop ourselves.
2019-09-30 12:15:36 +02:00
Simon McVittie
89dc344ccb icon-validator, portal: Guard against overlong symlink targets
If the buffer is too small, readlink() returns the number of bytes that
would have been stored if the buffer had been large enough.

Signed-off-by: Simon McVittie <smcv@collabora.com>

Closes: #2873
Approved by: matthiasclasen
2019-05-01 16:39:18 +00:00
Rafael Fontenelle
95e692794b Fix misspellings
Closes: #2807
Approved by: matthiasclasen
2019-04-08 12:50:42 +00:00
Matthew Leeds
e8816b7663 Remove extra newlines in variable definiton blocks
Uncrustify has an option "nl_func_var_def_blk" which is supposed to
ensure there's a newline character between the block of variable
definitions and the rest of the function body, but it gets confused and
thinks that the first instance of "g_autoptr" or "g_auto" being used on
a variable is the start of the function body. So this commit removes
those extra newline characters and removes that option in uncrustify.cfg
so they don't get re-added the next time uncrustify is run.

Here's the command I used:

perl -0777 -i -pe 's/\n(\n\s*g_auto\()/\1/g' `git ls-tree --name-only
-r HEAD | grep \\\.[ch]$ | grep -v common/valgrind-private.h |
grep -v app/flatpak-polkit-agent-text-listener\\\.[ch]`

I ran it again with "g_autoptr" in place of "g_auto", and made a few
manual edits to add back the newline when the g_auto* was in the middle
of a function body rather than at the top.

Closes: #2715
Approved by: matthiasclasen
2019-02-25 18:12:30 +00:00
Matthew Leeds
8d962a686f Run uncrustify
I had to make a few manual edits but other than those the changes look
reasonable.

Closes: #2715
Approved by: matthiasclasen
2019-02-25 18:12:30 +00:00
Ryan Gonzalez
d982f3c21b portal: Forward --devel from the calling instance (closes #2493)
Closes: #2515
Approved by: alexlarsson
2019-01-11 13:20:35 +00:00
Matthias Clasen
9f06ec5775 Fix coverage for system helper and portal
These services were not generating coverage data
because they always get ended by GDBus raising
SIGTERM when the bus goes away. Prevent this by
telling GDBus not to do that, and let the services
exit regularly, on their own terms.

This makes the system helper code show up in the
coverage statistics.

Closes: #2530
Approved by: matthiasclasen
2019-01-08 02:10:35 +00:00
Matthias Clasen
1d26870fa8 portal: Use the new --cwd option
The first argument of the Spawn portal call is the cwd
for the command to use inside the new sandbox. The portal
was mistakenly using it as cwd when running flatpak
on the host, which leads to errors. Fix this by
passing the cwd to flatpak via the new --cwdd option.

Closes: #2418

Closes: #2443
Approved by: alexlarsson
2018-12-20 15:35:24 +00:00
Matthias Clasen
5d068ab7f8 Fix another small memory leak
g_variant_iter_loop is tricky - if you exit the loop via
break or return, you have to clean up.

Closes: #2371
Approved by: alexlarsson
2018-12-18 14:50:26 +00:00
Matthias Clasen
9a1febd981 portal: Suport a watch-bus flag
This behaves just the same as the watch-bus flag that
was reently added to HostCommand.

Closes: #2439
Approved by: alexlarsson
2018-12-17 08:16:42 +00:00
Matthias Clasen
f53ef41032 portal: validate arguments better
Portals need to validate all their arguments.
We were not validating flags at all, and were not
very careful with some of the other arguments
either.

Closes: #2439
Approved by: alexlarsson
2018-12-17 08:16:42 +00:00
Will Thompson
97983ba377 portal, session-helper: fix typo in TIOCSCTTY comment
Closes: #2382
Approved by: matthiasclasen
2018-12-04 13:41:29 +00:00
Matthias Clasen
a1f82fd256 spawn: More precise error messages
Explain why exposes are invalid.

Closes: #2029
Approved by: alexlarsson
2018-08-28 07:50:13 +00:00
Alexander Larsson
3f4518b15c Run uncrustify
Closes: #1870
Approved by: alexlarsson
2018-07-08 10:05:37 +00:00
Alexander Larsson
2642b55e91 libflatpak: Guard public headers for individual includes 2018-05-29 16:37:21 +02:00
Simon McVittie
23a51ffa7c Don't distribute generated GDBus bindings for Flatpak portal
Closes: #1618
Approved by: alexlarsson
2018-04-30 12:20:13 +00:00
Alexander Larsson
442c0be116 common: Move flatpak-portal-error.[ch] back to common code
A symbol from this (flatpak_portal_error_quark) was leaked to libflatpak
due to being marked FLATPAK_EXTERN, so to keep ABI we move it back.

Fixes https://github.com/flatpak/flatpak/issues/1613

Closes: #1616
Approved by: alexlarsson
2018-04-26 07:41:17 +00:00
Alexander Larsson
f144c9fd52 portal: When spawning use the same runtime as the caller
Otherwise flatpak-spawn breaks when you e.g. `flatpak run -d`, because
the `--commit=` argument we use does not match the default runtime.
2018-04-24 10:30:06 +02:00
Alexander Larsson
d3dee9f052 Better build fix 2018-04-04 17:50:06 +02:00
Alexander Larsson
c0862fcbb8 Fix builddir != srcdir build 2018-04-04 17:42:24 +02:00
Alexander Larsson
a6ec434aed run: Escape : as \: in --filesystem= paths
This way we never get confused about which part of the argument
is the permission suffix, which could be exploitable if you can
control the --filesystem calls such as with sandboxed Spawns.
2018-04-04 17:25:59 +02:00
Alexander Larsson
11ef9999b6 Add flatpak portal
This listens to org.freedesktop.portal.Flatpak and lets flatpak
sandboxes do flatpak specific things.

Initially this only allows access to "Spawn", which lets you start a
new copy of the current or latest version of the calling app,
optionally with sandboxing.

This allows the app to re-start itself with the latest version after
an update, and the sandboxing is useful for apps that want to manually
sandbox part of themselves.

You can also expose one or more subdirectories of
~/.var/app/$appid/sandbox/ to the app, read-write or read-only. This is
useful to communicate with the sandbox.
2018-04-04 17:25:59 +02:00