From ec7af044599a19d5709fa67d45f6af1a7ac1ae88 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Wed, 4 Oct 2023 11:04:48 -0300 Subject: [PATCH 1/3] session: Delete transient permissions when peer dies This is what the documented behaviour mentions - if the peer dies, transient permissions are gone. This doesn't yet work since we're removing transient permissions when the session is closed. Related: https://github.com/flatpak/xdg-desktop-portal/issues/1124 --- src/restore-token.c | 23 +++++++++++++++++++++++ src/restore-token.h | 2 ++ src/xdg-desktop-portal.c | 2 ++ 3 files changed, 27 insertions(+) diff --git a/src/restore-token.c b/src/restore-token.c index 2e6f31fcf..71910d849 100644 --- a/src/restore-token.c +++ b/src/restore-token.c @@ -89,6 +89,29 @@ xdp_session_persistence_delete_transient_permissions (Session *session, g_hash_table_remove (transient_permissions, id); } +void +xdp_session_persistence_delete_transient_permissions_for_sender (const char *sender_name) +{ + + g_autoptr(GMutexLocker) locker = NULL; + GHashTableIter iter; + const char *key; + + locker = g_mutex_locker_new (&transient_permissions_lock); + + if (!transient_permissions) + return; + + g_hash_table_iter_init (&iter, transient_permissions); + while (g_hash_table_iter_next (&iter, (gpointer *) &key, NULL)) + { + g_auto(GStrv) split = g_strsplit (key, "/", 2); + + if (split && split[0] && g_strcmp0 (split[0], sender_name) == 0) + g_hash_table_iter_remove (&iter); + } +} + GVariant * xdp_session_persistence_get_transient_permissions (Session *session, const char *restore_token) diff --git a/src/restore-token.h b/src/restore-token.h index 1853017be..fdd3389e6 100644 --- a/src/restore-token.h +++ b/src/restore-token.h @@ -34,6 +34,8 @@ void xdp_session_persistence_set_transient_permissions (Session *session, void xdp_session_persistence_delete_transient_permissions (Session *session, const char *restore_token); +void xdp_session_persistence_delete_transient_permissions_for_sender (const char *sender_name); + GVariant * xdp_session_persistence_get_transient_permissions (Session *session, const char *restore_token); diff --git a/src/xdg-desktop-portal.c b/src/xdg-desktop-portal.c index 157752543..e377a9671 100644 --- a/src/xdg-desktop-portal.c +++ b/src/xdg-desktop-portal.c @@ -57,6 +57,7 @@ #include "realtime.h" #include "remote-desktop.h" #include "request.h" +#include "restore-token.h" #include "screen-cast.h" #include "screenshot.h" #include "secret.h" @@ -229,6 +230,7 @@ peer_died_cb (const char *name) { close_requests_for_sender (name); close_sessions_for_sender (name); + xdp_session_persistence_delete_transient_permissions_for_sender (name); } static void From 9e6c7d9daf3b0fa55e30ce4ed0bcfc29e440b8ab Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Wed, 4 Oct 2023 11:07:22 -0300 Subject: [PATCH 2/3] restore-token: Keep transient permissions on session close This is the counterpart to removing transient permissions when the peer dies - not remove them when the session is closed. Closes: https://github.com/flatpak/xdg-desktop-portal/issues/1124 --- src/restore-token.c | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/src/restore-token.c b/src/restore-token.c index 71910d849..b084d2528 100644 --- a/src/restore-token.c +++ b/src/restore-token.c @@ -27,28 +27,6 @@ static GHashTable *transient_permissions; #define RESTORE_DATA_TYPE "(suv)" -static void -internal_closed_cb (Session *session) -{ - g_autoptr(GMutexLocker) locker = NULL; - GHashTableIter iter; - const char *key; - - locker = g_mutex_locker_new (&transient_permissions_lock); - - if (!transient_permissions) - return; - - g_hash_table_iter_init (&iter, transient_permissions); - while (g_hash_table_iter_next (&iter, (gpointer *) &key, NULL)) - { - g_auto(GStrv) split = g_strsplit (key, "/", 2); - - if (split && split[0] && g_strcmp0 (split[0], session->sender) == 0) - g_hash_table_iter_remove (&iter); - } -} - void xdp_session_persistence_set_transient_permissions (Session *session, const char *restore_token, @@ -66,13 +44,6 @@ xdp_session_persistence_set_transient_permissions (Session *session, g_hash_table_insert (transient_permissions, g_strdup_printf ("%s/%s", session->sender, restore_token), g_variant_ref (restore_data)); - - if (!session->persistence.has_transient_permissions) - { - g_signal_connect (session, "internal-closed", - G_CALLBACK (internal_closed_cb), NULL); - session->persistence.has_transient_permissions = TRUE; - } } void From 3b63f097e4d42a584fa11702deb51ac37be876a5 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Wed, 4 Oct 2023 11:08:35 -0300 Subject: [PATCH 3/3] session: Remove unused signal and struct field They're not used anymore. --- src/session.c | 18 ------------------ src/session.h | 4 ---- 2 files changed, 22 deletions(-) diff --git a/src/session.c b/src/session.c index 20017de6d..fe1a0d916 100644 --- a/src/session.c +++ b/src/session.c @@ -22,15 +22,6 @@ #include -enum -{ - INTERNAL_CLOSED, - - N_SIGNALS -}; - -static guint signals[N_SIGNALS]; - enum { PROP_0, @@ -183,8 +174,6 @@ session_close (Session *session, SESSION_GET_CLASS (session)->close (session); - g_signal_emit (session, signals[INTERNAL_CLOSED], 0); - if (notify_closed) { GVariantBuilder details_builder; @@ -539,11 +528,4 @@ session_class_init (SessionClass *klass) G_PARAM_STATIC_STRINGS); g_object_class_install_properties (gobject_class, PROP_LAST, obj_props); - - signals[INTERNAL_CLOSED] = g_signal_new ("internal-closed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, NULL, - G_TYPE_NONE, 0); } diff --git a/src/session.h b/src/session.h index d52aa9780..14e62045c 100644 --- a/src/session.h +++ b/src/session.h @@ -45,10 +45,6 @@ struct _Session char *impl_dbus_name; GDBusConnection *impl_connection; XdpDbusImplSession *impl_session; - - struct { - gboolean has_transient_permissions; - } persistence; }; struct _SessionClass