diff options
author | Jason Downs <downsj@cvs.openbsd.org> | 1996-07-28 22:42:47 +0000 |
---|---|---|
committer | Jason Downs <downsj@cvs.openbsd.org> | 1996-07-28 22:42:47 +0000 |
commit | 929d2ac4bd3458c1901a52e32e0a5528e3bc9fed (patch) | |
tree | ccbb87a6c78222201de6dd916372875b422a0ad2 | |
parent | 4370e5be1ae72f684ef8ea2653cad1259ca997a6 (diff) |
Add anonymous statistics logging, based on FreeBSD but with the really
obvious bugs fixed.
-rw-r--r-- | libexec/ftpd/Makefile | 4 | ||||
-rw-r--r-- | libexec/ftpd/ftpd.8 | 12 | ||||
-rw-r--r-- | libexec/ftpd/ftpd.c | 73 | ||||
-rw-r--r-- | libexec/ftpd/pathnames.h | 2 |
4 files changed, 84 insertions, 7 deletions
diff --git a/libexec/ftpd/Makefile b/libexec/ftpd/Makefile index 7543ec7a0e8..c56268b7873 100644 --- a/libexec/ftpd/Makefile +++ b/libexec/ftpd/Makefile @@ -1,9 +1,9 @@ -# $OpenBSD: Makefile,v 1.5 1996/06/18 10:09:15 downsj Exp $ +# $OpenBSD: Makefile,v 1.6 1996/07/28 22:42:44 downsj Exp $ # $NetBSD: Makefile,v 1.13 1996/02/16 02:07:41 cgd Exp $ # @(#)Makefile 8.2 (Berkeley) 4/4/94 PROG= ftpd -CFLAGS+=-DHASSETPROCTITLE -Dunix +CFLAGS+=-DHASSETPROCTITLE -DSTATS -Dunix SRCS= ftpd.c ftpcmd.c logutmp.c logwtmp.c popen.c MAN= ftpd.8 CLEANFILES+=ftpcmd.c y.tab.h diff --git a/libexec/ftpd/ftpd.8 b/libexec/ftpd/ftpd.8 index 307b461adb0..1e2b91b8cd4 100644 --- a/libexec/ftpd/ftpd.8 +++ b/libexec/ftpd/ftpd.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ftpd.8,v 1.3 1996/06/18 10:09:17 downsj Exp $ +.\" $OpenBSD: ftpd.8,v 1.4 1996/07/28 22:42:45 downsj Exp $ .\" $NetBSD: ftpd.8,v 1.8 1996/01/14 20:55:23 thorpej Exp $ .\" .\" Copyright (c) 1985, 1988, 1991, 1993 @@ -43,7 +43,7 @@ Internet File Transfer Protocol server .Sh SYNOPSIS .Nm ftpd -.Op Fl dlU +.Op Fl dlSU .Op Fl T Ar maxtimeout .Op Fl t Ar timeout .Op Fl u Ar mask @@ -70,6 +70,12 @@ session is logged using syslog with a facility of LOG_FTP. If this option is specified twice, the retrieve (get), store (put), append, delete, make directory, remove directory and rename operations and their filename arguments are also logged. +.It Fl S +With this option set, +.Nm ftpd +logs all anonymous transfers to the file +.Pa /var/log/ftpd +when this file exists. .It Fl U Each concurrent .Xr ftp 1 @@ -310,6 +316,8 @@ Welcome notice after login. Displayed and access refused. .It Pa /var/run/utmp List of users on the system. +.It Pa /var/log/ftpd +Log file for anonymous transfers. .El .Sh SEE ALSO .Xr ftp 1 , diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c index 55a45d71d23..5c0bde903ca 100644 --- a/libexec/ftpd/ftpd.c +++ b/libexec/ftpd/ftpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ftpd.c,v 1.4 1996/07/28 19:45:36 downsj Exp $ */ +/* $OpenBSD: ftpd.c,v 1.5 1996/07/28 22:42:45 downsj Exp $ */ /* $NetBSD: ftpd.c,v 1.15 1995/06/03 22:46:47 mycroft Exp $ */ /* @@ -115,6 +115,10 @@ int timeout = 900; /* timeout after 15 minutes of inactivity */ int maxtimeout = 7200;/* don't allow idle time to be set beyond 2 hours */ int logging; int guest; +#ifdef STATS +int stats; +int statfd = -1; +#endif int dochroot; int type; int form; @@ -141,7 +145,14 @@ static struct utmp utmp; /* for utmp */ #if defined(KERBEROS) int notickets = 1; char *krbtkfile_env = NULL; -#endif +#endif + +#ifdef STATS +char *ident = NULL; + +void logxfer __P((char *, off_t, time_t)); +#endif + /* * Timeout intervals for retrying connections @@ -215,6 +226,11 @@ main(argc, argv, envp) int addrlen, ch, on = 1, tos; char *cp, line[LINE_MAX]; FILE *fd; +#ifdef STATS + char *argstr = "dlSt:T:u:Uv"; +#else + char *argstr = "dlt:T:u:Uv"; +#endif /* * LOG_NDELAY sets up the logging connection immediately, @@ -242,7 +258,7 @@ main(argc, argv, envp) /* set this here so klogin can use it... */ (void)snprintf(ttyline, sizeof(ttyline), "ftp%d", getpid()); - while ((ch = getopt(argc, argv, "dlt:T:u:Uv")) != EOF) { + while ((ch = getopt(argc, argv, argstr)) != EOF) { switch (ch) { case 'd': debug = 1; @@ -252,6 +268,12 @@ main(argc, argv, envp) logging++; /* > 1 == extra logging */ break; +#ifdef STATS + case 'S': + stats = 1; + break; +#endif + case 't': timeout = atoi(optarg); if (maxtimeout < timeout) @@ -620,6 +642,13 @@ skip: login(&utmp); } +#ifdef STATS + /* open stats file before chroot */ + if (guest && (stats == 1) && (statfd < 0)) + if ((statfd = open(_PATH_FTPDSTATFILE, O_WRONLY|O_APPEND)) < 0) + stats = 0; +#endif + logged_in = 1; dochroot = checkuser(_PATH_FTPCHROOT, pw->pw_name); @@ -666,6 +695,13 @@ skip: (void) fclose(fd); } if (guest) { +#ifdef STATS + if (ident != NULL) + free(ident); + ident = strdup(passwd); + if (ident == (char *)NULL) + fatal("Ran out of memory."); +#endif reply(230, "Guest login ok, access restrictions apply."); #ifdef HASSETPROCTITLE snprintf(proctitle, sizeof(proctitle), @@ -702,6 +738,9 @@ retrieve(cmd, name) FILE *fin, *dout; struct stat st; int (*closefunc) __P((FILE *)); +#ifdef STATS + time_t start; +#endif if (cmd == 0) { fin = fopen(name, "r"), closefunc = fclose; @@ -751,8 +790,15 @@ retrieve(cmd, name) dout = dataconn(name, st.st_size, "w"); if (dout == NULL) goto done; +#ifdef STATS + time(&start); +#endif send_data(fin, dout, st.st_blksize, st.st_size, (restart_point == 0 && cmd == 0 && S_ISREG(st.st_mode))); +#ifdef STATS + if ((cmd == 0) && guest && stats) + logxfer(name, st.st_size, start); +#endif (void) fclose(dout); data = -1; pdata = -1; @@ -1752,3 +1798,24 @@ out: globfree(&gl); } } + +#ifdef STATS +void +logxfer(name, size, start) + char *name; + off_t size; + time_t start; +{ + char buf[1024]; + char path[MAXPATHLEN + 1]; + time_t now; + + if ((statfd >= 0) && (getwd(path) != NULL)) { + time(&now); + snprintf(buf, sizeof(buf), "%.20s!%s!%s!%s/%s!%qd!%ld\n", + ctime(&now)+4, ident, remotehost, + path, name, size, now - start + (now == start)); + write(statfd, buf, strlen(buf)); + } +} +#endif diff --git a/libexec/ftpd/pathnames.h b/libexec/ftpd/pathnames.h index fd262360b56..99d7c8bdf21 100644 --- a/libexec/ftpd/pathnames.h +++ b/libexec/ftpd/pathnames.h @@ -1,3 +1,4 @@ +/* $OpenBSD: pathnames.h,v 1.2 1996/07/28 22:42:46 downsj Exp $ */ /* $NetBSD: pathnames.h,v 1.5 1995/04/11 02:44:59 cgd Exp $ */ /* @@ -41,3 +42,4 @@ #define _PATH_FTPCHROOT "/etc/ftpchroot" #define _PATH_FTPWELCOME "/etc/ftpwelcome" #define _PATH_FTPLOGINMESG "/etc/motd" +#define _PATH_FTPDSTATFILE "/var/log/ftpd" |