version 1.189, 2020/02/13 15:54:10 |
version 1.190, 2020/02/19 07:29:53 |
|
|
struct addrinfo hints, *res0, *res; |
struct addrinfo hints, *res0, *res; |
const char *savefile; |
const char *savefile; |
char *proxyurl = NULL; |
char *proxyurl = NULL; |
char *credentials = NULL; |
char *credentials = NULL, *proxy_credentials = NULL; |
int fd = -1, out = -1; |
int fd = -1, out = -1; |
volatile sig_t oldintr, oldinti; |
volatile sig_t oldintr, oldinti; |
FILE *fin = NULL; |
FILE *fin = NULL; |
|
|
* contain the path. Basic auth from RFC 2617, valid |
* contain the path. Basic auth from RFC 2617, valid |
* characters for path are in RFC 3986 section 3.3. |
* characters for path are in RFC 3986 section 3.3. |
*/ |
*/ |
if (proxyenv == NULL && (ishttpurl || ishttpsurl)) { |
if (ishttpurl || ishttpsurl) { |
if ((p = strchr(host, '@')) != NULL) { |
if ((p = strchr(host, '@')) != NULL) { |
*p = '\0'; |
*p = '\0'; |
credentials = recode_credentials(host); |
credentials = recode_credentials(host); |
|
|
warnx("Malformed proxy URL: %s", proxyenv); |
warnx("Malformed proxy URL: %s", proxyenv); |
goto cleanup_url_get; |
goto cleanup_url_get; |
} |
} |
credentials = recode_credentials(host); |
proxy_credentials = recode_credentials(host); |
*path = '@'; /* restore @ in proxyurl */ |
*path = '@'; /* restore @ in proxyurl */ |
|
|
/* |
/* |
|
|
|
|
#ifndef NOSSL |
#ifndef NOSSL |
if (proxyenv && sslhost) |
if (proxyenv && sslhost) |
proxy_connect(fd, sslhost, credentials); |
proxy_connect(fd, sslhost, proxy_credentials); |
#endif /* !NOSSL */ |
#endif /* !NOSSL */ |
break; |
break; |
} |
} |
|
|
* Host: directive must use the destination host address for |
* Host: directive must use the destination host address for |
* the original URI (path). |
* the original URI (path). |
*/ |
*/ |
|
ftp_printf(fin, "GET %s HTTP/1.1\r\n" |
|
"Connection: close\r\n" |
|
"Host: %s\r\n%s%s\r\n", |
|
epath, proxyhost, buf ? buf : "", httpuseragent); |
if (credentials) |
if (credentials) |
ftp_printf(fin, "GET %s HTTP/1.1\r\n" |
ftp_printf(fin, "Authorization: Basic %s\r\n", |
"Connection: close\r\n" |
credentials); |
"Proxy-Authorization: Basic %s\r\n" |
if (proxy_credentials) |
"Host: %s\r\n%s%s\r\n\r\n", |
ftp_printf(fin, "Proxy-Authorization: Basic %s\r\n", |
epath, credentials, |
proxy_credentials); |
proxyhost, buf ? buf : "", httpuseragent); |
ftp_printf(fin, "\r\n"); |
else |
|
ftp_printf(fin, "GET %s HTTP/1.1\r\n" |
|
"Connection: close\r\n" |
|
"Host: %s\r\n%s%s\r\n\r\n", |
|
epath, proxyhost, buf ? buf : "", httpuseragent); |
|
} else { |
} else { |
if (verbose) |
if (verbose) |
fprintf(ttyout, "Requesting %s\n", origline); |
fprintf(ttyout, "Requesting %s\n", origline); |
|
|
free(proxyurl); |
free(proxyurl); |
free(newline); |
free(newline); |
free(credentials); |
free(credentials); |
|
free(proxy_credentials); |
return (rval); |
return (rval); |
} |
} |
|
|
|
|
{ |
{ |
int l; |
int l; |
char buf[1024]; |
char buf[1024]; |
char *connstr, *hosttail, *port; |
char *connstr, *hosttail, *port, *crlf; |
|
ssize_t sz; |
|
|
if (*host == '[' && (hosttail = strrchr(host, ']')) != NULL && |
if (*host == '[' && (hosttail = strrchr(host, ']')) != NULL && |
(hosttail[1] == '\0' || hosttail[1] == ':')) { |
(hosttail[1] == '\0' || hosttail[1] == ':')) { |
|
|
#endif /* !SMALL */ |
#endif /* !SMALL */ |
if (write(socket, connstr, l) != l) |
if (write(socket, connstr, l) != l) |
err(1, "Could not send connect string"); |
err(1, "Could not send connect string"); |
read(socket, &buf, sizeof(buf)); /* only proxy header XXX: error handling? */ |
sz = read(socket, &buf, sizeof(buf) - 1); |
|
if (sz < 0) |
|
err(1, "Failed to receive response from proxy"); |
|
/* XXX should not assume we could read entire response at once. */ |
|
buf[sz] = '\0'; |
|
if ((strncmp(buf, "HTTP/1.0 ", 9) != 0 && |
|
strncmp(buf, "HTTP/1.1 ", 9) != 0) || |
|
(crlf = strstr(buf, "\r\n")) == NULL) |
|
errx(1, "Could not parse received response from proxy"); |
|
*crlf = '\0'; |
|
if (strncmp(buf + 9, "200 ", 4) != 0) |
|
errx(1, "CONNECT command on proxy failed: %s", buf + 9); |
|
*crlf = '\r'; /* revert CR */ |
|
if ((crlf = strstr(buf, "\r\n\r\n")) == NULL) |
|
errx(1, "Could not read the end of response from proxy"); |
|
|
free(connstr); |
free(connstr); |
return(200); |
return(200); |
} |
} |