xref: /csrg-svn/libexec/ftpd/logwtmp.c (revision 36304)
135673Sbostic /*
235673Sbostic  * Copyright (c) 1988 The Regents of the University of California.
335673Sbostic  * All rights reserved.
435673Sbostic  *
535673Sbostic  * Redistribution and use in source and binary forms are permitted
635673Sbostic  * provided that the above copyright notice and this paragraph are
735673Sbostic  * duplicated in all such forms and that any documentation,
835673Sbostic  * advertising materials, and other materials related to such
935673Sbostic  * distribution and use acknowledge that the software was developed
1035673Sbostic  * by the University of California, Berkeley.  The name of the
1135673Sbostic  * University may not be used to endorse or promote products derived
1235673Sbostic  * from this software without specific prior written permission.
1335673Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1435673Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1535673Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1635673Sbostic  *
1735673Sbostic  * static char sccsid[] = "@(#)logwtmp.c	5.2 (Berkeley) 9/20/88";
1835673Sbostic  */
1935673Sbostic 
2035673Sbostic #ifndef lint
21*36304Skarels static char sccsid[] = "@(#)logwtmp.c	5.3 (Berkeley) 12/07/88";
2235673Sbostic #endif /* not lint */
2335673Sbostic 
2435673Sbostic #include <sys/types.h>
2535673Sbostic #include <sys/file.h>
2635673Sbostic #include <sys/time.h>
2735673Sbostic #include <sys/stat.h>
2835673Sbostic #include <utmp.h>
2935673Sbostic 
3035673Sbostic #define	WTMPFILE	"/usr/adm/wtmp"
3135673Sbostic 
32*36304Skarels static int fd = -1;
3335674Sbostic 
34*36304Skarels /*
35*36304Skarels  * Modified version of logwtmp that holds wtmp file open
36*36304Skarels  * after first call, for use with ftp (which may chroot
37*36304Skarels  * after login, but before logout).
38*36304Skarels  */
3935673Sbostic logwtmp(line, name, host)
4035673Sbostic 	char *line, *name, *host;
4135673Sbostic {
4235673Sbostic 	struct utmp ut;
4335673Sbostic 	struct stat buf;
4435673Sbostic 	time_t time();
4535673Sbostic 	char *strncpy();
4635673Sbostic 
47*36304Skarels 	if (fd < 0 && (fd = open(WTMPFILE, O_WRONLY|O_APPEND, 0)) < 0)
4835673Sbostic 		return;
49*36304Skarels 	if (fstat(fd, &buf) == 0) {
5035673Sbostic 		(void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
5135673Sbostic 		(void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
5235673Sbostic 		(void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
5335673Sbostic 		(void)time(&ut.ut_time);
5435673Sbostic 		if (write(fd, (char *)&ut, sizeof(struct utmp)) !=
5535673Sbostic 		    sizeof(struct utmp))
5635673Sbostic 			(void)ftruncate(fd, buf.st_size);
5735673Sbostic 	}
5835673Sbostic }
59