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 tron in ticket #997:



details:   https://anonhg.NetBSD.org/src/rev/dd87e796a4f1
branches:  netbsd-6
changeset: 776520:dd87e796a4f1
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Tue Dec 17 21:07:59 2013 +0000

description:
Apply patch, requested by tron in ticket #997:
        usr.bin/ftp/Makefile                            patch
        usr.bin/ftp/cmds.c                              patch
        usr.bin/ftp/cmdtab.c                            patch
        usr.bin/ftp/extern.h                            patch
        usr.bin/ftp/fetch.c                             patch
        usr.bin/ftp/ftp.1                               patch
        usr.bin/ftp/ftp.c                               patch
        usr.bin/ftp/ftp_var.h                           patch
        usr.bin/ftp/main.c                              patch
        usr.bin/ftp/progressbar.c                       patch
        usr.bin/ftp/ssl.c                               patch
        usr.bin/ftp/ssl.h                               patch
        usr.bin/ftp/util.c                              patch
        usr.bin/ftp/version.h                           patch

Add HTTPS support to ftp(1).

diffstat:

 usr.bin/ftp/Makefile      |    8 +-
 usr.bin/ftp/cmds.c        |    6 +-
 usr.bin/ftp/cmdtab.c      |    5 +-
 usr.bin/ftp/extern.h      |    4 +-
 usr.bin/ftp/fetch.c       |  273 ++++++++++++++------
 usr.bin/ftp/ftp.1         |   44 ++-
 usr.bin/ftp/ftp.c         |    9 +-
 usr.bin/ftp/ftp_var.h     |    6 +-
 usr.bin/ftp/main.c        |   12 +-
 usr.bin/ftp/progressbar.c |    7 +-
 usr.bin/ftp/ssl.c         |  608 ++++++++++++++++++++++++++++++++++++++++++++++
 usr.bin/ftp/ssl.h         |   62 ++++
 usr.bin/ftp/util.c        |   40 +-
 usr.bin/ftp/version.h     |    4 +-
 14 files changed, 952 insertions(+), 136 deletions(-)

diffs (truncated from 1771 to 300 lines):

diff -r 4c0449f52244 -r dd87e796a4f1 usr.bin/ftp/Makefile
--- a/usr.bin/ftp/Makefile      Tue Dec 17 20:52:38 2013 +0000
+++ b/usr.bin/ftp/Makefile      Tue Dec 17 21:07:59 2013 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.35 2011/08/14 12:58:15 christos Exp $
+#      $NetBSD: Makefile,v 1.35.4.1 2013/12/17 21:07:59 bouyer Exp $
 #      from: @(#)Makefile      8.2 (Berkeley) 4/3/94
 
 .include <bsd.own.mk>
@@ -18,6 +18,12 @@
 .else
 LDADD+=        -ledit -lterminfo
 DPADD+=        ${LIBEDIT} ${LIBTERMINFO}
+.if (${MKCRYPTO} != "no")
+CPPFLAGS+= -DWITH_SSL
+SRCS+=ssl.c
+LDADD+= -lssl -lcrypto
+DPADD+= ${LIBSSL} ${LIBCRYPTO}
+.endif
 .endif
 
 .if (!defined(SMALLPROG) || defined(SMALLPROG_INET6)) && (${USE_INET6} != "no")
diff -r 4c0449f52244 -r dd87e796a4f1 usr.bin/ftp/cmds.c
--- a/usr.bin/ftp/cmds.c        Tue Dec 17 20:52:38 2013 +0000
+++ b/usr.bin/ftp/cmds.c        Tue Dec 17 21:07:59 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cmds.c,v 1.134 2012/01/15 20:43:24 christos Exp $      */
+/*     $NetBSD: cmds.c,v 1.134.2.1 2013/12/17 21:07:59 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 2012/01/15 20:43:24 christos Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.134.2.1 2013/12/17 21:07:59 bouyer Exp $");
 #endif
 #endif /* not lint */
 
@@ -2675,7 +2675,7 @@
                return;
        }
 
-#define        OPTIONINDENT ((int) sizeof("http_proxy"))
+#define        OPTIONINDENT ((int) sizeof("https_proxy"))
        if (argc == 1) {
                for (o = optiontab; o->name != NULL; o++) {
                        fprintf(ttyout, "%-*s\t%s\n", OPTIONINDENT,
diff -r 4c0449f52244 -r dd87e796a4f1 usr.bin/ftp/cmdtab.c
--- a/usr.bin/ftp/cmdtab.c      Tue Dec 17 20:52:38 2013 +0000
+++ b/usr.bin/ftp/cmdtab.c      Tue Dec 17 21:07:59 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cmdtab.c,v 1.51 2009/04/12 10:18:52 lukem Exp $        */
+/*     $NetBSD: cmdtab.c,v 1.51.8.1 2013/12/17 21:07:59 bouyer Exp $   */
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
 #if 0
 static char sccsid[] = "@(#)cmdtab.c   8.4 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: cmdtab.c,v 1.51 2009/04/12 10:18:52 lukem Exp $");
+__RCSID("$NetBSD: cmdtab.c,v 1.51.8.1 2013/12/17 21:07:59 bouyer Exp $");
 #endif
 #endif /* not lint */
 
@@ -298,6 +298,7 @@
        { "anonpass",   NULL },
        { "ftp_proxy",  NULL },
        { "http_proxy", NULL },
+       { "https_proxy",NULL },
        { "no_proxy",   NULL },
        { "pager",      NULL },
        { "prompt",     NULL },
diff -r 4c0449f52244 -r dd87e796a4f1 usr.bin/ftp/extern.h
--- a/usr.bin/ftp/extern.h      Tue Dec 17 20:52:38 2013 +0000
+++ b/usr.bin/ftp/extern.h      Tue Dec 17 21:07:59 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.79 2011/09/16 15:39:26 joerg Exp $        */
+/*     $NetBSD: extern.h,v 1.79.4.1 2013/12/17 21:07:59 bouyer Exp $   */
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -239,7 +239,7 @@
 void   updatelocalcwd(void);
 void   updateremotecwd(void);
 void   user(int, char **);
-int    ftp_connect(int, const struct sockaddr *, socklen_t);
+int    ftp_connect(int, const struct sockaddr *, socklen_t, int);
 int    ftp_listen(int, int);
 int    ftp_poll(struct pollfd *, int, int);
 void   *ftp_malloc(size_t);
diff -r 4c0449f52244 -r dd87e796a4f1 usr.bin/ftp/fetch.c
--- a/usr.bin/ftp/fetch.c       Tue Dec 17 20:52:38 2013 +0000
+++ b/usr.bin/ftp/fetch.c       Tue Dec 17 21:07:59 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fetch.c,v 1.195 2011/12/10 05:53:58 lukem Exp $        */
+/*     $NetBSD: fetch.c,v 1.195.2.1 2013/12/17 21:07:59 bouyer Exp $   */
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.195 2011/12/10 05:53:58 lukem Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.195.2.1 2013/12/17 21:07:59 bouyer Exp $");
 #endif /* not lint */
 
 /*
@@ -64,18 +64,23 @@
 #include <unistd.h>
 #include <time.h>
 
+#include "ssl.h"
 #include "ftp_var.h"
 #include "version.h"
 
 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;
 
 __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 void    base64_encode(const unsigned char *, size_t, unsigned char *);
@@ -100,7 +105,15 @@
 #define        FILE_URL        "file://"       /* file URL prefix */
 #define        FTP_URL         "ftp://";        /* ftp URL prefix */
 #define        HTTP_URL        "http://";       /* http URL prefix */
+#ifdef WITH_SSL
+#define        HTTPS_URL       "https://";      /* https URL prefix */
 
+#define        IS_HTTP_TYPE(urltype) \
+       (((urltype) == HTTP_URL_T) || ((urltype) == HTTPS_URL_T))
+#else
+#define        IS_HTTP_TYPE(urltype) \
+       ((urltype) == HTTP_URL_T)
+#endif
 
 /*
  * Determine if token is the next word in buf (case insensitive).
@@ -346,6 +359,13 @@
        } else if (STRNEQUAL(url, FILE_URL)) {
                url += sizeof(FILE_URL) - 1;
                *utype = FILE_URL_T;
+#ifdef WITH_SSL
+       } else if (STRNEQUAL(url, HTTPS_URL)) {
+               url += sizeof(HTTPS_URL) - 1;
+               *utype = HTTPS_URL_T;
+               *portnum = HTTPS_PORT;
+               tport = httpsport;
+#endif
        } else {
                warnx("Invalid %s `%s'", desc, url);
  cleanup_parse_url:
@@ -463,7 +483,7 @@
 /*
  * Retrieve URL, via a proxy if necessary, using HTTP.
  * If proxyenv is set, use that for the proxy, otherwise try ftp_proxy or
- * http_proxy as appropriate.
+ * http_proxy/https_proxy as appropriate.
  * Supports HTTP redirects.
  * Returns 1 on failure, 0 on completed xfer, -1 if ftp connection
  * is still open (e.g, ftp xfer with trailing /)
@@ -473,8 +493,10 @@
 {
        struct addrinfo         hints, *res, *res0 = NULL;
        int                     error;
-       sigfunc volatile        oldintr;
-       sigfunc volatile        oldintp;
+       sigfunc volatile        oldint;
+       sigfunc volatile        oldpipe;
+       sigfunc volatile        oldalrm;
+       sigfunc volatile        oldquit;
        int volatile            s;
        struct stat             sb;
        int volatile            ischunked;
@@ -498,17 +520,22 @@
        char                    *puser, *ppass, *useragent;
        off_t                   hashbytes, rangestart, rangeend, entitylen;
        int                     (*volatile closefunc)(FILE *);
-       FILE                    *volatile fin;
+       FETCH                   *volatile fin;
        FILE                    *volatile fout;
+       const char              *volatile penv = proxyenv;
        time_t                  mtime;
        url_t                   urltype;
        in_port_t               portnum;
-
-       DPRINTF("fetch_url: `%s' proxyenv `%s'\n", url, STRorNULL(proxyenv));
+#ifdef WITH_SSL
+       void                    *ssl;
+#endif
 
-       oldintr = oldintp = NULL;
+       DPRINTF("%s: `%s' proxyenv `%s'\n", __func__, url, STRorNULL(penv));
+
+       oldquit = oldalrm = oldint = oldpipe = NULL;
        closefunc = NULL;
-       fin = fout = NULL;
+       fin = NULL;
+       fout = NULL;
        s = -1;
        savefile = NULL;
        auth = location = message = NULL;
@@ -516,6 +543,9 @@
        rval = 1;
        uuser = pass = host = path = decodedpath = puser = ppass = NULL;
 
+       if (sigsetjmp(httpabort, 1))
+               goto cleanup_fetch_url;
+
        if (parse_url(url, "URL", &urltype, &uuser, &pass, &host, &port,
            &portnum, &path) == -1)
                goto cleanup_fetch_url;
@@ -531,7 +561,7 @@
                        rval = fetch_ftp(url);
                        goto cleanup_fetch_url;
                }
-               if (urltype != HTTP_URL_T || outfile == NULL)  {
+               if (!IS_HTTP_TYPE(urltype) || outfile == NULL)  {
                        warnx("Invalid URL (no file after host) `%s'", url);
                        goto cleanup_fetch_url;
                }
@@ -549,7 +579,7 @@
                else
                        savefile = ftp_strdup(decodedpath);
        }
-       DPRINTF("fetch_url: savefile `%s'\n", savefile);
+       DPRINTF("%s: savefile `%s'\n", __func__, savefile);
        if (EMPTYSTRING(savefile)) {
                if (urltype == FTP_URL_T) {
                        rval = fetch_ftp(url);
@@ -571,17 +601,17 @@
        }
        if (urltype == FILE_URL_T) {            /* file:// URLs */
                direction = "copied";
-               fin = fopen(decodedpath, "r");
+               fin = fetch_open(decodedpath, "r");
                if (fin == NULL) {
                        warn("Can't open `%s'", decodedpath);
                        goto cleanup_fetch_url;
                }
-               if (fstat(fileno(fin), &sb) == 0) {
+               if (fstat(fetch_fileno(fin), &sb) == 0) {
                        mtime = sb.st_mtime;
                        filesize = sb.st_size;
                }
                if (restart_point) {
-                       if (lseek(fileno(fin), restart_point, SEEK_SET) < 0) {
+                       if (lseek(fetch_fileno(fin), restart_point, SEEK_SET) < 0) {
                                warn("Can't seek to restart `%s'",
                                    decodedpath);
                                goto cleanup_fetch_url;
@@ -594,18 +624,25 @@
                                    (LLT)restart_point);
                        fputs("\n", ttyout);
                }
+               if (0 == rcvbuf_size) {
+                       rcvbuf_size = 8 * 1024; /* XXX */
+               }
        } else {                                /* ftp:// or http:// URLs */
                const char *leading;
                int hasleading;
 
-               if (proxyenv == NULL) {
-                       if (urltype == HTTP_URL_T)
-                               proxyenv = getoptionvalue("http_proxy");
+               if (penv == NULL) {
+#ifdef WITH_SSL
+                       if (urltype == HTTPS_URL_T)
+                               penv = getoptionvalue("https_proxy");
+#endif
+                       if (penv == NULL && IS_HTTP_TYPE(urltype))
+                               penv = getoptionvalue("http_proxy");
                        else if (urltype == FTP_URL_T)
-                               proxyenv = getoptionvalue("ftp_proxy");
+                               penv = getoptionvalue("ftp_proxy");
                }
                direction = "retrieved";
-               if (! EMPTYSTRING(proxyenv)) {                  /* use proxy */
+               if (! EMPTYSTRING(penv)) {                      /* use proxy */
                        url_t purltype;
                        char *phost, *ppath;
                        char *pport, *no_proxy;
@@ -652,21 +689,20 @@
                        if (isproxy) {
                                if (restart_point) {
                                        warnx("Can't restart via proxy URL `%s'",
-                                           proxyenv);



Home | Main Index | Thread Index | Old Index