Fix btmp accounting

Resolves: #2073275
This commit is contained in:
Ray Strode 2022-11-02 10:46:16 -04:00
parent a90e4d6a65
commit 36f981b7ae
5 changed files with 247 additions and 14 deletions

View File

@ -0,0 +1,227 @@
From d9dd381a574a02b239438db4fcc9d6ac2fd82ee0 Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Wed, 19 Oct 2022 14:50:33 -0400
Subject: [PATCH] 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 cc61efc9..e1bc62d7 100644
--- a/daemon/gdm-manager.c
+++ b/daemon/gdm-manager.c
@@ -628,113 +628,120 @@ switch_to_compatible_user_session (GdmManager *manager,
ret = TRUE;
out:
return ret;
}
static GdmDisplay *
get_display_for_user_session (GdmSession *session)
{
return g_object_get_data (G_OBJECT (session), "gdm-display");
}
static GdmSession *
get_user_session_for_display (GdmDisplay *display)
{
if (display == NULL) {
return NULL;
}
return g_object_get_data (G_OBJECT (display), "gdm-user-session");
}
static gboolean
add_session_record (GdmManager *manager,
GdmSession *session,
GPid pid,
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);
if (username == NULL) {
goto out;
}
g_object_get (G_OBJECT (session),
"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) {
case SESSION_RECORD_LOGIN:
gdm_session_record_login (pid,
username,
hostname,
display_name,
display_device);
break;
case SESSION_RECORD_LOGOUT:
gdm_session_record_logout (pid,
username,
hostname,
display_name,
display_device);
break;
case SESSION_RECORD_FAILED:
gdm_session_record_failed (pid,
username,
hostname,
display_name,
display_device);
break;
}
recorded = TRUE;
out:
g_free (display_name);
g_free (hostname);
g_free (display_device);
+ g_free (display_seat_id);
return recorded;
}
static GdmSession *
find_user_session_for_display (GdmManager *self,
GdmDisplay *display)
{
GList *node = self->priv->user_sessions;
while (node != NULL) {
GdmSession *session = node->data;
GdmDisplay *candidate_display;
GList *next_node = node->next;
candidate_display = get_display_for_user_session (session);
if (candidate_display == display)
return session;
node = next_node;
}
return NULL;
}
static gboolean
gdm_manager_handle_register_display (GdmDBusManager *manager,
GDBusMethodInvocation *invocation,
diff --git a/daemon/gdm-session-record.c b/daemon/gdm-session-record.c
index 7719d0a8..310323b6 100644
--- a/daemon/gdm-session-record.c
+++ b/daemon/gdm-session-record.c
@@ -125,66 +125,70 @@ record_set_host (UTMP *u,
*/
if (host_name != NULL
&& x11_display_name != NULL
&& g_str_has_prefix (x11_display_name, ":")) {
hostname = g_strdup_printf ("%s%s", host_name, x11_display_name);
} else {
hostname = g_strdup (x11_display_name);
}
if (hostname != NULL) {
memccpy (u->ut_host, hostname, '\0', sizeof (u->ut_host));
g_debug ("using ut_host %.*s", (int) sizeof (u->ut_host), u->ut_host);
#ifdef HAVE_UT_UT_SYSLEN
u->ut_syslen = MIN (strlen (hostname), sizeof (u->ut_host));
#endif
g_free (hostname);
}
#endif
}
static void
record_set_line (UTMP *u,
const char *display_device,
const char *x11_display_name)
{
/*
* Set ut_line to the device name associated with this display
* 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,
'\0',
sizeof (u->ut_line));
}
g_debug ("using ut_line %.*s", (int) sizeof (u->ut_line), u->ut_line);
}
void
gdm_session_record_login (GPid session_pid,
const char *user_name,
const char *host_name,
const char *x11_display_name,
const char *display_device)
{
UTMP session_record = { 0 };
if (x11_display_name == NULL)
x11_display_name = display_device;
record_set_username (&session_record, user_name);
g_debug ("Writing login record");
#if defined(HAVE_UT_UT_TYPE)
session_record.ut_type = USER_PROCESS;
g_debug ("using ut_type USER_PROCESS");
#endif
--
2.37.3

View File

@ -1,4 +1,4 @@
From 2e7965beae81e0e93d3f475f2ea29a7af6c23f29 Mon Sep 17 00:00:00 2001
From 58f2bb3560f1066d0cda93a749a6d1648e3c3d0c Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Thu, 20 Dec 2018 14:51:38 -0500
Subject: [PATCH 1/3] manager: allow multiple xdmcp logins for the same user
@ -53,7 +53,7 @@ index 87685d3c..4b3a1ffe 100644
#endif /* _GDM_SETTINGS_KEYS_H */
diff --git a/daemon/gdm-manager.c b/daemon/gdm-manager.c
index cc61efc9..dc839aeb 100644
index e1bc62d7..08c3cc17 100644
--- a/daemon/gdm-manager.c
+++ b/daemon/gdm-manager.c
@@ -566,93 +566,106 @@ get_display_and_details_for_bus_sender (GdmManager *self,
@ -180,8 +180,8 @@ index cc61efc9..dc839aeb 100644
SessionRecord record)
{
const char *username;
char *display_name, *hostname, *display_device;
@@ -1089,92 +1102,114 @@ open_temporary_reauthentication_channel (GdmManager *self,
char *display_name, *hostname, *display_device, *display_seat_id;
@@ -1096,92 +1109,114 @@ open_temporary_reauthentication_channel (GdmManager *self,
g_signal_connect (session,
"client-disconnected",
G_CALLBACK (on_reauthentication_client_disconnected),
@ -340,5 +340,5 @@ index a1035f95..929d13d9 100644
</gdmschemafile>
--
2.32.0
2.37.3

View File

@ -1,4 +1,4 @@
From 618dfea6563d4f0bad0583b38b63746e44969d5e Mon Sep 17 00:00:00 2001
From ea1de1173b46f76fe00b4f52b2b71ad16e35acc3 Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Wed, 5 Feb 2020 15:20:48 -0500
Subject: [PATCH 2/3] gdm-x-session: run session bus on non-seat0 seats
@ -147,5 +147,5 @@ index a65fa0f9..f13b54af 100644
self->selected_program);
}
--
2.32.0
2.37.3

View File

@ -1,4 +1,4 @@
From f30e557a8afcdfe5d571a625b4c99606315ed3b4 Mon Sep 17 00:00:00 2001
From 73ccd50cabda8102b724d9bf647ac5a74963040d Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Mon, 11 Feb 2019 10:32:55 -0500
Subject: [PATCH 3/3] session: ensure login screen over XDMCP connects to its
@ -101,5 +101,5 @@ index f13b54af..9f68166e 100644
gpointer key, value;
--
2.32.0
2.37.3

View File

@ -11,7 +11,7 @@
Name: gdm
Epoch: 1
Version: 40.1
Release: 17%{?dist}
Release: 18%{?dist}
Summary: The GNOME Display Manager
License: GPLv2+
@ -40,11 +40,13 @@ Patch50002: 0002-daemon-Support-X-servers-built-with-Dlisten_tcp-true.patch
Patch60001: 0001-session-settings-Fetch-session-from-user-even-if-use.patch
Patch70001: 0001-manager-Fix-btmp-record-accounting.patch
# Latest udev rules and support code
Patch70001: 0001-local-display-factory-Stall-startup-until-main-graph.patch
Patch70002: 0002-common-Add-API-to-reload-settings-from-disk.patch
Patch70003: 0003-common-Reload-settings-when-graphics-initialize.patch
Patch70004: 0004-data-Use-latest-upstream-udev-rules.patch
Patch90001: 0001-local-display-factory-Stall-startup-until-main-graph.patch
Patch90002: 0002-common-Add-API-to-reload-settings-from-disk.patch
Patch90003: 0003-common-Reload-settings-when-graphics-initialize.patch
Patch90004: 0004-data-Use-latest-upstream-udev-rules.patch
# Non-upstreamable workarounds
Patch66610001: 0001-data-reap-gdm-sessions-on-shutdown.patch
@ -345,6 +347,10 @@ dconf update || :
%{_libdir}/pkgconfig/gdm-pam-extensions.pc
%changelog
* Wed Nov 02 2022 Ray Strode <rstrode@redhat.com> - 40.1-18
- Fix btmp accounting
Resolves: #2073275
* Thu Sep 29 2022 Ray Strode <rstrode@redhat.com> - 40.1-17
- Disable Wayland on aspeed
Related: #2097308