cleanup utmp and utmpx support.
- make them symmetric - add a function to open the wtmp file explicitly very early in the game
This commit is contained in:
parent
277396bd87
commit
ea7965eb77
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: extern.h,v 1.52 2005/03/03 22:19:47 ginsbach Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.53 2005/06/23 04:20:41 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -180,17 +180,21 @@ void yyerror(char *);
|
||||
#ifdef SUPPORT_UTMP
|
||||
struct utmp;
|
||||
|
||||
void ftpd_initwtmp(void);
|
||||
void ftpd_logwtmp(const char *, const char *, const char *);
|
||||
void ftpd_login(const struct utmp *ut);
|
||||
int ftpd_logout(const char *line);
|
||||
void ftpd_login(const struct utmp *);
|
||||
int ftpd_logout(const char *);
|
||||
#endif
|
||||
|
||||
#ifdef SUPPORT_UTMPX
|
||||
struct utmpx;
|
||||
struct sockinet;
|
||||
void ftpd_loginx(const struct utmpx *);
|
||||
|
||||
void ftpd_initwtmpx(void);
|
||||
void ftpd_logwtmpx(const char *, const char *, const char *,
|
||||
struct sockinet *, int, int);
|
||||
struct sockinet *, int, int);
|
||||
void ftpd_loginx(const struct utmpx *);
|
||||
int ftpd_logoutx(const char *, int, int);
|
||||
#endif
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ftpd.c,v 1.165 2005/04/10 08:21:36 christos Exp $ */
|
||||
/* $NetBSD: ftpd.c,v 1.166 2005/06/23 04:20:41 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
|
||||
@ -105,7 +105,7 @@ __COPYRIGHT(
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)ftpd.c 8.5 (Berkeley) 4/28/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: ftpd.c,v 1.165 2005/04/10 08:21:36 christos Exp $");
|
||||
__RCSID("$NetBSD: ftpd.c,v 1.166 2005/06/23 04:20:41 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -437,6 +437,14 @@ main(int argc, char *argv[])
|
||||
if (EMPTYSTR(confdir))
|
||||
confdir = _DEFAULT_CONFDIR;
|
||||
|
||||
if (dowtmp) {
|
||||
#ifdef SUPPORT_UTMPX
|
||||
ftpd_initwtmpx();
|
||||
#endif
|
||||
#ifdef SUPPORT_UTMP
|
||||
ftpd_initwtmp();
|
||||
#endif
|
||||
}
|
||||
errno = 0;
|
||||
l = sysconf(_SC_LOGIN_NAME_MAX);
|
||||
if (l == -1 && errno != 0) {
|
||||
@ -1070,25 +1078,25 @@ login_utmp(const char *line, const char *name, const char *host,
|
||||
static void
|
||||
logout_utmp(void)
|
||||
{
|
||||
#ifdef SUPPORT_UTMPX
|
||||
int okwtmpx = dowtmp;
|
||||
#endif
|
||||
#ifdef SUPPORT_UTMP
|
||||
int okwtmp = dowtmp;
|
||||
#endif
|
||||
if (logged_in) {
|
||||
if (doutmp) {
|
||||
#ifdef SUPPORT_UTMPX
|
||||
okwtmp = logoutx(ttyline, 0, DEAD_PROCESS) & dowtmp;
|
||||
#endif
|
||||
#ifdef SUPPORT_UTMP
|
||||
okwtmp = ftpd_logout(ttyline) & dowtmp;
|
||||
#endif
|
||||
}
|
||||
if (okwtmp) {
|
||||
#ifdef SUPPORT_UTMPX
|
||||
ftpd_logwtmpx(ttyline, "", "", NULL, 0,
|
||||
DEAD_PROCESS);
|
||||
if (doutmp)
|
||||
okwtmpx &= ftpd_logoutx(ttyline, 0, DEAD_PROCESS);
|
||||
if (okwtmpx)
|
||||
ftpd_logwtmpx(ttyline, "", "", NULL, 0, DEAD_PROCESS);
|
||||
#endif
|
||||
#ifdef SUPPORT_UTMP
|
||||
if (doutmp)
|
||||
okwtmp &= ftpd_logout(ttyline);
|
||||
if (okwtmp)
|
||||
ftpd_logwtmp(ttyline, "", "");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,4 +154,10 @@ ftpd_loginx(const struct utmpx *ut)
|
||||
{
|
||||
(void)pututxline(ut);
|
||||
}
|
||||
|
||||
int
|
||||
ftpd_logoutx(const char *line, int status, int mode)
|
||||
{
|
||||
return logoutx(line, status, mode);
|
||||
}
|
||||
#endif
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: logwtmp.c,v 1.23 2004/11/11 01:14:10 christos 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.23 2004/11/11 01:14:10 christos 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.23 2004/11/11 01:14:10 christos 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.23 2004/11/11 01:14:10 christos 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,8 +101,19 @@ 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,
|
||||
struct sockinet *haddr, int status, int utx_type)
|
||||
@ -101,7 +121,7 @@ ftpd_logwtmpx(const char *line, const char *name, const char *host,
|
||||
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));
|
||||
|
Loading…
Reference in New Issue
Block a user