Skip to content

Commit

Permalink
curl: error out when options need features not present in libcurl
Browse files Browse the repository at this point in the history
Trying to use a proxy when libcurl was built with proxy support disabled
should make curl error out properly.

Remove knowledge of disabled features from the tool code and instead
make it properly respond to what libcurl returns. Update all tests to
properly require the necessary features to be present/absent so that the
test suite can still be run even with libcurl builds with disabled
features.

Ref: https://curl.se/mail/archive-2022-03/0013.html
Closes curl#8565
  • Loading branch information
bagder committed Mar 10, 2022
1 parent 96edc79 commit 95e8515
Show file tree
Hide file tree
Showing 23 changed files with 106 additions and 171 deletions.
88 changes: 47 additions & 41 deletions src/tool_operate.c
Expand Up @@ -1259,45 +1259,51 @@ static CURLcode single_transfer(struct GlobalConfig *global,
if(config->oauth_bearer)
my_setopt_str(curl, CURLOPT_XOAUTH2_BEARER, config->oauth_bearer);

{
my_setopt_str(curl, CURLOPT_PROXY, config->proxy);
/* new in libcurl 7.5 */
if(config->proxy)
my_setopt_enum(curl, CURLOPT_PROXYTYPE, config->proxyver);

my_setopt_str(curl, CURLOPT_PROXYUSERPWD, config->proxyuserpwd);

/* new in libcurl 7.3 */
my_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, config->proxytunnel?1L:0L);

/* new in libcurl 7.52.0 */
if(config->preproxy)
my_setopt_str(curl, CURLOPT_PRE_PROXY, config->preproxy);

/* new in libcurl 7.10.6 */
if(config->proxyanyauth)
my_setopt_bitmask(curl, CURLOPT_PROXYAUTH,
(long)CURLAUTH_ANY);
else if(config->proxynegotiate)
my_setopt_bitmask(curl, CURLOPT_PROXYAUTH,
(long)CURLAUTH_GSSNEGOTIATE);
else if(config->proxyntlm)
my_setopt_bitmask(curl, CURLOPT_PROXYAUTH,
(long)CURLAUTH_NTLM);
else if(config->proxydigest)
my_setopt_bitmask(curl, CURLOPT_PROXYAUTH,
(long)CURLAUTH_DIGEST);
else if(config->proxybasic)
my_setopt_bitmask(curl, CURLOPT_PROXYAUTH,
(long)CURLAUTH_BASIC);

/* new in libcurl 7.19.4 */
my_setopt_str(curl, CURLOPT_NOPROXY, config->noproxy);

my_setopt(curl, CURLOPT_SUPPRESS_CONNECT_HEADERS,
config->suppress_connect_headers?1L:0L);
my_setopt_str(curl, CURLOPT_PROXY, config->proxy);

if(config->proxy && result) {
errorf(global, "proxy support is disabled in this libcurl\n");
config->synthetic_error = TRUE;
result = CURLE_NOT_BUILT_IN;
break;
}

/* new in libcurl 7.5 */
if(config->proxy)
my_setopt_enum(curl, CURLOPT_PROXYTYPE, config->proxyver);

my_setopt_str(curl, CURLOPT_PROXYUSERPWD, config->proxyuserpwd);

/* new in libcurl 7.3 */
my_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, config->proxytunnel?1L:0L);

/* new in libcurl 7.52.0 */
if(config->preproxy)
my_setopt_str(curl, CURLOPT_PRE_PROXY, config->preproxy);

/* new in libcurl 7.10.6 */
if(config->proxyanyauth)
my_setopt_bitmask(curl, CURLOPT_PROXYAUTH,
(long)CURLAUTH_ANY);
else if(config->proxynegotiate)
my_setopt_bitmask(curl, CURLOPT_PROXYAUTH,
(long)CURLAUTH_GSSNEGOTIATE);
else if(config->proxyntlm)
my_setopt_bitmask(curl, CURLOPT_PROXYAUTH,
(long)CURLAUTH_NTLM);
else if(config->proxydigest)
my_setopt_bitmask(curl, CURLOPT_PROXYAUTH,
(long)CURLAUTH_DIGEST);
else if(config->proxybasic)
my_setopt_bitmask(curl, CURLOPT_PROXYAUTH,
(long)CURLAUTH_BASIC);

/* new in libcurl 7.19.4 */
my_setopt_str(curl, CURLOPT_NOPROXY, config->noproxy);

my_setopt(curl, CURLOPT_SUPPRESS_CONNECT_HEADERS,
config->suppress_connect_headers?1L:0L);

my_setopt(curl, CURLOPT_FAILONERROR, config->failonerror?1L:0L);
my_setopt(curl, CURLOPT_REQUEST_TARGET, config->request_target);
my_setopt(curl, CURLOPT_UPLOAD, per->uploadfile?1L:0L);
Expand Down Expand Up @@ -1469,8 +1475,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
}
/* For the time being if --proxy-capath is not set then we use the
--capath value for it, if any. See #1257 */
if((config->proxy_capath || config->capath) &&
!tool_setopt_skip(CURLOPT_PROXY_CAPATH)) {
if(config->proxy_capath || config->capath) {
result = res_setopt_str(curl, CURLOPT_PROXY_CAPATH,
(config->proxy_capath ?
config->proxy_capath :
Expand Down Expand Up @@ -1665,8 +1670,9 @@ static CURLcode single_transfer(struct GlobalConfig *global,

my_setopt_enum(curl, CURLOPT_SSLVERSION,
config->ssl_version | config->ssl_version_max);
my_setopt_enum(curl, CURLOPT_PROXY_SSLVERSION,
config->proxy_ssl_version);
if(config->proxy)
my_setopt_enum(curl, CURLOPT_PROXY_SSLVERSION,
config->proxy_ssl_version);

{
long mask =
Expand Down
120 changes: 0 additions & 120 deletions src/tool_setopt.c
Expand Up @@ -739,123 +739,3 @@ CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *global,
#include "tool_setopt.h"

#endif /* CURL_DISABLE_LIBCURL_OPTION */

/*
* tool_setopt_skip() allows the curl tool code to avoid setopt options that
* are explicitly disabled in the build.
*/
bool tool_setopt_skip(CURLoption tag)
{
#ifdef CURL_DISABLE_PROXY
#define USED_TAG
switch(tag) {
case CURLOPT_HAPROXYPROTOCOL:
case CURLOPT_HTTPPROXYTUNNEL:
case CURLOPT_NOPROXY:
case CURLOPT_PRE_PROXY:
case CURLOPT_PROXY:
case CURLOPT_PROXYAUTH:
case CURLOPT_PROXY_CAINFO:
case CURLOPT_PROXY_CAPATH:
case CURLOPT_PROXY_CRLFILE:
case CURLOPT_PROXYHEADER:
case CURLOPT_PROXY_KEYPASSWD:
case CURLOPT_PROXYPASSWORD:
case CURLOPT_PROXY_PINNEDPUBLICKEY:
case CURLOPT_PROXYPORT:
case CURLOPT_PROXY_SERVICE_NAME:
case CURLOPT_PROXY_SSLCERT:
case CURLOPT_PROXY_SSLCERTTYPE:
case CURLOPT_PROXY_SSL_CIPHER_LIST:
case CURLOPT_PROXY_SSLKEY:
case CURLOPT_PROXY_SSLKEYTYPE:
case CURLOPT_PROXY_SSL_OPTIONS:
case CURLOPT_PROXY_SSL_VERIFYHOST:
case CURLOPT_PROXY_SSL_VERIFYPEER:
case CURLOPT_PROXY_SSLVERSION:
case CURLOPT_PROXY_TLS13_CIPHERS:
case CURLOPT_PROXY_TLSAUTH_PASSWORD:
case CURLOPT_PROXY_TLSAUTH_TYPE:
case CURLOPT_PROXY_TLSAUTH_USERNAME:
case CURLOPT_PROXY_TRANSFER_MODE:
case CURLOPT_PROXYTYPE:
case CURLOPT_PROXYUSERNAME:
case CURLOPT_PROXYUSERPWD:
return TRUE;
default:
break;
}
#endif
#ifdef CURL_DISABLE_FTP
#define USED_TAG
switch(tag) {
case CURLOPT_FTPPORT:
case CURLOPT_FTP_ACCOUNT:
case CURLOPT_FTP_ALTERNATIVE_TO_USER:
case CURLOPT_FTP_FILEMETHOD:
case CURLOPT_FTP_SKIP_PASV_IP:
case CURLOPT_FTP_USE_EPRT:
case CURLOPT_FTP_USE_EPSV:
case CURLOPT_FTP_USE_PRET:
case CURLOPT_KRBLEVEL:
return TRUE;
default:
break;
}
#endif
#ifdef CURL_DISABLE_RTSP
#define USED_TAG
switch(tag) {
case CURLOPT_INTERLEAVEDATA:
return TRUE;
default:
break;
}
#endif
#if defined(CURL_DISABLE_HTTP) || defined(CURL_DISABLE_COOKIES)
#define USED_TAG
switch(tag) {
case CURLOPT_COOKIE:
case CURLOPT_COOKIEFILE:
case CURLOPT_COOKIEJAR:
case CURLOPT_COOKIESESSION:
return TRUE;
default:
break;
}
#endif
#if defined(CURL_DISABLE_TELNET)
#define USED_TAG
switch(tag) {
case CURLOPT_TELNETOPTIONS:
return TRUE;
default:
break;
}
#endif
#ifdef CURL_DISABLE_TFTP
#define USED_TAG
switch(tag) {
case CURLOPT_TFTP_BLKSIZE:
case CURLOPT_TFTP_NO_OPTIONS:
return TRUE;
default:
break;
}
#endif
#ifdef CURL_DISABLE_NETRC
#define USED_TAG
switch(tag) {
case CURLOPT_NETRC:
case CURLOPT_NETRC_FILE:
return TRUE;
default:
break;
}
#endif

#ifndef USED_TAG
(void)tag;
#endif
return FALSE;
}
13 changes: 3 additions & 10 deletions src/tool_setopt.h
Expand Up @@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
Expand All @@ -29,17 +29,10 @@
* Macros used in operate()
*/

#define SETOPT_CHECK(v,opt) do { \
if(!tool_setopt_skip(opt)) { \
result = (v); \
if(result) \
break; \
} \
#define SETOPT_CHECK(v,opt) do { \
result = (v); \
} while(0)

/* allow removed features to simulate success: */
bool tool_setopt_skip(CURLoption tag);

#ifndef CURL_DISABLE_LIBCURL_OPTION

/* Associate symbolic names with option values */
Expand Down
3 changes: 3 additions & 0 deletions tests/data/test1004
Expand Up @@ -29,6 +29,9 @@ Funny-head: yesyes
#
# Client-side
<client>
<features>
proxy
</features>
<server>
http
</server>
Expand Down
1 change: 1 addition & 0 deletions tests/data/test1034
Expand Up @@ -25,6 +25,7 @@ none
<features>
idn
http
proxy
</features>
<setenv>
LC_ALL=
Expand Down
1 change: 1 addition & 0 deletions tests/data/test1035
Expand Up @@ -23,6 +23,7 @@ none
<features>
idn
http
proxy
</features>
<setenv>
LC_ALL=
Expand Down
3 changes: 3 additions & 0 deletions tests/data/test1212
Expand Up @@ -23,6 +23,9 @@ boo

# Client-side
<client>
<features>
proxy
</features>
<server>
http
</server>
Expand Down
3 changes: 3 additions & 0 deletions tests/data/test1248
Expand Up @@ -22,6 +22,9 @@ foo

# Client-side
<client>
<features>
proxy
</features>
<server>
http
</server>
Expand Down
3 changes: 3 additions & 0 deletions tests/data/test1249
Expand Up @@ -22,6 +22,9 @@ foo

# Client-side
<client>
<features>
proxy
</features>
<server>
http
</server>
Expand Down
3 changes: 3 additions & 0 deletions tests/data/test1252
Expand Up @@ -23,6 +23,9 @@ foo

# Client-side
<client>
<features>
proxy
</features>
<server>
http
</server>
Expand Down
3 changes: 3 additions & 0 deletions tests/data/test700
Expand Up @@ -29,6 +29,9 @@ Funny-head: yesyes
#
# Client-side
<client>
<features>
proxy
</features>
<server>
http
socks4
Expand Down
3 changes: 3 additions & 0 deletions tests/data/test701
Expand Up @@ -29,6 +29,9 @@ Funny-head: yesyes
#
# Client-side
<client>
<features>
proxy
</features>
<server>
http
socks5
Expand Down
3 changes: 3 additions & 0 deletions tests/data/test702
Expand Up @@ -20,6 +20,9 @@ response 91

# Client-side
<client>
<features>
proxy
</features>
<server>
socks4
</server>
Expand Down
3 changes: 3 additions & 0 deletions tests/data/test706
Expand Up @@ -31,6 +31,9 @@ dr-xr-xr-x 5 0 1 512 Oct 1 1997 usr
#
# Client-side
<client>
<features>
proxy
</features>
<server>
ftp
socks4
Expand Down
3 changes: 3 additions & 0 deletions tests/data/test707
Expand Up @@ -31,6 +31,9 @@ dr-xr-xr-x 5 0 1 512 Oct 1 1997 usr
#
# Client-side
<client>
<features>
proxy
</features>
<server>
ftp
socks5
Expand Down
3 changes: 3 additions & 0 deletions tests/data/test708
Expand Up @@ -29,6 +29,9 @@ Funny-head: yesyes
#
# Client-side
<client>
<features>
proxy
</features>
<server>
http
socks4
Expand Down
3 changes: 3 additions & 0 deletions tests/data/test709
Expand Up @@ -29,6 +29,9 @@ Funny-head: yesyes
#
# Client-side
<client>
<features>
proxy
</features>
<server>
http
socks5
Expand Down

0 comments on commit 95e8515

Please sign in to comment.