Source-Changes-HG archive

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

[src/netbsd-1-4]: src/usr.bin/ftp pullup 1.52->1.55 (lukem)



details:   https://anonhg.NetBSD.org/src/rev/5edc6bc3a5c8
branches:  netbsd-1-4
changeset: 468903:5edc6bc3a5c8
user:      perry <perry%NetBSD.org@localhost>
date:      Tue Jun 22 21:01:48 1999 +0000

description:
pullup 1.52->1.55 (lukem)

diffstat:

 usr.bin/ftp/fetch.c |  302 +++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 239 insertions(+), 63 deletions(-)

diffs (truncated from 511 to 300 lines):

diff -r 508290dbb50c -r 5edc6bc3a5c8 usr.bin/ftp/fetch.c
--- a/usr.bin/ftp/fetch.c       Tue Jun 22 21:01:18 1999 +0000
+++ b/usr.bin/ftp/fetch.c       Tue Jun 22 21:01:48 1999 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: fetch.c,v 1.52 1999/03/22 07:36:40 lukem Exp $ */
+/*     $NetBSD: fetch.c,v 1.52.2.1 1999/06/22 21:01:48 perry Exp $     */
 
 /*-
  * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
- * by Jason Thorpe and Luke Mewburn.
+ * by Luke Mewburn.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.52 1999/03/22 07:36:40 lukem Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.52.2.1 1999/06/22 21:01:48 perry Exp $");
 #endif /* not lint */
 
 /*
@@ -75,11 +75,13 @@
        UNKNOWN_URL_T=-1,
        HTTP_URL_T,
        FTP_URL_T,
-       FILE_URL_T
+       FILE_URL_T,
+       CLASSIC_URL_T
 } url_t;
 
 void           aborthttp __P((int));
-static int     auth_url __P((const char *, char **));
+static int     auth_url __P((const char *, char **, const char *,
+                               const char *));
 static void    base64_encode __P((const char *, size_t, char *));
 static int     go_fetch __P((const char *));
 static int     fetch_ftp __P((const char *));
@@ -106,9 +108,11 @@
  * Sets response to a malloc(3)ed string; caller should free.
  */
 static int
-auth_url(challenge, response)
+auth_url(challenge, response, guser, gpass)
        const char       *challenge;
        char            **response;
+       const char       *guser;
+       const char       *gpass;
 {
        char            *cp, *ep, *clear, *line, *realm, *scheme;
        char            user[BUFSIZ], *pass;
@@ -153,23 +157,33 @@
                goto cleanup_auth_url;
        }
 
-       fprintf(ttyout, "Username for `%s': ", realm);
-       (void)fflush(ttyout);
-       if (fgets(user, sizeof(user) - 1, stdin) == NULL)
-               goto cleanup_auth_url;
-       user[strlen(user) - 1] = '\0';
-       pass = getpass("Password: ");
+       if (guser != NULL) {
+               strncpy(user, guser, sizeof(user) - 1);
+               user[sizeof(user) - 1] = '\0';
+       } else {
+               fprintf(ttyout, "Username for `%s': ", realm);
+               (void)fflush(ttyout);
+               if (fgets(user, sizeof(user) - 1, stdin) == NULL)
+                       goto cleanup_auth_url;
+               user[strlen(user) - 1] = '\0';
+       }
+       if (gpass != NULL)
+               pass = (char *)gpass;
+       else
+               pass = getpass("Password: ");
 
        len = strlen(user) + strlen(pass) + 1;          /* user + ":" + pass */
        clear = (char *)xmalloc(len + 1);
-       sprintf(clear, "%s:%s", user, pass);
-       memset(pass, '\0', strlen(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;
 
 cleanup_auth_url:
@@ -246,10 +260,21 @@
  * malloc(3)ed strings of the relevant section, and port to
  * the number given, or ftpport if ftp://, or httpport if http://.
  *
- * XXX: this is not totally RFC1738 compliant; path will have the
- * leading `/' unless it's an ftp:// URL; this makes things easier
- * for file:// and http:// URLs. ftp:// URLs have all leading `/'s
- * removed.
+ * XXX: this is not totally RFC 1738 compliant; path will have the
+ * leading `/' unless it's an ftp:// URL, as this makes things easier
+ * for file:// and http:// URLs. ftp:// URLs have the `/' between the
+ * host and the url-path removed, but any additional leading slashes
+ * in the url-path are retained (because they imply that we should
+ * later do "CWD" with a null argument).
+ *
+ * Examples:
+ *      input url                       output path
+ *      ---------                       -----------
+ *     "http://host";                   NULL
+ *     "http://host/";                  "/"
+ *     "http://host/dir/file";          "/dir/file"
+ *     "ftp://host/dir/file";           "dir/file"
+ *     "ftp://host//dir/file";          "/dir/file"
  */
 static int
 parse_url(url, desc, type, user, pass, host, port, path)
@@ -306,16 +331,16 @@
                thost = (char *)xmalloc(len + 1);
                strncpy(thost, url, len);
                thost[len] = '\0';
-               if (*type == FTP_URL_T) /* skip all leading /'s for ftp URLs */
-                       while (*ep && *ep == '/')
-                               ep++;
+               if (*type == FTP_URL_T) /* skip first / for ftp URLs */
+                       ep++;
                *path = xstrdup(ep);
        }
 
        cp = strchr(thost, '@');
-                                       /* look for user[:pass]@ in ftp URLs */
-       if (*type == FTP_URL_T && cp != NULL) {
-               anonftp = 0;            /* disable anonftp */
+                                       /* look for user[:pass]@ in URLs */
+       if (cp != NULL) {
+               if (*type == FTP_URL_T)
+                       anonftp = 0;    /* disable anonftp */
                *user = thost;
                *cp = '\0';
                *host = xstrdup(cp + 1);
@@ -344,8 +369,9 @@
        if (debug)
                fprintf(ttyout,
                    "parse_url: user `%s' pass `%s' host %s:%d path `%s'\n",
-                   *user ? *user : "", *pass ? *pass : "", *host ? *host : "",
-                   ntohs(*port), *path ? *path : "");
+                   *user ? *user : "<null>", *pass ? *pass : "<null>",
+                   *host ? *host : "<null>", ntohs(*port),
+                   *path ? *path : "<null>");
 
        return (0);
 }
@@ -377,6 +403,7 @@
        char                    *cp, *ep, *buf, *savefile;
        char                    *auth, *location, *message;
        char                    *user, *pass, *host, *path, *decodedpath;
+       char                    *puser, *ppass;
        off_t                   hashbytes;
        int                      (*closefunc) __P((FILE *));
        FILE                    *fin, *fout;
@@ -392,7 +419,7 @@
        ischunked = isproxy = hcode = 0;
        rval = 1;
        hp = NULL;
-       user = pass = host = path = decodedpath = NULL;
+       user = pass = host = path = decodedpath = puser = ppass = NULL;
 
 #ifdef __GNUC__                        /* shut up gcc warnings */
        (void)&closefunc;
@@ -482,8 +509,7 @@
                direction = "retrieved";
                if (proxyenv != NULL) {                         /* use proxy */
                        url_t purltype;
-                       char *puser, *ppass, *phost;
-                       char *ppath;
+                       char *phost, *ppath;
 
                        isproxy = 1;
 
@@ -531,22 +557,16 @@
                                     && strcmp(ppath, "/") != 0)) {
                                        warnx("Malformed proxy URL `%s'",
                                            proxyenv);
-                                       FREEPTR(puser);
-                                       FREEPTR(ppass);
                                        FREEPTR(phost);
                                        FREEPTR(ppath);
                                        goto cleanup_fetch_url;
                                }
 
-                               FREEPTR(user);
-                               user = puser;
-                               FREEPTR(pass);
-                               pass = ppass;
                                FREEPTR(host);
                                host = phost;
                                FREEPTR(path);
+                               path = xstrdup(url);
                                FREEPTR(ppath);
-                               path = xstrdup(url);
                        }
                } /* proxyenv != NULL */
 
@@ -790,6 +810,7 @@
                        }
 
                }
+                               /* finished parsing header */
                FREEPTR(buf);
 
                switch (hcode) {
@@ -826,6 +847,7 @@
                case 407:
                    {
                        char **authp;
+                       char *auser, *apass;
 
                        fprintf(ttyout, "%s\n", message);
                        if (EMPTYSTRING(auth)) {
@@ -833,7 +855,15 @@
                            "No authentication challenge provided by server");
                                goto cleanup_fetch_url;
                        }
-                       authp = (hcode == 401) ? &wwwauth : &proxyauth;
+                       if (hcode == 401) {
+                               authp = &wwwauth;
+                               auser = user;
+                               apass = pass;
+                       } else {
+                               authp = &proxyauth;
+                               auser = puser;
+                               apass = ppass;
+                       }
                        if (*authp != NULL) {
                                char reply[10];
 
@@ -842,8 +872,10 @@
                                if (fgets(reply, sizeof(reply), stdin) != NULL
                                    && tolower(reply[0]) != 'y')
                                        goto cleanup_fetch_url;
+                               auser = NULL;
+                               apass = NULL;
                        }
-                       if (auth_url(auth, authp) == 0) {
+                       if (auth_url(auth, authp, auser, apass) == 0) {
                                rval = fetch_url(url, proxyenv,
                                    proxyauth, wwwauth);
                                memset(*authp, '\0', strlen(*authp));
@@ -998,6 +1030,8 @@
        FREEPTR(host);
        FREEPTR(path);
        FREEPTR(decodedpath);
+       FREEPTR(puser);
+       FREEPTR(ppass);
        FREEPTR(buf);
        FREEPTR(auth);
        FREEPTR(location);
@@ -1031,15 +1065,15 @@
        char            portnum[6];             /* large enough for "65535\0" */
        char            *host, *path, *dir, *file, *user, *pass;
        in_port_t       port;
-       int             dirhasglob, filehasglob, oautologin, rval, xargc;
+       int             dirhasglob, filehasglob, oautologin, rval, type, xargc;
+       url_t           urltype;
 
        host = path = dir = file = user = pass = NULL;
        port = 0;
        rval = 1;
+       type = TYPE_I;
 
        if (strncasecmp(url, FTP_URL, sizeof(FTP_URL) - 1) == 0) {
-               url_t urltype;
-
                if ((parse_url(url, "URL", &urltype, &user, &pass,
                    &host, &port, &path) == -1) ||
                    (user != NULL && *user == '\0') ||
@@ -1050,8 +1084,31 @@
                }
                url_decode(user);
                url_decode(pass);
-               url_decode(path);
+               /*
+                * Note: Don't url_decode(path) here.  We need to keep the
+                * distinction between "/" and "%2F" until later.
+                */
+
+                                       /* check for trailing ';type=[aid]' */
+               cp = strrchr(path, ';');
+               if (cp != NULL) {
+                       if (strcasecmp(cp, ";type=a") == 0)
+                               type = TYPE_A;
+                       else if (strcasecmp(cp, ";type=i") == 0)
+                               type = TYPE_I;



Home | Main Index | Thread Index | Old Index