2 * Portions Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Portions Copyright (c) 1996, Jason Downs. All rights reserved.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
42 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
43 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
44 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
46 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
47 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
48 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
49 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 #include <sys/types.h>
56 #include <sys/param.h>
72 typedef struct utmp UTMP;
75 static int topslot = -1;
78 * Special versions of login()/logout() which hold the utmp file open,
83 ftpd_login(const struct utmp *ut)
88 * First, loop through /etc/ttys, if needed, to initialize the
89 * top of the tty slots, since ftpd has no tty.
93 while (getttyent() != (struct ttyent *)NULL)
96 if ((topslot < 0) || ((fd < 0)
97 && (fd = open(_PATH_UTMP, O_RDWR|O_CREAT, 0644)) < 0))
101 * Now find a slot that's not in use...
103 (void)lseek(fd, (off_t)(topslot * sizeof(UTMP)), SEEK_SET);
106 if (read(fd, &ubuf, sizeof(UTMP)) == sizeof(UTMP)) {
107 if (!ubuf.ut_name[0]) {
108 (void)lseek(fd, -(off_t)sizeof(UTMP), SEEK_CUR);
113 (void)lseek(fd, (off_t)(topslot * sizeof(UTMP)),
119 (void)write(fd, ut, sizeof(UTMP));
123 ftpd_logout(const char *line)
132 (void)lseek(fd, 0, SEEK_SET);
134 while (read(fd, &ut, sizeof(UTMP)) == sizeof(UTMP)) {
136 || strncmp(ut.ut_line, line, UT_LINESIZE))
138 memset(ut.ut_name, 0, UT_NAMESIZE);
139 memset(ut.ut_host, 0, UT_HOSTSIZE);
140 (void)time(&ut.ut_time);
141 (void)lseek(fd, -(off_t)sizeof(UTMP), SEEK_CUR);
142 (void)write(fd, &ut, sizeof(UTMP));
150 * special version of loginx which updates utmpx only.
153 ftpd_loginx(const struct utmpx *ut)
155 (void)pututxline(ut);
159 ftpd_logoutx(const char *line, int status, int mode)
161 return logoutx(line, status, mode);