Compare commits

...

16 Commits
devel ... wtmp

Author SHA1 Message Date
BLINDAUER Emmanuel
4ff49d0ae3
Move some definitions, and small fixes 2018-08-02 09:02:07 +09:00
BLINDAUER Emmanuel
0041228b72
More g_* functions usage
Follow coding standard
2018-08-02 09:02:07 +09:00
BLINDAUER Emmanuel
3ef2e5f7ff
don't forget a free
use g_*
2018-08-02 09:02:07 +09:00
BLINDAUER Emmanuel
c61ea8df9e
Extract the exact ip from the client_ip 2018-08-02 09:02:07 +09:00
Blindauer Emmanuel
8fc741ea45
Add support for FreeBSD 2018-08-02 09:02:07 +09:00
BLINDAUER Emmanuel
7d8f7c14b5
Add the loginuid pam module, as we are starting a session.
So /proc/<uid>/loginuid will be filled by the uid of the user.
This will fix entries in 'last' with "gone - no logout" instead of
'still logged in'
2018-08-02 09:02:07 +09:00
Koichiro IWAO
8493e08667
cosmetic changes 2018-08-02 09:02:07 +09:00
Koichiro IWAO
844799049e
Include sys/time.h to use gettimeofday() 2018-08-02 09:02:07 +09:00
BLINDAUER Emmanuel
8085d898b0
Remove utmp.{c,h} 2018-08-02 09:02:07 +09:00
BLINDAUER Emmanuel
016037a0be
Add GNU_SOURCE to configure.ac: it allow usage f more GNU functions,
like updwtmpx
2018-08-02 09:02:07 +09:00
BLINDAUER Emmanuel
38786d46a9
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)
2018-08-02 09:02:07 +09:00
Koichiro IWAO
ae31066bcd
os_calls.h needs to be included to use g_snprintf() 2018-08-02 09:02:07 +09:00
Koichiro IWAO
db86911365
don't forget include utmp.h 2018-08-02 09:02:07 +09:00
Koichiro IWAO
477852a1eb
sesman: add utmp files to makefile 2018-08-02 09:02:07 +09:00
Koichiro IWAO
42c0ff4d3d
remove trailing space 2018-08-02 09:02:06 +09:00
BLINDAUER Emmanuel
9d6537ae2a
Initial support for utmp/wtmp on linux 2018-08-02 09:02:03 +09:00
8 changed files with 221 additions and 1 deletions

View File

@ -5,6 +5,7 @@ AC_INIT([xrdp], [0.9.7], [xrdp-devel@googlegroups.com])
AC_CONFIG_HEADERS(config_ac.h:config_ac-h.in) AC_CONFIG_HEADERS(config_ac.h:config_ac-h.in)
AM_INIT_AUTOMAKE([1.7.2 foreign]) AM_INIT_AUTOMAKE([1.7.2 foreign])
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])
AC_GNU_SOURCE
AC_PROG_CC AC_PROG_CC
AC_C_CONST AC_C_CONST
AC_PROG_LIBTOOL AC_PROG_LIBTOOL
@ -321,6 +322,8 @@ AC_CHECK_HEADER([X11/extensions/Xrandr.h], [],
[AC_MSG_ERROR([please install libxrandr-dev or libXrandr-devel])], [AC_MSG_ERROR([please install libxrandr-dev or libXrandr-devel])],
[#include <X11/Xlib.h>]) [#include <X11/Xlib.h>])
AC_CHECK_HEADERS(utmp.h utmpx.h)
CFLAGS="$save_CFLAGS" CFLAGS="$save_CFLAGS"
AC_SUBST([moduledir], '${libdir}/xrdp') AC_SUBST([moduledir], '${libdir}/xrdp')

View File

@ -1,5 +1,8 @@
#%PAM-1.0 #%PAM-1.0
@include common-auth @include common-auth
@include common-account @include common-account
# Set the loginuid process attribute.
session required pam_loginuid.so
@include common-session @include common-session
@include common-password @include common-password

View File

@ -1,5 +1,8 @@
#%PAM-1.0 #%PAM-1.0
auth include password-auth auth include password-auth
account include password-auth account include password-auth
# Set the loginuid process attribute.
session required pam_loginuid.so
session include password-auth session include password-auth
password include password-auth password include password-auth

View File

@ -1,5 +1,8 @@
#%PAM-1.0 #%PAM-1.0
auth include common-auth auth include common-auth
account include common-account account include common-account
# Set the loginuid process attribute.
session required pam_loginuid.so
session include common-session session include common-session
password include common-password password include common-password

View File

@ -61,6 +61,8 @@ xrdp_sesman_SOURCES = \
sesman.h \ sesman.h \
session.c \ session.c \
session.h \ session.h \
sessionrecord.c \
sessionrecord.h \
sig.c \ sig.c \
sig.h \ sig.h \
xauth.c \ xauth.c \

View File

@ -40,6 +40,7 @@
#include "sesman.h" #include "sesman.h"
#include "libscp_types.h" #include "libscp_types.h"
#include "xauth.h" #include "xauth.h"
#include "sessionrecord.h"
#include "xrdp_sockets.h" #include "xrdp_sockets.h"
#ifndef PR_SET_NO_NEW_PRIVS #ifndef PR_SET_NO_NEW_PRIVS
@ -520,6 +521,7 @@ session_start_fork(tbus data, tui8 type, struct SCP_CONNECTION *c,
*/ */
} }
#endif #endif
utmp_login(g_getpid(), display, s->username, s->client_ip);
window_manager_pid = g_fork(); /* parent becomes X, window_manager_pid = g_fork(); /* parent becomes X,
child forks wm, and waits, todo */ child forks wm, and waits, todo */
if (window_manager_pid == -1) if (window_manager_pid == -1)
@ -942,8 +944,8 @@ session_kill(int pid)
{ {
/* deleting the session */ /* deleting the session */
log_message(LOG_LEVEL_INFO, "++ terminated session: username %s, display :%d.0, session_pid %d, ip %s", tmp->item->name, tmp->item->display, tmp->item->pid, tmp->item->client_ip); log_message(LOG_LEVEL_INFO, "++ terminated session: username %s, display :%d.0, session_pid %d, ip %s", tmp->item->name, tmp->item->display, tmp->item->pid, tmp->item->client_ip);
utmp_logout(tmp->item->pid, tmp->item->display, tmp->item->name, tmp->item->client_ip);
g_free(tmp->item); g_free(tmp->item);
if (prev == 0) if (prev == 0)
{ {
/* prev does no exist, so it's the first element - so we set /* prev does no exist, so it's the first element - so we set

165
sesman/sessionrecord.c Normal file
View File

@ -0,0 +1,165 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Emmanuel Blindauer 2017
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
*
* @file sessionrecord.c
* @brief utmp/wtmp handling code
* Idea: Only implement actual utmp, i.e. utmpx for 99%.
* See http://80386.nl/unix/utmpx/
*/
#if defined(HAVE_CONFIG_H)
#include <config_ac.h>
#endif
#include <paths.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
#include "log.h"
#include "os_calls.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"
/*
* 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
*/
void
add_xtmp_entry(int pid, const char *display_id, const char *user, const char *rhostname, const short state)
{
_utmp ut;
struct timeval tv;
char *hostname = 0;
/* The string rhostname containt too much data, only get the ip
* the format is
* "2001:123:12:1234:1234:1234:1234:1234:53194 - socket: 12"
* "::ffff:99.99.9.999:51165 - socket: 12"
* "99.99.9.999:51165 - socket: 12"
*
* So the IP is the string up the two last colons
*/
int i = g_strlen(rhostname) - 1;
while ((i > 0) && (rhostname[i] != ':'))
{
i--;
}
i--;
while ((i > 0) && (rhostname[i] != ':'))
{
i--;
}
hostname = g_strndup(rhostname, i);
g_memset(&ut, 0, sizeof(ut));
ut.ut_type = state;
ut.ut_pid = pid;
gettimeofday(&tv, NULL);
ut.ut_tv.tv_sec = tv.tv_sec;
ut.ut_tv.tv_usec = tv.tv_usec;
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_host, hostname, sizeof(ut.ut_host));
/* update the utmp file */
/* open utmp */
setutxent();
/* add the computed entry */
pututxline(&ut);
/* closes utmp */
endutxent();
/* update the wtmp file if needed */
_updwtmp(&ut);
g_free(hostname);
}
void
utmp_login(int pid, int display, const char *user, const char *rhostname)
{
char str_display[16];
log_message(LOG_LEVEL_DEBUG,
"adding login info for utmp/wtmp: %d - %d - %s - %s",
pid, display, user, rhostname);
g_snprintf(str_display, 15, XRDP_LINE_FORMAT, display);
add_xtmp_entry(pid, str_display, user, rhostname, USER_PROCESS);
}
void
utmp_logout(int pid, int display, const char *user, const char *rhostname)
{
char str_display[16];
log_message(LOG_LEVEL_DEBUG,
"adding logout info for utmp/wtmp: %d - %d - %s - %s",
pid, display, user, rhostname);
g_snprintf(str_display, 15, XRDP_LINE_FORMAT, display);
add_xtmp_entry(pid, str_display, user, rhostname, DEAD_PROCESS);
}

39
sesman/sessionrecord.h Normal file
View File

@ -0,0 +1,39 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Emmanuel Blindauer 2017
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
*
* @file sessionrecord.h
* @brief utmp/wtmp handling code
*
*/
#ifndef SESSIONRECORD_H
#define SESSIONRECORD_H
/**
* @brief functions for adding utmp entries. one at login, one for logout
*
* @param pid of the session, display, login, and hostname
*/
void utmp_login(int pid, int display, const char *user, const char *rhostname);
void utmp_logout(int pid, int display, const char *user, const char *rhostname);
#endif