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