diff --git a/mozilla/build/mac/NGLayoutBuildList.pm b/mozilla/build/mac/NGLayoutBuildList.pm index 590ff896908..49c814abb22 100644 --- a/mozilla/build/mac/NGLayoutBuildList.pm +++ b/mozilla/build/mac/NGLayoutBuildList.pm @@ -397,7 +397,6 @@ sub BuildClientDist() _InstallFromManifest(":mozilla:js:src:xpconnect:public:MANIFEST", "$distdirectory:xpconnect:"); #CAPS - _InstallFromManifest(":mozilla:caps:public:MANIFEST", "$distdirectory:caps:"); _InstallFromManifest(":mozilla:caps:include:MANIFEST", "$distdirectory:caps:"); _InstallFromManifest(":mozilla:caps:idl:MANIFEST", "$distdirectory:idl:"); diff --git a/mozilla/caps/Makefile.in b/mozilla/caps/Makefile.in index db7fb4c04a6..cea4586b06c 100644 --- a/mozilla/caps/Makefile.in +++ b/mozilla/caps/Makefile.in @@ -21,7 +21,7 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -DIRS = idl public include src +DIRS = idl include src include $(topsrcdir)/config/rules.mk diff --git a/mozilla/caps/idl/MANIFEST b/mozilla/caps/idl/MANIFEST index 3dec8aa8987..7fb34727b81 100644 --- a/mozilla/caps/idl/MANIFEST +++ b/mozilla/caps/idl/MANIFEST @@ -1,5 +1,9 @@ -nsIPrincipal.idl -nsIScriptSecurityManager.idl nsICapsSecurityCallbacks.idl +nsIPrincipal.idl +nsIPrincipalArray.idl +nsIPrincipalManager.idl nsIPrivilege.idl +nsIPrivilegeManager.idl +nsIScriptSecurityManager.idl +nsICapsManager.idl nsITarget.idl diff --git a/mozilla/caps/idl/Makefile.in b/mozilla/caps/idl/Makefile.in index 9c6e53dec71..ea75a1cfb23 100644 --- a/mozilla/caps/idl/Makefile.in +++ b/mozilla/caps/idl/Makefile.in @@ -28,7 +28,11 @@ XPIDLSRCS = \ nsIScriptSecurityManager.idl \ nsICapsSecurityCallbacks.idl \ nsIPrincipal.idl \ + nsIPrincipalArray.idl \ + nsIPrincipalManager.idl \ nsIPrivilege.idl \ + nsIPrivilegeManager.idl \ + nsICapsManager.idl \ nsITarget.idl \ $(NULL) diff --git a/mozilla/caps/idl/makefile.win b/mozilla/caps/idl/makefile.win index 46d01f08a54..e40d3773cc4 100644 --- a/mozilla/caps/idl/makefile.win +++ b/mozilla/caps/idl/makefile.win @@ -23,7 +23,11 @@ XPIDLSRCS= \ .\nsIScriptSecurityManager.idl \ .\nsICapsSecurityCallbacks.idl \ .\nsIPrincipal.idl \ + .\nsIPrincipalArray.idl \ + .\nsIPrincipalManager.idl \ .\nsIPrivilege.idl \ + .\nsIPrivilegeManager.idl \ + .\nsICapsManager.idl \ .\nsITarget.idl \ $(NULL) diff --git a/mozilla/caps/idl/nsICapsManager.idl b/mozilla/caps/idl/nsICapsManager.idl new file mode 100644 index 00000000000..6d234934218 --- /dev/null +++ b/mozilla/caps/idl/nsICapsManager.idl @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1999 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsISupports.idl" +#include "nsIPrincipal.idl" +#include "nsIPrincipalArray.idl" +#include "nsIPrincipalManager.idl" +#include "nsIPrivilegeManager.idl" +#include "nsITarget.idl" +#include "nsICapsSecurityCallbacks.idl" + +interface nsIScriptContext; + +[uuid(7cb78236-47b0-11d3-ba17-0060b0f199a2)] +interface nsICapsManager : nsISupports { + + void GetPrincipalManager(out nsIPrincipalManager prinMan); + + void GetPrivilegeManager(out nsIPrivilegeManager privMan); + + void CreateCodebasePrincipal([const] in string codebaseURL, out nsIPrincipal prin); +%{C++ + NS_IMETHOD + CreateCertificatePrincipal(const unsigned char * * certChain, PRUint32 * certChainLengths, PRUint32 noOfCerts, nsIPrincipal * * prin) = 0; +%} + + void GetPermission(in nsIPrincipal prin, in nsITarget target, out short privilegeState); + + void SetPermission(in nsIPrincipal prin, in nsITarget target, in short privilegeState); + + void AskPermission(in nsIPrincipal prin, in nsITarget target, out short privilegeState); + + void Initialize(out boolean result); + + void InitializeFrameWalker(in nsICapsSecurityCallbacks aInterface); + + void EnablePrivilege(in nsIScriptContext cx, [const] in string targetName, in long callerDepth, out boolean result); + + void IsPrivilegeEnabled(in nsIScriptContext cx, [const] in string targetName, in long callerDepth, out boolean result); + + void RevertPrivilege(in nsIScriptContext cx, [const] in string targetName, in long callerDepth, out boolean result); + + void DisablePrivilege(in nsIScriptContext cx, [const] in string targetName, in long callerDepth, out boolean result); + + void IsAllowed(in voidStar annotation, [const] in string target, out boolean result); + +}; + +%{C++ +#define NS_CCAPSMANAGER_CID \ +{ /* fd347500-307f-11d2-97f0-00805f8a28d0 */ \ + 0xfd347500, \ + 0x307f, \ + 0x11d2, \ + {0x97, 0xf0, 0x00, 0x80, 0x5f, 0x8a, 0x28, 0xd0} \ +} +%} \ No newline at end of file diff --git a/mozilla/caps/idl/nsIPrincipal.idl b/mozilla/caps/idl/nsIPrincipal.idl index 09a7bdba124..754dfab8449 100644 --- a/mozilla/caps/idl/nsIPrincipal.idl +++ b/mozilla/caps/idl/nsIPrincipal.idl @@ -20,7 +20,7 @@ [uuid(ff9313d0-25e1-11d2-8160-006008119d7a)] interface nsIPrincipal : nsISupports { - const short PrincipalType_Unknown=-1; + const short PrincipalType_Unknown=0; const short PrincipalType_CodebaseExact=1; const short PrincipalType_CodebaseRegex=2; const short PrincipalType_Certificate=3; @@ -44,7 +44,7 @@ interface nsICodebasePrincipal : nsIPrincipal { [uuid(ebfefcd0-25e1-11d2-8160-006008119d7a)] interface nsICertificatePrincipal : nsIPrincipal { - void GetPublicKey(out string publicKey, out unsigned long publicKeySize); + void GetPublicKey(out string publicKey); void GetCompanyName(out string ppCompanyName); void GetCertificateAuthority(out string ppCertAuthority); void GetSerialNumber(out string ppSerialNumber); diff --git a/mozilla/caps/idl/nsIPrincipalArray.idl b/mozilla/caps/idl/nsIPrincipalArray.idl new file mode 100644 index 00000000000..52126d1a463 --- /dev/null +++ b/mozilla/caps/idl/nsIPrincipalArray.idl @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1999 Netscape Communications Corporation. All Rights + * Reserved. + */ +#include "nsISupports.idl" +#include "nsIPrincipal.idl" + +[uuid(f118c9cc-452c-11d3-ba17-0060b0f199a2)] +interface nsIPrincipalArray : nsISupports +{ + const short SetComparisonType_ProperSubset = -1; + const short SetComparisonType_Equal = 0; + const short SetComparisonType_NoSubset = 1; + + void ComparePrincipalArray(in nsIPrincipalArray other, out short comparisonType); + + void IntersectPrincipalArray(in nsIPrincipalArray other, out nsIPrincipalArray result); + + void FreePrincipalArray(); + + void AddPrincipalArrayElement(in nsIPrincipal principal); + + void GetPrincipalArrayElement(in unsigned long index, out nsIPrincipal result); + + void SetPrincipalArrayElement(in unsigned long index, in nsIPrincipal principal); + + void GetPrincipalArraySize(out unsigned long result); +}; \ No newline at end of file diff --git a/mozilla/caps/idl/nsIPrincipalManager.idl b/mozilla/caps/idl/nsIPrincipalManager.idl new file mode 100644 index 00000000000..95a6452e5e4 --- /dev/null +++ b/mozilla/caps/idl/nsIPrincipalManager.idl @@ -0,0 +1,46 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1999 Netscape Communications Corporation. All Rights + * Reserved. + */ +#include "nsISupports.idl" +#include "nsIPrincipal.idl" +#include "nsITarget.idl" +#include "nsIPrincipalArray.idl" + +interface nsIScriptContext; + +//#define NS_ALL_PRIVILEGES ((nsITarget *)NULL) + + +[uuid(dc7d0bb0-25e1-11d2-8160-006008119d7a)] +interface nsIPrincipalManager : nsISupports +{ + void CreateCodebasePrincipal([const] in string codebaseURL, out nsIPrincipal prin); + +%{C++ + NS_IMETHOD + CreateCertificatePrincipal(const unsigned char * * certChain, PRUint32 * certChainLengths, PRUint32 noOfCerts, nsIPrincipal * * prin) = 0; +%} + + void RegisterPrincipal(in nsIPrincipal prin); + + void CanExtendTrust(in nsIPrincipalArray fromPrinArray, in nsIPrincipalArray toPrinArray, out boolean result); + + void NewPrincipalArray(in unsigned long count, out nsIPrincipalArray result); + + void CheckMatchPrincipal(in nsIScriptContext cx, in nsIPrincipal principal, in long callerDepth, out boolean result); + +}; diff --git a/mozilla/caps/idl/nsIPrivilegeManager.idl b/mozilla/caps/idl/nsIPrivilegeManager.idl new file mode 100644 index 00000000000..66a3cf2c7b8 --- /dev/null +++ b/mozilla/caps/idl/nsIPrivilegeManager.idl @@ -0,0 +1,46 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1999 Netscape Communications Corporation. All Rights + * Reserved. + */ +#include "nsISupports.idl" +#include "nsIPrincipal.idl" +#include "nsITarget.idl" +#include "nsIPrincipalArray.idl" + +interface nsIScriptContext; + +[uuid(43019898-4782-11d3-ba17-0060b0f199a2)] +interface nsIPrivilegeManager : nsISupports +{ + void IsPrivilegeEnabled(in nsIScriptContext cx, in nsITarget target, in long callerDepth, out boolean result); + + void EnablePrivilege(in nsIScriptContext cx, in nsITarget target, in nsIPrincipal prin, in long callerDeph, out boolean result); + + void RevertPrivilege(in nsIScriptContext cx, in nsITarget target, in long callerDepth, out boolean result); + + void DisablePrivilege(in nsIScriptContext cx, in nsITarget target, in long callerDepth, out boolean result); + + void CheckPrivilegeGranted(in nsIScriptContext cx, in nsITarget target, in long callerDepth, in voidStar data, out boolean result); + + void GetPrincipalPrivilege(in nsITarget target, in nsIPrincipal prin, in voidStar data, out nsIPrivilege priv); + + void RemovePrincipalsPrivilege(in string prinName, in string targetName, out boolean result); + + void AskPermission(in nsIPrincipal useThisPrin, in nsITarget target, in voidStar data, out boolean result); + + void SetPermission(in nsIPrincipal useThisPrin, in nsITarget target, in nsIPrivilege newPrivilege); + +}; \ No newline at end of file diff --git a/mozilla/caps/include/MANIFEST b/mozilla/caps/include/MANIFEST index 6211487b504..8d2698434da 100644 --- a/mozilla/caps/include/MANIFEST +++ b/mozilla/caps/include/MANIFEST @@ -6,7 +6,8 @@ nsCCapsManagerFactory.h nsCertificatePrincipal.h nsCodebasePrincipal.h nsLoadZig.h -nsPrincipalTools.h +nsPrincipalArray.h +nsPrincipalManager.h nsPrivilege.h nsPrivilegeManager.h nsPrivilegeTable.h diff --git a/mozilla/caps/include/Makefile.in b/mozilla/caps/include/Makefile.in index 149f4cbe051..5dd7c93cf47 100644 --- a/mozilla/caps/include/Makefile.in +++ b/mozilla/caps/include/Makefile.in @@ -32,7 +32,8 @@ EXPORTS = \ nsCertificatePrincipal.h \ nsCodebasePrincipal.h \ nsLoadZig.h \ - nsPrincipalTools.h \ + nsPrincipalArray.h \ + nsPrincipalManager.h \ nsPrivilege.h \ nsPrivilegeManager.h \ nsPrivilegeTable.h \ diff --git a/mozilla/caps/include/makefile.win b/mozilla/caps/include/makefile.win index c9091873ac6..1acef4defeb 100755 --- a/mozilla/caps/include/makefile.win +++ b/mozilla/caps/include/makefile.win @@ -37,7 +37,8 @@ EXPORTS= \ nsCertificatePrincipal.h \ nsCodebasePrincipal.h \ nsLoadZig.h \ - nsPrincipalTools.h \ + nsPrincipalArray.h \ + nsPrincipalManager.h \ nsPrivilege.h \ nsPrivilegeManager.h \ nsPrivilegeTable.h \ diff --git a/mozilla/caps/include/nsCCapsManager.h b/mozilla/caps/include/nsCCapsManager.h index 074f8028ae1..c985ed12cf4 100644 --- a/mozilla/caps/include/nsCCapsManager.h +++ b/mozilla/caps/include/nsCCapsManager.h @@ -20,11 +20,14 @@ #define _NS_CCAPS_MANAGER_H_ #include "nsIPrincipal.h" +#include "nsIPrincipalManager.h" +#include "nsIPrivilegeManager.h" #include "nsIPrivilege.h" #include "nsISupports.h" #include "nsICapsManager.h" #include "nsAgg.h" #include "nsPrivilegeManager.h" +#include "nsPrincipalManager.h" /** * nsCCapsManager implements the nsICapsManager @@ -44,203 +47,72 @@ NS_DECL_AGGREGATED //////////////////////////////////////////////////////////////////////////// // from nsICapsManager: +NS_IMETHOD +GetPrincipalManager(nsIPrincipalManager * * prinMan); + +NS_IMETHOD +GetPrivilegeManager(nsIPrivilegeManager * * privMan); + NS_IMETHOD CreateCodebasePrincipal(const char *codebaseURL, nsIPrincipal** prin); NS_IMETHOD CreateCertificatePrincipal(const unsigned char **certChain, PRUint32 *certChainLengths, PRUint32 noOfCerts, nsIPrincipal** prin); -/** - * Creates a CodeSourcePrincipal, which has both nsICodebasePrincipal - * and nsICertPrincipal - * - * @param certByteData - The ceritificate's byte array data including the chain. - * @param certByteDataSize - the length of certificate byte array. - * @param codebaseURL - the codebase URL - */ -/* -NS_IMETHOD -CreateCodeSourcePrincipal(const unsigned char **certChain, PRUint32 *certChainLengths, PRUint32 noOfCerts, const char *codebaseURL, nsIPrincipal** prin); -*/ - -/** - * Returns the permission for given principal and target - * - * @param prin - is either certificate principal or codebase principal - * @param target - is NS_ALL_PRIVILEGES. - * @param state - the return value is passed in this parameter. - */ NS_IMETHOD GetPermission(nsIPrincipal * prin, nsITarget * target, PRInt16 * privilegeState); -/** - * Set the permission state for given principal and target. This wouldn't - * prompt the end user with UI. - * - * @param prin - is either certificate principal or codebase principal - * @param target - is NS_ALL_PRIVILEGES. - * @param state - is permisson state that should be set for the given prin - * and target parameters. - */ NS_IMETHOD -SetPermission(nsIPrincipal * prin, nsITarget* target, PRInt16 * privilegeState); +SetPermission(nsIPrincipal * prin, nsITarget* target, PRInt16 privilegeState); -/** - * Prompts the user if they want to grant permission for the given principal and - * for the given target. - * - * @param prin - is either certificate principal or codebase principal - * @param target - is NS_ALL_PRIVILEGES. - * @param result - is the permission user has given for the given principal and - * target - */ NS_IMETHOD AskPermission(nsIPrincipal * prin, nsITarget * target, PRInt16 * privilegeState); - - -/* - * All of the following methods are used by JS (the code located - * in lib/libmocha area). - */ - -/** - * Initializes the capabilities subsytem (ie setting the system principal, initializing - * privilege Manager, creating the capsManager factory etc - * - * @param result - is true if principal was successfully registered with the system - */ NS_IMETHOD Initialize(PRBool * result); NS_IMETHOD InitializeFrameWalker(nsICapsSecurityCallbacks * aInterface); -/** - * Registers the given Principal with the system. - * - * @param prin - is either certificate principal or codebase principal - * @param result - is true if principal was successfully registered with the system - */ NS_IMETHOD RegisterPrincipal(nsIPrincipal * prin); -/** - * Prompts the user if they want to grant permission for the principal located - * at the given stack depth for the given target. - * - * @param context - is the parameter JS needs to determinte the principal - * @param targetName - is the name of the target. - * @param callerDepth - is the depth of JS stack frame, which JS uses to determinte the - * principal - * @param result - is true if user has given permission for the given principal and - * target - */ NS_IMETHOD -EnablePrivilege(void* context, const char* targetName, PRInt32 callerDepth, PRBool *result); - -/** - * Returns if the user granted permission for the principal located at the given - * stack depth for the given target. - * - * @param context - is the parameter JS needs to determinte the principal - * @param targetName - is the name of the target. - * @param callerDepth - is the depth of JS stack frame, which JS uses to determinte the - * principal - * @param result - is true if user has given permission for the given principal and - * target - */ -NS_IMETHOD -IsPrivilegeEnabled(void* context, const char* targetName, PRInt32 callerDepth, PRBool *result); - -/** - * Reverts the permission (granted/denied) user gave for the principal located - * at the given stack depth for the given target. - * - * @param context - is the parameter JS needs to determinte the principal - * @param targetName - is the name of the target. - * @param callerDepth - is the depth of JS stack frame, which JS uses to determinte the - * principal - * @param result - is true if user has given permission for the given principal and - * target - */ -NS_IMETHOD -RevertPrivilege(void* context, const char* targetName, PRInt32 callerDepth, PRBool *result); - -/** - * Disable permissions for the principal located at the given stack depth for the - * given target. - * - * @param context - is the parameter JS needs to determinte the principal - * @param targetName - is the name of the target. - * @param callerDepth - is the depth of JS stack frame, which JS uses to determinte the - * principal - * @param result - is true if user has given permission for the given principal and - * target - */ -NS_IMETHOD -DisablePrivilege(void* context, const char* targetName, PRInt32 callerDepth, PRBool *result); - - -/* XXX: Some of the arguments for the following interfaces may change. - * This is a first cut. I need to talk to joki. We should get rid of void* parameters. - */ -NS_IMETHOD -ComparePrincipalArray(void* prin1Array, void* prin2Array, PRInt16 * comparisonType); +EnablePrivilege(nsIScriptContext * context, const char* targetName, PRInt32 callerDepth, PRBool *result); NS_IMETHOD -IntersectPrincipalArray(void* prin1Array, void* prin2Array, void* *result); +IsPrivilegeEnabled(nsIScriptContext * context, const char* targetName, PRInt32 callerDepth, PRBool *result); NS_IMETHOD -CanExtendTrust(void* fromPrinArray, void* toPrinArray, PRBool *result); +RevertPrivilege(nsIScriptContext * context, const char* targetName, PRInt32 callerDepth, PRBool *result); NS_IMETHOD -CreateMixedPrincipalArray(void *zig, char* name, const char* codebase, void** result); +DisablePrivilege(nsIScriptContext * context, const char* targetName, PRInt32 callerDepth, PRBool *result); + +//NS_IMETHOD +//CreateMixedPrincipalArray(void * zig, const char * name, const char* codebase, nsIPrincipalArray * * result); NS_IMETHOD -NewPrincipalArray(PRUint32 count, void* *result); - -NS_IMETHOD -FreePrincipalArray(void *prinArray); - -NS_IMETHOD -GetPrincipalArrayElement(void *prinArrayArg, PRUint32 index, nsIPrincipal * * result); - -NS_IMETHOD -SetPrincipalArrayElement(void *prinArrayArg, PRUint32 index, nsIPrincipal * principal); - -NS_IMETHOD -GetPrincipalArraySize(void *prinArrayArg, PRUint32 *result); - -/* The following interfaces will replace all of the following old calls. - * - * nsCapsGetPermission(struct nsPrivilege *privilege) - * nsCapsGetPrivilege(struct nsPrivilegeTable *annotation, struct nsITarget *target) - * - */ -NS_IMETHOD -IsAllowed(void *annotation, char* target, PRBool *result); - -//////////////////////////////////////////////////////////////////////////// -// from nsCCapsManager: +IsAllowed(void * annotation, const char * target, PRBool * result); nsCCapsManager(nsISupports *aOuter); virtual ~nsCCapsManager(void); void -CreateNSPrincipalArray(nsPrincipalArray* prinArray, nsPrincipalArray* *pPrincipalArray); -/* +CreateNSPrincipalArray(nsIPrincipalArray * prinArray, nsIPrincipalArray * * pPrincipalArray); + NS_METHOD -GetNSPrincipal(nsIPrincipal * pNSIPrincipal, nsIPrincipal ** ppNSPRincipal); -*/ -NS_METHOD -GetNSPrincipalArray(nsPrincipalArray* prinArray, nsPrincipalArray* *pPrincipalArray); +GetNSPrincipalArray(nsIPrincipalArray * prinArray, nsIPrincipalArray * * pPrincipalArray); void SetSystemPrivilegeManager(); +void +SetSystemPrincipalManager(); + protected: - nsPrivilegeManager * privilegeManager; + nsIPrivilegeManager * privilegeManager; + nsIPrincipalManager * principalManager; }; -#endif // nsCCapsManager_h___ +#endif // nsCCapsManager_h___ \ No newline at end of file diff --git a/mozilla/caps/include/nsCaps.h b/mozilla/caps/include/nsCaps.h index dbe857af494..4a159692b3e 100644 --- a/mozilla/caps/include/nsCaps.h +++ b/mozilla/caps/include/nsCaps.h @@ -26,8 +26,7 @@ class nsTarget; class nsIPrincipal; class nsIPrivilege; class nsPrivilegeTable; - -struct nsPrivilegeManager; +class nsPrivilegeManager; struct NSJSJavaFrameWrapper; /* wrappers for nsPrivilegeManager object */ @@ -52,12 +51,6 @@ nsCapsDisablePrivilege(void* context, class nsITarget * target, PRInt32 callerDe PR_EXTERN(void*) nsCapsGetClassPrincipalsFromStack(void* context, PRInt32 callerDepth); -PR_EXTERN(PRInt16) -nsCapsComparePrincipalArray(void* prin1Array, void* prin2Array); - -PR_EXTERN(void*) -nsCapsIntersectPrincipalArray(void* prin1Array, void* prin2Array); - PR_EXTERN(PRBool) nsCapsCanExtendTrust(void* from, void* to); @@ -80,19 +73,6 @@ nsCapsPrincipalGetVendor(nsIPrincipal * principal); PR_EXTERN(void *) nsCapsNewPrincipalArray(PRUint32 count); -PR_EXTERN(void) -nsCapsFreePrincipalArray(void * prinArray); - -PR_EXTERN(void *) -nsCapsGetPrincipalArrayElement(void * prinArray, PRUint32 index); - -PR_EXTERN(void) -nsCapsSetPrincipalArrayElement(void * prinArray, PRUint32 index, void *element); - -PR_EXTERN(PRUint32) -nsCapsGetPrincipalArraySize(void * prinArray); - - /* wrappers for nsITarget object */ PR_EXTERN(class nsITarget *) nsCapsFindTarget(char * name); diff --git a/mozilla/caps/include/nsCertificatePrincipal.h b/mozilla/caps/include/nsCertificatePrincipal.h index 34a179841b9..5b5437cb921 100644 --- a/mozilla/caps/include/nsCertificatePrincipal.h +++ b/mozilla/caps/include/nsCertificatePrincipal.h @@ -26,7 +26,7 @@ public: NS_DECL_ISUPPORTS NS_IMETHOD - GetPublicKey(char ** pk, PRUint32 * pkSize); + GetPublicKey(char ** pk); NS_IMETHOD GetCompanyName(char ** cn); @@ -58,14 +58,13 @@ public: NS_IMETHOD Equals(nsIPrincipal * other, PRBool * result); - nsCertificatePrincipal(PRInt16 * type, const unsigned char ** certChain, - PRUint32 * certChainLengths, PRUint32 noOfCerts, nsresult * result); + nsCertificatePrincipal(PRInt16 type, const char * key); + nsCertificatePrincipal(PRInt16 type, const unsigned char ** certChain, PRUint32 * certChainLengths, PRUint32 noOfCerts); virtual ~nsCertificatePrincipal(void); protected: PRInt16 itsType; - char * itsKey; - PRUint32 itsKeyLength; + const char * itsKey; nsVector * itsCertificateArray; char * itsCompanyName; char * itsCertificateAuthority; diff --git a/mozilla/caps/include/nsCodebasePrincipal.h b/mozilla/caps/include/nsCodebasePrincipal.h index ed9a58ae3f3..eb519ce0853 100644 --- a/mozilla/caps/include/nsCodebasePrincipal.h +++ b/mozilla/caps/include/nsCodebasePrincipal.h @@ -50,12 +50,12 @@ public: NS_IMETHOD Equals(nsIPrincipal * other, PRBool * result); - nsCodebasePrincipal(PRInt16 * type, const char *codebaseURL); + nsCodebasePrincipal(PRInt16 type, const char *codebaseURL); virtual ~nsCodebasePrincipal(void); protected: - const char * codeBaseURL; - PRInt16 * itsType; + const char * itsCodeBaseURL; + PRInt16 itsType; }; #endif // _NS_CODEBASE_PRINCIPAL_H_ diff --git a/mozilla/caps/include/nsPrincipalArray.h b/mozilla/caps/include/nsPrincipalArray.h new file mode 100644 index 00000000000..6434da13465 --- /dev/null +++ b/mozilla/caps/include/nsPrincipalArray.h @@ -0,0 +1,69 @@ +#ifndef _NS_PRINCIPAL_ARRAY_H_ +#define _NS_PRINCIPAL_ARRAY_H_ + +#include "nsIPrincipalArray.h" +#include "nsIPrincipal.h" +#include "nsVector.h" +#include "nsHashtable.h" + + +class nsPrincipalArray : public nsIPrincipalArray { +public: + +NS_DECL_ISUPPORTS + +nsPrincipalArray(void); +nsPrincipalArray(PRUint32 count); +~nsPrincipalArray(); + +NS_IMETHOD +ComparePrincipalArray(nsIPrincipalArray * other, PRInt16 * comparisonType); + +NS_IMETHOD +IntersectPrincipalArray(nsIPrincipalArray * other , nsIPrincipalArray * * result); + +NS_IMETHOD +FreePrincipalArray(); + +NS_IMETHOD +AddPrincipalArrayElement(nsIPrincipal * principal); + +NS_IMETHOD +GetPrincipalArrayElement(PRUint32 index, nsIPrincipal * * result); + +NS_IMETHOD +SetPrincipalArrayElement(PRUint32 index, nsIPrincipal * principal); + +NS_IMETHOD +GetPrincipalArraySize(PRUint32 * result); + +private: +nsVector * itsArray; +}; + +class PrincipalKey: public nsHashKey { +public: + nsIPrincipal * itsPrincipal; + + PrincipalKey(nsIPrincipal * prin) { + itsPrincipal = prin; + } + + PRUint32 HashValue(void) const { + PRUint32 * code = 0; + itsPrincipal->HashCode(code); + return *code; + } + + PRBool Equals(const nsHashKey * aKey) const { + PRBool result = PR_FALSE; + itsPrincipal->Equals(((const PrincipalKey *) aKey)->itsPrincipal,& result); + return result; + } + + nsHashKey * Clone(void) const { + return new PrincipalKey(itsPrincipal); + } +}; + +#endif /* _NS_PRINCIPAL_TOOLS_H_ */ \ No newline at end of file diff --git a/mozilla/caps/include/nsPrincipalManager.h b/mozilla/caps/include/nsPrincipalManager.h new file mode 100644 index 00000000000..a9f7e6c77ad --- /dev/null +++ b/mozilla/caps/include/nsPrincipalManager.h @@ -0,0 +1,102 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef _NS_PRINCIPAL_MANAGER_H_ +#define _NS_PRINCIPAL_MANAGER_H_ + +#include "nsIPrincipalManager.h" +#include "nsPrivilegeManager.h" + +PRBool nsPrincipalManagerInitialize(void); + +class nsPrincipalManager : public nsIPrincipalManager { + +public: + + NS_DECL_ISUPPORTS + + NS_IMETHOD + CreateCodebasePrincipal(const char *codebaseURL, nsIPrincipal * * prin); + + NS_IMETHOD + CreateCertificatePrincipal(const unsigned char * * certChain, PRUint32 * certChainLengths, PRUint32 noOfCerts, nsIPrincipal * * prin); + + NS_IMETHOD + RegisterPrincipal(nsIPrincipal * prin); + + NS_IMETHOD + CanExtendTrust(nsIPrincipalArray * fromPrinArray, nsIPrincipalArray * toPrinArray, PRBool * result); + + NS_IMETHOD + NewPrincipalArray(PRUint32 count, nsIPrincipalArray * * result); + + NS_IMETHOD + CheckMatchPrincipal(nsIScriptContext * context, nsIPrincipal * principal, PRInt32 callerDepth, PRBool * result); + + static nsIPrincipalArray * + GetMyPrincipals(PRInt32 callerDepth); + + static nsIPrincipalArray * + GetMyPrincipals(nsIScriptContext * context, PRInt32 callerDepth); + + nsIPrincipal * + GetPrincipalFromString(char * prinName); + + static nsIPrincipal * + GetSystemPrincipal(void); + + static PRBool + HasSystemPrincipal(nsIPrincipalArray * prinArray); + + static nsIPrincipal * + GetUnsignedPrincipal(void); + + static nsIPrincipal * + GetUnknownPrincipal(void); + + static nsPrincipalManager * + GetPrincipalManager(void); + + const char * + GetAllPrincipalsString(void); + + void + AddToPrincipalNameToPrincipalTable(nsIPrincipal * prin); + + void + RemoveFromPrincipalNameToPrincipalTable(nsIPrincipal * prin); + + void + SetSystemPrincipal(nsIPrincipal * prin); + + nsIPrincipalArray * + GetClassPrincipalsFromStack(PRInt32 callerDepth); + + nsIPrincipalArray * + GetClassPrincipalsFromStack(nsIScriptContext * context, PRInt32 callerDepth); + + nsPrincipalManager(void); + virtual ~nsPrincipalManager(void); + +private: + nsHashtable * itsPrinNameToPrincipalTable; + static PRBool theInited; + +}; + +#endif /* _NS_PRINCIPAL_MANAGER_H_*/ \ No newline at end of file diff --git a/mozilla/caps/include/nsPrincipalTools.h b/mozilla/caps/include/nsPrincipalTools.h deleted file mode 100644 index 3f077659901..00000000000 --- a/mozilla/caps/include/nsPrincipalTools.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef _NS_PRINCIPAL_TOOLS_H_ -#define _NS_PRINCIPAL_TOOLS_H_ - -#include "nsIPrincipal.h" -#include "nsHashtable.h" - -typedef nsVector nsPrincipalArray; - -class PrincipalKey: public nsHashKey { -public: - nsIPrincipal * itsPrincipal; - - PrincipalKey(nsIPrincipal * prin) { - itsPrincipal = prin; - } - - PRUint32 HashValue(void) const { - PRUint32 * code = 0; - itsPrincipal->HashCode(code); - return *code; - } - - PRBool Equals(const nsHashKey * aKey) const { - PRBool result = PR_FALSE; - itsPrincipal->Equals(((const PrincipalKey *) aKey)->itsPrincipal,& result); - return result; - } - - nsHashKey * Clone(void) const { - return new PrincipalKey(itsPrincipal); - } -}; - -#endif /* _NS_PRINCIPAL_TOOLS_H_ */ diff --git a/mozilla/caps/include/nsPrivilegeManager.h b/mozilla/caps/include/nsPrivilegeManager.h index 5f8ecf7dd93..f13200915bc 100755 --- a/mozilla/caps/include/nsPrivilegeManager.h +++ b/mozilla/caps/include/nsPrivilegeManager.h @@ -27,7 +27,8 @@ #include "nsCaps.h" #include "nsTarget.h" #include "nsIPrincipal.h" -#include "nsPrincipalTools.h" +#include "nsIPrincipalArray.h" +#include "nsIPrivilegeManager.h" #include "nsIPrivilege.h" #include "nsPrivilegeTable.h" #include "nsSystemPrivilegeTable.h" @@ -41,13 +42,11 @@ PR_END_EXTERN_C PRBool nsPrivilegeManagerInitialize(void); -struct nsPrivilegeManager { +class nsPrivilegeManager : public nsIPrivilegeManager { public: -enum { SetComparisonType_ProperSubset=-1 }; -enum { SetComparisonType_Equal=0 }; -enum { SetComparisonType_NoSubset=1 }; +NS_DECL_ISUPPORTS nsPrivilegeManager(void); virtual ~nsPrivilegeManager(void); @@ -64,6 +63,110 @@ FindPrivilege(char * privStr); static nsIPrivilege * Add(nsIPrivilege * privilege1, nsIPrivilege * privilege2); +PRBool +IsPrivilegeEnabled(nsITarget *target, PRInt32 callerDepth); + +NS_IMETHOD +IsPrivilegeEnabled(nsIScriptContext * context, nsITarget * target, PRInt32 callerDepth, PRBool * result); + +PRBool +EnablePrivilege(nsITarget * target, PRInt32 callerDepth); + +PRBool +EnablePrivilege(nsIScriptContext * context, nsITarget * target, PRInt32 callerDepth); + +PRBool +EnablePrivilege(nsITarget * target, nsIPrincipal * preferredPrincipal, PRInt32 callerDepth); + +NS_IMETHOD +EnablePrivilege(nsIScriptContext * context, nsITarget * target, nsIPrincipal * preferredPrincipal, PRInt32 callerDepth, PRBool * result); + +PRBool +RevertPrivilege(nsITarget * target, PRInt32 callerDepth); + +NS_IMETHOD +RevertPrivilege(nsIScriptContext * context, nsITarget *target, PRInt32 callerDepth, PRBool * result); + +PRBool +DisablePrivilege(nsITarget *target, PRInt32 callerDepth); + +NS_IMETHOD +DisablePrivilege(nsIScriptContext * context, nsITarget *target, PRInt32 callerDepth, PRBool * result); + +PRBool +EnablePrincipalPrivilegeHelper(nsITarget *target, PRInt32 callerDepth, + nsIPrincipal * preferredPrin, void * data, + nsITarget *impersonator); + +PRBool +EnablePrincipalPrivilegeHelper(nsIScriptContext * context, nsITarget *target, PRInt32 callerDepth, + nsIPrincipal * preferredPrin, void * data, + nsITarget *impersonator); + +nsPrivilegeTable * +EnableScopePrivilegeHelper(nsITarget *target, PRInt32 callerDepth, + void *data, PRBool helpingSetScopePrivilege, + nsIPrincipal * prefPrin); + +nsPrivilegeTable * +EnableScopePrivilegeHelper(nsIScriptContext * context, nsITarget *target, PRInt32 callerDepth, void *data, + PRBool helpingSetScopePrivilege, nsIPrincipal * prefPrin); + +NS_IMETHOD +AskPermission(nsIPrincipal * useThisPrin, nsITarget* target, void* data, PRBool * result); + +NS_IMETHOD +SetPermission(nsIPrincipal * useThisPrin, nsITarget * target, nsIPrivilege * newPrivilege); + +void +UpdatePrivilegeTable(nsITarget *target, nsPrivilegeTable * privTable, nsIPrivilege * newPrivilege); + +PRBool +CheckPrivilegeGranted(nsITarget *target, PRInt32 callerDepth); + +PRBool +CheckPrivilegeGranted(nsIScriptContext * context, nsITarget *target, PRInt32 callerDepth); + +PRBool +CheckPrivilegeGranted(nsITarget * target, nsIPrincipal * principal, void *data); + +PRBool +CheckPrivilegeGranted(nsITarget * target, PRInt32 callerDepth, void * data); + +NS_IMETHOD +CheckPrivilegeGranted(nsIScriptContext * context, nsITarget * target, PRInt32 callerDepth, void * data, PRBool * result); + +NS_IMETHOD +GetPrincipalPrivilege(nsITarget * target, nsIPrincipal * prin, void * data, nsIPrivilege * * result); + +static nsPrivilegeManager * +GetPrivilegeManager(void); + +char * +CheckPrivilegeEnabled(nsTargetArray * targetArray, PRInt32 callerDepth, void *data); + +char * +CheckPrivilegeEnabled(nsIScriptContext * context, nsTargetArray * targetArray, PRInt32 callerDepth, void *data); + +void +GetTargetsWithPrivileges(char *prinName, char** forever, char** session, char **denied); + +nsPrivilegeTable * +GetPrivilegeTableFromStack(PRInt32 callerDepth, PRBool createIfNull); + +nsPrivilegeTable * +GetPrivilegeTableFromStack(nsIScriptContext * context, PRInt32 callerDepth, PRBool createIfNull); + +NS_IMETHODIMP +RemovePrincipalsPrivilege(const char * prinName, const char * targetName, PRBool * result); + +void +Remove(nsIPrincipal *prin, nsITarget *target); + +/* Helper functions for ADMIN UI */ +PRBool +RemovePrincipal(char *prinName); + void RegisterSystemPrincipal(nsIPrincipal * principal); @@ -73,175 +176,15 @@ RegisterPrincipal(nsIPrincipal * principal); PRBool UnregisterPrincipal(nsIPrincipal * principal); -PRBool -IsPrivilegeEnabled(nsITarget *target, PRInt32 callerDepth); - -PRBool -IsPrivilegeEnabled(void* context, nsITarget *target, - PRInt32 callerDepth); - -PRBool -EnablePrivilege(nsITarget * target, PRInt32 callerDepth); - -PRBool -EnablePrivilege(void * context, nsITarget * target, PRInt32 callerDepth); - -PRBool -EnablePrivilege(nsITarget * target, nsIPrincipal * preferredPrincipal, - PRInt32 callerDepth); - -PRBool -EnablePrivilege(void* context, nsITarget *target, nsIPrincipal * preferredPrincipal, - PRInt32 callerDepth); - -PRBool -RevertPrivilege(nsITarget * target, PRInt32 callerDepth); - -PRBool -RevertPrivilege(void* context, nsITarget *target, PRInt32 callerDepth); - -PRBool -DisablePrivilege(nsITarget *target, PRInt32 callerDepth); - -PRBool -DisablePrivilege(void * context, nsITarget *target, PRInt32 callerDepth); - -PRBool -EnablePrincipalPrivilegeHelper(nsITarget *target, PRInt32 callerDepth, - nsIPrincipal * preferredPrin, void * data, - nsITarget *impersonator); - -PRBool -EnablePrincipalPrivilegeHelper(void* context, nsITarget *target, - PRInt32 callerDepth, - nsIPrincipal * preferredPrin, - void * data, - nsITarget *impersonator); - -nsPrivilegeTable * -EnableScopePrivilegeHelper(nsITarget *target, - PRInt32 callerDepth, - void *data, - PRBool helpingSetScopePrivilege, - nsIPrincipal * prefPrin); - -nsPrivilegeTable * -EnableScopePrivilegeHelper(void* context, nsITarget *target, - PRInt32 callerDepth, void *data, - PRBool helpingSetScopePrivilege, - nsIPrincipal * prefPrin); - -PRBool -AskPermission(nsIPrincipal * useThisPrin, nsITarget* target, void* data); - -void -SetPermission(nsIPrincipal * useThisPrin, nsITarget * target, nsIPrivilege * newPrivilege); - void RegisterPrincipalAndSetPrivileges(nsIPrincipal * principal, nsITarget * target, nsIPrivilege * newPrivilege); -void -UpdatePrivilegeTable(nsITarget *target, nsPrivilegeTable * privTable, nsIPrivilege * newPrivilege); - -PRBool -CheckPrivilegeGranted(nsITarget *target, PRInt32 callerDepth); - -PRBool -CheckPrivilegeGranted(void* context, nsITarget *target, PRInt32 callerDepth); - -PRBool -CheckPrivilegeGranted(nsITarget * target, nsIPrincipal * principal, void *data); - -PRBool -CheckPrivilegeGranted(nsITarget * target, PRInt32 callerDepth, void * data); - -PRBool -CheckPrivilegeGranted(void * context, nsITarget * target, PRInt32 callerDepth, void * data); - -nsIPrivilege * -GetPrincipalPrivilege(nsITarget * target, nsIPrincipal * prin, void * data); - -static nsPrivilegeManager * -GetPrivilegeManager(void); - -static nsPrincipalArray * -GetMyPrincipals(PRInt32 callerDepth); - -static nsPrincipalArray * -GetMyPrincipals(void* context, PRInt32 callerDepth); - -static nsIPrincipal * -GetSystemPrincipal(void); - -static PRBool -HasSystemPrincipal(nsPrincipalArray * prinArray); - -static nsIPrincipal * -GetUnsignedPrincipal(void); - -static nsIPrincipal * -GetUnknownPrincipal(void); - -PRInt16 -ComparePrincipalArray(nsPrincipalArray * prin1Array, nsPrincipalArray * prin2Array); - -nsPrincipalArray * -IntersectPrincipalArray(nsPrincipalArray * pa1, nsPrincipalArray * pa2); - -PRBool -CanExtendTrust(nsPrincipalArray * pa1, nsPrincipalArray * pa2); - -PRBool -CheckMatchPrincipal(nsIPrincipal * principal, PRInt32 callerDepth); - -PRBool -CheckMatchPrincipal(void* context, nsIPrincipal * principal, PRInt32 callerDepth); - -/* Helper functions for ADMIN UI */ -const char * -GetAllPrincipalsString(void); - -nsIPrincipal * -GetPrincipalFromString(char *prinName); - -void -GetTargetsWithPrivileges(char *prinName, char** forever, char** session, char **denied); - -PRBool -RemovePrincipal(char *prinName); - -PRBool -RemovePrincipalsPrivilege(char *prinName, char *targetName); - -void -Remove(nsIPrincipal *prin, nsITarget *target); - -/* The following are old native methods */ -char * -CheckPrivilegeEnabled(nsTargetArray * targetArray, PRInt32 callerDepth, void *data); - -char * -CheckPrivilegeEnabled(void* context, nsTargetArray * targetArray, PRInt32 callerDepth, void *data); - -nsPrincipalArray * -GetClassPrincipalsFromStack(PRInt32 callerDepth); - -nsPrincipalArray * -GetClassPrincipalsFromStack(void* context, PRInt32 callerDepth); - -nsPrivilegeTable * -GetPrivilegeTableFromStack(PRInt32 callerDepth, PRBool createIfNull); - -nsPrivilegeTable * -GetPrivilegeTableFromStack(void* context, PRInt32 callerDepth, PRBool createIfNull); - /* End of native methods */ private: nsHashtable * itsPrinToPrivTable; nsHashtable * itsPrinToMacroTargetPrivTable; -nsHashtable * itsPrinNameToPrincipalTable; static PRBool theSecurityInited; @@ -251,18 +194,15 @@ static PRBool theInited; /* Private Methods */ -void -AddToPrincipalNameToPrincipalTable(nsIPrincipal * prin); - PRBool -EnablePrivilegePrivate(void* context, nsITarget *target, nsIPrincipal *preferredPrincipal, +EnablePrivilegePrivate(nsIScriptContext * context, nsITarget *target, nsIPrincipal *preferredPrincipal, PRInt32 callerDepth); PRInt16 -GetPrincipalPrivilege(nsITarget * target, nsPrincipalArray * callerPrinArray, void * data); +GetPrincipalPrivilege(nsITarget * target, nsIPrincipalArray * callerPrinArray, void * data); PRBool -IsPermissionGranted(nsITarget *target, nsPrincipalArray* callerPrinArray, void *data); +IsPermissionGranted(nsITarget *target, nsIPrincipalArray * callerPrinArray, void *data); /* The following methods are used to save and load the persistent store */ @@ -271,7 +211,6 @@ Save(nsIPrincipal * prin, nsITarget * target, nsIPrivilege * newPrivilege); void Load(void); - }; diff --git a/mozilla/caps/include/nsTarget.h b/mozilla/caps/include/nsTarget.h index 30950acece9..60e38e6df8a 100755 --- a/mozilla/caps/include/nsTarget.h +++ b/mozilla/caps/include/nsTarget.h @@ -22,6 +22,7 @@ #include "nsHashtable.h" #include "nsVector.h" #include "nsIPrincipal.h" +#include "nsIPrincipalArray.h" #include "nsIPrivilege.h" #include "nsITarget.h" #include "nsUserDialogHelper.h" @@ -81,7 +82,7 @@ public: nsIPrivilege * CheckPrivilegeEnabled(nsTargetArray * targetArray); - nsIPrivilege * CheckPrivilegeEnabled(nsIPrincipal *p, void * data); + nsIPrivilege * CheckPrivilegeEnabled(nsIPrincipal * p, void * data); NS_IMETHOD RegisterTarget(void * context, nsITarget * * target); diff --git a/mozilla/caps/macbuild/Caps.mcp b/mozilla/caps/macbuild/Caps.mcp index e355fbf59ac..9160c6b03fa 100644 Binary files a/mozilla/caps/macbuild/Caps.mcp and b/mozilla/caps/macbuild/Caps.mcp differ diff --git a/mozilla/caps/macbuild/CapsIDL.mcp b/mozilla/caps/macbuild/CapsIDL.mcp index c02304fb964..c19990344e8 100644 Binary files a/mozilla/caps/macbuild/CapsIDL.mcp and b/mozilla/caps/macbuild/CapsIDL.mcp differ diff --git a/mozilla/caps/makefile.win b/mozilla/caps/makefile.win index 0a545c414fc..f43543f717b 100644 --- a/mozilla/caps/makefile.win +++ b/mozilla/caps/makefile.win @@ -37,7 +37,7 @@ DEPTH=.. #// DIRS - There are subdirectories to process #// #//------------------------------------------------------------------------ -DIRS= idl public include src +DIRS= idl include src #//------------------------------------------------------------------------ #// diff --git a/mozilla/caps/src/Makefile.in b/mozilla/caps/src/Makefile.in index a34cc7729f6..ce42c416c12 100644 --- a/mozilla/caps/src/Makefile.in +++ b/mozilla/caps/src/Makefile.in @@ -34,6 +34,8 @@ CPPSRCS = \ nsCCapsManagerFactory.cpp \ nsCertificatePrincipal.cpp \ nsCodebasePrincipal.cpp \ + nsPrincipalArray.cpp \ + nsPrincipalManager.cpp \ nsPrivilege.cpp \ nsPrivilegeManager.cpp \ nsPrivilegeTable.cpp \ diff --git a/mozilla/caps/src/admin.cpp b/mozilla/caps/src/admin.cpp index 434552d5641..99b697314dc 100644 --- a/mozilla/caps/src/admin.cpp +++ b/mozilla/caps/src/admin.cpp @@ -23,6 +23,7 @@ #include "prlog.h" #include "admin.h" #include "nsPrivilegeManager.h" +#include "nsPrincipalManager.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ @@ -37,8 +38,7 @@ extern "C" { PR_PUBLIC_API(const char *) java_netscape_security_getPrincipals(const char *charSetName) { - nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::GetPrivilegeManager(); - const char *prins = nsPrivManager->GetAllPrincipalsString(); + const char * prins = nsPrincipalManager::GetPrincipalManager()->GetAllPrincipalsString(); PRBool test_admin_api = PR_FALSE; if (test_admin_api) { char *a1; @@ -52,26 +52,24 @@ java_netscape_security_getPrincipals(const char *charSetName) } PR_PUBLIC_API(PRBool) -java_netscape_security_removePrincipal(const char *charSetName, char *prinName) +java_netscape_security_removePrincipal(const char * charSetName, char * prinName) { - nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::GetPrivilegeManager(); - return nsPrivManager->RemovePrincipal(prinName); + return nsPrivilegeManager::GetPrivilegeManager()->RemovePrincipal(prinName); } PR_PUBLIC_API(void) -java_netscape_security_getPrivilegeDescs(const char *charSetName, char *prinName, - char** forever, char** session, char **denied) +java_netscape_security_getPrivilegeDescs(const char * charSetName, char * prinName, char * * forever, char * * session, char * * denied) { - nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::GetPrivilegeManager(); - nsPrivManager->GetTargetsWithPrivileges(prinName, forever, session, denied); + nsPrivilegeManager::GetPrivilegeManager()->GetTargetsWithPrivileges(prinName, forever, session, denied); } PR_PUBLIC_API(PRBool) -java_netscape_security_removePrivilege(const char *charSetName, char *prinName, - char *targetName) +java_netscape_security_removePrivilege(const char * charSetName, char * prinName, char * targetName) { - nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::GetPrivilegeManager(); - return nsPrivManager->RemovePrincipalsPrivilege(prinName, targetName); + PRBool result; + nsPrivilegeManager::GetPrivilegeManager()->RemovePrincipalsPrivilege(prinName, targetName,& result); + return result; + } diff --git a/mozilla/caps/src/makefile.win b/mozilla/caps/src/makefile.win index c10374f82cd..f41547cd8bd 100755 --- a/mozilla/caps/src/makefile.win +++ b/mozilla/caps/src/makefile.win @@ -61,6 +61,8 @@ CPP_OBJS= \ .\$(OBJDIR)\nsCCapsManagerFactory.obj \ .\$(OBJDIR)\nsCertificatePrincipal.obj \ .\$(OBJDIR)\nsCodebasePrincipal.obj \ + .\$(OBJDIR)\nsPrincipalArray.obj \ + .\$(OBJDIR)\nsPrincipalManager.obj \ .\$(OBJDIR)\nsPrivilege.obj \ .\$(OBJDIR)\nsPrivilegeManager.obj \ .\$(OBJDIR)\nsPrivilegeTable.obj \ diff --git a/mozilla/caps/src/nsCCapsManager.cpp b/mozilla/caps/src/nsCCapsManager.cpp index 59c97420ea2..7077c25b0e6 100644 --- a/mozilla/caps/src/nsCCapsManager.cpp +++ b/mozilla/caps/src/nsCCapsManager.cpp @@ -19,6 +19,7 @@ #include "nsCCapsManager.h" #include "nsCodebasePrincipal.h" #include "nsCertificatePrincipal.h" +#include "nsPrincipalArray.h" #include "nsCaps.h" #include "nsICapsSecurityCallbacks.h" #include "nsLoadZig.h" @@ -57,48 +58,33 @@ nsCCapsManager::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr) //////////////////////////////////////////////////////////////////////////// // from nsICapsManager: -NS_METHOD -nsCCapsManager::CreateCodebasePrincipal(const char *codebaseURL, - nsIPrincipal** prin) +NS_IMETHODIMP +nsCCapsManager::GetPrincipalManager(nsIPrincipalManager * * prinMan) { - nsresult result = NS_OK; - nsCodebasePrincipal *pNSCCodebasePrincipal = - new nsCodebasePrincipal((PRInt16 *)nsIPrincipal::PrincipalType_CodebaseExact, codebaseURL); - if (pNSCCodebasePrincipal == NULL) - { - return NS_ERROR_OUT_OF_MEMORY; - } - pNSCCodebasePrincipal->AddRef(); - *prin = (nsIPrincipal *)pNSCCodebasePrincipal; - return result; + * prinMan = principalManager; + return NS_OK; } -NS_METHOD -nsCCapsManager::CreateCertificatePrincipal(const unsigned char **certChain, - PRUint32 *certChainLengths, - PRUint32 noOfCerts, - nsIPrincipal** prin) +NS_IMETHODIMP +nsCCapsManager::GetPrivilegeManager(nsIPrivilegeManager * * privMan) { - nsresult result = NS_OK; - nsCertificatePrincipal *pNSCCertPrincipal = - new nsCertificatePrincipal((PRInt16 *)nsIPrincipal::PrincipalType_Certificate, - certChain, certChainLengths, noOfCerts, &result); - if (pNSCCertPrincipal == NULL) - { - return NS_ERROR_OUT_OF_MEMORY; - } - pNSCCertPrincipal->AddRef(); - *prin = (nsIPrincipal *)pNSCCertPrincipal; - return NS_OK; + * privMan = privilegeManager; + return NS_OK; +} + +NS_IMETHODIMP +nsCCapsManager::CreateCodebasePrincipal(const char * codebaseURL, nsIPrincipal * * prin) +{ + return nsPrincipalManager::GetPrincipalManager()->CreateCodebasePrincipal(codebaseURL, prin); +} + +NS_IMETHODIMP +nsCCapsManager::CreateCertificatePrincipal(const unsigned char **certChain, PRUint32 * certChainLengths, + PRUint32 noOfCerts, nsIPrincipal** prin) +{ + return nsPrincipalManager::GetPrincipalManager()->CreateCertificatePrincipal(certChain,certChainLengths,noOfCerts,prin); } -/** -* Returns the permission for given principal and target -* -* @param prin - is either certificate principal or codebase principal -* @param target - is NS_ALL_PRIVILEGES. -* @param state - the return value is passed in this parameter. -*/ NS_METHOD nsCCapsManager::GetPermission(nsIPrincipal * prin, nsITarget * ignoreTarget, PRInt16 * privilegeState) { @@ -107,24 +93,16 @@ nsCCapsManager::GetPermission(nsIPrincipal * prin, nsITarget * ignoreTarget, PRI nsresult result = NS_OK; if( target == NULL ) return NS_OK; if (privilegeManager != NULL) { - nsIPrivilege * privilege = privilegeManager->GetPrincipalPrivilege(target, prin, NULL); + nsIPrivilege * privilege; + privilegeManager->GetPrincipalPrivilege(target, prin, NULL, & privilege); // ARIEL WORK ON THIS SHIT // * privilegeState = this->ConvertPrivilegeToPermission(privilege); } return NS_OK; } -/** -* Set the permission state for given principal and target. This wouldn't -* prompt the end user with UI. -* -* @param prin - is either certificate principal or codebase principal -* @param target - is NS_ALL_PRIVILEGES. -* @param state - is permisson state that should be set for the given prin -* and target parameters. -*/ NS_METHOD -nsCCapsManager::SetPermission(nsIPrincipal * prin, nsITarget * ignoreTarget, PRInt16 * privilegeState) +nsCCapsManager::SetPermission(nsIPrincipal * prin, nsITarget * ignoreTarget, PRInt16 privilegeState) { nsITarget * target = nsTarget::FindTarget(ALL_JAVA_PERMISSION); if(target == NULL ) return NS_OK; @@ -136,26 +114,19 @@ nsCCapsManager::SetPermission(nsIPrincipal * prin, nsITarget * ignoreTarget, PRI return NS_OK; } -/** -* Prompts the user if they want to grant permission for the given principal and -* for the given target. -* -* @param prin - is either certificate principal or codebase principal -* @param target - is NS_ALL_PRIVILEGES. -* @param result - is the permission user has given for the given principal and -* target -*/ NS_METHOD nsCCapsManager::AskPermission(nsIPrincipal * prin, nsITarget * ignoreTarget, PRInt16 * privilegeState) { - nsITarget *target = nsTarget::FindTarget(ALL_JAVA_PERMISSION); + nsITarget * target = nsTarget::FindTarget(ALL_JAVA_PERMISSION); if( target == NULL ) { - * privilegeState = nsIPrivilege::PrivilegeState_Blank; - return NS_OK; + * privilegeState = nsIPrivilege::PrivilegeState_Blank; + return NS_OK; } if (privilegeManager != NULL) { - privilegeManager->AskPermission(prin, target, NULL); - nsIPrivilege * privilege = privilegeManager->GetPrincipalPrivilege(target, prin, NULL); + PRBool perm; + privilegeManager->AskPermission(prin, target, NULL, & perm); + nsIPrivilege * privilege; + privilegeManager->GetPrincipalPrivilege(target, prin, NULL,& privilege); // * privilegeState = ConvertPrivilegeToPermission(privilege); } return NS_OK; @@ -170,15 +141,10 @@ nsCCapsManager::AskPermission(nsIPrincipal * prin, nsITarget * ignoreTarget, PRI NS_METHOD nsCCapsManager::Initialize(PRBool * result) { - *result = nsCapsInitialize(); + * result = nsCapsInitialize(); return NS_OK; } -/** - * Initializes the capabilities frame walking code. - * - * @param aInterface - interface for calling frame walking code. - */ NS_METHOD nsCCapsManager::InitializeFrameWalker(nsICapsSecurityCallbacks* aInterface) { @@ -186,16 +152,10 @@ nsCCapsManager::InitializeFrameWalker(nsICapsSecurityCallbacks* aInterface) return NS_OK; } -/** - * Registers the given Principal with the system. - * - * @param prin - is either certificate principal or codebase principal - * @param result - is true if principal was successfully registered with the system - */ NS_METHOD nsCCapsManager::RegisterPrincipal(nsIPrincipal * prin) { - if (privilegeManager != NULL) privilegeManager->RegisterPrincipal(prin); +// if (principalManager != NULL) privilegeManager->RegisterPrincipal(prin); return NS_OK; } @@ -211,18 +171,18 @@ nsCCapsManager::RegisterPrincipal(nsIPrincipal * prin) * target */ NS_METHOD -nsCCapsManager::EnablePrivilege(void* context, const char* targetName, PRInt32 callerDepth, PRBool *ret_val) +nsCCapsManager::EnablePrivilege(nsIScriptContext * context, const char* targetName, PRInt32 callerDepth, PRBool * ret_val) { - nsITarget *target = nsTarget::FindTarget((char*)targetName); - nsresult result = NS_OK; - if( target == NULL ) - { - *ret_val = PR_FALSE; - return NS_OK; - } - if (privilegeManager != NULL) - *ret_val = privilegeManager->EnablePrivilege(context, target, callerDepth); - return NS_OK; + nsITarget *target = nsTarget::FindTarget((char*)targetName); + nsresult result = NS_OK; + if( target == NULL ) + { + * ret_val = PR_FALSE; + return NS_OK; + } +// if (privilegeManager != NULL) +// ret_val = privilegeManager->EnablePrivilege(context, target, NULL, callerDepth, ret_val); + return NS_OK; } /** @@ -237,35 +197,22 @@ nsCCapsManager::EnablePrivilege(void* context, const char* targetName, PRInt32 c * target */ NS_METHOD -nsCCapsManager::IsPrivilegeEnabled(void* context, const char* targetName, PRInt32 callerDepth, PRBool *ret_val) +nsCCapsManager::IsPrivilegeEnabled(nsIScriptContext * context, const char* targetName, PRInt32 callerDepth, PRBool *ret_val) { - nsITarget *target = nsTarget::FindTarget((char*)targetName); - nsresult result = NS_OK; - if( target == NULL ) - { - *ret_val = PR_FALSE; - return NS_OK; - } - if (privilegeManager != NULL) - { - *ret_val = privilegeManager->IsPrivilegeEnabled(context, target, callerDepth); - } - return NS_OK; + nsITarget *target = nsTarget::FindTarget((char*)targetName); + nsresult result = NS_OK; + if( target == NULL ) + { + * ret_val = PR_FALSE; + return NS_OK; + } + if (privilegeManager != NULL) + privilegeManager->IsPrivilegeEnabled(context, target, callerDepth, ret_val); + return NS_OK; } -/** - * Reverts the permission (granted/denied) user gave for the principal located - * at the given stack depth for the given target. - * - * @param context - is the parameter JS needs to determinte the principal - * @param targetName - is the name of the target. - * @param callerDepth - is the depth of JS stack frame, which JS uses to determinte the - * principal - * @param ret_val - is true if user has given permission for the given principal and - * target - */ NS_METHOD -nsCCapsManager::RevertPrivilege(void* context, const char* targetName, PRInt32 callerDepth, PRBool *ret_val) +nsCCapsManager::RevertPrivilege(nsIScriptContext * context, const char* targetName, PRInt32 callerDepth, PRBool *ret_val) { nsITarget *target = nsTarget::FindTarget((char*)targetName); nsresult result = NS_OK; @@ -274,23 +221,12 @@ nsCCapsManager::RevertPrivilege(void* context, const char* targetName, PRInt32 c return NS_OK; } if (privilegeManager != NULL) - * ret_val = privilegeManager->RevertPrivilege(context, target, callerDepth); + privilegeManager->RevertPrivilege(context, target, callerDepth,ret_val); return NS_OK; } -/** - * Disable permissions for the principal located at the given stack depth for the - * given target. - * - * @param context - is the parameter JS needs to determinte the principal - * @param targetName - is the name of the target. - * @param callerDepth - is the depth of JS stack frame, which JS uses to determinte the - * principal - * @param ret_val - is true if user has given permission for the given principal and - * target - */ NS_METHOD -nsCCapsManager::DisablePrivilege(void* context, const char* targetName, PRInt32 callerDepth, PRBool *ret_val) +nsCCapsManager::DisablePrivilege(nsIScriptContext * context, const char* targetName, PRInt32 callerDepth, PRBool *ret_val) { nsITarget *target = nsTarget::FindTarget((char*)targetName); nsresult result = NS_OK; @@ -299,72 +235,10 @@ nsCCapsManager::DisablePrivilege(void* context, const char* targetName, PRInt32 return NS_OK; } if (privilegeManager != NULL) - * ret_val = privilegeManager->DisablePrivilege(context, target, callerDepth); + privilegeManager->DisablePrivilege(context, target, callerDepth,ret_val); return NS_OK; } -/* XXX: Some of the arguments for the following interfaces may change. - * This is a first cut. I need to talk to joki. We should get rid of void* parameters. - */ -NS_METHOD -nsCCapsManager::ComparePrincipalArray(void* prin1Array, void* prin2Array, PRInt16 * comparisonType) -{ - nsresult result = NS_OK; - * comparisonType = nsPrivilegeManager::SetComparisonType_NoSubset; - if (privilegeManager != NULL) { - nsPrincipalArray * newPrin1Array=NULL; - nsPrincipalArray * newPrin2Array=NULL; - result = GetNSPrincipalArray((nsPrincipalArray*) prin1Array, &newPrin1Array); - if (result != NS_OK) return result; - result = GetNSPrincipalArray((nsPrincipalArray*) prin2Array, &newPrin2Array); - if (result != NS_OK) return result; - * comparisonType = privilegeManager->ComparePrincipalArray(newPrin1Array, newPrin2Array); - nsCapsFreePrincipalArray(newPrin1Array); - nsCapsFreePrincipalArray(newPrin2Array); - } - return NS_OK; -} - -NS_METHOD -nsCCapsManager::IntersectPrincipalArray(void * prin1Array, void * prin2Array, void * * ret_val) -{ - nsresult result = NS_OK; - *ret_val = NULL; - if (privilegeManager != NULL) { - nsPrincipalArray *newPrin1Array=NULL; - nsPrincipalArray *newPrin2Array=NULL; - nsPrincipalArray *intersectPrinArray=NULL; - result = this->GetNSPrincipalArray((nsPrincipalArray*) prin1Array, &newPrin1Array); - if (result != NS_OK) return result; - result = this->GetNSPrincipalArray((nsPrincipalArray*) prin2Array, &newPrin2Array); - if (result != NS_OK) return result; - intersectPrinArray = privilegeManager->IntersectPrincipalArray(newPrin1Array, newPrin2Array); - this->CreateNSPrincipalArray(intersectPrinArray, (nsPrincipalArray**)ret_val); - nsCapsFreePrincipalArray(newPrin1Array); - nsCapsFreePrincipalArray(newPrin2Array); - } - return NS_OK; -} - -NS_METHOD -nsCCapsManager::CanExtendTrust(void * fromPrinArray, void * toPrinArray, PRBool * ret_val) -{ - nsresult result = NS_OK; - if (privilegeManager != NULL) { - nsPrincipalArray *newPrin1Array=NULL; - nsPrincipalArray *newPrin2Array=NULL; - result = this->GetNSPrincipalArray((nsPrincipalArray*) fromPrinArray, &newPrin1Array); - if (result != NS_OK) return result; - result = this->GetNSPrincipalArray((nsPrincipalArray*) toPrinArray, &newPrin2Array); - if (result != NS_OK) return result; - *ret_val = privilegeManager->CanExtendTrust(newPrin1Array, newPrin2Array); - nsCapsFreePrincipalArray(newPrin1Array); - nsCapsFreePrincipalArray(newPrin2Array); - } - return NS_OK; -} - - /* interfaces for nsIPrincipal object, may be we should move some of them to nsIprincipal */ /************** //Principals must be created by type, the nsPrincipal data member is deprecated @@ -386,21 +260,15 @@ nsCCapsManager::NewPrincipal(PRInt16 *principalType, void* key, PRUint32 key_len //XXX: nsPrincipal struct if deprecated, access as nsIPrincipal //do not use IsCodebaseExact, Tostring, or any other of the principal specific objects from here -NS_METHOD -nsCCapsManager::NewPrincipalArray(PRUint32 count, void* *ret_val) -{ - *ret_val = nsCapsNewPrincipalArray(count); - return NS_OK; -} - /* * CreateMixedPrincipalArray take codebase and ZIG file information and returns a * pointer to an array of nsIPrincipal objects. + */ + /* NS_METHOD -nsCCapsManager::CreateMixedPrincipalArray(void *aZig, char* name, const char* codebase, void** result) +nsCCapsManager::CreateMixedPrincipalArray(void *aZig, const char * name, const char* codebase, nsIPrincipalArray * * result) { - /* *result = NULL; PRBool hasCodebase; int i; @@ -443,58 +311,18 @@ nsCCapsManager::CreateMixedPrincipalArray(void *aZig, char* name, const char* co RegisterPrincipal(principal, NULL); SetPrincipalArrayElement(*result, i++, principal); } - */ return NS_OK; } - -NS_METHOD -nsCCapsManager::FreePrincipalArray(void *prinArray) -{ - nsCapsFreePrincipalArray(prinArray); - return NS_OK; -} - -NS_METHOD -nsCCapsManager::GetPrincipalArrayElement(void *prinArrayArg, PRUint32 index, nsIPrincipal* *ret_val) -{ - //method is deprecated, Principals must be accessed and indexed as nsIPrincipals, not by data member - /* - nsIPrincipal* pNSIPrincipal; - nsPrincipal *pNSPrincipal = (nsPrincipal *)nsCapsGetPrincipalArrayElement(prinArrayArg, index); - (pNSPrincipal->isCodebase()) ? - pNSIPrincipal = (nsIPrincipal*)new nsCodebasePrincipal(pNSPrincipal) - : - pNSIPrincipal = (nsIPrincipal*)new nsCertificatePrincipal(pNSPrincipal); - } - - *ret_val = pNSIPrincipal; - */ - *ret_val = NULL; - return NS_OK; -} - -NS_METHOD -nsCCapsManager::SetPrincipalArrayElement(void *prinArrayArg, PRUint32 index, nsIPrincipal* principal) -{ - nsCapsSetPrincipalArrayElement(prinArrayArg, index, principal); - return NS_OK; -} - -NS_METHOD -nsCCapsManager::GetPrincipalArraySize(void *prinArrayArg, PRUint32 *ret_val) -{ - *ret_val = nsCapsGetPrincipalArraySize(prinArrayArg); - return NS_OK; -} +*/ /* The following interfaces will replace all of the following old calls. * nsCapsGetPermission(struct nsPrivilege *privilege) * nsCapsGetPrivilege(struct nsPrivilegeTable *annotation, struct nsITarget *target) */ NS_METHOD -nsCCapsManager::IsAllowed(void *annotation, char* targetName, PRBool *ret_val) +nsCCapsManager::IsAllowed(void *annotation, const char * targetName, PRBool * ret_val) { - nsITarget *target = nsTarget::FindTarget(targetName); + nsITarget *target = nsTarget::FindTarget((char *)targetName); nsresult result = NS_OK; if( target == NULL ) { *ret_val = PR_FALSE; @@ -511,15 +339,11 @@ nsCCapsManager::IsAllowed(void *annotation, char* targetName, PRBool *ret_val) return NS_OK; } - -//////////////////////////////////////////////////////////////////////////// -// from nsCCapsManager: - -nsCCapsManager::nsCCapsManager(nsISupports *aOuter):privilegeManager(NULL) +nsCCapsManager::nsCCapsManager(nsISupports * aOuter):privilegeManager(NULL) { NS_INIT_AGGREGATED(aOuter); - PRBool result; - privilegeManager = (Initialize(&result) == NS_OK) ? new nsPrivilegeManager(): NULL; +// PRBool result; +// privilegeManager = (Initialize(& result) == NS_OK) ? new nsPrivilegeManager(): NULL; } nsCCapsManager::~nsCCapsManager() @@ -527,8 +351,8 @@ nsCCapsManager::~nsCCapsManager() } void -nsCCapsManager::CreateNSPrincipalArray(nsPrincipalArray* prinArray, - nsPrincipalArray* *pPrincipalArray) +nsCCapsManager::CreateNSPrincipalArray(nsIPrincipalArray* prinArray, + nsIPrincipalArray* *pPrincipalArray) { //prin arrays will either be removed, or updated to use the nsIPrincipal Object /* @@ -552,11 +376,13 @@ nsCCapsManager::CreateNSPrincipalArray(nsPrincipalArray* prinArray, *pPrincipalArray = newPrinArray; */ } +/* NS_METHOD nsCCapsManager::GetNSPrincipalArray(nsPrincipalArray* prinArray, nsPrincipalArray* *pPrincipalArray) { -/* + + nsIPrincipal* pNSIPrincipal; nsIPrincipal *pNSPrincipal = NULL; nsresult result = NS_OK; @@ -577,9 +403,9 @@ nsCCapsManager::GetNSPrincipalArray(nsPrincipalArray* prinArray, } *pPrincipalArray = newPrinArray; return result; - */ return NS_OK; } +*/ /* NS_METHOD nsCCapsManager::GetNSPrincipal(nsIPrincipal* pNSIPrincipal, nsPrincipal **ppNSPrincipal) @@ -705,9 +531,19 @@ nsCCapsManager::ConvertPermissionToPrivilege(nsPermission state) void nsCCapsManager::SetSystemPrivilegeManager() { - nsPrivilegeManager *pNSPrivilegeManager = nsPrivilegeManager::GetPrivilegeManager(); + nsIPrivilegeManager * pNSPrivilegeManager = (nsIPrivilegeManager *)nsPrivilegeManager::GetPrivilegeManager(); if ((privilegeManager != NULL ) && (privilegeManager != pNSPrivilegeManager)) { delete privilegeManager; privilegeManager = pNSPrivilegeManager; } } + +void +nsCCapsManager::SetSystemPrincipalManager() +{ + nsIPrincipalManager * prinMan = (nsIPrincipalManager *)nsPrincipalManager::GetPrincipalManager(); + if ((principalManager != NULL ) && (principalManager != prinMan)) { + delete principalManager; + principalManager = prinMan; + } +} \ No newline at end of file diff --git a/mozilla/caps/src/nsCaps.cpp b/mozilla/caps/src/nsCaps.cpp index 66a65046a6d..78b3487fdfa 100644 --- a/mozilla/caps/src/nsCaps.cpp +++ b/mozilla/caps/src/nsCaps.cpp @@ -22,6 +22,7 @@ #include "prmon.h" #include "prlog.h" #include "nsCaps.h" +#include "nsPrincipalManager.h" #include "nsPrivilegeManager.h" #include "nsIPrincipal.h" #include "nsCertificatePrincipal.h" @@ -66,11 +67,11 @@ nsCapsInitialize() // sysPrin = CreateSystemPrincipal("java40.jar", "java/lang/Object.class"); #endif */ - if (sysPrin == NULL) { - nsresult res; - sysPrin = new nsCertificatePrincipal((PRInt16 *)nsIPrincipal::PrincipalType_Certificate,(const unsigned char **) "52:54:45:4e:4e:45:54:49", - (unsigned int *)strlen("52:54:45:4e:4e:45:54:49"),1,& res); - } +// if (sysPrin == NULL) { +// nsresult res; +// sysPrin = new nsCertificatePrincipal((PRInt16 *)nsIPrincipal::PrincipalType_Certificate,(const unsigned char **) "52:54:45:4e:4e:45:54:49", +// (unsigned int *)strlen("52:54:45:4e:4e:45:54:49"),1,& res); +// } nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::GetPrivilegeManager(); if (nsPrivManager == NULL) { nsPrivilegeManagerInitialize(); @@ -107,61 +108,78 @@ nsCapsRegisterPrincipal(class nsIPrincipal *principal) PR_IMPLEMENT(PRBool) nsCapsEnablePrivilege(void * context, class nsITarget * target, PRInt32 callerDepth) { - nsPrivilegeManager * nsPrivManager = nsPrivilegeManager::GetPrivilegeManager(); - return (nsPrivManager == NULL) ? PR_FALSE : nsPrivManager->EnablePrivilege(context, target, callerDepth); + if (nsPrivilegeManager::GetPrivilegeManager() == NULL) return PR_FALSE; + else { + PRBool result; + nsPrivilegeManager::GetPrivilegeManager()->EnablePrivilege((nsIScriptContext *)context, target, NULL, callerDepth,& result); + return result; + } } PR_IMPLEMENT(PRBool) nsCapsIsPrivilegeEnabled(void* context, class nsITarget *target, PRInt32 callerDepth) { - nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::GetPrivilegeManager(); - return (nsPrivManager == NULL) ? PR_FALSE : nsPrivManager->IsPrivilegeEnabled(context, target, callerDepth); + if (nsPrivilegeManager::GetPrivilegeManager() == NULL) return PR_FALSE; + else { + PRBool result; + nsPrivilegeManager::GetPrivilegeManager()->IsPrivilegeEnabled((nsIScriptContext *)context, target, callerDepth,& result); + return result; + } } PR_IMPLEMENT(PRBool) nsCapsRevertPrivilege(void* context, class nsITarget * target, PRInt32 callerDepth) { - nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::GetPrivilegeManager(); - return (nsPrivManager == NULL ) ? PR_FALSE : nsPrivManager->RevertPrivilege(context, target, callerDepth); + if (nsPrivilegeManager::GetPrivilegeManager() == NULL ) return PR_FALSE; + else { + PRBool result; + nsPrivilegeManager::GetPrivilegeManager()->RevertPrivilege((nsIScriptContext *)context, target, callerDepth,& result); + return result; + } } PR_IMPLEMENT(PRBool) nsCapsDisablePrivilege(void* context, class nsITarget * target, PRInt32 callerDepth) { - nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::GetPrivilegeManager(); - return (nsPrivManager == NULL) ? PR_FALSE : nsPrivManager->DisablePrivilege(context, target, callerDepth); + if (nsPrivilegeManager::GetPrivilegeManager() == NULL) return PR_FALSE; + else { + PRBool result; + nsPrivilegeManager::GetPrivilegeManager()->DisablePrivilege((nsIScriptContext *)context, target, callerDepth,& result); + return result; + } } PR_IMPLEMENT(void*) nsCapsGetClassPrincipalsFromStack(void* context, PRInt32 callerDepth) { - nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::GetPrivilegeManager(); - return (nsPrivManager == NULL) ? NULL - : (void *)nsPrivManager->GetClassPrincipalsFromStack(context, callerDepth); + nsPrincipalManager * nsPrinManager = nsPrincipalManager::GetPrincipalManager(); + return (nsPrinManager == NULL) ? NULL + : (void *)nsPrinManager->GetClassPrincipalsFromStack((nsIScriptContext *)context, callerDepth); } -PR_IMPLEMENT(PRInt16) -nsCapsComparePrincipalArray(void * prin1Array, void * prin2Array) -{ - nsPrivilegeManager * nsPrivManager = nsPrivilegeManager::GetPrivilegeManager(); - return (nsPrivManager == NULL) ? nsPrivilegeManager::SetComparisonType_NoSubset - : nsPrivManager->ComparePrincipalArray((nsPrincipalArray*)prin1Array, (nsPrincipalArray*)prin2Array); -} +//PR_IMPLEMENT(PRInt16) +//nsCapsComparePrincipalArray(void * prin1Array, void * prin2Array) +//{ +// nsPrivilegeManager * nsPrivManager = nsPrivilegeManager::GetPrivilegeManager(); +// return (nsPrivManager == NULL) ? nsPrivilegeManager::SetComparisonType_NoSubset +// : nsPrivManager->ComparePrincipalArray((nsPrincipalArray*)prin1Array, (nsPrincipalArray*)prin2Array); +//} -PR_IMPLEMENT(void*) -nsCapsIntersectPrincipalArray(void* prin1Array, void* prin2Array) -{ - nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::GetPrivilegeManager(); - return (nsPrivManager == NULL) ? NULL - : nsPrivManager->IntersectPrincipalArray((nsPrincipalArray*)prin1Array, (nsPrincipalArray*)prin2Array); -} +//PR_IMPLEMENT(void*) +//nsCapsIntersectPrincipalArray(void* prin1Array, void* prin2Array) +//{ +// nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::GetPrivilegeManager(); +// return (nsPrivManager == NULL) ? NULL +// : nsPrivManager->IntersectPrincipalArray((nsPrincipalArray*)prin1Array, (nsPrincipalArray*)prin2Array); +//} PR_IMPLEMENT(PRBool) nsCapsCanExtendTrust(void* from, void* to) { - nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::GetPrivilegeManager(); - return (nsPrivManager == NULL) ? PR_FALSE - : nsPrivManager->CanExtendTrust((nsPrincipalArray *)from, (nsPrincipalArray *)to); + nsPrincipalManager * nsPrinManager = nsPrincipalManager::GetPrincipalManager(); + PRBool result = PR_FALSE; + if (nsPrinManager != NULL) nsPrinManager->CanExtendTrust((nsIPrincipalArray *)from, (nsIPrincipalArray *)to,& result); + return result; } /* wrappers for nsPrincipal object */ @@ -200,46 +218,6 @@ nsCapsPrincipalGetVendor(class nsIPrincipal *principal) return NULL; } */ -PR_EXTERN(void *) -nsCapsNewPrincipalArray(PRUint32 count) -{ - nsPrincipalArray *prinArray = new nsPrincipalArray(); - prinArray->SetSize(count, 1); - return prinArray; -} - -PR_EXTERN(void) -nsCapsFreePrincipalArray(void *prinArrayArg) -{ - nsPrincipalArray *prinArray = (nsPrincipalArray *)prinArrayArg; - if (prinArray) { - prinArray->RemoveAll(); - delete prinArray; - } -} - -PR_EXTERN(void *) -nsCapsGetPrincipalArrayElement(void *prinArrayArg, PRUint32 index) -{ - nsPrincipalArray *prinArray = (nsPrincipalArray *)prinArrayArg; - return (prinArray == NULL) ? NULL : prinArray->Get(index); -} - -PR_EXTERN(void) -nsCapsSetPrincipalArrayElement(void *prinArrayArg, PRUint32 index, void *element) -{ - nsPrincipalArray *prinArray = (nsPrincipalArray *)prinArrayArg; - if (prinArray == NULL) return; - prinArray->Set(index, element); -} - -PR_EXTERN(PRUint32) -nsCapsGetPrincipalArraySize(void *prinArrayArg) -{ - nsPrincipalArray *prinArray = (nsPrincipalArray *)prinArrayArg; - return (prinArray == NULL) ? 0 : prinArray->GetSize(); -} - /* wrappers for nsTarget object */ PR_IMPLEMENT(class nsITarget *) nsCapsFindTarget(char * name) diff --git a/mozilla/caps/src/nsCertificatePrincipal.cpp b/mozilla/caps/src/nsCertificatePrincipal.cpp index 0478294053a..67ad7bfc64a 100644 --- a/mozilla/caps/src/nsCertificatePrincipal.cpp +++ b/mozilla/caps/src/nsCertificatePrincipal.cpp @@ -23,10 +23,9 @@ static NS_DEFINE_IID(kICertificatePrincipalIID, NS_ICERTIFICATEPRINCIPAL_IID); NS_IMPL_ISUPPORTS(nsCertificatePrincipal, kICertificatePrincipalIID); NS_IMETHODIMP -nsCertificatePrincipal::GetPublicKey(char ** publicKey, PRUint32 * publicKeyLength) +nsCertificatePrincipal::GetPublicKey(char ** publicKey) { - publicKey = & this->itsKey; - publicKeyLength = & this->itsKeyLength; + * publicKey = (char *)this->itsKey; return (itsKey == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; } @@ -98,10 +97,16 @@ nsCertificatePrincipal::Equals(nsIPrincipal * other, PRBool * result) return NS_OK; } -nsCertificatePrincipal::nsCertificatePrincipal(PRInt16 * type, const unsigned char **certChain, - PRUint32 *certChainLengths, PRUint32 noOfCerts, nsresult *result) +nsCertificatePrincipal::nsCertificatePrincipal(PRInt16 type, const char * key) { - this->itsType = * type; + this->itsType = type; + this->itsKey = key; +} + +nsCertificatePrincipal::nsCertificatePrincipal(PRInt16 type, const unsigned char **certChain, + PRUint32 *certChainLengths, PRUint32 noOfCerts) +{ + this->itsType = type; /* m_pNSPrincipal = new nsPrincipal(nsPrincipalType_CertChain, certChain, certChainLengths, noOfCerts); diff --git a/mozilla/caps/src/nsCodebasePrincipal.cpp b/mozilla/caps/src/nsCodebasePrincipal.cpp index 42046c98213..8ebb2ff3305 100644 --- a/mozilla/caps/src/nsCodebasePrincipal.cpp +++ b/mozilla/caps/src/nsCodebasePrincipal.cpp @@ -26,28 +26,28 @@ NS_IMPL_ISUPPORTS(nsCodebasePrincipal, kICodebasePrincipalIID); NS_IMETHODIMP nsCodebasePrincipal::GetURL(char **cburl) { - cburl = (char **)&codeBaseURL; + * cburl = (char *)itsCodeBaseURL; return NS_OK; } NS_IMETHODIMP nsCodebasePrincipal::IsCodebaseExact(PRBool * result) { - * result = (this->itsType == (PRInt16 *)nsIPrincipal::PrincipalType_CodebaseExact) ? PR_TRUE : PR_FALSE; + * result = (this->itsType == nsIPrincipal::PrincipalType_CodebaseExact) ? PR_TRUE : PR_FALSE; return NS_OK; } NS_IMETHODIMP nsCodebasePrincipal::IsCodebaseRegex(PRBool * result) { - * result = (itsType == (PRInt16 *)nsIPrincipal::PrincipalType_CodebaseRegex) ? PR_TRUE : PR_FALSE; + * result = (itsType == nsIPrincipal::PrincipalType_CodebaseRegex) ? PR_TRUE : PR_FALSE; return NS_OK; } NS_IMETHODIMP nsCodebasePrincipal::GetType(PRInt16 * type) { - type = itsType; + * type = itsType; return NS_OK; } @@ -63,7 +63,7 @@ nsCodebasePrincipal::IsSecure(PRBool * result) } NS_IMETHODIMP -nsCodebasePrincipal::ToString(char **result) +nsCodebasePrincipal::ToString(char * * result) { return NS_OK; } @@ -78,15 +78,23 @@ nsCodebasePrincipal::HashCode(PRUint32 * code) NS_IMETHODIMP nsCodebasePrincipal::Equals(nsIPrincipal * other, PRBool * result) { - PRInt16 * oType = 0; - other->GetType(oType); - *result = (itsType == oType) ? PR_TRUE : PR_FALSE; + PRInt16 oType = 0; +// char ** oCodeBase; + other->GetType(& oType); + * result = (itsType == oType) ? PR_TRUE : PR_FALSE; +//XXXariel fix this +// if (* result) { +// nsICodebasePrincipal * cbother = (nsCodebasePrincipal)other; +// cbother->GetURL(& oCodeBase); +// } +// * result = (itsCodebase == oCodeBase) ? PR_TRUE : PR_FALSE; return NS_OK; } -nsCodebasePrincipal::nsCodebasePrincipal(PRInt16 * type, const char * codeBaseURL) + +nsCodebasePrincipal::nsCodebasePrincipal(PRInt16 type, const char * codeBaseURL) { - this->itsType=type; - this->codeBaseURL=codeBaseURL; + this->itsType = type; + this->itsCodeBaseURL = codeBaseURL; } nsCodebasePrincipal::~nsCodebasePrincipal(void) diff --git a/mozilla/caps/src/nsPrincipalArray.cpp b/mozilla/caps/src/nsPrincipalArray.cpp new file mode 100644 index 00000000000..670ef45febe --- /dev/null +++ b/mozilla/caps/src/nsPrincipalArray.cpp @@ -0,0 +1,141 @@ +#include "nsPrincipalArray.h" + +static NS_DEFINE_IID(kIPrincipalArrayIID, NS_IPRINCIPALARRAY_IID); + +NS_IMPL_ISUPPORTS(nsPrincipalArray, kIPrincipalArrayIID); +nsPrincipalArray::nsPrincipalArray(void) +{ + nsPrincipalArray(0); +} + +nsPrincipalArray::nsPrincipalArray(PRUint32 count) +{ + nsVector * itsArray = new nsVector(); + itsArray->SetSize(count, 1); +} +nsPrincipalArray::~nsPrincipalArray(void) +{ + this->FreePrincipalArray(); +} + +NS_IMETHODIMP +nsPrincipalArray::SetPrincipalArrayElement(PRUint32 index, nsIPrincipal * principal) +{ + if (itsArray != NULL) this->itsArray->Set(index, principal); + return NS_OK; +} + +NS_IMETHODIMP +nsPrincipalArray::GetPrincipalArraySize(PRUint32 * size) +{ + * size = (itsArray == NULL) ? 0 : itsArray->GetSize(); + return NS_OK; +} + +NS_IMETHODIMP +nsPrincipalArray::FreePrincipalArray() +{ + if (itsArray) { + itsArray->RemoveAll(); + delete itsArray; + } + return NS_OK; +} + +NS_IMETHODIMP +nsPrincipalArray::AddPrincipalArrayElement(nsIPrincipal * principal) +{ + if(!itsArray) itsArray = new nsVector(); + itsArray->Add(principal); + return NS_OK; +} + +NS_IMETHODIMP +nsPrincipalArray::GetPrincipalArrayElement(PRUint32 index, nsIPrincipal * * result) +{ + * result = (itsArray == NULL) ? NULL : (nsIPrincipal *) itsArray->Get(index); + return NS_OK; +} + +NS_IMETHODIMP +nsPrincipalArray::ComparePrincipalArray(nsIPrincipalArray * other, PRInt16 * comparisonType) +{ + nsHashtable * p2Hashtable = new nsHashtable(); + PRBool value; + nsIPrincipal * prin; + PRUint32 i; + other->GetPrincipalArraySize(& i); + for (i; i-- > 0;) { + other->GetPrincipalArrayElement(i,& prin); + PrincipalKey prinKey(prin); + p2Hashtable->Put(& prinKey, (void *)PR_TRUE); + } + this->GetPrincipalArraySize(& i); + for (i; i-- > 0;) { + this->GetPrincipalArrayElement(i,& prin); + PrincipalKey prinKey(prin); + value = (PRBool)p2Hashtable->Get(&prinKey); + if (!value) + { + * comparisonType = nsPrincipalArray::SetComparisonType_NoSubset; + return NS_OK; + } + if (value == PR_TRUE) p2Hashtable->Put(&prinKey, (void *)PR_FALSE); + } + other->GetPrincipalArraySize(& i); + for (i; i-- > 0;) { + other->GetPrincipalArrayElement(i,& prin); + PrincipalKey prinKey(prin); + value = (PRBool)p2Hashtable->Get(&prinKey); + if (value == PR_TRUE) + { + * comparisonType = nsPrincipalArray::SetComparisonType_ProperSubset; + return NS_OK; + } + } + * comparisonType = nsPrincipalArray::SetComparisonType_Equal; + return NS_OK; +} + +NS_METHOD +nsPrincipalArray::IntersectPrincipalArray(nsIPrincipalArray * other, nsIPrincipalArray * * result) +{ + PRUint32 thisLength = 0, otherLength = 0; + this->GetPrincipalArraySize(& thisLength); + other->GetPrincipalArraySize(& otherLength); + nsVector * in = new nsVector(); + PRUint32 count = 0; + nsIPrincipal * prin1, * prin2; + PRUint32 i = 0, j=0; + in->SetSize(thisLength, 1); + PRUint32 inLength = in->GetSize(); + for (i=0; i < thisLength; i++) { + for (j=0; j < otherLength; j++) { + this->GetPrincipalArrayElement(i,& prin1); + other->GetPrincipalArrayElement(j,& prin2); + PRBool eq; + prin1->Equals(prin2, & eq); + if (eq) { + in->Set(i, (void *)PR_TRUE); + count++; + break; + } else { + in->Set(i, (void *)PR_FALSE); + } + } + } + * result = new nsPrincipalArray(count); + PRBool doesIntersect; + PR_ASSERT(inLength == thisLength); + PR_ASSERT(inLength == inLength); + for (i=0; i < inLength; i++) { + doesIntersect = (PRBool)in->Get(i); + if (doesIntersect) { + PR_ASSERT(j < count); + this->GetPrincipalArrayElement(i,& prin1); + (* result)->SetPrincipalArrayElement(j, prin1); + j++; + } + } + return NS_OK; +} \ No newline at end of file diff --git a/mozilla/caps/src/nsPrincipalManager.cpp b/mozilla/caps/src/nsPrincipalManager.cpp new file mode 100644 index 00000000000..c69b9b6da6a --- /dev/null +++ b/mozilla/caps/src/nsPrincipalManager.cpp @@ -0,0 +1,316 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "prmem.h" +#include "prmon.h" +#include "prlog.h" +#include "prprf.h" +#include "plbase64.h" +#include "plstr.h" +#include "nsPrincipalManager.h" +#include "nsPrincipalArray.h" +#include "nsCaps.h" +#include "nsCertificatePrincipal.h" +#include "nsCodebasePrincipal.h" + +#define UNSIGNED_PRINCIPAL_KEY "4a:52:4f:53:4b:49:4e:44" +#define UNKNOWN_PRINCIPAL_KEY "52:4f:53:4b:49:4e:44:4a" + +static nsIPrincipal * theSystemPrincipal = NULL; +static nsIPrincipal * theUnsignedPrincipal = NULL; +static nsIPrincipal * theUnknownPrincipal = NULL; +static nsIPrincipalArray * theUnknownPrincipalArray = NULL; +static nsIPrincipalArray * theUnsignedPrincipalArray = NULL; +char * gListOfPrincipals; + + +static PRBool GetPrincipalString(nsHashKey * aKey, void * aData, void * closure); +static nsPrincipalManager * thePrincipalManager = NULL; + +static NS_DEFINE_IID(kIPrincipalManagerIID, NS_IPRINCIPALMANAGER_IID); + +NS_IMPL_ISUPPORTS(nsPrincipalManager, kIPrincipalManagerIID); + +nsIPrincipal * +nsPrincipalManager::GetSystemPrincipal(void) +{ + return theSystemPrincipal; +} +nsIPrincipal * +nsPrincipalManager::GetUnsignedPrincipal(void) +{ + return theUnsignedPrincipal; +} + +nsIPrincipal * +nsPrincipalManager::GetUnknownPrincipal(void) +{ + return theUnknownPrincipal; +} + +PRBool +nsPrincipalManager::HasSystemPrincipal(nsIPrincipalArray * prinArray) +{ + nsIPrincipal * sysPrin = nsPrincipalManager::GetSystemPrincipal(); + nsIPrincipal * prin; + if (sysPrin == NULL) return PR_FALSE; + PRUint32 i; + prinArray->GetPrincipalArraySize(& i); + for (i; i-- > 0;) { + prinArray->GetPrincipalArrayElement(i,& prin); + PRBool result; + sysPrin->Equals(prin, & result); + if (result) return PR_TRUE; + } + return PR_FALSE; +} + +NS_IMETHODIMP +nsPrincipalManager::CreateCodebasePrincipal(const char * codebaseURL, nsIPrincipal * * prin) { + * prin = new nsCodebasePrincipal(nsIPrincipal::PrincipalType_CodebaseExact, codebaseURL); + if (prin == NULL) return NS_ERROR_OUT_OF_MEMORY; + (* prin)->AddRef(); + return NS_OK; +} + +NS_IMETHODIMP +nsPrincipalManager::CreateCertificatePrincipal(const unsigned char * * certChain, PRUint32 * certChainLengths, PRUint32 noOfCerts, nsIPrincipal * * prin) +{ + * prin = new nsCertificatePrincipal(nsIPrincipal::PrincipalType_Certificate, + certChain, certChainLengths, noOfCerts); + if (!prin) return NS_ERROR_OUT_OF_MEMORY; + (* prin)->AddRef(); + return NS_OK; +} + + +NS_IMETHODIMP +nsPrincipalManager::CanExtendTrust(nsIPrincipalArray * from, nsIPrincipalArray * to, PRBool * result) +{ + if ((from == NULL) || (to == NULL)) { + * result = PR_FALSE; + return NS_OK; + } + nsIPrincipalArray * intersect; + from->IntersectPrincipalArray(to,& intersect); + PRUint32 intersectSize = 0, fromSize = 0; + intersect->GetPrincipalArraySize(& intersectSize); + from->GetPrincipalArraySize(& fromSize); + if (intersectSize == fromSize) { + * result = PR_TRUE; + return NS_OK; + } + if (intersectSize == 0 || (intersectSize != (fromSize - 1))) return PR_FALSE; + nsIPrincipal * prin; + PRUint32 i; + for (i=0; i < intersectSize; i++) { + intersect->GetPrincipalArrayElement(i, & prin); + PRInt16 prinType = nsIPrincipal::PrincipalType_Unknown; + prin->GetType(& prinType); + if (prinType == nsIPrincipal::PrincipalType_CodebaseExact || + prinType == nsIPrincipal::PrincipalType_CodebaseRegex) { + * result = PR_FALSE; + return NS_OK; + } + } + PRUint32 codebaseCount = 0; + for (i=0; i < fromSize; i++) { + from->GetPrincipalArrayElement(i, & prin); + PRInt16 prinType = nsIPrincipal::PrincipalType_Unknown; + prin->GetType(& prinType); + if (prinType == nsIPrincipal::PrincipalType_CodebaseExact || + prinType == nsIPrincipal::PrincipalType_CodebaseRegex) + codebaseCount++; + } + * result = (codebaseCount == 1) ? PR_TRUE : PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP +nsPrincipalManager::CheckMatchPrincipal(nsIScriptContext * context, nsIPrincipal * prin, PRInt32 callerDepth, PRBool * result) +{ + nsIPrincipalArray * prinArray = new nsPrincipalArray(); + prinArray->AddPrincipalArrayElement(prin); + nsIPrincipalArray * classPrinArray = this->GetClassPrincipalsFromStack(context, callerDepth); + PRInt16 compType = 0; + prinArray->ComparePrincipalArray(classPrinArray,& compType); + * result = (compType != nsPrincipalArray::SetComparisonType_NoSubset) ? PR_TRUE : PR_FALSE; + return NS_OK; +} +nsIPrincipalArray * +nsPrincipalManager::GetClassPrincipalsFromStack(PRInt32 callerDepth) +{ + return this->GetClassPrincipalsFromStack(NULL, callerDepth); +} + +nsIPrincipalArray * +nsPrincipalManager::GetClassPrincipalsFromStack(nsIScriptContext * context, PRInt32 callerDepth) +{ + nsIPrincipalArray * principalArray = theUnknownPrincipalArray; + int depth = 0; + struct NSJSJavaFrameWrapper * wrapper = NULL; + if (nsCapsNewNSJSJavaFrameWrapperCallback == NULL) return NULL; + wrapper = (* nsCapsNewNSJSJavaFrameWrapperCallback)((void *)context); + if (wrapper == NULL) return NULL; + for ((* nsCapsGetStartFrameCallback)(wrapper);(!(* nsCapsIsEndOfFrameCallback)(wrapper));) { + if ((* nsCapsIsValidFrameCallback)(wrapper)) { + if (depth >= callerDepth) { + principalArray = (nsIPrincipalArray *) (* nsCapsGetPrincipalArrayCallback)(wrapper); + break; + } + } + if (!(* nsCapsGetNextFrameCallback)(wrapper, &depth)) break; + } + (* nsCapsFreeNSJSJavaFrameWrapperCallback)(wrapper); + return principalArray; +} + +nsIPrincipalArray * +nsPrincipalManager::GetMyPrincipals(PRInt32 callerDepth) +{ + return nsPrincipalManager::GetMyPrincipals(NULL, callerDepth); +} + +nsIPrincipalArray * +nsPrincipalManager::GetMyPrincipals(nsIScriptContext * context, PRInt32 callerDepth) +{ + return (thePrincipalManager == NULL) + ? NULL : thePrincipalManager->GetClassPrincipalsFromStack(context, callerDepth); +} + + + +nsIPrincipal * +nsPrincipalManager::GetPrincipalFromString(char * prinName) +{ + StringKey prinNameKey(prinName); + nsCaps_lock(); + nsIPrincipal * prin = (nsIPrincipal *)itsPrinNameToPrincipalTable->Get(& prinNameKey); + nsCaps_unlock(); + return prin; +} + +void +nsPrincipalManager::AddToPrincipalNameToPrincipalTable(nsIPrincipal * prin) +{ + char * prinName; + prin->ToString(& prinName); + if (prinName == NULL) return; + StringKey prinNameKey(prinName); + nsCaps_lock(); + if (itsPrinNameToPrincipalTable->Get(& prinNameKey) == NULL) + itsPrinNameToPrincipalTable->Put(& prinNameKey, prin); + nsCaps_unlock(); + +} + +void +nsPrincipalManager::RemoveFromPrincipalNameToPrincipalTable(nsIPrincipal * prin) +{ + char * prinName; + prin->ToString(& prinName); + StringKey prinNameKey(prinName); + nsCaps_lock(); + itsPrinNameToPrincipalTable->Remove(& prinNameKey); + nsCaps_unlock(); +} + +static PRBool +GetPrincipalString(nsHashKey * aKey, void * aData, void * closure) +{ + /* Admin UI */ + /* XXX: Ignore empty strings */ + const char *string = ((StringKey *) aKey)->itsString; + gListOfPrincipals = (!gListOfPrincipals) + ? PR_sprintf_append(gListOfPrincipals, "\"%s\"", string) + : PR_sprintf_append(gListOfPrincipals, ",\"%s\"", string); + return PR_TRUE; +} + +const char * +nsPrincipalManager::GetAllPrincipalsString(void) +{ + /* Admin UI */ + char *principalStrings=NULL; + if (itsPrinNameToPrincipalTable == NULL) return NULL; + nsCaps_lock(); + gListOfPrincipals = NULL; + itsPrinNameToPrincipalTable->Enumerate(GetPrincipalString); + if (gListOfPrincipals) { + principalStrings = PL_strdup(gListOfPrincipals); + PR_Free(gListOfPrincipals); + } + gListOfPrincipals = NULL; + nsCaps_unlock(); + return principalStrings; +} + +nsPrincipalManager * +nsPrincipalManager::GetPrincipalManager(void) +{ + return thePrincipalManager; +} + +void +nsPrincipalManager::SetSystemPrincipal(nsIPrincipal * prin) +{ + theSystemPrincipal = prin; +} + +NS_IMETHODIMP +nsPrincipalManager::RegisterPrincipal(nsIPrincipal * prin) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsPrincipalManager::NewPrincipalArray(PRUint32 count, nsIPrincipalArray * * result) +{ + * result = (nsIPrincipalArray *) new nsPrincipalArray(count); + return NS_OK; +} + + + +nsPrincipalManager::nsPrincipalManager(void) +{ + nsCaps_lock(); + itsPrinNameToPrincipalTable = new nsHashtable(); + nsCaps_unlock(); +} + +nsPrincipalManager::~nsPrincipalManager(void) { + nsCaps_lock(); + if (itsPrinNameToPrincipalTable) delete itsPrinNameToPrincipalTable; + nsCaps_unlock(); +} + +PRBool +nsPrincipalManagerInitialize(void) +{ + theUnsignedPrincipal = new nsCertificatePrincipal(nsIPrincipal::PrincipalType_Certificate, UNSIGNED_PRINCIPAL_KEY); + theUnsignedPrincipalArray = new nsPrincipalArray(); + theUnsignedPrincipalArray->AddPrincipalArrayElement(theUnsignedPrincipal); + theUnknownPrincipal = new nsCertificatePrincipal(nsIPrincipal::PrincipalType_Certificate, UNKNOWN_PRINCIPAL_KEY); + theUnknownPrincipalArray = new nsPrincipalArray(); + theUnknownPrincipalArray->AddPrincipalArrayElement(theUnknownPrincipal); + thePrincipalManager = new nsPrincipalManager(); + return PR_TRUE; +} + +PRBool nsPrincipalManager::theInited = nsPrincipalManagerInitialize(); \ No newline at end of file diff --git a/mozilla/caps/src/nsPrivilegeManager.cpp b/mozilla/caps/src/nsPrivilegeManager.cpp index 23dbbf332f8..2a74f5a3c9d 100755 --- a/mozilla/caps/src/nsPrivilegeManager.cpp +++ b/mozilla/caps/src/nsPrivilegeManager.cpp @@ -18,6 +18,8 @@ #include "nsPrivilegeManager.h" #include "nsPrivilege.h" +#include "nsPrincipalArray.h" +#include "nsPrincipalManager.h" #include "prmem.h" #include "prmon.h" #include "prlog.h" @@ -30,12 +32,15 @@ #include "jsec2rdf.h" #endif /* ENABLE_RDF */ + static nsPrivilegeManager * thePrivilegeManager = NULL; +/* static nsIPrincipal * theSystemPrincipal = NULL; static nsIPrincipal * theUnsignedPrincipal; static nsIPrincipal * theUnknownPrincipal; -static nsPrincipalArray * theUnknownPrincipalArray; -static nsPrincipalArray * theUnsignedPrincipalArray; +static nsIPrincipalArray * theUnknownPrincipalArray; +static nsIPrincipalArray * theUnsignedPrincipalArray; +*/ static nsIPrivilege * thePrivilegeCache[nsIPrivilege::PrivilegeState_NumberOfPrivileges][nsIPrivilege::PrivilegeDuration_NumberOfDurations]; static PRMonitor *caps_lock = NULL; @@ -43,13 +48,10 @@ static PRMonitor *caps_lock = NULL; * a void * as argument and it passed that argument as a parameter to the * callback function. */ -char * gListOfPrincipals; char * gForever; char * gSession; char * gDenied; -nsPrivilegeTable *gPrivilegeTable; - -static PRBool GetPrincipalString(nsHashKey *aKey, void *aData, void* closure); +nsPrivilegeTable * gPrivilegeTable; #ifdef ENABLE_RDF static nsIPrincipal * RDF_getPrincipal(JSec_Principal jsec_pr); @@ -74,22 +76,6 @@ CMGetBoolPref(char * pref_name) } PR_END_EXTERN_C -PRBool -nsPrivilegeInitialize(void) -{ - PRInt16 privState; - PRInt16 durationState; - for (int i = 0; i < nsIPrivilege::PrivilegeState_NumberOfPrivileges; i++) { - for(int j = 0; j < nsIPrivilege::PrivilegeDuration_NumberOfDurations; j++) { - privState = (PRInt16) i; - durationState = (PRInt16) j; - thePrivilegeCache[i][j] = new nsPrivilege(privState, durationState); - } - } - return PR_TRUE; -} - -PRBool theInited = nsPrivilegeInitialize(); PRBool nsCaps_lock(void) @@ -109,14 +95,15 @@ nsCaps_unlock(void) if(caps_lock != NULL) PR_ExitMonitor(caps_lock); } +static NS_DEFINE_IID(kIPrivilegeManagerIID, NS_IPRIVILEGEMANAGER_IID); +NS_IMPL_ISUPPORTS(nsPrivilegeManager, kIPrivilegeManagerIID); nsPrivilegeManager::nsPrivilegeManager(void) { nsCaps_lock(); itsPrinToPrivTable = new nsHashtable(); itsPrinToMacroTargetPrivTable = new nsHashtable(); - itsPrinNameToPrincipalTable = new nsHashtable(); nsCaps_unlock(); } @@ -125,7 +112,6 @@ nsPrivilegeManager::~nsPrivilegeManager(void) nsCaps_lock(); if (itsPrinToPrivTable) delete itsPrinToPrivTable; if (itsPrinToMacroTargetPrivTable) delete itsPrinToMacroTargetPrivTable; - if (itsPrinNameToPrincipalTable) delete itsPrinNameToPrincipalTable; nsCaps_unlock(); } @@ -192,19 +178,6 @@ nsPrivilegeManager::Add(nsIPrivilege * priv1, nsIPrivilege * priv2) { return (p1state < p2state) ? priv1 : priv2; } -void -nsPrivilegeManager::AddToPrincipalNameToPrincipalTable(nsIPrincipal * prin) -{ - char *prinName; - prin->ToString(&prinName); - if (prinName == NULL) return; - StringKey prinNameKey(prinName); - nsCaps_lock(); - if (NULL == itsPrinNameToPrincipalTable->Get(&prinNameKey)) - itsPrinNameToPrincipalTable->Put(&prinNameKey, prin); - nsCaps_unlock(); -} - void nsPrivilegeManager::RegisterSystemPrincipal(nsIPrincipal * prin) { @@ -214,7 +187,7 @@ nsPrivilegeManager::RegisterSystemPrincipal(nsIPrincipal * prin) itsPrinToPrivTable->Put(&prinKey, new nsSystemPrivilegeTable()); if (NULL == itsPrinToMacroTargetPrivTable->Get(&prinKey)) itsPrinToMacroTargetPrivTable->Put(&prinKey, new nsSystemPrivilegeTable()); - theSystemPrincipal = prin; +// nsPrincipalManager::GetPrincipalManager()->SetSystemPrincipal(prin); CreateSystemTargets(prin); // Load the signed applet's ACL from the persistence store this->Load(); @@ -234,9 +207,9 @@ nsPrivilegeManager::RegisterPrincipal(nsIPrincipal * prin) itsPrinToPrivTable->Put(&prinKey, new nsPrivilegeTable()); } if (NULL == itsPrinToMacroTargetPrivTable->Get(&prinKey)) { - itsPrinToMacroTargetPrivTable->Put(&prinKey, new nsPrivilegeTable()); + itsPrinToMacroTargetPrivTable->Put(& prinKey, new nsPrivilegeTable()); } - this->AddToPrincipalNameToPrincipalTable(prin); +// nsPrincipalManager::GetPrincipalManager()->AddToPrincipalNameToPrincipalTable(prin); nsCaps_unlock(); } @@ -245,7 +218,7 @@ PRBool nsPrivilegeManager::UnregisterPrincipal(nsIPrincipal * prin) { PRBool result; - prin->Equals(this->GetSystemPrincipal(),&result); + prin->Equals(nsPrincipalManager::GetPrincipalManager()->GetSystemPrincipal(),& result); if (result) return PR_FALSE; PrincipalKey prinKey(prin); nsCaps_lock(); @@ -258,10 +231,7 @@ nsPrivilegeManager::UnregisterPrincipal(nsIPrincipal * prin) void *old_prin = itsPrinToPrivTable->Remove(&prinKey); void *old_prin1 = itsPrinToMacroTargetPrivTable->Remove(&prinKey); /* remove principal from PrinNameToPrincipalTable */ - char * prinName; - prin->ToString(& prinName); - StringKey prinNameKey(prinName); - itsPrinNameToPrincipalTable->Remove(&prinNameKey); + nsPrincipalManager::GetPrincipalManager()->RemoveFromPrincipalNameToPrincipalTable(prin); /* remove the principal from RDF also */ RDF_RemovePrincipal(prin); nsCaps_unlock(); @@ -271,18 +241,24 @@ nsPrivilegeManager::UnregisterPrincipal(nsIPrincipal * prin) PRBool nsPrivilegeManager::IsPrivilegeEnabled(nsITarget * target, PRInt32 callerDepth) { - return this->IsPrivilegeEnabled(NULL, target, callerDepth); + PRBool result; + IsPrivilegeEnabled(NULL, target, callerDepth,& result); + return result; } -PRBool -nsPrivilegeManager::IsPrivilegeEnabled(void *context, nsITarget * target, PRInt32 callerDepth) +NS_IMETHODIMP +nsPrivilegeManager::IsPrivilegeEnabled(nsIScriptContext * context, nsITarget * target, PRInt32 callerDepth, PRBool * result) { nsTargetArray * targetArray = new nsTargetArray(); nsITarget * targ = nsTarget::FindTarget(target); - if (targ != target) return PR_FALSE; + if (targ != target) { + * result = PR_FALSE; + return NS_OK; + } targetArray->Add(targ); - return (this->CheckPrivilegeEnabled(context, targetArray, callerDepth, NULL) != NULL) ? PR_FALSE : PR_TRUE; + * result = (this->CheckPrivilegeEnabled(context, targetArray, callerDepth, NULL) != NULL) ? PR_FALSE : PR_TRUE; + return NS_OK; } PRBool @@ -292,7 +268,7 @@ nsPrivilegeManager::EnablePrivilege(nsITarget * target, PRInt32 callerDepth) } PRBool -nsPrivilegeManager::EnablePrivilege(void* context, nsITarget * target, PRInt32 callerDepth) +nsPrivilegeManager::EnablePrivilege(nsIScriptContext * context, nsITarget * target, PRInt32 callerDepth) { return this->EnablePrivilegePrivate(context, target, NULL, callerDepth); } @@ -303,78 +279,85 @@ nsPrivilegeManager::EnablePrivilege(nsITarget * target, nsIPrincipal * preferred return this->EnablePrivilegePrivate(NULL, target, preferredPrincipal, callerDepth); } -PRBool -nsPrivilegeManager::EnablePrivilege(void* context, nsITarget * target, nsIPrincipal * preferredPrincipal, - PRInt32 callerDepth) +NS_IMETHODIMP +nsPrivilegeManager::EnablePrivilege(nsIScriptContext * context, nsITarget * target, nsIPrincipal * preferredPrincipal, PRInt32 callerDepth, PRBool * result) { - return this->EnablePrivilegePrivate(context, target, preferredPrincipal, callerDepth); + * result = this->EnablePrivilegePrivate(context, target, preferredPrincipal, callerDepth); + return NS_OK; } PRBool nsPrivilegeManager::RevertPrivilege(nsITarget * target, PRInt32 callerDepth) { - return this->RevertPrivilege(NULL, target, callerDepth); + PRBool result; + this->RevertPrivilege(NULL, target, callerDepth,& result); + return result; } -PRBool -nsPrivilegeManager::RevertPrivilege(void* context, nsITarget * target, PRInt32 callerDepth) +NS_IMETHODIMP +nsPrivilegeManager::RevertPrivilege(nsIScriptContext * context, nsITarget * target, PRInt32 callerDepth, PRBool * result) { nsITarget * targ = nsTarget::FindTarget(target); - if (targ != target) return PR_FALSE; + if (targ != target) { + * result = PR_FALSE; + return NS_OK; + } nsPrivilegeTable *privTable = this->GetPrivilegeTableFromStack(context, callerDepth, PR_TRUE); nsCaps_lock(); privTable->Put(target, nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Blank, nsIPrivilege::PrivilegeDuration_Scope)); nsCaps_unlock(); - return PR_TRUE; + * result = PR_TRUE; + return NS_OK; } PRBool nsPrivilegeManager::DisablePrivilege(nsITarget * target, PRInt32 callerDepth) { - return this->DisablePrivilege(NULL, target, callerDepth); + PRBool result; + result = this->DisablePrivilege(NULL, target, callerDepth,& result); + return result; } -PRBool -nsPrivilegeManager::DisablePrivilege(void * context, nsITarget * target, PRInt32 callerDepth) +NS_IMETHODIMP +nsPrivilegeManager::DisablePrivilege(nsIScriptContext * context, nsITarget * target, PRInt32 callerDepth, PRBool * result) { nsITarget * targ = nsTarget::FindTarget(target); - if (targ != target) return PR_FALSE; + if (targ != target) { + * result = PR_FALSE; + return NS_OK; + } nsPrivilegeTable *privTable = this->GetPrivilegeTableFromStack(context, callerDepth, PR_TRUE); nsCaps_lock(); privTable->Put(target, nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Forbidden, nsIPrivilege::PrivilegeDuration_Scope)); nsCaps_unlock(); - return PR_TRUE; + * result = PR_TRUE; + return NS_OK; } PRBool -nsPrivilegeManager::EnablePrincipalPrivilegeHelper(nsITarget *target, - PRInt32 callerDepth, - nsIPrincipal * preferredPrin, - void * data, - nsITarget *impersonator) +nsPrivilegeManager::EnablePrincipalPrivilegeHelper(nsITarget *target, PRInt32 callerDepth, + nsIPrincipal * preferredPrin, void * data, nsITarget *impersonator) { return this->EnablePrincipalPrivilegeHelper(NULL, target, callerDepth, preferredPrin, data, impersonator); } PRBool -nsPrivilegeManager::EnablePrincipalPrivilegeHelper(void *context, - nsITarget *target, - PRInt32 callerDepth, - nsIPrincipal * preferredPrin, - void * data, - nsITarget *impersonator) +nsPrivilegeManager::EnablePrincipalPrivilegeHelper(nsIScriptContext * context, nsITarget *target, + PRInt32 callerDepth, nsIPrincipal * preferredPrin, void * data, nsITarget *impersonator) { - nsPrincipalArray* callerPrinArray; + nsIPrincipalArray* callerPrinArray; nsIPrincipal * useThisPrin = NULL; /* Get the registered target */ nsITarget *targ = nsTarget::FindTarget(target); if (targ != target) return PR_FALSE; - callerPrinArray = this->GetClassPrincipalsFromStack(context, callerDepth); + callerPrinArray = nsPrincipalManager::GetPrincipalManager()->GetClassPrincipalsFromStack((nsIScriptContext *)context, callerDepth); if (preferredPrin != NULL) { - nsIPrincipal *callerPrin; - for (PRUint32 i = callerPrinArray->GetSize(); i-- > 0;) { - callerPrin = (nsIPrincipal *)callerPrinArray->Get(i); + nsIPrincipal * callerPrin; + PRUint32 i; + callerPrinArray->GetPrincipalArraySize(& i); + for (i; i-- > 0;) { + callerPrinArray->GetPrincipalArrayElement(i, & callerPrin); PRBool result; callerPrin->Equals(preferredPrin, & result); if (result @@ -391,10 +374,12 @@ nsPrivilegeManager::EnablePrincipalPrivilegeHelper(void *context, if ((useThisPrin == NULL) && (impersonator)){ nsITarget *t1; t1 = impersonator; - if (PR_FALSE == this->IsPrivilegeEnabled(context, t1, 0)) return PR_FALSE; + PRBool penabled; + this->IsPrivilegeEnabled(context, t1, 0, & penabled); + if (!penabled) return PR_FALSE; useThisPrin = preferredPrin; callerPrinArray = new nsPrincipalArray(); - callerPrinArray->Add(preferredPrin); + callerPrinArray->AddPrincipalArrayElement(preferredPrin); } } if (this->IsPermissionGranted(target, callerPrinArray, data)) return PR_TRUE; @@ -412,20 +397,21 @@ nsPrivilegeManager::EnablePrincipalPrivilegeHelper(void *context, // get us something reasonable. // if (useThisPrin == NULL) { - if (callerPrinArray->GetSize() == 0) return PR_FALSE; + PRUint32 size; + callerPrinArray->GetPrincipalArraySize(& size); + if (size == 0) return PR_FALSE; // throw new ForbiddenTargetException("request's caller has no principal!"); - useThisPrin = (nsIPrincipal *)callerPrinArray->Get(0); + callerPrinArray->GetPrincipalArrayElement(0,& useThisPrin); } // Do a user dialog - return AskPermission(useThisPrin, target, data); + PRBool result; + AskPermission(useThisPrin, target, data,& result); + return result; } nsPrivilegeTable * -nsPrivilegeManager::EnableScopePrivilegeHelper(nsITarget *target, - PRInt32 callerDepth, - void *data, - PRBool helpingSetScopePrivilege, +nsPrivilegeManager::EnableScopePrivilegeHelper(nsITarget *target, PRInt32 callerDepth, void *data, PRBool helpingSetScopePrivilege, nsIPrincipal *prefPrin) { return this->EnableScopePrivilegeHelper(NULL, target, callerDepth, data, @@ -434,11 +420,8 @@ nsPrivilegeManager::EnableScopePrivilegeHelper(nsITarget *target, nsPrivilegeTable * -nsPrivilegeManager::EnableScopePrivilegeHelper(void* context, nsITarget *target, - PRInt32 callerDepth, - void *data, - PRBool helpingSetScopePrivilege, - nsIPrincipal * prefPrin) +nsPrivilegeManager::EnableScopePrivilegeHelper(nsIScriptContext * context, nsITarget *target, PRInt32 callerDepth, + void *data, PRBool helpingSetScopePrivilege, nsIPrincipal * prefPrin) { nsPrivilegeTable *privTable; nsIPrivilege * allowedScope; @@ -449,7 +432,7 @@ nsPrivilegeManager::EnableScopePrivilegeHelper(void* context, nsITarget *target, //throw new ForbiddenTargetException(target + " is not a registered target"); (prefPrin != NULL) ? res = this->CheckPrivilegeGranted(target, prefPrin, data) : - res = this->CheckPrivilegeGranted(context, target, callerDepth, data); + this->CheckPrivilegeGranted(context, target, callerDepth, data,& res); if (res == PR_FALSE) return NULL; privTable = this->GetPrivilegeTableFromStack(context, callerDepth, (helpingSetScopePrivilege ? PR_FALSE : PR_TRUE)); @@ -462,15 +445,15 @@ nsPrivilegeManager::EnableScopePrivilegeHelper(void* context, nsITarget *target, return privTable; } -PRBool -nsPrivilegeManager::AskPermission(nsIPrincipal * useThisPrin, nsITarget * target, void * data) +NS_IMETHODIMP +nsPrivilegeManager::AskPermission(nsIPrincipal * useThisPrin, nsITarget * target, void * data, PRBool * result) { /* PRBool ret_val = PR_FALSE; nsPrivilege* newPrivilege = NULL; // Get the Lock to display the dialog nsCaps_lock(); - nsPrincipalArray* callerPrinArray = new nsPrincipalArray(); + nsIPrincipalArray* callerPrinArray = new nsIPrincipalArray(); callerPrinArray->Add(useThisPrin); if (PR_TRUE == this->IsPermissionGranted(target, callerPrinArray, data)) { ret_val = PR_TRUE; @@ -503,11 +486,10 @@ done: delete callerPrinArray; nsCaps_unlock(); */ - return PR_TRUE; - + return NS_OK; } -void +NS_IMETHODIMP nsPrivilegeManager::SetPermission(nsIPrincipal * useThisPrin, nsITarget * target, nsIPrivilege * newPrivilege) { /* @@ -529,6 +511,7 @@ nsPrivilegeManager::SetPermission(nsIPrincipal * useThisPrin, nsITarget * target if (!result) save(useThisPrin, target, newPrivilege); } */ + return NS_OK; } @@ -570,19 +553,24 @@ nsPrivilegeManager::UpdatePrivilegeTable(nsITarget * target, nsPrivilegeTable * PRBool nsPrivilegeManager::CheckPrivilegeGranted(nsITarget *target, PRInt32 callerDepth) { - return this->CheckPrivilegeGranted(NULL, target, callerDepth, NULL); + PRBool result; + this->CheckPrivilegeGranted(NULL, target, callerDepth, NULL,& result); + return result; } PRBool -nsPrivilegeManager::CheckPrivilegeGranted(void* context, nsITarget *target, PRInt32 callerDepth) +nsPrivilegeManager::CheckPrivilegeGranted(nsIScriptContext * context, nsITarget *target, PRInt32 callerDepth) { - return this->CheckPrivilegeGranted(context, target, callerDepth, NULL); + PRBool result; + CheckPrivilegeGranted(context, target, callerDepth, NULL,& result); + return result; } PRBool nsPrivilegeManager::CheckPrivilegeGranted(nsITarget *target, nsIPrincipal *prin, void *data) { - nsIPrivilege * privilege = this->GetPrincipalPrivilege(target, prin, data); + nsIPrivilege * privilege; + this->GetPrincipalPrivilege(target, prin, data,& privilege); PRBool allowed; privilege->IsAllowed(& allowed); return (allowed) ? PR_TRUE : PR_FALSE; @@ -591,228 +579,132 @@ nsPrivilegeManager::CheckPrivilegeGranted(nsITarget *target, nsIPrincipal *prin, PRBool nsPrivilegeManager::CheckPrivilegeGranted(nsITarget *target, PRInt32 callerDepth, void *data) { - return CheckPrivilegeGranted(NULL, target, callerDepth, data); + PRBool result; + CheckPrivilegeGranted(NULL, target, callerDepth, data,& result); + return result; } -PRBool -nsPrivilegeManager::CheckPrivilegeGranted(void* context, nsITarget *target, PRInt32 callerDepth, void *data) +NS_IMETHODIMP +nsPrivilegeManager::CheckPrivilegeGranted(nsIScriptContext * context, nsITarget * target, PRInt32 callerDepth, void * data, PRBool * result) { - nsPrincipalArray* callerPrinArray = GetClassPrincipalsFromStack(context, callerDepth); - PRInt16 privilegeState = GetPrincipalPrivilege(target, callerPrinArray, data); - return (privilegeState == nsIPrivilege::PrivilegeState_Allowed) ? PR_TRUE : PR_FALSE; + nsIPrincipalArray* callerPrinArray = + nsPrincipalManager::GetPrincipalManager()->GetClassPrincipalsFromStack((nsIScriptContext *)context, callerDepth); + PRInt16 privilegeState = this->GetPrincipalPrivilege(target, callerPrinArray, data); + * result = (privilegeState == nsIPrivilege::PrivilegeState_Allowed) ? PR_TRUE : PR_FALSE; + return NS_OK; } -nsPrivilegeManager * +nsPrivilegeManager * nsPrivilegeManager::GetPrivilegeManager(void) { return thePrivilegeManager; } - -nsPrincipalArray * +/* +nsIPrincipalArray * nsPrivilegeManager::GetMyPrincipals(PRInt32 callerDepth) { return nsPrivilegeManager::GetMyPrincipals(NULL, callerDepth); } -nsPrincipalArray * +nsIPrincipalArray * nsPrivilegeManager::GetMyPrincipals(void* context, PRInt32 callerDepth) { return (thePrivilegeManager == NULL) ? NULL : thePrivilegeManager->GetClassPrincipalsFromStack(context, callerDepth); } - +*/ +/* nsIPrincipal * nsPrivilegeManager::GetSystemPrincipal(void) { return theSystemPrincipal; } - +*/ +/* PRBool -nsPrivilegeManager::HasSystemPrincipal(nsPrincipalArray *prinArray) +nsPrivilegeManager::HasSystemPrincipal(nsIPrincipalArray *prinArray) { nsIPrincipal * sysPrin = nsPrivilegeManager::GetSystemPrincipal(); nsIPrincipal * prin; if (sysPrin == NULL) return PR_FALSE; - for (int i = prinArray->GetSize(); i-- > 0;) { - prin = (nsIPrincipal *)prinArray->Get(i); + PRUint32 i; + prinArray->GetPrincipalArraySize(& i); + for (i; i-- > 0;) { + prinArray->GetPrincipalArrayElement(i,& prin); PRBool result; sysPrin->Equals(prin, & result); if (result) return PR_TRUE; } return PR_FALSE; } - +*/ +/* nsIPrincipal * nsPrivilegeManager::GetUnsignedPrincipal(void) { return theUnsignedPrincipal; } - +*/ +/* nsIPrincipal * nsPrivilegeManager::GetUnknownPrincipal(void) { return theUnknownPrincipal; } - -PRInt16 -nsPrivilegeManager::ComparePrincipalArray(nsPrincipalArray * p1, nsPrincipalArray * p2) -{ - nsHashtable *p2Hashtable = new nsHashtable(); - PRBool value; - nsIPrincipal * prin; - PRUint32 i; - for (i = p2->GetSize(); i-- > 0;) { - prin = (nsIPrincipal *)p2->Get(i); - PrincipalKey prinKey(prin); - p2Hashtable->Put(&prinKey, (void *)PR_TRUE); - } - for (i = p1->GetSize(); i-- > 0;) { - prin = (nsIPrincipal *)p1->Get(i); - PrincipalKey prinKey(prin); - value = (PRBool)p2Hashtable->Get(&prinKey); - if (!value) return nsPrivilegeManager::SetComparisonType_NoSubset; - if (value == PR_TRUE) p2Hashtable->Put(&prinKey, (void *)PR_FALSE); - } - for (i = p2->GetSize(); i-- > 0;) { - prin = (nsIPrincipal *)p2->Get(i); - PrincipalKey prinKey(prin); - value = (PRBool)p2Hashtable->Get(&prinKey); - if (value == PR_TRUE) return nsPrivilegeManager::SetComparisonType_ProperSubset; - } - return nsPrivilegeManager::SetComparisonType_Equal; -} - -nsPrincipalArray* -nsPrivilegeManager::IntersectPrincipalArray(nsPrincipalArray * p1, nsPrincipalArray * p2) -{ - int p1_length = p1->GetSize(); - int p2_length = p2->GetSize(); - nsPrincipalArray *in = new nsPrincipalArray(); - int count = 0; - nsIPrincipal * prin1; - nsIPrincipal * prin2; - int i; - in->SetSize(p1_length, 1); - int in_length = in->GetSize(); - for (i=0; i < p1_length; i++) { - for (int j=0; j < p2_length; j++) { - prin1 = (nsIPrincipal *)p1->Get(i); - prin2 = (nsIPrincipal *)p2->Get(j); - PRBool eq; - prin1->Equals(prin2, & eq); - if (eq) { - in->Set(i, (void *)PR_TRUE); - count++; - break; - } else { - in->Set(i, (void *)PR_FALSE); - } - } - } - nsPrincipalArray *result = new nsPrincipalArray(); - result->SetSize(count, 1); - PRBool doesIntersect; - int j=0; - PR_ASSERT(in_length == (int)(p1->GetSize())); - PR_ASSERT(in_length == (int)(in->GetSize())); - for (i=0; i < in_length; i++) { - doesIntersect = (PRBool)in->Get(i); - if (doesIntersect) { - PR_ASSERT(j < count); - result->Set(j, p1->Get(i)); - j++; - } - } - return result; -} - +*/ +/* PRBool -nsPrivilegeManager::CanExtendTrust(nsPrincipalArray * from, nsPrincipalArray * to) +nsPrivilegeManager::CanExtendTrust(nsIPrincipalArray * from, nsIPrincipalArray * to) { - if ((from == NULL) || (to == NULL)) return PR_FALSE; - nsPrincipalArray * intersect = this->IntersectPrincipalArray(from, to); - if (intersect->GetSize() == from->GetSize()) return PR_TRUE; - if (intersect->GetSize() == 0 || - (intersect->GetSize() != (from->GetSize() - 1))) - return PR_FALSE; - int intersect_size = intersect->GetSize(); - nsIPrincipal * prin; - int i; - for (i=0; i < intersect_size; i++) { - prin = (nsIPrincipal *)intersect->Get(i); -//XXX ARIEL: update this call -// if (prin->isCodebase()) return PR_FALSE; - } - int codebaseCount = 0; - int from_size = from->GetSize(); - for (i=0; i < from_size; i++) { - prin = (nsIPrincipal *)from->Get(i); -//XXX ARIEL: update this call -// if (prin->isCodebase()) codebaseCount++; - } - return (codebaseCount == 1) ? PR_TRUE : PR_FALSE; + if ((from == NULL) || (to == NULL)) return PR_FALSE; + nsIPrincipalArray * intersect; + from->IntersectPrincipalArray(to,& intersect); + PRUint32 intersectSize = 0, fromSize = 0; + intersect->GetPrincipalArraySize(& intersectSize); + from->GetPrincipalArraySize(& fromSize); + if (intersectSize == fromSize) return PR_TRUE; + if (intersectSize == 0 || (intersectSize != (fromSize - 1))) return PR_FALSE; + nsIPrincipal * prin; + PRUint32 i; + for (i=0; i < intersectSize; i++) { + intersect->GetPrincipalArrayElement(i, & prin); + PRInt16 prinType = nsIPrincipal::PrincipalType_Unknown; + prin->GetType(& prinType); + if (prinType == nsIPrincipal::PrincipalType_CodebaseExact || + prinType == nsIPrincipal::PrincipalType_CodebaseRegex) + return PR_FALSE; + } + PRUint32 codebaseCount = 0; + for (i=0; i < fromSize; i++) { + from->GetPrincipalArrayElement(i, & prin); + PRInt16 prinType = nsIPrincipal::PrincipalType_Unknown; + prin->GetType(& prinType); + if (prinType == nsIPrincipal::PrincipalType_CodebaseExact || + prinType == nsIPrincipal::PrincipalType_CodebaseRegex) + codebaseCount++; + } + return (codebaseCount == 1) ? PR_TRUE : PR_FALSE; } - - +*/ +/* PRBool nsPrivilegeManager::CheckMatchPrincipal(nsIPrincipal * prin, PRInt32 callerDepth) { return this->CheckMatchPrincipal(NULL, prin, callerDepth); } - +*/ +/* PRBool nsPrivilegeManager::CheckMatchPrincipal(void * context, nsIPrincipal * prin, PRInt32 callerDepth) { - nsPrincipalArray *prinArray = new nsPrincipalArray(); - prinArray->Add(prin); - nsPrincipalArray *classPrinArray = this->GetClassPrincipalsFromStack(context, callerDepth); - return (this->ComparePrincipalArray(prinArray, classPrinArray) != nsPrivilegeManager::SetComparisonType_NoSubset) ? PR_TRUE : PR_FALSE; -} - -static PRBool -GetPrincipalString(nsHashKey * aKey, void * aData, void * closure) -{ - /* Admin UI */ - /* XXX: Ignore empty strings */ - const char *string = ((StringKey *) aKey)->itsString; - if (gListOfPrincipals == NULL) { - gListOfPrincipals = PR_sprintf_append(gListOfPrincipals, "\"%s\"", string); - } else { - gListOfPrincipals = PR_sprintf_append(gListOfPrincipals, ",\"%s\"", string); - } - return PR_TRUE; -} - - -const char * -nsPrivilegeManager::GetAllPrincipalsString(void) -{ - /* Admin UI */ - char *principalStrings=NULL; - if (itsPrinNameToPrincipalTable == NULL) return NULL; - nsCaps_lock(); - gListOfPrincipals = NULL; - itsPrinNameToPrincipalTable->Enumerate(GetPrincipalString); - if (gListOfPrincipals) { - principalStrings = PL_strdup(gListOfPrincipals); - PR_Free(gListOfPrincipals); - } - gListOfPrincipals = NULL; - nsCaps_unlock(); - return principalStrings; -} - - -nsIPrincipal * -nsPrivilegeManager::GetPrincipalFromString(char *prinName) -{ - /* Admin UI */ - StringKey prinNameKey(prinName); - nsCaps_lock(); - nsIPrincipal * prin = (nsIPrincipal *)itsPrinNameToPrincipalTable->Get(&prinNameKey); - nsCaps_unlock(); - return prin; + nsIPrincipalArray * prinArray = new nsPrincipalArray(0); + prinArray->AddPrincipalArrayElement(prin); + nsIPrincipalArray * classPrinArray = this->GetClassPrincipalsFromStack(context, callerDepth); + PRInt16 compType = 0; + prinArray->ComparePrincipalArray(classPrinArray,& compType); + return (compType != nsPrincipalArray::SetComparisonType_NoSubset) ? PR_TRUE : PR_FALSE; } +*/ static PRBool GetPermissionsString(nsHashKey * aKey, void * aData, void * closure) @@ -838,17 +730,16 @@ nsPrivilegeManager::GetTargetsWithPrivileges(char *prinName, char** forever, *forever = gForever = NULL; *session = gSession = NULL; *denied = gDenied = NULL; - nsIPrincipal * prin = this->GetPrincipalFromString(prinName); + nsIPrincipal * prin = nsPrincipalManager::GetPrincipalManager()->GetPrincipalFromString(prinName); if (prin == NULL) { - nsCaps_unlock(); - return; + nsCaps_unlock(); + return; } PrincipalKey prinKey(prin); - nsPrivilegeTable * pt = - (nsPrivilegeTable *)itsPrinToMacroTargetPrivTable->Get(&prinKey); + nsPrivilegeTable * pt = (nsPrivilegeTable *)itsPrinToMacroTargetPrivTable->Get(& prinKey); if (pt == NULL) { - nsCaps_unlock(); - return; + nsCaps_unlock(); + return; } pt->Enumerate(GetPermissionsString); /* The caller should free up the allocated memory */ @@ -864,41 +755,48 @@ nsPrivilegeManager::GetTargetsWithPrivileges(char *prinName, char** forever, PRBool nsPrivilegeManager::RemovePrincipal(char * prinName) { - /* Admin UI */ - nsCaps_lock(); - nsIPrincipal * prin = this->GetPrincipalFromString(prinName); - if (prin == NULL) { - nsCaps_unlock(); - return PR_FALSE; - } - this->UnregisterPrincipal(prin); - nsCaps_unlock(); - return PR_TRUE; + /* Admin UI */ + nsCaps_lock(); + nsIPrincipal * prin = nsPrincipalManager::GetPrincipalManager()->GetPrincipalFromString(prinName); + if (prin == NULL) { + nsCaps_unlock(); + return PR_FALSE; + } + this->UnregisterPrincipal(prin); + nsCaps_unlock(); + return PR_TRUE; } -PRBool -nsPrivilegeManager::RemovePrincipalsPrivilege(char *prinName, char *targetDesc) +NS_IMETHODIMP +nsPrivilegeManager::RemovePrincipalsPrivilege(const char * prinName, const char * targetDesc, PRBool * result) { - /* Admin UI */ - nsIPrincipal * prin = this->GetPrincipalFromString(prinName); - if (prin == NULL) return PR_FALSE; - /* targetDesc is passed to the admin UI in getPermissionsString */ - nsITarget * target = nsTarget::GetTargetFromDescription(targetDesc); - if (target == NULL) return PR_FALSE; - this->Remove(prin, target); - return PR_TRUE; + /* Admin UI */ + nsIPrincipal * prin = nsPrincipalManager::GetPrincipalManager()->GetPrincipalFromString((char *)prinName); + if (prin == NULL) { + * result = PR_FALSE; + return NS_OK; + } + /* targetDesc is passed to the admin UI in getPermissionsString */ + nsITarget * target = nsTarget::GetTargetFromDescription((char *)targetDesc); + if (target == NULL) { + * result = PR_FALSE; + return NS_OK; + } + this->Remove(prin, target); + * result = PR_TRUE; + return NS_OK; } static PRBool UpdatePrivileges(nsHashKey *aKey, void *aData, void* closure) { - /* Admin UI */ - TargetKey *targetKey = (TargetKey *) aKey; - nsITarget *target = targetKey->itsTarget; - nsPrivilege *priv = (nsPrivilege *)aData; - nsPrivilegeManager *mgr = nsPrivilegeManager::GetPrivilegeManager(); - mgr->UpdatePrivilegeTable(target, gPrivilegeTable, priv); - return PR_TRUE; + /* Admin UI */ + TargetKey * targetKey = (TargetKey *) aKey; + nsITarget * target = targetKey->itsTarget; + nsPrivilege * priv = (nsPrivilege *)aData; + nsPrivilegeManager * mgr = nsPrivilegeManager::GetPrivilegeManager(); + mgr->UpdatePrivilegeTable(target, gPrivilegeTable, priv); + return PR_TRUE; } void @@ -912,7 +810,7 @@ nsPrivilegeManager::Remove(nsIPrincipal * prin, nsITarget * target) return; } PrincipalKey prinKey(prin); - nsPrivilegeTable *mpt = (nsPrivilegeTable *)itsPrinToMacroTargetPrivTable->Get(&prinKey); + nsPrivilegeTable * mpt = (nsPrivilegeTable *)itsPrinToMacroTargetPrivTable->Get(&prinKey); if (mpt == NULL) { nsCaps_unlock(); return; @@ -932,29 +830,24 @@ nsPrivilegeManager::Remove(nsIPrincipal * prin, nsITarget * target) // PRIVATE METHODS -#define UNSIGNED_PRIN_KEY "4a:52:4f:53:4b:49:4e:44" -#define UNKNOWN_PRIN_KEY "52:4f:53:4b:49:4e:44:4a" - PRBool -nsPrivilegeManager::EnablePrivilegePrivate(void* context, nsITarget *target, nsIPrincipal * prefPrin, - PRInt32 callerDepth) +nsPrivilegeManager::EnablePrivilegePrivate(nsIScriptContext * context, nsITarget *target, nsIPrincipal * prefPrin, PRInt32 callerDepth) { - if (PR_FALSE == this->EnablePrincipalPrivilegeHelper(context, target, callerDepth, - prefPrin, NULL, NULL)) return PR_FALSE; - - return (NULL == this->EnableScopePrivilegeHelper(context, target, callerDepth, NULL, PR_FALSE, prefPrin)) - ? PR_FALSE : PR_TRUE; + if (PR_FALSE == this->EnablePrincipalPrivilegeHelper(context, target, callerDepth, prefPrin, NULL, NULL)) return PR_FALSE; + return (NULL == this->EnableScopePrivilegeHelper(context, target, callerDepth, NULL, PR_FALSE, prefPrin)) ? PR_FALSE : PR_TRUE; } PRInt16 -nsPrivilegeManager::GetPrincipalPrivilege(nsITarget * target, nsPrincipalArray * callerPrinArray, void *data) +nsPrivilegeManager::GetPrincipalPrivilege(nsITarget * target, nsIPrincipalArray * callerPrinArray, void *data) { nsIPrivilege * privilege; nsIPrincipal * principal; PRBool isAllowed = PR_FALSE; - for (int i = callerPrinArray->GetSize(); i-- > 0; ) { - principal = (nsIPrincipal *)callerPrinArray->Get(i); - privilege = this->GetPrincipalPrivilege(target, principal, data); + PRUint32 i; + callerPrinArray->GetPrincipalArraySize(& i); + for (i; i-- > 0; ) { + callerPrinArray->GetPrincipalArrayElement(i,& principal); + this->GetPrincipalPrivilege(target, principal, data,& privilege); if (privilege == NULL) continue; PRInt16 privilegeState; privilege->GetState(& privilegeState); @@ -967,27 +860,35 @@ nsPrivilegeManager::GetPrincipalPrivilege(nsITarget * target, nsPrincipalArray * } return (isAllowed) ? (PRInt16)nsIPrivilege::PrivilegeState_Allowed : (PRInt16)nsIPrivilege::PrivilegeState_Blank; } -nsIPrivilege * -nsPrivilegeManager::GetPrincipalPrivilege(nsITarget *target, nsIPrincipal * prin, void *data) + +NS_IMETHODIMP +nsPrivilegeManager::GetPrincipalPrivilege(nsITarget * target, nsIPrincipal * prin, void * data, nsIPrivilege * * result) { - if ( (prin == NULL) || (target == NULL) ) - return nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Blank, nsIPrivilege::PrivilegeDuration_Session); - if (this->GetSystemPrincipal() == prin) - return nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Allowed, nsIPrivilege::PrivilegeDuration_Session); + if ( (prin == NULL) || (target == NULL) ) { + * result = nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Blank, nsIPrivilege::PrivilegeDuration_Session); + return NS_OK; + } +// if (nsPrincipalManager::GetPrincipalManager()->GetSystemPrincipal() == prin) { +// * result = nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Allowed, nsIPrivilege::PrivilegeDuration_Session); +// return NS_OK; +// } PrincipalKey prinKey(prin); nsPrivilegeTable *privTable = (nsPrivilegeTable *) itsPrinToPrivTable->Get(&prinKey); - if (privTable == NULL) - return nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Blank, nsIPrivilege::PrivilegeDuration_Session); + if (privTable == NULL) { + * result = nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Blank, nsIPrivilege::PrivilegeDuration_Session); + return NS_OK; + } nsITarget * tempTarget = nsTarget::FindTarget(target); - if (tempTarget != target) - return nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Blank, nsIPrivilege::PrivilegeDuration_Session); - return privTable->Get(target); + if (tempTarget != target) { + * result = nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Blank, nsIPrivilege::PrivilegeDuration_Session); + return NS_OK; + } + * result = privTable->Get(target); + return NS_OK; } PRBool -nsPrivilegeManager::IsPermissionGranted(nsITarget *target, - nsPrincipalArray* callerPrinArray, - void *data) +nsPrivilegeManager::IsPermissionGranted(nsITarget * target, nsIPrincipalArray * callerPrinArray, void * data) { PRInt16 privilegeState = this->GetPrincipalPrivilege(target, callerPrinArray, data); switch(privilegeState) { @@ -999,22 +900,20 @@ nsPrivilegeManager::IsPermissionGranted(nsITarget *target, } char * -nsPrivilegeManager::CheckPrivilegeEnabled(nsTargetArray * targetArray, - PRInt32 callerDepth, void *data) +nsPrivilegeManager::CheckPrivilegeEnabled(nsTargetArray * targetArray, PRInt32 callerDepth, void *data) { return this->CheckPrivilegeEnabled(NULL, targetArray, callerDepth, data); } char * -nsPrivilegeManager::CheckPrivilegeEnabled(void *context, nsTargetArray * targetArray, - PRInt32 callerDepth, void *data) +nsPrivilegeManager::CheckPrivilegeEnabled(nsIScriptContext * context, nsTargetArray * targetArray, PRInt32 callerDepth, void *data) { /* struct NSJSJavaFrameWrapper *wrapper = NULL; nsTarget *target; nsPrivilegeTable *annotation; nsPrivilege *privilege; - nsPrincipalArray * prinArray = theUnknownPrincipalArray; + nsIPrincipalArray * prinArray = theUnknownPrincipalArray; int depth = 0; nsPermissionState perm; nsPermissionState scopePerm; @@ -1045,7 +944,7 @@ nsPrivilegeManager::CheckPrivilegeEnabled(void *context, nsTargetArray * targetA goto done; } annotation =(nsPrivilegeTable *) (*nsCapsGetAnnotationCallback)(wrapper); - prinArray = (nsPrincipalArray *) (*nsCapsGetPrincipalArrayCallback)(wrapper); + prinArray = (nsIPrincipalArray *) (*nsCapsGetPrincipalArrayCallback)(wrapper); * When the Registration Mode flag is enabled, we allow secure * operations if and only iff the principal codebase is 'file:'. @@ -1129,17 +1028,17 @@ done: */ return NULL; } - -nsPrincipalArray * +/* +nsIPrincipalArray * nsPrivilegeManager::GetClassPrincipalsFromStack(PRInt32 callerDepth) { return this->GetClassPrincipalsFromStack(NULL, callerDepth); } -nsPrincipalArray * +nsIPrincipalArray * nsPrivilegeManager::GetClassPrincipalsFromStack(void* context, PRInt32 callerDepth) { - nsPrincipalArray * principalArray = theUnknownPrincipalArray; + nsIPrincipalArray * principalArray = theUnknownPrincipalArray; int depth = 0; struct NSJSJavaFrameWrapper *wrapper = NULL; if (nsCapsNewNSJSJavaFrameWrapperCallback == NULL) return NULL; @@ -1150,8 +1049,7 @@ nsPrivilegeManager::GetClassPrincipalsFromStack(void* context, PRInt32 callerDep ) { if ((*nsCapsIsValidFrameCallback)(wrapper)) { if (depth >= callerDepth) { - principalArray = - (nsPrincipalArray *) (*nsCapsGetPrincipalArrayCallback)(wrapper); + principalArray = (nsIPrincipalArray *) (*nsCapsGetPrincipalArrayCallback)(wrapper); break; } } @@ -1160,17 +1058,16 @@ nsPrivilegeManager::GetClassPrincipalsFromStack(void* context, PRInt32 callerDep (*nsCapsFreeNSJSJavaFrameWrapperCallback)(wrapper); return principalArray; } - +*/ nsPrivilegeTable * -nsPrivilegeManager::GetPrivilegeTableFromStack(PRInt32 callerDepth, - PRBool createIfNull) +nsPrivilegeManager::GetPrivilegeTableFromStack(PRInt32 callerDepth, PRBool createIfNull) { return this->GetPrivilegeTableFromStack(NULL, callerDepth, createIfNull); } nsPrivilegeTable * -nsPrivilegeManager::GetPrivilegeTableFromStack(void *context, PRInt32 callerDepth, PRBool createIfNull) +nsPrivilegeManager::GetPrivilegeTableFromStack(nsIScriptContext * context, PRInt32 callerDepth, PRBool createIfNull) { nsPrivilegeTable *privTable = NULL; int depth = 0; @@ -1355,7 +1252,7 @@ void nsPrivilegeManager::Save(nsIPrincipal * prin, nsITarget *target, nsIPrivilege *newPrivilege) { PRBool eq; - prin->Equals(this->GetSystemPrincipal(), &eq); + prin->Equals(nsPrincipalManager::GetPrincipalManager()->GetSystemPrincipal(),& eq); if (eq) return; #ifdef ENABLE_RDF nsCaps_lock(); @@ -1410,27 +1307,20 @@ nsPrivilegeManager::Load(void) PRBool nsPrivilegeManagerInitialize(void) { - /* XXX: How do we determine SystemPrincipal so that we can create System - Targets? Are all SystemTargtes Java specific only. What about JS - specific targets - */ -//XXX ARIEL: fix this -// theUnsignedPrincipal = new nsIPrincipal(nsIPrincipal::PrincipalType_Certificate, -// UNSIGNED_PRIN_KEY, -// strlen(UNSIGNED_PRIN_KEY)); - theUnsignedPrincipalArray = new nsPrincipalArray(); - theUnsignedPrincipalArray->Add(theUnsignedPrincipal); -// theUnknownPrincipal = new nsIPrincipal(nsIPrincipal::PrincipalType_Certificate, -// UNKNOWN_PRIN_KEY, -// strlen(UNKNOWN_PRIN_KEY)); - theUnknownPrincipalArray = new nsPrincipalArray(); - theUnknownPrincipalArray->Add(theUnknownPrincipal); - thePrivilegeManager = new nsPrivilegeManager(); + thePrivilegeManager = new nsPrivilegeManager(); + PRInt16 privState = 0, durationState = 0; + for (PRInt16 i = 0; i < nsIPrivilege::PrivilegeState_NumberOfPrivileges; i++) { + for(PRInt16 j = 0; j < nsIPrivilege::PrivilegeDuration_NumberOfDurations; j++) { + privState = i; + durationState = j; + thePrivilegeCache[i][j] = new nsPrivilege(privState, durationState); + } + } #ifdef ENABLE_RDF RDFJSec_InitPrivilegeDB(); #endif /* ENABLE_RDF */ - return PR_FALSE; + return PR_TRUE; } PRBool nsPrivilegeManager::theInited = nsPrivilegeManagerInitialize(); diff --git a/mozilla/caps/src/nsTarget.cpp b/mozilla/caps/src/nsTarget.cpp index f46ce039517..495da22eac2 100755 --- a/mozilla/caps/src/nsTarget.cpp +++ b/mozilla/caps/src/nsTarget.cpp @@ -19,6 +19,7 @@ #include "prlog.h" #include "nsTarget.h" #include "nsPrivilegeManager.h" +#include "nsPrincipalManager.h" #include "nsUserTarget.h" #include "nsUserDialogHelper.h" #include "xp.h" @@ -705,9 +706,11 @@ nsTarget::RegisterTarget(void * context, nsITarget * * targetResult) targetResult = & targ; return NS_OK; } - nsPrivilegeManager * mgr = nsPrivilegeManager::GetPrivilegeManager(); - if ((mgr != NULL) && (context != NULL) && - (!mgr->CheckMatchPrincipal(context, itsPrincipal, 1))) { + nsPrivilegeManager * privMgr = nsPrivilegeManager::GetPrivilegeManager(); + nsPrincipalManager * prinMgr = nsPrincipalManager::GetPrincipalManager(); + PRBool cmp = PR_FALSE; + prinMgr->CheckMatchPrincipal((nsIScriptContext *)context, itsPrincipal, 1,& cmp); + if ((privMgr != NULL) && (context != NULL) && !cmp) { nsCaps_unlock(); targetResult = NULL; return NS_OK; @@ -719,7 +722,7 @@ nsTarget::RegisterTarget(void * context, nsITarget * * targetResult) theTargetRegistry->Put(&targKey, this); // hash table will "canonicalize" name if (!theSystemTargetRegistry) theSystemTargetRegistry = new nsHashtable(); PRBool eq; - itsPrincipal->Equals(nsPrivilegeManager::GetSystemPrincipal(),&eq); + itsPrincipal->Equals(nsPrincipalManager::GetSystemPrincipal(),& eq); if (eq) { IntegerKey ikey(PL_HashString(itsName)); theSystemTargetRegistry->Put(&ikey, this); @@ -753,7 +756,7 @@ nsITarget * nsTarget::FindTarget(char * name, nsIPrincipal * prin) { PRBool eq; - prin->Equals(nsPrivilegeManager::GetSystemPrincipal(),&eq); + prin->Equals(nsPrincipalManager::GetSystemPrincipal(),&eq); if (eq) return nsTarget::FindTarget(name); /* name and principal combination uniquely identfies a target */ nsITarget * targ = new nsTarget((char *)name, prin, @@ -769,13 +772,13 @@ nsTarget::FindTarget(char * name, nsIPrincipal * prin) //WHAT THE HELL IS VOID * DATA???????????????????????????????????????????????????? // these methods are already done by the privilege manager, get them outa here nsIPrivilege * -nsTarget::CheckPrivilegeEnabled(nsPrincipalArray * prinArray, void * data) +nsTarget::CheckPrivilegeEnabled(nsTargetArray * prinArray, void * data) { return nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Blank, nsIPrivilege::PrivilegeDuration_Session); } nsIPrivilege * -nsTarget::CheckPrivilegeEnabled(nsPrincipalArray* prinArray) +nsTarget::CheckPrivilegeEnabled(nsTargetArray * prinArray) { return this->CheckPrivilegeEnabled(prinArray, NULL); } diff --git a/mozilla/dom/src/base/nsJSSecurityManager.cpp b/mozilla/dom/src/base/nsJSSecurityManager.cpp index b1c746083bb..05d2cc9c764 100644 --- a/mozilla/dom/src/base/nsJSSecurityManager.cpp +++ b/mozilla/dom/src/base/nsJSSecurityManager.cpp @@ -17,7 +17,7 @@ */ #include "nsJSSecurityManager.h" -#include "nsICapsManager.h" +#include "nsCCapsManager.h" #include "nsIServiceManager.h" #ifdef OJI #include "jvmmgr.h" @@ -50,8 +50,8 @@ nsJSSecurityManager::nsJSSecurityManager() nsJSSecurityManager::~nsJSSecurityManager() { - nsServiceManager::ReleaseService(kPrefServiceCID, mPrefs); - NS_IF_RELEASE(mCapsManager); + nsServiceManager::ReleaseService(kPrefServiceCID, mPrefs); + NS_IF_RELEASE(mCapsManager); } NS_IMETHODIMP @@ -84,18 +84,16 @@ NS_IMPL_RELEASE(nsJSSecurityManager) NS_IMETHODIMP nsJSSecurityManager::Init() { - return nsServiceManager::GetService(kPrefServiceCID, nsIPref::GetIID(), (nsISupports**)&mPrefs); + return nsServiceManager::GetService(kPrefServiceCID, nsIPref::GetIID(), (nsISupports**)&mPrefs); } NS_IMETHODIMP -nsJSSecurityManager::CheckScriptAccess(nsIScriptContext* aContext, void* aObj, - const char* aProp, PRBool* aResult) +nsJSSecurityManager::CheckScriptAccess(nsIScriptContext* aContext, void* aObj, const char* aProp, PRBool* aResult) { #ifdef SECURITY_ENABLED *aResult = PR_FALSE; JSContext* cx = (JSContext*)aContext->GetNativeContext(); PRInt32 secLevel = CheckForPrivilege(cx, (char*)aProp, nsnull); - switch (secLevel) { case SCRIPT_SECURITY_ALL_ACCESS: *aResult = PR_TRUE; @@ -118,12 +116,8 @@ nsJSSecurityManager::CheckScriptAccess(nsIScriptContext* aContext, void* aObj, void nsJSSecurityManager::InitCaps(void) { - if (nsnull == mCapsManager) { - return; - } - - nsresult res = nsServiceManager::GetService(kCCapsManagerCID, kICapsManagerIID, - (nsISupports**)&mCapsManager); + if (nsnull == mCapsManager) return; + nsresult res = nsServiceManager::GetService(kCCapsManagerCID, kICapsManagerIID, (nsISupports**)& mCapsManager); if ((NS_OK == res) && (nsnull != mCapsManager)) { mCapsManager->InitializeFrameWalker(this); } @@ -496,7 +490,7 @@ nsJSSecurityManager::PrincipalsCanAccessTarget(JSContext *aCx, PRInt16 aTarget) nsPrivilegeTable * annotation; JSStackFrame *fp; void *annotationRef; - void *principalArray = nsnull; + nsIPrincipalArray * principalArray = nsnull; #ifdef OJI JSStackFrame *pFrameToStartLooking = *JVM_GetStartJSFrameFromParallelStack(); JSStackFrame *pFrameToEndLooking = JVM_GetEndJSFrameFromParallelStack(pFrameToStartLooking); @@ -522,40 +516,30 @@ nsJSSecurityManager::PrincipalsCanAccessTarget(JSContext *aCx, PRInt16 aTarget) //NS_ASSERTION(aTarget < sizeof(targetStrings)/sizeof(targetStrings[0]), ""); /* Find annotation */ - annotationRef = nsnull; - principalArray = nsnull; - fp = pFrameToStartLooking; - while ((fp = JS_FrameIterator(aCx, &fp)) != pFrameToEndLooking) { - void *current; - if (JS_GetFrameScript(aCx, fp) == nsnull) - continue; - current = JS_GetFramePrincipalArray(aCx, fp); - if (current == nsnull) { - return PR_FALSE; - } - annotationRef = (void *) JS_GetFrameAnnotation(aCx, fp); - if (annotationRef) { - if (nsnull != principalArray) { - PRBool canExtend; - mCapsManager->CanExtendTrust(current, principalArray, &canExtend); - if (!canExtend) { - return PR_FALSE; - } - break; - } - } - if (nsnull != principalArray) { - mCapsManager->IntersectPrincipalArray(principalArray, current, &principalArray); - } - else { - principalArray = current; - } - } - - if (annotationRef) { - annotation = (nsPrivilegeTable *)annotationRef; - } - else { + annotationRef = nsnull; + principalArray = nsnull; + fp = pFrameToStartLooking; + while ((fp = JS_FrameIterator(aCx, &fp)) != pFrameToEndLooking) { + nsIPrincipalArray * current; + if (JS_GetFrameScript(aCx, fp) == nsnull) continue; + current = (nsIPrincipalArray *)JS_GetFramePrincipalArray(aCx, fp); + if (current == nsnull) return PR_FALSE; + annotationRef = (void *) JS_GetFrameAnnotation(aCx, fp); + if (annotationRef) { + if (principalArray != nsnull) { + PRBool canExtend; + nsIPrincipalManager * prinMan; + mCapsManager->GetPrincipalManager(& prinMan); + prinMan->CanExtendTrust(current, principalArray, & canExtend); + if (!canExtend) return PR_FALSE; + break; + } + } + if (principalArray != nsnull) current->IntersectPrincipalArray(principalArray,& principalArray); + else principalArray = current; + } + if (annotationRef) annotation = (nsPrivilegeTable *)annotationRef; + else { #ifdef OJI /* * Call from Java into JS. Just call the Java routine for checking @@ -1004,8 +988,8 @@ nsJSSecurityManager::SetDocumentDomain(JSContext *aCx, JSPrincipals *aPrincipals return NS_ERROR_FAILURE; } if (data->principalsArrayRef != nsnull) { - mCapsManager->FreePrincipalArray((void*)(data->principalsArrayRef)); - data->principalsArrayRef = nsnull; + ((nsIPrincipalArray *)data->principalsArrayRef)->FreePrincipalArray(); + data->principalsArrayRef = nsnull; } *aReturn = PR_TRUE; return NS_OK; @@ -1266,12 +1250,10 @@ DestroyJSPrincipals(JSContext *aCx, JSPrincipals *aPrincipals) } if (data->principalsArrayRef != nsnull) { /* XXX: raman: Should we free up the principals that are in that array also? */ - nsICapsManager* capsMan; - nsresult res = nsServiceManager::GetService(kCCapsManagerCID, kICapsManagerIID, - (nsISupports**)&capsMan); - + nsICapsManager * capsMan; + nsresult res = nsServiceManager::GetService(kCCapsManagerCID, kICapsManagerIID, (nsISupports**)&capsMan); if ((NS_OK == res) && (nsnull != capsMan)) { - capsMan->FreePrincipalArray((void*)(data->principalsArrayRef)); + ((nsIPrincipalArray *)data->principalsArrayRef)->FreePrincipalArray(); NS_RELEASE(capsMan); } } @@ -1287,8 +1269,7 @@ DestroyJSPrincipals(JSContext *aCx, JSPrincipals *aPrincipals) if (data->zip) //ns_zip_close(data->zip); - if (data->url) - NS_RELEASE(data->url); + if (data->url) NS_RELEASE(data->url); PR_Free(data); } } @@ -1300,18 +1281,16 @@ GetPrincipalArray(JSContext *aCx, struct JSPrincipals *aPrincipals) nsJSPrincipalsData *data = (nsJSPrincipalsData *)aPrincipals; //Get array of principals - if (data->principalsArrayRef == nsnull) { - nsICapsManager* capsMan; - nsresult res = nsServiceManager::GetService(kCCapsManagerCID, kICapsManagerIID, - (nsISupports**)&capsMan); - - if ((NS_OK == res) && (nsnull != capsMan)) { - capsMan->CreateMixedPrincipalArray(nsnull, nsnull, - aPrincipals->codebase, - (void**)&(data->principalsArrayRef)); - NS_RELEASE(capsMan); - } - } + if (data->principalsArrayRef == nsnull) { + nsICapsManager * capsMan; + nsresult res = nsServiceManager::GetService(kCCapsManagerCID, kICapsManagerIID, (nsISupports**)& capsMan); + if ((NS_OK == res) && (nsnull != capsMan)) { + nsIPrincipalManager * prinMan; + capsMan->GetPrincipalManager(& prinMan); +// prinMan->CreateMixedPrincipalArray(nsnull, nsnull, aPrincipals->codebase, (nsIPrincipalArray * *)&(data->principalsArrayRef)); + NS_RELEASE(capsMan); + } + } return data->principalsArrayRef; } @@ -1329,20 +1308,20 @@ GlobalPrivilegesEnabled(JSContext *aCx, JSPrincipals *aPrincipals) void nsJSSecurityManager::PrintPrincipalsToConsole(JSContext *aCx, JSPrincipals *aPrincipals) { - void *principalsArray; - nsIPrincipal *principal; + nsIPrincipalArray * principalsArray; + nsIPrincipal *principal; //cd .. char *vendor; PRUint32 i, count; static char emptyStr[] = "\n"; - principalsArray = aPrincipals->getPrincipalArray(aCx, aPrincipals); + principalsArray = (nsIPrincipalArray *)aPrincipals->getPrincipalArray(aCx, aPrincipals); if (principalsArray == nsnull) { PrintToConsole(emptyStr); return; } PrintToConsole("[\n"); - mCapsManager->GetPrincipalArraySize(principalsArray, &count); - for (i = 0; i < count; i++) { - mCapsManager->GetPrincipalArrayElement(principalsArray, i, &principal); + principalsArray->GetPrincipalArraySize(& count); + for (i = 0; i < count; i++) { + principalsArray->GetPrincipalArrayElement(i, & principal); // mCapsManager->GetVendor(principal, &vendor); // if (vendor == nsnull) { // JS_ReportOutOfMemory(aCx); @@ -1362,9 +1341,9 @@ nsJSSecurityManager::InvalidateCertPrincipals(JSContext *aCx, JSPrincipals *aPri if (data->principalsArrayRef) { PrintToConsole("Invalidating certificate principals in "); PrintPrincipalsToConsole(aCx, aPrincipals); - mCapsManager->FreePrincipalArray((void*)(data->principalsArrayRef)); - data->principalsArrayRef = nsnull; - } + ((nsIPrincipalArray *)data->principalsArrayRef)->FreePrincipalArray(); + data->principalsArrayRef = nsnull; + } data->signedness = HAS_UNSIGNED_SCRIPTS; } @@ -1397,6 +1376,9 @@ nsJSSecurityManager::FindOriginURL(JSContext *aCx, JSObject *aGlobal) PRBool nsJSSecurityManager::CanExtendTrust(JSContext *aCx, void *aFrom, void *aTo) { +// this code is already taken care of by nsPrivilegeManager, there is no need for the +//JSContext object, this needs to be reviewed and modified, i don't think this method +//should exist at all in this class if (aFrom == nsnull || aTo == nsnull) { return PR_FALSE; } @@ -1404,25 +1386,26 @@ nsJSSecurityManager::CanExtendTrust(JSContext *aCx, void *aFrom, void *aTo) return PR_TRUE; } - PRBool canExtend; - mCapsManager->CanExtendTrust(aFrom, aTo, &canExtend); - - return canExtend; + PRBool canExtend; + nsIPrincipalManager * prinMan; + mCapsManager->GetPrincipalManager(& prinMan); + prinMan->CanExtendTrust((nsIPrincipalArray *)aFrom,(nsIPrincipalArray *) aTo, &canExtend); + return canExtend; } PRUint32 nsJSSecurityManager::GetPrincipalsCount(JSContext *aCx, JSPrincipals *aPrincipals) { - void *principalArray; +// again, why??????? +// these methods are handled by nsIPrincipalArray, get rid of duplicates + nsIPrincipalArray * principalArray; PRUint32 count; - principalArray = aPrincipals->getPrincipalArray(aCx, aPrincipals); - if (nsnull == principalArray) { - return 0; - } - - mCapsManager->GetPrincipalArraySize(principalArray, &count); - return count; + principalArray = (nsIPrincipalArray *)aPrincipals->getPrincipalArray(aCx, aPrincipals); + // this check is already done in nsPrincipalArray +// if (nsnull == principalArray) return 0; + principalArray->GetPrincipalArraySize(& count); + return count; } char * @@ -1847,8 +1830,7 @@ nsJSSecurityManager::CheckEarlyAccess(JSContext* aCx, JSPrincipals *aPrincipals) * "principals". Return true iff the intersection is nonnsnull. */ PRBool -nsJSSecurityManager::IntersectPrincipals(JSContext *aCx, JSPrincipals *aPrincipals, - JSPrincipals *aNewPrincipals) +nsJSSecurityManager::IntersectPrincipals(JSContext *aCx, JSPrincipals *aPrincipals, JSPrincipals *aNewPrincipals) { nsJSPrincipalsData* data = (nsJSPrincipalsData*)aPrincipals; nsJSPrincipalsData* newData = (nsJSPrincipalsData*)aNewPrincipals; @@ -1872,23 +1854,19 @@ nsJSSecurityManager::IntersectPrincipals(JSContext *aCx, JSPrincipals *aPrincipa return PR_TRUE; } // Compute the intersection. - void* principalArray = aPrincipals->getPrincipalArray(aCx, aPrincipals); - void* newPrincipalArray = aNewPrincipals->getPrincipalArray(aCx, aNewPrincipals); - + nsIPrincipalArray * principalArray = (nsIPrincipalArray *)aPrincipals->getPrincipalArray(aCx, aPrincipals); + nsIPrincipalArray * newPrincipalArray = (nsIPrincipalArray *)aNewPrincipals->getPrincipalArray(aCx, aNewPrincipals); if (principalArray == nsnull || newPrincipalArray == nsnull) { InvalidateCertPrincipals(aCx, aPrincipals); return PR_TRUE; } - void* intersectArray; - mCapsManager->IntersectPrincipalArray(principalArray, - newPrincipalArray, - &intersectArray); - - if (nsnull == intersectArray) { - InvalidateCertPrincipals(aCx, aPrincipals); - return PR_TRUE; - } + nsIPrincipalArray * intersectArray; + principalArray->IntersectPrincipalArray(newPrincipalArray, & intersectArray); + if (nsnull == intersectArray) { + InvalidateCertPrincipals(aCx, aPrincipals); + return PR_TRUE; + } data->principalsArrayRef = intersectArray; return PR_TRUE; @@ -1907,13 +1885,12 @@ nsJSSecurityManager::PrincipalsEqual(JSContext *aCx, JSPrincipals *aPrinA, JSPri if (dataA->signedness != dataB->signedness) return PR_FALSE; - void* arrayA = aPrinA->getPrincipalArray(aCx, aPrinA); - void* arrayB = aPrinB->getPrincipalArray(aCx, aPrinB); + nsIPrincipalArray * arrayA = (nsIPrincipalArray *)aPrinA->getPrincipalArray(aCx, aPrinA); + nsIPrincipalArray * arrayB = (nsIPrincipalArray *)aPrinB->getPrincipalArray(aCx, aPrinB); - PRInt16 comparisonType; - mCapsManager->ComparePrincipalArray(arrayA, arrayB, & comparisonType); - - return (PRBool)(nsPrivilegeManager::SetComparisonType_Equal == comparisonType); + PRInt16 comparisonType; + arrayA->ComparePrincipalArray(arrayB, & comparisonType); + return (PRBool)(nsIPrincipalArray::SetComparisonType_Equal == comparisonType); } /******************************************************************************* @@ -1955,24 +1932,20 @@ nsJSSecurityManager::NewJSFrameIterator(void *aContext) PRBool nsJSSecurityManager::NextJSJavaFrame(struct nsJSFrameIterator *aIterator) { - void *current; - void *previous; - - if (aIterator->fp == 0) { - return PR_FALSE; - } - - current = JS_GetFramePrincipalArray(aIterator->cx, aIterator->fp); + nsIPrincipalArray * current; + nsIPrincipalArray * previous; + if (aIterator->fp == 0) return PR_FALSE; + current = (nsIPrincipalArray *)JS_GetFramePrincipalArray(aIterator->cx, aIterator->fp); if (current == nsnull) { if (JS_GetFrameScript(aIterator->cx, aIterator->fp)) aIterator->sawEmptyPrincipals = PR_TRUE; } else { - void* arrayIntersect; + nsIPrincipalArray * arrayIntersect; if (aIterator->intersect) { - previous = aIterator->intersect; - mCapsManager->IntersectPrincipalArray(current, previous, &arrayIntersect); + previous = (nsIPrincipalArray *)aIterator->intersect; + current->IntersectPrincipalArray(previous,& arrayIntersect); /* XXX: raman: should we do a free the previous principal Array */ - mCapsManager->FreePrincipalArray((void*)(aIterator->intersect)); + ((nsIPrincipalArray *)aIterator->intersect)->FreePrincipalArray(); } aIterator->intersect = current; } @@ -1985,14 +1958,13 @@ nsJSSecurityManager::NextJSFrame(struct nsJSFrameIterator **aIterator) { nsJSFrameIterator *iterator = *aIterator; PRBool result = NextJSJavaFrame(iterator); - if (!result) { - if (iterator->intersect) { - mCapsManager->FreePrincipalArray((void*)(iterator->intersect)); - } - PR_Free(iterator); - *aIterator = nsnull; - } - return result; + if (!result) { + if (iterator->intersect) + ((nsIPrincipalArray *)(* aIterator)->intersect)->FreePrincipalArray(); + PR_Free(iterator); + * aIterator = nsnull; + } + return result; } /** diff --git a/mozilla/dom/src/base/nsJSSecurityManager.h b/mozilla/dom/src/base/nsJSSecurityManager.h index c6a4dee8166..d58ae2c3588 100644 --- a/mozilla/dom/src/base/nsJSSecurityManager.h +++ b/mozilla/dom/src/base/nsJSSecurityManager.h @@ -24,8 +24,7 @@ #include "nsIXPCSecurityManager.h" #include "nsIScriptSecurityManager.h" #include "nsICapsSecurityCallbacks.h" - -class nsICapsManager; +#include "nsICapsManager.h" class nsIPref; typedef struct nsJSFrameIterator { @@ -181,7 +180,7 @@ private: //Local vars nsIPref* mPrefs; - nsICapsManager* mCapsManager; + nsICapsManager * mCapsManager; }; //XXX temporarily bit flags for determining what we want to parse from the URL