aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/lukemftpd/src/logwtmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/lukemftpd/src/logwtmp.c')
-rw-r--r--contrib/lukemftpd/src/logwtmp.c39
1 files changed, 32 insertions, 7 deletions
diff --git a/contrib/lukemftpd/src/logwtmp.c b/contrib/lukemftpd/src/logwtmp.c
index 93b61a919dbe..33d73deea57c 100644
--- a/contrib/lukemftpd/src/logwtmp.c
+++ b/contrib/lukemftpd/src/logwtmp.c
@@ -1,4 +1,4 @@
-/* $NetBSD: logwtmp.c,v 1.22 2004-08-09 12:56:48 lukem Exp $ */
+/* $NetBSD: logwtmp.c,v 1.24 2005/06/23 04:20:41 christos Exp $ */
/*
* Copyright (c) 1988, 1993
@@ -36,7 +36,7 @@
#if 0
static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: logwtmp.c,v 1.22 2004-08-09 12:56:48 lukem Exp $");
+__RCSID("$NetBSD: logwtmp.c,v 1.24 2005/06/23 04:20:41 christos Exp $");
#endif
#endif /* not lint */
@@ -51,8 +51,11 @@ __RCSID("$NetBSD: logwtmp.c,v 1.22 2004-08-09 12:56:48 lukem Exp $");
#include <stdio.h>
#include <string.h>
#include <time.h>
+#include <syslog.h>
#include <unistd.h>
+#ifdef SUPPORT_UTMP
#include <utmp.h>
+#endif
#ifdef SUPPORT_UTMPX
#include <utmpx.h>
#endif
@@ -64,10 +67,16 @@ __RCSID("$NetBSD: logwtmp.c,v 1.22 2004-08-09 12:56:48 lukem Exp $");
#include "extern.h"
+#ifdef SUPPORT_UTMP
static int fd = -1;
-#ifdef SUPPORT_UTMPX
-static int fdx = -1;
-#endif
+
+void
+ftpd_initwtmp(void)
+{
+ const char *wf = _PATH_WTMP;
+ if ((fd = open(wf, O_WRONLY|O_APPEND, 0)) == -1)
+ syslog(LOG_ERR, "Cannot open `%s' (%m)", wf);
+}
/*
* Modified version of logwtmp that holds wtmp file open
@@ -92,20 +101,36 @@ ftpd_logwtmp(const char *line, const char *name, const char *host)
(void)ftruncate(fd, buf.st_size);
}
}
+#endif
#ifdef SUPPORT_UTMPX
+static int fdx = -1;
+
+void
+ftpd_initwtmpx(void)
+{
+ const char *wf = _PATH_WTMPX;
+ if ((fd = open(wf, O_WRONLY|O_APPEND, 0)) == -1)
+ syslog(LOG_ERR, "Cannot open `%s' (%m)", wf);
+}
+
void
-ftpd_logwtmpx(const char *line, const char *name, const char *host, int status, int utx_type)
+ftpd_logwtmpx(const char *line, const char *name, const char *host,
+ struct sockinet *haddr, int status, int utx_type)
{
struct utmpx ut;
struct stat buf;
- if (fdx < 0 && (fdx = open(_PATH_WTMPX, O_WRONLY|O_APPEND, 0)) < 0)
+ if (fdx < 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));
+ if (haddr)
+ (void)memcpy(&ut.ut_ss, &haddr->si_su, haddr->su_len);
+ else
+ (void)memset(&ut.ut_ss, 0, sizeof(ut.ut_ss));
ut.ut_type = utx_type;
if (WIFEXITED(status))
ut.ut_exit.e_exit = (uint16_t)WEXITSTATUS(status);