Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/ftp * migrate the SYST parsing from setpeer() into a...



details:   https://anonhg.NetBSD.org/src/rev/09f2c5051f52
branches:  trunk
changeset: 487932:09f2c5051f52
user:      lukem <lukem%NetBSD.org@localhost>
date:      Thu Jun 15 13:08:23 2000 +0000

description:
* migrate the SYST parsing from setpeer() into a separate remotesyst().
  call remotesyst() only when login has been successful
  some servers don't let you run SYST until you've successfully logged in.
* in fetch_ftp(), always call setpeer() with autologin disabled, and use
  the following ftp_login() to DTRT.
  this prevents ftp from trying to login a second time if the first autologin
  fails when connecting to a remote site anonymously using autofetch.
* reset unix_proxy and unix_server in cleanuppeer()
* missed a function conversion in the KNF sweep...

diffstat:

 usr.bin/ftp/cmds.c    |    5 +-
 usr.bin/ftp/extern.h  |    5 +-
 usr.bin/ftp/fetch.c   |   12 ++--
 usr.bin/ftp/util.c    |  121 +++++++++++++++++++++++++++----------------------
 usr.bin/ftp/version.h |    4 +-
 5 files changed, 80 insertions(+), 67 deletions(-)

diffs (285 lines):

diff -r e8ae62ed6c76 -r 09f2c5051f52 usr.bin/ftp/cmds.c
--- a/usr.bin/ftp/cmds.c        Thu Jun 15 13:04:05 2000 +0000
+++ b/usr.bin/ftp/cmds.c        Thu Jun 15 13:08:23 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cmds.c,v 1.86 2000/05/28 07:53:30 lukem Exp $  */
+/*     $NetBSD: cmds.c,v 1.87 2000/06/15 13:08:23 lukem Exp $  */
 
 /*-
  * Copyright (c) 1996-2000 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.86 2000/05/28 07:53:30 lukem Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.87 2000/06/15 13:08:23 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -1465,6 +1465,7 @@
                (void)command("ACCT %s", argv[3]);
        }
        connected = -1;
+       remotesyst();
 }
 
 /*
diff -r e8ae62ed6c76 -r 09f2c5051f52 usr.bin/ftp/extern.h
--- a/usr.bin/ftp/extern.h      Thu Jun 15 13:04:05 2000 +0000
+++ b/usr.bin/ftp/extern.h      Thu Jun 15 13:08:23 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.56 2000/05/31 14:23:57 lukem Exp $        */
+/*     $NetBSD: extern.h,v 1.57 2000/06/15 13:08:25 lukem Exp $        */
 
 /*-
  * Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
@@ -194,8 +194,9 @@
            const char *, int, int);
 void   reget(int, char **);
 char   *remglob(char **, int, char **);
+time_t remotemodtime(const char *, int);
 off_t  remotesize(const char *, int);
-time_t remotemodtime(const char *, int);
+void   remotesyst(void);
 void   removedir(int, char **);
 void   renamefile(int, char **);
 void   reset(int, char **);
diff -r e8ae62ed6c76 -r 09f2c5051f52 usr.bin/ftp/fetch.c
--- a/usr.bin/ftp/fetch.c       Thu Jun 15 13:04:05 2000 +0000
+++ b/usr.bin/ftp/fetch.c       Thu Jun 15 13:08:23 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fetch.c,v 1.115 2000/06/05 09:22:52 lukem Exp $        */
+/*     $NetBSD: fetch.c,v 1.116 2000/06/15 13:08:25 lukem Exp $        */
 
 /*-
  * Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.115 2000/06/05 09:22:52 lukem Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.116 2000/06/15 13:08:25 lukem Exp $");
 #endif /* not lint */
 
 /*
@@ -1508,12 +1508,12 @@
                xargc = 3;
        }
        oautologin = autologin;
-       if (user != NULL)
-               autologin = 0;
+               /* don't autologin in setpeer(), use ftp_login() below */
+       autologin = 0;
        setpeer(xargc, xargv);
        autologin = oautologin;
-       if ((connected == 0) || ((connected == 1)
-           && !ftp_login(host, user, pass))) {
+       if ((connected == 0) ||
+           (connected == 1 && !ftp_login(host, user, pass))) {
                warnx("Can't connect or login to host `%s'", host);
                goto cleanup_fetch_ftp;
        }
diff -r e8ae62ed6c76 -r 09f2c5051f52 usr.bin/ftp/util.c
--- a/usr.bin/ftp/util.c        Thu Jun 15 13:04:05 2000 +0000
+++ b/usr.bin/ftp/util.c        Thu Jun 15 13:08:23 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: util.c,v 1.95 2000/05/01 10:35:19 lukem Exp $  */
+/*     $NetBSD: util.c,v 1.96 2000/06/15 13:08:27 lukem Exp $  */
 
 /*-
  * Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: util.c,v 1.95 2000/05/01 10:35:19 lukem Exp $");
+__RCSID("$NetBSD: util.c,v 1.96 2000/06/15 13:08:27 lukem Exp $");
 #endif /* not lint */
 
 /*
@@ -110,8 +110,7 @@
 #include "ftp_var.h"
 
 /*
- * Connect to peer server and
- * auto-login, if possible.
+ * Connect to peer server and auto-login, if possible.
  */
 void
 setpeer(int argc, char *argv[])
@@ -150,8 +149,6 @@
                host = hookup(argv[1], port);
 
        if (host) {
-               int overbose;
-
                if (gatemode && verbose) {
                        fprintf(ttyout,
                            "Connecting via pass-through server %s\n",
@@ -175,58 +172,68 @@
                bytesize = 8;
                if (autologin)
                        (void)ftp_login(argv[1], NULL, NULL);
+       }
+}
 
-               overbose = verbose;
-               if (debug == 0)
-                       verbose = -1;
-               if (command("SYST") == COMPLETE && overbose) {
-                       char *cp, c;
-                       c = 0;
-                       cp = strchr(reply_string + 4, ' ');
-                       if (cp == NULL)
-                               cp = strchr(reply_string + 4, '\r');
-                       if (cp) {
-                               if (cp[-1] == '.')
-                                       cp--;
-                               c = *cp;
-                               *cp = '\0';
-                       }
+/*
+ * Determine the remote system type.
+ * Call after a successful login (i.e, connected = -1)
+ */
+void
+remotesyst(void)
+{
+       int overbose;
 
-                       fprintf(ttyout, "Remote system type is %s.\n",
-                           reply_string + 4);
-                       if (cp)
-                               *cp = c;
+       overbose = verbose;
+       if (debug == 0)
+               verbose = -1;
+       if (command("SYST") == COMPLETE && overbose) {
+               char *cp, c;
+               c = 0;
+               cp = strchr(reply_string + 4, ' ');
+               if (cp == NULL)
+                       cp = strchr(reply_string + 4, '\r');
+               if (cp) {
+                       if (cp[-1] == '.')
+                               cp--;
+                       c = *cp;
+                       *cp = '\0';
                }
-               if (!strncmp(reply_string, "215 UNIX Type: L8", 17)) {
-                       if (proxy)
-                               unix_proxy = 1;
-                       else
-                               unix_server = 1;
-                       /*
-                        * Set type to 0 (not specified by user),
-                        * meaning binary by default, but don't bother
-                        * telling server.  We can use binary
-                        * for text files unless changed by the user.
-                        */
-                       type = 0;
-                       (void)strlcpy(typename, "binary", sizeof(typename));
-                       if (overbose)
-                           fprintf(ttyout,
-                               "Using %s mode to transfer files.\n",
-                               typename);
-               } else {
-                       if (proxy)
-                               unix_proxy = 0;
-                       else
-                               unix_server = 0;
-                       if (overbose &&
-                           !strncmp(reply_string, "215 TOPS20", 10))
-                               fputs(
+
+               fprintf(ttyout, "Remote system type is %s.\n",
+                   reply_string + 4);
+               if (cp)
+                       *cp = c;
+       }
+       if (!strncmp(reply_string, "215 UNIX Type: L8", 17)) {
+               if (proxy)
+                       unix_proxy = 1;
+               else
+                       unix_server = 1;
+               /*
+                * Set type to 0 (not specified by user),
+                * meaning binary by default, but don't bother
+                * telling server.  We can use binary
+                * for text files unless changed by the user.
+                */
+               type = 0;
+               (void)strlcpy(typename, "binary", sizeof(typename));
+               if (overbose)
+                   fprintf(ttyout,
+                       "Using %s mode to transfer files.\n",
+                       typename);
+       } else {
+               if (proxy)
+                       unix_proxy = 0;
+               else
+                       unix_server = 0;
+               if (overbose &&
+                   !strncmp(reply_string, "215 TOPS20", 10))
+                       fputs(
 "Remember to set tenex mode when transferring binary files from this machine.\n",
-                                   ttyout);
-               }
-               verbose = overbose;
+                           ttyout);
        }
+       verbose = overbose;
 }
 
 /*
@@ -236,13 +243,15 @@
  * to perform a clean shutdown before this is invoked.
  */
 void
-cleanuppeer()
+cleanuppeer(void)
 {
 
        if (cout)
                (void)fclose(cout);
        cout = NULL;
        connected = 0;
+       unix_server = 0;
+       unix_proxy = 0;
                        /*
                         * determine if anonftp was specifically set with -a
                         * (1), or implicitly set by auto_fetch() (2). in the
@@ -312,7 +321,8 @@
 
 
 /*
- * login to remote host, using given username & password if supplied
+ * Login to remote host, using given username & password if supplied.
+ * Return non-zero if successful.
  */
 int
 ftp_login(const char *host, const char *user, const char *pass)
@@ -417,6 +427,7 @@
                goto cleanup_ftp_login;
 
        connected = -1;
+       remotesyst();
        for (n = 0; n < macnum; ++n) {
                if (!strcmp("init", macros[n].mac_name)) {
                        (void)strlcpy(line, "$init", sizeof(line));
diff -r e8ae62ed6c76 -r 09f2c5051f52 usr.bin/ftp/version.h
--- a/usr.bin/ftp/version.h     Thu Jun 15 13:04:05 2000 +0000
+++ b/usr.bin/ftp/version.h     Thu Jun 15 13:08:23 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: version.h,v 1.13 2000/06/11 15:17:11 lukem Exp $       */
+/*     $NetBSD: version.h,v 1.14 2000/06/15 13:08:28 lukem Exp $       */
 /*-
  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -40,5 +40,5 @@
 #endif
 
 #ifndef FTP_VERSION
-#define        FTP_VERSION     "20000612"
+#define        FTP_VERSION     "20000615"
 #endif



Home | Main Index | Thread Index | Old Index