xref: /csrg-svn/libexec/ftpd/logwtmp.c (revision 35673)
1*35673Sbostic /*
2*35673Sbostic  * Copyright (c) 1988 The Regents of the University of California.
3*35673Sbostic  * All rights reserved.
4*35673Sbostic  *
5*35673Sbostic  * Redistribution and use in source and binary forms are permitted
6*35673Sbostic  * provided that the above copyright notice and this paragraph are
7*35673Sbostic  * duplicated in all such forms and that any documentation,
8*35673Sbostic  * advertising materials, and other materials related to such
9*35673Sbostic  * distribution and use acknowledge that the software was developed
10*35673Sbostic  * by the University of California, Berkeley.  The name of the
11*35673Sbostic  * University may not be used to endorse or promote products derived
12*35673Sbostic  * from this software without specific prior written permission.
13*35673Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14*35673Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15*35673Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16*35673Sbostic  *
17*35673Sbostic  * static char sccsid[] = "@(#)logwtmp.c	5.2 (Berkeley) 9/20/88";
18*35673Sbostic  */
19*35673Sbostic 
20*35673Sbostic #ifndef lint
21*35673Sbostic static char sccsid[] = "@(#)logwtmp.c	5.1 (Berkeley) 09/22/88";
22*35673Sbostic #endif /* not lint */
23*35673Sbostic 
24*35673Sbostic #include <sys/types.h>
25*35673Sbostic #include <sys/file.h>
26*35673Sbostic #include <sys/time.h>
27*35673Sbostic #include <sys/stat.h>
28*35673Sbostic #include <utmp.h>
29*35673Sbostic 
30*35673Sbostic #define	WTMPFILE	"/usr/adm/wtmp"
31*35673Sbostic 
32*35673Sbostic logwtmp(line, name, host)
33*35673Sbostic 	char *line, *name, *host;
34*35673Sbostic {
35*35673Sbostic 	struct utmp ut;
36*35673Sbostic 	struct stat buf;
37*35673Sbostic 	int fd;
38*35673Sbostic 	time_t time();
39*35673Sbostic 	char *strncpy();
40*35673Sbostic 
41*35673Sbostic 	if ((fd = open(WTMPFILE, O_WRONLY|O_APPEND, 0)) < 0)
42*35673Sbostic 		return;
43*35673Sbostic 	if (!fstat(fd, &buf)) {
44*35673Sbostic 		(void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
45*35673Sbostic 		(void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
46*35673Sbostic 		(void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
47*35673Sbostic 		(void)time(&ut.ut_time);
48*35673Sbostic 		if (write(fd, (char *)&ut, sizeof(struct utmp)) !=
49*35673Sbostic 		    sizeof(struct utmp))
50*35673Sbostic 			(void)ftruncate(fd, buf.st_size);
51*35673Sbostic 	}
52*35673Sbostic 	(void)close(fd);
53*35673Sbostic }
54