|
|
795d2c |
From 086d68f24d984fb48e44aa16aa815825cd5ed0bc Mon Sep 17 00:00:00 2001
|
|
|
795d2c |
From: Jason Pleau <jason@jpleau.ca>
|
|
|
795d2c |
Date: Wed, 30 May 2018 21:48:22 -0400
|
|
|
795d2c |
Subject: [PATCH] daemon/gdm-session-record.c: open/close the utmp database
|
|
|
795d2c |
|
|
|
795d2c |
pututxline() was used without first opening the utxmp database and
|
|
|
795d2c |
without closing it, preventing the logout entry from being fully
|
|
|
795d2c |
committed.
|
|
|
795d2c |
|
|
|
795d2c |
This caused the number of logged-in users to increment after each login,
|
|
|
795d2c |
as logging out did not correctly remove the user login record from utmp.
|
|
|
795d2c |
|
|
|
795d2c |
This commit wraps pututxline() between setutxent() and endutxent(),
|
|
|
795d2c |
making sure that the login/logout operation are fully flushed.
|
|
|
795d2c |
|
|
|
795d2c |
Fixes #381
|
|
|
795d2c |
---
|
|
|
795d2c |
daemon/gdm-session-record.c | 4 ++++
|
|
|
795d2c |
1 file changed, 4 insertions(+)
|
|
|
795d2c |
|
|
|
795d2c |
diff --git a/daemon/gdm-session-record.c b/daemon/gdm-session-record.c
|
|
|
795d2c |
index 487f10047..d2df58873 100644
|
|
|
795d2c |
--- a/daemon/gdm-session-record.c
|
|
|
795d2c |
+++ b/daemon/gdm-session-record.c
|
|
|
795d2c |
@@ -186,104 +186,108 @@ gdm_session_record_login (GPid session_pid,
|
|
|
795d2c |
|
|
|
795d2c |
g_debug ("Writing login record");
|
|
|
795d2c |
|
|
|
795d2c |
#if defined(HAVE_UT_UT_TYPE)
|
|
|
795d2c |
session_record.ut_type = USER_PROCESS;
|
|
|
795d2c |
g_debug ("using ut_type USER_PROCESS");
|
|
|
795d2c |
#endif
|
|
|
795d2c |
|
|
|
795d2c |
record_set_timestamp (&session_record);
|
|
|
795d2c |
record_set_pid (&session_record, session_pid);
|
|
|
795d2c |
record_set_host (&session_record, x11_display_name, host_name);
|
|
|
795d2c |
record_set_line (&session_record, display_device, x11_display_name);
|
|
|
795d2c |
|
|
|
795d2c |
/* Handle wtmp */
|
|
|
795d2c |
g_debug ("Writing wtmp session record to " GDM_NEW_SESSION_RECORDS_FILE);
|
|
|
795d2c |
#if defined(HAVE_UPDWTMPX)
|
|
|
795d2c |
updwtmpx (GDM_NEW_SESSION_RECORDS_FILE, &session_record);
|
|
|
795d2c |
#elif defined(HAVE_UPDWTMP)
|
|
|
795d2c |
updwtmp (GDM_NEW_SESSION_RECORDS_FILE, &session_record);
|
|
|
795d2c |
#elif defined(HAVE_LOGWTMP) && defined(HAVE_UT_UT_HOST)
|
|
|
795d2c |
#if defined(HAVE_UT_UT_USER)
|
|
|
795d2c |
logwtmp (session_record.ut_line, session_record.ut_user, session_record.ut_host);
|
|
|
795d2c |
#elif defined(HAVE_UT_UT_NAME)
|
|
|
795d2c |
logwtmp (session_record.ut_line, session_record.ut_name, session_record.ut_host);
|
|
|
795d2c |
#endif
|
|
|
795d2c |
#endif
|
|
|
795d2c |
|
|
|
795d2c |
/* Handle utmp */
|
|
|
795d2c |
#if defined(HAVE_GETUTXENT)
|
|
|
795d2c |
g_debug ("Adding or updating utmp record for login");
|
|
|
795d2c |
+ setutxent();
|
|
|
795d2c |
pututxline (&session_record);
|
|
|
795d2c |
+ endutxent();
|
|
|
795d2c |
#elif defined(HAVE_LOGIN)
|
|
|
795d2c |
login (&session_record);
|
|
|
795d2c |
#endif
|
|
|
795d2c |
}
|
|
|
795d2c |
|
|
|
795d2c |
void
|
|
|
795d2c |
gdm_session_record_logout (GPid session_pid,
|
|
|
795d2c |
const char *user_name,
|
|
|
795d2c |
const char *host_name,
|
|
|
795d2c |
const char *x11_display_name,
|
|
|
795d2c |
const char *display_device)
|
|
|
795d2c |
{
|
|
|
795d2c |
UTMP session_record = { 0 };
|
|
|
795d2c |
|
|
|
795d2c |
if (x11_display_name == NULL)
|
|
|
795d2c |
x11_display_name = display_device;
|
|
|
795d2c |
|
|
|
795d2c |
g_debug ("Writing logout record");
|
|
|
795d2c |
|
|
|
795d2c |
#if defined(HAVE_UT_UT_TYPE)
|
|
|
795d2c |
session_record.ut_type = DEAD_PROCESS;
|
|
|
795d2c |
g_debug ("using ut_type DEAD_PROCESS");
|
|
|
795d2c |
#endif
|
|
|
795d2c |
|
|
|
795d2c |
record_set_timestamp (&session_record);
|
|
|
795d2c |
record_set_pid (&session_record, session_pid);
|
|
|
795d2c |
record_set_host (&session_record, x11_display_name, host_name);
|
|
|
795d2c |
record_set_line (&session_record, display_device, x11_display_name);
|
|
|
795d2c |
|
|
|
795d2c |
/* Handle wtmp */
|
|
|
795d2c |
g_debug ("Writing wtmp logout record to " GDM_NEW_SESSION_RECORDS_FILE);
|
|
|
795d2c |
#if defined(HAVE_UPDWTMPX)
|
|
|
795d2c |
updwtmpx (GDM_NEW_SESSION_RECORDS_FILE, &session_record);
|
|
|
795d2c |
#elif defined (HAVE_UPDWTMP)
|
|
|
795d2c |
updwtmp (GDM_NEW_SESSION_RECORDS_FILE, &session_record);
|
|
|
795d2c |
#elif defined(HAVE_LOGWTMP)
|
|
|
795d2c |
logwtmp (session_record.ut_line, "", "");
|
|
|
795d2c |
#endif
|
|
|
795d2c |
|
|
|
795d2c |
/* Handle utmp */
|
|
|
795d2c |
#if defined(HAVE_GETUTXENT)
|
|
|
795d2c |
g_debug ("Adding or updating utmp record for logout");
|
|
|
795d2c |
+ setutxent();
|
|
|
795d2c |
pututxline (&session_record);
|
|
|
795d2c |
+ endutxent();
|
|
|
795d2c |
#elif defined(HAVE_LOGOUT)
|
|
|
795d2c |
logout (session_record.ut_line);
|
|
|
795d2c |
#endif
|
|
|
795d2c |
}
|
|
|
795d2c |
|
|
|
795d2c |
void
|
|
|
795d2c |
gdm_session_record_failed (GPid session_pid,
|
|
|
795d2c |
const char *user_name,
|
|
|
795d2c |
const char *host_name,
|
|
|
795d2c |
const char *x11_display_name,
|
|
|
795d2c |
const char *display_device)
|
|
|
795d2c |
{
|
|
|
795d2c |
UTMP session_record = { 0 };
|
|
|
795d2c |
|
|
|
795d2c |
if (x11_display_name == NULL)
|
|
|
795d2c |
x11_display_name = display_device;
|
|
|
795d2c |
|
|
|
795d2c |
record_set_username (&session_record, user_name);
|
|
|
795d2c |
|
|
|
795d2c |
g_debug ("Writing failed session attempt record");
|
|
|
795d2c |
|
|
|
795d2c |
#if defined(HAVE_UT_UT_TYPE)
|
|
|
795d2c |
session_record.ut_type = USER_PROCESS;
|
|
|
795d2c |
g_debug ("using ut_type USER_PROCESS");
|
|
|
795d2c |
#endif
|
|
|
795d2c |
|
|
|
795d2c |
record_set_timestamp (&session_record);
|
|
|
795d2c |
record_set_pid (&session_record, session_pid);
|
|
|
795d2c |
record_set_host (&session_record, x11_display_name, host_name);
|
|
|
795d2c |
record_set_line (&session_record, display_device, x11_display_name);
|
|
|
795d2c |
--
|
|
|
795d2c |
2.17.1
|
|
|
795d2c |
|