xref: /csrg-svn/libexec/ftpd/logwtmp.c (revision 46669)
135673Sbostic /*
235673Sbostic  * Copyright (c) 1988 The Regents of the University of California.
335673Sbostic  * All rights reserved.
435673Sbostic  *
542667Sbostic  * %sccs.include.redist.c%
635673Sbostic  *
735673Sbostic  */
835673Sbostic 
935673Sbostic #ifndef lint
10*46669Sbostic static char sccsid[] = "@(#)logwtmp.c	5.7 (Berkeley) 02/25/91";
1135673Sbostic #endif /* not lint */
1235673Sbostic 
1335673Sbostic #include <sys/types.h>
1435673Sbostic #include <sys/time.h>
1535673Sbostic #include <sys/stat.h>
16*46669Sbostic #include <fcntl.h>
1735673Sbostic #include <utmp.h>
18*46669Sbostic #include <unistd.h>
19*46669Sbostic #include <string.h>
2035673Sbostic 
2136304Skarels static int fd = -1;
2235674Sbostic 
2336304Skarels /*
2436304Skarels  * Modified version of logwtmp that holds wtmp file open
2536304Skarels  * after first call, for use with ftp (which may chroot
2636304Skarels  * after login, but before logout).
2736304Skarels  */
2835673Sbostic logwtmp(line, name, host)
2935673Sbostic 	char *line, *name, *host;
3035673Sbostic {
3135673Sbostic 	struct utmp ut;
3235673Sbostic 	struct stat buf;
3335673Sbostic 	time_t time();
3435673Sbostic 	char *strncpy();
3535673Sbostic 
3637274Sbostic 	if (fd < 0 && (fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0)
3735673Sbostic 		return;
3836304Skarels 	if (fstat(fd, &buf) == 0) {
3935673Sbostic 		(void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
4035673Sbostic 		(void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
4135673Sbostic 		(void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
4235673Sbostic 		(void)time(&ut.ut_time);
4335673Sbostic 		if (write(fd, (char *)&ut, sizeof(struct utmp)) !=
4435673Sbostic 		    sizeof(struct utmp))
4535673Sbostic 			(void)ftruncate(fd, buf.st_size);
4635673Sbostic 	}
4735673Sbostic }
48