Source-Changes-HG archive

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

[src/trunk]: src/libexec/ftpd * add ftpd.conf directive `portrange class min ...



details:   https://anonhg.NetBSD.org/src/rev/f345fe46aa74
branches:  trunk
changeset: 480440:f345fe46aa74
user:      lukem <lukem%NetBSD.org@localhost>
date:      Wed Jan 12 22:39:27 2000 +0000

description:
* add ftpd.conf directive `portrange class min max', which allows specification
  of the port range used by passive connections. based on work in [bin/9158]
  from Takahiro Kambe <taca%sky.yamashina.kyoto.jp@localhost>
* change the way global variables are defined and extern-ed to be more
  consistent.

diffstat:

 libexec/ftpd/conf.c      |  55 +++++++++++++++++++++++++++++++++++++---
 libexec/ftpd/extern.h    |  64 ++++++++++++++++++++++++++---------------------
 libexec/ftpd/ftpcmd.y    |  10 ++-----
 libexec/ftpd/ftpd.c      |  58 +++++++++++++++++++++++++++++++++++--------
 libexec/ftpd/ftpd.conf.5 |  14 +++++++++-
 libexec/ftpd/logwtmp.c   |   5 ++-
 libexec/ftpd/popen.c     |   5 ++-
 libexec/ftpd/version.h   |   4 +-
 8 files changed, 155 insertions(+), 60 deletions(-)

diffs (truncated from 460 to 300 lines):

diff -r cb6a4215311b -r f345fe46aa74 libexec/ftpd/conf.c
--- a/libexec/ftpd/conf.c       Wed Jan 12 19:33:18 2000 +0000
+++ b/libexec/ftpd/conf.c       Wed Jan 12 22:39:27 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: conf.c,v 1.27 2000/01/10 08:03:50 lukem Exp $  */
+/*     $NetBSD: conf.c,v 1.28 2000/01/12 22:39:27 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.27 2000/01/10 08:03:50 lukem Exp $");
+__RCSID("$NetBSD: conf.c,v 1.28 2000/01/12 22:39:27 lukem Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -49,6 +49,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <glob.h>
+#include <setjmp.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -69,8 +70,6 @@
 static char *strend __P((const char *, char *));
 static int filetypematch __P((char *, int));
 
-struct ftpclass curclass;
-
 
 /*
  * Initialise curclass to an `empty' state
@@ -88,6 +87,7 @@
                cnext = conv->next;
                free(conv);
        }
+
        curclass.checkportcmd = 0;
        REASSIGN(curclass.classname, NULL);
        curclass.conversions =  NULL;
@@ -101,12 +101,13 @@
        REASSIGN(curclass.motd, xstrdup(_PATH_FTPLOGINMESG));
        REASSIGN(curclass.notify, NULL);
        curclass.passive =      1;
+       curclass.portmin =      0;
+       curclass.portmax =      0;
        curclass.rateget =      0;
        curclass.rateput =      0;
        curclass.timeout =      900;            /* 15 minutes */
        curclass.umask =        027;
        curclass.upload =       1;
-
 }
 
 /*
@@ -319,6 +320,50 @@
                        else
                                curclass.passive = 1;
 
+               } else if (strcasecmp(word, "portrange") == 0) {
+                       int minport, maxport;
+                       char *min, *max;
+
+                       if (none) {
+                               curclass.portmin = 0;
+                               curclass.portmax = 0;
+                               continue;
+                       }
+                       if (EMPTYSTR(arg))
+                               continue;
+                       min = arg;
+                       NEXTWORD(p, max);
+                       if (EMPTYSTR(max)) {
+                               syslog(LOG_WARNING,
+                                  "%s line %d: missing maxport argument",
+                                  infile, (int)line);
+                               continue;
+                       }
+                       minport = (int)strtol(min, &endp, 10);
+                       if (*endp != 0 || minport < IPPORT_RESERVED ||
+                           minport > IPPORT_ANONMAX) {
+                               syslog(LOG_WARNING,
+                                   "%s line %d: invalid minport %s",
+                                   infile, (int)line, min);
+                               continue;
+                       }
+                       maxport = (int)strtol(max, &endp, 10);
+                       if (*endp != 0 || maxport < IPPORT_RESERVED ||
+                           maxport > IPPORT_ANONMAX) {
+                               syslog(LOG_WARNING,
+                                   "%s line %d: invalid maxport %s",
+                                   infile, (int)line, max);
+                               continue;
+                       }
+                       if (minport >= maxport) {
+                               syslog(LOG_WARNING,
+                                   "%s line %d: minport %d >= maxport %d",
+                                   infile, (int)line, minport, maxport);
+                               continue;
+                       }
+                       curclass.portmin = minport;
+                       curclass.portmax = maxport;
+
                } else if (strcasecmp(word, "rateget") == 0) {
                        if (none || EMPTYSTR(arg))
                                continue;
diff -r cb6a4215311b -r f345fe46aa74 libexec/ftpd/extern.h
--- a/libexec/ftpd/extern.h     Wed Jan 12 19:33:18 2000 +0000
+++ b/libexec/ftpd/extern.h     Wed Jan 12 22:39:27 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.22 2000/01/08 11:09:56 lukem Exp $        */
+/*     $NetBSD: extern.h,v 1.23 2000/01/12 22:39:28 lukem Exp $        */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -171,7 +171,9 @@
                                           UMASK */
        char            *motd;          /* MotD file to display after login */
        char            *notify;        /* Files to notify about upon chdir */
-       int              passive;       /* Allow PASV */
+       int              passive;       /* Allow PASV mode */
+       int              portmin;       /* Minumum port for passive mode */
+       int              portmax;       /* Maximum port for passive mode */
        int              rateget;       /* Get (RETR) transfer rate throttle */
        int              rateput;       /* Put (STOR) transfer rate throttle */
        unsigned int     timeout;       /* Default timeout */
@@ -196,37 +198,41 @@
 #define su_family      su_si.si_family
 #define su_port                su_si.si_port
 
-extern  int yyparse __P((void));
+extern  int            yyparse __P((void));
+
+#ifndef        GLOBAL
+#define        GLOBAL  extern
+#endif
 
-extern char            cbuf[];
-extern int             connections;
-extern struct ftpclass curclass;
-extern union sockunion data_dest;
-extern int             debug;
-extern int             form;
-extern int             hasyyerrored;
-extern union sockunion his_addr;
-extern char            hostname[];
+GLOBAL int             connections;
+GLOBAL struct ftpclass curclass;
+GLOBAL union sockunion data_dest;
+GLOBAL int             debug;
+GLOBAL jmp_buf         errcatch;
+GLOBAL int             form;
+GLOBAL int             hasyyerrored;
+GLOBAL union sockunion his_addr;
+GLOBAL char            hostname[];
 #ifdef KERBEROS5
-extern krb5_context    kcontext;
+GLOBAL krb5_context    kcontext;
 #endif
-extern int             logged_in;
-extern int             logging;
-extern int             pdata;
-extern char            proctitle[];
-extern struct passwd  *pw;
-extern char            remotehost[];
-extern off_t           restart_point;
-extern char            tmpline[];
-extern sig_atomic_t    transflag;
-extern int             type;
-extern int             usedefault;
-extern const char      version[];
+GLOBAL int             logged_in;
+GLOBAL int             logging;
+GLOBAL int             pdata;
+GLOBAL char            proctitle[];
+GLOBAL struct passwd  *pw;
+GLOBAL char            remotehost[];
+GLOBAL off_t           restart_point;
+GLOBAL char            tmpline[];
+GLOBAL sig_atomic_t    transflag;
+GLOBAL int             type;
+GLOBAL int             usedefault;
+GLOBAL 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;
+GLOBAL off_t           total_data_in,  total_data_out,  total_data;
+GLOBAL off_t           total_files_in, total_files_out, total_files;
+GLOBAL off_t           total_bytes_in, total_bytes_out, total_bytes;
+GLOBAL off_t           total_xfers_in, total_xfers_out, total_xfers;
 
 
 #define EMPTYSTR(p)    ((p) == NULL || *(p) == '\0')
diff -r cb6a4215311b -r f345fe46aa74 libexec/ftpd/ftpcmd.y
--- a/libexec/ftpd/ftpcmd.y     Wed Jan 12 19:33:18 2000 +0000
+++ b/libexec/ftpd/ftpcmd.y     Wed Jan 12 22:39:27 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ftpcmd.y,v 1.43 1999/12/21 12:52:18 lukem Exp $        */
+/*     $NetBSD: ftpcmd.y,v 1.44 2000/01/12 22:39:28 lukem Exp $        */
 
 /*-
  * Copyright (c) 1997-1999 The NetBSD Foundation, Inc.
@@ -83,7 +83,7 @@
 #if 0
 static char sccsid[] = "@(#)ftpcmd.y   8.3 (Berkeley) 4/6/94";
 #else
-__RCSID("$NetBSD: ftpcmd.y,v 1.43 1999/12/21 12:52:18 lukem Exp $");
+__RCSID("$NetBSD: ftpcmd.y,v 1.44 2000/01/12 22:39:28 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -116,16 +116,12 @@
 
 #include "extern.h"
 
-off_t  restart_point;
-
 static int cmd_type;
 static int cmd_form;
 static int cmd_bytesz;
+
 char   cbuf[512];
 char   *fromname;
-int    hasyyerrored;
-
-extern jmp_buf         errcatch;
 
 %}
 
diff -r cb6a4215311b -r f345fe46aa74 libexec/ftpd/ftpd.c
--- a/libexec/ftpd/ftpd.c       Wed Jan 12 19:33:18 2000 +0000
+++ b/libexec/ftpd/ftpd.c       Wed Jan 12 22:39:27 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ftpd.c,v 1.83 2000/01/08 11:14:36 lukem Exp $  */
+/*     $NetBSD: ftpd.c,v 1.84 2000/01/12 22:39:28 lukem Exp $  */
 
 /*
  * Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
@@ -109,7 +109,7 @@
 #if 0
 static char sccsid[] = "@(#)ftpd.c     8.5 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: ftpd.c,v 1.83 2000/01/08 11:14:36 lukem Exp $");
+__RCSID("$NetBSD: ftpd.c,v 1.84 2000/01/12 22:39:28 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -160,6 +160,7 @@
 #include <krb5/krb5.h>
 #endif
 
+#define        GLOBAL
 #include "extern.h"
 #include "pathnames.h"
 #include "version.h"
@@ -248,7 +249,7 @@
                        "<unknown>"
 
 static void     ack __P((const char *));
-static void     myoob __P((int));
+static int      bind_pasv_addr __P((void));
 static int      checkuser __P((const char *, const char *, int, int, char **));
 static int      checkaccess __P((const char *));
 static FILE    *dataconn __P((const char *, off_t, const char *));
@@ -257,6 +258,7 @@
 static FILE    *getdatasock __P((const char *));
 static char    *gunique __P((const char *));
 static void     lostconn __P((int));
+static void     myoob __P((int));
 static int      receive_data __P((FILE *, FILE *));
 static void     replydirname __P((const char *, const char *));
 static int      send_data __P((FILE *, FILE *, off_t, int));
@@ -2228,6 +2230,43 @@
        }
 }
 
+static int
+bind_pasv_addr()
+{
+       static int passiveport;
+       int port, len;
+
+       len = pasv_addr.su_len;
+       if (curclass.portmin == 0 && curclass.portmax == 0) {
+               pasv_addr.su_port = 0;
+               return (bind(pdata, (struct sockaddr *)&pasv_addr, len));
+       }
+
+       if (passiveport == 0) {
+               srand(getpid());
+               passiveport = rand() % (curclass.portmax - curclass.portmin)
+                   + curclass.portmin;
+       }
+
+       port = passiveport;



Home | Main Index | Thread Index | Old Index