Source-Changes-HG archive

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

[src/netbsd-6]: src/usr.bin/ftp Apply patch, requested by nonaka in ticket #1...



details:   https://anonhg.NetBSD.org/src/rev/9c2edb5a6a78
branches:  netbsd-6
changeset: 777086:9c2edb5a6a78
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Sat Aug 27 13:57:01 2016 +0000

description:
Apply patch, requested by nonaka in ticket #1375:
        src/usr.bin/ftp/cmds.c:         patch
        src/usr.bin/ftp/fetch.c:        patch
        src/usr.bin/ftp/ftp.1:          patch
        src/usr.bin/ftp/ftp.c:          patch
        src/usr.bin/ftp/ftp_var.h:      patch
        src/usr.bin/ftp/main.c:         patch
        src/usr.bin/ftp/ssl.c:          patch
        src/usr.bin/ftp/ssl.h:          patch
        src/usr.bin/ftp/version.h:      patch
Update ftp(1) to version 20150912, adding https via proxy support.

diffstat:

 usr.bin/ftp/cmds.c    |    12 +-
 usr.bin/ftp/fetch.c   |  1565 +++++++++++++++++++++++++++++-------------------
 usr.bin/ftp/ftp.1     |    13 +-
 usr.bin/ftp/ftp.c     |    16 +-
 usr.bin/ftp/ftp_var.h |    13 +-
 usr.bin/ftp/main.c    |    19 +-
 usr.bin/ftp/ssl.c     |    14 +-
 usr.bin/ftp/ssl.h     |     7 +-
 usr.bin/ftp/version.h |     6 +-
 9 files changed, 1012 insertions(+), 653 deletions(-)

diffs (truncated from 2295 to 300 lines):

diff -r c113b1226656 -r 9c2edb5a6a78 usr.bin/ftp/cmds.c
--- a/usr.bin/ftp/cmds.c        Sat Aug 27 13:34:42 2016 +0000
+++ b/usr.bin/ftp/cmds.c        Sat Aug 27 13:57:01 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cmds.c,v 1.134.2.1 2013/12/17 21:07:59 bouyer Exp $    */
+/*     $NetBSD: cmds.c,v 1.134.2.2 2016/08/27 13:57:01 bouyer Exp $    */
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
 #if 0
 static char sccsid[] = "@(#)cmds.c     8.6 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: cmds.c,v 1.134.2.1 2013/12/17 21:07:59 bouyer Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.134.2.2 2016/08/27 13:57:01 bouyer Exp $");
 #endif
 #endif /* not lint */
 
@@ -1967,15 +1967,15 @@
        char *cp2 = dst;
        size_t i, ostop;
 
-       for (ostop = 0; *(ntout + ostop) && ostop < 16; ostop++)
+       for (ostop = 0; ntout[ostop] && ostop < sizeof(ntout); ostop++)
                continue;
        for (cp1 = src; *cp1; cp1++) {
                int found = 0;
-               for (i = 0; *(ntin + i) && i < 16; i++) {
-                       if (*cp1 == *(ntin + i)) {
+               for (i = 0; i < sizeof(ntin) && ntin[i]; i++) {
+                       if (*cp1 == ntin[i]) {
                                found++;
                                if (i < ostop) {
-                                       *cp2++ = *(ntout + i);
+                                       *cp2++ = ntout[i];
                                        if (cp2 - dst >= (ptrdiff_t)(dlen - 1))
                                                goto out;
                                }
diff -r c113b1226656 -r 9c2edb5a6a78 usr.bin/ftp/fetch.c
--- a/usr.bin/ftp/fetch.c       Sat Aug 27 13:34:42 2016 +0000
+++ b/usr.bin/ftp/fetch.c       Sat Aug 27 13:57:01 2016 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: fetch.c,v 1.195.2.2 2014/10/27 05:53:04 snj Exp $      */
+/*     $NetBSD: fetch.c,v 1.195.2.3 2016/08/27 13:57:01 bouyer Exp $   */
 
 /*-
- * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -10,6 +10,9 @@
  * This code is derived from software contributed to The NetBSD Foundation
  * by Scott Aaron Bamford.
  *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Thomas Klausner.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -34,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.195.2.2 2014/10/27 05:53:04 snj Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.195.2.3 2016/08/27 13:57:01 bouyer Exp $");
 #endif /* not lint */
 
 /*
@@ -71,27 +74,47 @@
 typedef enum {
        UNKNOWN_URL_T=-1,
        HTTP_URL_T,
-#ifdef WITH_SSL
        HTTPS_URL_T,
-#endif
        FTP_URL_T,
        FILE_URL_T,
        CLASSIC_URL_T
 } url_t;
 
+struct authinfo {
+       char *auth;
+       char *user;
+       char *pass;
+};
+
+struct urlinfo {
+       char *host;
+       char *port;
+       char *path;
+       url_t utype;
+       in_port_t portnum;
+};
+
+struct posinfo {
+       off_t rangestart;
+       off_t rangeend;
+       off_t entitylen;
+};
+
 __dead static void     aborthttp(int);
 __dead static void     timeouthttp(int);
 #ifndef NO_AUTH
-static int     auth_url(const char *, char **, const char *, const char *);
+static int     auth_url(const char *, char **, const struct authinfo *);
 static void    base64_encode(const unsigned char *, size_t, unsigned char *);
 #endif
 static int     go_fetch(const char *);
 static int     fetch_ftp(const char *);
 static int     fetch_url(const char *, const char *, char *, char *);
 static const char *match_token(const char **, const char *);
-static int     parse_url(const char *, const char *, url_t *, char **,
-                           char **, char **, char **, in_port_t *, char **);
+static int     parse_url(const char *, const char *, struct urlinfo *,
+    struct authinfo *);
 static void    url_decode(char *);
+static void    freeauthinfo(struct authinfo *);
+static void    freeurlinfo(struct urlinfo *);
 
 static int     redirect_loop;
 
@@ -143,6 +166,54 @@
        return orig;
 }
 
+static void
+initposinfo(struct posinfo *pi)
+{
+       pi->rangestart = pi->rangeend = pi->entitylen = -1;
+}
+
+static void
+initauthinfo(struct authinfo *ai, char *auth)
+{
+       ai->auth = auth;
+       ai->user = ai->pass = 0;
+}
+
+static void
+freeauthinfo(struct authinfo *a)
+{
+       FREEPTR(a->user);
+       if (a->pass != NULL)
+               memset(a->pass, 0, strlen(a->pass));
+       FREEPTR(a->pass);
+}
+
+static void
+initurlinfo(struct urlinfo *ui)
+{
+       ui->host = ui->port = ui->path = 0;
+       ui->utype = UNKNOWN_URL_T;
+       ui->portnum = 0;
+}
+
+static void
+copyurlinfo(struct urlinfo *dui, struct urlinfo *sui)
+{
+       dui->host = ftp_strdup(sui->host);
+       dui->port = ftp_strdup(sui->port);
+       dui->path = ftp_strdup(sui->path);
+       dui->utype = sui->utype;
+       dui->portnum = sui->portnum;
+}
+
+static void
+freeurlinfo(struct urlinfo *ui)
+{
+       FREEPTR(ui->host);
+       FREEPTR(ui->port);
+       FREEPTR(ui->path);
+}
+
 #ifndef NO_AUTH
 /*
  * Generate authorization response based on given authentication challenge.
@@ -150,8 +221,7 @@
  * Sets response to a malloc(3)ed string; caller should free.
  */
 static int
-auth_url(const char *challenge, char **response, const char *guser,
-       const char *gpass)
+auth_url(const char *challenge, char **response, const struct authinfo *auth)
 {
        const char      *cp, *scheme, *errormsg;
        char            *ep, *clear, *realm;
@@ -195,8 +265,8 @@
        }
 
        fprintf(ttyout, "Username for `%s': ", realm);
-       if (guser != NULL) {
-               (void)strlcpy(uuser, guser, sizeof(uuser));
+       if (auth->user != NULL) {
+               (void)strlcpy(uuser, auth->user, sizeof(uuser));
                fprintf(ttyout, "%s\n", uuser);
        } else {
                (void)fflush(ttyout);
@@ -205,8 +275,8 @@
                        goto cleanup_auth_url;
                }
        }
-       if (gpass != NULL)
-               upass = gpass;
+       if (auth->pass != NULL)
+               upass = auth->pass;
        else {
                gotpass = getpass("Password: ");
                if (gotpass == NULL) {
@@ -226,7 +296,7 @@
 
                                                /* scheme + " " + enc + "\0" */
        rlen = strlen(scheme) + 1 + (clen + 2) * 4 / 3 + 1;
-       *response = (char *)ftp_malloc(rlen);
+       *response = ftp_malloc(rlen);
        (void)strlcpy(*response, scheme, rlen);
        len = strlcat(*response, " ", rlen);
                        /* use  `clen - 1'  to not encode the trailing NUL */
@@ -325,57 +395,48 @@
  *     "ftp://host/dir/file";           "dir/file"
  *     "ftp://host//dir/file";          "/dir/file"
  */
+
 static int
-parse_url(const char *url, const char *desc, url_t *utype,
-               char **uuser, char **pass, char **host, char **port,
-               in_port_t *portnum, char **path)
+parse_url(const char *url, const char *desc, struct urlinfo *ui,
+    struct authinfo *auth) 
 {
        const char      *origurl, *tport;
        char            *cp, *ep, *thost;
        size_t           len;
 
-       if (url == NULL || desc == NULL || utype == NULL || uuser == NULL
-           || pass == NULL || host == NULL || port == NULL || portnum == NULL
-           || path == NULL)
+       if (url == NULL || desc == NULL || ui == NULL || auth == NULL)
                errx(1, "parse_url: invoked with NULL argument!");
        DPRINTF("parse_url: %s `%s'\n", desc, url);
 
        origurl = url;
-       *utype = UNKNOWN_URL_T;
-       *uuser = *pass = *host = *port = *path = NULL;
-       *portnum = 0;
        tport = NULL;
 
        if (STRNEQUAL(url, HTTP_URL)) {
                url += sizeof(HTTP_URL) - 1;
-               *utype = HTTP_URL_T;
-               *portnum = HTTP_PORT;
+               ui->utype = HTTP_URL_T;
+               ui->portnum = HTTP_PORT;
                tport = httpport;
        } else if (STRNEQUAL(url, FTP_URL)) {
                url += sizeof(FTP_URL) - 1;
-               *utype = FTP_URL_T;
-               *portnum = FTP_PORT;
+               ui->utype = FTP_URL_T;
+               ui->portnum = FTP_PORT;
                tport = ftpport;
        } else if (STRNEQUAL(url, FILE_URL)) {
                url += sizeof(FILE_URL) - 1;
-               *utype = FILE_URL_T;
+               ui->utype = FILE_URL_T;
+               tport = "";
 #ifdef WITH_SSL
        } else if (STRNEQUAL(url, HTTPS_URL)) {
                url += sizeof(HTTPS_URL) - 1;
-               *utype = HTTPS_URL_T;
-               *portnum = HTTPS_PORT;
+               ui->utype = HTTPS_URL_T;
+               ui->portnum = HTTPS_PORT;
                tport = httpsport;
 #endif
        } else {
                warnx("Invalid %s `%s'", desc, url);
  cleanup_parse_url:
-               FREEPTR(*uuser);
-               if (*pass != NULL)
-                       memset(*pass, 0, strlen(*pass));
-               FREEPTR(*pass);
-               FREEPTR(*host);
-               FREEPTR(*port);
-               FREEPTR(*path);
+               freeauthinfo(auth);
+               freeurlinfo(ui);
                return (-1);
        }
 
@@ -390,26 +451,26 @@
                len = ep - url;
                thost = (char *)ftp_malloc(len + 1);
                (void)strlcpy(thost, url, len + 1);
-               if (*utype == FTP_URL_T)        /* skip first / for ftp URLs */
+               if (ui->utype == FTP_URL_T)     /* skip first / for ftp URLs */
                        ep++;
-               *path = ftp_strdup(ep);
+               ui->path = ftp_strdup(ep);



Home | Main Index | Thread Index | Old Index