nsIAuthModule.cpp (1972B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #include "nsIAuthModule.h" 6 #if defined(USE_SSPI) 7 # include "nsAuthSSPI.h" 8 #else 9 # include "nsAuthSambaNTLM.h" 10 #endif 11 #include "nsCRT.h" 12 #include "nsAuthGSSAPI.h" 13 #include "nsAuthSASL.h" 14 #include "nsNTLMAuthModule.h" 15 #include "nsNSSComponent.h" 16 17 // static 18 already_AddRefed<nsIAuthModule> nsIAuthModule::CreateInstance( 19 const char* aType) { 20 nsCOMPtr<nsIAuthModule> auth; 21 if (!nsCRT::strcmp(aType, "kerb-gss")) { 22 auth = new nsAuthGSSAPI(PACKAGE_TYPE_KERBEROS); 23 } else if (!nsCRT::strcmp(aType, "negotiate-gss")) { 24 auth = new nsAuthGSSAPI(PACKAGE_TYPE_NEGOTIATE); 25 #if defined(USE_SSPI) 26 } else if (!nsCRT::strcmp(aType, "negotiate-sspi")) { 27 auth = new nsAuthSSPI(); 28 } else if (!nsCRT::strcmp(aType, "kerb-sspi")) { 29 auth = new nsAuthSSPI(PACKAGE_TYPE_KERBEROS); 30 } else if (!nsCRT::strcmp(aType, "sys-ntlm")) { 31 auth = new nsAuthSSPI(PACKAGE_TYPE_NTLM); 32 #elif !defined(XP_MACOSX) 33 } else if (!nsCRT::strcmp(aType, "sys-ntlm")) { 34 RefPtr<nsAuthSambaNTLM> sambaAuth = new nsAuthSambaNTLM(); 35 36 nsresult rv = sambaAuth->SpawnNTLMAuthHelper(); 37 if (NS_FAILED(rv)) { 38 // Failure here probably means that cached credentials were not available 39 return nullptr; 40 } 41 42 auth = std::move(sambaAuth); 43 #endif 44 } else if (!nsCRT::strcmp(aType, "sasl-gssapi")) { 45 auth = new nsAuthSASL(); 46 } else if (!nsCRT::strcmp(aType, "ntlm") && XRE_IsParentProcess() && 47 EnsureNSSInitializedChromeOrContent()) { 48 RefPtr<nsNTLMAuthModule> ntlmAuth = new nsNTLMAuthModule(); 49 50 nsresult rv = ntlmAuth->InitTest(); 51 if (NS_FAILED(rv)) { 52 return nullptr; 53 } 54 55 auth = std::move(ntlmAuth); 56 } else { 57 return nullptr; 58 } 59 60 return auth.forget(); 61 } 62 63 mozilla::LazyLogModule gNegotiateLog("negotiateauth");