Selaa lähdekoodia

Factoring our HttpAuthenticationFailed before fixing the Bug 1420

Source commit: 65b8f04125ff57e0dd859a2264b7cc08750b4f75
Martin Prikryl 9 vuotta sitten
vanhempi
sitoutus
fc80db90fd
2 muutettua tiedostoa jossa 20 lisäystä ja 14 poistoa
  1. 19 14
      source/core/WebDAVFileSystem.cpp
  2. 1 0
      source/core/WebDAVFileSystem.h

+ 19 - 14
source/core/WebDAVFileSystem.cpp

@@ -1819,25 +1819,30 @@ bool __fastcall TWebDAVFileSystem::IsNtlmAuthentication()
     SameText(FAuthorizationProtocol, L"Negotiate");
 }
 //---------------------------------------------------------------------------
+void __fastcall TWebDAVFileSystem::HttpAuthenticationFailed()
+{
+  // NTLM/GSSAPI failed
+  if (IsNtlmAuthentication())
+  {
+    // Next time do not try Negotiate (NTLM/GSSAPI),
+    // otherwise we end up in an endless loop.
+    // If the server returns all other challenges in the response, removing the Negotiate
+    // protocol will itself ensure that other protocols are tried (we haven't seen this behaviour).
+    // IIS will return only Negotiate response if the request was Negotiate, so there's no fallback.
+    // We have to retry with a fresh request. That's what FAuthenticationRetry does.
+    FTerminal->LogEvent(FORMAT(L"%s challenge failed, will try different challenge", (FAuthorizationProtocol)));
+    ne_remove_server_auth(FNeonSession);
+    NeonAddAuthentiation(false);
+    FAuthenticationRetry = true;
+  }
+}
+//---------------------------------------------------------------------------
 void TWebDAVFileSystem::NeonPostHeaders(ne_request * /*Req*/, void * UserData, const ne_status * Status)
 {
   TWebDAVFileSystem * FileSystem = static_cast<TWebDAVFileSystem *>(UserData);
   if (Status->code == HttpUnauthorized)
   {
-    // NTLM/GSSAPI failed
-    if (FileSystem->IsNtlmAuthentication())
-    {
-      // Next time do not try Negotiate (NTLM/GSSAPI),
-      // otherwise we end up in an endless loop.
-      // If the server returns all other challenges in the response, removing the Negotiate
-      // protocol will itself ensure that other protocols are tried (we haven't seen this behaviour).
-      // IIS will return only Negotiate response if the request was Negotiate, so there's no fallback.
-      // We have to retry with a fresh request. That's what FAuthenticationRetry does.
-      FileSystem->FTerminal->LogEvent(FORMAT(L"%s challenge failed, will try different challenge", (FileSystem->FAuthorizationProtocol)));
-      ne_remove_server_auth(FileSystem->FNeonSession);
-      FileSystem->NeonAddAuthentiation(false);
-      FileSystem->FAuthenticationRetry = true;
-    }
+    FileSystem->HttpAuthenticationFailed();
   }
 }
 //---------------------------------------------------------------------------

+ 1 - 0
source/core/WebDAVFileSystem.h

@@ -146,6 +146,7 @@ protected:
   static void InitSslSession(ssl_st * Ssl, ne_session * Session);
   void __fastcall InitSslSessionImpl(ssl_st * Ssl);
   void __fastcall NeonAddAuthentiation(bool UseNegotiate);
+  void __fastcall HttpAuthenticationFailed();
 
 private:
   TFileSystemInfo FFileSystemInfo;