summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-01-18 20:08:29 +0100
committerLubomir Rintel <lkundrak@v3.sk>2023-01-26 09:22:43 +0100
commit7122ef4007068309698a7f4a9ce656c0142872e7 (patch)
tree27d668e9f99b71fd26bb0de8ad4b055e2153404e
parent4c42f90e3c5ff435044ec31686858e4ddd03d4e0 (diff)
downloadNetworkManager-7122ef4007068309698a7f4a9ce656c0142872e7.tar.gz
curl: use CURLOPT_PROTOCOLS_STR instead of deprecated CURLOPT_PROTOCOLS
CURLOPT_PROTOCOLS [0] was deprecated in libcurl 7.85.0 with CURLOPT_PROTOCOLS_STR [1] as a replacement. Well, technically it was only deprecated in 7.87.0, and retroactively marked as deprecated since 7.85.0 [2]. But CURLOPT_PROTOCOLS_STR exists since 7.85.0, so that's what we want to use. This causes compiler warnings and build errors: ../src/core/nm-connectivity.c: In function 'do_curl_request': ../src/core/nm-connectivity.c:770:5: error: 'CURLOPT_PROTOCOLS' is deprecated: since 7.85.0. Use CURLOPT_PROTOCOLS_STR [-Werror=deprecated-declarations] 770 | curl_easy_setopt(ehandle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); | ^~~~~~~~~~~~~~~~ In file included from ../src/core/nm-connectivity.c:13: /usr/include/curl/curl.h:1749:3: note: declared here 1749 | CURLOPTDEPRECATED(CURLOPT_PROTOCOLS, CURLOPTTYPE_LONG, 181, | ^~~~~~~~~~~~~~~~~ This patch is largely taken from systemd patch [2]. Based-on-patch-by: Frantisek Sumsal <frantisek@sumsal.cz> [0] https://curl.se/libcurl/c/CURLOPT_PROTOCOLS.html [1] https://curl.se/libcurl/c/CURLOPT_PROTOCOLS_STR.html [2] https://github.com/curl/curl/commit/6967571bf20624bc4cfa68fb8f90cbc53a87c6f2 [3] https://github.com/systemd/systemd/pull/25982/commits/e61a4c0b7c79eabbe4eb50ff2e663734fde769f0 Fixes: 7a1734926a4d ('connectivity,cloud-setup: restrict curl protocols to HTTP and HTTPS') (cherry picked from commit dabfea2fc265e563af85cad62743c1c18738294c)
-rw-r--r--src/core/nm-connectivity.c6
-rw-r--r--src/nm-cloud-setup/nm-http-client.c5
2 files changed, 11 insertions, 0 deletions
diff --git a/src/core/nm-connectivity.c b/src/core/nm-connectivity.c
index cd30853d3d..c0e77e3559 100644
--- a/src/core/nm-connectivity.c
+++ b/src/core/nm-connectivity.c
@@ -767,7 +767,13 @@ do_curl_request(NMConnectivityCheckHandle *cb_data, const char *hosts)
curl_easy_setopt(ehandle, CURLOPT_INTERFACE, cb_data->ifspec);
curl_easy_setopt(ehandle, CURLOPT_RESOLVE, cb_data->concheck.hosts);
curl_easy_setopt(ehandle, CURLOPT_IPRESOLVE, resolve);
+
+#if LIBCURL_VERSION_NUM >= 0x075500 /* libcurl 7.85.0 */
+ curl_easy_setopt(ehandle, CURLOPT_PROTOCOLS_STR, "HTTP,HTTPS");
+#else
curl_easy_setopt(ehandle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
+#endif
+
if (_LOGT_ENABLED() && easy_debug_enabled()) {
curl_easy_setopt(ehandle, CURLOPT_DEBUGFUNCTION, easy_debug_cb);
curl_easy_setopt(ehandle, CURLOPT_DEBUGDATA, cb_data);
diff --git a/src/nm-cloud-setup/nm-http-client.c b/src/nm-cloud-setup/nm-http-client.c
index a0053d472d..a0964e2165 100644
--- a/src/nm-cloud-setup/nm-http-client.c
+++ b/src/nm-cloud-setup/nm-http-client.c
@@ -305,7 +305,12 @@ nm_http_client_get(NMHttpClient *self,
curl_easy_setopt(edata->ehandle, CURLOPT_WRITEFUNCTION, _get_writefunction_cb);
curl_easy_setopt(edata->ehandle, CURLOPT_WRITEDATA, edata);
curl_easy_setopt(edata->ehandle, CURLOPT_PRIVATE, edata);
+
+#if LIBCURL_VERSION_NUM >= 0x075500 /* libcurl 7.85.0 */
+ curl_easy_setopt(edata->ehandle, CURLOPT_PROTOCOLS_STR, "HTTP,HTTPS");
+#else
curl_easy_setopt(edata->ehandle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
+#endif
if (http_headers) {
for (i = 0; http_headers[i]; ++i) {