From bacda8049258f13e8085584f6ce3c2ed71c9bf1a 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/sesexec/Makefile.am | 4 +-- sesman/sesexec/session.c | 2 +- sesman/sesexec/{utmp.c => sessionrecord.c} | 30 ++++++++++++---------- sesman/sesexec/{utmp.h => sessionrecord.h} | 18 ++++++++++--- 5 files changed, 37 insertions(+), 19 deletions(-) rename sesman/sesexec/{utmp.c => sessionrecord.c} (85%) rename sesman/sesexec/{utmp.h => sessionrecord.h} (83%) diff --git a/configure.ac b/configure.ac index 6d0403a1..e62e83c2 100644 --- a/configure.ac +++ b/configure.ac @@ -514,6 +514,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" # perform unit tests if libcheck and libmocka found diff --git a/sesman/sesexec/Makefile.am b/sesman/sesexec/Makefile.am index e8740967..c270c4c0 100644 --- a/sesman/sesexec/Makefile.am +++ b/sesman/sesexec/Makefile.am @@ -25,8 +25,8 @@ xrdp_sesexec_SOURCES = \ env.h \ login_info.c \ login_info.h \ - utmp.c \ - utmp.h \ + sessionrecord.c \ + sessionrecord.h \ xauth.c \ xauth.h \ xwait.c \ diff --git a/sesman/sesexec/session.c b/sesman/sesexec/session.c index df7f9649..a54aa23e 100644 --- a/sesman/sesexec/session.c +++ b/sesman/sesexec/session.c @@ -47,8 +47,8 @@ #include "login_info.h" #include "os_calls.h" #include "sesexec.h" +#include "sessionrecord.h" #include "string_calls.h" -#include "utmp.h" #include "xauth.h" #include "xwait.h" #include "xrdp_sockets.h" diff --git a/sesman/sesexec/utmp.c b/sesman/sesexec/sessionrecord.c similarity index 85% rename from sesman/sesexec/utmp.c rename to sesman/sesexec/sessionrecord.c index ffef17d6..f833a829 100644 --- a/sesman/sesexec/utmp.c +++ b/sesman/sesexec/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/sesexec/utmp.h b/sesman/sesexec/sessionrecord.h similarity index 83% rename from sesman/sesexec/utmp.h rename to sesman/sesexec/sessionrecord.h index f378ad8b..1dbe9e6e 100644 --- a/sesman/sesexec/utmp.h +++ b/sesman/sesexec/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" /**