Move some definitions, and small fixes
This commit is contained in:
parent
0041228b72
commit
4ff49d0ae3
@ -40,13 +40,52 @@
|
|||||||
#include "os_calls.h"
|
#include "os_calls.h"
|
||||||
#include "sessionrecord.h"
|
#include "sessionrecord.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_UTMPX_H
|
||||||
|
#include <utmpx.h>
|
||||||
|
typedef struct utmpx _utmp;
|
||||||
|
#else
|
||||||
|
#include <utmpx.h>
|
||||||
|
typedef struct utmp _utmp;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define XRDP_LINE_FORMAT "xrdp:%d"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prepare the utmp/ struct and write it.
|
* update the wtmp file on UTMPX platforms (~ Linux)
|
||||||
|
* but no on FreeBSD : FreeBSD uses utx to do the job
|
||||||
|
*/
|
||||||
|
#ifdef HAVE_UTMPX_H
|
||||||
|
#if !defined(__FreeBSD__)
|
||||||
|
static inline void
|
||||||
|
_updwtmp(const _utmp *ut)
|
||||||
|
{
|
||||||
|
updwtmpx(_PATH_WTMP, ut);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static inline void
|
||||||
|
_updwtmp(const _utmp ut)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#elif defined(HAVE_UTMP_H)
|
||||||
|
/* Does such system still exist ? */
|
||||||
|
_updwtmp(const _utmp *ut)
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_DEBUG,
|
||||||
|
"Unsupported system: HAVE_UTMP_H defined without HAVE_UTMPX_H");
|
||||||
|
updwtmp("/var/log/wtmp", ut);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Prepare the utmp struct and write it.
|
||||||
* this can handle login and logout at once with the 'state' parameter
|
* this can handle login and logout at once with the 'state' parameter
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int
|
void
|
||||||
add_xtmp_entry(int pid, const char *line, const char *user, const char *rhostname, short state)
|
add_xtmp_entry(int pid, const char *display_id, const char *user, const char *rhostname, const short state)
|
||||||
{
|
{
|
||||||
_utmp ut;
|
_utmp ut;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
@ -61,12 +100,12 @@ add_xtmp_entry(int pid, const char *line, const char *user, const char *rhostnam
|
|||||||
* So the IP is the string up the two last colons
|
* So the IP is the string up the two last colons
|
||||||
*/
|
*/
|
||||||
int i = g_strlen(rhostname) - 1;
|
int i = g_strlen(rhostname) - 1;
|
||||||
while ((i>0) && (rhostname[i] != ':'))
|
while ((i > 0) && (rhostname[i] != ':'))
|
||||||
{
|
{
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
i--;
|
i--;
|
||||||
while ((i>0) && (rhostname[i] != ':'))
|
while ((i > 0) && (rhostname[i] != ':'))
|
||||||
{
|
{
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
@ -75,36 +114,31 @@ add_xtmp_entry(int pid, const char *line, const char *user, const char *rhostnam
|
|||||||
|
|
||||||
g_memset(&ut, 0, sizeof(ut));
|
g_memset(&ut, 0, sizeof(ut));
|
||||||
|
|
||||||
ut.ut_type=state;
|
ut.ut_type = state;
|
||||||
ut.ut_pid = pid;
|
ut.ut_pid = pid;
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
ut.ut_tv.tv_sec = tv.tv_sec;
|
ut.ut_tv.tv_sec = tv.tv_sec;
|
||||||
ut.ut_tv.tv_usec = tv.tv_usec;
|
ut.ut_tv.tv_usec = tv.tv_usec;
|
||||||
g_strncpy(ut.ut_line, line , sizeof(ut.ut_line));
|
g_strncpy(ut.ut_line, display_id , sizeof(ut.ut_line));
|
||||||
g_strncpy(ut.ut_user, user , sizeof(ut.ut_user));
|
g_strncpy(ut.ut_user, user , sizeof(ut.ut_user));
|
||||||
g_strncpy(ut.ut_host, hostname, sizeof(ut.ut_host));
|
g_strncpy(ut.ut_host, hostname, sizeof(ut.ut_host));
|
||||||
|
|
||||||
/* utmp */
|
/* update the utmp file */
|
||||||
|
/* open utmp */
|
||||||
setutxent();
|
setutxent();
|
||||||
|
/* add the computed entry */
|
||||||
pututxline(&ut);
|
pututxline(&ut);
|
||||||
|
/* closes utmp */
|
||||||
endutxent();
|
endutxent();
|
||||||
|
|
||||||
/* wtmp : update on linux, FreeBSD uses utx */
|
/* update the wtmp file if needed */
|
||||||
#ifdef HAVE_UTMPX_H
|
|
||||||
#if !defined(__FreeBSD__)
|
|
||||||
updwtmpx(_PATH_WTMP, &ut);
|
|
||||||
#endif
|
|
||||||
#elif defined(HAVE_UTMP_H)
|
|
||||||
/* Does such system still exist ? */
|
|
||||||
log_message(LOG_LEVEL_DEBUG, "HAVE_UTMP_H");
|
|
||||||
updwtmp("/var/log/wtmp", &ut);
|
|
||||||
#endif
|
|
||||||
g_free(hostname);
|
|
||||||
|
|
||||||
return 0;
|
_updwtmp(&ut);
|
||||||
|
|
||||||
|
g_free(hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
void
|
||||||
utmp_login(int pid, int display, const char *user, const char *rhostname)
|
utmp_login(int pid, int display, const char *user, const char *rhostname)
|
||||||
{
|
{
|
||||||
char str_display[16];
|
char str_display[16];
|
||||||
@ -114,10 +148,10 @@ utmp_login(int pid, int display, const char *user, const char *rhostname)
|
|||||||
pid, display, user, rhostname);
|
pid, display, user, rhostname);
|
||||||
g_snprintf(str_display, 15, XRDP_LINE_FORMAT, display);
|
g_snprintf(str_display, 15, XRDP_LINE_FORMAT, display);
|
||||||
|
|
||||||
return add_xtmp_entry(pid, str_display, user, rhostname, USER_PROCESS);
|
add_xtmp_entry(pid, str_display, user, rhostname, USER_PROCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
void
|
||||||
utmp_logout(int pid, int display, const char *user, const char *rhostname)
|
utmp_logout(int pid, int display, const char *user, const char *rhostname)
|
||||||
{
|
{
|
||||||
char str_display[16];
|
char str_display[16];
|
||||||
@ -127,5 +161,5 @@ utmp_logout(int pid, int display, const char *user, const char *rhostname)
|
|||||||
pid, display, user, rhostname);
|
pid, display, user, rhostname);
|
||||||
g_snprintf(str_display, 15, XRDP_LINE_FORMAT, display);
|
g_snprintf(str_display, 15, XRDP_LINE_FORMAT, display);
|
||||||
|
|
||||||
return add_xtmp_entry(pid, str_display, user, rhostname, DEAD_PROCESS);
|
add_xtmp_entry(pid, str_display, user, rhostname, DEAD_PROCESS);
|
||||||
}
|
}
|
||||||
|
@ -26,26 +26,14 @@
|
|||||||
#ifndef SESSIONRECORD_H
|
#ifndef SESSIONRECORD_H
|
||||||
#define SESSIONRECORD_H
|
#define SESSIONRECORD_H
|
||||||
|
|
||||||
#ifdef HAVE_UTMPX_H
|
|
||||||
#include <utmpx.h>
|
|
||||||
typedef struct utmpx _utmp;
|
|
||||||
#else
|
|
||||||
#include <utmpx.h>
|
|
||||||
typedef struct utmp _utmp;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define XRDP_LINE_FORMAT "xrdp:%d"
|
|
||||||
|
|
||||||
int add_xtmp_entry(int pid, const char *line, const char *user, const char *rhostname, short state);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief functions for adding utmp entries. one at login, one for logout
|
* @brief functions for adding utmp entries. one at login, one for logout
|
||||||
*
|
*
|
||||||
* @param pid of the session, display, login, and hostname
|
* @param pid of the session, display, login, and hostname
|
||||||
* @return 0
|
|
||||||
*/
|
*/
|
||||||
int utmp_login(int pid, int display, const char *user, const char *rhostname);
|
void utmp_login(int pid, int display, const char *user, const char *rhostname);
|
||||||
|
|
||||||
int utmp_logout(int pid, int display, const char *user, const char *rhostname);
|
void utmp_logout(int pid, int display, const char *user, const char *rhostname);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user