@@ -131,7 +131,8 @@ enum http_follow_config http_follow_config = HTTP_FOLLOW_INITIAL;
131131
132132static struct credential cert_auth = CREDENTIAL_INIT ;
133133static int ssl_cert_password_required ;
134- static unsigned long http_auth_methods = CURLAUTH_ANY ;
134+ static unsigned long http_auth_any = CURLAUTH_ANY & ~CURLAUTH_NTLM ;
135+ static unsigned long http_auth_methods ;
135136static int http_auth_methods_restricted ;
136137/* Modes for which empty_auth cannot actually help us. */
137138static unsigned long empty_auth_useless =
@@ -437,6 +438,15 @@ static int http_options(const char *var, const char *value,
437438 return 0 ;
438439 }
439440
441+ if (!strcmp ("http.allowntlmauth" , var )) {
442+ if (git_config_bool (var , value )) {
443+ http_auth_any |= CURLAUTH_NTLM ;
444+ } else {
445+ http_auth_any &= ~CURLAUTH_NTLM ;
446+ }
447+ return 0 ;
448+ }
449+
440450 if (!strcmp ("http.schannelcheckrevoke" , var )) {
441451 if (value && !strcmp (value , "best-effort" )) {
442452 http_schannel_check_revoke_mode =
@@ -675,6 +685,11 @@ static void init_curl_http_auth(CURL *result)
675685
676686 credential_fill (the_repository , & http_auth , 1 );
677687
688+ if (http_auth .ntlm_allow && !(http_auth_methods & CURLAUTH_NTLM )) {
689+ http_auth_methods |= CURLAUTH_NTLM ;
690+ curl_easy_setopt (result , CURLOPT_HTTPAUTH , http_auth_methods );
691+ }
692+
678693 if (http_auth .password ) {
679694 if (always_auth_proactively ()) {
680695 /*
@@ -750,11 +765,11 @@ static void init_curl_proxy_auth(CURL *result)
750765 if (i == ARRAY_SIZE (proxy_authmethods )) {
751766 warning ("unsupported proxy authentication method %s: using anyauth" ,
752767 http_proxy_authmethod );
753- curl_easy_setopt (result , CURLOPT_PROXYAUTH , CURLAUTH_ANY );
768+ curl_easy_setopt (result , CURLOPT_PROXYAUTH , http_auth_any );
754769 }
755770 }
756771 else
757- curl_easy_setopt (result , CURLOPT_PROXYAUTH , CURLAUTH_ANY );
772+ curl_easy_setopt (result , CURLOPT_PROXYAUTH , http_auth_any );
758773}
759774
760775static int has_cert_password (void )
@@ -1101,7 +1116,7 @@ static CURL *get_curl_handle(void)
11011116 }
11021117
11031118 curl_easy_setopt (result , CURLOPT_NETRC , CURL_NETRC_OPTIONAL );
1104- curl_easy_setopt (result , CURLOPT_HTTPAUTH , CURLAUTH_ANY );
1119+ curl_easy_setopt (result , CURLOPT_HTTPAUTH , http_auth_any );
11051120
11061121#ifdef CURLGSSAPI_DELEGATION_FLAG
11071122 if (curl_deleg ) {
@@ -1500,6 +1515,8 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)
15001515 set_long_from_env (& http_max_retries , "GIT_HTTP_MAX_RETRIES" );
15011516 set_long_from_env (& http_max_retry_time , "GIT_HTTP_MAX_RETRY_TIME" );
15021517
1518+ http_auth_methods = http_auth_any ;
1519+
15031520 curl_default = get_curl_handle ();
15041521}
15051522
@@ -1931,6 +1948,8 @@ static int handle_curl_result(struct slot_results *results)
19311948 } else if (missing_target (results ))
19321949 return HTTP_MISSING_TARGET ;
19331950 else if (results -> http_code == 401 ) {
1951+ http_auth .ntlm_suppressed = (results -> auth_avail & CURLAUTH_NTLM ) &&
1952+ !(http_auth_any & CURLAUTH_NTLM );
19341953 if ((http_auth .username && http_auth .password ) || \
19351954 (http_auth .authtype && http_auth .credential )) {
19361955 if (http_auth .multistage ) {
@@ -1940,6 +1959,16 @@ static int handle_curl_result(struct slot_results *results)
19401959 credential_reject (the_repository , & http_auth );
19411960 if (always_auth_proactively ())
19421961 http_proactive_auth = PROACTIVE_AUTH_NONE ;
1962+ if (http_auth .ntlm_suppressed ) {
1963+ warning (_ ("Due to its cryptographic weaknesses, "
1964+ "NTLM authentication has been\n"
1965+ "disabled in Git by default. You can "
1966+ "re-enable it for trusted servers\n"
1967+ "by running:\n\n"
1968+ "git config set "
1969+ "http.%s://%s.allowNTLMAuth true" ),
1970+ http_auth .protocol , http_auth .host );
1971+ }
19431972 return HTTP_NOAUTH ;
19441973 } else {
19451974 if (curl_empty_auth == -1 &&
@@ -2464,6 +2493,13 @@ static int http_request_recoverable(const char *url,
24642493 http_reauth_prepare (1 );
24652494 }
24662495
2496+ /*
2497+ * Re-enable NTLM auth if the helper allows it and we would
2498+ * otherwise suppress authentication via NTLM.
2499+ */
2500+ if (http_auth .ntlm_suppressed && http_auth .ntlm_allow )
2501+ http_auth_methods |= CURLAUTH_NTLM ;
2502+
24672503 ret = http_request (url , result , target , options );
24682504 }
24692505 if (ret == HTTP_RATE_LIMITED ) {
0 commit comments