1 /* logwtmp.c: Put an entry in the wtmp file.
3 %%% portions-copyright-cmetz-96
4 Portions of this software are Copyright 1996-1999 by Craig Metz, All Rights
5 Reserved. The Inner Net License Version 2 applies to these portions of
7 You should have received a copy of the license with this software. If
8 you didn't get a copy, you may request one from <license@inner.net>.
10 Portions of this software are Copyright 1995 by Randall Atkinson and Dan
11 McDonald, All Rights Reserved. All Rights under this copyright are assigned
12 to the U.S. Naval Research Laboratory (NRL). The NRL Copyright Notice and
13 License Agreement applies to this software.
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.
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
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.
27 Modified at NRL for OPIE 2.1. Set process type for HPUX.
28 Modified at NRL for OPIE 2.0.
32 * Copyright (c) 1988 The Regents of the University of California.
33 * All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. All advertising materials mentioning features or use of this software
44 * must display the following acknowledgement:
45 * This product includes software developed by the University of
46 * California, Berkeley and its contributors.
47 * 4. Neither the name of the University nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
67 #include <sys/types.h>
70 #endif /* HAVE_SYS_TIME_H */
76 #endif /* HAVE_UNISTD_H */
79 #endif /* HAVE_STRING_H */
92 #define _PATH_WTMP WTMP_FILE
95 #define _PATH_WTMP PATH_WTMP_AC
96 #endif /* PATH_WTMP_AC */
97 #endif /* WTMP_FILE */
98 #endif /* _PATH_WTMP */
102 #define _PATH_WTMPX WTMPX_FILE
103 #else /* WTMPX_FILE */
105 #define _PATH_WTMPX PATH_WTMPX_AC
106 #endif /* PATH_WTMPX_AC */
107 #endif /* WTMPX_FILE */
108 #endif /* _PATH_WTMPX */
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).
115 VOIDRET opielogwtmp
FUNCTION((line
, name
, host
), char *line AND
char *name AND
char *host AND
char *id
)
120 #if DOUTMPX && defined(_PATH_WTMPX)
122 #endif /* DOUTMPX && defined(_PATH_WTMPX) */
125 memset(&ut
, 0, sizeof(struct utmp
));
129 #if DOUTMPX && defined(_PATH_WTMPX)
131 #endif /* DOUTMPX && defined(_PATH_WTMPX) */
134 if (!strncmp(line
, "/dev/", 5))
137 if (fd
< 0 && (fd
= open(_PATH_WTMP
, O_WRONLY
| O_APPEND
, 0)) < 0)
139 if (fstat(fd
, &buf
) == 0) {
140 #if HAVE_UT_TYPE && defined(USER_PROCESS)
142 ut
.ut_type
= USER_PROCESS
;
144 ut
.ut_type
= DEAD_PROCESS
;
145 #endif /* HAVE_UT_TYPE && defined(USER_PROCESS) */
148 strncpy(ut
.ut_id
, id
, sizeof(ut
.ut_id
));
149 #endif /* HAVE_UT_ID */
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
));
156 strncpy(ut
.ut_host
, host
, sizeof(ut
.ut_host
));
157 #endif /* HAVE_UT_HOST */
159 if (write(fd
, (char *) &ut
, sizeof(struct utmp
)) !=
161 ftruncate(fd
, buf
.st_size
);
164 #if DOUTMPX && defined(_PATH_WTMPX)
165 memset(&utx
, 0, sizeof(struct utmpx
));
167 if (fdx
< 0 && (fdx
= open(_PATH_WTMPX
, O_WRONLY
| O_APPEND
, 0)) < 0)
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
));
175 utx
.ut_type
= USER_PROCESS
;
177 utx
.ut_type
= DEAD_PROCESS
;
178 #endif /* USER_PROCESS */
180 strncpy(utx
.ut_id
, id
, sizeof(utx
.ut_id
));
181 utx
.ut_pid
= getpid();
183 utx
.ut_syslen
= strlen(utx
.ut_host
) + 1;
184 #endif /* HAVE_UTX_SYSLEN */
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
);
195 #endif /* DOUTMPX && defined(_PATH_WTMPX) */
196 #endif /* !DISABLE_WTMP */