diff options
Diffstat (limited to 'contrib/lukemftpd/src/logwtmp.c')
-rw-r--r-- | contrib/lukemftpd/src/logwtmp.c | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/contrib/lukemftpd/src/logwtmp.c b/contrib/lukemftpd/src/logwtmp.c index 5da4a1d..93b61a9 100644 --- a/contrib/lukemftpd/src/logwtmp.c +++ b/contrib/lukemftpd/src/logwtmp.c @@ -1,4 +1,4 @@ -/* $NetBSD: logwtmp.c,v 1.17 2002/09/12 08:55:31 itojun Exp $ */ +/* $NetBSD: logwtmp.c,v 1.22 2004-08-09 12:56:48 lukem Exp $ */ /* * Copyright (c) 1988, 1993 @@ -12,11 +12,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -40,7 +36,7 @@ #if 0 static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: logwtmp.c,v 1.17 2002/09/12 08:55:31 itojun Exp $"); +__RCSID("$NetBSD: logwtmp.c,v 1.22 2004-08-09 12:56:48 lukem Exp $"); #endif #endif /* not lint */ @@ -48,15 +44,18 @@ __RCSID("$NetBSD: logwtmp.c,v 1.17 2002/09/12 08:55:31 itojun Exp $"); #include <sys/param.h> #include <sys/time.h> #include <sys/stat.h> +#include <sys/wait.h> #include <fcntl.h> -#include <setjmp.h> #include <signal.h> #include <stdio.h> #include <string.h> #include <time.h> #include <unistd.h> #include <utmp.h> +#ifdef SUPPORT_UTMPX +#include <utmpx.h> +#endif #include <util.h> #ifdef KERBEROS5 @@ -66,6 +65,9 @@ __RCSID("$NetBSD: logwtmp.c,v 1.17 2002/09/12 08:55:31 itojun Exp $"); #include "extern.h" static int fd = -1; +#ifdef SUPPORT_UTMPX +static int fdx = -1; +#endif /* * Modified version of logwtmp that holds wtmp file open @@ -73,7 +75,7 @@ static int fd = -1; * after login, but before logout). */ void -logwtmp(const char *line, const char *name, const char *host) +ftpd_logwtmp(const char *line, const char *name, const char *host) { struct utmp ut; struct stat buf; @@ -90,3 +92,29 @@ logwtmp(const char *line, const char *name, const char *host) (void)ftruncate(fd, buf.st_size); } } + +#ifdef SUPPORT_UTMPX +void +ftpd_logwtmpx(const char *line, const char *name, const char *host, int status, int utx_type) +{ + struct utmpx ut; + struct stat buf; + + if (fdx < 0 && (fdx = open(_PATH_WTMPX, O_WRONLY|O_APPEND, 0)) < 0) + return; + if (fstat(fdx, &buf) == 0) { + (void)strncpy(ut.ut_line, line, sizeof(ut.ut_line)); + (void)strncpy(ut.ut_name, name, sizeof(ut.ut_name)); + (void)strncpy(ut.ut_host, host, sizeof(ut.ut_host)); + ut.ut_type = utx_type; + if (WIFEXITED(status)) + ut.ut_exit.e_exit = (uint16_t)WEXITSTATUS(status); + if (WIFSIGNALED(status)) + ut.ut_exit.e_termination = (uint16_t)WTERMSIG(status); + (void)gettimeofday(&ut.ut_tv, NULL); + if(write(fdx, (char *)&ut, sizeof(struct utmpx)) != + sizeof(struct utmpx)) + (void)ftruncate(fdx, buf.st_size); + } +} +#endif |