Skip to content

Commit

Permalink
http: when loading libcurl lazily, allow for multiple SSL backends
Browse files Browse the repository at this point in the history
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 <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Sep 24, 2024
1 parent 7015b7e commit e463c5f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions compat/lazyload-curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,26 @@ static curl_easy_setopt_pointer_type curl_easy_setopt_pointer_func;
typedef CURLcode (*curl_easy_setopt_off_t_type)(CURL *curl, CURLoption opt, curl_off_t value);
static curl_easy_setopt_off_t_type curl_easy_setopt_off_t_func;

static char ssl_backend[64];

static void lazy_load_curl(void)
{
static int initialized;
void *libcurl;
void *libcurl = NULL;
func_t curl_easy_getinfo_func, curl_easy_setopt_func;

if (initialized)
return;

initialized = 1;
libcurl = load_library(LIBCURL_FILE_NAME("libcurl"));
if (ssl_backend[0]) {
char dll_name[64 + 16];
snprintf(dll_name, sizeof(dll_name) - 1,
LIBCURL_FILE_NAME("libcurl-%s"), ssl_backend);
libcurl = load_library(dll_name);
}
if (!libcurl)
libcurl = load_library(LIBCURL_FILE_NAME("libcurl"));
if (!libcurl)
die("failed to load library '%s'", LIBCURL_FILE_NAME("libcurl"));

Expand Down Expand Up @@ -246,6 +255,9 @@ CURLcode curl_global_init(long flags)

CURLsslset curl_global_sslset(curl_sslbackend id, const char *name, const curl_ssl_backend ***avail)
{
if (name && strlen(name) < sizeof(ssl_backend))
strlcpy(ssl_backend, name, sizeof(ssl_backend));

lazy_load_curl();
return curl_global_sslset_func(id, name, avail);
}
Expand Down

0 comments on commit e463c5f

Please sign in to comment.