secret-backend: Allow override the backend also under Flatpak/Snap

This can help applications, which rely on certain behavior, like when
multiple processes are accessing the secrets and expect that secrets
saved by one process can be read by another process.

It also adds consistency, to be able to change the backend with
the host system libsecret and sandboxed libsecret.

Related to https://gitlab.gnome.org/GNOME/libsecret/-/issues/62
This commit is contained in:
Milan Crha 2023-09-18 13:28:12 +02:00
parent cc309e255a
commit 51725df97d

View File

@ -152,18 +152,16 @@ backend_get_impl_type (void)
g_type_ensure (secret_file_backend_get_type ()); g_type_ensure (secret_file_backend_get_type ());
#endif #endif
envvar = g_getenv ("SECRET_BACKEND");
if (envvar == NULL || *envvar == '\0') {
extension_name = "service";
#ifdef WITH_CRYPTO #ifdef WITH_CRYPTO
if ((g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS) || g_getenv ("SNAP_NAME") != NULL) && if ((g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS) || g_getenv ("SNAP_NAME") != NULL) &&
_secret_file_backend_check_portal_version ()) _secret_file_backend_check_portal_version ())
extension_name = "file"; extension_name = "file";
else
#endif #endif
{ } else {
envvar = g_getenv ("SECRET_BACKEND"); extension_name = envvar;
if (envvar == NULL || *envvar == '\0')
extension_name = "service";
else
extension_name = envvar;
} }
ep = g_io_extension_point_lookup (SECRET_BACKEND_EXTENSION_POINT_NAME); ep = g_io_extension_point_lookup (SECRET_BACKEND_EXTENSION_POINT_NAME);