Blame SOURCES/0014-libgdm-Fetch-connection-synchronously.patch

b61949
From 1974c64e7611d737d354dc9cb57a8a266e179e84 Mon Sep 17 00:00:00 2001
b61949
From: Ray Strode <rstrode@redhat.com>
b61949
Date: Sun, 11 Oct 2020 21:36:44 -0400
b61949
Subject: [PATCH 14/15] libgdm: Fetch connection synchronously
b61949
b61949
There's a race condition in the client connection code at the moment,
b61949
where a user verifier could be waiting for its connection when the login
b61949
screen asks for a greeter synchronously.  The greeter will then end up
b61949
with a different connection that the user verifier which breaks
b61949
expectations.
b61949
b61949
This commit just makes the connection fetching code synchronous for now
b61949
to side step the problem.
b61949
---
b61949
 libgdm/gdm-client.c | 94 +++++----------------------------------------
b61949
 1 file changed, 9 insertions(+), 85 deletions(-)
b61949
b61949
diff --git a/libgdm/gdm-client.c b/libgdm/gdm-client.c
b61949
index 66f6102ec..afe78087f 100644
b61949
--- a/libgdm/gdm-client.c
b61949
+++ b/libgdm/gdm-client.c
b61949
@@ -419,180 +419,104 @@ gdm_client_get_connection_sync (GdmClient      *client,
b61949
                                                       G_DBUS_PROXY_FLAGS_NONE,
b61949
                                                       "org.gnome.DisplayManager",
b61949
                                                       "/org/gnome/DisplayManager/Manager",
b61949
                                                       cancellable,
b61949
                                                       error);
b61949
 
b61949
         if (manager == NULL) {
b61949
                 return NULL;
b61949
         }
b61949
 
b61949
         ret = gdm_manager_call_open_session_sync (manager,
b61949
                                                   &address,
b61949
                                                   cancellable,
b61949
                                                   error);
b61949
 
b61949
         if (!ret) {
b61949
                 return NULL;
b61949
         }
b61949
 
b61949
         g_debug ("GdmClient: connecting to address: %s", address);
b61949
 
b61949
         connection = g_dbus_connection_new_for_address_sync (address,
b61949
                                                              G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
b61949
                                                              NULL,
b61949
                                                              cancellable,
b61949
                                                              error);
b61949
 
b61949
         return connection;
b61949
 }
b61949
 
b61949
-static void
b61949
-on_connected (GObject            *source_object,
b61949
-              GAsyncResult       *result,
b61949
-              gpointer            user_data)
b61949
-{
b61949
-        g_autoptr(GTask)           task = user_data;
b61949
-        g_autoptr(GDBusConnection) connection = NULL;
b61949
-        g_autoptr(GError)          error = NULL;
b61949
-
b61949
-        connection = g_dbus_connection_new_for_address_finish (result, &error);
b61949
-        if (!connection) {
b61949
-                g_task_return_error (task, g_steal_pointer (&error));
b61949
-                return;
b61949
-        }
b61949
-
b61949
-        g_task_return_pointer (task,
b61949
-                               g_steal_pointer (&connection),
b61949
-                               (GDestroyNotify) g_object_unref);
b61949
-}
b61949
-
b61949
-static void
b61949
-on_session_opened (GdmManager         *manager,
b61949
-                   GAsyncResult       *result,
b61949
-                   gpointer            user_data)
b61949
-{
b61949
-        GCancellable     *cancellable;
b61949
-        g_autoptr(GTask)     task = user_data;
b61949
-        g_autoptr(GdmClient) client = NULL;
b61949
-        g_autoptr(GError)    error = NULL;
b61949
-        g_autofree char     *address = NULL;
b61949
-
b61949
-        client = GDM_CLIENT (g_async_result_get_source_object (G_ASYNC_RESULT (task)));
b61949
-
b61949
-        if (!gdm_manager_call_open_session_finish (manager,
b61949
-                                                   &address,
b61949
-                                                   result,
b61949
-                                                   &error)) {
b61949
-                g_task_return_error (task, g_steal_pointer (&error));
b61949
-                return;
b61949
-        }
b61949
-
b61949
-        cancellable = g_task_get_cancellable (task);
b61949
-        g_dbus_connection_new_for_address (address,
b61949
-                                           G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
b61949
-                                           NULL,
b61949
-                                           cancellable,
b61949
-                                           on_connected,
b61949
-                                           g_steal_pointer (&task));
b61949
-}
b61949
-
b61949
-static void
b61949
-on_got_manager_for_opening_connection (GdmClient           *client,
b61949
-                                       GAsyncResult        *result,
b61949
-                                       gpointer             user_data)
b61949
-{
b61949
-        GCancellable *cancellable;
b61949
-        g_autoptr(GTask)      task = user_data;
b61949
-        g_autoptr(GdmManager) manager = NULL;
b61949
-        g_autoptr(GError)     error = NULL;
b61949
-
b61949
-        manager = g_task_propagate_pointer (G_TASK (result), &error);
b61949
-        if (manager == NULL) {
b61949
-                g_task_return_error (task, g_steal_pointer (&error));
b61949
-                return;
b61949
-        }
b61949
-
b61949
-        cancellable = g_task_get_cancellable (task);
b61949
-        gdm_manager_call_open_session (manager,
b61949
-                                       cancellable,
b61949
-                                       (GAsyncReadyCallback)
b61949
-                                       on_session_opened,
b61949
-                                       g_steal_pointer (&task));
b61949
-}
b61949
-
b61949
 static GDBusConnection *
b61949
 gdm_client_get_connection_finish (GdmClient      *client,
b61949
                                   GAsyncResult   *result,
b61949
                                   GError        **error)
b61949
 {
b61949
         GDBusConnection *connection;
b61949
 
b61949
         g_return_val_if_fail (GDM_IS_CLIENT (client), NULL);
b61949
 
b61949
         connection = g_task_propagate_pointer (G_TASK (result), error);
b61949
         if (connection == NULL) {
b61949
                 return NULL;
b61949
         }
b61949
 
b61949
         return connection;
b61949
 }
b61949
 
b61949
 static void
b61949
 gdm_client_get_connection (GdmClient           *client,
b61949
                             GCancellable        *cancellable,
b61949
                             GAsyncReadyCallback  callback,
b61949
                             gpointer             user_data)
b61949
 {
b61949
         g_autoptr(GTask) task = NULL;
b61949
+        g_autoptr(GError) error = NULL;
b61949
         GDBusConnection *connection;
b61949
 
b61949
         g_return_if_fail (GDM_IS_CLIENT (client));
b61949
 
b61949
         task = g_task_new (G_OBJECT (client),
b61949
                            cancellable,
b61949
                            callback,
b61949
                            user_data);
b61949
 
b61949
-        connection = gdm_client_get_open_connection (client);
b61949
+        connection = gdm_client_get_connection_sync (client,
b61949
+                                                     cancellable,
b61949
+                                                     &error);
b61949
         if (connection != NULL) {
b61949
-            g_task_return_pointer (task,
b61949
-                                   g_object_ref (connection),
b61949
-                                   (GDestroyNotify) g_object_unref);
b61949
-            return;
b61949
+                g_task_return_pointer (task,
b61949
+                                       g_object_ref (connection),
b61949
+                                       (GDestroyNotify) g_object_unref);
b61949
+        } else {
b61949
+                g_task_return_error (task, g_steal_pointer (&error));
b61949
         }
b61949
-
b61949
-        get_manager (client,
b61949
-                     cancellable,
b61949
-                     (GAsyncReadyCallback)
b61949
-                     on_got_manager_for_opening_connection,
b61949
-                     g_steal_pointer (&task));
b61949
 }
b61949
 
b61949
 /**
b61949
  * gdm_client_open_reauthentication_channel_sync:
b61949
  * @client: a #GdmClient
b61949
  * @username: user to reauthenticate
b61949
  * @cancellable: a #GCancellable
b61949
  * @error: a #GError
b61949
  *
b61949
  * Gets a #GdmUserVerifier object that can be used to
b61949
  * reauthenticate an already logged in user. Free with
b61949
  * g_object_unref to close reauthentication channel.
b61949
  *
b61949
  * Returns: (transfer full): #GdmUserVerifier or %NULL if @username is not
b61949
  * already logged in.
b61949
  */
b61949
 GdmUserVerifier *
b61949
 gdm_client_open_reauthentication_channel_sync (GdmClient     *client,
b61949
                                                const char    *username,
b61949
                                                GCancellable  *cancellable,
b61949
                                                GError       **error)
b61949
 {
b61949
         g_autoptr(GDBusConnection) connection = NULL;
b61949
         g_autoptr(GdmManager)      manager = NULL;
b61949
         g_autofree char *address = NULL;
b61949
         GdmUserVerifier *user_verifier = NULL;
b61949
         gboolean         ret;
b61949
 
b61949
         g_return_val_if_fail (GDM_IS_CLIENT (client), NULL);
b61949
 
b61949
-- 
52125b
2.25.1
b61949