diff options
| author | christos <christos@NetBSD.org> | 2005-06-23 04:20:41 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2005-06-23 04:20:41 +0000 |
| commit | ea7965eb77a8c83ddb672fc3f8ea87fcebf34216 (patch) | |
| tree | 453db28f5ec366c3ddf2890b5f24960cc1607eaa /libexec | |
| parent | 277396bd87bdd2798c8114fec80392e2e18c9c26 (diff) | |
cleanup utmp and utmpx support.
- make them symmetric
- add a function to open the wtmp file explicitly very early in the game
Diffstat (limited to 'libexec')
| -rw-r--r-- | libexec/ftpd/extern.h | 14 | ||||
| -rw-r--r-- | libexec/ftpd/ftpd.c | 32 | ||||
| -rw-r--r-- | libexec/ftpd/logutmp.c | 6 | ||||
| -rw-r--r-- | libexec/ftpd/logwtmp.c | 32 |
4 files changed, 61 insertions, 23 deletions
diff --git a/libexec/ftpd/extern.h b/libexec/ftpd/extern.h index 6625b46bfa0..8d0d2f8cd26 100644 --- a/libexec/ftpd/extern.h +++ b/libexec/ftpd/extern.h @@ -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> diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c index 6cf40a44bbf..8da9a96aeaa 100644 --- a/libexec/ftpd/ftpd.c +++ b/libexec/ftpd/ftpd.c @@ -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) { - int okwtmp = dowtmp; - if (logged_in) { - if (doutmp) { #ifdef SUPPORT_UTMPX - okwtmp = logoutx(ttyline, 0, DEAD_PROCESS) & dowtmp; + int okwtmpx = dowtmp; #endif #ifdef SUPPORT_UTMP - okwtmp = ftpd_logout(ttyline) & dowtmp; + int okwtmp = dowtmp; #endif - } - if (okwtmp) { + if (logged_in) { #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 - } } } diff --git a/libexec/ftpd/logutmp.c b/libexec/ftpd/logutmp.c index c93a8ebd347..71ee558245c 100644 --- a/libexec/ftpd/logutmp.c +++ b/libexec/ftpd/logutmp.c @@ -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 diff --git a/libexec/ftpd/logwtmp.c b/libexec/ftpd/logwtmp.c index a20c42093b9..33d73deea57 100644 --- a/libexec/ftpd/logwtmp.c +++ b/libexec/ftpd/logwtmp.c @@ -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)); |
