1 /*
2 * Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 *
7 */
8
9 #ifndef lint
10 static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 06/04/93";
11 #endif /* not lint */
12
13 #include <sys/types.h>
14 #include <sys/time.h>
15 #include <sys/stat.h>
16
17 #include <fcntl.h>
18 #include <utmp.h>
19 #include <unistd.h>
20 #include <stdio.h>
21 #include <string.h>
22 #include "extern.h"
23
24 static int fd = -1;
25
26 /*
27 * Modified version of logwtmp that holds wtmp file open
28 * after first call, for use with ftp (which may chroot
29 * after login, but before logout).
30 */
31 void
logwtmp(line,name,host)32 logwtmp(line, name, host)
33 char *line, *name, *host;
34 {
35 struct utmp ut;
36 struct stat buf;
37
38 if (fd < 0 && (fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0)
39 return;
40 if (fstat(fd, &buf) == 0) {
41 (void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
42 (void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
43 (void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
44 (void)time(&ut.ut_time);
45 if (write(fd, (char *)&ut, sizeof(struct utmp)) !=
46 sizeof(struct utmp))
47 (void)ftruncate(fd, buf.st_size);
48 }
49 }
50