xref: /csrg-svn/libexec/ftpd/logwtmp.c (revision 35674)
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*35674Sbostic static char sccsid[] = "@(#)logwtmp.c	5.2 (Berkeley) 09/22/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*35674Sbostic static int fd;
33*35674Sbostic 
3435673Sbostic logwtmp(line, name, host)
3535673Sbostic 	char *line, *name, *host;
3635673Sbostic {
3735673Sbostic 	struct utmp ut;
3835673Sbostic 	struct stat buf;
3935673Sbostic 	time_t time();
4035673Sbostic 	char *strncpy();
4135673Sbostic 
42*35674Sbostic 	if (!fd && (fd = open(WTMPFILE, O_WRONLY|O_APPEND, 0)) < 0)
4335673Sbostic 		return;
4435673Sbostic 	if (!fstat(fd, &buf)) {
4535673Sbostic 		(void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
4635673Sbostic 		(void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
4735673Sbostic 		(void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
4835673Sbostic 		(void)time(&ut.ut_time);
4935673Sbostic 		if (write(fd, (char *)&ut, sizeof(struct utmp)) !=
5035673Sbostic 		    sizeof(struct utmp))
5135673Sbostic 			(void)ftruncate(fd, buf.st_size);
5235673Sbostic 	}
5335673Sbostic }
54