2002-02-20 08:51:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2001-09-25 05:03:58 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-08-20 13:51:02 +04:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1999-08-20 13:51:02 +04:00
|
|
|
*
|
2001-09-25 05:03:58 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-08-20 13:51:02 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 05:03:58 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998-2000
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:43:54 +03:00
|
|
|
*
|
2001-09-25 05:03:58 +04:00
|
|
|
* Contributor(s):
|
2004-04-18 01:52:36 +04:00
|
|
|
* Norris Boyd <nboyd@atg.com>
|
|
|
|
* Mitch Stoltz <mstoltz@netscape.com>
|
|
|
|
* Christopher A. Aillon <christopher@aillon.com>
|
2005-07-20 01:55:36 +04:00
|
|
|
* Giorgio Maone <g.maone@informaction.com>
|
2001-09-25 05:03:58 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 01:52:36 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 05:03:58 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 01:52:36 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 05:03:58 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 01:52:36 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 05:03:58 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2000-02-10 07:56:56 +03:00
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
#ifndef nsScriptSecurityManager_h__
|
|
|
|
#define nsScriptSecurityManager_h__
|
1999-08-20 13:51:02 +04:00
|
|
|
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "jsapi.h"
|
2000-04-14 07:14:53 +04:00
|
|
|
#include "jsdbgapi.h"
|
1999-09-07 06:54:19 +04:00
|
|
|
#include "nsIXPCSecurityManager.h"
|
2003-10-22 02:11:49 +04:00
|
|
|
#include "nsInterfaceHashtable.h"
|
1999-11-12 01:10:36 +03:00
|
|
|
#include "nsHashtable.h"
|
2000-01-19 00:54:01 +03:00
|
|
|
#include "nsCOMPtr.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
#include "nsIPrefService.h"
|
2000-07-26 08:53:01 +04:00
|
|
|
#include "nsISecurityPref.h"
|
2005-11-08 23:47:16 +03:00
|
|
|
#include "nsIChannelEventSink.h"
|
2000-08-22 10:02:14 +04:00
|
|
|
#include "nsIJSContextStack.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
#include "nsIObserver.h"
|
2002-02-13 07:20:46 +03:00
|
|
|
#include "pldhash.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "plstr.h"
|
2000-08-22 10:02:14 +04:00
|
|
|
|
2001-03-23 07:22:56 +03:00
|
|
|
class nsIDocShell;
|
2001-04-17 05:21:44 +04:00
|
|
|
class nsString;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
class nsIClassInfo;
|
2003-10-22 02:11:49 +04:00
|
|
|
class nsIIOService;
|
|
|
|
class nsIXPConnect;
|
2003-07-29 09:28:00 +04:00
|
|
|
class nsIStringBundle;
|
2001-08-07 07:59:29 +04:00
|
|
|
class nsSystemPrincipal;
|
2002-02-13 07:20:46 +03:00
|
|
|
struct ClassPolicy;
|
2005-10-21 03:49:59 +04:00
|
|
|
class ClassInfoData;
|
2006-02-24 07:38:46 +03:00
|
|
|
class DomainPolicy;
|
2001-03-23 07:22:56 +03:00
|
|
|
|
2004-07-10 23:38:28 +04:00
|
|
|
#if defined(DEBUG_mstoltz) || defined(DEBUG_caillon)
|
2003-10-22 02:11:49 +04:00
|
|
|
#define DEBUG_CAPS_HACKER
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG_CAPS_HACKER
|
|
|
|
#define DEBUG_CAPS_CheckPropertyAccessImpl
|
|
|
|
#define DEBUG_CAPS_LookupPolicy
|
|
|
|
#define DEBUG_CAPS_CheckComponentPermissions
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#define DEBUG_CAPS_CanCreateWrapper
|
|
|
|
#define DEBUG_CAPS_CanCreateInstance
|
|
|
|
#define DEBUG_CAPS_CanGetService
|
2005-07-20 01:55:36 +04:00
|
|
|
#define DEBUG_CAPS_DomainPolicyLifeCycle
|
2003-10-22 02:11:49 +04:00
|
|
|
#endif
|
|
|
|
|
2000-03-21 07:05:35 +03:00
|
|
|
/////////////////////
|
2003-10-22 02:11:49 +04:00
|
|
|
// PrincipalKey //
|
2000-03-21 07:05:35 +03:00
|
|
|
/////////////////////
|
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
class PrincipalKey : public PLDHashEntryHdr
|
2003-07-24 09:15:20 +04:00
|
|
|
{
|
2000-03-21 07:05:35 +03:00
|
|
|
public:
|
2003-10-22 02:11:49 +04:00
|
|
|
typedef const nsIPrincipal* KeyType;
|
|
|
|
typedef const nsIPrincipal* KeyTypePointer;
|
|
|
|
|
|
|
|
PrincipalKey(const nsIPrincipal* key)
|
|
|
|
: mKey(NS_CONST_CAST(nsIPrincipal*, key))
|
|
|
|
{
|
2000-03-21 07:05:35 +03:00
|
|
|
}
|
2003-10-22 02:11:49 +04:00
|
|
|
|
|
|
|
PrincipalKey(const PrincipalKey& toCopy)
|
|
|
|
: mKey(toCopy.mKey)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~PrincipalKey()
|
|
|
|
{
|
2000-03-21 07:05:35 +03:00
|
|
|
}
|
2003-10-22 02:11:49 +04:00
|
|
|
|
|
|
|
KeyType GetKey() const
|
|
|
|
{
|
|
|
|
return mKey;
|
2003-07-24 09:15:20 +04:00
|
|
|
}
|
2003-10-22 02:11:49 +04:00
|
|
|
|
|
|
|
KeyTypePointer GetKeyPointer() const
|
|
|
|
{
|
|
|
|
return mKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool KeyEquals(KeyTypePointer aKey) const
|
|
|
|
{
|
2000-03-21 07:05:35 +03:00
|
|
|
PRBool eq;
|
2003-10-22 02:11:49 +04:00
|
|
|
mKey->Equals(NS_CONST_CAST(nsIPrincipal*, aKey),
|
|
|
|
&eq);
|
2000-03-21 07:05:35 +03:00
|
|
|
return eq;
|
|
|
|
}
|
2003-10-22 02:11:49 +04:00
|
|
|
|
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey)
|
|
|
|
{
|
|
|
|
return aKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PLDHashNumber HashKey(KeyTypePointer aKey)
|
|
|
|
{
|
|
|
|
PRUint32 hash;
|
|
|
|
NS_CONST_CAST(nsIPrincipal*, aKey)->GetHashValue(&hash);
|
|
|
|
return PLDHashNumber(hash);
|
2003-07-24 09:15:20 +04:00
|
|
|
}
|
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
enum { ALLOW_MEMMOVE = PR_TRUE };
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIPrincipal> mKey;
|
2000-03-21 07:05:35 +03:00
|
|
|
};
|
|
|
|
|
2002-02-13 07:20:46 +03:00
|
|
|
////////////////////
|
|
|
|
// Policy Storage //
|
|
|
|
////////////////////
|
|
|
|
|
|
|
|
// Property Policy
|
|
|
|
union SecurityLevel
|
|
|
|
{
|
2004-06-16 19:58:22 +04:00
|
|
|
PRInt32 level;
|
2002-02-13 07:20:46 +03:00
|
|
|
char* capability;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Security levels
|
|
|
|
// These values all have the low bit set (except UNDEFINED_ACCESS)
|
|
|
|
// to distinguish them from pointer values, because no pointer
|
|
|
|
// to allocated memory ever has the low bit set. A SecurityLevel
|
|
|
|
// contains either one of these constants or a pointer to a string
|
|
|
|
// representing the name of a capability.
|
|
|
|
|
|
|
|
#define SCRIPT_SECURITY_UNDEFINED_ACCESS 0
|
|
|
|
#define SCRIPT_SECURITY_ACCESS_IS_SET_BIT 1
|
|
|
|
#define SCRIPT_SECURITY_NO_ACCESS \
|
|
|
|
((1 << 0) | SCRIPT_SECURITY_ACCESS_IS_SET_BIT)
|
|
|
|
#define SCRIPT_SECURITY_SAME_ORIGIN_ACCESS \
|
|
|
|
((1 << 1) | SCRIPT_SECURITY_ACCESS_IS_SET_BIT)
|
|
|
|
#define SCRIPT_SECURITY_ALL_ACCESS \
|
|
|
|
((1 << 2) | SCRIPT_SECURITY_ACCESS_IS_SET_BIT)
|
|
|
|
|
|
|
|
#define SECURITY_ACCESS_LEVEL_FLAG(_sl) \
|
|
|
|
((_sl.level == 0) || \
|
|
|
|
(_sl.level & SCRIPT_SECURITY_ACCESS_IS_SET_BIT))
|
|
|
|
|
|
|
|
|
|
|
|
struct PropertyPolicy : public PLDHashEntryHdr
|
|
|
|
{
|
|
|
|
jsval key; // property name as jsval
|
|
|
|
SecurityLevel mGet;
|
|
|
|
SecurityLevel mSet;
|
|
|
|
};
|
|
|
|
|
2003-08-06 00:09:21 +04:00
|
|
|
PR_STATIC_CALLBACK(PRBool)
|
2002-02-13 07:20:46 +03:00
|
|
|
InitPropertyPolicyEntry(PLDHashTable *table,
|
|
|
|
PLDHashEntryHdr *entry,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
PropertyPolicy* pp = (PropertyPolicy*)entry;
|
|
|
|
pp->key = (jsval)key;
|
|
|
|
pp->mGet.level = SCRIPT_SECURITY_UNDEFINED_ACCESS;
|
|
|
|
pp->mSet.level = SCRIPT_SECURITY_UNDEFINED_ACCESS;
|
2003-08-06 00:09:21 +04:00
|
|
|
return PR_TRUE;
|
2002-02-13 07:20:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(void)
|
|
|
|
ClearPropertyPolicyEntry(PLDHashTable *table, PLDHashEntryHdr *entry)
|
|
|
|
{
|
|
|
|
PropertyPolicy* pp = (PropertyPolicy*)entry;
|
|
|
|
pp->key = JSVAL_VOID;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Class Policy
|
|
|
|
#define NO_POLICY_FOR_CLASS (ClassPolicy*)1
|
|
|
|
|
|
|
|
struct ClassPolicy : public PLDHashEntryHdr
|
|
|
|
{
|
2003-08-06 00:09:21 +04:00
|
|
|
char* key;
|
2002-03-20 08:53:46 +03:00
|
|
|
PLDHashTable* mPolicy;
|
2006-02-24 07:38:46 +03:00
|
|
|
|
|
|
|
// Note: the DomainPolicy owns us, so if if dies we will too. Hence no
|
|
|
|
// need to refcount it here (and in fact, we'd probably leak if we tried).
|
|
|
|
DomainPolicy* mDomainWeAreWildcardFor;
|
2002-02-13 07:20:46 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(void)
|
|
|
|
ClearClassPolicyEntry(PLDHashTable *table, PLDHashEntryHdr *entry)
|
|
|
|
{
|
|
|
|
ClassPolicy* cp = (ClassPolicy *)entry;
|
|
|
|
if (cp->key)
|
|
|
|
{
|
|
|
|
PL_strfree(cp->key);
|
|
|
|
cp->key = nsnull;
|
|
|
|
}
|
2002-03-20 08:53:46 +03:00
|
|
|
PL_DHashTableDestroy(cp->mPolicy);
|
2002-02-13 07:20:46 +03:00
|
|
|
}
|
|
|
|
|
2006-02-24 07:38:46 +03:00
|
|
|
// Note: actual impl is going to be after the DomainPolicy class definition,
|
|
|
|
// since we need to access members of DomainPolicy in the impl
|
|
|
|
PR_STATIC_CALLBACK(void)
|
|
|
|
MoveClassPolicyEntry(PLDHashTable *table,
|
|
|
|
const PLDHashEntryHdr *from,
|
|
|
|
PLDHashEntryHdr *to);
|
|
|
|
|
2003-08-06 00:09:21 +04:00
|
|
|
PR_STATIC_CALLBACK(PRBool)
|
2002-02-13 07:20:46 +03:00
|
|
|
InitClassPolicyEntry(PLDHashTable *table,
|
|
|
|
PLDHashEntryHdr *entry,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
static PLDHashTableOps classPolicyOps =
|
|
|
|
{
|
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
PL_DHashGetKeyStub,
|
|
|
|
PL_DHashVoidPtrKeyStub,
|
|
|
|
PL_DHashMatchEntryStub,
|
|
|
|
PL_DHashMoveEntryStub,
|
|
|
|
ClearPropertyPolicyEntry,
|
|
|
|
PL_DHashFinalizeStub,
|
|
|
|
InitPropertyPolicyEntry
|
|
|
|
};
|
|
|
|
|
|
|
|
ClassPolicy* cp = (ClassPolicy*)entry;
|
2006-02-24 07:38:46 +03:00
|
|
|
cp->mDomainWeAreWildcardFor = nsnull;
|
2002-02-13 07:20:46 +03:00
|
|
|
cp->key = PL_strdup((const char*)key);
|
2003-08-06 00:09:21 +04:00
|
|
|
if (!cp->key)
|
|
|
|
return PR_FALSE;
|
2002-03-20 08:53:46 +03:00
|
|
|
cp->mPolicy = PL_NewDHashTable(&classPolicyOps, nsnull,
|
2003-08-06 00:09:21 +04:00
|
|
|
sizeof(PropertyPolicy), 16);
|
|
|
|
if (!cp->mPolicy) {
|
|
|
|
PL_strfree(cp->key);
|
|
|
|
cp->key = nsnull;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
2002-02-13 07:20:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Domain Policy
|
|
|
|
class DomainPolicy : public PLDHashTable
|
|
|
|
{
|
|
|
|
public:
|
2003-06-26 04:18:43 +04:00
|
|
|
DomainPolicy() : mWildcardPolicy(nsnull),
|
|
|
|
mRefCount(0)
|
2002-02-13 07:20:46 +03:00
|
|
|
{
|
2005-06-29 20:29:49 +04:00
|
|
|
mGeneration = sGeneration;
|
|
|
|
|
|
|
|
#ifdef DEBUG_CAPS_DomainPolicyLifeCycle
|
|
|
|
++sObjects;
|
|
|
|
_printPopulationInfo();
|
|
|
|
#endif
|
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool Init()
|
|
|
|
{
|
|
|
|
static const PLDHashTableOps domainPolicyOps =
|
2002-02-13 07:20:46 +03:00
|
|
|
{
|
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
PL_DHashGetKeyStub,
|
|
|
|
PL_DHashStringKey,
|
2003-08-06 00:09:21 +04:00
|
|
|
PL_DHashMatchStringKey,
|
2006-02-24 07:38:46 +03:00
|
|
|
MoveClassPolicyEntry,
|
2002-02-13 07:20:46 +03:00
|
|
|
ClearClassPolicyEntry,
|
|
|
|
PL_DHashFinalizeStub,
|
|
|
|
InitClassPolicyEntry
|
|
|
|
};
|
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
return PL_DHashTableInit(this, &domainPolicyOps, nsnull,
|
|
|
|
sizeof(ClassPolicy), 16);
|
2002-02-13 07:20:46 +03:00
|
|
|
}
|
|
|
|
|
2002-03-10 03:41:08 +03:00
|
|
|
~DomainPolicy()
|
|
|
|
{
|
|
|
|
PL_DHashTableFinish(this);
|
2005-07-20 01:55:36 +04:00
|
|
|
NS_ASSERTION(mRefCount == 0, "Wrong refcount in DomainPolicy dtor");
|
2005-06-29 20:29:49 +04:00
|
|
|
#ifdef DEBUG_CAPS_DomainPolicyLifeCycle
|
2005-07-20 01:55:36 +04:00
|
|
|
printf("DomainPolicy deleted with mRefCount = %d\n", mRefCount);
|
2005-06-29 20:29:49 +04:00
|
|
|
--sObjects;
|
|
|
|
_printPopulationInfo();
|
|
|
|
#endif
|
|
|
|
|
2002-03-10 03:41:08 +03:00
|
|
|
}
|
|
|
|
|
2002-02-13 07:20:46 +03:00
|
|
|
void Hold()
|
|
|
|
{
|
|
|
|
mRefCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drop()
|
|
|
|
{
|
|
|
|
if (--mRefCount == 0)
|
|
|
|
delete this;
|
|
|
|
}
|
2005-06-29 20:29:49 +04:00
|
|
|
|
|
|
|
static void InvalidateAll()
|
|
|
|
{
|
|
|
|
sGeneration++;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool IsInvalid()
|
|
|
|
{
|
|
|
|
return mGeneration != sGeneration;
|
|
|
|
}
|
|
|
|
|
2003-06-26 04:18:43 +04:00
|
|
|
ClassPolicy* mWildcardPolicy;
|
|
|
|
|
2002-02-13 07:20:46 +03:00
|
|
|
private:
|
|
|
|
PRUint32 mRefCount;
|
2005-06-29 20:29:49 +04:00
|
|
|
PRUint32 mGeneration;
|
|
|
|
static PRUint32 sGeneration;
|
|
|
|
|
|
|
|
#ifdef DEBUG_CAPS_DomainPolicyLifeCycle
|
|
|
|
static PRUint32 sObjects;
|
|
|
|
static void _printPopulationInfo();
|
|
|
|
#endif
|
|
|
|
|
2002-02-13 07:20:46 +03:00
|
|
|
};
|
|
|
|
|
2006-02-24 07:38:46 +03:00
|
|
|
PR_STATIC_CALLBACK(void)
|
|
|
|
MoveClassPolicyEntry(PLDHashTable *table,
|
|
|
|
const PLDHashEntryHdr *from,
|
|
|
|
PLDHashEntryHdr *to)
|
|
|
|
{
|
|
|
|
memcpy(to, from, table->entrySize);
|
|
|
|
|
|
|
|
// Now update the mDefaultPolicy pointer that points to us, if any.
|
|
|
|
ClassPolicy* cp = NS_STATIC_CAST(ClassPolicy*, to);
|
|
|
|
if (cp->mDomainWeAreWildcardFor) {
|
|
|
|
NS_ASSERTION(cp->mDomainWeAreWildcardFor->mWildcardPolicy ==
|
|
|
|
NS_STATIC_CAST(const ClassPolicy*, from),
|
|
|
|
"Unexpected wildcard policy on mDomainWeAreWildcardFor");
|
|
|
|
cp->mDomainWeAreWildcardFor->mWildcardPolicy = cp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-13 07:20:46 +03:00
|
|
|
/////////////////////////////
|
|
|
|
// nsScriptSecurityManager //
|
|
|
|
/////////////////////////////
|
1999-08-20 13:51:02 +04:00
|
|
|
#define NS_SCRIPTSECURITYMANAGER_CID \
|
|
|
|
{ 0x7ee2a4c0, 0x4b93, 0x17d3, \
|
|
|
|
{ 0xba, 0x18, 0x00, 0x60, 0xb0, 0xf1, 0x99, 0xa2 }}
|
|
|
|
|
2002-02-13 07:20:46 +03:00
|
|
|
class nsScriptSecurityManager : public nsIScriptSecurityManager,
|
2005-02-06 15:39:31 +03:00
|
|
|
public nsIPrefSecurityCheck,
|
2005-11-08 23:47:16 +03:00
|
|
|
public nsIChannelEventSink,
|
2002-02-13 07:20:46 +03:00
|
|
|
public nsIObserver
|
1999-09-07 06:54:19 +04:00
|
|
|
{
|
1999-08-20 13:51:02 +04:00
|
|
|
public:
|
2002-02-13 07:20:46 +03:00
|
|
|
static void Shutdown();
|
1999-08-30 01:58:42 +04:00
|
|
|
|
|
|
|
NS_DEFINE_STATIC_CID_ACCESSOR(NS_SCRIPTSECURITYMANAGER_CID)
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISCRIPTSECURITYMANAGER
|
1999-09-07 06:54:19 +04:00
|
|
|
NS_DECL_NSIXPCSECURITYMANAGER
|
2005-02-06 15:39:31 +03:00
|
|
|
NS_DECL_NSIPREFSECURITYCHECK
|
2005-11-08 23:47:16 +03:00
|
|
|
NS_DECL_NSICHANNELEVENTSINK
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_DECL_NSIOBSERVER
|
2001-04-17 05:21:44 +04:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
static nsScriptSecurityManager*
|
1999-08-30 01:58:42 +04:00
|
|
|
GetScriptSecurityManager();
|
2000-08-22 10:02:14 +04:00
|
|
|
|
2001-08-07 07:59:29 +04:00
|
|
|
static nsSystemPrincipal*
|
|
|
|
SystemPrincipalSingletonConstructor();
|
|
|
|
|
2002-02-13 07:20:46 +03:00
|
|
|
JSContext* GetCurrentJSContext();
|
|
|
|
|
|
|
|
JSContext* GetSafeJSContext();
|
2001-04-17 05:21:44 +04:00
|
|
|
|
1999-08-20 13:51:02 +04:00
|
|
|
private:
|
2000-01-19 00:54:01 +03:00
|
|
|
|
2003-01-17 05:00:01 +03:00
|
|
|
// GetScriptSecurityManager is the only call that can make one
|
|
|
|
nsScriptSecurityManager();
|
|
|
|
virtual ~nsScriptSecurityManager();
|
|
|
|
|
2002-02-13 16:30:06 +03:00
|
|
|
static JSBool JS_DLL_CALLBACK
|
2003-03-06 22:40:14 +03:00
|
|
|
CheckObjectAccess(JSContext *cx, JSObject *obj,
|
|
|
|
jsval id, JSAccessMode mode,
|
|
|
|
jsval *vp);
|
2002-02-13 07:20:46 +03:00
|
|
|
|
2005-04-11 03:27:07 +04:00
|
|
|
// Returns null if a principal cannot be found; generally callers
|
|
|
|
// should error out at that point.
|
|
|
|
static nsIPrincipal*
|
2006-05-04 19:23:43 +04:00
|
|
|
doGetObjectPrincipal(JSContext *cx, JSObject *obj,
|
|
|
|
PRBool aAllowShortCircuit = PR_FALSE);
|
2005-04-11 03:27:07 +04:00
|
|
|
|
|
|
|
// Returns null if a principal cannot be found. Note that rv can be NS_OK
|
|
|
|
// when this happens -- this means that there was no JS running.
|
|
|
|
nsIPrincipal*
|
|
|
|
doGetSubjectPrincipal(nsresult* rv);
|
|
|
|
|
2004-10-15 20:53:35 +04:00
|
|
|
static nsresult
|
|
|
|
GetBaseURIScheme(nsIURI* aURI, nsCString& aScheme);
|
2001-08-03 00:32:48 +04:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
static nsresult
|
2002-06-15 03:54:18 +04:00
|
|
|
ReportError(JSContext* cx, const nsAString& messageTag,
|
|
|
|
nsIURI* aSource, nsIURI* aTarget);
|
2001-01-27 04:42:20 +03:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
nsresult
|
2002-02-13 07:20:46 +03:00
|
|
|
CheckPropertyAccessImpl(PRUint32 aAction,
|
|
|
|
nsIXPCNativeCallContext* aCallContext,
|
|
|
|
JSContext* cx, JSObject* aJSObject,
|
2001-05-19 04:33:51 +04:00
|
|
|
nsISupports* aObj, nsIURI* aTargetURI,
|
|
|
|
nsIClassInfo* aClassInfo,
|
2002-02-13 07:20:46 +03:00
|
|
|
const char* aClassName, jsval aProperty,
|
|
|
|
void** aCachedClassPolicy);
|
1999-08-30 01:58:42 +04:00
|
|
|
|
2003-06-19 03:48:57 +04:00
|
|
|
nsresult
|
|
|
|
CheckSameOriginPrincipalInternal(nsIPrincipal* aSubject,
|
|
|
|
nsIPrincipal* aObject,
|
|
|
|
PRBool aIsCheckConnect);
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
nsresult
|
2002-06-15 03:54:18 +04:00
|
|
|
CheckSameOriginDOMProp(nsIPrincipal* aSubject,
|
|
|
|
nsIPrincipal* aObject,
|
2003-05-29 03:22:36 +04:00
|
|
|
PRUint32 aAction,
|
|
|
|
PRBool aIsCheckConnect);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
|
|
|
nsresult
|
2003-06-26 04:18:43 +04:00
|
|
|
LookupPolicy(nsIPrincipal* principal,
|
2005-10-21 03:49:59 +04:00
|
|
|
ClassInfoData& aClassData, jsval aProperty,
|
2003-06-26 04:18:43 +04:00
|
|
|
PRUint32 aAction,
|
|
|
|
ClassPolicy** aCachedClassPolicy,
|
|
|
|
SecurityLevel* result);
|
1999-08-30 01:58:42 +04:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
nsresult
|
|
|
|
CreateCodebasePrincipal(nsIURI* aURI, nsIPrincipal** result);
|
|
|
|
|
2005-07-22 23:05:42 +04:00
|
|
|
// This is just like the API method, but it doesn't check that the subject
|
2005-07-23 00:49:12 +04:00
|
|
|
// name is non-empty or aCertificate is non-null, and it doesn't change the
|
2005-07-22 23:05:42 +04:00
|
|
|
// certificate in the table (if any) in any way if aModifyTable is false.
|
|
|
|
nsresult
|
|
|
|
DoGetCertificatePrincipal(const nsACString& aCertFingerprint,
|
|
|
|
const nsACString& aSubjectName,
|
|
|
|
const nsACString& aPrettyName,
|
|
|
|
nsISupports* aCertificate,
|
|
|
|
nsIURI* aURI,
|
|
|
|
PRBool aModifyTable,
|
|
|
|
nsIPrincipal **result);
|
|
|
|
|
2005-04-11 03:27:07 +04:00
|
|
|
// Returns null if a principal cannot be found. Note that rv can be NS_OK
|
|
|
|
// when this happens -- this means that there was no script for the
|
|
|
|
// context. Callers MUST pass in a non-null rv here.
|
|
|
|
static nsIPrincipal*
|
|
|
|
GetSubjectPrincipal(JSContext* cx, nsresult* rv);
|
|
|
|
|
|
|
|
// Returns null if a principal cannot be found. Note that rv can be NS_OK
|
|
|
|
// when this happens -- this means that there was no script for the frame.
|
|
|
|
// Callers MUST pass in a non-null rv here.
|
|
|
|
static nsIPrincipal*
|
|
|
|
GetFramePrincipal(JSContext* cx, JSStackFrame* fp, nsresult* rv);
|
2000-04-14 07:14:53 +04:00
|
|
|
|
2005-04-11 03:27:07 +04:00
|
|
|
// Returns null if a principal cannot be found. Note that rv can be NS_OK
|
|
|
|
// when this happens -- this means that there was no script. Callers MUST
|
|
|
|
// pass in a non-null rv here.
|
|
|
|
static nsIPrincipal*
|
|
|
|
GetScriptPrincipal(JSContext* cx, JSScript* script, nsresult* rv);
|
|
|
|
|
|
|
|
// Returns null if a principal cannot be found. Note that rv can be NS_OK
|
|
|
|
// when this happens -- this means that there was no script associated
|
2005-05-04 10:28:36 +04:00
|
|
|
// with the function object, and no global object associated with the scope
|
|
|
|
// of obj (the last object on its parent chain). If the caller is walking
|
|
|
|
// the JS stack, fp must point to the current frame in the stack iteration.
|
|
|
|
// Callers MUST pass in a non-null rv here.
|
2005-04-11 03:27:07 +04:00
|
|
|
static nsIPrincipal*
|
2005-05-04 10:28:36 +04:00
|
|
|
GetFunctionObjectPrincipal(JSContext* cx, JSObject* obj, JSStackFrame *fp,
|
|
|
|
nsresult* rv);
|
2005-04-11 03:27:07 +04:00
|
|
|
|
|
|
|
// Returns null if a principal cannot be found. Note that rv can be NS_OK
|
|
|
|
// when this happens -- this means that there was no script
|
|
|
|
// running. Callers MUST pass in a non-null rv here.
|
|
|
|
static nsIPrincipal*
|
2001-05-11 04:43:27 +04:00
|
|
|
GetPrincipalAndFrame(JSContext *cx,
|
2005-04-11 03:27:07 +04:00
|
|
|
JSStackFrame** frameResult,
|
|
|
|
nsresult* rv);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
2002-03-20 08:53:46 +03:00
|
|
|
static PRBool
|
2003-07-29 09:28:00 +04:00
|
|
|
CheckConfirmDialog(JSContext* cx, nsIPrincipal* aPrincipal,
|
|
|
|
const char* aCapability, PRBool *checkValue);
|
2002-03-20 08:53:46 +03:00
|
|
|
|
2004-09-01 11:53:32 +04:00
|
|
|
static void
|
|
|
|
FormatCapabilityString(nsAString& aCapability);
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
nsresult
|
2000-04-26 07:50:07 +04:00
|
|
|
SavePrincipal(nsIPrincipal* aToSave);
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
nsresult
|
2001-08-14 04:18:58 +04:00
|
|
|
CheckXPCPermissions(nsISupports* aObj,
|
|
|
|
const char* aObjectSecurityLevel);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
2003-01-17 05:00:01 +03:00
|
|
|
nsresult
|
|
|
|
Init();
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
nsresult
|
|
|
|
InitPrefs();
|
2000-11-30 08:32:08 +03:00
|
|
|
|
2000-05-16 07:40:51 +04:00
|
|
|
static nsresult
|
2005-07-22 23:05:42 +04:00
|
|
|
GetPrincipalPrefNames(const char* prefBase,
|
|
|
|
nsCString& grantedPref,
|
|
|
|
nsCString& deniedPref,
|
|
|
|
nsCString& subjectNamePref);
|
2000-05-16 07:40:51 +04:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
nsresult
|
2002-02-13 07:20:46 +03:00
|
|
|
InitPolicies();
|
|
|
|
|
|
|
|
nsresult
|
2002-03-20 08:53:46 +03:00
|
|
|
InitDomainPolicy(JSContext* cx, const char* aPolicyName,
|
2002-02-13 07:20:46 +03:00
|
|
|
DomainPolicy* aDomainPolicy);
|
1999-11-25 08:28:18 +03:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
nsresult
|
2001-08-03 00:32:48 +04:00
|
|
|
InitPrincipals(PRUint32 prefCount, const char** prefNames,
|
|
|
|
nsISecurityPref* securityPref);
|
2000-01-19 00:54:01 +03:00
|
|
|
|
2003-03-12 05:17:37 +03:00
|
|
|
#ifdef XPC_IDISPATCH_SUPPORT
|
|
|
|
// While this header is included outside of caps, this class isn't
|
|
|
|
// referenced so this should be fine.
|
|
|
|
nsresult
|
|
|
|
CheckComponentPermissions(JSContext *cx, const nsCID &aCID);
|
|
|
|
#endif
|
2003-10-22 02:11:49 +04:00
|
|
|
#ifdef DEBUG_CAPS_HACKER
|
2002-02-13 07:20:46 +03:00
|
|
|
void
|
|
|
|
PrintPolicyDB();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// JS strings we need to clean up on shutdown
|
|
|
|
static jsval sEnabledID;
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
inline void
|
2001-08-03 00:32:48 +04:00
|
|
|
JSEnabledPrefChanged(nsISecurityPref* aSecurityPref);
|
2000-01-06 03:59:18 +03:00
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
static const char sJSEnabledPrefName[];
|
|
|
|
static const char sJSMailEnabledPrefName[];
|
2000-02-10 07:56:56 +03:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
nsObjectHashtable* mOriginToPolicyMap;
|
2002-02-13 07:20:46 +03:00
|
|
|
DomainPolicy* mDefaultPolicy;
|
|
|
|
nsObjectHashtable* mCapabilities;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrefBranch> mPrefBranch;
|
|
|
|
nsCOMPtr<nsISecurityPref> mSecurityPref;
|
2003-10-22 02:11:49 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> mSystemPrincipal;
|
2000-04-26 07:50:07 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> mSystemCertificate;
|
2003-10-22 02:11:49 +04:00
|
|
|
nsInterfaceHashtable<PrincipalKey, nsIPrincipal> mPrincipals;
|
2002-02-13 07:20:46 +03:00
|
|
|
nsCOMPtr<nsIThreadJSContextStack> mJSContextStack;
|
2003-10-22 02:11:49 +04:00
|
|
|
PRPackedBool mIsJavaScriptEnabled;
|
|
|
|
PRPackedBool mIsMailJavaScriptEnabled;
|
|
|
|
PRPackedBool mIsWritingPrefs;
|
|
|
|
PRPackedBool mPolicyPrefsChanged;
|
2003-03-12 05:17:37 +03:00
|
|
|
#ifdef XPC_IDISPATCH_SUPPORT
|
2003-10-22 02:11:49 +04:00
|
|
|
PRPackedBool mXPCDefaultGrantAll;
|
|
|
|
static const char sXPCDefaultGrantAllName[];
|
2003-03-12 05:17:37 +03:00
|
|
|
#endif
|
1999-10-29 02:09:03 +04:00
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
static nsIIOService *sIOService;
|
|
|
|
static nsIXPConnect *sXPConnect;
|
2003-07-29 09:28:00 +04:00
|
|
|
static nsIStringBundle *sStrBundle;
|
2005-06-08 01:57:56 +04:00
|
|
|
static JSRuntime *sRuntime;
|
2003-07-24 09:15:20 +04:00
|
|
|
};
|
2003-10-22 02:11:49 +04:00
|
|
|
|
|
|
|
#endif // nsScriptSecurityManager_h__
|