1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00

Use pututxline() in place of pututline(), since the former is standardised by

X/Open and actually seems to be more common (NetBSD has it).  Also use
updwtmpx() rather than directly writing to the wtmpx file, though more for
reasons of aesthetics than anything practical.

[originally from svn r5678]
This commit is contained in:
Ben Harris 2005-04-25 23:28:25 +00:00
parent 318913822d
commit 62b943922e
2 changed files with 40 additions and 38 deletions

View File

@ -15,13 +15,16 @@ if test "X$GCC" = Xyes; then
fi fi
AC_CHECK_HEADERS([sys/sockio.h],,,[ ]) AC_CHECK_HEADERS([sys/sockio.h],,,[ ])
AC_CHECK_HEADERS([utmpx.h],,,[
#include <sys/types.h>
#include <utmp.h>])
AM_PATH_GTK([1.2.0], [all_targets="all-cli all-gtk"], [all_targets="all-cli"]) AM_PATH_GTK([1.2.0], [all_targets="all-cli all-gtk"], [all_targets="all-cli"])
AC_SUBST([all_targets]) AC_SUBST([all_targets])
AC_SEARCH_LIBS([socket], [xnet]) AC_SEARCH_LIBS([socket], [xnet])
AC_CHECK_FUNCS([getaddrinfo ptsname pututline setresuid strsignal]) AC_CHECK_FUNCS([getaddrinfo ptsname setresuid strsignal])
AC_OUTPUT AC_OUTPUT
@ -37,7 +40,7 @@ AH_BOTTOM([
#ifndef HAVE_STRSIGNAL #ifndef HAVE_STRSIGNAL
# define HAVE_NO_STRSIGNAL # define HAVE_NO_STRSIGNAL
#endif #endif
#ifndef HAVE_PUTUTLINE #ifndef HAVE_UTMPX_H
# define OMIT_UTMP # define OMIT_UTMP
#endif #endif
#ifndef HAVE_PTSNAME #ifndef HAVE_PTSNAME

View File

@ -24,6 +24,10 @@
#include "putty.h" #include "putty.h"
#include "tree234.h" #include "tree234.h"
#ifdef HAVE_UTMPX_H
#include <utmpx.h>
#endif
#ifndef FALSE #ifndef FALSE
#define FALSE 0 #define FALSE 0
#endif #endif
@ -31,12 +35,15 @@
#define TRUE 1 #define TRUE 1
#endif #endif
#ifndef UTMP_FILE /* updwtmpx() needs the name of the wtmp file. Try to find it. */
#define UTMP_FILE "/var/run/utmp" #ifndef WTMPX_FILE
#ifdef _PATH_WTMPX
#define WTMPX_FILE _PATH_WTMPX
#else
#define WTMPX_FILE "/var/log/wtmpx"
#endif #endif
#ifndef WTMP_FILE
#define WTMP_FILE "/var/log/wtmp"
#endif #endif
#ifndef LASTLOG_FILE #ifndef LASTLOG_FILE
#ifdef _PATH_LASTLOG #ifdef _PATH_LASTLOG
#define LASTLOG_FILE _PATH_LASTLOG #define LASTLOG_FILE _PATH_LASTLOG
@ -160,7 +167,7 @@ static Pty single_pty = NULL;
#ifndef OMIT_UTMP #ifndef OMIT_UTMP
static int pty_utmp_helper_pid, pty_utmp_helper_pipe; static int pty_utmp_helper_pid, pty_utmp_helper_pipe;
static int pty_stamped_utmp; static int pty_stamped_utmp;
static struct utmp utmp_entry; static struct utmpx utmp_entry;
#endif #endif
/* /*
@ -180,8 +187,7 @@ static void setup_utmp(char *ttyname, char *location)
FILE *lastlog; FILE *lastlog;
#endif #endif
struct passwd *pw; struct passwd *pw;
FILE *wtmp; struct timeval tv;
time_t uttime;
pw = getpwuid(getuid()); pw = getpwuid(getuid());
memset(&utmp_entry, 0, sizeof(utmp_entry)); memset(&utmp_entry, 0, sizeof(utmp_entry));
@ -191,22 +197,20 @@ static void setup_utmp(char *ttyname, char *location)
strncpy(utmp_entry.ut_id, ttyname+8, lenof(utmp_entry.ut_id)); strncpy(utmp_entry.ut_id, ttyname+8, lenof(utmp_entry.ut_id));
strncpy(utmp_entry.ut_user, pw->pw_name, lenof(utmp_entry.ut_user)); strncpy(utmp_entry.ut_user, pw->pw_name, lenof(utmp_entry.ut_user));
strncpy(utmp_entry.ut_host, location, lenof(utmp_entry.ut_host)); strncpy(utmp_entry.ut_host, location, lenof(utmp_entry.ut_host));
/* Apparently there are some architectures where (struct utmp).ut_time /*
* is not essentially time_t (e.g. Linux amd64). Hence the temporary. */ * Apparently there are some architectures where (struct
time(&uttime); * utmpx).ut_tv is not essentially struct timeval (e.g. Linux
utmp_entry.ut_time = uttime; /* may truncate */ * amd64). Hence the temporary.
*/
gettimeofday(&tv, NULL);
utmp_entry.ut_tv.tv_sec = tv.tv_sec;
utmp_entry.ut_tv.tv_usec = tv.tv_usec;
#if defined HAVE_PUTUTLINE setutxent();
utmpname(UTMP_FILE); pututxline(&utmp_entry);
setutent(); endutxent();
pututline(&utmp_entry);
endutent();
#endif
if ((wtmp = fopen(WTMP_FILE, "a")) != NULL) { updwtmpx(WTMPX_FILE, &utmp_entry);
fwrite(&utmp_entry, 1, sizeof(utmp_entry), wtmp);
fclose(wtmp);
}
#ifdef HAVE_LASTLOG #ifdef HAVE_LASTLOG
memset(&lastlog_entry, 0, sizeof(lastlog_entry)); memset(&lastlog_entry, 0, sizeof(lastlog_entry));
@ -226,31 +230,26 @@ static void setup_utmp(char *ttyname, char *location)
static void cleanup_utmp(void) static void cleanup_utmp(void)
{ {
FILE *wtmp; struct timeval tv;
time_t uttime;
if (!pty_stamped_utmp) if (!pty_stamped_utmp)
return; return;
utmp_entry.ut_type = DEAD_PROCESS; utmp_entry.ut_type = DEAD_PROCESS;
memset(utmp_entry.ut_user, 0, lenof(utmp_entry.ut_user)); memset(utmp_entry.ut_user, 0, lenof(utmp_entry.ut_user));
time(&uttime); gettimeofday(&tv, NULL);
utmp_entry.ut_time = uttime; utmp_entry.ut_tv.tv_sec = tv.tv_sec;
utmp_entry.ut_tv.tv_usec = tv.tv_usec;
if ((wtmp = fopen(WTMP_FILE, "a")) != NULL) { updwtmpx(WTMPX_FILE, &utmp_entry);
fwrite(&utmp_entry, 1, sizeof(utmp_entry), wtmp);
fclose(wtmp);
}
memset(utmp_entry.ut_line, 0, lenof(utmp_entry.ut_line)); memset(utmp_entry.ut_line, 0, lenof(utmp_entry.ut_line));
utmp_entry.ut_time = 0; utmp_entry.ut_tv.tv_sec = 0;
utmp_entry.ut_tv.tv_usec = 0;
#if defined HAVE_PUTUTLINE setutxent();
utmpname(UTMP_FILE); pututxline(&utmp_entry);
setutent(); endutxent();
pututline(&utmp_entry);
endutent();
#endif
pty_stamped_utmp = 0; /* ensure we never double-cleanup */ pty_stamped_utmp = 0; /* ensure we never double-cleanup */
} }