Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/ftp ftp(1): split the auth processing function.
details: https://anonhg.NetBSD.org/src/rev/afe5f297a210
branches: trunk
changeset: 821728:afe5f297a210
user: nonaka <nonaka%NetBSD.org@localhost>
date: Wed Feb 15 11:52:11 2017 +0000
description:
ftp(1): split the auth processing function.
diffstat:
usr.bin/ftp/fetch.c | 137 +++++++++++++++++++++------------------------------
1 files changed, 56 insertions(+), 81 deletions(-)
diffs (208 lines):
diff -r 67082b42dc15 -r afe5f297a210 usr.bin/ftp/fetch.c
--- a/usr.bin/ftp/fetch.c Wed Feb 15 06:53:55 2017 +0000
+++ b/usr.bin/ftp/fetch.c Wed Feb 15 11:52:11 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fetch.c,v 1.227 2017/01/31 21:05:35 christos Exp $ */
+/* $NetBSD: fetch.c,v 1.228 2017/02/15 11:52:11 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.227 2017/01/31 21:05:35 christos Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.228 2017/02/15 11:52:11 nonaka Exp $");
#endif /* not lint */
/*
@@ -855,7 +855,6 @@
#define C_OK 0
#define C_CLEANUP 1
#define C_IMPROPER 2
-#define C_RESTART 3
static int
getresponseline(FETCH *fin, char *buf, size_t buflen, int *len)
@@ -950,6 +949,52 @@
return 0;
}
+#ifndef NO_AUTH
+static void
+do_auth(int hcode, const char *url, const char *penv, struct authinfo *wauth,
+ struct authinfo *pauth, char **auth, const char *message,
+ volatile int *rval)
+{
+ struct authinfo aauth;
+ char *response;
+
+ if (hcode == 401)
+ aauth = *wauth;
+ else
+ aauth = *pauth;
+
+ if (verbose || aauth.auth == NULL ||
+ aauth.user == NULL || aauth.pass == NULL)
+ fprintf(ttyout, "%s\n", message);
+ if (EMPTYSTRING(*auth)) {
+ warnx("No authentication challenge provided by server");
+ return;
+ }
+
+ if (aauth.auth != NULL) {
+ char reply[10];
+
+ fprintf(ttyout, "Authorization failed. Retry (y/n)? ");
+ if (get_line(stdin, reply, sizeof(reply), NULL) < 0) {
+ return;
+ }
+ if (tolower((unsigned char)reply[0]) != 'y')
+ return;
+
+ aauth.user = NULL;
+ aauth.pass = NULL;
+ }
+
+ if (auth_url(*auth, &response, &aauth) == 0) {
+ *rval = fetch_url(url, penv,
+ hcode == 401 ? pauth->auth : response,
+ hcode == 401 ? response: wauth->auth);
+ memset(response, 0, strlen(response));
+ FREEPTR(response);
+ }
+}
+#endif
+
static int
negotiate_connection(FETCH *fin, const char *url, const char *penv,
struct posinfo *pi, time_t *mtime, struct authinfo *wauth,
@@ -1085,49 +1130,8 @@
#ifndef NO_AUTH
case 401:
case 407:
- {
- struct authinfo aauth;
- char **authp;
-
- if (hcode == 401)
- aauth = *wauth;
- else
- aauth = *pauth;
-
- if (verbose || aauth.auth == NULL ||
- aauth.user == NULL || aauth.pass == NULL)
- fprintf(ttyout, "%s\n", message);
- if (EMPTYSTRING(*auth)) {
- warnx(
- "No authentication challenge provided by server");
- goto cleanup_fetch_url;
- }
-
- if (aauth.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;
- aauth.user = NULL;
- aauth.pass = NULL;
- }
-
- authp = &aauth.auth;
- if (auth_url(*auth, authp, &aauth) == 0) {
- *rval = fetch_url(url, penv,
- hcode == 401 ? pauth->auth : aauth.auth,
- hcode == 401 ? aauth.auth : wauth->auth);
- memset(*authp, 0, strlen(*authp));
- FREEPTR(*authp);
- }
+ do_auth(hcode, url, penv, wauth, pauth, auth, message, rval);
goto cleanup_fetch_url;
- }
#endif
default:
if (message)
@@ -1153,8 +1157,9 @@
#ifdef WITH_SSL
static int
-connectmethod(int s, FETCH *fin, struct urlinfo *oui, struct urlinfo *ui,
- struct authinfo *pauth, char **auth, int *hasleading)
+connectmethod(FETCH *fin, const char *url, const char *penv,
+ struct urlinfo *oui, struct urlinfo *ui, struct authinfo *wauth,
+ struct authinfo *pauth, char **auth, int *hasleading, volatile int *rval)
{
void *ssl;
int hcode, rv;
@@ -1219,30 +1224,7 @@
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;
+ do_auth(hcode, url, penv, wauth, pauth, auth, message, rval);
goto cleanup_fetch_url;
#endif
default:
@@ -1253,7 +1235,7 @@
goto cleanup_fetch_url;
}
- if ((ssl = fetch_start_ssl(s, oui->host)) == NULL)
+ if ((ssl = fetch_start_ssl(fetch_fileno(fin), oui->host)) == NULL)
goto cleanup_fetch_url;
fetch_set_ssl(fin, ssl);
@@ -1265,9 +1247,6 @@
cleanup_fetch_url:
rv = C_CLEANUP;
goto out;
-restart_fetch_url:
- rv = C_RESTART;
- goto out;
out:
FREEPTR(message);
return rv;
@@ -1480,12 +1459,8 @@
hasleading = 0;
#ifdef WITH_SSL
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*/
+ switch (connectmethod(fin, url, penv, &oui, &ui,
+ &wauth, &pauth, &auth, &hasleading, &rval)) {
case C_CLEANUP:
goto cleanup_fetch_url;
case C_IMPROPER:
Home |
Main Index |
Thread Index |
Old Index