@@ -128,7 +128,8 @@ enum http_follow_config http_follow_config = HTTP_FOLLOW_INITIAL;
128128
129129static struct credential cert_auth = CREDENTIAL_INIT ;
130130static int ssl_cert_password_required ;
131- static unsigned long http_auth_methods = CURLAUTH_ANY ;
131+ static unsigned long http_auth_any = CURLAUTH_ANY & ~CURLAUTH_NTLM ;
132+ static unsigned long http_auth_methods ;
132133static int http_auth_methods_restricted ;
133134/* Modes for which empty_auth cannot actually help us. */
134135static unsigned long empty_auth_useless =
@@ -429,6 +430,15 @@ static int http_options(const char *var, const char *value,
429430 return 0 ;
430431 }
431432
433+ if (!strcmp ("http.allowntlmauth" , var )) {
434+ if (git_config_bool (var , value )) {
435+ http_auth_any |= CURLAUTH_NTLM ;
436+ } else {
437+ http_auth_any &= ~CURLAUTH_NTLM ;
438+ }
439+ return 0 ;
440+ }
441+
432442 if (!strcmp ("http.schannelcheckrevoke" , var )) {
433443 if (value && !strcmp (value , "best-effort" )) {
434444 http_schannel_check_revoke_mode =
@@ -645,6 +655,11 @@ static void init_curl_http_auth(CURL *result)
645655
646656 credential_fill (& http_auth , 1 );
647657
658+ if (http_auth .ntlm_allow && !(http_auth_methods & CURLAUTH_NTLM )) {
659+ http_auth_methods |= CURLAUTH_NTLM ;
660+ curl_easy_setopt (result , CURLOPT_HTTPAUTH , http_auth_methods );
661+ }
662+
648663 if (http_auth .password ) {
649664 if (always_auth_proactively ()) {
650665 /*
@@ -704,11 +719,11 @@ static void init_curl_proxy_auth(CURL *result)
704719 if (i == ARRAY_SIZE (proxy_authmethods )) {
705720 warning ("unsupported proxy authentication method %s: using anyauth" ,
706721 http_proxy_authmethod );
707- curl_easy_setopt (result , CURLOPT_PROXYAUTH , CURLAUTH_ANY );
722+ curl_easy_setopt (result , CURLOPT_PROXYAUTH , http_auth_any );
708723 }
709724 }
710725 else
711- curl_easy_setopt (result , CURLOPT_PROXYAUTH , CURLAUTH_ANY );
726+ curl_easy_setopt (result , CURLOPT_PROXYAUTH , http_auth_any );
712727}
713728
714729static int has_cert_password (void )
@@ -1091,7 +1106,7 @@ static CURL *get_curl_handle(void)
10911106#endif
10921107
10931108 curl_easy_setopt (result , CURLOPT_NETRC , CURL_NETRC_OPTIONAL );
1094- curl_easy_setopt (result , CURLOPT_HTTPAUTH , CURLAUTH_ANY );
1109+ curl_easy_setopt (result , CURLOPT_HTTPAUTH , http_auth_any );
10951110
10961111#ifdef CURLGSSAPI_DELEGATION_FLAG
10971112 if (curl_deleg ) {
@@ -1461,6 +1476,8 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)
14611476 ssl_cert_password_required = 1 ;
14621477 }
14631478
1479+ http_auth_methods = http_auth_any ;
1480+
14641481 curl_default = get_curl_handle ();
14651482}
14661483
@@ -1894,6 +1911,12 @@ static int handle_curl_result(struct slot_results *results)
18941911 } else if (missing_target (results ))
18951912 return HTTP_MISSING_TARGET ;
18961913 else if (results -> http_code == 401 ) {
1914+ http_auth .ntlm_suppressed = (results -> auth_avail & CURLAUTH_NTLM ) &&
1915+ !(http_auth_any & CURLAUTH_NTLM );
1916+ if (http_auth .ntlm_suppressed && http_auth .ntlm_allow ) {
1917+ http_auth_methods |= CURLAUTH_NTLM ;
1918+ return HTTP_REAUTH ;
1919+ }
18971920 if ((http_auth .username && http_auth .password ) || \
18981921 (http_auth .authtype && http_auth .credential )) {
18991922 if (http_auth .multistage ) {
@@ -1903,6 +1926,16 @@ static int handle_curl_result(struct slot_results *results)
19031926 credential_reject (& http_auth );
19041927 if (always_auth_proactively ())
19051928 http_proactive_auth = PROACTIVE_AUTH_NONE ;
1929+ if (http_auth .ntlm_suppressed ) {
1930+ warning (_ ("Due to its cryptographic weaknesses, "
1931+ "NTLM authentication has been\n"
1932+ "disabled in Git by default. You can "
1933+ "re-enable it for trusted servers\n"
1934+ "by running:\n\n"
1935+ "git config set "
1936+ "http.%s://%s.allowNTLMAuth true" ),
1937+ http_auth .protocol , http_auth .host );
1938+ }
19061939 return HTTP_NOAUTH ;
19071940 } else {
19081941 http_auth_methods &= ~CURLAUTH_GSSNEGOTIATE ;
0 commit comments