generic: drop libutempter support

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-01-26 17:01:48 +02:00
parent 504b2db6ee
commit 9b97882c3d
4 changed files with 77 additions and 105 deletions

View file

@ -93,43 +93,36 @@ if (UNIX)
set(UTIL_LIBRARY)
check_library_exists(utempter addToUtmp "" HAVE_ADDTOUTEMP)
check_include_files(utempter.h HAVE_UTEMPTER_H)
if (HAVE_ADDTOUTEMP AND HAVE_UTEMPTER_H)
set(HAVE_UTEMPTER 1)
set(UTEMPTER_LIBRARY utempter)
else (HAVE_ADDTOUTEMP AND HAVE_UTEMPTER_H)
check_function_exists(login login_in_libc)
if (NOT login_in_libc)
check_library_exists(util login "" login_in_libutil)
if (login_in_libutil)
set(UTIL_LIBRARY util)
endif (login_in_libutil)
endif (NOT login_in_libc)
if (CMAKE_SYSTEM_NAME MATCHES Linux OR CMAKE_SYSTEM_NAME MATCHES Darwin OR CMAKE_SYSTEM_NAME MATCHES GNU/FreeBSD OR CMAKE_SYSTEM_NAME STREQUAL GNU)
set (HAVE_UTMPX)
else (CMAKE_SYSTEM_NAME MATCHES Linux OR CMAKE_SYSTEM_NAME MATCHES Darwin OR CMAKE_SYSTEM_NAME MATCHES GNU/FreeBSD OR CMAKE_SYSTEM_NAME STREQUAL GNU)
check_function_exists(getutxent HAVE_UTMPX)
endif (CMAKE_SYSTEM_NAME MATCHES Linux OR CMAKE_SYSTEM_NAME MATCHES Darwin OR CMAKE_SYSTEM_NAME MATCHES GNU/FreeBSD OR CMAKE_SYSTEM_NAME STREQUAL GNU)
if (HAVE_UTMPX)
set(utmp utmpx)
if (login_in_libutil)
check_library_exists(util loginx "" HAVE_LOGINX)
endif (login_in_libutil)
else (HAVE_UTMPX)
set(utmp utmp)
endif (HAVE_UTMPX)
if (login_in_libc OR login_in_libutil)
set(HAVE_LOGIN 1)
else (login_in_libc OR login_in_libutil)
set(HAVE_LOGIN)
endif (login_in_libc OR login_in_libutil)
check_struct_has_member("struct ${utmp}" "ut_type" "${utmp}.h" HAVE_STRUCT_UTMP_UT_TYPE)
check_struct_has_member("struct ${utmp}" "ut_pid" "${utmp}.h" HAVE_STRUCT_UTMP_UT_PID)
check_struct_has_member("struct ${utmp}" "ut_session" "${utmp}.h" HAVE_STRUCT_UTMP_UT_SESSION)
check_struct_has_member("struct ${utmp}" "ut_syslen" "${utmp}.h" HAVE_STRUCT_UTMP_UT_SYSLEN)
check_struct_has_member("struct ${utmp}" "ut_id" "${utmp}.h" HAVE_STRUCT_UTMP_UT_ID)
endif (HAVE_ADDTOUTEMP AND HAVE_UTEMPTER_H)
check_function_exists(login login_in_libc)
if (NOT login_in_libc)
check_library_exists(util login "" login_in_libutil)
if (login_in_libutil)
set(UTIL_LIBRARY util)
endif (login_in_libutil)
endif (NOT login_in_libc)
if (CMAKE_SYSTEM_NAME MATCHES Linux OR CMAKE_SYSTEM_NAME MATCHES Darwin OR CMAKE_SYSTEM_NAME MATCHES GNU/FreeBSD OR CMAKE_SYSTEM_NAME STREQUAL GNU)
set (HAVE_UTMPX)
else (CMAKE_SYSTEM_NAME MATCHES Linux OR CMAKE_SYSTEM_NAME MATCHES Darwin OR CMAKE_SYSTEM_NAME MATCHES GNU/FreeBSD OR CMAKE_SYSTEM_NAME STREQUAL GNU)
check_function_exists(getutxent HAVE_UTMPX)
endif (CMAKE_SYSTEM_NAME MATCHES Linux OR CMAKE_SYSTEM_NAME MATCHES Darwin OR CMAKE_SYSTEM_NAME MATCHES GNU/FreeBSD OR CMAKE_SYSTEM_NAME STREQUAL GNU)
if (HAVE_UTMPX)
set(utmp utmpx)
if (login_in_libutil)
check_library_exists(util loginx "" HAVE_LOGINX)
endif (login_in_libutil)
else (HAVE_UTMPX)
set(utmp utmp)
endif (HAVE_UTMPX)
if (login_in_libc OR login_in_libutil)
set(HAVE_LOGIN 1)
else (login_in_libc OR login_in_libutil)
set(HAVE_LOGIN)
endif (login_in_libc OR login_in_libutil)
check_struct_has_member("struct ${utmp}" "ut_type" "${utmp}.h" HAVE_STRUCT_UTMP_UT_TYPE)
check_struct_has_member("struct ${utmp}" "ut_pid" "${utmp}.h" HAVE_STRUCT_UTMP_UT_PID)
check_struct_has_member("struct ${utmp}" "ut_session" "${utmp}.h" HAVE_STRUCT_UTMP_UT_SESSION)
check_struct_has_member("struct ${utmp}" "ut_syslen" "${utmp}.h" HAVE_STRUCT_UTMP_UT_SYSLEN)
check_struct_has_member("struct ${utmp}" "ut_id" "${utmp}.h" HAVE_STRUCT_UTMP_UT_ID)
check_function_exists(openpty openpty_in_libc)
if (NOT openpty_in_libc)

View file

@ -17,7 +17,6 @@
#cmakedefine HAVE_SYS_STROPTS_H 1
#cmakedefine HAVE_SYS_FILIO_H 1
#cmakedefine HAVE_UTEMPTER 1
#cmakedefine HAVE_LOGIN 1
#cmakedefine HAVE_UTMPX 1
#cmakedefine HAVE_LOGINX 1

View file

@ -12,7 +12,6 @@ add_library(kpty ${LIBRARY_TYPE} ${kpty_LIB_SRCS})
target_link_libraries(kpty PRIVATE
${UTIL_LIBRARY}
${UTEMPTER_LIBRARY}
)
target_link_libraries(kpty PUBLIC

View file

@ -51,22 +51,16 @@
# include <util.h>
#endif
#ifdef HAVE_UTEMPTER
extern "C" {
# include <utempter.h>
}
#ifdef HAVE_UTMPX
# include <utmpx.h>
#else
# ifdef HAVE_UTMPX
# include <utmpx.h>
# else
# include <utmp.h>
# endif
# if !defined(_PATH_UTMPX) && defined(_UTMPX_FILE)
# define _PATH_UTMPX _UTMPX_FILE
# endif
# if !defined(_PATH_WTMPX) && defined(_WTMPX_FILE)
# define _PATH_WTMPX _WTMPX_FILE
# endif
# include <utmp.h>
#endif
#if !defined(_PATH_UTMPX) && defined(_UTMPX_FILE)
# define _PATH_UTMPX _UTMPX_FILE
#endif
#if !defined(_PATH_WTMPX) && defined(_WTMPX_FILE)
# define _PATH_WTMPX _WTMPX_FILE
#endif
/* for HP-UX (some versions) the extern C is needed, and for other
@ -465,17 +459,11 @@ void KPty::setCTty()
void KPty::login(const char *user, const char *remotehost)
{
#ifdef HAVE_UTEMPTER
Q_D(KPty);
addToUtmp(d->ttyName, remotehost, d->masterFd);
Q_UNUSED(user);
#else
# ifdef HAVE_UTMPX
#ifdef HAVE_UTMPX
struct utmpx l_struct;
# else
#else
struct utmp l_struct;
# endif
#endif
memset(&l_struct, 0, sizeof(l_struct));
// note: strncpy without terminators _is_ correct here. man 4 utmp
@ -484,124 +472,117 @@ void KPty::login(const char *user, const char *remotehost)
if (remotehost) {
strncpy(l_struct.ut_host, remotehost, sizeof(l_struct.ut_host));
# ifdef HAVE_STRUCT_UTMP_UT_SYSLEN
#ifdef HAVE_STRUCT_UTMP_UT_SYSLEN
l_struct.ut_syslen = qMin(strlen(remotehost), sizeof(l_struct.ut_host));
# endif
#endif
}
# ifndef __GLIBC__
#ifndef __GLIBC__
Q_D(KPty);
const char *str_ptr = d->ttyName.data();
if (!memcmp(str_ptr, "/dev/", 5))
str_ptr += 5;
strncpy(l_struct.ut_line, str_ptr, sizeof(l_struct.ut_line));
# ifdef HAVE_STRUCT_UTMP_UT_ID
# ifdef HAVE_STRUCT_UTMP_UT_ID
strncpy(l_struct.ut_id,
str_ptr + strlen(str_ptr) - sizeof(l_struct.ut_id),
sizeof(l_struct.ut_id));
# endif
# endif
#endif
# ifdef HAVE_UTMPX
#ifdef HAVE_UTMPX
gettimeofday(&l_struct.ut_tv, 0);
# else
#else
l_struct.ut_time = time(0);
# endif
#endif
// on Linux login() fills these, atleast on NetBSD that is not the case and
// the utmp/utmpx struct values must be filled before calling
// loginx()/login()
# ifdef HAVE_STRUCT_UTMP_UT_TYPE
#ifdef HAVE_STRUCT_UTMP_UT_TYPE
l_struct.ut_type = USER_PROCESS;
# endif
# ifdef HAVE_STRUCT_UTMP_UT_PID
#endif
#ifdef HAVE_STRUCT_UTMP_UT_PID
l_struct.ut_pid = getpid();
# ifdef HAVE_STRUCT_UTMP_UT_SESSION
#endif
#ifdef HAVE_STRUCT_UTMP_UT_SESSION
l_struct.ut_session = getsid(0);
# endif
#endif
# if defined(HAVE_LOGINX)
#if defined(HAVE_LOGINX)
::loginx(&l_struct);
# elif defined(HAVE_LOGIN)
#elif defined(HAVE_LOGIN)
::login(&l_struct);
# elif defined(HAVE_UTMPX)
#elif defined(HAVE_UTMPX)
utmpxname(_PATH_UTMPX);
setutxent();
pututxline(&l_struct);
endutxent();
updwtmpx(_PATH_WTMPX, &l_struct);
# else
#else
utmpname(_PATH_UTMP);
setutent();
pututline(&l_struct);
endutent();
updwtmp(_PATH_WTMP, &l_struct);
# endif
# endif
#endif
}
void KPty::logout()
{
#ifdef HAVE_UTEMPTER
Q_D(KPty);
removeLineFromUtmp(d->ttyName, d->masterFd);
#else
Q_D(KPty);
const char *str_ptr = d->ttyName.data();
if (!memcmp(str_ptr, "/dev/", 5))
str_ptr += 5;
# ifdef __GLIBC__
#ifdef __GLIBC__
else {
const char *sl_ptr = strrchr(str_ptr, '/');
if (sl_ptr)
str_ptr = sl_ptr + 1;
}
# endif
# if defined(HAVE_LOGINX)
#endif
#if defined(HAVE_LOGINX)
::logoutx(str_ptr, 0, DEAD_PROCESS);
# elif defined(HAVE_LOGIN)
#elif defined(HAVE_LOGIN)
::logout(str_ptr);
# else
# ifdef HAVE_UTMPX
#else
# ifdef HAVE_UTMPX
struct utmpx l_struct, *ut;
# else
# else
struct utmp l_struct, *ut;
# endif
# endif
memset(&l_struct, 0, sizeof(l_struct));
strncpy(l_struct.ut_line, str_ptr, sizeof(l_struct.ut_line));
# ifdef HAVE_UTMPX
# ifdef HAVE_UTMPX
utmpxname(_PATH_UTMPX);
setutxent();
if ((ut = getutxline(&l_struct))) {
# else
# else
utmpname(_PATH_UTMP);
setutent();
if ((ut = getutline(&l_struct))) {
# endif
# endif
memset(ut->ut_name, 0, sizeof(*ut->ut_name));
memset(ut->ut_host, 0, sizeof(*ut->ut_host));
# ifdef HAVE_STRUCT_UTMP_UT_SYSLEN
# ifdef HAVE_STRUCT_UTMP_UT_SYSLEN
ut->ut_syslen = 0;
# endif
# ifdef HAVE_STRUCT_UTMP_UT_TYPE
# endif
# ifdef HAVE_STRUCT_UTMP_UT_TYPE
ut->ut_type = DEAD_PROCESS;
# endif
# ifdef HAVE_UTMPX
# endif
# ifdef HAVE_UTMPX
gettimeofday(&(ut->ut_tv), 0);
pututxline(ut);
}
endutxent();
# else
# else
ut->ut_time = time(0);
pututline(ut);
}
endutent();
# endif
# endif
#endif
}