Commit a278adc2 authored by Daiki Ueno's avatar Daiki Ueno Committed by Daiki Ueno

secret-backend: Check if portal is available

Before decising to use the file backend, check if the necessary portal
interface is available on the D-Bus.

Suggested by Patrick Griffis.
parent 8f886f07
Pipeline #122979 passed with stages
in 9 minutes and 57 seconds
......@@ -155,7 +155,8 @@ backend_get_impl_type (void)
#endif
#ifdef WITH_GCRYPT
if (g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS))
if (g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS) &&
_secret_file_backend_check_portal_version ())
extension_name = "file";
else
#endif
......
......@@ -33,6 +33,7 @@ EGG_SECURE_DECLARE (secret_file_backend);
#define PORTAL_OBJECT_PATH "/org/freedesktop/portal/desktop"
#define PORTAL_REQUEST_INTERFACE "org.freedesktop.portal.Request"
#define PORTAL_SECRET_INTERFACE "org.freedesktop.portal.Secret"
#define PORTAL_SECRET_VERSION 1
static void secret_file_backend_async_initable_iface (GAsyncInitableIface *iface);
static void secret_file_backend_backend_iface (SecretBackendInterface *iface);
......@@ -776,3 +777,50 @@ secret_file_backend_backend_iface (SecretBackendInterface *iface)
iface->search = secret_file_backend_real_search;
iface->search_finish = secret_file_backend_real_search_finish;
}
gboolean
_secret_file_backend_check_portal_version (void)
{
GDBusConnection *connection;
GVariant *ret;
GVariant *value;
guint32 version;
GError *error = NULL;
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
if (!connection) {
g_warning ("couldn't get session bus: %s", error->message);
g_error_free (error);
return FALSE;
}
ret = g_dbus_connection_call_sync (connection,
PORTAL_BUS_NAME,
PORTAL_OBJECT_PATH,
"org.freedesktop.DBus.Properties",
"Get",
g_variant_new ("(ss)",
PORTAL_SECRET_INTERFACE,
"version"),
G_VARIANT_TYPE ("(v)"),
0, -1, NULL, &error);
g_object_unref (connection);
if (!ret) {
g_message ("secret portal is not available: %s",
error->message);
g_error_free (error);
return FALSE;
}
g_variant_get (ret, "(v)", &value);
g_variant_unref (ret);
version = g_variant_get_uint32 (value);
g_variant_unref (value);
if (version != PORTAL_SECRET_VERSION) {
g_message ("secret portal version mismatch: %u != %u",
version, PORTAL_SECRET_VERSION);
return FALSE;
}
return TRUE;
}
......@@ -26,6 +26,8 @@ G_BEGIN_DECLS
#define SECRET_TYPE_FILE_BACKEND (secret_file_backend_get_type ())
G_DECLARE_FINAL_TYPE (SecretFileBackend, secret_file_backend, SECRET, FILE_BACKEND, GObject)
gboolean _secret_file_backend_check_portal_version (void);
G_END_DECLS
#endif /* __SECRET_FILE_BACKEND_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment