[gdm/fix-btmp-accounting: 23/23] manager: Fix btmp record accounting




commit 46240824ed086d5f76a30bb30cf7b9ddc98518c0
Author: Ray Strode <rstrode redhat com>
Date:   Wed Oct 19 14:50:33 2022 -0400

    manager: Fix btmp record accounting
    
    Before a user logs in they don't have a display.
    
    btmp records currently need a display though, and they
    get written when the user can't log in.
    
    Furthermore, the display from X11 point of view is
    somewhat archaic. We use wayland by default now.
    
    In lieu of a display, this commit gives the btmp record
    the seat id instead.

 daemon/gdm-manager.c        | 11 +++++++++--
 daemon/gdm-session-record.c |  8 ++++++--
 2 files changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/daemon/gdm-manager.c b/daemon/gdm-manager.c
index 1c8e59924..de3ac966f 100644
--- a/daemon/gdm-manager.c
+++ b/daemon/gdm-manager.c
@@ -653,13 +653,14 @@ add_session_record (GdmManager    *manager,
                     SessionRecord  record)
 {
         const char *username;
-        char *display_name, *hostname, *display_device;
+        char *display_name, *hostname, *display_device, *display_seat_id;
         gboolean recorded = FALSE;
 
         display_name = NULL;
         username = NULL;
         hostname = NULL;
         display_device = NULL;
+        display_seat_id = NULL;
 
         username = gdm_session_get_username (session);
 
@@ -671,10 +672,15 @@ add_session_record (GdmManager    *manager,
                       "display-name", &display_name,
                       "display-hostname", &hostname,
                       "display-device", &display_device,
+                      "display-seat-id", &display_seat_id,
                       NULL);
 
         if (display_name == NULL && display_device == NULL) {
-                goto out;
+                if (display_seat_id == NULL)
+                        goto out;
+
+                display_name = g_strdup ("login screen");
+                display_device = g_strdup (display_seat_id);
         }
 
         switch (record) {
@@ -706,6 +712,7 @@ out:
         g_free (display_name);
         g_free (hostname);
         g_free (display_device);
+        g_free (display_seat_id);
 
         return recorded;
 }
diff --git a/daemon/gdm-session-record.c b/daemon/gdm-session-record.c
index 7719d0a86..310323b69 100644
--- a/daemon/gdm-session-record.c
+++ b/daemon/gdm-session-record.c
@@ -152,12 +152,16 @@ record_set_line (UTMP       *u,
          * but remove the "/dev/" prefix.  If no device, then use the
          * $DISPLAY value.
          */
-        if (display_device != NULL
-            && g_str_has_prefix (display_device, "/dev/")) {
+        if (display_device != NULL && g_str_has_prefix (display_device, "/dev/")) {
                 memccpy (u->ut_line,
                          display_device + strlen ("/dev/"),
                          '\0',
                          sizeof (u->ut_line));
+        } else if (display_device != NULL && g_str_has_prefix (display_device, "seat")) {
+                memccpy (u->ut_line,
+                         display_device,
+                         '\0',
+                         sizeof (u->ut_line));
         } else if (x11_display_name != NULL) {
                 memccpy (u->ut_line,
                          x11_display_name,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]