Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/ftp If EPSV or EPRT fails, disable epsv4 for the res...



details:   https://anonhg.NetBSD.org/src/rev/03ced552e0eb
branches:  trunk
changeset: 476899:03ced552e0eb
user:      lukem <lukem%NetBSD.org@localhost>
date:      Fri Oct 01 08:01:12 1999 +0000

description:
If EPSV or EPRT fails, disable epsv4 for the rest of the current connection.
the disabled state can be overridden by toggling epsv4.

(I got sick of the errors about EPSV not being supported on almost
every server I connect to. This way we retain support for epsv4, but
it's not so whiny after the first failure...)

diffstat:

 usr.bin/ftp/cmds.c    |  30 ++++++++++++++++--------------
 usr.bin/ftp/ftp.1     |  17 +++++++++--------
 usr.bin/ftp/ftp.c     |  26 ++++++++++++++++++++------
 usr.bin/ftp/ftp_var.h |   3 ++-
 usr.bin/ftp/main.c    |   5 +++--
 5 files changed, 50 insertions(+), 31 deletions(-)

diffs (218 lines):

diff -r 2db4432fd3e8 -r 03ced552e0eb usr.bin/ftp/cmds.c
--- a/usr.bin/ftp/cmds.c        Fri Oct 01 07:58:02 1999 +0000
+++ b/usr.bin/ftp/cmds.c        Fri Oct 01 08:01:12 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cmds.c,v 1.67 1999/10/01 06:18:32 lukem Exp $  */
+/*     $NetBSD: cmds.c,v 1.68 1999/10/01 08:01:12 lukem Exp $  */
 
 /*-
  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@@ -107,7 +107,7 @@
 #if 0
 static char sccsid[] = "@(#)cmds.c     8.6 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: cmds.c,v 1.67 1999/10/01 06:18:32 lukem Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.68 1999/10/01 08:01:12 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -717,7 +717,8 @@
            "Socket buffer sizes: send %d, receive %d.\n",
            sndbuf_size, rcvbuf_size);
        fprintf(ttyout, "Use of PORT cmds: %s.\n", onoff(sendport));
-       fprintf(ttyout, "Use of EPSV/EPRT cmds for IPv4: %s.\n", onoff(epsv4));
+       fprintf(ttyout, "Use of EPSV/EPRT cmds for IPv4: %s%s.\n", onoff(epsv4),
+           epsv4bad ? " (disabled for this connection)" : "");
 #ifndef NO_EDITCOMPLETE
        fprintf(ttyout, "Command line editing: %s.\n", onoff(editing));
 #endif /* !NO_EDITCOMPLETE */
@@ -1619,6 +1620,7 @@
        cout = NULL;
        connected = 0;
        data = -1;
+       epsv4bad = 0;
        if (!proxy) {
                macnum = 0;
        }
@@ -2036,6 +2038,17 @@
 }
 
 void
+setepsv4(argc, argv)
+       int argc;
+       char *argv[];
+{
+
+       code = togglevar(argc, argv, &epsv4,
+           verbose ? "EPSV/EPRT on IPv4" : NULL);
+       epsv4bad = 0;
+}
+
+void
 setsunique(argc, argv)
        int argc;
        char *argv[];
@@ -2454,14 +2467,3 @@
        fprintf(ttyout, "Socket buffer sizes: send %d, receive %d.\n",
            sndbuf_size, rcvbuf_size);
 }
-
-
-void
-setepsv4(argc, argv)
-       int argc;
-       char *argv[];
-{
-
-       code = togglevar(argc, argv, &epsv4,
-           verbose ? "EPSV/EPRT on IPv4" : NULL);
-}
diff -r 2db4432fd3e8 -r 03ced552e0eb usr.bin/ftp/ftp.1
--- a/usr.bin/ftp/ftp.1 Fri Oct 01 07:58:02 1999 +0000
+++ b/usr.bin/ftp/ftp.1 Fri Oct 01 08:01:12 1999 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: ftp.1,v 1.49 1999/10/01 05:08:32 lukem Exp $
+.\"    $NetBSD: ftp.1,v 1.50 1999/10/01 08:01:12 lukem Exp $
 .\"
 .\" Copyright (c) 1985, 1989, 1990, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -409,20 +409,21 @@
 This is automatically enabled if input is from a terminal, and
 disabled otherwise.
 .It Ic epsv4
-Toggle the use of 
+Toggle the use of the extended
 .Dv EPSV
 and
 .Dv EPRT
-commands on IPv4 connections.
-This is enabled by default
-.Po
-first try
+commands on IPv4 connections; first try
 .Dv EPSV /
 .Dv EPRT ,
 and then
 .Dv PASV /
-.Dv PORT
-.Pc .
+.Dv PORT .
+This is enabled by default.
+If an extended command fails then this option will be temporarily
+disabled for the duration of the current connection, or until
+.Ic epsv4
+is executed again.
 .It Ic exit
 A synonym for
 .Ic bye .
diff -r 2db4432fd3e8 -r 03ced552e0eb usr.bin/ftp/ftp.c
--- a/usr.bin/ftp/ftp.c Fri Oct 01 07:58:02 1999 +0000
+++ b/usr.bin/ftp/ftp.c Fri Oct 01 08:01:12 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ftp.c,v 1.73 1999/10/01 06:55:44 lukem Exp $   */
+/*     $NetBSD: ftp.c,v 1.74 1999/10/01 08:01:12 lukem Exp $   */
 
 /*
  * Copyright (c) 1985, 1989, 1993, 1994
@@ -67,7 +67,7 @@
 #if 0
 static char sccsid[] = "@(#)ftp.c      8.6 (Berkeley) 10/27/94";
 #else
-__RCSID("$NetBSD: ftp.c,v 1.73 1999/10/01 06:55:44 lukem Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.74 1999/10/01 08:01:12 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -1375,7 +1375,7 @@
                result = COMPLETE + 1;
                switch (data_addr.su_family) {
                case AF_INET:
-                       if (epsv4) {
+                       if (epsv4 && !epsv4bad) {
                                result = command(pasvcmd = "EPSV");
                                /*
                                 * this code is to be friendly with broken
@@ -1387,6 +1387,13 @@
                                                ttyout);
                                        result = COMPLETE + 1;
                                }
+                               if (result != COMPLETE) {
+                                       epsv4bad = 1;
+                                       if (debug)
+                                               fputs(
+                                       "disabling epsv4 for this connection\n",
+                                                   ttyout);
+                               }
                        }
                        if (result != COMPLETE)
                                result = command(pasvcmd = "PASV");
@@ -1635,7 +1642,7 @@
 
                switch (data_addr.su_family) {
                case AF_INET:
-                       if (!epsv4) {
+                       if (!epsv4 || epsv4bad) {
                                result = COMPLETE + 1;
                                break;
                        }
@@ -1648,8 +1655,15 @@
                                        NULL, 0, NI_NUMERICHOST)) {
                                result = ERROR;
                        } else {
-                               result = command("EPRT |%d|%s|%d|",
-                                       af, hname, ntohs(data_addr.su_port));
+                               result = command("EPRT |%d|%s|%d|", af, hname,
+                                               ntohs(data_addr.su_port));
+                               if (result != COMPLETE) {
+                                       epsv4bad = 1;
+                                       if (debug)
+                                               fputs(
+                                       "disabling epsv4 for this connection\n",
+                                                   ttyout);
+                               }
                        }
                        break;
 #endif
diff -r 2db4432fd3e8 -r 03ced552e0eb usr.bin/ftp/ftp_var.h
--- a/usr.bin/ftp/ftp_var.h     Fri Oct 01 07:58:02 1999 +0000
+++ b/usr.bin/ftp/ftp_var.h     Fri Oct 01 08:01:12 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ftp_var.h,v 1.39 1999/10/01 06:55:45 lukem Exp $       */
+/*     $NetBSD: ftp_var.h,v 1.40 1999/10/01 08:01:13 lukem Exp $       */
 
 /*
  * Copyright (c) 1985, 1989, 1993, 1994
@@ -204,6 +204,7 @@
 GLOBAL char   *tmpdir;         /* temporary directory */
 GLOBAL FILE   *ttyout;         /* stdout, or stderr if retrieving to stdout */
 GLOBAL int     epsv4;          /* use EPSV/EPRT on IPv4 connections */
+GLOBAL int     epsv4bad;       /* EPSV doesn't work on the current server */
 
 #ifndef NO_EDITCOMPLETE
 GLOBAL int       editing;      /* command line editing enabled */
diff -r 2db4432fd3e8 -r 03ced552e0eb usr.bin/ftp/main.c
--- a/usr.bin/ftp/main.c        Fri Oct 01 07:58:02 1999 +0000
+++ b/usr.bin/ftp/main.c        Fri Oct 01 08:01:12 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.57 1999/10/01 06:55:45 lukem Exp $  */
+/*     $NetBSD: main.c,v 1.58 1999/10/01 08:01:13 lukem Exp $  */
 
 /*
  * Copyright (c) 1985, 1989, 1993, 1994
@@ -72,7 +72,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.6 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.57 1999/10/01 06:55:45 lukem Exp $");
+__RCSID("$NetBSD: main.c,v 1.58 1999/10/01 08:01:13 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -149,6 +149,7 @@
 #else
        epsv4 = 0;
 #endif
+       epsv4bad = 0;
 
        /*
         * Get the default socket buffer sizes if we don't already have them.



Home | Main Index | Thread Index | Old Index