Deleted Added
full compact
logwtmp.c (59118) logwtmp.c (92906)
1/* logwtmp.c: Put an entry in the wtmp file.
2
3%%% portions-copyright-cmetz-96
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
4Portions of this software are Copyright 1996-1999 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
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.4. Set process to dead if name is null.
18 Added support for ut_id and ut_syslen.
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 */
19 Modified by cmetz for OPIE 2.32. Don't leave line=NULL, skip
20 past /dev/ in line. Fill in ut_host on systems with UTMPX and
21 ut_host.
22 Modified by cmetz for OPIE 2.31. Move wtmp log functions here, to
23 improve portability. Added DISABLE_WTMP.
24 Modified by cmetz for OPIE 2.22. Call gettimeofday() properly.
25 Modified by cmetz for OPIE 2.2. Use FUNCTION declaration et al.
26 Ifdef around some headers. Added file close hook.

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

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

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

133 } else
134 if (!strncmp(line, "/dev/", 5))
135 line += 5;
136
137 if (fd < 0 && (fd = open(_PATH_WTMP, O_WRONLY | O_APPEND, 0)) < 0)
138 return;
139 if (fstat(fd, &buf) == 0) {
140#if HAVE_UT_TYPE && defined(USER_PROCESS)
139 ut.ut_type = USER_PROCESS;
141 if (name && *name)
142 ut.ut_type = USER_PROCESS;
143 else
144 ut.ut_type = DEAD_PROCESS;
140#endif /* HAVE_UT_TYPE && defined(USER_PROCESS) */
145#endif /* HAVE_UT_TYPE && defined(USER_PROCESS) */
146#if HAVE_UT_ID
147 if (id)
148 strncpy(ut.ut_id, id, sizeof(ut.ut_id));
149#endif /* HAVE_UT_ID */
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));
150#if HAVE_UT_PID
151 ut.ut_pid = getpid();
152#endif /* HAVE_UT_PID */
153 strncpy(ut.ut_line, line, sizeof(ut.ut_line));
154 strncpy(ut.ut_name, name, sizeof(ut.ut_name));
155#if HAVE_UT_HOST
156 strncpy(ut.ut_host, host, sizeof(ut.ut_host));
157#endif /* HAVE_UT_HOST */

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

165 memset(&utx, 0, sizeof(struct utmpx));
166
167 if (fdx < 0 && (fdx = open(_PATH_WTMPX, O_WRONLY | O_APPEND, 0)) < 0)
168 return;
169 if (fstat(fdx, &buf) == 0) {
170 strncpy(utx.ut_line, line, sizeof(utx.ut_line));
171 strncpy(utx.ut_name, name, sizeof(utx.ut_name));
172 strncpy(utx.ut_host, host, sizeof(utx.ut_host));
173#ifdef USER_PROCESS
174 if (name && *name)
175 utx.ut_type = USER_PROCESS;
176 else
177 utx.ut_type = DEAD_PROCESS;
178#endif /* USER_PROCESS */
179 if (id)
180 strncpy(utx.ut_id, id, sizeof(utx.ut_id));
181 utx.ut_pid = getpid();
182#if HAVE_UTX_SYSLEN
183 utx.ut_syslen = strlen(utx.ut_host) + 1;
184#endif /* HAVE_UTX_SYSLEN */
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}
185#if HAVE_GETTIMEOFDAY
186#if HAVE_ONE_ARG_GETTIMEOFDAY
187 gettimeofday(&utx.ut_tv);
188#else /* HAVE_ONE_ARG_GETTIMEOFDAY */
189 gettimeofday(&utx.ut_tv, NULL);
190#endif /* HAVE_ONE_ARG_GETTIMEOFDAY */
191#endif /* HAVE_GETTIMEOFDAY */
192 if (write(fdx, (char *) &utx, sizeof(struct utmpx)) != sizeof(struct utmpx))
193 ftruncate(fdx, buf.st_size);
194 }
195#endif /* DOUTMPX && defined(_PATH_WTMPX) */
196#endif /* !DISABLE_WTMP */
197}