From 7e8037880004b03fd1b66d81df5a59d6fde8d66e Mon Sep 17 00:00:00 2001 From: lukem Date: Sun, 9 Jan 2000 10:08:45 +0000 Subject: [PATCH] * new ftpd.conf directive: template class [refclass] following directives for refclass will apply to class as well. this makes setting up a `template' class with many default settings easy, whilst allowing for class-specific overrides * prevent crash when the optional limitfile wasn't given to limit * document count_users() * document default setting of limit in ftpd.conf(5) * crank version --- libexec/ftpd/conf.c | 29 ++++++++++++++++++++++------- libexec/ftpd/ftpd.conf.5 | 30 +++++++++++++++++++++++++----- libexec/ftpd/version.h | 4 ++-- 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/libexec/ftpd/conf.c b/libexec/ftpd/conf.c index 404ae124c68e..7751515a474c 100644 --- a/libexec/ftpd/conf.c +++ b/libexec/ftpd/conf.c @@ -1,4 +1,4 @@ -/* $NetBSD: conf.c,v 1.25 2000/01/08 11:09:56 lukem Exp $ */ +/* $NetBSD: conf.c,v 1.26 2000/01/09 10:08:45 lukem Exp $ */ /*- * Copyright (c) 1997-2000 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include #ifndef lint -__RCSID("$NetBSD: conf.c,v 1.25 2000/01/08 11:09:56 lukem Exp $"); +__RCSID("$NetBSD: conf.c,v 1.26 2000/01/09 10:08:45 lukem Exp $"); #endif /* not lint */ #include @@ -101,8 +101,6 @@ init_curclass() REASSIGN(curclass.motd, xstrdup(_PATH_FTPLOGINMESG)); REASSIGN(curclass.notify, NULL); curclass.passive = 1; - curclass.maxrateget = 0; - curclass.maxrateput = 0; curclass.rateget = 0; curclass.rateput = 0; curclass.timeout = 900; /* 15 minutes */ @@ -124,7 +122,7 @@ parse_conf(findclass) size_t len; int none, match, rate; char *endp; - char *class, *word, *arg; + char *class, *word, *arg, *template; const char *infile; size_t line; unsigned int timeout; @@ -142,6 +140,7 @@ parse_conf(findclass) return; line = 0; + template = NULL; for (; (buf = fparseln(f, &len, &line, NULL, FPARSELN_UNESCCOMM | FPARSELN_UNESCCONT | FPARSELN_UNESCESC)) != NULL; @@ -162,7 +161,8 @@ parse_conf(findclass) continue; if (strcasecmp(class, "none") == 0) none = 1; - if (strcasecmp(class, findclass) != 0 && + if ((strcasecmp(class, findclass) != 0 && + (template != NULL && strcasecmp(class, template) != 0)) && !none && strcasecmp(class, "all") != 0) continue; @@ -261,7 +261,8 @@ parse_conf(findclass) continue; } curclass.limit = limit; - REASSIGN(curclass.limitfile, xstrdup(p)); + REASSIGN(curclass.limitfile, + EMPTYSTR(p) ? NULL : xstrdup(p)); } else if (strcasecmp(word, "maxtimeout") == 0) { if (none || EMPTYSTR(arg)) @@ -368,6 +369,11 @@ parse_conf(findclass) } curclass.timeout = timeout; + } else if (strcasecmp(word, "template") == 0) { + if (none) + continue; + REASSIGN(template, EMPTYSTR(arg) ? NULL : xstrdup(arg)); + } else if (strcasecmp(word, "umask") == 0) { mode_t umask; @@ -397,6 +403,7 @@ parse_conf(findclass) continue; } } + REASSIGN(template, NULL); fclose(f); } @@ -742,6 +749,14 @@ strsuftoi(arg) return (val); } +/* + * Count the number of current connections, reading from + * /var/run/ftpd.pids- + * Does a kill -0 on each pid in that file, and only counts + * processes that exist (or frees the slot if it doesn't). + * Adds getpid() to the first free slot. Truncates the file + * if possible. + */ void count_users() { diff --git a/libexec/ftpd/ftpd.conf.5 b/libexec/ftpd/ftpd.conf.5 index b5dbcfaf8871..a38374e28a77 100644 --- a/libexec/ftpd/ftpd.conf.5 +++ b/libexec/ftpd/ftpd.conf.5 @@ -1,4 +1,4 @@ -.\" $NetBSD: ftpd.conf.5,v 1.6 2000/01/08 11:09:56 lukem Exp $ +.\" $NetBSD: ftpd.conf.5,v 1.7 2000/01/09 10:08:45 lukem Exp $ .\" .\" Copyright (c) 1997-2000 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -34,7 +34,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd January 8, 2000 +.Dd January 9, 2000 .Dt FTPD.CONF 5 .Os .Sh NAME @@ -200,7 +200,7 @@ Otherwise, each time the user enters a new directory, check if exists, and if so, display its contents to the user. Escape sequences are supported; refer to .Sx Display file escape sequences -in +in .Xr ftpd 8 for more information. .It Xo Sy limit Ar class @@ -258,7 +258,7 @@ Otherwise, use as the message of the day file to display after login. Escape sequences are supported; refer to .Sx Display file escape sequences -in +in .Xr ftpd 8 for more information. .It Sy notify Ar class Op Ar fileglob @@ -290,7 +290,7 @@ If .Ar rate is 0, the throttle is disabled. .Pp -An optional suffix may be provided, which changes the intrepretation of +An optional suffix may be provided, which changes the intrepretation of .Ar rate as follows: .Bl -tag -width 3n -offset indent -compact @@ -310,6 +310,25 @@ to .Ar rate , which is parsed as per .Sy rateget Ar rate . +.It Sy template Ar class Op Ar refclass +Define +.Ar refclass +as the +.Sq template +for +.Ar class ; +any reference to +.Ar refclass +in following directives will also apply to members of +.Ar class . +This is useful to define a template class so that other classes which are +to share common attributes can be easily defined without unnecessary +duplication. +There can be only one template defined at a time. +If +.Ar refclass +is not given, disable the template for +.Ar class . .It Sy timeout Ar class Ar time Set the inactivity timeout period. (the default is fifteen minutes). @@ -354,6 +373,7 @@ classtype chroot CHROOT classtype guest GUEST classtype real REAL display none +limit all -1 # unlimited connections maxtimeout all 7200 # 2 hours modify all motd all motd diff --git a/libexec/ftpd/version.h b/libexec/ftpd/version.h index bf924ae325f6..d89b72a348bb 100644 --- a/libexec/ftpd/version.h +++ b/libexec/ftpd/version.h @@ -1,4 +1,4 @@ -/* $NetBSD: version.h,v 1.4 2000/01/08 11:09:56 lukem Exp $ */ +/* $NetBSD: version.h,v 1.5 2000/01/09 10:08:45 lukem Exp $ */ /*- * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc. * All rights reserved. @@ -36,5 +36,5 @@ */ #ifndef FTPD_VERSION -#define FTPD_VERSION "Version: NetBSD-ftpd/20000108" +#define FTPD_VERSION "Version: NetBSD-ftpd/20000109" #endif