ftpd doesn't log anonymous logins
cak at Purdue.ARPA
cak at Purdue.ARPA
Sat Jan 14 03:23:00 AEST 1984
From: Christopher A Kent <cak at Purdue.ARPA>
Description:
The FTP daemon doesn't properly log anonymous logins in
/usr/adm/wtmp because the chroot to /usr/ftp is done before wtmp is
opened; thus the open always fails. My previous fix to this was not
wonderful, because while it correctly record logins, it never recorded
logouts. This version does both. I also changed logging to be done via
syslog(3), and now log the ident supplied by anonymous users as well as
all connections.
Repeat-By:
ftp to localhost, log in as ftp, quit, and do a last. No record.
Fix:
Apply the following diffs to ftpd.c; note that logging must be
explicitly enabled with -l in /etc/rc.local.
RCS file: RCS/ftpd.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -c -r1.1 -r1.2
*** /tmp/,RCSt1006490 Fri Jan 13 12:21:37 1984
--- /tmp/,RCSt2006490 Fri Jan 13 12:21:43 1984
***************
*** 1,5
#ifndef lint
! static char rcsid[] = "$Header: /usr/src/etc/ftpd/RCS/ftpd.c,v 1.1 84/01/11 19:46:08 cak Rel $";
static char sccsid[] = "@(#)ftpd.c 4.28 (Berkeley) 9/22/83";
#endif
--- 1,5 -----
#ifndef lint
! static char rcsid[] = "$Header: /usr/src/etc/ftpd/RCS/ftpd.c,v 1.2 84/01/13 11:55:30 cak Exp $";
static char sccsid[] = "@(#)ftpd.c 4.28 (Berkeley) 9/22/83";
#endif
***************
*** 55,60
int timeout;
int logging;
int guest;
int type;
int form;
int stru; /* avoid C keyword */
--- 55,61 -----
int timeout;
int logging;
int guest;
+ int wtmp;
int type;
int form;
int stru; /* avoid C keyword */
***************
*** 235,240
pw->pw_name, pw->pw_dir);
goto bad;
}
if (guest && chroot(pw->pw_dir) < 0) {
reply(550, "Can't set guest privileges.");
goto bad;
--- 236,245 -----
pw->pw_name, pw->pw_dir);
goto bad;
}
+
+ if (guest) /* grab wtmp before chroot */
+ wtmp = open("/usr/adm/wtmp", O_WRONLY|O_APPEND);
+
if (guest && chroot(pw->pw_dir) < 0) {
reply(550, "Can't set guest privileges.");
goto bad;
***************
*** 724,730
dologin(pw)
struct passwd *pw;
{
- int wtmp;
char line[32];
wtmp = open("/usr/adm/wtmp", O_WRONLY|O_APPEND);
--- 729,734 -----
dologin(pw)
struct passwd *pw;
{
char line[32];
if (guest && (wtmp >= 0))
***************
*** 727,733
int wtmp;
char line[32];
! wtmp = open("/usr/adm/wtmp", O_WRONLY|O_APPEND);
if (wtmp >= 0) {
/* hack, but must be unique and no tty line */
sprintf(line, "ftp%d", getpid());
--- 731,740 -----
{
char line[32];
! if (guest && (wtmp >= 0))
! lseek(wtmp, 0, L_XTND);
! else
! wtmp = open("/usr/adm/wtmp", O_WRONLY|O_APPEND);
if (wtmp >= 0) {
/* hack, but must be unique and no tty line */
sprintf(line, "ftp%d", getpid());
***************
*** 736,742
SCPYN(utmp.ut_host, remotehost);
utmp.ut_time = time(0);
(void) write(wtmp, (char *)&utmp, sizeof (utmp));
! (void) close(wtmp);
}
}
--- 743,750 -----
SCPYN(utmp.ut_host, remotehost);
utmp.ut_time = time(0);
(void) write(wtmp, (char *)&utmp, sizeof (utmp));
! if (!guest)
! (void) close(wtmp);
}
}
***************
*** 747,754
dologout(status)
int status;
{
- int wtmp;
-
if (!logged_in)
_exit(status);
seteuid(0);
--- 755,760 -----
dologout(status)
int status;
{
if (!logged_in)
_exit(status);
seteuid(0);
***************
*** 752,758
if (!logged_in)
_exit(status);
seteuid(0);
! wtmp = open("/usr/adm/wtmp", O_WRONLY|O_APPEND);
if (wtmp >= 0) {
SCPYN(utmp.ut_name, "");
SCPYN(utmp.ut_host, "");
--- 758,767 -----
if (!logged_in)
_exit(status);
seteuid(0);
! if (guest && (wtmp >= 0))
! lseek(wtmp, 0, L_XTND);
! else
! wtmp = open("/usr/adm/wtmp", O_WRONLY|O_APPEND);
if (wtmp >= 0) {
SCPYN(utmp.ut_name, "");
SCPYN(utmp.ut_host, "");
----------
More information about the Comp.unix.wizards
mailing list