head 1.1; access; symbols pkgsrc-2026Q1:1.1.0.40 pkgsrc-2026Q1-base:1.1 pkgsrc-2025Q4:1.1.0.38 pkgsrc-2025Q4-base:1.1 pkgsrc-2025Q3:1.1.0.36 pkgsrc-2025Q3-base:1.1 pkgsrc-2025Q2:1.1.0.34 pkgsrc-2025Q2-base:1.1 pkgsrc-2025Q1:1.1.0.32 pkgsrc-2025Q1-base:1.1 pkgsrc-2024Q4:1.1.0.30 pkgsrc-2024Q4-base:1.1 pkgsrc-2024Q3:1.1.0.28 pkgsrc-2024Q3-base:1.1 pkgsrc-2024Q2:1.1.0.26 pkgsrc-2024Q2-base:1.1 pkgsrc-2024Q1:1.1.0.24 pkgsrc-2024Q1-base:1.1 pkgsrc-2023Q4:1.1.0.22 pkgsrc-2023Q4-base:1.1 pkgsrc-2023Q3:1.1.0.20 pkgsrc-2023Q3-base:1.1 pkgsrc-2023Q2:1.1.0.18 pkgsrc-2023Q2-base:1.1 pkgsrc-2023Q1:1.1.0.16 pkgsrc-2023Q1-base:1.1 pkgsrc-2022Q4:1.1.0.14 pkgsrc-2022Q4-base:1.1 pkgsrc-2022Q3:1.1.0.12 pkgsrc-2022Q3-base:1.1 pkgsrc-2022Q2:1.1.0.10 pkgsrc-2022Q2-base:1.1 pkgsrc-2022Q1:1.1.0.8 pkgsrc-2022Q1-base:1.1 pkgsrc-2021Q4:1.1.0.6 pkgsrc-2021Q4-base:1.1 pkgsrc-2021Q3:1.1.0.4 pkgsrc-2021Q3-base:1.1 pkgsrc-2021Q2:1.1.0.2 pkgsrc-2021Q2-base:1.1; locks; strict; comment @# @; 1.1 date 2021.04.16.13.57.52; author cirnatdan; state Exp; branches; next ; commitid 6rs8yYxeYRqruwPC; desc @@ 1.1 log @x11/libgdm: import libgdm-40.0 The GNOME Display Manager is a system service that is responsible for providing graphical log-ins and managing local and remote displays. This package installs libgdm, which is the client part of GDM. @ text @$NetBSD$ $OpenBSD: patch-daemon_gdm-session-record_c,v 1.11 2019/11/02 15:34:07 ajacoutot Exp $ https://bugzilla.gnome.org/show_bug.cgi?id=722482 Index: daemon/gdm-session-record.c --- daemon/gdm-session-record.c.orig 2020-05-04 20:11:25.000000000 +0000 +++ daemon/gdm-session-record.c @@@@ -33,6 +33,16 @@@@ #include #endif +#if defined(HAVE_UTIL_H) +#include +#endif + +#if defined(HAVE_GETTTYENT) +#include /* open(2) */ +#include +static int fd = -1; +#endif + #include #include #include @@@@ -43,6 +53,9 @@@@ #define GDM_BAD_SESSION_RECORDS_FILE "/var/log/btmp" #endif +static void write_utmp_login_manually (struct utmp *ut); +static void write_utmp_logout_manually (char *); + #if !defined(GDM_NEW_SESSION_RECORDS_FILE) # if defined(WTMPX_FILE) # define GDM_NEW_SESSION_RECORDS_FILE WTMPX_FILE @@@@ -168,6 +181,84 @@@@ record_set_line (UTMP *u, g_debug ("using ut_line %.*s", (int) sizeof (u->ut_line), u->ut_line); } +static void +write_utmp_login_manually (struct utmp *ut) +{ +#if defined(HAVE_GETTTYENT) && defined(HAVE_UTMP_H) + UTMP ubuf; + int topslot = -1; + + g_debug ("Adding new utmp record"); + + /* + * First, loop through /etc/ttys, if needed, to initialize the + * top of the tty slots, since gdm has no tty. + */ + if (topslot < 0) { + topslot = 0; + while (getttyent () != (struct ttyent *) NULL) + topslot++; + } + if ((topslot < 0) || ((fd < 0) && + (fd = open (_PATH_UTMP, O_RDWR|O_CREAT, 0644)) < 0)) + return; + + /* + * Now find a slot that's not in use... + */ + (void) lseek (fd, (off_t) (topslot * sizeof (struct utmp)), SEEK_SET); + + while (1) { + if (read (fd, &ubuf, sizeof (struct utmp)) == + sizeof (struct utmp)) { + if (!ubuf.ut_name[0]) { + (void) lseek (fd, -(off_t) sizeof (struct utmp), + SEEK_CUR); + break; + } + topslot++; + } else { + (void) lseek (fd, (off_t) (topslot * + sizeof (struct utmp)), SEEK_SET); + break; + } + } + + (void) write (fd, ut, sizeof (struct utmp)); +#endif +} + +static void +write_utmp_logout_manually (char *line) +{ +#if defined(HAVE_GETTTYENT) && defined(HAVE_UTMP_H) && !defined(HAVE_GETUTXENT) + int rval = 1; + struct timeval tv; + UTMP ut; + + g_debug ("Removing utmp record"); + + if (fd >= 0) { + (void) lseek (fd, 0, SEEK_SET); + while (read (fd, &ut, sizeof (struct utmp)) == sizeof (struct utmp)) { + if (!ut.ut_name[0] || + strncmp (ut.ut_line, line, UT_LINESIZE)) + continue; + bzero (ut.ut_name, UT_NAMESIZE); + bzero (ut.ut_host, UT_HOSTSIZE); + gettimeofday (&tv, NULL); + ut.ut_time = tv.tv_sec; + (void) lseek (fd, -(off_t) sizeof (struct utmp), SEEK_CUR); + (void) write (fd, &ut, sizeof (struct utmp)); + rval = 0; + } + } + + if (rval != 0) + g_debug ("Failed to remove utmp record"); +#endif +} + void gdm_session_record_login (GPid session_pid, const char *user_name, @@@@ -214,8 +305,9 @@@@ gdm_session_record_login (GPid setutxent(); pututxline (&session_record); endutxent(); -#elif defined(HAVE_LOGIN) - login (&session_record); +#else + if (strcmp (session_record.ut_name, "(unknown)") != 0) + write_utmp_login_manually (&session_record); #endif } @@@@ -259,8 +351,8 @@@@ gdm_session_record_logout (GPid setutxent(); pututxline (&session_record); endutxent(); -#elif defined(HAVE_LOGOUT) - logout (session_record.ut_line); +#else + write_utmp_logout_manually (session_record.ut_line); #endif } @