Skip to content

Commit 44ae0bc

Browse files
committed
fixup! http: add an "auto" mode for http.emptyauth
Note: we keep a "black list" of authentication methods for which we do not want to enable http.emptyAuth automatically. A white list would be nicer, but less robust, as we want to support linking to several cURL versions and the list of authentication methods (as well as their names) changed over time. [jes: actually added the "auto" handling, excluded Digest, too] This fixes #1034 Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 0f93447 commit 44ae0bc

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

http.c

+33-22
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,10 @@ static int http_options(const char *var, const char *value, void *cb)
334334
return git_config_string(&user_agent, var, value);
335335

336336
if (!strcmp("http.emptyauth", var)) {
337-
curl_empty_auth = git_config_bool(var, value);
337+
if (value && !strcmp("auto", value))
338+
curl_empty_auth = -1;
339+
else
340+
curl_empty_auth = git_config_bool(var, value);
338341
return 0;
339342
}
340343

@@ -385,29 +388,37 @@ static int http_options(const char *var, const char *value, void *cb)
385388

386389
static int curl_empty_auth_enabled(void)
387390
{
388-
if (curl_empty_auth < 0) {
389-
#ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
390-
/*
391-
* In the automatic case, kick in the empty-auth
392-
* hack as long as we would potentially try some
393-
* method more exotic than "Basic".
394-
*
395-
* But only do so when this is _not_ our initial
396-
* request, as we would not then yet know what
397-
* methods are available.
398-
*/
399-
return http_auth_methods_restricted &&
400-
http_auth_methods != CURLAUTH_BASIC;
391+
if (curl_empty_auth >= 0)
392+
return curl_empty_auth;
393+
394+
#ifndef LIBCURL_CAN_HANDLE_AUTH_ANY
395+
/*
396+
* Our libcurl is too old to do AUTH_ANY in the first place;
397+
* just default to turning the feature off.
398+
*/
401399
#else
402-
/*
403-
* Our libcurl is too old to do AUTH_ANY in the first place;
404-
* just default to turning the feature off.
405-
*/
406-
return 0;
400+
/*
401+
* In the automatic case, kick in the empty-auth
402+
* hack as long as we would potentially try some
403+
* method more exotic than "Basic".
404+
*
405+
* But only do this when this is our second or
406+
* subsequent * request, as by then we know what
407+
* methods are available.
408+
*/
409+
if (http_auth_methods_restricted)
410+
switch (http_auth_methods) {
411+
case CURLAUTH_BASIC:
412+
case CURLAUTH_DIGEST:
413+
#ifdef CURLAUTH_DIGEST_IE
414+
case CURLAUTH_DIGEST_IE:
407415
#endif
408-
}
409-
410-
return curl_empty_auth;
416+
return 0;
417+
default:
418+
return 1;
419+
}
420+
#endif
421+
return 0;
411422
}
412423

413424
static void init_curl_http_auth(CURL *result)

0 commit comments

Comments
 (0)