diff --git a/lib/libfetch/fetch.c b/lib/libfetch/fetch.c index cb09efcfeac4..3eb8075fc780 100644 --- a/lib/libfetch/fetch.c +++ b/lib/libfetch/fetch.c @@ -80,9 +80,6 @@ fetchXGet(struct url *URL, struct url_stat *us, char *flags) else if (strcasecmp(URL->scheme, "http") == 0) return fetchXGetHTTP(URL, us, flags); else if (strcasecmp(URL->scheme, "ftp") == 0) { - if (!direct && - getenv("FTP_PROXY") == NULL && getenv("HTTP_PROXY") != NULL) - return fetchXGetHTTP(URL, us, flags); return fetchXGetFTP(URL, us, flags); } else { _url_seterr(URL_BAD_SCHEME); @@ -115,9 +112,6 @@ fetchPut(struct url *URL, char *flags) else if (strcasecmp(URL->scheme, "http") == 0) return fetchPutHTTP(URL, flags); else if (strcasecmp(URL->scheme, "ftp") == 0) { - if (!direct && - getenv("FTP_PROXY") == NULL && getenv("HTTP_PROXY") != NULL) - return fetchPutHTTP(URL, flags); return fetchPutFTP(URL, flags); } else { _url_seterr(URL_BAD_SCHEME); @@ -140,9 +134,6 @@ fetchStat(struct url *URL, struct url_stat *us, char *flags) else if (strcasecmp(URL->scheme, "http") == 0) return fetchStatHTTP(URL, us, flags); else if (strcasecmp(URL->scheme, "ftp") == 0) { - if (!direct && - getenv("FTP_PROXY") == NULL && getenv("HTTP_PROXY") != NULL) - return fetchStatHTTP(URL, us, flags); return fetchStatFTP(URL, us, flags); } else { _url_seterr(URL_BAD_SCHEME); @@ -165,9 +156,6 @@ fetchList(struct url *URL, char *flags) else if (strcasecmp(URL->scheme, "http") == 0) return fetchListHTTP(URL, flags); else if (strcasecmp(URL->scheme, "ftp") == 0) { - if (!direct && - getenv("FTP_PROXY") == NULL && getenv("HTTP_PROXY") != NULL) - return fetchListHTTP(URL, flags); return fetchListFTP(URL, flags); } else { _url_seterr(URL_BAD_SCHEME); diff --git a/lib/libfetch/ftp.c b/lib/libfetch/ftp.c index de7d2d8db1b0..a5eb1d351734 100644 --- a/lib/libfetch/ftp.c +++ b/lib/libfetch/ftp.c @@ -594,7 +594,7 @@ _ftp_connect(char *host, int port, char *user, char *pwd, char *flags) af = AF_INET6; /* check for proxy */ - if (!direct && (p = getenv("FTP_PROXY")) != NULL) { + if (!direct && (p = getenv("FTP_PROXY")) != NULL && *p) { char c = 0; #ifdef INET6 @@ -762,6 +762,17 @@ _ftp_cached_connect(struct url *url, char *flags) return cd; } +/* + * Check to see if we should use an HTTP proxy instead + */ +static int +_ftp_use_http_proxy(void) +{ + char *p; + + return ((p = getenv("HTTP_PROXY")) && *p && !getenv("FTP_PROXY")); +} + /* * Get and stat file */ @@ -769,6 +780,9 @@ FILE * fetchXGetFTP(struct url *url, struct url_stat *us, char *flags) { int cd; + + if (_ftp_use_http_proxy()) + return fetchXGetHTTP(url, us, flags); /* connect to server */ if ((cd = _ftp_cached_connect(url, flags)) == NULL) @@ -804,6 +818,9 @@ fetchPutFTP(struct url *url, char *flags) { int cd; + if (_ftp_use_http_proxy()) + return fetchPutHTTP(url, flags); + /* connect to server */ if ((cd = _ftp_cached_connect(url, flags)) == NULL) return NULL; @@ -825,6 +842,9 @@ fetchStatFTP(struct url *url, struct url_stat *us, char *flags) { int cd; + if (_ftp_use_http_proxy()) + return fetchStatHTTP(url, us, flags); + us->size = -1; us->atime = us->mtime = 0; @@ -847,6 +867,9 @@ extern void warnx(char *, ...); struct url_ent * fetchListFTP(struct url *url, char *flags) { + if (_ftp_use_http_proxy()) + return fetchListHTTP(url, flags); + warnx("fetchListFTP(): not implemented"); return NULL; }