Blame SOURCES/0001-daemon-gdm-session-record.c-open-close-the-utmp-data.patch

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