Skip to content

Commit efc83d6

Browse files
committed
http-proxy: only attempt FTP over HTTP proxy
... all other non-HTTP protocol schemes are now defaulting to "tunnel trough" mode if a HTTP proxy is specified. In reality there are no HTTP proxies out there that allow those other schemes. Assisted-by: Ray Satiro, Michael Kaufmann Closes #1505
1 parent 4d1147a commit efc83d6

File tree

6 files changed

+14
-313
lines changed

6 files changed

+14
-313
lines changed

lib/ftp.c

+2-77
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ const struct Curl_handler Curl_handler_ftp = {
180180
ZERO_NULL, /* readwrite */
181181
PORT_FTP, /* defport */
182182
CURLPROTO_FTP, /* protocol */
183-
PROTOPT_DUAL | PROTOPT_CLOSEACTION | PROTOPT_NEEDSPWD
184-
| PROTOPT_NOURLQUERY /* flags */
183+
PROTOPT_DUAL | PROTOPT_CLOSEACTION | PROTOPT_NEEDSPWD |
184+
PROTOPT_NOURLQUERY | PROTOPT_PROXY_AS_HTTP /* flags */
185185
};
186186

187187

@@ -212,59 +212,6 @@ const struct Curl_handler Curl_handler_ftps = {
212212
};
213213
#endif
214214

215-
#ifndef CURL_DISABLE_HTTP
216-
/*
217-
* HTTP-proxyed FTP protocol handler.
218-
*/
219-
220-
static const struct Curl_handler Curl_handler_ftp_proxy = {
221-
"FTP", /* scheme */
222-
Curl_http_setup_conn, /* setup_connection */
223-
Curl_http, /* do_it */
224-
Curl_http_done, /* done */
225-
ZERO_NULL, /* do_more */
226-
ZERO_NULL, /* connect_it */
227-
ZERO_NULL, /* connecting */
228-
ZERO_NULL, /* doing */
229-
ZERO_NULL, /* proto_getsock */
230-
ZERO_NULL, /* doing_getsock */
231-
ZERO_NULL, /* domore_getsock */
232-
ZERO_NULL, /* perform_getsock */
233-
ZERO_NULL, /* disconnect */
234-
ZERO_NULL, /* readwrite */
235-
PORT_FTP, /* defport */
236-
CURLPROTO_HTTP, /* protocol */
237-
PROTOPT_NONE /* flags */
238-
};
239-
240-
241-
#ifdef USE_SSL
242-
/*
243-
* HTTP-proxyed FTPS protocol handler.
244-
*/
245-
246-
static const struct Curl_handler Curl_handler_ftps_proxy = {
247-
"FTPS", /* scheme */
248-
Curl_http_setup_conn, /* setup_connection */
249-
Curl_http, /* do_it */
250-
Curl_http_done, /* done */
251-
ZERO_NULL, /* do_more */
252-
ZERO_NULL, /* connect_it */
253-
ZERO_NULL, /* connecting */
254-
ZERO_NULL, /* doing */
255-
ZERO_NULL, /* proto_getsock */
256-
ZERO_NULL, /* doing_getsock */
257-
ZERO_NULL, /* domore_getsock */
258-
ZERO_NULL, /* perform_getsock */
259-
ZERO_NULL, /* disconnect */
260-
ZERO_NULL, /* readwrite */
261-
PORT_FTPS, /* defport */
262-
CURLPROTO_HTTP, /* protocol */
263-
PROTOPT_NONE /* flags */
264-
};
265-
#endif
266-
#endif
267-
268215
static void close_secondarysocket(struct connectdata *conn)
269216
{
270217
if(CURL_SOCKET_BAD != conn->sock[SECONDARYSOCKET]) {
@@ -4462,28 +4409,6 @@ static CURLcode ftp_setup_connection(struct connectdata *conn)
44624409
char command;
44634410
struct FTP *ftp;
44644411

4465-
if(conn->bits.httpproxy && !data->set.tunnel_thru_httpproxy) {
4466-
/* Unless we have asked to tunnel ftp operations through the proxy, we
4467-
switch and use HTTP operations only */
4468-
#ifndef CURL_DISABLE_HTTP
4469-
if(conn->handler == &Curl_handler_ftp)
4470-
conn->handler = &Curl_handler_ftp_proxy;
4471-
else {
4472-
#ifdef USE_SSL
4473-
conn->handler = &Curl_handler_ftps_proxy;
4474-
#else
4475-
failf(data, "FTPS not supported!");
4476-
return CURLE_UNSUPPORTED_PROTOCOL;
4477-
#endif
4478-
}
4479-
/* set it up as a HTTP connection instead */
4480-
return conn->handler->setup_connection(conn);
4481-
#else
4482-
failf(data, "FTP over http proxy requires HTTP support built-in!");
4483-
return CURLE_UNSUPPORTED_PROTOCOL;
4484-
#endif
4485-
}
4486-
44874412
conn->data->req.protop = ftp = malloc(sizeof(struct FTP));
44884413
if(NULL == ftp)
44894414
return CURLE_OUT_OF_MEMORY;

lib/imap.c

-77
Original file line numberDiff line numberDiff line change
@@ -160,58 +160,6 @@ const struct Curl_handler Curl_handler_imaps = {
160160
};
161161
#endif
162162

163-
#ifndef CURL_DISABLE_HTTP
164-
/*
165-
* HTTP-proxyed IMAP protocol handler.
166-
*/
167-
168-
static const struct Curl_handler Curl_handler_imap_proxy = {
169-
"IMAP", /* scheme */
170-
Curl_http_setup_conn, /* setup_connection */
171-
Curl_http, /* do_it */
172-
Curl_http_done, /* done */
173-
ZERO_NULL, /* do_more */
174-
ZERO_NULL, /* connect_it */
175-
ZERO_NULL, /* connecting */
176-
ZERO_NULL, /* doing */
177-
ZERO_NULL, /* proto_getsock */
178-
ZERO_NULL, /* doing_getsock */
179-
ZERO_NULL, /* domore_getsock */
180-
ZERO_NULL, /* perform_getsock */
181-
ZERO_NULL, /* disconnect */
182-
ZERO_NULL, /* readwrite */
183-
PORT_IMAP, /* defport */
184-
CURLPROTO_HTTP, /* protocol */
185-
PROTOPT_NONE /* flags */
186-
};
187-
188-
#ifdef USE_SSL
189-
/*
190-
* HTTP-proxyed IMAPS protocol handler.
191-
*/
192-
193-
static const struct Curl_handler Curl_handler_imaps_proxy = {
194-
"IMAPS", /* scheme */
195-
Curl_http_setup_conn, /* setup_connection */
196-
Curl_http, /* do_it */
197-
Curl_http_done, /* done */
198-
ZERO_NULL, /* do_more */
199-
ZERO_NULL, /* connect_it */
200-
ZERO_NULL, /* connecting */
201-
ZERO_NULL, /* doing */
202-
ZERO_NULL, /* proto_getsock */
203-
ZERO_NULL, /* doing_getsock */
204-
ZERO_NULL, /* domore_getsock */
205-
ZERO_NULL, /* perform_getsock */
206-
ZERO_NULL, /* disconnect */
207-
ZERO_NULL, /* readwrite */
208-
PORT_IMAPS, /* defport */
209-
CURLPROTO_HTTP, /* protocol */
210-
PROTOPT_NONE /* flags */
211-
};
212-
#endif
213-
#endif
214-
215163
/* SASL parameters for the imap protocol */
216164
static const struct SASLproto saslimap = {
217165
"imap", /* The service name */
@@ -1715,31 +1663,6 @@ static CURLcode imap_setup_connection(struct connectdata *conn)
17151663

17161664
/* Clear the TLS upgraded flag */
17171665
conn->tls_upgraded = FALSE;
1718-
1719-
/* Set up the proxy if necessary */
1720-
if(conn->bits.httpproxy && !data->set.tunnel_thru_httpproxy) {
1721-
/* Unless we have asked to tunnel IMAP operations through the proxy, we
1722-
switch and use HTTP operations only */
1723-
#ifndef CURL_DISABLE_HTTP
1724-
if(conn->handler == &Curl_handler_imap)
1725-
conn->handler = &Curl_handler_imap_proxy;
1726-
else {
1727-
#ifdef USE_SSL
1728-
conn->handler = &Curl_handler_imaps_proxy;
1729-
#else
1730-
failf(data, "IMAPS not supported!");
1731-
return CURLE_UNSUPPORTED_PROTOCOL;
1732-
#endif
1733-
}
1734-
1735-
/* set it up as an HTTP connection instead */
1736-
return conn->handler->setup_connection(conn);
1737-
#else
1738-
failf(data, "IMAP over http proxy requires HTTP support built-in!");
1739-
return CURLE_UNSUPPORTED_PROTOCOL;
1740-
#endif
1741-
}
1742-
17431666
data->state.path++; /* don't include the initial slash */
17441667

17451668
return CURLE_OK;

lib/pop3.c

-77
Original file line numberDiff line numberDiff line change
@@ -158,58 +158,6 @@ const struct Curl_handler Curl_handler_pop3s = {
158158
};
159159
#endif
160160

161-
#ifndef CURL_DISABLE_HTTP
162-
/*
163-
* HTTP-proxyed POP3 protocol handler.
164-
*/
165-
166-
static const struct Curl_handler Curl_handler_pop3_proxy = {
167-
"POP3", /* scheme */
168-
Curl_http_setup_conn, /* setup_connection */
169-
Curl_http, /* do_it */
170-
Curl_http_done, /* done */
171-
ZERO_NULL, /* do_more */
172-
ZERO_NULL, /* connect_it */
173-
ZERO_NULL, /* connecting */
174-
ZERO_NULL, /* doing */
175-
ZERO_NULL, /* proto_getsock */
176-
ZERO_NULL, /* doing_getsock */
177-
ZERO_NULL, /* domore_getsock */
178-
ZERO_NULL, /* perform_getsock */
179-
ZERO_NULL, /* disconnect */
180-
ZERO_NULL, /* readwrite */
181-
PORT_POP3, /* defport */
182-
CURLPROTO_HTTP, /* protocol */
183-
PROTOPT_NONE /* flags */
184-
};
185-
186-
#ifdef USE_SSL
187-
/*
188-
* HTTP-proxyed POP3S protocol handler.
189-
*/
190-
191-
static const struct Curl_handler Curl_handler_pop3s_proxy = {
192-
"POP3S", /* scheme */
193-
Curl_http_setup_conn, /* setup_connection */
194-
Curl_http, /* do_it */
195-
Curl_http_done, /* done */
196-
ZERO_NULL, /* do_more */
197-
ZERO_NULL, /* connect_it */
198-
ZERO_NULL, /* connecting */
199-
ZERO_NULL, /* doing */
200-
ZERO_NULL, /* proto_getsock */
201-
ZERO_NULL, /* doing_getsock */
202-
ZERO_NULL, /* domore_getsock */
203-
ZERO_NULL, /* perform_getsock */
204-
ZERO_NULL, /* disconnect */
205-
ZERO_NULL, /* readwrite */
206-
PORT_POP3S, /* defport */
207-
CURLPROTO_HTTP, /* protocol */
208-
PROTOPT_NONE /* flags */
209-
};
210-
#endif
211-
#endif
212-
213161
/* SASL parameters for the pop3 protocol */
214162
static const struct SASLproto saslpop3 = {
215163
"pop", /* The service name */
@@ -1355,31 +1303,6 @@ static CURLcode pop3_setup_connection(struct connectdata *conn)
13551303

13561304
/* Clear the TLS upgraded flag */
13571305
conn->tls_upgraded = FALSE;
1358-
1359-
/* Set up the proxy if necessary */
1360-
if(conn->bits.httpproxy && !data->set.tunnel_thru_httpproxy) {
1361-
/* Unless we have asked to tunnel POP3 operations through the proxy, we
1362-
switch and use HTTP operations only */
1363-
#ifndef CURL_DISABLE_HTTP
1364-
if(conn->handler == &Curl_handler_pop3)
1365-
conn->handler = &Curl_handler_pop3_proxy;
1366-
else {
1367-
#ifdef USE_SSL
1368-
conn->handler = &Curl_handler_pop3s_proxy;
1369-
#else
1370-
failf(data, "POP3S not supported!");
1371-
return CURLE_UNSUPPORTED_PROTOCOL;
1372-
#endif
1373-
}
1374-
1375-
/* set it up as an HTTP connection instead */
1376-
return conn->handler->setup_connection(conn);
1377-
#else
1378-
failf(data, "POP3 over http proxy requires HTTP support built-in!");
1379-
return CURLE_UNSUPPORTED_PROTOCOL;
1380-
#endif
1381-
}
1382-
13831306
data->state.path++; /* don't include the initial slash */
13841307

13851308
return CURLE_OK;

lib/smtp.c

-76
Original file line numberDiff line numberDiff line change
@@ -157,58 +157,6 @@ const struct Curl_handler Curl_handler_smtps = {
157157
};
158158
#endif
159159

160-
#ifndef CURL_DISABLE_HTTP
161-
/*
162-
* HTTP-proxyed SMTP protocol handler.
163-
*/
164-
165-
static const struct Curl_handler Curl_handler_smtp_proxy = {
166-
"SMTP", /* scheme */
167-
Curl_http_setup_conn, /* setup_connection */
168-
Curl_http, /* do_it */
169-
Curl_http_done, /* done */
170-
ZERO_NULL, /* do_more */
171-
ZERO_NULL, /* connect_it */
172-
ZERO_NULL, /* connecting */
173-
ZERO_NULL, /* doing */
174-
ZERO_NULL, /* proto_getsock */
175-
ZERO_NULL, /* doing_getsock */
176-
ZERO_NULL, /* domore_getsock */
177-
ZERO_NULL, /* perform_getsock */
178-
ZERO_NULL, /* disconnect */
179-
ZERO_NULL, /* readwrite */
180-
PORT_SMTP, /* defport */
181-
CURLPROTO_HTTP, /* protocol */
182-
PROTOPT_NONE /* flags */
183-
};
184-
185-
#ifdef USE_SSL
186-
/*
187-
* HTTP-proxyed SMTPS protocol handler.
188-
*/
189-
190-
static const struct Curl_handler Curl_handler_smtps_proxy = {
191-
"SMTPS", /* scheme */
192-
Curl_http_setup_conn, /* setup_connection */
193-
Curl_http, /* do_it */
194-
Curl_http_done, /* done */
195-
ZERO_NULL, /* do_more */
196-
ZERO_NULL, /* connect_it */
197-
ZERO_NULL, /* connecting */
198-
ZERO_NULL, /* doing */
199-
ZERO_NULL, /* proto_getsock */
200-
ZERO_NULL, /* doing_getsock */
201-
ZERO_NULL, /* domore_getsock */
202-
ZERO_NULL, /* perform_getsock */
203-
ZERO_NULL, /* disconnect */
204-
ZERO_NULL, /* readwrite */
205-
PORT_SMTPS, /* defport */
206-
CURLPROTO_HTTP, /* protocol */
207-
PROTOPT_NONE /* flags */
208-
};
209-
#endif
210-
#endif
211-
212160
/* SASL parameters for the smtp protocol */
213161
static const struct SASLproto saslsmtp = {
214162
"smtp", /* The service name */
@@ -1451,30 +1399,6 @@ static CURLcode smtp_setup_connection(struct connectdata *conn)
14511399
/* Clear the TLS upgraded flag */
14521400
conn->tls_upgraded = FALSE;
14531401

1454-
/* Set up the proxy if necessary */
1455-
if(conn->bits.httpproxy && !data->set.tunnel_thru_httpproxy) {
1456-
/* Unless we have asked to tunnel SMTP operations through the proxy, we
1457-
switch and use HTTP operations only */
1458-
#ifndef CURL_DISABLE_HTTP
1459-
if(conn->handler == &Curl_handler_smtp)
1460-
conn->handler = &Curl_handler_smtp_proxy;
1461-
else {
1462-
#ifdef USE_SSL
1463-
conn->handler = &Curl_handler_smtps_proxy;
1464-
#else
1465-
failf(data, "SMTPS not supported!");
1466-
return CURLE_UNSUPPORTED_PROTOCOL;
1467-
#endif
1468-
}
1469-
/* set it up as a HTTP connection instead */
1470-
return conn->handler->setup_connection(conn);
1471-
1472-
#else
1473-
failf(data, "SMTP over http proxy requires HTTP support built-in!");
1474-
return CURLE_UNSUPPORTED_PROTOCOL;
1475-
#endif
1476-
}
1477-
14781402
/* Initialise the SMTP layer */
14791403
result = smtp_init(conn);
14801404
if(result)

lib/url.c

+9-6
Original file line numberDiff line numberDiff line change
@@ -5348,12 +5348,15 @@ static CURLcode create_conn_helper_init_proxy(struct connectdata *conn)
53485348
result = CURLE_UNSUPPORTED_PROTOCOL;
53495349
goto out;
53505350
#else
5351-
/* force this connection's protocol to become HTTP if not already
5352-
compatible - if it isn't tunneling through */
5353-
if(!(conn->handler->protocol & PROTO_FAMILY_HTTP) &&
5354-
!conn->bits.tunnel_proxy)
5355-
conn->handler = &Curl_handler_http;
5356-
5351+
/* force this connection's protocol to become HTTP if compatible */
5352+
if(!(conn->handler->protocol & PROTO_FAMILY_HTTP)) {
5353+
if((conn->handler->flags & PROTOPT_PROXY_AS_HTTP) &&
5354+
!conn->bits.tunnel_proxy)
5355+
conn->handler = &Curl_handler_http;
5356+
else
5357+
/* if not converting to HTTP over the proxy, enforce tunneling */
5358+
conn->bits.tunnel_proxy = TRUE;
5359+
}
53575360
conn->bits.httpproxy = TRUE;
53585361
#endif
53595362
}

0 commit comments

Comments
 (0)