Skip to content

Commit

Permalink
http-proxy: only attempt FTP over HTTP proxy
Browse files Browse the repository at this point in the history
... all other 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
  • Loading branch information
bagder committed May 22, 2017
1 parent 945919d commit 7906896
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 220 deletions.
4 changes: 2 additions & 2 deletions lib/ftp.c
Expand Up @@ -180,8 +180,8 @@ const struct Curl_handler Curl_handler_ftp = {
ZERO_NULL, /* readwrite */
PORT_FTP, /* defport */
CURLPROTO_FTP, /* protocol */
PROTOPT_DUAL | PROTOPT_CLOSEACTION | PROTOPT_NEEDSPWD
| PROTOPT_NOURLQUERY /* flags */
PROTOPT_DUAL | PROTOPT_CLOSEACTION | PROTOPT_NEEDSPWD |
PROTOPT_NOURLQUERY | PROTOPT_HTTP_PROXY /* flags */
};


Expand Down
73 changes: 2 additions & 71 deletions lib/imap.c
Expand Up @@ -160,58 +160,6 @@ const struct Curl_handler Curl_handler_imaps = {
};
#endif

#ifndef CURL_DISABLE_HTTP
/*
* HTTP-proxyed IMAP protocol handler.
*/

static const struct Curl_handler Curl_handler_imap_proxy = {
"IMAP", /* scheme */
Curl_http_setup_conn, /* setup_connection */
Curl_http, /* do_it */
Curl_http_done, /* done */
ZERO_NULL, /* do_more */
ZERO_NULL, /* connect_it */
ZERO_NULL, /* connecting */
ZERO_NULL, /* doing */
ZERO_NULL, /* proto_getsock */
ZERO_NULL, /* doing_getsock */
ZERO_NULL, /* domore_getsock */
ZERO_NULL, /* perform_getsock */
ZERO_NULL, /* disconnect */
ZERO_NULL, /* readwrite */
PORT_IMAP, /* defport */
CURLPROTO_HTTP, /* protocol */
PROTOPT_NONE /* flags */
};

#ifdef USE_SSL
/*
* HTTP-proxyed IMAPS protocol handler.
*/

static const struct Curl_handler Curl_handler_imaps_proxy = {
"IMAPS", /* scheme */
Curl_http_setup_conn, /* setup_connection */
Curl_http, /* do_it */
Curl_http_done, /* done */
ZERO_NULL, /* do_more */
ZERO_NULL, /* connect_it */
ZERO_NULL, /* connecting */
ZERO_NULL, /* doing */
ZERO_NULL, /* proto_getsock */
ZERO_NULL, /* doing_getsock */
ZERO_NULL, /* domore_getsock */
ZERO_NULL, /* perform_getsock */
ZERO_NULL, /* disconnect */
ZERO_NULL, /* readwrite */
PORT_IMAPS, /* defport */
CURLPROTO_HTTP, /* protocol */
PROTOPT_NONE /* flags */
};
#endif
#endif

/* SASL parameters for the imap protocol */
static const struct SASLproto saslimap = {
"imap", /* The service name */
Expand Down Expand Up @@ -1716,25 +1664,8 @@ static CURLcode imap_setup_connection(struct connectdata *conn)
/* Clear the TLS upgraded flag */
conn->tls_upgraded = FALSE;

/* Set up the proxy if necessary */
if(conn->bits.httpproxy && !data->set.tunnel_thru_httpproxy) {
/* Unless we have asked to tunnel IMAP operations through the proxy, we
switch and use HTTP operations only */
#ifndef CURL_DISABLE_HTTP
if(conn->handler == &Curl_handler_imap)
conn->handler = &Curl_handler_imap_proxy;
else {
#ifdef USE_SSL
conn->handler = &Curl_handler_imaps_proxy;
#else
failf(data, "IMAPS not supported!");
return CURLE_UNSUPPORTED_PROTOCOL;
#endif
}

/* set it up as an HTTP connection instead */
return conn->handler->setup_connection(conn);
#else
if(conn->bits.httpproxy) {
#ifdef CURL_DISABLE_HTTP
failf(data, "IMAP over http proxy requires HTTP support built-in!");
return CURLE_UNSUPPORTED_PROTOCOL;
#endif
Expand Down
73 changes: 2 additions & 71 deletions lib/pop3.c
Expand Up @@ -158,58 +158,6 @@ const struct Curl_handler Curl_handler_pop3s = {
};
#endif

#ifndef CURL_DISABLE_HTTP
/*
* HTTP-proxyed POP3 protocol handler.
*/

static const struct Curl_handler Curl_handler_pop3_proxy = {
"POP3", /* scheme */
Curl_http_setup_conn, /* setup_connection */
Curl_http, /* do_it */
Curl_http_done, /* done */
ZERO_NULL, /* do_more */
ZERO_NULL, /* connect_it */
ZERO_NULL, /* connecting */
ZERO_NULL, /* doing */
ZERO_NULL, /* proto_getsock */
ZERO_NULL, /* doing_getsock */
ZERO_NULL, /* domore_getsock */
ZERO_NULL, /* perform_getsock */
ZERO_NULL, /* disconnect */
ZERO_NULL, /* readwrite */
PORT_POP3, /* defport */
CURLPROTO_HTTP, /* protocol */
PROTOPT_NONE /* flags */
};

#ifdef USE_SSL
/*
* HTTP-proxyed POP3S protocol handler.
*/

static const struct Curl_handler Curl_handler_pop3s_proxy = {
"POP3S", /* scheme */
Curl_http_setup_conn, /* setup_connection */
Curl_http, /* do_it */
Curl_http_done, /* done */
ZERO_NULL, /* do_more */
ZERO_NULL, /* connect_it */
ZERO_NULL, /* connecting */
ZERO_NULL, /* doing */
ZERO_NULL, /* proto_getsock */
ZERO_NULL, /* doing_getsock */
ZERO_NULL, /* domore_getsock */
ZERO_NULL, /* perform_getsock */
ZERO_NULL, /* disconnect */
ZERO_NULL, /* readwrite */
PORT_POP3S, /* defport */
CURLPROTO_HTTP, /* protocol */
PROTOPT_NONE /* flags */
};
#endif
#endif

/* SASL parameters for the pop3 protocol */
static const struct SASLproto saslpop3 = {
"pop", /* The service name */
Expand Down Expand Up @@ -1356,25 +1304,8 @@ static CURLcode pop3_setup_connection(struct connectdata *conn)
/* Clear the TLS upgraded flag */
conn->tls_upgraded = FALSE;

/* Set up the proxy if necessary */
if(conn->bits.httpproxy && !data->set.tunnel_thru_httpproxy) {
/* Unless we have asked to tunnel POP3 operations through the proxy, we
switch and use HTTP operations only */
#ifndef CURL_DISABLE_HTTP
if(conn->handler == &Curl_handler_pop3)
conn->handler = &Curl_handler_pop3_proxy;
else {
#ifdef USE_SSL
conn->handler = &Curl_handler_pop3s_proxy;
#else
failf(data, "POP3S not supported!");
return CURLE_UNSUPPORTED_PROTOCOL;
#endif
}

/* set it up as an HTTP connection instead */
return conn->handler->setup_connection(conn);
#else
if(conn->bits.httpproxy) {
#ifdef CURL_DISABLE_HTTP
failf(data, "POP3 over http proxy requires HTTP support built-in!");
return CURLE_UNSUPPORTED_PROTOCOL;
#endif
Expand Down
72 changes: 2 additions & 70 deletions lib/smtp.c
Expand Up @@ -157,58 +157,6 @@ const struct Curl_handler Curl_handler_smtps = {
};
#endif

#ifndef CURL_DISABLE_HTTP
/*
* HTTP-proxyed SMTP protocol handler.
*/

static const struct Curl_handler Curl_handler_smtp_proxy = {
"SMTP", /* scheme */
Curl_http_setup_conn, /* setup_connection */
Curl_http, /* do_it */
Curl_http_done, /* done */
ZERO_NULL, /* do_more */
ZERO_NULL, /* connect_it */
ZERO_NULL, /* connecting */
ZERO_NULL, /* doing */
ZERO_NULL, /* proto_getsock */
ZERO_NULL, /* doing_getsock */
ZERO_NULL, /* domore_getsock */
ZERO_NULL, /* perform_getsock */
ZERO_NULL, /* disconnect */
ZERO_NULL, /* readwrite */
PORT_SMTP, /* defport */
CURLPROTO_HTTP, /* protocol */
PROTOPT_NONE /* flags */
};

#ifdef USE_SSL
/*
* HTTP-proxyed SMTPS protocol handler.
*/

static const struct Curl_handler Curl_handler_smtps_proxy = {
"SMTPS", /* scheme */
Curl_http_setup_conn, /* setup_connection */
Curl_http, /* do_it */
Curl_http_done, /* done */
ZERO_NULL, /* do_more */
ZERO_NULL, /* connect_it */
ZERO_NULL, /* connecting */
ZERO_NULL, /* doing */
ZERO_NULL, /* proto_getsock */
ZERO_NULL, /* doing_getsock */
ZERO_NULL, /* domore_getsock */
ZERO_NULL, /* perform_getsock */
ZERO_NULL, /* disconnect */
ZERO_NULL, /* readwrite */
PORT_SMTPS, /* defport */
CURLPROTO_HTTP, /* protocol */
PROTOPT_NONE /* flags */
};
#endif
#endif

/* SASL parameters for the smtp protocol */
static const struct SASLproto saslsmtp = {
"smtp", /* The service name */
Expand Down Expand Up @@ -1452,24 +1400,8 @@ static CURLcode smtp_setup_connection(struct connectdata *conn)
conn->tls_upgraded = FALSE;

/* Set up the proxy if necessary */
if(conn->bits.httpproxy && !data->set.tunnel_thru_httpproxy) {
/* Unless we have asked to tunnel SMTP operations through the proxy, we
switch and use HTTP operations only */
#ifndef CURL_DISABLE_HTTP
if(conn->handler == &Curl_handler_smtp)
conn->handler = &Curl_handler_smtp_proxy;
else {
#ifdef USE_SSL
conn->handler = &Curl_handler_smtps_proxy;
#else
failf(data, "SMTPS not supported!");
return CURLE_UNSUPPORTED_PROTOCOL;
#endif
}
/* set it up as a HTTP connection instead */
return conn->handler->setup_connection(conn);

#else
if(conn->bits.httpproxy) {
#ifdef CURL_DISABLE_HTTP
failf(data, "SMTP over http proxy requires HTTP support built-in!");
return CURLE_UNSUPPORTED_PROTOCOL;
#endif
Expand Down
15 changes: 9 additions & 6 deletions lib/url.c
Expand Up @@ -5317,12 +5317,15 @@ static CURLcode create_conn_helper_init_proxy(struct connectdata *conn)
result = CURLE_UNSUPPORTED_PROTOCOL;
goto out;
#else
/* force this connection's protocol to become HTTP if not already
compatible - if it isn't tunneling through */
if(!(conn->handler->protocol & PROTO_FAMILY_HTTP) &&
!conn->bits.tunnel_proxy)
conn->handler = &Curl_handler_http;

/* force this connection's protocol to become HTTP if compatible */
if(!(conn->handler->protocol & PROTO_FAMILY_HTTP)) {
if((conn->handler->flags & PROTOPT_HTTP_PROXY) &&
!conn->bits.tunnel_proxy)
conn->handler = &Curl_handler_http;
else
/* if not converting to HTTP over the proxy, enforce tunneling */
conn->bits.tunnel_proxy = TRUE;
}
conn->bits.httpproxy = TRUE;
#endif
}
Expand Down
1 change: 1 addition & 0 deletions lib/urldata.h
Expand Up @@ -855,6 +855,7 @@ struct Curl_handler {
#define PROTOPT_STREAM (1<<9) /* a protocol with individual logical streams */
#define PROTOPT_URLOPTIONS (1<<10) /* allow options part in the userinfo field
of the URL */
#define PROTOPT_HTTP_PROXY (1<<11) /* allow over a HTTP proxy */

/* return the count of bytes sent, or -1 on error */
typedef ssize_t (Curl_send)(struct connectdata *conn, /* connection data */
Expand Down

0 comments on commit 7906896

Please sign in to comment.