diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2020-01-23 23:33:46 +0100 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2020-07-17 09:33:38 +0200 |
commit | f2f8833715669cbb8138b0d1ed3a3ede4e416161 (patch) | |
tree | e90f271bee3468dc4c3005245c5de5493933fe0c /src/libtracker-sparql/bus | |
parent | 1a1dd3c2b095b43876070ef0a70c31a7d142d00e (diff) | |
download | tracker-f2f8833715669cbb8138b0d1ed3a3ede4e416161.tar.gz |
libtracker-bus: Fallback through portal on bus connections
If the DBus name is not accessible and we are inside a flatpak
sandbox, fallback through the portal service so we can get a
connection filtered by policies.
Diffstat (limited to 'src/libtracker-sparql/bus')
-rw-r--r-- | src/libtracker-sparql/bus/tracker-bus.vala | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/src/libtracker-sparql/bus/tracker-bus.vala b/src/libtracker-sparql/bus/tracker-bus.vala index 72069873f..13a6d9dec 100644 --- a/src/libtracker-sparql/bus/tracker-bus.vala +++ b/src/libtracker-sparql/bus/tracker-bus.vala @@ -22,8 +22,16 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection { string dbus_name; string object_path; + private const string DBUS_PEER_IFACE = "org.freedesktop.DBus.Peer"; + + private const string PORTAL_NAME = "org.freedesktop.portal.Tracker"; + private const string PORTAL_PATH = "/org/freedesktop/portal/Tracker"; + private const string PORTAL_IFACE = "org.freedesktop.portal.Tracker"; + private const string ENDPOINT_IFACE = "org.freedesktop.Tracker3.Endpoint"; + private const int timeout = 30000; + public string bus_name { get { return dbus_name; } } @@ -34,12 +42,41 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection { public Connection (string dbus_name, string object_path, DBusConnection? dbus_connection) throws Sparql.Error, IOError, DBusError, GLib.Error { Object (); - this.dbus_name = dbus_name; this.bus = dbus_connection; - this.object_path = object_path; // ensure that error domain is registered with GDBus new Sparql.Error.INTERNAL (""); + + var message = new DBusMessage.method_call (dbus_name, object_path, DBUS_PEER_IFACE, "Ping"); + + try { + this.bus.send_message_with_reply_sync (message, 0, timeout, null).to_gerror(); + this.dbus_name = dbus_name; + this.object_path = object_path; + } catch (GLib.Error e) { + if (GLib.FileUtils.test ("/.flatpak-info", GLib.FileTest.EXISTS)) { + /* We are in a flatpak sandbox, check going through the portal */ + + if (object_path == "/org/freedesktop/Tracker3/Endpoint") + object_path = null; + + string uri = Tracker.util_build_dbus_uri (GLib.BusType.SESSION, dbus_name, object_path); + message = new DBusMessage.method_call (PORTAL_NAME, PORTAL_PATH, PORTAL_IFACE, "CreateSession"); + message.set_body (new Variant ("(s)", uri)); + + var reply = this.bus.send_message_with_reply_sync (message, 0, timeout, null); + + reply.to_gerror(); + + var variant = reply.get_body (); + variant.get_child(0, "o", out object_path); + + this.dbus_name = PORTAL_NAME; + this.object_path = object_path; + } else { + throw e; + } + } } static void pipe (out UnixInputStream input, out UnixOutputStream output) throws IOError { |