Back to index

lightning-sunbird  0.9+nobinonly
nsAuthFactory.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Negotiateauth
00015  *
00016  * The Initial Developer of the Original Code is IBM Corporation.
00017  * Portions created by the Initial Developer are Copyright (C) 2004
00018  * the Initial Developer. All Rights Reserved.
00019  *
00020  * Contributor(s):
00021  *   Darin Fisher <darin@meer.net>
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 #include "nsIGenericFactory.h"
00038 #include "nsAuth.h"
00039 
00040 //-----------------------------------------------------------------------------
00041 
00042 #define NS_HTTPNEGOTIATEAUTH_CID                   \
00043 { /* 75c80fd0-accb-432c-af59-ec60668c3990 */       \
00044   0x75c80fd0,                                      \
00045   0xaccb,                                          \
00046   0x432c,                                          \
00047   {0xaf, 0x59, 0xec, 0x60, 0x66, 0x8c, 0x39, 0x90} \
00048 }
00049 
00050 #include "nsHttpNegotiateAuth.h"
00051 NS_GENERIC_FACTORY_CONSTRUCTOR(nsHttpNegotiateAuth)
00052 //-----------------------------------------------------------------------------
00053 
00054 #define NS_NEGOTIATEAUTH_CID                       \
00055 { /* 96ec4163-efc8-407a-8735-007fb26be4e8 */       \
00056   0x96ec4163,                                      \
00057   0xefc8,                                          \
00058   0x407a,                                          \
00059   {0x87, 0x35, 0x00, 0x7f, 0xb2, 0x6b, 0xe4, 0xe8} \
00060 }
00061 #define NS_GSSAUTH_CID                             \
00062 { /* dc8e21a0-03e4-11da-8cd6-0800200c9a66 */       \
00063   0xdc8e21a0,                                      \
00064   0x03e4,                                          \
00065   0x11da,                                          \
00066   {0x8c, 0xd6, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66} \
00067 }
00068 
00069 #include "nsAuthGSSAPI.h"
00070 
00071 #if defined( USE_SSPI )
00072 #include "nsAuthSSPI.h"
00073 
00074 static NS_METHOD
00075 nsSysNTLMAuthConstructor(nsISupports *outer, REFNSIID iid, void **result)
00076 {
00077   if (outer)
00078     return NS_ERROR_NO_AGGREGATION;
00079 
00080   nsAuthSSPI *auth = new nsAuthSSPI(PACKAGE_TYPE_NTLM);
00081   if (!auth)
00082     return NS_ERROR_OUT_OF_MEMORY;
00083   
00084   NS_ADDREF(auth);
00085   nsresult rv = auth->QueryInterface(iid, result);
00086   NS_RELEASE(auth);
00087   return rv;
00088 }
00089 
00090 static NS_METHOD
00091 nsKerbSSPIAuthConstructor(nsISupports *outer, REFNSIID iid, void **result)
00092 {
00093   if (outer)
00094     return NS_ERROR_NO_AGGREGATION;
00095 
00096   nsAuthSSPI *auth = new nsAuthSSPI(PACKAGE_TYPE_KERBEROS);
00097   if (!auth)
00098     return NS_ERROR_OUT_OF_MEMORY;
00099   
00100   NS_ADDREF(auth);
00101   nsresult rv = auth->QueryInterface(iid, result);
00102   NS_RELEASE(auth);
00103   return rv;
00104 }
00105 
00106 #define NS_SYSNTLMAUTH_CID                         \
00107 { /* dc195987-6e9a-47bc-b1fd-ab895d398833 */       \
00108   0xdc195987,                                      \
00109   0x6e9a,                                          \
00110   0x47bc,                                          \
00111   {0xb1, 0xfd, 0xab, 0x89, 0x5d, 0x39, 0x88, 0x33} \
00112 }
00113 
00114 #define NS_NEGOTIATEAUTHSSPI_CID                   \
00115 { /* 78d3b0c0-0241-11da-8cd6-0800200c9a66 */       \
00116   0x78d3b0c0,                                      \
00117   0x0241,                                          \
00118   0x11da,                                          \
00119   {0x8c, 0xd6, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66} \
00120 }
00121 
00122 #define NS_KERBAUTHSSPI_CID                        \
00123 { /* 8c3a0e20-03e5-11da-8cd6-0800200c9a66 */       \
00124   0x8c3a0e20,                                      \
00125   0x03e5,                                          \
00126   0x11da,                                          \
00127   {0x8c, 0xd6, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66} \
00128 }
00129 
00130 #endif
00131 
00132 static NS_METHOD
00133 nsKerbGSSAPIAuthConstructor(nsISupports *outer, REFNSIID iid, void **result)
00134 {
00135   if (outer)
00136     return NS_ERROR_NO_AGGREGATION;
00137 
00138   nsAuthGSSAPI *auth = new nsAuthGSSAPI(PACKAGE_TYPE_KERBEROS);
00139   if (!auth)
00140     return NS_ERROR_OUT_OF_MEMORY;
00141   
00142   NS_ADDREF(auth);
00143   nsresult rv = auth->QueryInterface(iid, result);
00144   NS_RELEASE(auth);
00145   return rv;
00146 }
00147 
00148 static NS_METHOD
00149 nsGSSAPIAuthConstructor(nsISupports *outer, REFNSIID iid, void **result)
00150 {
00151   if (outer)
00152     return NS_ERROR_NO_AGGREGATION;
00153 
00154   nsAuthGSSAPI *auth = new nsAuthGSSAPI(PACKAGE_TYPE_NEGOTIATE);
00155   if (!auth)
00156     return NS_ERROR_OUT_OF_MEMORY;
00157   
00158   NS_ADDREF(auth);
00159   nsresult rv = auth->QueryInterface(iid, result);
00160   NS_RELEASE(auth);
00161   return rv;
00162 }
00163 
00164 
00165 #if defined( USE_SSPI )
00166 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAuthSSPI)
00167 #endif
00168 
00169 #define NS_AUTHSASL_CID                            \
00170 { /* 815e42e0-72cc-480f-934b-148e33c228a6 */       \
00171   0x815e42e0,                                      \
00172   0x72cc,                                          \
00173   0x480f,                                          \
00174   {0x93, 0x4b, 0x14, 0x8e, 0x33, 0xc2, 0x28, 0xa6} \
00175 }
00176 
00177 #include "nsAuthSASL.h"
00178 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAuthSASL)
00179 
00180 //-----------------------------------------------------------------------------
00181 
00182 static nsModuleComponentInfo components[] = {
00183   { "nsAuthKerbGSS", 
00184     NS_GSSAUTH_CID,
00185     NS_AUTH_MODULE_CONTRACTID_PREFIX "kerb-gss",
00186     nsKerbGSSAPIAuthConstructor
00187   },
00188   { "nsAuthNegoGSSAPI", 
00189     NS_NEGOTIATEAUTH_CID,
00190     NS_AUTH_MODULE_CONTRACTID_PREFIX "negotiate-gss",
00191     nsGSSAPIAuthConstructor
00192   },
00193 #if defined( USE_SSPI )
00194   { "nsAuthNegoSSPI", 
00195     NS_NEGOTIATEAUTHSSPI_CID,
00196     NS_AUTH_MODULE_CONTRACTID_PREFIX "negotiate-sspi",
00197     nsAuthSSPIConstructor
00198   },
00199   { "nsAuthKerbSSPI", 
00200     NS_KERBAUTHSSPI_CID,
00201     NS_AUTH_MODULE_CONTRACTID_PREFIX "kerb-sspi",
00202     nsKerbSSPIAuthConstructor
00203   },
00204   { "nsAuthSYSNTLM", 
00205     NS_SYSNTLMAUTH_CID,
00206     NS_AUTH_MODULE_CONTRACTID_PREFIX "sys-ntlm",
00207     nsSysNTLMAuthConstructor
00208   },
00209 #endif
00210   { "nsHttpNegotiateAuth", 
00211     NS_HTTPNEGOTIATEAUTH_CID,
00212     NS_HTTP_AUTHENTICATOR_CONTRACTID_PREFIX "negotiate",
00213     nsHttpNegotiateAuthConstructor
00214   },
00215   { "nsAuthSASL",
00216     NS_AUTHSASL_CID,
00217     NS_AUTH_MODULE_CONTRACTID_PREFIX "sasl-gssapi",
00218     nsAuthSASLConstructor
00219   }
00220 };
00221 
00222 //-----------------------------------------------------------------------------
00223 #if defined( PR_LOGGING )
00224 PRLogModuleInfo *gNegotiateLog;
00225 
00226 // setup nspr logging ...
00227 PR_STATIC_CALLBACK(nsresult)
00228 InitNegotiateAuth(nsIModule *self)
00229 {
00230   gNegotiateLog = PR_NewLogModule("negotiateauth");
00231   return NS_OK;
00232 }
00233 #else
00234 #define InitNegotiateAuth nsnull
00235 #endif
00236 
00237 NS_IMPL_NSGETMODULE_WITH_CTOR(nsAuthModule, components, InitNegotiateAuth)