xref: /csrg-svn/libexec/ftpd/logwtmp.c (revision 42667)
135673Sbostic /*
235673Sbostic  * Copyright (c) 1988 The Regents of the University of California.
335673Sbostic  * All rights reserved.
435673Sbostic  *
5*42667Sbostic  * %sccs.include.redist.c%
635673Sbostic  *
735673Sbostic  */
835673Sbostic 
935673Sbostic #ifndef lint
10*42667Sbostic static char sccsid[] = "@(#)logwtmp.c	5.6 (Berkeley) 06/01/90";
1135673Sbostic #endif /* not lint */
1235673Sbostic 
1335673Sbostic #include <sys/types.h>
1435673Sbostic #include <sys/file.h>
1535673Sbostic #include <sys/time.h>
1635673Sbostic #include <sys/stat.h>
1735673Sbostic #include <utmp.h>
1835673Sbostic 
1936304Skarels static int fd = -1;
2035674Sbostic 
2136304Skarels /*
2236304Skarels  * Modified version of logwtmp that holds wtmp file open
2336304Skarels  * after first call, for use with ftp (which may chroot
2436304Skarels  * after login, but before logout).
2536304Skarels  */
2635673Sbostic logwtmp(line, name, host)
2735673Sbostic 	char *line, *name, *host;
2835673Sbostic {
2935673Sbostic 	struct utmp ut;
3035673Sbostic 	struct stat buf;
3135673Sbostic 	time_t time();
3235673Sbostic 	char *strncpy();
3335673Sbostic 
3437274Sbostic 	if (fd < 0 && (fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0)
3535673Sbostic 		return;
3636304Skarels 	if (fstat(fd, &buf) == 0) {
3735673Sbostic 		(void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
3835673Sbostic 		(void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
3935673Sbostic 		(void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
4035673Sbostic 		(void)time(&ut.ut_time);
4135673Sbostic 		if (write(fd, (char *)&ut, sizeof(struct utmp)) !=
4235673Sbostic 		    sizeof(struct utmp))
4335673Sbostic 			(void)ftruncate(fd, buf.st_size);
4435673Sbostic 	}
4535673Sbostic }
46