Fix regexp match pair end-index == -1 assumption. (r=dmandelin, a=blocker b=605754)
[mozilla-central.git] / extensions / auth / nsAuthFactory.cpp
blob1af8147ad283f1b2956127556a01f9203934805c
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is the Negotiateauth
16 * The Initial Developer of the Original Code is IBM Corporation.
17 * Portions created by the Initial Developer are Copyright (C) 2004
18 * the Initial Developer. All Rights Reserved.
20 * Contributor(s):
21 * Darin Fisher <darin@meer.net>
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
37 #include "mozilla/ModuleUtils.h"
38 #include "nsAuth.h"
40 //-----------------------------------------------------------------------------
42 #define NS_HTTPNEGOTIATEAUTH_CID \
43 { /* 75c80fd0-accb-432c-af59-ec60668c3990 */ \
44 0x75c80fd0, \
45 0xaccb, \
46 0x432c, \
47 {0xaf, 0x59, 0xec, 0x60, 0x66, 0x8c, 0x39, 0x90} \
50 #include "nsHttpNegotiateAuth.h"
51 NS_GENERIC_FACTORY_CONSTRUCTOR(nsHttpNegotiateAuth)
52 //-----------------------------------------------------------------------------
54 #define NS_NEGOTIATEAUTH_CID \
55 { /* 96ec4163-efc8-407a-8735-007fb26be4e8 */ \
56 0x96ec4163, \
57 0xefc8, \
58 0x407a, \
59 {0x87, 0x35, 0x00, 0x7f, 0xb2, 0x6b, 0xe4, 0xe8} \
61 #define NS_GSSAUTH_CID \
62 { /* dc8e21a0-03e4-11da-8cd6-0800200c9a66 */ \
63 0xdc8e21a0, \
64 0x03e4, \
65 0x11da, \
66 {0x8c, 0xd6, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66} \
69 #include "nsAuthGSSAPI.h"
71 #if defined( USE_SSPI )
72 #include "nsAuthSSPI.h"
74 static nsresult
75 nsSysNTLMAuthConstructor(nsISupports *outer, REFNSIID iid, void **result)
77 if (outer)
78 return NS_ERROR_NO_AGGREGATION;
80 nsAuthSSPI *auth = new nsAuthSSPI(PACKAGE_TYPE_NTLM);
81 if (!auth)
82 return NS_ERROR_OUT_OF_MEMORY;
84 NS_ADDREF(auth);
85 nsresult rv = auth->QueryInterface(iid, result);
86 NS_RELEASE(auth);
87 return rv;
90 static nsresult
91 nsKerbSSPIAuthConstructor(nsISupports *outer, REFNSIID iid, void **result)
93 if (outer)
94 return NS_ERROR_NO_AGGREGATION;
96 nsAuthSSPI *auth = new nsAuthSSPI(PACKAGE_TYPE_KERBEROS);
97 if (!auth)
98 return NS_ERROR_OUT_OF_MEMORY;
100 NS_ADDREF(auth);
101 nsresult rv = auth->QueryInterface(iid, result);
102 NS_RELEASE(auth);
103 return rv;
106 #define NS_SYSNTLMAUTH_CID \
107 { /* dc195987-6e9a-47bc-b1fd-ab895d398833 */ \
108 0xdc195987, \
109 0x6e9a, \
110 0x47bc, \
111 {0xb1, 0xfd, 0xab, 0x89, 0x5d, 0x39, 0x88, 0x33} \
114 #define NS_NEGOTIATEAUTHSSPI_CID \
115 { /* 78d3b0c0-0241-11da-8cd6-0800200c9a66 */ \
116 0x78d3b0c0, \
117 0x0241, \
118 0x11da, \
119 {0x8c, 0xd6, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66} \
122 #define NS_KERBAUTHSSPI_CID \
123 { /* 8c3a0e20-03e5-11da-8cd6-0800200c9a66 */ \
124 0x8c3a0e20, \
125 0x03e5, \
126 0x11da, \
127 {0x8c, 0xd6, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66} \
130 #else
132 #define NS_SAMBANTLMAUTH_CID \
133 { /* bc54f001-6eb0-4e32-9f49-7e064d8e70ef */ \
134 0xbc54f001, \
135 0x6eb0, \
136 0x4e32, \
137 {0x9f, 0x49, 0x7e, 0x06, 0x4d, 0x8e, 0x70, 0xef} \
140 #include "nsAuthSambaNTLM.h"
141 static nsresult
142 nsSambaNTLMAuthConstructor(nsISupports *outer, REFNSIID iid, void **result)
144 if (outer)
145 return NS_ERROR_NO_AGGREGATION;
147 nsCOMPtr<nsAuthSambaNTLM> auth = new nsAuthSambaNTLM();
148 if (!auth)
149 return NS_ERROR_OUT_OF_MEMORY;
151 nsresult rv = auth->SpawnNTLMAuthHelper();
152 if (NS_FAILED(rv)) {
153 // Failure here probably means that cached credentials were not available
154 return rv;
157 return auth->QueryInterface(iid, result);
160 #endif
162 static nsresult
163 nsKerbGSSAPIAuthConstructor(nsISupports *outer, REFNSIID iid, void **result)
165 if (outer)
166 return NS_ERROR_NO_AGGREGATION;
168 nsAuthGSSAPI *auth = new nsAuthGSSAPI(PACKAGE_TYPE_KERBEROS);
169 if (!auth)
170 return NS_ERROR_OUT_OF_MEMORY;
172 NS_ADDREF(auth);
173 nsresult rv = auth->QueryInterface(iid, result);
174 NS_RELEASE(auth);
175 return rv;
178 static nsresult
179 nsGSSAPIAuthConstructor(nsISupports *outer, REFNSIID iid, void **result)
181 if (outer)
182 return NS_ERROR_NO_AGGREGATION;
184 nsAuthGSSAPI *auth = new nsAuthGSSAPI(PACKAGE_TYPE_NEGOTIATE);
185 if (!auth)
186 return NS_ERROR_OUT_OF_MEMORY;
188 NS_ADDREF(auth);
189 nsresult rv = auth->QueryInterface(iid, result);
190 NS_RELEASE(auth);
191 return rv;
195 #if defined( USE_SSPI )
196 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAuthSSPI)
197 #endif
199 #define NS_AUTHSASL_CID \
200 { /* 815e42e0-72cc-480f-934b-148e33c228a6 */ \
201 0x815e42e0, \
202 0x72cc, \
203 0x480f, \
204 {0x93, 0x4b, 0x14, 0x8e, 0x33, 0xc2, 0x28, 0xa6} \
207 #include "nsAuthSASL.h"
208 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAuthSASL)
210 NS_DEFINE_NAMED_CID(NS_GSSAUTH_CID);
211 NS_DEFINE_NAMED_CID(NS_NEGOTIATEAUTH_CID);
212 #if defined( USE_SSPI )
213 NS_DEFINE_NAMED_CID(NS_NEGOTIATEAUTHSSPI_CID);
214 NS_DEFINE_NAMED_CID(NS_KERBAUTHSSPI_CID);
215 NS_DEFINE_NAMED_CID(NS_SYSNTLMAUTH_CID);
216 #else
217 NS_DEFINE_NAMED_CID(NS_SAMBANTLMAUTH_CID);
218 #endif
219 NS_DEFINE_NAMED_CID(NS_HTTPNEGOTIATEAUTH_CID);
220 NS_DEFINE_NAMED_CID(NS_AUTHSASL_CID);
223 static const mozilla::Module::CIDEntry kAuthCIDs[] = {
224 { &kNS_GSSAUTH_CID, false, NULL, nsKerbGSSAPIAuthConstructor },
225 { &kNS_NEGOTIATEAUTH_CID, false, NULL, nsGSSAPIAuthConstructor },
226 #if defined( USE_SSPI )
227 { &kNS_NEGOTIATEAUTHSSPI_CID, false, NULL, nsAuthSSPIConstructor },
228 { &kNS_KERBAUTHSSPI_CID, false, NULL, nsKerbSSPIAuthConstructor },
229 { &kNS_SYSNTLMAUTH_CID, false, NULL, nsSysNTLMAuthConstructor },
230 #else
231 { &kNS_SAMBANTLMAUTH_CID, false, NULL, nsSambaNTLMAuthConstructor },
232 #endif
233 { &kNS_HTTPNEGOTIATEAUTH_CID, false, NULL, nsHttpNegotiateAuthConstructor },
234 { &kNS_AUTHSASL_CID, false, NULL, nsAuthSASLConstructor },
235 { NULL }
238 static const mozilla::Module::ContractIDEntry kAuthContracts[] = {
239 { NS_AUTH_MODULE_CONTRACTID_PREFIX "kerb-gss", &kNS_GSSAUTH_CID },
240 { NS_AUTH_MODULE_CONTRACTID_PREFIX "negotiate-gss", &kNS_NEGOTIATEAUTH_CID },
241 #if defined( USE_SSPI )
242 { NS_AUTH_MODULE_CONTRACTID_PREFIX "negotiate-sspi", &kNS_NEGOTIATEAUTHSSPI_CID },
243 { NS_AUTH_MODULE_CONTRACTID_PREFIX "kerb-sspi", &kNS_KERBAUTHSSPI_CID },
244 { NS_AUTH_MODULE_CONTRACTID_PREFIX "sys-ntlm", &kNS_SYSNTLMAUTH_CID },
245 #else
246 { NS_AUTH_MODULE_CONTRACTID_PREFIX "sys-ntlm", &kNS_SAMBANTLMAUTH_CID },
247 #endif
248 { NS_HTTP_AUTHENTICATOR_CONTRACTID_PREFIX "negotiate", &kNS_HTTPNEGOTIATEAUTH_CID },
249 { NS_AUTH_MODULE_CONTRACTID_PREFIX "sasl-gssapi", &kNS_AUTHSASL_CID },
250 { NULL }
253 //-----------------------------------------------------------------------------
254 #if defined( PR_LOGGING )
255 PRLogModuleInfo *gNegotiateLog;
257 // setup nspr logging ...
258 static nsresult
259 InitNegotiateAuth()
261 gNegotiateLog = PR_NewLogModule("negotiateauth");
262 return NS_OK;
264 #else
265 #define InitNegotiateAuth nsnull
266 #endif
268 static void
269 DestroyNegotiateAuth()
271 nsAuthGSSAPI::Shutdown();
274 static const mozilla::Module kAuthModule = {
275 mozilla::Module::kVersion,
276 kAuthCIDs,
277 kAuthContracts,
278 NULL,
279 NULL,
280 InitNegotiateAuth,
281 DestroyNegotiateAuth
284 NSMODULE_DEFN(nsAuthModule) = &kAuthModule;