Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/libexec/ftpd - new ftpd.conf directives:



details:   https://anonhg.NetBSD.org/src/rev/fac1edb9329d
branches:  trunk
changeset: 499303:fac1edb9329d
user:      lukem <lukem%NetBSD.org@localhost>
date:      Thu Nov 16 13:15:13 2000 +0000

description:
- new ftpd.conf directives:
        maxfilesize     set the maximum size of uploaded files
        sanenames       if set, only permit uploaded filenames that contain
                        characters from the set "-+,._A-Za-z0-9" and that
                        don't start with `.'

- new/changed command line options:
        -e emailaddr    define email address for %E (see below)
        -P dataport     use dataport as the dataport (instead of ctrlport-1)
        -q              use pid files to count users    [default]
        -Q              don't use pid files to count users
        -u              write entries to utmp
        -U              don't write entries to utmp     [default]
        -w              write entries to wtmp           [default]
        -W              don't write entries to wtmp

          NOTE: -U used to mean `write utmp entries'. Its meaning has changed
                so that it's orthogonal with -q/-Q and -w/-W. This isn't
                considered a major problem, because using -U isn't going to
                enable something you don't want, but will disable something
                you did want (which is safer).

- new display file escape sequences:
        %E      email address
        %s      literal `s' if the previous %M or %N wasn't ``1''.
        %S      literal `S' if the previous %M or %N wasn't ``1''.

- expand the description of building ~ftp/incoming to cover the
  appropriate ftpd.conf(5) directives (which are defaults, but it pays
  to explicitly explain them)

- replace strsuftoi() with strsuftoll(), which returns a long long if
  supported, otherwise a long

- rework the way that check_modify and check_upload are done in the yacc
  parser; they're merged into a common check_write() function which is
  called explicitly

- merge all ftpclass `flag variables' into a single bitfield-based flag element

- move various common bits of parse_conf() into a couple of macros

- clean up some comments

diffstat:

 libexec/ftpd/cmds.c      |   20 ++--
 libexec/ftpd/conf.c      |  170 +++++++++++++++++++---------------
 libexec/ftpd/extern.h    |   85 +++++++++-------
 libexec/ftpd/ftpcmd.y    |  235 ++++++++++++++++++++++++----------------------
 libexec/ftpd/ftpd.8      |   99 ++++++++++++++++---
 libexec/ftpd/ftpd.c      |  140 +++++++++++++++++++++------
 libexec/ftpd/ftpd.conf.5 |   24 ++++-
 libexec/ftpd/version.h   |    4 +-
 8 files changed, 484 insertions(+), 293 deletions(-)

diffs (truncated from 1633 to 300 lines):

diff -r aaa4dfd7dadd -r fac1edb9329d libexec/ftpd/cmds.c
--- a/libexec/ftpd/cmds.c       Thu Nov 16 13:04:21 2000 +0000
+++ b/libexec/ftpd/cmds.c       Thu Nov 16 13:15:13 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cmds.c,v 1.7 2000/11/15 02:32:30 lukem Exp $   */
+/*     $NetBSD: cmds.c,v 1.8 2000/11/16 13:15:13 lukem Exp $   */
 
 /*
  * Copyright (c) 1999-2000 The NetBSD Foundation, Inc.
@@ -101,7 +101,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: cmds.c,v 1.7 2000/11/15 02:32:30 lukem Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.8 2000/11/16 13:15:13 lukem Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -602,7 +602,7 @@
                         * since we only need this info in such a case.
                         */
        pdir = fe->pdirstat;
-       if (pdir == NULL && curclass.modify) {
+       if (pdir == NULL && CURCLASS_FLAGS_ISSET(modify)) {
                size_t          len;
                char            realdir[MAXPATHLEN], *p;
                struct stat     dir;
@@ -636,15 +636,15 @@
        }
 
                        /* 'a': can APPE to file */
-       if (wok && curclass.upload && S_ISREG(fe->stat->st_mode))
+       if (wok && CURCLASS_FLAGS_ISSET(upload) && S_ISREG(fe->stat->st_mode))
                CPUTC('a', fd);
 
                        /* 'c': can create or append to files in directory */
-       if (wok && curclass.modify && S_ISDIR(fe->stat->st_mode))
+       if (wok && CURCLASS_FLAGS_ISSET(modify) && S_ISDIR(fe->stat->st_mode))
                CPUTC('c', fd);
 
                        /* 'd': can delete file or directory */
-       if (pdirwok && curclass.modify) {
+       if (pdirwok && CURCLASS_FLAGS_ISSET(modify)) {
                int candel;
 
                candel = 1;
@@ -674,7 +674,7 @@
                CPUTC('e', fd);
 
                        /* 'f': can rename file or directory */
-       if (pdirwok && curclass.modify)
+       if (pdirwok && CURCLASS_FLAGS_ISSET(modify))
                CPUTC('f', fd);
 
                        /* 'l': can list directory */
@@ -682,11 +682,11 @@
                CPUTC('l', fd);
 
                        /* 'm': can create directory */
-       if (wok && curclass.modify && S_ISDIR(fe->stat->st_mode))
+       if (wok && CURCLASS_FLAGS_ISSET(modify) && S_ISDIR(fe->stat->st_mode))
                CPUTC('m', fd);
 
                        /* 'p': can remove files in directory */
-       if (wok && curclass.modify && S_ISDIR(fe->stat->st_mode))
+       if (wok && CURCLASS_FLAGS_ISSET(modify) && S_ISDIR(fe->stat->st_mode))
                CPUTC('p', fd);
 
                        /* 'r': can RETR file */
@@ -694,7 +694,7 @@
                CPUTC('r', fd);
 
                        /* 'w': can STOR file */
-       if (wok && curclass.upload && S_ISREG(fe->stat->st_mode))
+       if (wok && CURCLASS_FLAGS_ISSET(upload) && S_ISREG(fe->stat->st_mode))
                CPUTC('w', fd);
 
        CPUTC(';', fd);
diff -r aaa4dfd7dadd -r fac1edb9329d libexec/ftpd/conf.c
--- a/libexec/ftpd/conf.c       Thu Nov 16 13:04:21 2000 +0000
+++ b/libexec/ftpd/conf.c       Thu Nov 16 13:15:13 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: conf.c,v 1.35 2000/11/15 02:32:30 lukem Exp $  */
+/*     $NetBSD: conf.c,v 1.36 2000/11/16 13:15:13 lukem Exp $  */
 
 /*-
  * Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: conf.c,v 1.35 2000/11/15 02:32:30 lukem Exp $");
+__RCSID("$NetBSD: conf.c,v 1.36 2000/11/16 13:15:13 lukem Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -88,7 +88,6 @@
                free(conv);
        }
 
-       curclass.checkportcmd = 1;
        REASSIGN(curclass.chroot, NULL);
        REASSIGN(curclass.classname, NULL);
        curclass.conversions =  NULL;
@@ -96,13 +95,12 @@
        REASSIGN(curclass.homedir, NULL);
        curclass.limit =        -1;             /* unlimited connections */
        REASSIGN(curclass.limitfile, NULL);
+       curclass.maxfilesize =  -1;             /* unlimited file size */
        curclass.maxrateget =   0;
        curclass.maxrateput =   0;
        curclass.maxtimeout =   7200;           /* 2 hours */
-       curclass.modify =       1;
        REASSIGN(curclass.motd, xstrdup(_PATH_FTPLOGINMESG));
        REASSIGN(curclass.notify, NULL);
-       curclass.passive =      1;
        curclass.portmin =      0;
        curclass.portmax =      0;
        curclass.rateget =      0;
@@ -110,7 +108,12 @@
        curclass.timeout =      900;            /* 15 minutes */
            /* curclass.type is set elsewhere */
        curclass.umask =        027;
-       curclass.upload =       1;
+
+       CURCLASS_FLAGS_SET(checkportcmd);
+       CURCLASS_FLAGS_SET(modify);
+       CURCLASS_FLAGS_SET(passive);
+       CURCLASS_FLAGS_CLR(sanenames);
+       CURCLASS_FLAGS_SET(upload);
 }
 
 /*
@@ -123,7 +126,8 @@
        FILE            *f;
        char            *buf, *p;
        size_t           len;
-       int              none, match, rate;
+       LLT              llval;
+       int              none, match;
        char            *endp;
        char            *class, *word, *arg, *template;
        const char      *infile;
@@ -134,7 +138,7 @@
        init_curclass();
        REASSIGN(curclass.classname, xstrdup(findclass));
        if (strcasecmp(findclass, "guest") == 0) {
-               curclass.modify = 0;
+               CURCLASS_FLAGS_CLR(modify);
                curclass.umask = 0707;
        }
 
@@ -170,19 +174,29 @@
                       strcasecmp(class, "all") == 0) )
                        continue;
 
+#define CONF_FLAG(x) \
+       do { \
+               if (none || \
+                   (!EMPTYSTR(arg) && strcasecmp(arg, "off") == 0)) \
+                       CURCLASS_FLAGS_CLR(x); \
+               else \
+                       CURCLASS_FLAGS_SET(x); \
+       } while (0)
+
+#define CONF_STRING(x) \
+       do { \
+               if (none || EMPTYSTR(arg)) \
+                       arg = NULL; \
+               else \
+                       arg = xstrdup(arg); \
+               REASSIGN(curclass.x, arg); \
+       } while (0)
+
                if (strcasecmp(word, "checkportcmd") == 0) {
-                       if (none ||
-                           (!EMPTYSTR(arg) && strcasecmp(arg, "off") == 0))
-                               curclass.checkportcmd = 0;
-                       else
-                               curclass.checkportcmd = 1;
+                       CONF_FLAG(checkportcmd);
 
                } else if (strcasecmp(word, "chroot") == 0) {
-                       if (none || EMPTYSTR(arg))
-                               arg = NULL;
-                       else
-                               arg = xstrdup(arg);
-                       REASSIGN(curclass.chroot, arg);
+                       CONF_STRING(chroot);
 
                } else if (strcasecmp(word, "classtype") == 0) {
                        if (!none && !EMPTYSTR(arg)) {
@@ -253,18 +267,22 @@
                        REASSIGN(conv->command, convcmd);
 
                } else if (strcasecmp(word, "display") == 0) {
-                       if (none || EMPTYSTR(arg))
-                               arg = NULL;
-                       else
-                               arg = xstrdup(arg);
-                       REASSIGN(curclass.display, arg);
+                       CONF_STRING(display);
 
                } else if (strcasecmp(word, "homedir") == 0) {
+                       CONF_STRING(homedir);
+
+               } else if (strcasecmp(word, "maxfilesize") == 0) {
                        if (none || EMPTYSTR(arg))
-                               arg = NULL;
-                       else
-                               arg = xstrdup(arg);
-                       REASSIGN(curclass.homedir, arg);
+                               continue;
+                       llval = strsuftoll(arg);
+                       if (llval == -1) {
+                               syslog(LOG_WARNING,
+                                   "%s line %d: invalid maxfilesize %s",
+                                   infile, (int)line, arg);
+                               continue;
+                       }
+                       curclass.maxfilesize = llval;
 
                } else if (strcasecmp(word, "limit") == 0) {
                        int limit;
@@ -308,33 +326,16 @@
                        curclass.maxtimeout = timeout;
 
                } else if (strcasecmp(word, "modify") == 0) {
-                       if (none ||
-                           (!EMPTYSTR(arg) && strcasecmp(arg, "off") == 0))
-                               curclass.modify = 0;
-                       else
-                               curclass.modify = 1;
+                       CONF_FLAG(modify);
 
                } else if (strcasecmp(word, "motd") == 0) {
-                       if (none || EMPTYSTR(arg))
-                               arg = NULL;
-                       else
-                               arg = xstrdup(arg);
-                       REASSIGN(curclass.motd, arg);
-
+                       CONF_STRING(motd);
 
                } else if (strcasecmp(word, "notify") == 0) {
-                       if (none || EMPTYSTR(arg))
-                               arg = NULL;
-                       else
-                               arg = xstrdup(arg);
-                       REASSIGN(curclass.notify, arg);
+                       CONF_STRING(notify);
 
                } else if (strcasecmp(word, "passive") == 0) {
-                       if (none ||
-                           (!EMPTYSTR(arg) && strcasecmp(arg, "off") == 0))
-                               curclass.passive = 0;
-                       else
-                               curclass.passive = 1;
+                       CONF_FLAG(passive);
 
                } else if (strcasecmp(word, "portrange") == 0) {
                        int minport, maxport;
@@ -383,28 +384,31 @@
                } else if (strcasecmp(word, "rateget") == 0) {
                        if (none || EMPTYSTR(arg))
                                continue;
-                       rate = strsuftoi(arg);
-                       if (rate == -1) {
+                       llval = strsuftoll(arg);
+                       if (llval == -1) {
                                syslog(LOG_WARNING,
                                    "%s line %d: invalid rateget %s",
                                    infile, (int)line, arg);
                                continue;
                        }
-                       curclass.maxrateget = rate;
-                       curclass.rateget = rate;
+                       curclass.maxrateget = llval;
+                       curclass.rateget = llval;
 
                } else if (strcasecmp(word, "rateput") == 0) {
                        if (none || EMPTYSTR(arg))
                                continue;
-                       rate = strsuftoi(arg);
-                       if (rate == -1) {
+                       llval = strsuftoll(arg);
+                       if (llval == -1) {
                                syslog(LOG_WARNING,
                                    "%s line %d: invalid rateput %s",
                                    infile, (int)line, arg);
                                continue;
                        }
-                       curclass.maxrateput = rate;
-                       curclass.rateput = rate;
+                       curclass.maxrateput = llval;
+                       curclass.rateput = llval;
+
+               } else if (strcasecmp(word, "sanenames") == 0) {
+                       CONF_FLAG(sanenames);
 



Home | Main Index | Thread Index | Old Index