Blame SOURCES/0001-display-ask-accountservice-if-there-are-users-rather.patch

f83012
From 781e865705b0c134271c9ec21655cd5d8ce37fec Mon Sep 17 00:00:00 2001
f83012
From: Ray Strode <rstrode@redhat.com>
f83012
Date: Sat, 14 Dec 2019 13:50:53 -0500
f83012
Subject: [PATCH] display: ask accountservice if there are users rather than
f83012
 enumerate users
f83012
f83012
At the moment we ask accountsservice to give us the list of users just
f83012
to find out if there is a list of users.
f83012
f83012
That's rather inefficient and might be wrong for directory server users
f83012
that have never logged in before.
f83012
f83012
This commit changes gdm to ask accountsservice the question we really
f83012
want to know the answer to; whether or not there are users.
f83012
---
f83012
 daemon/gdm-display.c | 55 ++++++++++++++++++--------------------------
f83012
 1 file changed, 22 insertions(+), 33 deletions(-)
f83012
f83012
diff --git a/daemon/gdm-display.c b/daemon/gdm-display.c
f83012
index 878be88da..875534272 100644
f83012
--- a/daemon/gdm-display.c
f83012
+++ b/daemon/gdm-display.c
f83012
@@ -57,62 +57,60 @@
f83012
 struct GdmDisplayPrivate
f83012
 {
f83012
         char                 *id;
f83012
         char                 *seat_id;
f83012
         char                 *session_id;
f83012
         char                 *session_class;
f83012
         char                 *session_type;
f83012
 
f83012
         char                 *remote_hostname;
f83012
         int                   x11_display_number;
f83012
         char                 *x11_display_name;
f83012
         int                   status;
f83012
         time_t                creation_time;
f83012
         GTimer               *server_timer;
f83012
 
f83012
         char                 *x11_cookie;
f83012
         gsize                 x11_cookie_size;
f83012
         GdmDisplayAccessFile *access_file;
f83012
 
f83012
         guint                 finish_idle_id;
f83012
 
f83012
         xcb_connection_t     *xcb_connection;
f83012
         int                   xcb_screen_number;
f83012
 
f83012
         GDBusConnection      *connection;
f83012
         GdmDisplayAccessFile *user_access_file;
f83012
 
f83012
         GdmDBusDisplay       *display_skeleton;
f83012
         GDBusObjectSkeleton  *object_skeleton;
f83012
 
f83012
-        GDBusProxy           *accountsservice_proxy;
f83012
-
f83012
         /* this spawns and controls the greeter session */
f83012
         GdmLaunchEnvironment *launch_environment;
f83012
 
f83012
         guint                 is_local : 1;
f83012
         guint                 is_initial : 1;
f83012
         guint                 allow_timed_login : 1;
f83012
         guint                 have_existing_user_accounts : 1;
f83012
         guint                 doing_initial_setup : 1;
f83012
 };
f83012
 
f83012
 enum {
f83012
         PROP_0,
f83012
         PROP_ID,
f83012
         PROP_STATUS,
f83012
         PROP_SEAT_ID,
f83012
         PROP_SESSION_ID,
f83012
         PROP_SESSION_CLASS,
f83012
         PROP_SESSION_TYPE,
f83012
         PROP_REMOTE_HOSTNAME,
f83012
         PROP_X11_DISPLAY_NUMBER,
f83012
         PROP_X11_DISPLAY_NAME,
f83012
         PROP_X11_COOKIE,
f83012
         PROP_X11_AUTHORITY_FILE,
f83012
         PROP_IS_CONNECTED,
f83012
         PROP_IS_LOCAL,
f83012
         PROP_LAUNCH_ENVIRONMENT,
f83012
         PROP_IS_INITIAL,
f83012
         PROP_ALLOW_TIMED_LOGIN,
f83012
         PROP_HAVE_EXISTING_USER_ACCOUNTS,
f83012
         PROP_DOING_INITIAL_SETUP,
f83012
@@ -512,96 +510,88 @@ queue_finish (GdmDisplay *self)
f83012
         if (self->priv->finish_idle_id == 0) {
f83012
                 self->priv->finish_idle_id = g_idle_add ((GSourceFunc)finish_idle, self);
f83012
         }
f83012
 }
f83012
 
f83012
 static void
f83012
 _gdm_display_set_status (GdmDisplay *self,
f83012
                          int         status)
f83012
 {
f83012
         if (status != self->priv->status) {
f83012
                 self->priv->status = status;
f83012
                 g_object_notify (G_OBJECT (self), "status");
f83012
         }
f83012
 }
f83012
 
f83012
 static gboolean
f83012
 gdm_display_real_prepare (GdmDisplay *self)
f83012
 {
f83012
         g_return_val_if_fail (GDM_IS_DISPLAY (self), FALSE);
f83012
 
f83012
         g_debug ("GdmDisplay: prepare display");
f83012
 
f83012
         _gdm_display_set_status (self, GDM_DISPLAY_PREPARED);
f83012
 
f83012
         return TRUE;
f83012
 }
f83012
 
f83012
 static void
f83012
 look_for_existing_users_sync (GdmDisplay *self)
f83012
 {
f83012
-        GError *error = NULL;
f83012
-        GVariant *call_result;
f83012
-        GVariant *user_list;
f83012
-
f83012
-        self->priv->accountsservice_proxy = g_dbus_proxy_new_sync (self->priv->connection,
f83012
-                                                                   0, NULL,
f83012
-                                                                   "org.freedesktop.Accounts",
f83012
-                                                                   "/org/freedesktop/Accounts",
f83012
-                                                                   "org.freedesktop.Accounts",
f83012
-                                                                   NULL,
f83012
-                                                                   &error);
f83012
-
f83012
-        if (!self->priv->accountsservice_proxy) {
f83012
-                g_warning ("Failed to contact accountsservice: %s", error->message);
f83012
-                goto out;
f83012
-        }
f83012
-
f83012
-        call_result = g_dbus_proxy_call_sync (self->priv->accountsservice_proxy,
f83012
-                                              "ListCachedUsers",
f83012
-                                              NULL,
f83012
-                                              0,
f83012
+        g_autoptr (GVariant) result = NULL;
f83012
+        g_autoptr (GVariant) result_child = NULL;
f83012
+        g_autoptr (GError) error = NULL;
f83012
+        gboolean has_no_users = FALSE;
f83012
+
f83012
+        result = g_dbus_connection_call_sync (self->priv->connection,
f83012
+                                              "org.freedesktop.Accounts",
f83012
+                                              "/org/freedesktop/Accounts",
f83012
+                                              "org.freedesktop.DBus.Properties",
f83012
+                                              "Get",
f83012
+                                              g_variant_new ("(ss)", "org.freedesktop.Accounts", "HasNoUsers"),
f83012
+                                              G_VARIANT_TYPE ("(v)"),
f83012
+                                              G_DBUS_CALL_FLAGS_NONE,
f83012
                                               -1,
f83012
                                               NULL,
f83012
                                               &error);
f83012
 
f83012
-        if (!call_result) {
f83012
-                g_warning ("Failed to list cached users: %s", error->message);
f83012
-                goto out;
f83012
+        if (result == NULL) {
f83012
+                g_warning ("Failed to contact accountsservice: %s", error->message);
f83012
+                return;
f83012
         }
f83012
 
f83012
-        g_variant_get (call_result, "(@ao)", &user_list);
f83012
-        self->priv->have_existing_user_accounts = g_variant_n_children (user_list) > 0;
f83012
-        g_variant_unref (user_list);
f83012
-        g_variant_unref (call_result);
f83012
-out:
f83012
-        g_clear_error (&error);
f83012
+        g_variant_get (result, "(v)", &result_child);
f83012
+        has_no_users = g_variant_get_boolean (result_child);
f83012
+        self->priv->have_existing_user_accounts = !has_no_users;
f83012
+
f83012
+        g_debug ("GdmDisplay: machine does %shave existing user accounts",
f83012
+                 has_no_users? "not " : "");
f83012
 }
f83012
 
f83012
 gboolean
f83012
 gdm_display_prepare (GdmDisplay *self)
f83012
 {
f83012
         gboolean ret;
f83012
 
f83012
         g_return_val_if_fail (GDM_IS_DISPLAY (self), FALSE);
f83012
 
f83012
         g_debug ("GdmDisplay: Preparing display: %s", self->priv->id);
f83012
 
f83012
         /* FIXME: we should probably do this in a more global place,
f83012
          * asynchronously
f83012
          */
f83012
         look_for_existing_users_sync (self);
f83012
 
f83012
         self->priv->doing_initial_setup = wants_initial_setup (self);
f83012
 
f83012
         g_object_ref (self);
f83012
         ret = GDM_DISPLAY_GET_CLASS (self)->prepare (self);
f83012
         g_object_unref (self);
f83012
 
f83012
         return ret;
f83012
 }
f83012
 
f83012
 gboolean
f83012
 gdm_display_manage (GdmDisplay *self)
f83012
 {
f83012
         gboolean res;
f83012
 
f83012
@@ -1332,61 +1322,60 @@ gdm_display_init (GdmDisplay *self)
f83012
 
f83012
         self->priv = GDM_DISPLAY_GET_PRIVATE (self);
f83012
 
f83012
         self->priv->creation_time = time (NULL);
f83012
         self->priv->server_timer = g_timer_new ();
f83012
 }
f83012
 
f83012
 static void
f83012
 gdm_display_finalize (GObject *object)
f83012
 {
f83012
         GdmDisplay *self;
f83012
 
f83012
         g_return_if_fail (object != NULL);
f83012
         g_return_if_fail (GDM_IS_DISPLAY (object));
f83012
 
f83012
         self = GDM_DISPLAY (object);
f83012
 
f83012
         g_return_if_fail (self->priv != NULL);
f83012
 
f83012
         g_debug ("GdmDisplay: Finalizing display: %s", self->priv->id);
f83012
         g_free (self->priv->id);
f83012
         g_free (self->priv->seat_id);
f83012
         g_free (self->priv->session_class);
f83012
         g_free (self->priv->remote_hostname);
f83012
         g_free (self->priv->x11_display_name);
f83012
         g_free (self->priv->x11_cookie);
f83012
 
f83012
         g_clear_object (&self->priv->display_skeleton);
f83012
         g_clear_object (&self->priv->object_skeleton);
f83012
         g_clear_object (&self->priv->connection);
f83012
-        g_clear_object (&self->priv->accountsservice_proxy);
f83012
 
f83012
         if (self->priv->access_file != NULL) {
f83012
                 g_object_unref (self->priv->access_file);
f83012
         }
f83012
 
f83012
         if (self->priv->user_access_file != NULL) {
f83012
                 g_object_unref (self->priv->user_access_file);
f83012
         }
f83012
 
f83012
         if (self->priv->server_timer != NULL) {
f83012
                 g_timer_destroy (self->priv->server_timer);
f83012
         }
f83012
 
f83012
         G_OBJECT_CLASS (gdm_display_parent_class)->finalize (object);
f83012
 }
f83012
 
f83012
 GDBusObjectSkeleton *
f83012
 gdm_display_get_object_skeleton (GdmDisplay *self)
f83012
 {
f83012
         return self->priv->object_skeleton;
f83012
 }
f83012
 
f83012
 static void
f83012
 on_launch_environment_session_opened (GdmLaunchEnvironment *launch_environment,
f83012
                                       GdmDisplay           *self)
f83012
 {
f83012
         char       *session_id;
f83012
 
f83012
         g_debug ("GdmDisplay: Greeter session opened");
f83012
         session_id = gdm_launch_environment_get_session_id (launch_environment);
f83012
-- 
f83012
2.21.0
f83012