extensions/auth/nsAuthFactory.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include "mozilla/ModuleUtils.h"
michael@0 6 #include "nsAuth.h"
michael@0 7 #include "nsAutoPtr.h"
michael@0 8
michael@0 9 //-----------------------------------------------------------------------------
michael@0 10
michael@0 11 #define NS_HTTPNEGOTIATEAUTH_CID \
michael@0 12 { /* 75c80fd0-accb-432c-af59-ec60668c3990 */ \
michael@0 13 0x75c80fd0, \
michael@0 14 0xaccb, \
michael@0 15 0x432c, \
michael@0 16 {0xaf, 0x59, 0xec, 0x60, 0x66, 0x8c, 0x39, 0x90} \
michael@0 17 }
michael@0 18
michael@0 19 #include "nsHttpNegotiateAuth.h"
michael@0 20 NS_GENERIC_FACTORY_CONSTRUCTOR(nsHttpNegotiateAuth)
michael@0 21 //-----------------------------------------------------------------------------
michael@0 22
michael@0 23 #define NS_NEGOTIATEAUTH_CID \
michael@0 24 { /* 96ec4163-efc8-407a-8735-007fb26be4e8 */ \
michael@0 25 0x96ec4163, \
michael@0 26 0xefc8, \
michael@0 27 0x407a, \
michael@0 28 {0x87, 0x35, 0x00, 0x7f, 0xb2, 0x6b, 0xe4, 0xe8} \
michael@0 29 }
michael@0 30 #define NS_GSSAUTH_CID \
michael@0 31 { /* dc8e21a0-03e4-11da-8cd6-0800200c9a66 */ \
michael@0 32 0xdc8e21a0, \
michael@0 33 0x03e4, \
michael@0 34 0x11da, \
michael@0 35 {0x8c, 0xd6, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66} \
michael@0 36 }
michael@0 37
michael@0 38 #include "nsAuthGSSAPI.h"
michael@0 39
michael@0 40 #if defined( USE_SSPI )
michael@0 41 #include "nsAuthSSPI.h"
michael@0 42
michael@0 43 static nsresult
michael@0 44 nsSysNTLMAuthConstructor(nsISupports *outer, REFNSIID iid, void **result)
michael@0 45 {
michael@0 46 if (outer)
michael@0 47 return NS_ERROR_NO_AGGREGATION;
michael@0 48
michael@0 49 nsAuthSSPI *auth = new nsAuthSSPI(PACKAGE_TYPE_NTLM);
michael@0 50 if (!auth)
michael@0 51 return NS_ERROR_OUT_OF_MEMORY;
michael@0 52
michael@0 53 NS_ADDREF(auth);
michael@0 54 nsresult rv = auth->QueryInterface(iid, result);
michael@0 55 NS_RELEASE(auth);
michael@0 56 return rv;
michael@0 57 }
michael@0 58
michael@0 59 static nsresult
michael@0 60 nsKerbSSPIAuthConstructor(nsISupports *outer, REFNSIID iid, void **result)
michael@0 61 {
michael@0 62 if (outer)
michael@0 63 return NS_ERROR_NO_AGGREGATION;
michael@0 64
michael@0 65 nsAuthSSPI *auth = new nsAuthSSPI(PACKAGE_TYPE_KERBEROS);
michael@0 66 if (!auth)
michael@0 67 return NS_ERROR_OUT_OF_MEMORY;
michael@0 68
michael@0 69 NS_ADDREF(auth);
michael@0 70 nsresult rv = auth->QueryInterface(iid, result);
michael@0 71 NS_RELEASE(auth);
michael@0 72 return rv;
michael@0 73 }
michael@0 74
michael@0 75 #define NS_SYSNTLMAUTH_CID \
michael@0 76 { /* dc195987-6e9a-47bc-b1fd-ab895d398833 */ \
michael@0 77 0xdc195987, \
michael@0 78 0x6e9a, \
michael@0 79 0x47bc, \
michael@0 80 {0xb1, 0xfd, 0xab, 0x89, 0x5d, 0x39, 0x88, 0x33} \
michael@0 81 }
michael@0 82
michael@0 83 #define NS_NEGOTIATEAUTHSSPI_CID \
michael@0 84 { /* 78d3b0c0-0241-11da-8cd6-0800200c9a66 */ \
michael@0 85 0x78d3b0c0, \
michael@0 86 0x0241, \
michael@0 87 0x11da, \
michael@0 88 {0x8c, 0xd6, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66} \
michael@0 89 }
michael@0 90
michael@0 91 #define NS_KERBAUTHSSPI_CID \
michael@0 92 { /* 8c3a0e20-03e5-11da-8cd6-0800200c9a66 */ \
michael@0 93 0x8c3a0e20, \
michael@0 94 0x03e5, \
michael@0 95 0x11da, \
michael@0 96 {0x8c, 0xd6, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66} \
michael@0 97 }
michael@0 98
michael@0 99 #else
michael@0 100
michael@0 101 #define NS_SAMBANTLMAUTH_CID \
michael@0 102 { /* bc54f001-6eb0-4e32-9f49-7e064d8e70ef */ \
michael@0 103 0xbc54f001, \
michael@0 104 0x6eb0, \
michael@0 105 0x4e32, \
michael@0 106 {0x9f, 0x49, 0x7e, 0x06, 0x4d, 0x8e, 0x70, 0xef} \
michael@0 107 }
michael@0 108
michael@0 109 #include "nsAuthSambaNTLM.h"
michael@0 110 static nsresult
michael@0 111 nsSambaNTLMAuthConstructor(nsISupports *outer, REFNSIID iid, void **result)
michael@0 112 {
michael@0 113 if (outer)
michael@0 114 return NS_ERROR_NO_AGGREGATION;
michael@0 115
michael@0 116 nsRefPtr<nsAuthSambaNTLM> auth = new nsAuthSambaNTLM();
michael@0 117 if (!auth)
michael@0 118 return NS_ERROR_OUT_OF_MEMORY;
michael@0 119
michael@0 120 nsresult rv = auth->SpawnNTLMAuthHelper();
michael@0 121 if (NS_FAILED(rv)) {
michael@0 122 // Failure here probably means that cached credentials were not available
michael@0 123 return rv;
michael@0 124 }
michael@0 125
michael@0 126 return auth->QueryInterface(iid, result);
michael@0 127 }
michael@0 128
michael@0 129 #endif
michael@0 130
michael@0 131 static nsresult
michael@0 132 nsKerbGSSAPIAuthConstructor(nsISupports *outer, REFNSIID iid, void **result)
michael@0 133 {
michael@0 134 if (outer)
michael@0 135 return NS_ERROR_NO_AGGREGATION;
michael@0 136
michael@0 137 nsAuthGSSAPI *auth = new nsAuthGSSAPI(PACKAGE_TYPE_KERBEROS);
michael@0 138 if (!auth)
michael@0 139 return NS_ERROR_OUT_OF_MEMORY;
michael@0 140
michael@0 141 NS_ADDREF(auth);
michael@0 142 nsresult rv = auth->QueryInterface(iid, result);
michael@0 143 NS_RELEASE(auth);
michael@0 144 return rv;
michael@0 145 }
michael@0 146
michael@0 147 static nsresult
michael@0 148 nsGSSAPIAuthConstructor(nsISupports *outer, REFNSIID iid, void **result)
michael@0 149 {
michael@0 150 if (outer)
michael@0 151 return NS_ERROR_NO_AGGREGATION;
michael@0 152
michael@0 153 nsAuthGSSAPI *auth = new nsAuthGSSAPI(PACKAGE_TYPE_NEGOTIATE);
michael@0 154 if (!auth)
michael@0 155 return NS_ERROR_OUT_OF_MEMORY;
michael@0 156
michael@0 157 NS_ADDREF(auth);
michael@0 158 nsresult rv = auth->QueryInterface(iid, result);
michael@0 159 NS_RELEASE(auth);
michael@0 160 return rv;
michael@0 161 }
michael@0 162
michael@0 163
michael@0 164 #if defined( USE_SSPI )
michael@0 165 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAuthSSPI)
michael@0 166 #endif
michael@0 167
michael@0 168 #define NS_AUTHSASL_CID \
michael@0 169 { /* 815e42e0-72cc-480f-934b-148e33c228a6 */ \
michael@0 170 0x815e42e0, \
michael@0 171 0x72cc, \
michael@0 172 0x480f, \
michael@0 173 {0x93, 0x4b, 0x14, 0x8e, 0x33, 0xc2, 0x28, 0xa6} \
michael@0 174 }
michael@0 175
michael@0 176 #include "nsAuthSASL.h"
michael@0 177 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAuthSASL)
michael@0 178
michael@0 179 NS_DEFINE_NAMED_CID(NS_GSSAUTH_CID);
michael@0 180 NS_DEFINE_NAMED_CID(NS_NEGOTIATEAUTH_CID);
michael@0 181 #if defined( USE_SSPI )
michael@0 182 NS_DEFINE_NAMED_CID(NS_NEGOTIATEAUTHSSPI_CID);
michael@0 183 NS_DEFINE_NAMED_CID(NS_KERBAUTHSSPI_CID);
michael@0 184 NS_DEFINE_NAMED_CID(NS_SYSNTLMAUTH_CID);
michael@0 185 #else
michael@0 186 NS_DEFINE_NAMED_CID(NS_SAMBANTLMAUTH_CID);
michael@0 187 #endif
michael@0 188 NS_DEFINE_NAMED_CID(NS_HTTPNEGOTIATEAUTH_CID);
michael@0 189 NS_DEFINE_NAMED_CID(NS_AUTHSASL_CID);
michael@0 190
michael@0 191
michael@0 192 static const mozilla::Module::CIDEntry kAuthCIDs[] = {
michael@0 193 { &kNS_GSSAUTH_CID, false, nullptr, nsKerbGSSAPIAuthConstructor },
michael@0 194 { &kNS_NEGOTIATEAUTH_CID, false, nullptr, nsGSSAPIAuthConstructor },
michael@0 195 #if defined( USE_SSPI )
michael@0 196 { &kNS_NEGOTIATEAUTHSSPI_CID, false, nullptr, nsAuthSSPIConstructor },
michael@0 197 { &kNS_KERBAUTHSSPI_CID, false, nullptr, nsKerbSSPIAuthConstructor },
michael@0 198 { &kNS_SYSNTLMAUTH_CID, false, nullptr, nsSysNTLMAuthConstructor },
michael@0 199 #else
michael@0 200 { &kNS_SAMBANTLMAUTH_CID, false, nullptr, nsSambaNTLMAuthConstructor },
michael@0 201 #endif
michael@0 202 { &kNS_HTTPNEGOTIATEAUTH_CID, false, nullptr, nsHttpNegotiateAuthConstructor },
michael@0 203 { &kNS_AUTHSASL_CID, false, nullptr, nsAuthSASLConstructor },
michael@0 204 { nullptr }
michael@0 205 };
michael@0 206
michael@0 207 static const mozilla::Module::ContractIDEntry kAuthContracts[] = {
michael@0 208 { NS_AUTH_MODULE_CONTRACTID_PREFIX "kerb-gss", &kNS_GSSAUTH_CID },
michael@0 209 { NS_AUTH_MODULE_CONTRACTID_PREFIX "negotiate-gss", &kNS_NEGOTIATEAUTH_CID },
michael@0 210 #if defined( USE_SSPI )
michael@0 211 { NS_AUTH_MODULE_CONTRACTID_PREFIX "negotiate-sspi", &kNS_NEGOTIATEAUTHSSPI_CID },
michael@0 212 { NS_AUTH_MODULE_CONTRACTID_PREFIX "kerb-sspi", &kNS_KERBAUTHSSPI_CID },
michael@0 213 { NS_AUTH_MODULE_CONTRACTID_PREFIX "sys-ntlm", &kNS_SYSNTLMAUTH_CID },
michael@0 214 #else
michael@0 215 { NS_AUTH_MODULE_CONTRACTID_PREFIX "sys-ntlm", &kNS_SAMBANTLMAUTH_CID },
michael@0 216 #endif
michael@0 217 { NS_HTTP_AUTHENTICATOR_CONTRACTID_PREFIX "negotiate", &kNS_HTTPNEGOTIATEAUTH_CID },
michael@0 218 { NS_AUTH_MODULE_CONTRACTID_PREFIX "sasl-gssapi", &kNS_AUTHSASL_CID },
michael@0 219 { nullptr }
michael@0 220 };
michael@0 221
michael@0 222 //-----------------------------------------------------------------------------
michael@0 223 #if defined( PR_LOGGING )
michael@0 224 PRLogModuleInfo *gNegotiateLog;
michael@0 225
michael@0 226 // setup nspr logging ...
michael@0 227 static nsresult
michael@0 228 InitNegotiateAuth()
michael@0 229 {
michael@0 230 gNegotiateLog = PR_NewLogModule("negotiateauth");
michael@0 231 return NS_OK;
michael@0 232 }
michael@0 233 #else
michael@0 234 #define InitNegotiateAuth nullptr
michael@0 235 #endif
michael@0 236
michael@0 237 static void
michael@0 238 DestroyNegotiateAuth()
michael@0 239 {
michael@0 240 nsAuthGSSAPI::Shutdown();
michael@0 241 }
michael@0 242
michael@0 243 static const mozilla::Module kAuthModule = {
michael@0 244 mozilla::Module::kVersion,
michael@0 245 kAuthCIDs,
michael@0 246 kAuthContracts,
michael@0 247 nullptr,
michael@0 248 nullptr,
michael@0 249 InitNegotiateAuth,
michael@0 250 DestroyNegotiateAuth
michael@0 251 };
michael@0 252
michael@0 253 NSMODULE_DEFN(nsAuthModule) = &kAuthModule;

mercurial