Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/ftp handle proxy authentication correctly.



details:   https://anonhg.NetBSD.org/src/rev/dde9f2eced0f
branches:  trunk
changeset: 349575:dde9f2eced0f
user:      nonaka <nonaka%NetBSD.org@localhost>
date:      Thu Dec 15 04:49:15 2016 +0000

description:
handle proxy authentication correctly.

diffstat:

 usr.bin/ftp/fetch.c |  47 +++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 41 insertions(+), 6 deletions(-)

diffs (103 lines):

diff -r d2184da78134 -r dde9f2eced0f usr.bin/ftp/fetch.c
--- a/usr.bin/ftp/fetch.c       Thu Dec 15 04:38:04 2016 +0000
+++ b/usr.bin/ftp/fetch.c       Thu Dec 15 04:49:15 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fetch.c,v 1.225 2016/10/17 00:52:53 christos Exp $     */
+/*     $NetBSD: fetch.c,v 1.226 2016/12/15 04:49:15 nonaka Exp $       */
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.225 2016/10/17 00:52:53 christos Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.226 2016/12/15 04:49:15 nonaka Exp $");
 #endif /* not lint */
 
 /*
@@ -855,8 +855,7 @@
 #define C_OK 0
 #define C_CLEANUP 1
 #define C_IMPROPER 2
-#define C_PROXY 3
-#define C_NOPROXY 4
+#define C_RESTART 3
 
 static int
 getresponseline(FETCH *fin, char *buf, size_t buflen, int *len)
@@ -1087,7 +1086,7 @@
        case 401:
        case 407:
            {
-               struct  authinfo aauth;
+               struct authinfo aauth;
                char **authp;
 
                if (hcode == 401)
@@ -1122,7 +1121,8 @@
                authp = &aauth.auth;
                if (auth_url(*auth, authp, &aauth) == 0) {
                        *rval = fetch_url(url, penv,
-                           pauth->auth, wauth->auth);
+                           hcode == 401 ? pauth->auth : aauth.auth,
+                           hcode == 401 ? aauth.auth : wauth->auth);
                        memset(*authp, 0, strlen(*authp));
                        FREEPTR(*authp);
                }
@@ -1217,6 +1217,34 @@
        switch (hcode) {
        case 200:
                break;
+#ifndef NO_AUTH
+       case 407:
+               if (verbose || pauth->auth == NULL ||
+                   pauth->user == NULL || pauth->pass == NULL)
+                       fprintf(ttyout, "%s\n", message);
+               if (EMPTYSTRING(*auth)) {
+                       warnx("No authentication challenge provided by server");
+                       goto cleanup_fetch_url;
+               }
+
+               if (pauth->auth != NULL) {
+                       char reply[10];
+
+                       fprintf(ttyout, "Authorization failed. Retry (y/n)? ");
+                       if (get_line(stdin, reply, sizeof(reply), NULL)
+                           < 0) {
+                               goto cleanup_fetch_url;
+                       }
+                       if (tolower((unsigned char)reply[0]) != 'y')
+                               goto cleanup_fetch_url;
+                       pauth->user = NULL;
+                       pauth->pass = NULL;
+               }
+
+               if (auth_url(*auth, &pauth->auth, pauth) == 0)
+                       goto restart_fetch_url;
+               goto cleanup_fetch_url;
+#endif
        default:
                if (message)
                        warnx("Error proxy connect " "`%s'", message);
@@ -1237,6 +1265,9 @@
 cleanup_fetch_url:
        rv = C_CLEANUP;
        goto out;
+restart_fetch_url:
+       rv = C_RESTART;
+       goto out;
 out:
        FREEPTR(message);
        return rv;
@@ -1445,6 +1476,10 @@
                if (isproxy && oui.utype == HTTPS_URL_T) {
                        switch (connectmethod(s, fin, &oui, &ui, &pauth, &auth,
                            &hasleading)) {
+                       case C_RESTART:
+                               rval = fetch_url(url, penv, pauth.auth,
+                                   wauth.auth);
+                               /*FALLTHROUGH*/
                        case C_CLEANUP:
                                goto cleanup_fetch_url;
                        case C_IMPROPER:



Home | Main Index | Thread Index | Old Index