From 38786d46a9738b5307988ebb9916080681250506 Mon Sep 17 00:00:00 2001 From: BLINDAUER Emmanuel Date: Tue, 26 Sep 2017 21:06:44 +0200 Subject: [PATCH] WIP utmp/wtmp - renamed the two files, including the header was conflicting with official headers - configure look for utmp/utmpx headers, wo we know which struct to use - reworked the usage for linux, works mostly (last still showing 'gone' for loggued users) --- configure.ac | 2 ++ sesman/Makefile.am | 2 ++ sesman/session.c | 1 + sesman/{utmp.c => sessionrecord.c} | 30 +++++++++++++++++------------- sesman/{utmp.h => sessionrecord.h} | 18 +++++++++++++++--- 5 files changed, 37 insertions(+), 16 deletions(-) rename sesman/{utmp.c => sessionrecord.c} (85%) rename sesman/{utmp.h => sessionrecord.h} (83%) diff --git a/configure.ac b/configure.ac index fdac5e00..635719df 100644 --- a/configure.ac +++ b/configure.ac @@ -321,6 +321,8 @@ AC_CHECK_HEADER([X11/extensions/Xrandr.h], [], [AC_MSG_ERROR([please install libxrandr-dev or libXrandr-devel])], [#include ]) +AC_CHECK_HEADERS(utmp.h utmpx.h) + CFLAGS="$save_CFLAGS" AC_SUBST([moduledir], '${libdir}/xrdp') diff --git a/sesman/Makefile.am b/sesman/Makefile.am index 7c4f1e63..b7fa117b 100644 --- a/sesman/Makefile.am +++ b/sesman/Makefile.am @@ -61,6 +61,8 @@ xrdp_sesman_SOURCES = \ sesman.h \ session.c \ session.h \ + sessionrecord.c \ + sessionrecord.h \ sig.c \ sig.h \ utmp.c \ diff --git a/sesman/session.c b/sesman/session.c index 89069278..8504db06 100644 --- a/sesman/session.c +++ b/sesman/session.c @@ -40,6 +40,7 @@ #include "sesman.h" #include "libscp_types.h" #include "xauth.h" +#include "sessionrecord.h" #include "xrdp_sockets.h" #include "utmp.h" diff --git a/sesman/utmp.c b/sesman/sessionrecord.c similarity index 85% rename from sesman/utmp.c rename to sesman/sessionrecord.c index ffef17d6..f833a829 100644 --- a/sesman/utmp.c +++ b/sesman/sessionrecord.c @@ -18,7 +18,7 @@ /** * - * @file utmp.c + * @file sessionrecord.c * @brief utmp/wtmp handling code * */ @@ -27,27 +27,26 @@ #include #endif -#include -#include +#include #include -#include #include +#include +#include +#include #include "log.h" #include "os_calls.h" +#include "sessionrecord.h" -#include -#include - -/* - * Prepare the utmpx struct and write it. +/* + * Prepare the utmp/ struct and write it. * this can handle login and logout at once with the 'state' parameter */ int add_xtmp_entry(int pid, const char *line, const char *user, const char *rhostname, short state) { - struct utmpx ut; + _utmp ut; struct timeval tv; memset (&ut, 0, sizeof (ut)); @@ -66,9 +65,14 @@ add_xtmp_entry(int pid, const char *line, const char *user, const char *rhostnam pututxline(&ut); endutxent (); - /* wtmp XXX hardcoded! */ - updwtmpx("/var/log/wtmp", &ut); - + /* wtmp XXX hardcoded! UTMPX_FILE pb def*/ +#ifdef HAVE_UTMPX_H + log_message(LOG_LEVEL_DEBUG, "HAVE_UTMPX_H"); + updwtmpx(_PATH_WTMP, &ut); +#elif defined(HAVE_UTMP_H) + log_message(LOG_LEVEL_DEBUG, "HAVE_UTMP_H"); + updwtmp("/var/log/wtmp", &ut); +#endif return 0; } diff --git a/sesman/utmp.h b/sesman/sessionrecord.h similarity index 83% rename from sesman/utmp.h rename to sesman/sessionrecord.h index f378ad8b..1dbe9e6e 100644 --- a/sesman/utmp.h +++ b/sesman/sessionrecord.h @@ -18,13 +18,25 @@ /** * - * @file utmp.h + * @file sessionrecord.h * @brief utmp/wtmp handling code * */ -#ifndef UTMP_H -#define UTMP_H +#ifndef SESSIONRECORD_H +#define SESSIONRECORD_H + + +#ifdef HAVE_UTMPX_H +#include +typedef struct utmpx _utmp; +#else +#include +typedef struct utmp _utmp; +#endif + + + #define XRDP_LINE_FORMAT "xrdp:%d" /**