From: Daniel Stenberg Date: Wed, 9 Mar 2022 09:00:21 +0000 (+0100) Subject: curl: error out when options need features not present in libcurl X-Git-Tag: curl-7_83_0~169 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=95e8515ca0;p=thirdparty%2Fcurl.git curl: error out when options need features not present in libcurl 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 #8565 --- diff --git a/src/tool_operate.c b/src/tool_operate.c index daeb02e6b5..05296c9e75 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -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); @@ -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 : @@ -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 = diff --git a/src/tool_setopt.c b/src/tool_setopt.c index 0b5975abc1..6d763ab944 100644 --- a/src/tool_setopt.c +++ b/src/tool_setopt.c @@ -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; -} diff --git a/src/tool_setopt.h b/src/tool_setopt.h index da44298628..0d02c0c058 100644 --- a/src/tool_setopt.h +++ b/src/tool_setopt.h @@ -7,7 +7,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2021, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2022, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -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 */ diff --git a/tests/data/test1004 b/tests/data/test1004 index cb2b6d69cf..3b75081bd4 100644 --- a/tests/data/test1004 +++ b/tests/data/test1004 @@ -29,6 +29,9 @@ Funny-head: yesyes # # Client-side + +proxy + http diff --git a/tests/data/test1034 b/tests/data/test1034 index 565a1b7285..ec41651a21 100644 --- a/tests/data/test1034 +++ b/tests/data/test1034 @@ -25,6 +25,7 @@ none idn http +proxy LC_ALL= diff --git a/tests/data/test1035 b/tests/data/test1035 index a2b98cc943..73d8aefed5 100644 --- a/tests/data/test1035 +++ b/tests/data/test1035 @@ -23,6 +23,7 @@ none idn http +proxy LC_ALL= diff --git a/tests/data/test1212 b/tests/data/test1212 index 5a93089717..d445f93763 100644 --- a/tests/data/test1212 +++ b/tests/data/test1212 @@ -23,6 +23,9 @@ boo # Client-side + +proxy + http diff --git a/tests/data/test1248 b/tests/data/test1248 index 721c03e738..c289e8c0bd 100644 --- a/tests/data/test1248 +++ b/tests/data/test1248 @@ -22,6 +22,9 @@ foo # Client-side + +proxy + http diff --git a/tests/data/test1249 b/tests/data/test1249 index cae3e995ad..554b173ef2 100644 --- a/tests/data/test1249 +++ b/tests/data/test1249 @@ -22,6 +22,9 @@ foo # Client-side + +proxy + http diff --git a/tests/data/test1252 b/tests/data/test1252 index 13fe3b3d9e..262cf3c9bc 100644 --- a/tests/data/test1252 +++ b/tests/data/test1252 @@ -23,6 +23,9 @@ foo # Client-side + +proxy + http diff --git a/tests/data/test700 b/tests/data/test700 index 23e0037664..e2a0d3320d 100644 --- a/tests/data/test700 +++ b/tests/data/test700 @@ -29,6 +29,9 @@ Funny-head: yesyes # # Client-side + +proxy + http socks4 diff --git a/tests/data/test701 b/tests/data/test701 index db22d668ed..f4cd7f14b3 100644 --- a/tests/data/test701 +++ b/tests/data/test701 @@ -29,6 +29,9 @@ Funny-head: yesyes # # Client-side + +proxy + http socks5 diff --git a/tests/data/test702 b/tests/data/test702 index dd84ffe263..4e06f88890 100644 --- a/tests/data/test702 +++ b/tests/data/test702 @@ -20,6 +20,9 @@ response 91 # Client-side + +proxy + socks4 diff --git a/tests/data/test706 b/tests/data/test706 index b0531e7883..873f129892 100644 --- a/tests/data/test706 +++ b/tests/data/test706 @@ -31,6 +31,9 @@ dr-xr-xr-x 5 0 1 512 Oct 1 1997 usr # # Client-side + +proxy + ftp socks4 diff --git a/tests/data/test707 b/tests/data/test707 index d4c3ab7c67..e589193453 100644 --- a/tests/data/test707 +++ b/tests/data/test707 @@ -31,6 +31,9 @@ dr-xr-xr-x 5 0 1 512 Oct 1 1997 usr # # Client-side + +proxy + ftp socks5 diff --git a/tests/data/test708 b/tests/data/test708 index ff5b91444a..72f4dcec8e 100644 --- a/tests/data/test708 +++ b/tests/data/test708 @@ -29,6 +29,9 @@ Funny-head: yesyes # # Client-side + +proxy + http socks4 diff --git a/tests/data/test709 b/tests/data/test709 index 9d43c7521a..d6380aff2b 100644 --- a/tests/data/test709 +++ b/tests/data/test709 @@ -29,6 +29,9 @@ Funny-head: yesyes # # Client-side + +proxy + http socks5 diff --git a/tests/data/test710 b/tests/data/test710 index 5302022fe1..6400eefb38 100644 --- a/tests/data/test710 +++ b/tests/data/test710 @@ -29,6 +29,9 @@ Funny-head: yesyes # # Client-side + +proxy + http socks5 diff --git a/tests/data/test711 b/tests/data/test711 index a70631a08e..e5f1c39fd6 100644 --- a/tests/data/test711 +++ b/tests/data/test711 @@ -22,6 +22,9 @@ silly content # # Client-side + +proxy + ftp socks5 diff --git a/tests/data/test712 b/tests/data/test712 index 0c6a643383..dbdf1adbec 100644 --- a/tests/data/test712 +++ b/tests/data/test712 @@ -19,6 +19,9 @@ silly content # # Client-side + +proxy + ftp socks5 diff --git a/tests/data/test713 b/tests/data/test713 index 1803f8e9ea..8c94a9cc12 100644 --- a/tests/data/test713 +++ b/tests/data/test713 @@ -20,6 +20,9 @@ silly content # # Client-side + +proxy + ftp socks5 diff --git a/tests/data/test714 b/tests/data/test714 index b405bcd96d..1e042404e2 100644 --- a/tests/data/test714 +++ b/tests/data/test714 @@ -35,6 +35,9 @@ silly content # # Client-side + +proxy + ftp http-proxy diff --git a/tests/data/test715 b/tests/data/test715 index 1bbceb7900..d3d89d514b 100644 --- a/tests/data/test715 +++ b/tests/data/test715 @@ -36,6 +36,9 @@ silly content # # Client-side + +proxy + ftp http-proxy