1 /* $NetBSD: logutmp.c,v 1.12 2011/09/16 16:13:17 plunky Exp $ */
4 * Portions Copyright (c) 1988, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * Portions Copyright (c) 1996, Jason Downs. 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.
44 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
45 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
46 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
47 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
48 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
49 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
50 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
51 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 #include <sys/cdefs.h>
59 __RCSID("$NetBSD: logutmp.c,v 1.12 2011/09/16 16:13:17 plunky Exp $");
62 #include <sys/types.h>
63 #include <sys/param.h>
80 typedef struct utmp UTMP
;
83 static int topslot
= -1;
86 * Special versions of login()/logout() which hold the utmp file open,
91 ftpd_login(const struct utmp
*ut
)
96 * First, loop through /etc/ttys, if needed, to initialize the
97 * top of the tty slots, since ftpd has no tty.
101 while (getttyent() != NULL
)
104 if ((topslot
< 0) || ((fd
< 0)
105 && (fd
= open(_PATH_UTMP
, O_RDWR
|O_CREAT
, 0644)) < 0))
109 * Now find a slot that's not in use...
111 (void)lseek(fd
, (off_t
)(topslot
* sizeof(UTMP
)), SEEK_SET
);
114 if (read(fd
, &ubuf
, sizeof(UTMP
)) == sizeof(UTMP
)) {
115 if (!ubuf
.ut_name
[0]) {
116 (void)lseek(fd
, -(off_t
)sizeof(UTMP
), SEEK_CUR
);
121 (void)lseek(fd
, (off_t
)(topslot
* sizeof(UTMP
)),
127 (void)write(fd
, ut
, sizeof(UTMP
));
131 ftpd_logout(const char *line
)
140 (void)lseek(fd
, 0, SEEK_SET
);
142 while (read(fd
, &ut
, sizeof(UTMP
)) == sizeof(UTMP
)) {
144 || strncmp(ut
.ut_line
, line
, UT_LINESIZE
))
146 memset(ut
.ut_name
, 0, UT_NAMESIZE
);
147 memset(ut
.ut_host
, 0, UT_HOSTSIZE
);
148 (void)time(&ut
.ut_time
);
149 (void)lseek(fd
, -(off_t
)sizeof(UTMP
), SEEK_CUR
);
150 (void)write(fd
, &ut
, sizeof(UTMP
));
155 #endif /* SUPPORT_UTMP */
159 * special version of loginx which updates utmpx only.
162 ftpd_loginx(const struct utmpx
*ut
)
164 (void)pututxline(ut
);
168 ftpd_logoutx(const char *line
, int status
, int mode
)
170 return logoutx(line
, status
, mode
);