From c82515b578eb47b9cab9e82efb0eb57158a02004 Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Tue, 20 May 1997 20:30:24 +0000 Subject: [PATCH] Add support for logging to wtmpx git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1751 ec53bebd-3082-4978-b11e-865c3cabbd6b --- appl/ftp/ftpd/logwtmp.c | 48 +++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/appl/ftp/ftpd/logwtmp.c b/appl/ftp/ftpd/logwtmp.c index 53571cd63..fb1f8d2d9 100644 --- a/appl/ftp/ftpd/logwtmp.c +++ b/appl/ftp/ftpd/logwtmp.c @@ -42,20 +42,31 @@ RCSID("$Id$"); #endif #include -#include #include #include #include +#ifdef HAVE_UTMP_H +#include +#endif +#ifdef HAVE_UTMPX_H +#include +#endif #include "extern.h" +#ifndef WTMP_FILE +#define WTMP_FILE "/var/adm/wtmp" +#endif void logwtmp(char *line, char *name, char *host) { static int init = 0; - static int fd; - + static int fd, fdx; + struct timeval tv; struct utmp ut; +#ifdef WTMPX_FILE + struct utmpx utx; +#endif memset(&ut, 0, sizeof(struct utmp)); #ifdef HAVE_UT_TYPE @@ -72,13 +83,38 @@ logwtmp(char *line, char *name, char *host) #ifdef HAVE_UT_HOST strncpy(ut.ut_host, host, sizeof(ut.ut_host)); #endif - ut.ut_time = time(NULL); +#ifdef WTMPX_FILE + strncpy(utx.ut_line, line, sizeof(utx.ut_line)); + strncpy(utx.ut_user, name, sizeof(utx.ut_user)); + strncpy(utx.ut_host, host, sizeof(utx.ut_host)); +#ifdef HAVE_UT_SYSLEN + utx.ut_syslen = strlen(host) + 1; + if (utx.ut_syslen > sizeof(utx.ut_host)) + utx.ut_syslen = sizeof(utx.ut_host); +#endif + gettimeofday (&tv, 0); + utx.ut_tv.tv_sec = tv.tv_sec; + utx.ut_tv.tv_usec = tv.tv_usec; + + if(name[0]) + utx.ut_type = USER_PROCESS; + else + utx.ut_type = DEAD_PROCESS; +#endif + if(!init){ - fd = open(WTMP_PATH, O_WRONLY|O_APPEND, 0); + fd = open(WTMP_FILE, O_WRONLY|O_APPEND, 0); +#ifdef WTMPX_FILE + fdx = open(WTMPX_FILE, O_WRONLY|O_APPEND, 0); +#endif init = 1; } - if(fd >= 0) + if(fd >= 0) { write(fd, &ut, sizeof(struct utmp)); /* XXX */ +#ifdef WTMPX_FILE + write(fdx, &utx, sizeof(struct utmpx)); +#endif + } }