On 12/01/15(Mon) 14:22, Alexander Bluhm wrote:
> On Mon, Jan 12, 2015 at 01:04:14PM +0000, Stuart Henderson wrote:
> > Good catch, definition for *proxyhost needs to go outside the #ifndef.
>
> Thanks, new diff:
Awesome, I can now run fw_update(1) behind our broken proxy. ok with
me.
>
> 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 12 Jan 2015 13:17:38 -0000
> @@ -187,6 +187,7 @@ url_get(const char *origline, const char
> off_t hashbytes;
> const char *errstr;
> ssize_t len, wlen;
> + char *proxyhost = NULL;
> #ifndef SMALL
> char *sslpath = NULL, *sslhost = NULL;
> char *locbase, *full_host = NULL;
> @@ -300,6 +301,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 +644,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 +681,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 +999,7 @@ cleanup_url_get:
> else if (s != -1)
> close(s);
> free(buf);
> + free(proxyhost);
> free(proxyurl);
> free(newline);
> free(credentials);
> @@ -1486,6 +1495,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);
> }
>
>