Hi,
Fetching port distfiles with ftp from githup does not work when
using a https proxy. The problem is that the http Host header is
not not set and githup.com needs that.
So remember the host form the url and write it into the http request.
Also write the http request into the debugging output to see what
is going on.
Note that using Proxy-Authorization together with Cookie did not
work. I have fixed the format string.
ok?
bluhm
Index: usr.bin/ftp/fetch.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/usr.bin/ftp/fetch.c,v
retrieving revision 1.135
diff -u -p -r1.135 fetch.c
--- usr.bin/ftp/fetch.c 25 Nov 2014 08:22:09 -0000 1.135
+++ usr.bin/ftp/fetch.c 10 Jan 2015 01:04:03 -0000
@@ -188,7 +188,7 @@ url_get(const char *origline, const char
const char *errstr;
ssize_t len, wlen;
#ifndef SMALL
- char *sslpath = NULL, *sslhost = NULL;
+ char *sslpath = NULL, *sslhost = NULL, *proxyhost = NULL;
char *locbase, *full_host = NULL;
const char *scheme;
int ishttpurl = 0, ishttpsurl = 0;
@@ -300,6 +300,9 @@ noslash:
errx(1, "Can't allocate memory for https
path/host.");
}
#endif /* !SMALL */
+ proxyhost = strdup(host);
+ if (proxyhost == NULL)
+ errx(1, "Can't allocate memory for proxy host.");
proxyurl = strdup(proxyenv);
if (proxyurl == NULL)
errx(1, "Can't allocate memory for proxy URL.");
@@ -640,17 +643,18 @@ again:
fprintf(ttyout, " (via %s)\n", proxyurl);
/*
* Host: directive must use the destination host address for
- * the original URI (path). We do not attach it at this moment.
+ * the original URI (path).
*/
if (credentials)
ftp_printf(fin, tls, "GET %s HTTP/1.0\r\n"
- "Proxy-Authorization: Basic %s%s\r\n%s\r\n\r\n",
- epath, credentials, buf ? buf : "",
- httpuseragent);
+ "Proxy-Authorization: Basic %s\r\n"
+ "Host: %s\r\n%s%s\r\n\r\n",
+ epath, credentials,
+ proxyhost, buf ? buf : "", httpuseragent);
else
- ftp_printf(fin, tls, "GET %s HTTP/1.0\r\n%s%s\r\n\r\n",
- epath, buf ? buf : "", httpuseragent);
-
+ ftp_printf(fin, tls, "GET %s HTTP/1.0\r\n"
+ "Host: %s\r\n%s%s\r\n\r\n",
+ epath, proxyhost, buf ? buf : "", httpuseragent);
} else {
#ifndef SMALL
if (resume) {
@@ -676,7 +680,10 @@ again:
restart_point ? "HTTP/1.1\r\nConnection: close" :
#endif /* !SMALL */
"HTTP/1.0");
- if (strchr(host, ':')) {
+ if (proxyhost) {
+ ftp_printf(fin, tls, "%s", proxyhost);
+ port = NULL;
+ } else if (strchr(host, ':')) {
/*
* strip off scoped address portion, since it's
* local to node
@@ -991,6 +998,7 @@ cleanup_url_get:
else if (s != -1)
close(s);
free(buf);
+ free(proxyhost);
free(proxyurl);
free(newline);
free(credentials);
@@ -1486,6 +1494,13 @@ ftp_printf(FILE *fp, struct tls *tls, co
ret = 0;
va_end(ap);
+#ifndef SMALL
+ if (debug) {
+ va_start(ap, fmt);
+ ret = vfprintf(ttyout, fmt, ap);
+ va_end(ap);
+ }
+#endif /* !SMALL */
return (ret);
}