Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site ut-sally.UUCP Path: utzoo!linus!security!genrad!grkermit!masscomp!clyde!floyd!harpo!seismo!ut-sally!jsq From: jsq@ut-sally.UUCP Newsgroups: net.unix-wizards Subject: Re: ftpd doesn't log anonymous logins Message-ID: <787@ut-sally.UUCP> Date: Tue, 17-Jan-84 14:01:08 EST Article-I.D.: ut-sally.787 Posted: Tue Jan 17 14:01:08 1984 Date-Received: Wed, 18-Jan-84 07:36:13 EST References: <15447@sri-arpa.UUCP> Organization: U. Texas CS Dept., Austin, Texas Lines: 196 Cak@Purdue's fix to logging of anonymous logins by ftpd in wtmp had several problems. The following is another fix for the same but, which has been run by cak for criticism. I will submit it to Berkeley shortly. *** ftpd.c.dist Tue Jan 17 12:33:52 1984 --- ftpd.c Tue Jan 17 12:41:11 1984 *************** *** 234,242 pw->pw_name, pw->pw_dir); goto bad; } ! if (guest && chroot(pw->pw_dir) < 0) { ! reply(550, "Can't set guest privileges."); ! goto bad; } if (!guest) reply(230, "User %s logged in.", pw->pw_name); --- 234,246 ----- pw->pw_name, pw->pw_dir); goto bad; } ! if (guest) { ! dologset(1); ! if (chroot(pw->pw_dir) < 0) { ! dologset(0); ! reply(550, "Can't set guest privileges."); ! goto bad; ! } } if (!guest) reply(230, "User %s logged in.", pw->pw_name); *************** *** 716,721 #define SCPYN(a, b) strncpy(a, b, sizeof (a)) struct utmp utmp; /* * Record login in wtmp file. --- 720,726 ----- #define SCPYN(a, b) strncpy(a, b, sizeof (a)) struct utmp utmp; + int wtmp = -1; /* * Open or close wtmp. *************** *** 718,723 struct utmp utmp; /* * Record login in wtmp file. */ dologin(pw) --- 723,745 ----- int wtmp = -1; /* + * Open or close wtmp. + */ + dologset(flag) + int flag; + { + if (flag) { + if (wtmp < 0) + wtmp = open("/usr/adm/wtmp", O_WRONLY|O_APPEND); + return; + } + if (wtmp < 0) + return; + (void) close (wtmp); + wtmp = -1; + } + + /* * Record login in wtmp file. */ dologin(pw) *************** *** 723,729 dologin(pw) struct passwd *pw; { - int wtmp; char line[32]; wtmp = open("/usr/adm/wtmp", O_WRONLY|O_APPEND); --- 745,750 ----- dologin(pw) struct passwd *pw; { char line[32]; dologset(1); *************** *** 726,732 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()); --- 747,753 ----- { char line[32]; ! dologset(1); if (wtmp >= 0) { /* hack, but must be unique and no tty line */ sprintf(line, "ftp%d", getpid()); *************** *** 735,741 SCPYN(utmp.ut_host, remotehost); utmp.ut_time = time(0); (void) write(wtmp, (char *)&utmp, sizeof (utmp)); ! (void) close(wtmp); } } --- 756,763 ----- SCPYN(utmp.ut_host, remotehost); utmp.ut_time = time(0); (void) write(wtmp, (char *)&utmp, sizeof (utmp)); ! if (!guest) ! dologset(0); } } *************** *** 746,753 dologout(status) int status; { - int wtmp; - if (!logged_in) _exit(status); seteuid(0); --- 768,773 ----- dologout(status) int status; { if (!logged_in) _exit(status); seteuid(0); *************** *** 751,757 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, ""); --- 771,778 ----- if (!logged_in) _exit(status); seteuid(0); ! if (!guest) ! dologset(1); if (wtmp >= 0) { SCPYN(utmp.ut_name, ""); SCPYN(utmp.ut_host, ""); *************** *** 757,763 SCPYN(utmp.ut_host, ""); utmp.ut_time = time(0); (void) write(wtmp, (char *)&utmp, sizeof (utmp)); ! (void) close(wtmp); } /* beware of flushing buffers after a SIGPIPE */ _exit(status); --- 778,784 ----- SCPYN(utmp.ut_host, ""); utmp.ut_time = time(0); (void) write(wtmp, (char *)&utmp, sizeof (utmp)); ! dologset(0); } /* beware of flushing buffers after a SIGPIPE */ _exit(status); -- John Quarterman, CS Dept., University of Texas, Austin, Texas {ihnp4,seismo,ctvax}!ut-sally!jsq, jsq@ut-sally.{ARPA,UUCP}