]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl: error out when options need features not present in libcurl
authorDaniel Stenberg <daniel@haxx.se>
Wed, 9 Mar 2022 09:00:21 +0000 (10:00 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 10 Mar 2022 07:30:45 +0000 (08:30 +0100)
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

23 files changed:
src/tool_operate.c
src/tool_setopt.c
src/tool_setopt.h
tests/data/test1004
tests/data/test1034
tests/data/test1035
tests/data/test1212
tests/data/test1248
tests/data/test1249
tests/data/test1252
tests/data/test700
tests/data/test701
tests/data/test702
tests/data/test706
tests/data/test707
tests/data/test708
tests/data/test709
tests/data/test710
tests/data/test711
tests/data/test712
tests/data/test713
tests/data/test714
tests/data/test715

index daeb02e6b5ef552cb3bde52bb9938f62651882fa..05296c9e75517745b96f5b908f3453c8d290743b 100644 (file)
@@ -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 =
index 0b5975abc13d83b313d975d979d0afb3e5ddc687..6d763ab9443ffb5a44884a2b9ae449606f4cc3b6 100644 (file)
@@ -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;
-}
index da442986284e38d612ede1e981e4239f4dc828f1..0d02c0c058618035ea8de5d0b2788f6ddf390aa1 100644 (file)
@@ -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
  * 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 */
index cb2b6d69cfc18ec9d79298a712abe35191c6c262..3b75081bd4d1163c08b3f7155418adcd47904c4f 100644 (file)
@@ -29,6 +29,9 @@ Funny-head: yesyes
 #
 # Client-side
 <client>
+<features>
+proxy
+</features>
 <server>
 http
 </server>
index 565a1b7285b8158d18bc82c1b542b6da5fe03607..ec41651a217c0fe7ec08b7788509184efeeaa109 100644 (file)
@@ -25,6 +25,7 @@ none
 <features>
 idn
 http
+proxy
 </features>
 <setenv>
 LC_ALL=
index a2b98cc943c200fe9ed358ba9ad917775865d297..73d8aefed5c57c7ba92322e5d21fe6c2247f2827 100644 (file)
@@ -23,6 +23,7 @@ none
 <features>
 idn
 http
+proxy
 </features>
 <setenv>
 LC_ALL=
index 5a93089717e76178102654ef4f31106c08a0a9cd..d445f937639f2cb7b11fb5c23a5bbf3c0797f497 100644 (file)
@@ -23,6 +23,9 @@ boo
 
 # Client-side
 <client>
+<features>
+proxy
+</features>
 <server>
 http
 </server>
index 721c03e738036e2b188ff339ca5338c659716647..c289e8c0bd71389de660eb7829f9247f6eb85a5e 100644 (file)
@@ -22,6 +22,9 @@ foo
 
 # Client-side
 <client>
+<features>
+proxy
+</features>
 <server>
 http
 </server>
index cae3e995adba56a553b3c086813bddcb5a9d7c1f..554b173ef282736e97a666c272a0ba3c92d18be3 100644 (file)
@@ -22,6 +22,9 @@ foo
 
 # Client-side
 <client>
+<features>
+proxy
+</features>
 <server>
 http
 </server>
index 13fe3b3d9ed4fcd72974e166606ddf3e4f2fec0a..262cf3c9bcc41283a3aa08a6155c0fca6747cdcf 100644 (file)
@@ -23,6 +23,9 @@ foo
 
 # Client-side
 <client>
+<features>
+proxy
+</features>
 <server>
 http
 </server>
index 23e00376647a4e9ea26481afaf5288ef5f8f7b37..e2a0d3320d7a4a0e038c738d3ca17ad4432f39b6 100644 (file)
@@ -29,6 +29,9 @@ Funny-head: yesyes
 #
 # Client-side
 <client>
+<features>
+proxy
+</features>
 <server>
 http
 socks4
index db22d668ed57518c13c2bf70e16778d306b90c2a..f4cd7f14b3494a251805ea302cb41e2da4f64ec7 100644 (file)
@@ -29,6 +29,9 @@ Funny-head: yesyes
 #
 # Client-side
 <client>
+<features>
+proxy
+</features>
 <server>
 http
 socks5
index dd84ffe26339c5475844a6af7fb21a2ac263c4c8..4e06f88890c42350cfc664590c69f0da0f4ef8bb 100644 (file)
@@ -20,6 +20,9 @@ response 91
 
 # Client-side
 <client>
+<features>
+proxy
+</features>
 <server>
 socks4
 </server>
index b0531e78830aa3ee384d58f83bd0c182d6451295..873f129892b1653e29f2b93e10b9231f438e0b0d 100644 (file)
@@ -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
index d4c3ab7c676edb743b829ec00ec2f46b1bd2caaa..e58919345345e2488115fbdc6271b4cc8d5d2822 100644 (file)
@@ -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
index ff5b91444a52c9ad75cfded6e1360431331d12f3..72f4dcec8e8ff27fccdcdbdb788629e20627a1c0 100644 (file)
@@ -29,6 +29,9 @@ Funny-head: yesyes
 #
 # Client-side
 <client>
+<features>
+proxy
+</features>
 <server>
 http
 socks4
index 9d43c7521a4f943d50630ab6c71029eea476bf79..d6380aff2b36bb9856fdd5ac00a68f230360c649 100644 (file)
@@ -29,6 +29,9 @@ Funny-head: yesyes
 #
 # Client-side
 <client>
+<features>
+proxy
+</features>
 <server>
 http
 socks5
index 5302022fe1d15b0ec157a22202899484717acc35..6400eefb3859f53654547d461ba22103b4212b8e 100644 (file)
@@ -29,6 +29,9 @@ Funny-head: yesyes
 #
 # Client-side
 <client>
+<features>
+proxy
+</features>
 <server>
 http
 socks5
index a70631a08e5ba5849e5a76a899f2a88485a1419b..e5f1c39fd6fe9b4b889849c1286405e48c5e1ced 100644 (file)
@@ -22,6 +22,9 @@ silly content
 #
 # Client-side
 <client>
+<features>
+proxy
+</features>
 <server>
 ftp
 socks5
index 0c6a643383a8266d6f5487b83a1d10938a48ba36..dbdf1adbec83eba7d8a12313150675e90772499b 100644 (file)
@@ -19,6 +19,9 @@ silly content
 #
 # Client-side
 <client>
+<features>
+proxy
+</features>
 <server>
 ftp
 socks5
index 1803f8e9ea8a54ffbfd9bdb4a50747b41cf5f469..8c94a9cc12adb2f093ad8073ea0d378ca50f3f49 100644 (file)
@@ -20,6 +20,9 @@ silly content
 #
 # Client-side
 <client>
+<features>
+proxy
+</features>
 <server>
 ftp
 socks5
index b405bcd96d2761b13f73472dbc5feb2a22bfe5da..1e042404e2856bb3370099211f26fde7998cf4c4 100644 (file)
@@ -35,6 +35,9 @@ silly content
 #
 # Client-side
 <client>
+<features>
+proxy
+</features>
 <server>
 ftp
 http-proxy
index 1bbceb7900de03fd92468c7af98e7a38b3a1077b..d3d89d514b7a5f9168377c685573b8f531a07d7d 100644 (file)
@@ -36,6 +36,9 @@ silly content
 #
 # Client-side
 <client>
+<features>
+proxy
+</features>
 <server>
 ftp
 http-proxy