Blame SOURCES/0002-manager-Fix-btmp-record-accounting.patch

4abf37
From 20725e4c65555178ed64a3cb77ee979ec98998f8 Mon Sep 17 00:00:00 2001
4abf37
From: Ray Strode <rstrode@redhat.com>
4abf37
Date: Wed, 19 Oct 2022 14:50:33 -0400
4abf37
Subject: [PATCH 2/2] manager: Fix btmp record accounting
4abf37
4abf37
Before a user logs in they don't have a display.
4abf37
4abf37
btmp records currently need a display though, and they
4abf37
get written when the user can't log in.
4abf37
4abf37
Furthermore, the display from X11 point of view is
4abf37
somewhat archaic. We use wayland by default now.
4abf37
4abf37
In lieu of a display, this commit gives the btmp record
4abf37
the seat id instead.
4abf37
---
4abf37
 daemon/gdm-manager.c        | 11 +++++++++--
4abf37
 daemon/gdm-session-record.c |  8 ++++++--
4abf37
 2 files changed, 15 insertions(+), 4 deletions(-)
4abf37
4abf37
diff --git a/daemon/gdm-manager.c b/daemon/gdm-manager.c
4abf37
index 4b62b8b1..c70248f3 100644
4abf37
--- a/daemon/gdm-manager.c
4abf37
+++ b/daemon/gdm-manager.c
4abf37
@@ -641,113 +641,120 @@ switch_to_compatible_user_session (GdmManager *manager,
4abf37
 
4abf37
         ret = TRUE;
4abf37
 
4abf37
  out:
4abf37
         return ret;
4abf37
 }
4abf37
 
4abf37
 static GdmDisplay *
4abf37
 get_display_for_user_session (GdmSession *session)
4abf37
 {
4abf37
         return g_object_get_data (G_OBJECT (session), "gdm-display");
4abf37
 }
4abf37
 
4abf37
 static GdmSession *
4abf37
 get_user_session_for_display (GdmDisplay *display)
4abf37
 {
4abf37
         if (display == NULL) {
4abf37
                 return NULL;
4abf37
         }
4abf37
 
4abf37
         return g_object_get_data (G_OBJECT (display), "gdm-user-session");
4abf37
 }
4abf37
 
4abf37
 static gboolean
4abf37
 add_session_record (GdmManager    *manager,
4abf37
                     GdmSession    *session,
4abf37
                     GPid           pid,
4abf37
                     SessionRecord  record)
4abf37
 {
4abf37
         const char *username;
4abf37
-        char *display_name, *hostname, *display_device;
4abf37
+        char *display_name, *hostname, *display_device, *display_seat_id;
4abf37
         gboolean recorded = FALSE;
4abf37
 
4abf37
         display_name = NULL;
4abf37
         username = NULL;
4abf37
         hostname = NULL;
4abf37
         display_device = NULL;
4abf37
+        display_seat_id = NULL;
4abf37
 
4abf37
         username = gdm_session_get_username (session);
4abf37
 
4abf37
         if (username == NULL) {
4abf37
                 goto out;
4abf37
         }
4abf37
 
4abf37
         g_object_get (G_OBJECT (session),
4abf37
                       "display-name", &display_name,
4abf37
                       "display-hostname", &hostname,
4abf37
                       "display-device", &display_device,
4abf37
+                      "display-seat-id", &display_seat_id,
4abf37
                       NULL);
4abf37
 
4abf37
         if (display_name == NULL && display_device == NULL) {
4abf37
-                goto out;
4abf37
+                if (display_seat_id == NULL)
4abf37
+                        goto out;
4abf37
+
4abf37
+                display_name = g_strdup ("login screen");
4abf37
+                display_device = g_strdup (display_seat_id);
4abf37
         }
4abf37
 
4abf37
         switch (record) {
4abf37
             case SESSION_RECORD_LOGIN:
4abf37
                 gdm_session_record_login (pid,
4abf37
                                           username,
4abf37
                                           hostname,
4abf37
                                           display_name,
4abf37
                                           display_device);
4abf37
                 break;
4abf37
             case SESSION_RECORD_LOGOUT:
4abf37
                 gdm_session_record_logout (pid,
4abf37
                                            username,
4abf37
                                            hostname,
4abf37
                                            display_name,
4abf37
                                            display_device);
4abf37
                 break;
4abf37
             case SESSION_RECORD_FAILED:
4abf37
                 gdm_session_record_failed (pid,
4abf37
                                            username,
4abf37
                                            hostname,
4abf37
                                            display_name,
4abf37
                                            display_device);
4abf37
                 break;
4abf37
         }
4abf37
 
4abf37
         recorded = TRUE;
4abf37
 out:
4abf37
         g_free (display_name);
4abf37
         g_free (hostname);
4abf37
         g_free (display_device);
4abf37
+        g_free (display_seat_id);
4abf37
 
4abf37
         return recorded;
4abf37
 }
4abf37
 
4abf37
 static GdmSession *
4abf37
 find_user_session_for_display (GdmManager *self,
4abf37
                                GdmDisplay *display)
4abf37
 {
4abf37
 
4abf37
         GList *node = self->priv->user_sessions;
4abf37
 
4abf37
         while (node != NULL) {
4abf37
                 GdmSession *session = node->data;
4abf37
                 GdmDisplay *candidate_display;
4abf37
                 GList *next_node = node->next;
4abf37
 
4abf37
                 candidate_display = get_display_for_user_session (session);
4abf37
 
4abf37
                 if (candidate_display == display)
4abf37
                         return session;
4abf37
 
4abf37
                 node = next_node;
4abf37
         }
4abf37
 
4abf37
         return NULL;
4abf37
 }
4abf37
 
4abf37
 static gboolean
4abf37
 gdm_manager_handle_register_display (GdmDBusManager        *manager,
4abf37
                                      GDBusMethodInvocation *invocation,
4abf37
diff --git a/daemon/gdm-session-record.c b/daemon/gdm-session-record.c
4abf37
index 7719d0a8..310323b6 100644
4abf37
--- a/daemon/gdm-session-record.c
4abf37
+++ b/daemon/gdm-session-record.c
4abf37
@@ -125,66 +125,70 @@ record_set_host (UTMP       *u,
4abf37
          */
4abf37
         if (host_name != NULL
4abf37
             && x11_display_name != NULL
4abf37
             && g_str_has_prefix (x11_display_name, ":")) {
4abf37
                 hostname = g_strdup_printf ("%s%s", host_name, x11_display_name);
4abf37
         } else {
4abf37
                 hostname = g_strdup (x11_display_name);
4abf37
         }
4abf37
 
4abf37
         if (hostname != NULL) {
4abf37
                 memccpy (u->ut_host, hostname, '\0', sizeof (u->ut_host));
4abf37
                 g_debug ("using ut_host %.*s", (int) sizeof (u->ut_host), u->ut_host);
4abf37
 #ifdef HAVE_UT_UT_SYSLEN
4abf37
                 u->ut_syslen = MIN (strlen (hostname), sizeof (u->ut_host));
4abf37
 #endif
4abf37
                 g_free (hostname);
4abf37
         }
4abf37
 #endif
4abf37
 }
4abf37
 
4abf37
 static void
4abf37
 record_set_line (UTMP       *u,
4abf37
                  const char *display_device,
4abf37
                  const char *x11_display_name)
4abf37
 {
4abf37
         /*
4abf37
          * Set ut_line to the device name associated with this display
4abf37
          * but remove the "/dev/" prefix.  If no device, then use the
4abf37
          * $DISPLAY value.
4abf37
          */
4abf37
-        if (display_device != NULL
4abf37
-            && g_str_has_prefix (display_device, "/dev/")) {
4abf37
+        if (display_device != NULL && g_str_has_prefix (display_device, "/dev/")) {
4abf37
                 memccpy (u->ut_line,
4abf37
                          display_device + strlen ("/dev/"),
4abf37
                          '\0',
4abf37
                          sizeof (u->ut_line));
4abf37
+        } else if (display_device != NULL && g_str_has_prefix (display_device, "seat")) {
4abf37
+                memccpy (u->ut_line,
4abf37
+                         display_device,
4abf37
+                         '\0',
4abf37
+                         sizeof (u->ut_line));
4abf37
         } else if (x11_display_name != NULL) {
4abf37
                 memccpy (u->ut_line,
4abf37
                          x11_display_name,
4abf37
                          '\0',
4abf37
                          sizeof (u->ut_line));
4abf37
         }
4abf37
 
4abf37
         g_debug ("using ut_line %.*s", (int) sizeof (u->ut_line), u->ut_line);
4abf37
 }
4abf37
 
4abf37
 void
4abf37
 gdm_session_record_login (GPid                  session_pid,
4abf37
                           const char           *user_name,
4abf37
                           const char           *host_name,
4abf37
                           const char           *x11_display_name,
4abf37
                           const char           *display_device)
4abf37
 {
4abf37
         UTMP        session_record = { 0 };
4abf37
 
4abf37
         if (x11_display_name == NULL)
4abf37
                 x11_display_name = display_device;
4abf37
 
4abf37
         record_set_username (&session_record, user_name);
4abf37
 
4abf37
         g_debug ("Writing login record");
4abf37
 
4abf37
 #if defined(HAVE_UT_UT_TYPE)
4abf37
         session_record.ut_type = USER_PROCESS;
4abf37
         g_debug ("using ut_type USER_PROCESS");
4abf37
 #endif
4abf37
-- 
4abf37
2.31.1
4abf37