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

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