Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/ftp * fix gate mode to login as `user@realhost' rath...



details:   https://anonhg.NetBSD.org/src/rev/64da034a31e3
branches:  trunk
changeset: 473411:64da034a31e3
user:      lukem <lukem%NetBSD.org@localhost>
date:      Wed Jun 02 02:03:57 1999 +0000

description:
* fix gate mode to login as `user@realhost' rather than using PASSERVE;
  the latter only seemed to work for TIS Gauntlet and not TIS fwtk.
  thanks to simonb%netbsd.org@localhost for testing this. fixes [bin/5556].
* if EOF (e.g, ^D) is entered at a username/password/account prompt which
  happens to use fgets(), exit the login rather than treating EOF as CR.
* don't use the comma operator where separate statements are valid
* always use snprintf to copy stuff into malloced buffers, just in case
  typos creep in and mean that the buffer ends up being overflowed

diffstat:

 usr.bin/ftp/cmds.c  |  24 ++++++++++++++++--------
 usr.bin/ftp/fetch.c |   8 ++++----
 usr.bin/ftp/ftp.1   |   6 ++++--
 usr.bin/ftp/ftp.c   |   6 +++---
 usr.bin/ftp/main.c  |   6 +++---
 usr.bin/ftp/util.c  |  49 ++++++++++++++++++++++++++++++++++---------------
 6 files changed, 64 insertions(+), 35 deletions(-)

diffs (298 lines):

diff -r 201593857511 -r 64da034a31e3 usr.bin/ftp/cmds.c
--- a/usr.bin/ftp/cmds.c        Tue Jun 01 19:53:51 1999 +0000
+++ b/usr.bin/ftp/cmds.c        Wed Jun 02 02:03:57 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cmds.c,v 1.48 1999/05/12 11:06:00 lukem Exp $  */
+/*     $NetBSD: cmds.c,v 1.49 1999/06/02 02:03:57 lukem Exp $  */
 
 /*-
  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
 #if 0
 static char sccsid[] = "@(#)cmds.c     8.6 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: cmds.c,v 1.48 1999/05/12 11:06:00 lukem Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.49 1999/06/02 02:03:57 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -1349,15 +1349,22 @@
        }
        n = command("USER %s", argv[1]);
        if (n == CONTINUE) {
-               if (argc < 3 )
-                       argv[2] = getpass("Password: "), argc++;
+               if (argc < 3) {
+                       argv[2] = getpass("Password: ");
+                       argc++;
+               }
                n = command("PASS %s", argv[2]);
        }
        if (n == CONTINUE) {
                if (argc < 4) {
                        (void)fputs("Account: ", ttyout);
                        (void)fflush(ttyout);
-                       (void)fgets(acct, sizeof(acct) - 1, stdin);
+                       if (fgets(acct, sizeof(acct) - 1, stdin) == NULL) {
+                               fprintf(ttyout,
+                                   "\nEOF received; login aborted.\n");
+                               code = -1;
+                               return;
+                       }
                        acct[strlen(acct) - 1] = '\0';
                        argv[3] = acct; argc++;
                }
@@ -2255,7 +2262,7 @@
        int argc;
        char *argv[];
 {
-       int ohash, orestart_point, overbose;
+       int ohash, orestart_point, overbose, len;
        char *p, *pager, *oldargv1;
 
        if ((argc < 2 && !another(&argc, &argv, "filename")) || argc > 2) {
@@ -2271,8 +2278,9 @@
        p = getenv("PAGER");
        if (p == NULL)
                p = PAGER;
-       pager = xmalloc(strlen(p) + 2);
-       (void)sprintf(pager, "|%s", p);
+       len = strlen(p) + 2;
+       pager = xmalloc(len);
+       (void)snprintf(pager, len, "|%s", p);
 
        ohash = hash;
        orestart_point = restart_point;
diff -r 201593857511 -r 64da034a31e3 usr.bin/ftp/fetch.c
--- a/usr.bin/ftp/fetch.c       Tue Jun 01 19:53:51 1999 +0000
+++ b/usr.bin/ftp/fetch.c       Wed Jun 02 02:03:57 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fetch.c,v 1.54 1999/05/12 11:16:43 lukem Exp $ */
+/*     $NetBSD: fetch.c,v 1.55 1999/06/02 02:03:57 lukem Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.54 1999/05/12 11:16:43 lukem Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.55 1999/06/02 02:03:57 lukem Exp $");
 #endif /* not lint */
 
 /*
@@ -174,14 +174,14 @@
 
        len = strlen(user) + strlen(pass) + 1;          /* user + ":" + pass */
        clear = (char *)xmalloc(len + 1);
-       sprintf(clear, "%s:%s", user, pass);
+       snprintf(clear, len, "%s:%s", user, pass);
        if (gpass == NULL)
                memset(pass, '\0', strlen(pass));
 
                                                /* scheme + " " + enc */
        len = strlen(scheme) + 1 + (len + 2) * 4 / 3;
        *response = (char *)xmalloc(len + 1);
-       len = sprintf(*response, "%s ", scheme);
+       len = snprintf(*response, len, "%s ", scheme);
        base64_encode(clear, strlen(clear), *response + len);
        memset(clear, '\0', strlen(clear));
        rval = 0;
diff -r 201593857511 -r 64da034a31e3 usr.bin/ftp/ftp.1
--- a/usr.bin/ftp/ftp.1 Tue Jun 01 19:53:51 1999 +0000
+++ b/usr.bin/ftp/ftp.1 Wed Jun 02 02:03:57 1999 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: ftp.1,v 1.39 1999/05/12 11:16:44 lukem Exp $
+.\"    $NetBSD: ftp.1,v 1.40 1999/06/02 02:03:57 lukem Exp $
 .\"
 .\" Copyright (c) 1985, 1989, 1990, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -35,7 +35,7 @@
 .\"
 .\"    @(#)ftp.1       8.3 (Berkeley) 10/9/94
 .\"
-.Dd May 12, 1999
+.Dd June 2, 1999
 .Dt FTP 1
 .Os
 .Sh NAME
@@ -1530,6 +1530,8 @@
 Used by
 .Ic page
 to display files.
+(Defaults to
+.Xr more 1 ).
 .It Ev SHELL
 For default shell.
 .It Ev ftp_proxy
diff -r 201593857511 -r 64da034a31e3 usr.bin/ftp/ftp.c
--- a/usr.bin/ftp/ftp.c Tue Jun 01 19:53:51 1999 +0000
+++ b/usr.bin/ftp/ftp.c Wed Jun 02 02:03:57 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ftp.c,v 1.43 1999/05/04 14:12:37 lukem Exp $   */
+/*     $NetBSD: ftp.c,v 1.44 1999/06/02 02:03:58 lukem Exp $   */
 
 /*
  * Copyright (c) 1985, 1989, 1993, 1994
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)ftp.c      8.6 (Berkeley) 10/27/94";
 #else
-__RCSID("$NetBSD: ftp.c,v 1.43 1999/05/04 14:12:37 lukem Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.44 1999/06/02 02:03:58 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -1603,7 +1603,7 @@
         * send IAC in urgent mode instead of DM because 4.3BSD places oob mark
         * after urgent byte rather than before as is protocol now
         */
-       sprintf(buf, "%c%c%c", IAC, IP, IAC);
+       snprintf(buf, sizeof(buf), "%c%c%c", IAC, IP, IAC);
        if (send(fileno(cout), buf, 3, MSG_OOB) != 3)
                warn("abort");
        fprintf(cout, "%cABOR\r\n", DM);
diff -r 201593857511 -r 64da034a31e3 usr.bin/ftp/main.c
--- a/usr.bin/ftp/main.c        Tue Jun 01 19:53:51 1999 +0000
+++ b/usr.bin/ftp/main.c        Wed Jun 02 02:03:57 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.41 1999/05/17 04:26:45 lukem Exp $  */
+/*     $NetBSD: main.c,v 1.42 1999/06/02 02:03:58 lukem Exp $  */
 
 /*
  * Copyright (c) 1985, 1989, 1993, 1994
@@ -43,7 +43,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.6 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.41 1999/05/17 04:26:45 lukem Exp $");
+__RCSID("$NetBSD: main.c,v 1.42 1999/06/02 02:03:58 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -164,7 +164,7 @@
        if (gatemode) {
                if (*gateserver == '\0') {
                        warnx(
-"Neither $FTPSERVER nor $GATE_SERVER is defined; disabling gate-ftp");
+"Neither $FTPSERVER nor GATE_SERVER is defined; disabling gate-ftp");
                        gatemode = 0;
                }
        }
diff -r 201593857511 -r 64da034a31e3 usr.bin/ftp/util.c
--- a/usr.bin/ftp/util.c        Tue Jun 01 19:53:51 1999 +0000
+++ b/usr.bin/ftp/util.c        Wed Jun 02 02:03:57 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: util.c,v 1.48 1999/05/20 14:08:12 matthias Exp $       */
+/*     $NetBSD: util.c,v 1.49 1999/06/02 02:03:58 lukem Exp $  */
 
 /*-
  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: util.c,v 1.48 1999/05/20 14:08:12 matthias Exp $");
+__RCSID("$NetBSD: util.c,v 1.49 1999/06/02 02:03:58 lukem Exp $");
 #endif /* not lint */
 
 /*
@@ -164,13 +164,10 @@
        if (host) {
                int overbose;
 
-               if (gatemode) {
-                       if (command("PASSERVE %s", argv[1]) != COMPLETE)
-                               return;
-                       if (verbose)
-                               fprintf(ttyout,
-                                   "Connected via pass-through server %s\n",
-                                   gateserver);
+               if (gatemode && verbose) {
+                       fprintf(ttyout,
+                           "Connecting via pass-through server %s\n",
+                           gateserver);
                }
 
                connected = 1;
@@ -249,9 +246,8 @@
 {
        char tmp[80];
        const char *acct;
-       char anonpass[MAXLOGNAME + 2]; /* "user@" */
        struct passwd *pw;
-       int n, aflag, rval, freeuser, freepass, freeacct;
+       int n, aflag, rval, freeuser, freepass, freeacct, len;
 
        acct = NULL;
        aflag = rval = freeuser = freepass = freeacct = 0;
@@ -260,12 +256,12 @@
         * Set up arguments for an anonymous FTP session, if necessary.
         */
        if (anonftp) {
-               memset(anonpass, 0, sizeof(anonpass));
-
                /*
                 * Set up anonymous login password.
                 */
                if ((pass = getenv("FTPANONPASS")) == NULL) {
+                       char *anonpass;
+
                        if ((pass = getlogin()) == NULL) {
                                if ((pw = getpwuid(getuid())) == NULL)
                                        pass = "anonymous";
@@ -280,8 +276,11 @@
                         * a FQDN in the anonymous password.
                         * - thorpej%netbsd.org@localhost
                         */
-                       snprintf(anonpass, sizeof(anonpass) - 1, "%s@", pass);
+                       len = strlen(pass) + 2;
+                       anonpass = xmalloc(len);
+                       snprintf(anonpass, len, "%s@", pass);
                        pass = anonpass;
+                       freepass = 1;
                }
                user = "anonymous";     /* as per RFC 1635 */
        }
@@ -307,13 +306,29 @@
                else
                        fprintf(ttyout, "Name (%s): ", host);
                *tmp = '\0';
-               (void)fgets(tmp, sizeof(tmp) - 1, stdin);
+               if (fgets(tmp, sizeof(tmp) - 1, stdin) == NULL) {
+                       fprintf(ttyout, "\nEOF received; login aborted.\n");
+                       code = -1;
+                       goto cleanup_ftp_login;
+               }
                tmp[strlen(tmp) - 1] = '\0';
                if (*tmp == '\0')
                        user = myname;
                else
                        user = tmp;
        }
+
+       if (gatemode) {
+               char *nuser;
+               int len;
+
+               len = strlen(user) + 1 + strlen(host) + 1;
+               nuser = xmalloc(len);
+               snprintf(nuser, len, "%s@%s", user, host);
+               user = nuser;
+               freeuser = 1;
+       }
+
        n = command("USER %s", user);
        if (n == CONTINUE) {
                if (pass == NULL)
@@ -326,6 +341,10 @@
                        acct = getpass("Account:");
                        freeacct = 0;
                }
+               if (acct[0] == '\0') {
+                       warnx("Login failed.");
+                       goto cleanup_ftp_login;
+               }
                n = command("ACCT %s", acct);
        }
        if ((n != COMPLETE) ||



Home | Main Index | Thread Index | Old Index