Index: usr.sbin/portsnap/phttpget/phttpget.c =================================================================== --- usr.sbin/portsnap/phttpget/phttpget.c +++ usr.sbin/portsnap/phttpget/phttpget.c @@ -45,12 +45,13 @@ #include #include #include +#include -static const char * env_HTTP_PROXY; +static const char env_HTTP_PROXY[MAXHOSTNAMELEN+1]; static char * env_HTTP_PROXY_AUTH; static const char * env_HTTP_USER_AGENT; static char * env_HTTP_TIMEOUT; -static const char * proxyport; +static const char proxyport[URL_SCHEMELEN+1]; static char * proxyauth; static struct timeval timo = { 15, 0}; @@ -106,7 +107,7 @@ /* Write 4 bytes */ for (j = 0; j < 4; j++) { - if (j <= ptlen + 1) + if (j <= ptlen) pc[j] = base64[(t >> 18) & 0x3f]; else pc[j] = '='; @@ -128,23 +129,7 @@ char *proxy_auth_user = NULL; char *proxy_auth_pass = NULL; long http_timeout; - - env_HTTP_PROXY = getenv("HTTP_PROXY"); - if (env_HTTP_PROXY == NULL) - env_HTTP_PROXY = getenv("http_proxy"); - if (env_HTTP_PROXY != NULL) { - if (strncmp(env_HTTP_PROXY, "http://", 7) == 0) - env_HTTP_PROXY += 7; - p = strchr(env_HTTP_PROXY, '/'); - if (p != NULL) - *p = 0; - p = strchr(env_HTTP_PROXY, ':'); - if (p != NULL) { - *p = 0; - proxyport = p + 1; - } else - proxyport = "3128"; - } + struct url *proxy_url = NULL; env_HTTP_PROXY_AUTH = getenv("HTTP_PROXY_AUTH"); if ((env_HTTP_PROXY != NULL) && @@ -161,6 +146,21 @@ proxy_auth_pass = env_HTTP_PROXY_AUTH; } + p = getenv("HTTP_PROXY"); + if (p == NULL) + p = getenv("http_proxy"); + if(p != NULL) + proxy_url = fetchParseURL(p); + if (proxy_url != NULL) { + if (proxy_url->port == 0) + proxy_url->port = 3183; + sprintf(env_HTTP_PROXY, "%s", proxy_url->host); + sprintf(proxyport, "%d", proxy_url->port); + /* Overrides HTTP_PROXY_AUTH */ + proxy_auth_user = proxy_url->user; + proxy_auth_pass = proxy_url->pass; + } + if ((proxy_auth_user != NULL) && (proxy_auth_pass != NULL)) { asprintf(&proxy_auth_userpass, "%s:%s", proxy_auth_user, proxy_auth_pass); @@ -181,6 +181,9 @@ } else proxyauth = NULL; + if (proxy_url != NULL) + fetchFreeURL(proxy_url); + env_HTTP_USER_AGENT = getenv("HTTP_USER_AGENT"); if (env_HTTP_USER_AGENT == NULL) env_HTTP_USER_AGENT = "phttpget/0.1";