After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 783130 - Make dbus activation sandbox-aware
Make dbus activation sandbox-aware
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2017-05-26 17:20 UTC by Matthias Clasen
Modified: 2017-05-29 21:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Update flatpak document portal interface (9.54 KB, patch)
2017-05-29 12:29 UTC, Matthias Clasen
none Details | Review
Add a wrapper for the AddFull document portal api (4.70 KB, patch)
2017-05-29 12:29 UTC, Matthias Clasen
none Details | Review
Make dbus activation sandbox-aware (4.16 KB, patch)
2017-05-29 12:29 UTC, Matthias Clasen
none Details | Review
Update flatpak document portal interface (9.72 KB, patch)
2017-05-29 14:24 UTC, Matthias Clasen
committed Details | Review
Add a wrapper for the AddFull document portal api (5.33 KB, patch)
2017-05-29 14:24 UTC, Matthias Clasen
committed Details | Review
Make dbus activation sandbox-aware (3.47 KB, patch)
2017-05-29 14:24 UTC, Matthias Clasen
none Details | Review
Make dbus activation sandbox-aware (3.09 KB, patch)
2017-05-29 14:31 UTC, Matthias Clasen
committed Details | Review

Description Matthias Clasen 2017-05-26 17:20:09 UTC
When launching a url handler by D-Bus, we need to make sure the launched application can actually see the file we are passing. With sandboxed applications, this is no longer automatically the case.

We fix this by calling the document portal to exported the files as-needed.

See the https://git.gnome.org/browse/glib/log/?h=sandboxed-dbus-activation branch.

Not that this code requires version 2 of the document portal API. If we talk to an older version, the AddFull call will fail, and the activate the application with the original uris, as before.
Comment 1 Matthias Clasen 2017-05-29 12:29:20 UTC
Created attachment 352761 [details] [review]
Update flatpak document portal interface

This api has been changed upstream, recently.
Comment 2 Matthias Clasen 2017-05-29 12:29:30 UTC
Created attachment 352762 [details] [review]
Add a wrapper for the AddFull document portal api

This is a wrapper which takes a list of uris and rewrites
them by calling AddFull with the file:// uris.
Comment 3 Matthias Clasen 2017-05-29 12:29:40 UTC
Created attachment 352763 [details] [review]
Make dbus activation sandbox-aware

When we call org.freedesktop.Application.Open to activate
an application and pass file uris, the application may not
be able to see the files due to a flatpak sandbox.

Flatpak puts the flatpak app-id in the  X-Flatpak key in
desktop files that it exports, so we can easily recognize
applications that may be affected by this.

In this case, call the document portal to export the files
and pass the resulting uri's instead of the original ones.
Comment 4 Philip Withnall 2017-05-29 12:31:39 UTC
Review of attachment 352761 [details] [review]:

> This api has been changed upstream, recently.

Would be good to include a link to upstream.
Comment 5 Philip Withnall 2017-05-29 12:40:48 UTC
Review of attachment 352762 [details] [review]:

::: gio/gdocumentportal.c
@@ +173,3 @@
+  GUnixFDList *fd_list = NULL;
+  GList *l;
+  int i, j;

Technically these should be gsize (or at least unsigned).

@@ +180,3 @@
+  if (!init_document_portal ())
+    {
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,

Maybe an error code like G_IO_ERROR_NOT_INITIALIZED would be more appropriate?

@@ +185,3 @@
+    }
+
+  length = g_list_length (uris);

If (length == 0) this function will end up returning NULL without setting an error. Is that desired, or do we want to add a precondition check to avoid (length == 0)?

@@ +202,3 @@
+          int fd;
+
+          fd = open (path, O_CLOEXEC | O_PATH);

s/open/g_open/ for consistency and portability.

@@ +216,3 @@
+    }
+
+  g_variant_builder_add (&builder, "u", 1 << 2); /* as-needed-by-app */

Move the flag definition out to a constant/enum somewhere, since it’s used in more than one place here.

@@ +237,3 @@
+      for (l = uris, i = 0, j = 0; l; l = l->next, i++)
+        {
+          char *uri = l->data;

const

@@ +242,3 @@
+          if (as_is[i]) /* use as-is, not a file uri */
+            {
+                ruri = g_strdup (uri);

Indentation problem.

@@ +259,3 @@
+            }
+
+          ruris = g_list_append (ruris, ruri);

Would be more efficient to prepend here, then reverse the list before returning.
Comment 6 Philip Withnall 2017-05-29 12:44:15 UTC
Review of attachment 352763 [details] [review]:

::: gio/gdocumentportal.c
@@ -218,3 @@
-  g_variant_builder_add (&builder, "u", 1 << 2); /* as-needed-by-app */
-  g_variant_builder_add (&builder, "s", app_id);
-  g_variant_builder_add (&builder, "^as", permissions);

Why has this lot been removed?
Comment 7 Matthias Clasen 2017-05-29 13:38:48 UTC
(In reply to Philip Withnall from comment #5)

> +
> +  length = g_list_length (uris);
> 
> If (length == 0) this function will end up returning NULL without setting an
> error. Is that desired, or do we want to add a precondition check to avoid
> (length == 0)?
> 

NULL-in, NULL-out seems just right to me. Not an error, it properly handled all the documents in the list (ie: none).
Comment 8 Matthias Clasen 2017-05-29 13:49:16 UTC
(In reply to Philip Withnall from comment #6)
> Review of attachment 352763 [details] [review] [review]:
> 
> ::: gio/gdocumentportal.c
> @@ -218,3 @@
> -  g_variant_builder_add (&builder, "u", 1 << 2); /* as-needed-by-app */
> -  g_variant_builder_add (&builder, "s", app_id);
> -  g_variant_builder_add (&builder, "^as", permissions);
> 
> Why has this lot been removed?

This was an accidental leftover from a version of the branch that didn't use dbus-codegen
Comment 9 Philip Withnall 2017-05-29 14:18:20 UTC
(In reply to Matthias Clasen from comment #7)
> (In reply to Philip Withnall from comment #5)
> 
> > +
> > +  length = g_list_length (uris);
> > 
> > If (length == 0) this function will end up returning NULL without setting an
> > error. Is that desired, or do we want to add a precondition check to avoid
> > (length == 0)?
> > 
> 
> NULL-in, NULL-out seems just right to me. Not an error, it properly handled
> all the documents in the list (ie: none).

Agreed. I just wanted to make sure it was deliberate.
Comment 10 Matthias Clasen 2017-05-29 14:24:18 UTC
Created attachment 352784 [details] [review]
Update flatpak document portal interface

This api has been changed upstream, recently.

A new AddFull method has been added in this commit:
https://github.com/flatpak/flatpak/commit/6ce8521b640c7a69f97a2fd7c96de94eb9a83125
Comment 11 Matthias Clasen 2017-05-29 14:24:32 UTC
Created attachment 352785 [details] [review]
Add a wrapper for the AddFull document portal api

This is a wrapper which takes a list of uris and rewrites
them by calling AddFull with the file:// uris.
Comment 12 Matthias Clasen 2017-05-29 14:24:44 UTC
Created attachment 352787 [details] [review]
Make dbus activation sandbox-aware

When we call org.freedesktop.Application.Open to activate
an application and pass file uris, the application may not
be able to see the files due to a flatpak sandbox.

Flatpak puts the flatpak app-id in the  X-Flatpak key in
desktop files that it exports, so we can easily recognize
applications that may be affected by this.

In this case, call the document portal to export the files
and pass the resulting uri's instead of the original ones.
Comment 13 Matthias Clasen 2017-05-29 14:27:30 UTC
Review of attachment 352787 [details] [review]:

::: gio/gdesktopappinfo.c
@@ +37,3 @@
 #ifdef G_OS_UNIX
 #include "glib-unix.h"
+#include "gunixfdlist.h"

This one is unnecessary and should be dropped

@@ +2873,3 @@
                           uris ? "Open" : "Activate", g_variant_builder_end (&builder),
                           NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
+

Some redundant whitespace changes here
Comment 14 Matthias Clasen 2017-05-29 14:31:06 UTC
Created attachment 352788 [details] [review]
Make dbus activation sandbox-aware

When we call org.freedesktop.Application.Open to activate
an application and pass file uris, the application may not
be able to see the files due to a flatpak sandbox.

Flatpak puts the flatpak app-id in the  X-Flatpak key in
desktop files that it exports, so we can easily recognize
applications that may be affected by this.

In this case, call the document portal to export the files
and pass the resulting uri's instead of the original ones.
Comment 15 Philip Withnall 2017-05-29 14:49:38 UTC
Review of attachment 352784 [details] [review]:

++
Comment 16 Philip Withnall 2017-05-29 14:51:00 UTC
Review of attachment 352785 [details] [review]:

Looks good too me.
Comment 17 Philip Withnall 2017-05-29 14:51:39 UTC
Review of attachment 352788 [details] [review]:

++
Comment 18 Matthias Clasen 2017-05-29 21:58:42 UTC
Attachment 352784 [details] pushed as a76fc7f - Update flatpak document portal interface
Attachment 352785 [details] pushed as 60a1cc9 - Add a wrapper for the AddFull document portal api
Attachment 352788 [details] pushed as d3b4f7c - Make dbus activation sandbox-aware