Deleted Added
sdiff udiff text old ( 59118 ) new ( 92906 )
full compact
1/* logwtmp.c: Put an entry in the wtmp file.
2
3%%% portions-copyright-cmetz-96
4Portions of this software are Copyright 1996-1998 by Craig Metz, All Rights
5Reserved. The Inner Net License Version 2 applies to these portions of
6the software.
7You should have received a copy of the license with this software. If
8you didn't get a copy, you may request one from <license@inner.net>.
9
10Portions of this software are Copyright 1995 by Randall Atkinson and Dan
11McDonald, All Rights Reserved. All Rights under this copyright are assigned
12to the U.S. Naval Research Laboratory (NRL). The NRL Copyright Notice and
13License Agreement applies to this software.
14
15 History:
16
17 Modified by cmetz for OPIE 2.32. Don't leave line=NULL, skip
18 past /dev/ in line. Fill in ut_host on systems with UTMPX and
19 ut_host.
20 Modified by cmetz for OPIE 2.31. Move wtmp log functions here, to
21 improve portability. Added DISABLE_WTMP.
22 Modified by cmetz for OPIE 2.22. Call gettimeofday() properly.
23 Modified by cmetz for OPIE 2.2. Use FUNCTION declaration et al.
24 Ifdef around some headers. Added file close hook.

--- 80 unchanged lines hidden (view full) ---

105#endif /* WTMPX_FILE */
106#endif /* _PATH_WTMPX */
107
108/*
109 * Modified version of logwtmp that holds wtmp file open
110 * after first call, for use with ftp (which may chroot
111 * after login, but before logout).
112 */
113VOIDRET opielogwtmp FUNCTION((line, name, host), char *line AND char *name AND char *host)
114{
115#if !DISABLE_WTMP
116 struct utmp ut;
117
118#if DOUTMPX && defined(_PATH_WTMPX)
119 struct utmpx utx;
120#endif /* DOUTMPX && defined(_PATH_WTMPX) */
121 struct stat buf;

--- 9 unchanged lines hidden (view full) ---

131 } else
132 if (!strncmp(line, "/dev/", 5))
133 line += 5;
134
135 if (fd < 0 && (fd = open(_PATH_WTMP, O_WRONLY | O_APPEND, 0)) < 0)
136 return;
137 if (fstat(fd, &buf) == 0) {
138#if HAVE_UT_TYPE && defined(USER_PROCESS)
139 ut.ut_type = USER_PROCESS;
140#endif /* HAVE_UT_TYPE && defined(USER_PROCESS) */
141#if HAVE_UT_PID
142 ut.ut_pid = getpid();
143#endif /* HAVE_UT_PID */
144 strncpy(ut.ut_line, line, sizeof(ut.ut_line));
145 strncpy(ut.ut_name, name, sizeof(ut.ut_name));
146#if HAVE_UT_HOST
147 strncpy(ut.ut_host, host, sizeof(ut.ut_host));
148#endif /* HAVE_UT_HOST */

--- 7 unchanged lines hidden (view full) ---

156 memset(&utx, 0, sizeof(struct utmpx));
157
158 if (fdx < 0 && (fdx = open(_PATH_WTMPX, O_WRONLY | O_APPEND, 0)) < 0)
159 return;
160 if (fstat(fdx, &buf) == 0) {
161 strncpy(utx.ut_line, line, sizeof(utx.ut_line));
162 strncpy(utx.ut_name, name, sizeof(utx.ut_name));
163 strncpy(utx.ut_host, host, sizeof(utx.ut_host));
164#if HAVE_GETTIMEOFDAY
165#if HAVE_ONE_ARG_GETTIMEOFDAY
166 gettimeofday(&utx.ut_tv);
167#else /* HAVE_ONE_ARG_GETTIMEOFDAY */
168 gettimeofday(&utx.ut_tv, NULL);
169#endif /* HAVE_ONE_ARG_GETTIMEOFDAY */
170#endif /* HAVE_GETTIMEOFDAY */
171 if (write(fdx, (char *) &utx, sizeof(struct utmpx)) != sizeof(struct utmpx))
172 ftruncate(fdx, buf.st_size);
173 }
174#endif /* DOUTMPX && defined(_PATH_WTMPX) */
175#endif /* !DISABLE_WTMP */
176}