Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/libexec/ftpd features/fixes:
details: https://anonhg.NetBSD.org/src/rev/7a9c8fb2d6ad
branches: trunk
changeset: 473024:7a9c8fb2d6ad
user: lukem <lukem%NetBSD.org@localhost>
date: Mon May 17 15:14:53 1999 +0000
description:
features/fixes:
* implement xferstats. full stats are displayed for `STAT', and a
summary is displayed upon exit (and syslogged). inspired by wu-ftpd.
* wrap data xfers in {send,receive}_data with alarm() timeouts. this
should remove the majority of the `hanging ftpd' problems that
people were still seeing. inspired by wu-ftpd.
* link with ../../bin/ls, so that bin/ls is not required under a
chroot()ed area for `LIST' to work. based on [bin/4497] from
"Soren S. Jorvang" <soren%t.dk@localhost>
* migrate code from util.c into ftpd.c, so that it doesn't conflict
with ls' util.c.
* remove man page comment about ~ftp/bin/ls being necessary.
* bump version to 7.2.0.
* syslog xfer time with xfer stats.
* if appropriate, syslog error message with command.
internal code stuff:
* change arguments of various functions from `char *' to `const char *'.
* define PLURAL(x) macro, which returns `' if x == 1, `s' otherwise.
use macro appropriately
* lreply(): a code of -1 means ``send line as is''. a code of 0
means ``send line with 4 space prefix''. don't print a space after
the `-' for any other code.
* logcmd(): add `const struct timeval *elapsed' and `const char *error'
for more flexible error reporting
diffstat:
libexec/ftpd/Makefile | 9 +-
libexec/ftpd/conf.c | 9 +-
libexec/ftpd/extern.h | 35 +-
libexec/ftpd/ftpcmd.y | 66 ++++-
libexec/ftpd/ftpd.8 | 22 +-
libexec/ftpd/ftpd.c | 613 ++++++++++++++++++++++++++++++++++++-------------
libexec/ftpd/popen.c | 20 +-
libexec/ftpd/util.c | 107 --------
8 files changed, 563 insertions(+), 318 deletions(-)
diffs (truncated from 1673 to 300 lines):
diff -r 8b5451ee2cb7 -r 7a9c8fb2d6ad libexec/ftpd/Makefile
--- a/libexec/ftpd/Makefile Mon May 17 12:16:03 1999 +0000
+++ b/libexec/ftpd/Makefile Mon May 17 15:14:53 1999 +0000
@@ -1,14 +1,17 @@
-# $NetBSD: Makefile,v 1.30 1999/02/18 21:22:51 scottr Exp $
+# $NetBSD: Makefile,v 1.31 1999/05/17 15:14:53 lukem Exp $
# @(#)Makefile 8.2 (Berkeley) 4/4/94
PROG= ftpd
-SRCS= conf.c ftpd.c ftpcmd.y logwtmp.c popen.c util.c
+SRCS= conf.c ftpd.c ftpcmd.y logwtmp.c popen.c
CPPFLAGS+=-DHASSETPROCTITLE
DPADD+= ${LIBCRYPT}
LDADD+= -lcrypt
MAN= ftpd.8
MLINKS+=ftpd.8 ftpd.conf.5
-.PATH: ${.CURDIR}/../../usr.bin/ftp ${.CURDIR}/../../usr.bin/login
+
+# for `internal' ls
+SRCS+= ls.c cmp.c print.c stat_flags.c util.c
+.PATH: ${.CURDIR}/../../bin/ls
.include <bsd.own.mk>
diff -r 8b5451ee2cb7 -r 7a9c8fb2d6ad libexec/ftpd/conf.c
--- a/libexec/ftpd/conf.c Mon May 17 12:16:03 1999 +0000
+++ b/libexec/ftpd/conf.c Mon May 17 15:14:53 1999 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: conf.c,v 1.18 1999/02/24 16:45:13 explorer Exp $ */
+/* $NetBSD: conf.c,v 1.19 1999/05/17 15:14:54 lukem Exp $ */
/*-
- * Copyright (c) 1997 The NetBSD Foundation, Inc.
+ * Copyright (c) 1997, 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: conf.c,v 1.18 1999/02/24 16:45:13 explorer Exp $");
+__RCSID("$NetBSD: conf.c,v 1.19 1999/05/17 15:14:54 lukem Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -379,7 +379,7 @@
t = localtime(&then);
age -= 365 * t->tm_year + t->tm_yday;
lreply(code, " it was last modified on %.24s - %d day%s ago",
- ctime(&then), age, age == 1 ? "" : "s");
+ ctime(&then), age, PLURAL(age));
}
globfree(&gl);
}
@@ -485,6 +485,5 @@
}
snprintf(cmd, LINE_MAX, cp->command, base);
- syslog(LOG_DEBUG, "get command: %s", cmd);
return(cmd);
}
diff -r 8b5451ee2cb7 -r 7a9c8fb2d6ad libexec/ftpd/extern.h
--- a/libexec/ftpd/extern.h Mon May 17 12:16:03 1999 +0000
+++ b/libexec/ftpd/extern.h Mon May 17 15:14:53 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.15 1998/12/28 04:54:01 lukem Exp $ */
+/* $NetBSD: extern.h,v 1.16 1999/05/17 15:14:54 lukem Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -39,33 +39,34 @@
char *conffilename __P((const char *));
char **copyblk __P((char **));
void cwd __P((const char *));
-void delete __P((char *));
+void delete __P((const char *));
char *do_conversion __P((const char *));
void dologout __P((int));
-void fatal __P((char *));
+void fatal __P((const char *));
int ftpd_pclose __P((FILE *));
FILE *ftpd_popen __P((char *, char *, int));
char *getline __P((char *, int, FILE *));
-void logcmd __P((const char *, off_t, const char *, const char *));
+void logcmd __P((const char *, off_t, const char *, const char *,
+ const struct timeval *, const char *));
void logwtmp __P((const char *, const char *, const char *));
void lreply __P((int, const char *, ...));
-void makedir __P((char *));
+void makedir __P((const char *));
void parse_conf __P((char *));
-void pass __P((char *));
+void pass __P((const char *));
void passive __P((void));
void perror_reply __P((int, const char *));
void pwd __P((void));
-void removedir __P((char *));
-void renamecmd __P((char *, char *));
+void removedir __P((const char *));
+void renamecmd __P((const char *, const char *));
char *renamefrom __P((char *));
void reply __P((int, const char *, ...));
-void retrieve __P((char *, char *));
-void send_file_list __P((char *));
+void retrieve __P((const char *, const char *));
+void send_file_list __P((const char *));
void show_chdir_messages __P((int));
void statcmd __P((void));
-void statfilecmd __P((char *));
-void store __P((char *, char *, int));
-void user __P((char *));
+void statfilecmd __P((const char *));
+void store __P((const char *, const char *, int));
+void user __P((const char *));
char *xstrdup __P((const char *));
void yyerror __P((char *));
@@ -120,3 +121,11 @@
extern int type;
extern int usedefault;
extern const char version[];
+
+extern off_t total_data_in, total_data_out, total_data;
+extern off_t total_files_in, total_files_out, total_files;
+extern off_t total_bytes_in, total_bytes_out, total_bytes;
+extern off_t total_xfers_in, total_xfers_out, total_xfers;
+
+
+#define PLURAL(s) ((s) == 1 ? "" : "s")
diff -r 8b5451ee2cb7 -r 7a9c8fb2d6ad libexec/ftpd/ftpcmd.y
--- a/libexec/ftpd/ftpcmd.y Mon May 17 12:16:03 1999 +0000
+++ b/libexec/ftpd/ftpcmd.y Mon May 17 15:14:53 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ftpcmd.y,v 1.26 1999/02/24 16:45:13 explorer Exp $ */
+/* $NetBSD: ftpcmd.y,v 1.27 1999/05/17 15:14:54 lukem Exp $ */
/*
* Copyright (c) 1985, 1988, 1993, 1994
@@ -47,7 +47,7 @@
#if 0
static char sccsid[] = "@(#)ftpcmd.y 8.3 (Berkeley) 4/6/94";
#else
-__RCSID("$NetBSD: ftpcmd.y,v 1.26 1999/02/24 16:45:13 explorer Exp $");
+__RCSID("$NetBSD: ftpcmd.y,v 1.27 1999/05/17 15:14:54 lukem Exp $");
#endif
#endif /* not lint */
@@ -185,6 +185,27 @@
| QUIT CRLF
{
+ if (logged_in) {
+ lreply(221,
+ "Data traffic for this session was %qd byte%s in %qd file%s.",
+ total_data, PLURAL(total_data),
+ total_files, PLURAL(total_files));
+ lreply(221,
+ "Total traffic for this session was %qd byte%s in %qd transfer%s.",
+ total_bytes, PLURAL(total_bytes),
+ total_xfers, PLURAL(total_xfers));
+ syslog(LOG_INFO,
+ "Data traffic: %qd byte%s in %qd file%s",
+ total_data, PLURAL(total_data),
+ total_files, PLURAL(total_files));
+ syslog(LOG_INFO,
+ "Total traffic: %qd byte%s in %qd transfer%s",
+ total_bytes, PLURAL(total_bytes),
+ total_xfers, PLURAL(total_xfers));
+ }
+ lreply(211,
+ "Thank you for using the FTP service on %s.",
+ hostname);
reply(221, "Goodbye.");
dologout(0);
}
@@ -564,10 +585,10 @@
| FEAT CRLF
{
lreply(211, "Features supported");
- printf(" MDTM\r\n");
- printf(" REST STREAM\r\n");
- printf(" SIZE\r\n");
- reply(211, "End");
+ lreply(-1, " MDTM");
+ lreply(-1, " REST STREAM");
+ lreply(-1, " SIZE");
+ reply(211, "End");
}
| OPTS SP STRING CRLF
@@ -1026,6 +1047,7 @@
int n;
FILE *iop;
{
+ off_t b;
int c;
char *cs;
@@ -1044,21 +1066,33 @@
tmpline[0] = '\0';
}
while ((c = getc(iop)) != EOF) {
+ total_bytes++;
+ total_bytes_in++;
c &= 0377;
if (c == IAC) {
if ((c = getc(iop)) != EOF) {
+ total_bytes++;
+ total_bytes_in++;
c &= 0377;
switch (c) {
case WILL:
case WONT:
c = getc(iop);
- printf("%c%c%c", IAC, DONT, 0377&c);
+ total_bytes++;
+ total_bytes_in++;
+ b = printf("%c%c%c", IAC, DONT, 0377&c);
+ total_bytes += b;
+ total_bytes_out += b;
(void) fflush(stdout);
continue;
case DO:
case DONT:
c = getc(iop);
- printf("%c%c%c", IAC, WONT, 0377&c);
+ total_bytes++;
+ total_bytes_in++;
+ b = printf("%c%c%c", IAC, WONT, 0377&c);
+ total_bytes += b;
+ total_bytes_out += b;
(void) fflush(stdout);
continue;
case IAC:
@@ -1360,6 +1394,7 @@
{
struct tab *c;
int width, NCMDS;
+ off_t b;
char *type;
if (ctab == sitetab)
@@ -1380,17 +1415,20 @@
int columns, lines;
lreply(214, "The following %scommands are recognized.", type);
- printf(
- " (`-' = not implemented, `+' = supports options)\r\n");
+ lreply(0, "(`-' = not implemented, `+' = supports options)");
columns = 76 / width;
if (columns == 0)
columns = 1;
lines = (NCMDS + columns - 1) / columns;
for (i = 0; i < lines; i++) {
- printf(" ");
+ b = printf(" ");
+ total_bytes += b;
+ total_bytes_out += b;
for (j = 0; j < columns; j++) {
c = ctab + j * lines + i;
- fputs(c->name, stdout);
+ b = printf("%s", c->name);
+ total_bytes += b;
+ total_bytes_out += b;
w = strlen(c->name);
if (! c->implemented) {
putchar('-');
@@ -1407,7 +1445,9 @@
w++;
}
}
- printf("\r\n");
+ b = printf("\r\n");
+ total_bytes += b;
+ total_bytes_out += b;
}
(void) fflush(stdout);
reply(214, "Direct comments to ftp-bugs@%s.", hostname);
diff -r 8b5451ee2cb7 -r 7a9c8fb2d6ad libexec/ftpd/ftpd.8
--- a/libexec/ftpd/ftpd.8 Mon May 17 12:16:03 1999 +0000
+++ b/libexec/ftpd/ftpd.8 Mon May 17 15:14:53 1999 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: ftpd.8,v 1.35 1999/03/22 18:25:44 garbled Exp $
+.\" $NetBSD: ftpd.8,v 1.36 1999/05/17 15:14:54 lukem Exp $
.\"
.\" Copyright (c) 1985, 1988, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -33,7 +33,7 @@
.\"
.\" @(#)ftpd.8 8.2 (Berkeley) 4/19/94
.\"
-.Dd September 7, 1998
+.Dd May 18, 1999
.Dt FTPD 8
.Os
.Sh NAME
@@ -535,12 +535,8 @@
Make this directory owned by
.Dq root
Home |
Main Index |
Thread Index |
Old Index