Skip to content

Commit 82baabb

Browse files
committed
http: when loading libcurl lazily, allow for multiple SSL backends
The previous commits introduced a compile-time option to load libcurl lazily, but it uses the hard-coded name "libcurl-4.dll" (or equivalent on platforms other than Windows). To allow for installing multiple libcurl flavors side by side, where each supports one specific SSL/TLS backend, let's first look whether `libcurl-<backend>-4.dll` exists, and only use `libcurl-4.dll` as a fall back. That will allow us to ship with a libcurl by default that only supports the Secure Channel backend for the `https://` protocol. This libcurl won't suffer from any dependency problem when upgrading OpenSSL to a new major version (which will change the DLL name, and hence break every program and library that depends on it). This is crucial because Git for Windows relies on libcurl to keep working when building and deploying a new OpenSSL package because that library is used by `git fetch` and `git clone`. Note that this feature is by no means specific to Windows. On Ubuntu, for example, a `git` built using `LAZY_LOAD_LIBCURL` will use `libcurl.so.4` for `http.sslbackend=openssl` and `libcurl-gnutls.so.4` for `http.sslbackend=gnutls`. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent f1e3572 commit 82baabb

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

compat/lazy-load-curl.c

+14-2
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,26 @@ static curl_easy_setopt_pointer_type curl_easy_setopt_pointer_func;
146146
typedef CURLcode (*curl_easy_setopt_off_t_type)(CURL *curl, CURLoption opt, curl_off_t value);
147147
static curl_easy_setopt_off_t_type curl_easy_setopt_off_t_func;
148148

149+
static char ssl_backend[64];
150+
149151
static void lazy_load_curl(void)
150152
{
151153
static int initialized;
152-
void *libcurl;
154+
void *libcurl = NULL;
153155
func_t curl_easy_getinfo_func, curl_easy_setopt_func;
154156

155157
if (initialized)
156158
return;
157159

158160
initialized = 1;
159-
libcurl = load_library(LIBCURL_FILE_NAME("libcurl"));
161+
if (ssl_backend[0]) {
162+
char dll_name[64 + 16];
163+
snprintf(dll_name, sizeof(dll_name) - 1,
164+
LIBCURL_FILE_NAME("libcurl-%s"), ssl_backend);
165+
libcurl = load_library(dll_name);
166+
}
167+
if (!libcurl)
168+
libcurl = load_library(LIBCURL_FILE_NAME("libcurl"));
160169
if (!libcurl)
161170
die("failed to load library '%s'", LIBCURL_FILE_NAME("libcurl"));
162171

@@ -213,6 +222,9 @@ CURLcode curl_global_init(long flags)
213222

214223
CURLsslset curl_global_sslset(curl_sslbackend id, const char *name, const curl_ssl_backend ***avail)
215224
{
225+
if (name && strlen(name) < sizeof(ssl_backend))
226+
strlcpy(ssl_backend, name, sizeof(ssl_backend));
227+
216228
lazy_load_curl();
217229
return curl_global_sslset_func(id, name, avail);
218230
}

0 commit comments

Comments
 (0)