mirror of
https://gitlab.gnome.org/GNOME/libsecret.git
synced 2024-12-22 20:58:52 +00:00
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.
This commit is contained in:
parent
8f886f0797
commit
a278adc208
@ -155,7 +155,8 @@ backend_get_impl_type (void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WITH_GCRYPT
|
#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";
|
extension_name = "file";
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
@ -33,6 +33,7 @@ EGG_SECURE_DECLARE (secret_file_backend);
|
|||||||
#define PORTAL_OBJECT_PATH "/org/freedesktop/portal/desktop"
|
#define PORTAL_OBJECT_PATH "/org/freedesktop/portal/desktop"
|
||||||
#define PORTAL_REQUEST_INTERFACE "org.freedesktop.portal.Request"
|
#define PORTAL_REQUEST_INTERFACE "org.freedesktop.portal.Request"
|
||||||
#define PORTAL_SECRET_INTERFACE "org.freedesktop.portal.Secret"
|
#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_async_initable_iface (GAsyncInitableIface *iface);
|
||||||
static void secret_file_backend_backend_iface (SecretBackendInterface *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 = secret_file_backend_real_search;
|
||||||
iface->search_finish = secret_file_backend_real_search_finish;
|
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 ())
|
#define SECRET_TYPE_FILE_BACKEND (secret_file_backend_get_type ())
|
||||||
G_DECLARE_FINAL_TYPE (SecretFileBackend, secret_file_backend, SECRET, FILE_BACKEND, GObject)
|
G_DECLARE_FINAL_TYPE (SecretFileBackend, secret_file_backend, SECRET, FILE_BACKEND, GObject)
|
||||||
|
|
||||||
|
gboolean _secret_file_backend_check_portal_version (void);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __SECRET_FILE_BACKEND_H__ */
|
#endif /* __SECRET_FILE_BACKEND_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user