1 : /* ***** BEGIN LICENSE BLOCK *****
2 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 : *
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/
8 : *
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.
13 : *
14 : * The Original Code is the Negotiateauth
15 : *
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.
19 : *
20 : * Contributor(s):
21 : * Darin Fisher <darin@meer.net>
22 : *
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.
34 : *
35 : * ***** END LICENSE BLOCK ***** */
36 :
37 : #include "mozilla/ModuleUtils.h"
38 : #include "nsAuth.h"
39 :
40 : //-----------------------------------------------------------------------------
41 :
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} \
48 : }
49 :
50 : #include "nsHttpNegotiateAuth.h"
51 0 : NS_GENERIC_FACTORY_CONSTRUCTOR(nsHttpNegotiateAuth)
52 : //-----------------------------------------------------------------------------
53 :
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} \
60 : }
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} \
67 : }
68 :
69 : #include "nsAuthGSSAPI.h"
70 :
71 : #if defined( USE_SSPI )
72 : #include "nsAuthSSPI.h"
73 :
74 : static nsresult
75 : nsSysNTLMAuthConstructor(nsISupports *outer, REFNSIID iid, void **result)
76 : {
77 : if (outer)
78 : return NS_ERROR_NO_AGGREGATION;
79 :
80 : nsAuthSSPI *auth = new nsAuthSSPI(PACKAGE_TYPE_NTLM);
81 : if (!auth)
82 : return NS_ERROR_OUT_OF_MEMORY;
83 :
84 : NS_ADDREF(auth);
85 : nsresult rv = auth->QueryInterface(iid, result);
86 : NS_RELEASE(auth);
87 : return rv;
88 : }
89 :
90 : static nsresult
91 : nsKerbSSPIAuthConstructor(nsISupports *outer, REFNSIID iid, void **result)
92 : {
93 : if (outer)
94 : return NS_ERROR_NO_AGGREGATION;
95 :
96 : nsAuthSSPI *auth = new nsAuthSSPI(PACKAGE_TYPE_KERBEROS);
97 : if (!auth)
98 : return NS_ERROR_OUT_OF_MEMORY;
99 :
100 : NS_ADDREF(auth);
101 : nsresult rv = auth->QueryInterface(iid, result);
102 : NS_RELEASE(auth);
103 : return rv;
104 : }
105 :
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} \
112 : }
113 :
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} \
120 : }
121 :
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} \
128 : }
129 :
130 : #else
131 :
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} \
138 : }
139 :
140 : #include "nsAuthSambaNTLM.h"
141 : static nsresult
142 0 : nsSambaNTLMAuthConstructor(nsISupports *outer, REFNSIID iid, void **result)
143 : {
144 0 : if (outer)
145 0 : return NS_ERROR_NO_AGGREGATION;
146 :
147 0 : nsCOMPtr<nsAuthSambaNTLM> auth = new nsAuthSambaNTLM();
148 0 : if (!auth)
149 0 : return NS_ERROR_OUT_OF_MEMORY;
150 :
151 0 : nsresult rv = auth->SpawnNTLMAuthHelper();
152 0 : if (NS_FAILED(rv)) {
153 : // Failure here probably means that cached credentials were not available
154 0 : return rv;
155 : }
156 :
157 0 : return auth->QueryInterface(iid, result);
158 : }
159 :
160 : #endif
161 :
162 : static nsresult
163 0 : nsKerbGSSAPIAuthConstructor(nsISupports *outer, REFNSIID iid, void **result)
164 : {
165 0 : if (outer)
166 0 : return NS_ERROR_NO_AGGREGATION;
167 :
168 0 : nsAuthGSSAPI *auth = new nsAuthGSSAPI(PACKAGE_TYPE_KERBEROS);
169 0 : if (!auth)
170 0 : return NS_ERROR_OUT_OF_MEMORY;
171 :
172 0 : NS_ADDREF(auth);
173 0 : nsresult rv = auth->QueryInterface(iid, result);
174 0 : NS_RELEASE(auth);
175 0 : return rv;
176 : }
177 :
178 : static nsresult
179 0 : nsGSSAPIAuthConstructor(nsISupports *outer, REFNSIID iid, void **result)
180 : {
181 0 : if (outer)
182 0 : return NS_ERROR_NO_AGGREGATION;
183 :
184 0 : nsAuthGSSAPI *auth = new nsAuthGSSAPI(PACKAGE_TYPE_NEGOTIATE);
185 0 : if (!auth)
186 0 : return NS_ERROR_OUT_OF_MEMORY;
187 :
188 0 : NS_ADDREF(auth);
189 0 : nsresult rv = auth->QueryInterface(iid, result);
190 0 : NS_RELEASE(auth);
191 0 : return rv;
192 : }
193 :
194 :
195 : #if defined( USE_SSPI )
196 : NS_GENERIC_FACTORY_CONSTRUCTOR(nsAuthSSPI)
197 : #endif
198 :
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} \
205 : }
206 :
207 : #include "nsAuthSASL.h"
208 0 : NS_GENERIC_FACTORY_CONSTRUCTOR(nsAuthSASL)
209 :
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);
221 :
222 :
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 }
236 : };
237 :
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 }
251 : };
252 :
253 : //-----------------------------------------------------------------------------
254 : #if defined( PR_LOGGING )
255 : PRLogModuleInfo *gNegotiateLog;
256 :
257 : // setup nspr logging ...
258 : static nsresult
259 0 : InitNegotiateAuth()
260 : {
261 0 : gNegotiateLog = PR_NewLogModule("negotiateauth");
262 0 : return NS_OK;
263 : }
264 : #else
265 : #define InitNegotiateAuth nsnull
266 : #endif
267 :
268 : static void
269 0 : DestroyNegotiateAuth()
270 : {
271 0 : nsAuthGSSAPI::Shutdown();
272 0 : }
273 :
274 : static const mozilla::Module kAuthModule = {
275 : mozilla::Module::kVersion,
276 : kAuthCIDs,
277 : kAuthContracts,
278 : NULL,
279 : NULL,
280 : InitNegotiateAuth,
281 : DestroyNegotiateAuth
282 : };
283 :
284 : NSMODULE_DEFN(nsAuthModule) = &kAuthModule;
|