version 1.72, 2007/02/08 03:19:12 |
version 1.73, 2007/04/17 14:58:51 |
|
|
#include <string.h> |
#include <string.h> |
#include <unistd.h> |
#include <unistd.h> |
#include <util.h> |
#include <util.h> |
|
#include <resolv.h> |
|
|
#ifndef SMALL |
#ifndef SMALL |
#include <openssl/ssl.h> |
#include <openssl/ssl.h> |
|
|
#define FTP_PROXY "ftp_proxy" /* env var with ftp proxy location */ |
#define FTP_PROXY "ftp_proxy" /* env var with ftp proxy location */ |
#define HTTP_PROXY "http_proxy" /* env var with http proxy location */ |
#define HTTP_PROXY "http_proxy" /* env var with http proxy location */ |
|
|
|
#define COOKIE_MAX_LEN 42 |
|
|
#define EMPTYSTRING(x) ((x) == NULL || (*(x) == '\0')) |
#define EMPTYSTRING(x) ((x) == NULL || (*(x) == '\0')) |
|
|
|
|
struct addrinfo hints, *res0, *res; |
struct addrinfo hints, *res0, *res; |
const char * volatile savefile; |
const char * volatile savefile; |
char * volatile proxyurl = NULL; |
char * volatile proxyurl = NULL; |
|
char *cookie = NULL; |
volatile int s = -1, out; |
volatile int s = -1, out; |
volatile sig_t oldintr; |
volatile sig_t oldintr; |
FILE *fin = NULL; |
FILE *fin = NULL; |
|
|
*--path = '/'; /* add / back to real path */ |
*--path = '/'; /* add / back to real path */ |
path = strchr(host, '/'); /* remove trailing / on host */ |
path = strchr(host, '/'); /* remove trailing / on host */ |
if (!EMPTYSTRING(path)) |
if (!EMPTYSTRING(path)) |
|
*path++ = '\0'; /* i guess this ++ is useless */ |
|
|
|
path = strchr(host, '@'); /* look for credentials in proxy */ |
|
if (!EMPTYSTRING(path)) { |
*path++ = '\0'; |
*path++ = '\0'; |
|
cookie = strchr(host, ':'); |
|
if (EMPTYSTRING(cookie)) { |
|
warnx("Malformed proxy URL: %s", proxyenv); |
|
goto cleanup_url_get; |
|
} |
|
cookie = malloc(COOKIE_MAX_LEN); |
|
b64_ntop(host, strlen(host), cookie, COOKIE_MAX_LEN); |
|
/* |
|
* This removes the password from proxyenv, |
|
* filling with stars |
|
*/ |
|
for (host = strchr(proxyenv + 5, ':'); *host != '@'; |
|
host++) |
|
*host = '*'; |
|
|
|
host = path; |
|
} |
path = newline; |
path = newline; |
} |
} |
|
|
|
|
* Host: directive must use the destination host address for |
* 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). We do not attach it at this moment. |
*/ |
*/ |
ftp_printf(fin, ssl, "GET %s HTTP/1.0\r\n%s\r\n\r\n", path, |
if (cookie) |
HTTP_USER_AGENT); |
ftp_printf(fin, ssl, "GET %s HTTP/1.0\r\n" |
|
"Proxy-Authorization: Basic %s\r\n%s\r\n\r\n", |
|
path, cookie, HTTP_USER_AGENT); |
|
else |
|
ftp_printf(fin, ssl, "GET %s HTTP/1.0\r\n%s\r\n\r\n", |
|
path, HTTP_USER_AGENT); |
|
|
} else { |
} else { |
ftp_printf(fin, ssl, "GET /%s HTTP/1.0\r\nHost: ", path); |
ftp_printf(fin, ssl, "GET /%s HTTP/1.0\r\nHost: ", path); |
if (strchr(host, ':')) { |
if (strchr(host, ':')) { |