From 17e8d60c01f8f020e3738db855584f23fb892a04 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 19 Feb 2007 11:53:54 +0000 Subject: - Robson Braga Araujo made passive FTP transfers work with SOCKS (both 4 and 5). --- lib/ftp.c | 17 +++++++++++++++++ lib/socks.c | 22 ++++++++++++++-------- lib/socks.h | 6 ++++++ lib/url.c | 6 ++++-- 4 files changed, 41 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/ftp.c b/lib/ftp.c index e0884437a..28ecdcdc1 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -1737,6 +1737,23 @@ static CURLcode ftp_state_pasv_resp(struct connectdata *conn, /* this just dumps information about this second connection */ ftp_pasv_verbose(conn, conninfo, newhost, connectport); + switch(data->set.proxytype) { + case CURLPROXY_SOCKS5: + result = Curl_SOCKS5(conn->proxyuser, conn->proxypasswd, newhost, newport, + SECONDARYSOCKET, conn); + break; + case CURLPROXY_HTTP: + /* do nothing here. handled later. */ + break; + case CURLPROXY_SOCKS4: + result = Curl_SOCKS4(conn->proxyuser, newhost, newport, + SECONDARYSOCKET, conn); + break; + default: + failf(data, "unknown proxytype option given"); + result = CURLE_COULDNT_CONNECT; + break; + } #ifndef CURL_DISABLE_HTTP if(conn->bits.tunnel_proxy && conn->bits.httpproxy) { /* FIX: this MUST wait for a proper connect first if 'connected' is diff --git a/lib/socks.c b/lib/socks.c index b8bda8eeb..accab029b 100644 --- a/lib/socks.c +++ b/lib/socks.c @@ -108,12 +108,15 @@ static int blockread_all(struct connectdata *conn, /* connection data */ * Nonsupport "Identification Protocol (RFC1413)" */ CURLcode Curl_SOCKS4(const char *proxy_name, + char *hostname, + int remote_port, + int sockindex, struct connectdata *conn) { unsigned char socksreq[262]; /* room for SOCKS4 request incl. user id */ int result; CURLcode code; - curl_socket_t sock = conn->sock[FIRSTSOCKET]; + curl_socket_t sock = conn->sock[sockindex]; long timeout; struct SessionHandle *data = conn->data; @@ -146,7 +149,7 @@ CURLcode Curl_SOCKS4(const char *proxy_name, socksreq[0] = 4; /* version (SOCKS4) */ socksreq[1] = 1; /* connect */ - *((unsigned short*)&socksreq[2]) = htons(conn->remote_port); + *((unsigned short*)&socksreq[2]) = htons(remote_port); /* DNS resolve */ { @@ -154,7 +157,7 @@ CURLcode Curl_SOCKS4(const char *proxy_name, Curl_addrinfo *hp=NULL; int rc; - rc = Curl_resolv(conn, conn->host.name, (int)conn->remote_port, &dns); + rc = Curl_resolv(conn, hostname, remote_port, &dns); if(rc == CURLRESOLV_ERROR) return CURLE_COULDNT_RESOLVE_PROXY; @@ -190,7 +193,7 @@ CURLcode Curl_SOCKS4(const char *proxy_name, } if(!hp) { failf(data, "Failed to resolve \"%s\" for SOCKS4 connect.", - conn->host.name); + hostname); return CURLE_COULDNT_RESOLVE_HOST; } } @@ -312,6 +315,9 @@ CURLcode Curl_SOCKS4(const char *proxy_name, */ CURLcode Curl_SOCKS5(const char *proxy_name, const char *proxy_password, + char *hostname, + int remote_port, + int sockindex, struct connectdata *conn) { /* @@ -336,7 +342,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name, ssize_t written; int result; CURLcode code; - curl_socket_t sock = conn->sock[FIRSTSOCKET]; + curl_socket_t sock = conn->sock[sockindex]; struct SessionHandle *data = conn->data; long timeout; @@ -507,7 +513,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name, { struct Curl_dns_entry *dns; Curl_addrinfo *hp=NULL; - int rc = Curl_resolv(conn, conn->host.name, (int)conn->remote_port, &dns); + int rc = Curl_resolv(conn, hostname, remote_port, &dns); if(rc == CURLRESOLV_ERROR) return CURLE_COULDNT_RESOLVE_HOST; @@ -541,12 +547,12 @@ CURLcode Curl_SOCKS5(const char *proxy_name, } if(!hp) { failf(data, "Failed to resolve \"%s\" for SOCKS5 connect.", - conn->host.name); + hostname); return CURLE_COULDNT_RESOLVE_HOST; } } - *((unsigned short*)&socksreq[8]) = htons(conn->remote_port); + *((unsigned short*)&socksreq[8]) = htons(remote_port); { const int packetsize = 10; diff --git a/lib/socks.h b/lib/socks.h index 0da987998..471b26224 100644 --- a/lib/socks.h +++ b/lib/socks.h @@ -28,6 +28,9 @@ * final destination server. */ CURLcode Curl_SOCKS4(const char *proxy_name, + char *hostname, + int remote_port, + int sockindex, struct connectdata *conn); /* @@ -36,6 +39,9 @@ CURLcode Curl_SOCKS4(const char *proxy_name, */ CURLcode Curl_SOCKS5(const char *proxy_name, const char *proxy_password, + char *hostname, + int remote_port, + int sockindex, struct connectdata *conn); #endif diff --git a/lib/url.c b/lib/url.c index 6d1fa0459..692e66c2d 100644 --- a/lib/url.c +++ b/lib/url.c @@ -2287,13 +2287,15 @@ static CURLcode ConnectPlease(struct SessionHandle *data, switch(data->set.proxytype) { case CURLPROXY_SOCKS5: - result = Curl_SOCKS5(conn->proxyuser, conn->proxypasswd, conn); + result = Curl_SOCKS5(conn->proxyuser, conn->proxypasswd, conn->host.name, + conn->remote_port, FIRSTSOCKET, conn); break; case CURLPROXY_HTTP: /* do nothing here. handled later. */ break; case CURLPROXY_SOCKS4: - result = Curl_SOCKS4(conn->proxyuser, conn); + result = Curl_SOCKS4(conn->proxyuser, conn->host.name, conn->remote_port, + FIRSTSOCKET, conn); break; default: failf(data, "unknown proxytype option given"); -- cgit v1.2.3