xpidling and updating nsTarget object. should resolve build errors on

SeaMonkey Ports
This commit is contained in:
arielb%netscape.com 1999-07-28 05:43:26 +00:00
Родитель 57eb2bf334
Коммит 944fa42b7b
23 изменённых файлов: 371 добавлений и 900 удалений

Просмотреть файл

@ -2,3 +2,4 @@ nsIPrincipal.idl
nsIScriptSecurityManager.idl
nsICapsSecurityCallbacks.idl
nsIPrivilege.idl
nsITarget.idl

Просмотреть файл

@ -29,6 +29,7 @@ XPIDLSRCS = \
nsICapsSecurityCallbacks.idl \
nsIPrincipal.idl \
nsIPrivilege.idl \
nsITarget.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -24,6 +24,7 @@ XPIDLSRCS= \
.\nsICapsSecurityCallbacks.idl \
.\nsIPrincipal.idl \
.\nsIPrivilege.idl \
.\nsITarget.idl \
$(NULL)
include <$(DEPTH)\config\rules.mak>

0
caps/idl/nsITarget.idl Normal file
Просмотреть файл

Просмотреть файл

@ -71,7 +71,7 @@ CreateCodeSourcePrincipal(const unsigned char **certChain, PRUint32 *certChainLe
* @param state - the return value is passed in this parameter.
*/
NS_IMETHOD
GetPermission(nsIPrincipal * prin, nsTarget * target, PRInt16 * privilegeState);
GetPermission(nsIPrincipal * prin, nsITarget * target, PRInt16 * privilegeState);
/**
* Set the permission state for given principal and target. This wouldn't
@ -83,7 +83,7 @@ GetPermission(nsIPrincipal * prin, nsTarget * target, PRInt16 * privilegeState);
* and target parameters.
*/
NS_IMETHOD
SetPermission(nsIPrincipal * prin, nsTarget* target, PRInt16 * privilegeState);
SetPermission(nsIPrincipal * prin, nsITarget* target, PRInt16 * privilegeState);
/**
* Prompts the user if they want to grant permission for the given principal and
@ -95,7 +95,7 @@ SetPermission(nsIPrincipal * prin, nsTarget* target, PRInt16 * privilegeState);
* target
*/
NS_IMETHOD
AskPermission(nsIPrincipal * prin, nsTarget * target, PRInt16 * privilegeState);
AskPermission(nsIPrincipal * prin, nsITarget * target, PRInt16 * privilegeState);
@ -215,7 +215,7 @@ 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 nsTarget *target)
* nsCapsGetPrivilege(struct nsPrivilegeTable *annotation, struct nsITarget *target)
*
*/
NS_IMETHOD

Просмотреть файл

@ -38,16 +38,16 @@ PR_EXTERN(PRBool)
nsCapsRegisterPrincipal(class nsIPrincipal * principal);
PR_EXTERN(PRBool)
nsCapsEnablePrivilege(void* context, class nsTarget *target, PRInt32 callerDepth);
nsCapsEnablePrivilege(void* context, class nsITarget * target, PRInt32 callerDepth);
PR_EXTERN(PRBool)
nsCapsIsPrivilegeEnabled(void* context, class nsTarget *target, PRInt32 callerDepth);
nsCapsIsPrivilegeEnabled(void* context, class nsITarget * target, PRInt32 callerDepth);
PR_EXTERN(PRBool)
nsCapsRevertPrivilege(void* context, class nsTarget *target, PRInt32 callerDepth);
nsCapsRevertPrivilege(void* context, class nsITarget * target, PRInt32 callerDepth);
PR_EXTERN(PRBool)
nsCapsDisablePrivilege(void* context, class nsTarget *target, PRInt32 callerDepth);
nsCapsDisablePrivilege(void* context, class nsITarget * target, PRInt32 callerDepth);
PR_EXTERN(void*)
nsCapsGetClassPrincipalsFromStack(void* context, PRInt32 callerDepth);
@ -93,9 +93,9 @@ PR_EXTERN(PRUint32)
nsCapsGetPrincipalArraySize(void * prinArray);
/* wrappers for nsTarget object */
PR_EXTERN(class nsTarget *)
nsCapsFindTarget(char *name);
/* wrappers for nsITarget object */
PR_EXTERN(class nsITarget *)
nsCapsFindTarget(char * name);
/* wrappers for nsPrivilege object */
@ -105,7 +105,7 @@ nsCapsGetPermission(class nsIPrivilege * privilege);
/* wrappers for nsPrivilegeTable object */
PR_EXTERN(nsIPrivilege *)
nsCapsGetPrivilege(nsPrivilegeTable * annotation, class nsTarget * target);
nsCapsGetPrivilege(nsPrivilegeTable * annotation, class nsITarget * target);
/* Methods for stack walking */

Просмотреть файл

@ -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;
itsPrincipal->HashCode(code);
return *code;
}
PRBool Equals(const nsHashKey * aKey) const {
PRBool * result;
itsPrincipal->Equals(((const PrincipalKey *) aKey)->itsPrincipal, result);
return *result;
}
nsHashKey * Clone(void) const {
return new PrincipalKey(itsPrincipal);
}
};
#endif /* _NS_PRINCIPAL_TOOLS_H_ */

Просмотреть файл

@ -74,92 +74,92 @@ PRBool
UnregisterPrincipal(nsIPrincipal * principal);
PRBool
IsPrivilegeEnabled(nsTarget *target, PRInt32 callerDepth);
IsPrivilegeEnabled(nsITarget *target, PRInt32 callerDepth);
PRBool
IsPrivilegeEnabled(void* context, nsTarget *target,
IsPrivilegeEnabled(void* context, nsITarget *target,
PRInt32 callerDepth);
PRBool
EnablePrivilege(nsTarget * target, PRInt32 callerDepth);
EnablePrivilege(nsITarget * target, PRInt32 callerDepth);
PRBool
EnablePrivilege(void * context, nsTarget * target, PRInt32 callerDepth);
EnablePrivilege(void * context, nsITarget * target, PRInt32 callerDepth);
PRBool
EnablePrivilege(nsTarget * target, nsIPrincipal * preferredPrincipal,
EnablePrivilege(nsITarget * target, nsIPrincipal * preferredPrincipal,
PRInt32 callerDepth);
PRBool
EnablePrivilege(void* context, nsTarget *target, nsIPrincipal * preferredPrincipal,
EnablePrivilege(void* context, nsITarget *target, nsIPrincipal * preferredPrincipal,
PRInt32 callerDepth);
PRBool
RevertPrivilege(nsTarget * target, PRInt32 callerDepth);
RevertPrivilege(nsITarget * target, PRInt32 callerDepth);
PRBool
RevertPrivilege(void* context, nsTarget *target, PRInt32 callerDepth);
RevertPrivilege(void* context, nsITarget *target, PRInt32 callerDepth);
PRBool
DisablePrivilege(nsTarget *target, PRInt32 callerDepth);
DisablePrivilege(nsITarget *target, PRInt32 callerDepth);
PRBool
DisablePrivilege(void * context, nsTarget *target, PRInt32 callerDepth);
DisablePrivilege(void * context, nsITarget *target, PRInt32 callerDepth);
PRBool
EnablePrincipalPrivilegeHelper(nsTarget *target, PRInt32 callerDepth,
EnablePrincipalPrivilegeHelper(nsITarget *target, PRInt32 callerDepth,
nsIPrincipal * preferredPrin, void * data,
nsTarget *impersonator);
nsITarget *impersonator);
PRBool
EnablePrincipalPrivilegeHelper(void* context, nsTarget *target,
EnablePrincipalPrivilegeHelper(void* context, nsITarget *target,
PRInt32 callerDepth,
nsIPrincipal * preferredPrin,
void * data,
nsTarget *impersonator);
nsITarget *impersonator);
nsPrivilegeTable *
EnableScopePrivilegeHelper(nsTarget *target,
EnableScopePrivilegeHelper(nsITarget *target,
PRInt32 callerDepth,
void *data,
PRBool helpingSetScopePrivilege,
nsIPrincipal * prefPrin);
nsPrivilegeTable *
EnableScopePrivilegeHelper(void* context, nsTarget *target,
EnableScopePrivilegeHelper(void* context, nsITarget *target,
PRInt32 callerDepth, void *data,
PRBool helpingSetScopePrivilege,
nsIPrincipal * prefPrin);
PRBool
AskPermission(nsIPrincipal * useThisPrin, nsTarget* target, void* data);
AskPermission(nsIPrincipal * useThisPrin, nsITarget* target, void* data);
void
SetPermission(nsIPrincipal * useThisPrin, nsTarget * target, nsIPrivilege * newPrivilege);
SetPermission(nsIPrincipal * useThisPrin, nsITarget * target, nsIPrivilege * newPrivilege);
void
RegisterPrincipalAndSetPrivileges(nsIPrincipal * principal, nsTarget * target, nsIPrivilege * newPrivilege);
RegisterPrincipalAndSetPrivileges(nsIPrincipal * principal, nsITarget * target, nsIPrivilege * newPrivilege);
void
UpdatePrivilegeTable(nsTarget *target, nsPrivilegeTable * privTable, nsIPrivilege * newPrivilege);
UpdatePrivilegeTable(nsITarget *target, nsPrivilegeTable * privTable, nsIPrivilege * newPrivilege);
PRBool
CheckPrivilegeGranted(nsTarget *target, PRInt32 callerDepth);
CheckPrivilegeGranted(nsITarget *target, PRInt32 callerDepth);
PRBool
CheckPrivilegeGranted(void* context, nsTarget *target, PRInt32 callerDepth);
CheckPrivilegeGranted(void* context, nsITarget *target, PRInt32 callerDepth);
PRBool
CheckPrivilegeGranted(nsTarget * target, nsIPrincipal * principal, void *data);
CheckPrivilegeGranted(nsITarget * target, nsIPrincipal * principal, void *data);
PRBool
CheckPrivilegeGranted(nsTarget * target, PRInt32 callerDepth, void * data);
CheckPrivilegeGranted(nsITarget * target, PRInt32 callerDepth, void * data);
PRBool
CheckPrivilegeGranted(void * context, nsTarget * target, PRInt32 callerDepth, void * data);
CheckPrivilegeGranted(void * context, nsITarget * target, PRInt32 callerDepth, void * data);
nsIPrivilege *
GetPrincipalPrivilege(nsTarget * target, nsIPrincipal * prin, void * data);
GetPrincipalPrivilege(nsITarget * target, nsIPrincipal * prin, void * data);
static nsPrivilegeManager *
GetPrivilegeManager(void);
@ -214,14 +214,14 @@ PRBool
RemovePrincipalsPrivilege(char *prinName, char *targetName);
void
Remove(nsIPrincipal *prin, nsTarget *target);
Remove(nsIPrincipal *prin, nsITarget *target);
/* The following are old native methods */
char *
CheckPrivilegeEnabled(nsTargetArray* targetArray, PRInt32 callerDepth, void *data);
CheckPrivilegeEnabled(nsTargetArray * targetArray, PRInt32 callerDepth, void *data);
char *
CheckPrivilegeEnabled(void* context, nsTargetArray* targetArray, PRInt32 callerDepth, void *data);
CheckPrivilegeEnabled(void* context, nsTargetArray * targetArray, PRInt32 callerDepth, void *data);
nsPrincipalArray *
GetClassPrincipalsFromStack(PRInt32 callerDepth);
@ -255,19 +255,19 @@ void
AddToPrincipalNameToPrincipalTable(nsIPrincipal * prin);
PRBool
EnablePrivilegePrivate(void* context, nsTarget *target, nsIPrincipal *preferredPrincipal,
EnablePrivilegePrivate(void* context, nsITarget *target, nsIPrincipal *preferredPrincipal,
PRInt32 callerDepth);
PRInt16
GetPrincipalPrivilege(nsTarget * target, nsPrincipalArray * callerPrinArray, void * data);
GetPrincipalPrivilege(nsITarget * target, nsPrincipalArray * callerPrinArray, void * data);
PRBool
IsPermissionGranted(nsTarget *target, nsPrincipalArray* callerPrinArray, void *data);
IsPermissionGranted(nsITarget *target, nsPrincipalArray* callerPrinArray, void *data);
/* The following methods are used to save and load the persistent store */
void
Save(nsIPrincipal * prin, nsTarget * target, nsIPrivilege * newPrivilege);
Save(nsIPrincipal * prin, nsITarget * target, nsIPrivilege * newPrivilege);
void
Load(void);

Просмотреть файл

@ -1,56 +0,0 @@
/* -*- 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_PRIVILEGE_TABLE_H_
#define _NS_PRIVILEGE_TABLE_H_
#include "prtypes.h"
#include "nsHashtable.h"
#include "nsCaps.h"
#include "nsTarget.h"
#include "nsIPrivilege.h"
class nsPrivilegeTable {
public:
nsPrivilegeTable(void);
virtual ~nsPrivilegeTable(void);
PRInt32 Size(void);
PRBool IsEmpty(void);
virtual nsIPrivilege * Get(nsTarget * t);
nsIPrivilege * Put(nsTarget * a, nsIPrivilege * priv);
nsIPrivilege * Remove(nsTarget * key);
nsPrivilegeTable * Clone(void);
void Clear(void);
void Enumerate(nsHashtableEnumFunc aEnumFunc);
private:
nsHashtable * itsTable;
};
#endif /* _NS_PRIVILEGE_TABLE_H_ */

Просмотреть файл

@ -1,38 +0,0 @@
/* -*- 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_SYSTEM_PRIVILEGE_TABLE_H_
#define _NS_SYSTEM_PRIVILEGE_TABLE_H_
#include "nsTarget.h"
#include "nsIPrivilege.h"
#include "nsPrivilegeTable.h"
#include "nsCom.h"
class nsSystemPrivilegeTable : public nsPrivilegeTable {
public:
/* Public Methods */
nsSystemPrivilegeTable(void);
virtual nsIPrivilege * Get(nsTarget * a);
};
#endif /* _NS_SYSTEM_PRIVILEGE_TABLE_H_ */

Просмотреть файл

@ -19,18 +19,13 @@
#ifndef _NS_TARGET_H_
#define _NS_TARGET_H_
#include <string.h>
#include "prtypes.h"
#include "plhash.h"
#include "nsHashtable.h"
#include "nsVector.h"
//#include "nsCaps.h"
#include "nsIPrincipal.h"
#include "nsIPrivilege.h"
#include "nsITarget.h"
#include "nsUserDialogHelper.h"
typedef nsVector nsTargetArray;
PR_BEGIN_EXTERN_C
#include "jpermission.h"
PR_PUBLIC_API(void)
@ -47,115 +42,96 @@ extern char* capsGetString(int id);
PR_END_EXTERN_C
extern PRBool CreateSystemTargets(nsIPrincipal * sysPrin);
extern PRBool CreateSystemTargets(nsIPrincipal *sysPrin);
class nsTarget {
class nsTarget : public nsITarget {
public:
/* Public Methods */
NS_DECL_ISUPPORTS
nsTarget(char *name, nsIPrincipal * prin,
PRInt32 risk = JavaSecUI_targetRiskHigh(),
/* XXX: char *riskColor = JavaSecUI_getString(CAPS_TARGET_RISK_COLOR_HIGH), */
char * riskColor = "High", char * description = NULL, char * detailDescription = NULL,
char * url = NULL, nsTargetArray* targetArray = NULL)
{
this->Init(name, prin, targetArray, risk, riskColor, description, detailDescription, url);
}
nsTarget(char *name, nsIPrincipal * prin,
PRInt32 risk = JavaSecUI_targetRiskHigh(),
/* XXX: char *riskColor = JavaSecUI_getString(CAPS_TARGET_RISK_COLOR_HIGH), */
char * riskColor = "High", int desc_id = 0, int detail_desc_id = 0,
int help_url_id = 0, nsTargetArray* targetArray = NULL);
virtual ~nsTarget(void);
nsTarget(char *name, nsIPrincipal * prin,
PRInt32 risk = JavaSecUI_targetRiskHigh(),
/* XXX: char *riskColor = JavaSecUI_getString(CAPS_TARGET_RISK_COLOR_HIGH), */
char * riskColor = "High",
char * description = NULL,
char * detailDescription = NULL,
char * url = NULL,
nsTargetArray* targetArray = NULL)
{
this->Init(name, prin, targetArray, risk, riskColor, description, detailDescription, url);
}
static nsITarget * FindTarget(nsITarget * target);
nsTarget(char *name, nsIPrincipal * prin,
PRInt32 risk = JavaSecUI_targetRiskHigh(),
/* XXX: char *riskColor = JavaSecUI_getString(CAPS_TARGET_RISK_COLOR_HIGH), */
char * riskColor = "High",
int desc_id = 0,
int detail_desc_id = 0,
int help_url_id = 0,
nsTargetArray* targetArray = NULL);
static nsITarget * FindTarget(char * name);
nsTarget * RegisterTarget(void);
static nsITarget * FindTarget(char * name, nsIPrincipal *prin);
nsTarget * RegisterTarget(void* context);
static nsITarget * GetTargetFromDescription(char *a);
static nsTarget * FindTarget(nsTarget *target);
static nsTargetArray * GetAllRegisteredTargets(void);
static nsTarget * FindTarget(char * name);
nsIPrivilege * CheckPrivilegeEnabled(nsTargetArray * targetArray, void *data);
static nsTarget * FindTarget(char * name, nsIPrincipal *prin);
nsIPrivilege * CheckPrivilegeEnabled(nsTargetArray * targetArray);
nsIPrivilege * CheckPrivilegeEnabled(nsTargetArray* prinArray, void *data);
nsIPrivilege * CheckPrivilegeEnabled(nsIPrincipal *p, void * data);
nsIPrivilege * CheckPrivilegeEnabled(nsTargetArray* prinArray);
NS_IMETHOD RegisterTarget(void * context, nsITarget * * target);
nsIPrivilege * CheckPrivilegeEnabled(nsIPrincipal *p, void *data);
virtual nsIPrivilege * EnablePrivilege(nsIPrincipal *prin, void *data);
NS_IMETHOD EnablePrivilege(nsIPrincipal * prin, void * data, nsIPrivilege * * priv);
// virtual nsIPrivilege * EnablePrivilege(nsIPrincipal *prin, void *data);
//seems more likely to bleong to nsIPrivilege
nsIPrivilege * GetPrincipalPrivilege(nsIPrincipal *prin, void *data);
nsTargetArray* GetFlattenedTargetArray(void);
NS_IMETHOD GetFlattenedTargetArray(nsTargetArray * * targs);
static nsTargetArray* GetAllRegisteredTargets(void);
NS_IMETHOD GetRisk(char * * risk);
char * GetRisk(void);
NS_IMETHOD GetRiskColor(char * * riskColor);
char * GetRiskColor(void);
NS_IMETHOD GetDescription(char * * description);
char * GetDescription(void);
NS_IMETHOD GetDetailDescription(char * * detailedDescription);
char * GetDetailDescription(void);
NS_IMETHOD GetHelpURL(char * * helpUrl);
static nsTarget * GetTargetFromDescription(char *a);
NS_IMETHOD GetDetailedInfo(void *a, char * * dinfo);
char * GetHelpURL(void);
NS_IMETHOD GetPrincipal (nsIPrincipal * * prin);
char * GetDetailedInfo(void *a);
NS_IMETHOD GetName(char * * name);
nsIPrincipal * GetPrincipal(void);
NS_IMETHOD IsRegistered(PRBool * result);
char * GetName(void);
NS_IMETHOD Equals(nsITarget * other, PRBool * eq);
PRBool Equals(nsTarget *a);
NS_IMETHOD HashCode(PRUint32 * code);
PRInt32 HashCode(void);
char * ToString(void);
PRBool IsRegistered(void);
NS_IMETHOD ToString(char * * result);
private:
/* Private Field Accessors */
char * itsName;
nsIPrincipal * itsPrincipal;
PRInt32 itsRisk;
char * itsRiskColorStr;
char * itsDescriptionStr;
char * itsDetailDescriptionStr;
char * itsURLStr;
PRBool itsRegistered;
nsTargetArray* itsTargetArray;
nsTargetArray* itsExpandedTargetArray;
char *itsString;
PRInt32 itsRisk;
char * itsRiskColorStr;
char * itsDescriptionStr;
char * itsDetailDescriptionStr;
char * itsURLStr;
nsTargetArray * itsTargetArray;
nsTargetArray * itsExpandedTargetArray;
char * itsString;
PRUint32 itsDescriptionHash;
static PRBool theInited;
/* Private Methods */
@ -169,22 +145,26 @@ private:
class TargetKey: public nsHashKey {
public:
nsTarget *itsTarget;
TargetKey(nsTarget *targ) {
itsTarget = targ;
}
PRUint32 HashValue(void) const {
return itsTarget->HashCode();
}
nsITarget * itsTarget;
TargetKey(nsITarget * targ) {
itsTarget = targ;
}
PRBool Equals(const nsHashKey *aKey) const {
return (itsTarget->Equals(((const TargetKey *) aKey)->itsTarget));
}
PRUint32 HashValue(void) const {
PRUint32 code=0;
itsTarget->HashCode(& code);
return NS_OK;
}
nsHashKey *Clone(void) const {
return new TargetKey(itsTarget);
}
PRBool Equals(const nsHashKey * aKey) const {
PRBool eq;
itsTarget->Equals(((const TargetKey *) aKey)->itsTarget, & eq);
return eq;
}
nsHashKey * Clone(void) const {
return new TargetKey(itsTarget);
}
};
/* XXX: IMO, IntegerKey and StringKey should be part of xpcom */

Просмотреть файл

@ -23,7 +23,7 @@
#include "prtypes.h"
#include "nsTarget.h"
#include "nsPrivilege.h"
//#include "nsPrincipal.h"
#include "nsPrivilegeManager.h"
#include "nsCom.h"
/* Any methods that is not defined here is in Java */
@ -37,8 +37,8 @@ public:
virtual ~nsUserTarget(void);
nsUserTarget(char *name, nsIPrincipal * prin, PRInt32 risk,
char *riskColor, char *description,
char *detailDescription, char *url)
char * riskColor, char * description,
char * detailDescription, char * url)
: nsTarget(name, prin, risk, riskColor, description, detailDescription, url, NULL)
{
}
@ -46,7 +46,7 @@ public:
nsUserTarget(char *name, nsIPrincipal * prin, PRInt32 risk,
char *riskColor, char *description,
char *detailDescription, char *url,
nsTargetArray *targetArray)
nsTargetArray * targetArray)
: nsTarget(name, prin, risk, riskColor, description, detailDescription, url, targetArray)
{
}
@ -66,7 +66,7 @@ public:
int desc_id,
int detail_desc_id,
int help_url_id,
nsTargetArray *targetArray)
nsTargetArray * targetArray)
: nsTarget(name, prin, risk, riskColor, desc_id, detail_desc_id,
help_url_id, targetArray)
{

Двоичные данные
caps/macbuild/CapsIDL.mcp

Двоичный файл не отображается.

Просмотреть файл

@ -1,255 +0,0 @@
/* -*- 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.
*/
#ifndef _NS_ICAPS_MANAGER_H_
#define _NS_ICAPS_MANAGER_H_
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsIPrincipal.h"
#include "nsTarget.h"
//class nsITarget;
class nsICapsSecurityCallbacks;
#define NS_ALL_PRIVILEGES ((nsITarget*)NULL)
/**
* The nsICapsManager interface is used to construct and manage principals.
* Principals are either certificates, or codebase principals. To construct
* a principal, QueryInterface on nsIPluginManager and then call CreateCertPrincipal
* or CreateCodebasePrincipal on the returned nsICapsManager.
* Once a principal is obtained, it can be passed to the nsICapsManager's
* SetPermission operations.
*/
class nsICapsManager : public nsISupports {
public:
/**
* Intializes the principal object with the codebase URL.
*
* @param codebaseURL - the codebase URL
* @param prin - the return value is passed in this parameter.
*/
NS_IMETHOD
CreateCodebasePrincipal(const char *codebaseURL, nsIPrincipal * * prin) = 0;
/**
* Initializes the Certificate principal with the certificate data. I am
* thinking Certificate data should contain all the data about the
* certificate, ie. the signer and the certificate chain.
*
* @param certChain - An array of pointers, with each pointer
* pointing to a certificate data.
* @param certChainLengths - An array of intergers. Each integer indicates
* the length of the cert that is in CertChain
* parametr.
* @param noOfCerts - the number of certifcates that are in the certChain array
* @param prin - the return value is passed in this parameter.
*/
NS_IMETHOD
CreateCertificatePrincipal(const unsigned char * * certChain, PRUint32 * certChainLengths, PRUint32 noOfCerts, nsIPrincipal * * prin) = 0;
/**
* 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, nsTarget * target, PRInt16 * privilegeState) = 0;
/**
* 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, nsTarget * target, PRInt16 * privilegeState) = 0;
/**
* 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, nsTarget * target, PRInt16 * privilegeState) = 0;
/*
* 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) = 0;
/**
* Initializes the capabilities frame walking code.
*
* @param aInterface - interface for calling frame walking code.
*/
NS_IMETHOD
InitializeFrameWalker(nsICapsSecurityCallbacks* aInterface) = 0;
/**
* 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
*/
//NEED TO FIGURE THIS SUCKER OUT ARIEL
// NS_IMETHOD
// RegisterPrincipal(nsIPrincipal* prin, PRBool *result) = 0;
/**
* 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) = 0;
/**
* 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) = 0;
/**
* 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) = 0;
/**
* 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) = 0;
/* 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) = 0;
NS_IMETHOD
IntersectPrincipalArray(void* prin1Array, void* prin2Array, void* *result) = 0;
NS_IMETHOD
CanExtendTrust(void* fromPrinArray, void* toPrinArray, PRBool *result) = 0;
/* interfaces for nsIPrincipal object, may be we should move some of them to nsIprincipal */
/*
NS_IMETHOD
NewPrincipal(nsPrincipalType type, void* key, PRUint32 key_len, void *zig, nsIPrincipal* *result) = 0;
*/
NS_IMETHOD
CreateMixedPrincipalArray(void *zig, char* name, const char* codebase, void** result) = 0;
NS_IMETHOD
NewPrincipalArray(PRUint32 count, void* *result) = 0;
NS_IMETHOD
FreePrincipalArray(void *prinArray) = 0;
NS_IMETHOD
GetPrincipalArrayElement(void *prinArrayArg, PRUint32 index, nsIPrincipal* *result) = 0;
NS_IMETHOD
SetPrincipalArrayElement(void *prinArrayArg, PRUint32 index, nsIPrincipal* principal) = 0;
NS_IMETHOD
GetPrincipalArraySize(void *prinArrayArg, PRUint32 *result) = 0;
/* The following interfaces will replace all of the following old calls.
*
* nsCapsGetPermission(struct nsPrivilege *privilege)
* nsCapsGetPrivilege(struct nsPrivilegeTable *annotation, struct nsTarget *target)
*
*/
NS_IMETHOD
IsAllowed(void *annotation, char* target, PRBool *result) = 0;
/* XXX: TODO: We need to set up the JS frame walking callbacks */
};
#define NS_ICAPSMANAGER_IID \
{ /* dc7d0bb0-25e1-11d2-8160-006008119d7a */ \
0xdc7d0bb0, \
0x25e1, \
0x11d2, \
{0x81, 0x60, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
#define NS_CCAPSMANAGER_CID \
{ /* fd347500-307f-11d2-97f0-00805f8a28d0 */ \
0xfd347500, \
0x307f, \
0x11d2, \
{0x97, 0xf0, 0x00, 0x80, 0x5f, 0x8a, 0x28, 0xd0} \
}
#endif // nsICapsManager_h___

Просмотреть файл

@ -100,10 +100,10 @@ nsCCapsManager::CreateCertificatePrincipal(const unsigned char **certChain,
* @param state - the return value is passed in this parameter.
*/
NS_METHOD
nsCCapsManager::GetPermission(nsIPrincipal * prin, nsTarget * ignoreTarget, PRInt16 * privilegeState)
nsCCapsManager::GetPermission(nsIPrincipal * prin, nsITarget * ignoreTarget, PRInt16 * privilegeState)
{
* privilegeState = nsIPrivilege::PrivilegeState_Blank;
nsTarget * target = nsTarget::FindTarget(ALL_JAVA_PERMISSION);
nsITarget * target = nsTarget::FindTarget(ALL_JAVA_PERMISSION);
nsresult result = NS_OK;
if( target == NULL ) return NS_OK;
if (privilegeManager != NULL) {
@ -124,9 +124,9 @@ nsCCapsManager::GetPermission(nsIPrincipal * prin, nsTarget * ignoreTarget, PRIn
* and target parameters.
*/
NS_METHOD
nsCCapsManager::SetPermission(nsIPrincipal * prin, nsTarget * ignoreTarget, PRInt16 * privilegeState)
nsCCapsManager::SetPermission(nsIPrincipal * prin, nsITarget * ignoreTarget, PRInt16 * privilegeState)
{
nsTarget * target = nsTarget::FindTarget(ALL_JAVA_PERMISSION);
nsITarget * target = nsTarget::FindTarget(ALL_JAVA_PERMISSION);
if(target == NULL ) return NS_OK;
if (privilegeManager != NULL) {
// WORK ON THIS ARIEL
@ -146,9 +146,9 @@ nsCCapsManager::SetPermission(nsIPrincipal * prin, nsTarget * ignoreTarget, PRIn
* target
*/
NS_METHOD
nsCCapsManager::AskPermission(nsIPrincipal * prin, nsTarget * ignoreTarget, PRInt16 * privilegeState)
nsCCapsManager::AskPermission(nsIPrincipal * prin, nsITarget * ignoreTarget, PRInt16 * privilegeState)
{
nsTarget *target = nsTarget::FindTarget(ALL_JAVA_PERMISSION);
nsITarget *target = nsTarget::FindTarget(ALL_JAVA_PERMISSION);
if( target == NULL ) {
* privilegeState = nsIPrivilege::PrivilegeState_Blank;
return NS_OK;
@ -213,7 +213,7 @@ nsCCapsManager::RegisterPrincipal(nsIPrincipal * prin)
NS_METHOD
nsCCapsManager::EnablePrivilege(void* context, const char* targetName, PRInt32 callerDepth, PRBool *ret_val)
{
nsTarget *target = nsTarget::FindTarget((char*)targetName);
nsITarget *target = nsTarget::FindTarget((char*)targetName);
nsresult result = NS_OK;
if( target == NULL )
{
@ -239,7 +239,7 @@ nsCCapsManager::EnablePrivilege(void* context, const char* targetName, PRInt32 c
NS_METHOD
nsCCapsManager::IsPrivilegeEnabled(void* context, const char* targetName, PRInt32 callerDepth, PRBool *ret_val)
{
nsTarget *target = nsTarget::FindTarget((char*)targetName);
nsITarget *target = nsTarget::FindTarget((char*)targetName);
nsresult result = NS_OK;
if( target == NULL )
{
@ -267,7 +267,7 @@ nsCCapsManager::IsPrivilegeEnabled(void* context, const char* targetName, PRInt3
NS_METHOD
nsCCapsManager::RevertPrivilege(void* context, const char* targetName, PRInt32 callerDepth, PRBool *ret_val)
{
nsTarget *target = nsTarget::FindTarget((char*)targetName);
nsITarget *target = nsTarget::FindTarget((char*)targetName);
nsresult result = NS_OK;
if( target == NULL ) {
* ret_val = PR_FALSE;
@ -292,7 +292,7 @@ nsCCapsManager::RevertPrivilege(void* context, const char* targetName, PRInt32 c
NS_METHOD
nsCCapsManager::DisablePrivilege(void* context, const char* targetName, PRInt32 callerDepth, PRBool *ret_val)
{
nsTarget *target = nsTarget::FindTarget((char*)targetName);
nsITarget *target = nsTarget::FindTarget((char*)targetName);
nsresult result = NS_OK;
if( target == NULL ) {
* ret_val = PR_FALSE;
@ -489,12 +489,12 @@ nsCCapsManager::GetPrincipalArraySize(void *prinArrayArg, PRUint32 *ret_val)
/* The following interfaces will replace all of the following old calls.
* nsCapsGetPermission(struct nsPrivilege *privilege)
* nsCapsGetPrivilege(struct nsPrivilegeTable *annotation, struct nsTarget *target)
* nsCapsGetPrivilege(struct nsPrivilegeTable *annotation, struct nsITarget *target)
*/
NS_METHOD
nsCCapsManager::IsAllowed(void *annotation, char* targetName, PRBool *ret_val)
{
nsTarget *target = nsTarget::FindTarget(targetName);
nsITarget *target = nsTarget::FindTarget(targetName);
nsresult result = NS_OK;
if( target == NULL ) {
*ret_val = PR_FALSE;

Просмотреть файл

@ -27,7 +27,7 @@
#include "nsCertificatePrincipal.h"
#include "nsIPrivilege.h"
#include "nsPrivilegeTable.h"
#include "nsTarget.h"
#include "nsITarget.h"
#include "nsCCapsManager.h"
#include "nsCCapsManagerFactory.h"
@ -58,7 +58,7 @@ nsCapsInitialize()
{
if(bNSCapsInitialized_g == PR_TRUE) return PR_TRUE;
bNSCapsInitialized_g = PR_TRUE;
nsIPrincipal * sysPrin;
nsIPrincipal * sysPrin = NULL;
/*
#if defined(_WIN32)
// sysPrin = CreateSystemPrincipal("java/classes/java40.jar", "java/lang/Object.class");
@ -105,28 +105,28 @@ nsCapsRegisterPrincipal(class nsIPrincipal *principal)
}
PR_IMPLEMENT(PRBool)
nsCapsEnablePrivilege(void * context, class nsTarget * target, PRInt32 callerDepth)
nsCapsEnablePrivilege(void * context, class nsITarget * target, PRInt32 callerDepth)
{
nsPrivilegeManager * nsPrivManager = nsPrivilegeManager::GetPrivilegeManager();
return (nsPrivManager == NULL) ? PR_FALSE : nsPrivManager->EnablePrivilege(context, target, callerDepth);
}
PR_IMPLEMENT(PRBool)
nsCapsIsPrivilegeEnabled(void* context, class nsTarget *target, PRInt32 callerDepth)
nsCapsIsPrivilegeEnabled(void* context, class nsITarget *target, PRInt32 callerDepth)
{
nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::GetPrivilegeManager();
return (nsPrivManager == NULL) ? PR_FALSE : nsPrivManager->IsPrivilegeEnabled(context, target, callerDepth);
}
PR_IMPLEMENT(PRBool)
nsCapsRevertPrivilege(void* context, class nsTarget *target, PRInt32 callerDepth)
nsCapsRevertPrivilege(void* context, class nsITarget * target, PRInt32 callerDepth)
{
nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::GetPrivilegeManager();
return (nsPrivManager == NULL ) ? PR_FALSE : nsPrivManager->RevertPrivilege(context, target, callerDepth);
}
PR_IMPLEMENT(PRBool)
nsCapsDisablePrivilege(void* context, class nsTarget *target, PRInt32 callerDepth)
nsCapsDisablePrivilege(void* context, class nsITarget * target, PRInt32 callerDepth)
{
nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::GetPrivilegeManager();
return (nsPrivManager == NULL) ? PR_FALSE : nsPrivManager->DisablePrivilege(context, target, callerDepth);
@ -241,8 +241,8 @@ nsCapsGetPrincipalArraySize(void *prinArrayArg)
}
/* wrappers for nsTarget object */
PR_IMPLEMENT(class nsTarget *)
nsCapsFindTarget(char *name)
PR_IMPLEMENT(class nsITarget *)
nsCapsFindTarget(char * name)
{
return nsTarget::FindTarget(name);
}
@ -258,7 +258,7 @@ nsCapsGetPermission(nsIPrivilege * privilege)
/* wrappers for nsPrivilegeTable object */
PR_IMPLEMENT(nsIPrivilege *)
nsCapsGetPrivilege(nsPrivilegeTable * annotation, class nsTarget * target)
nsCapsGetPrivilege(nsPrivilegeTable * annotation, class nsITarget * target)
{
return annotation->Get(target);
}

Просмотреть файл

@ -78,7 +78,7 @@ nsCodebasePrincipal::HashCode(PRUint32 * code)
NS_IMETHODIMP
nsCodebasePrincipal::Equals(nsIPrincipal * other, PRBool * result)
{
PRInt16 * oType;
PRInt16 * oType = 0;
other->GetType(oType);
*result = (itsType == oType) ? PR_TRUE : PR_FALSE;
return NS_OK;
@ -91,4 +91,4 @@ nsCodebasePrincipal::nsCodebasePrincipal(PRInt16 * type, const char * codeBaseUR
nsCodebasePrincipal::~nsCodebasePrincipal(void)
{
}
}

Просмотреть файл

@ -55,9 +55,8 @@ NS_IMETHODIMP
nsPrivilege::SameState(nsIPrivilege * other, PRBool * result)
{
nsresult rv;
PRInt16 * myState;
PRInt16 * myState = 0, * otherState = 0;
rv = this->GetState(myState);
PRInt16 * otherState;
rv = other->GetState(otherState);
* result = (otherState == myState) ? PR_TRUE : PR_FALSE;
return rv;
@ -67,9 +66,8 @@ NS_IMETHODIMP
nsPrivilege::SameDuration(nsIPrivilege * other, PRBool * result)
{
nsresult rv;
PRInt16 * myDur;
PRInt16 * myDur =0, * otherDur = 0;
rv = this->GetState(myDur);
PRInt16 * otherDur;
rv = other->GetState(otherDur);
* result = (otherDur == myDur) ? PR_TRUE : PR_FALSE;
return rv;
@ -79,7 +77,7 @@ NS_IMETHODIMP
nsPrivilege::IsAllowed(PRBool * result)
{
nsresult rv;
PRInt16 * myState;
PRInt16 * myState = 0;
rv = this->GetState(myState);
* result = (myState == (PRInt16 *)nsIPrivilege::PrivilegeState_Allowed) ? PR_TRUE : PR_FALSE;
return rv;
@ -89,7 +87,7 @@ NS_IMETHODIMP
nsPrivilege::IsForbidden(PRBool * result)
{
nsresult rv;
PRInt16 * myState;
PRInt16 * myState = 0;
rv = this->GetState(myState);
* result = (myState == (PRInt16 *)nsIPrivilege::PrivilegeState_Forbidden) ? PR_TRUE : PR_FALSE;
return rv;
@ -99,7 +97,7 @@ NS_IMETHODIMP
nsPrivilege::IsBlank(PRBool * result)
{
nsresult rv;
PRInt16 * myState;
PRInt16 * myState = 0;
rv = this->GetState(myState);
* result = (myState == (PRInt16 *)nsIPrivilege::PrivilegeState_Blank) ? PR_TRUE : PR_FALSE;
return rv;
@ -161,10 +159,10 @@ NS_IMETHODIMP
nsPrivilege::Equals(nsIPrivilege * other, PRBool * result)
{
nsresult rv;
PRBool * sameState, * sameDuration;
rv = this->SameState(other, sameState);
rv = this->SameDuration(other, sameDuration);
*result = (sameState && sameDuration) ? PR_TRUE : PR_FALSE;
PRBool sameState = PR_FALSE, sameDuration = PR_FALSE;
rv = this->SameState(other, & sameState);
rv = this->SameDuration(other, & sameDuration);
* result = (sameState && sameDuration) ? PR_TRUE : PR_FALSE;
return rv;
}
@ -178,4 +176,4 @@ nsPrivilege::nsPrivilege(PRInt16 state, PRInt16 duration)
nsPrivilege::~nsPrivilege(void)
{
if(itsString) delete [] itsString;
}
}

Просмотреть файл

@ -30,9 +30,6 @@
#include "jsec2rdf.h"
#endif /* ENABLE_RDF */
static nsPrivilegeManager * thePrivilegeManager = NULL;
static nsIPrincipal * theSystemPrincipal = NULL;
static nsIPrincipal * theUnsignedPrincipal;
@ -60,7 +57,7 @@ static JSec_Principal RDF_CreatePrincipal(nsPrincipal *prin);
#endif /* ENABLE_RDF */
static PRBool RDF_RemovePrincipal(nsIPrincipal *prin);
static PRBool RDF_RemovePrincipalsPrivilege(nsIPrincipal *prin, nsTarget *target);
static PRBool RDF_RemovePrincipalsPrivilege(nsIPrincipal * prin, nsITarget * target);
PR_BEGIN_EXTERN_C
#include "xp.h"
@ -189,8 +186,7 @@ nsPrivilegeManager::FindPrivilege(char * privStr)
nsIPrivilege *
nsPrivilegeManager::Add(nsIPrivilege * priv1, nsIPrivilege * priv2) {
nsresult rv;
PRInt16 * p1state;
PRInt16 * p2state;
PRInt16 * p1state = NULL, * p2state = NULL;
rv = priv1->GetState(p1state);
rv = priv2->GetState(p2state);
return (p1state < p2state) ? priv1 : priv2;
@ -273,58 +269,57 @@ nsPrivilegeManager::UnregisterPrincipal(nsIPrincipal * prin)
}
PRBool
nsPrivilegeManager::IsPrivilegeEnabled(nsTarget * target, PRInt32 callerDepth)
nsPrivilegeManager::IsPrivilegeEnabled(nsITarget * target, PRInt32 callerDepth)
{
return this->IsPrivilegeEnabled(NULL, target, callerDepth);
}
PRBool
nsPrivilegeManager::IsPrivilegeEnabled(void *context, nsTarget * target, PRInt32 callerDepth)
nsPrivilegeManager::IsPrivilegeEnabled(void *context, nsITarget * target, PRInt32 callerDepth)
{
nsTargetArray * targetArray = new nsTargetArray();
nsTarget *targ = nsTarget::FindTarget(target);
nsITarget * targ = nsTarget::FindTarget(target);
if (targ != target) return PR_FALSE;
targetArray->Add(targ);
return (this->CheckPrivilegeEnabled(context, targetArray, callerDepth, NULL) != NULL) ? PR_FALSE : PR_TRUE;
}
PRBool
nsPrivilegeManager::EnablePrivilege(nsTarget * target, PRInt32 callerDepth)
nsPrivilegeManager::EnablePrivilege(nsITarget * target, PRInt32 callerDepth)
{
return this->EnablePrivilegePrivate(NULL, target, NULL, callerDepth);
}
PRBool
nsPrivilegeManager::EnablePrivilege(void* context, nsTarget * target, PRInt32 callerDepth)
nsPrivilegeManager::EnablePrivilege(void* context, nsITarget * target, PRInt32 callerDepth)
{
return this->EnablePrivilegePrivate(context, target, NULL, callerDepth);
}
PRBool
nsPrivilegeManager::EnablePrivilege(nsTarget * target, nsIPrincipal * preferredPrincipal,
PRInt32 callerDepth)
nsPrivilegeManager::EnablePrivilege(nsITarget * target, nsIPrincipal * preferredPrincipal, PRInt32 callerDepth)
{
return this->EnablePrivilegePrivate(NULL, target, preferredPrincipal, callerDepth);
}
PRBool
nsPrivilegeManager::EnablePrivilege(void* context, nsTarget * target, nsIPrincipal * preferredPrincipal,
nsPrivilegeManager::EnablePrivilege(void* context, nsITarget * target, nsIPrincipal * preferredPrincipal,
PRInt32 callerDepth)
{
return this->EnablePrivilegePrivate(context, target, preferredPrincipal, callerDepth);
}
PRBool
nsPrivilegeManager::RevertPrivilege(nsTarget * target, PRInt32 callerDepth)
nsPrivilegeManager::RevertPrivilege(nsITarget * target, PRInt32 callerDepth)
{
return this->RevertPrivilege(NULL, target, callerDepth);
}
PRBool
nsPrivilegeManager::RevertPrivilege(void* context, nsTarget * target, PRInt32 callerDepth)
nsPrivilegeManager::RevertPrivilege(void* context, nsITarget * target, PRInt32 callerDepth)
{
nsTarget *targ = nsTarget::FindTarget(target);
nsITarget * targ = nsTarget::FindTarget(target);
if (targ != target) return PR_FALSE;
nsPrivilegeTable *privTable = this->GetPrivilegeTableFromStack(context, callerDepth, PR_TRUE);
nsCaps_lock();
@ -335,15 +330,15 @@ nsPrivilegeManager::RevertPrivilege(void* context, nsTarget * target, PRInt32 ca
PRBool
nsPrivilegeManager::DisablePrivilege(nsTarget * target, PRInt32 callerDepth)
nsPrivilegeManager::DisablePrivilege(nsITarget * target, PRInt32 callerDepth)
{
return this->DisablePrivilege(NULL, target, callerDepth);
}
PRBool
nsPrivilegeManager::DisablePrivilege(void * context, nsTarget * target, PRInt32 callerDepth)
nsPrivilegeManager::DisablePrivilege(void * context, nsITarget * target, PRInt32 callerDepth)
{
nsTarget * targ = nsTarget::FindTarget(target);
nsITarget * targ = nsTarget::FindTarget(target);
if (targ != target) return PR_FALSE;
nsPrivilegeTable *privTable = this->GetPrivilegeTableFromStack(context, callerDepth, PR_TRUE);
nsCaps_lock();
@ -353,27 +348,27 @@ nsPrivilegeManager::DisablePrivilege(void * context, nsTarget * target, PRInt32
}
PRBool
nsPrivilegeManager::EnablePrincipalPrivilegeHelper(nsTarget *target,
nsPrivilegeManager::EnablePrincipalPrivilegeHelper(nsITarget *target,
PRInt32 callerDepth,
nsIPrincipal * preferredPrin,
void * data,
nsTarget *impersonator)
nsITarget *impersonator)
{
return this->EnablePrincipalPrivilegeHelper(NULL, target, callerDepth, preferredPrin, data, impersonator);
}
PRBool
nsPrivilegeManager::EnablePrincipalPrivilegeHelper(void *context,
nsTarget *target,
nsITarget *target,
PRInt32 callerDepth,
nsIPrincipal * preferredPrin,
void * data,
nsTarget *impersonator)
nsITarget *impersonator)
{
nsPrincipalArray* callerPrinArray;
nsIPrincipal * useThisPrin = NULL;
/* Get the registered target */
nsTarget *targ = nsTarget::FindTarget(target);
nsITarget *targ = nsTarget::FindTarget(target);
if (targ != target) return PR_FALSE;
callerPrinArray = this->GetClassPrincipalsFromStack(context, callerDepth);
if (preferredPrin != NULL) {
@ -394,7 +389,7 @@ nsPrivilegeManager::EnablePrincipalPrivilegeHelper(void *context,
}
}
if ((useThisPrin == NULL) && (impersonator)){
nsTarget *t1;
nsITarget *t1;
t1 = impersonator;
if (PR_FALSE == this->IsPrivilegeEnabled(context, t1, 0)) return PR_FALSE;
useThisPrin = preferredPrin;
@ -427,7 +422,7 @@ nsPrivilegeManager::EnablePrincipalPrivilegeHelper(void *context,
nsPrivilegeTable *
nsPrivilegeManager::EnableScopePrivilegeHelper(nsTarget *target,
nsPrivilegeManager::EnableScopePrivilegeHelper(nsITarget *target,
PRInt32 callerDepth,
void *data,
PRBool helpingSetScopePrivilege,
@ -439,7 +434,7 @@ nsPrivilegeManager::EnableScopePrivilegeHelper(nsTarget *target,
nsPrivilegeTable *
nsPrivilegeManager::EnableScopePrivilegeHelper(void* context, nsTarget *target,
nsPrivilegeManager::EnableScopePrivilegeHelper(void* context, nsITarget *target,
PRInt32 callerDepth,
void *data,
PRBool helpingSetScopePrivilege,
@ -449,7 +444,7 @@ nsPrivilegeManager::EnableScopePrivilegeHelper(void* context, nsTarget *target,
nsIPrivilege * allowedScope;
PRBool res;
nsTarget * targ = nsTarget::FindTarget(target);
nsITarget * targ = nsTarget::FindTarget(target);
if (targ != target) return NULL;
//throw new ForbiddenTargetException(target + " is not a registered target");
(prefPrin != NULL) ?
@ -468,7 +463,7 @@ nsPrivilegeManager::EnableScopePrivilegeHelper(void* context, nsTarget *target,
}
PRBool
nsPrivilegeManager::AskPermission(nsIPrincipal * useThisPrin, nsTarget * target, void * data)
nsPrivilegeManager::AskPermission(nsIPrincipal * useThisPrin, nsITarget * target, void * data)
{
/*
PRBool ret_val = PR_FALSE;
@ -513,7 +508,7 @@ done:
}
void
nsPrivilegeManager::SetPermission(nsIPrincipal * useThisPrin, nsTarget * target, nsIPrivilege * newPrivilege)
nsPrivilegeManager::SetPermission(nsIPrincipal * useThisPrin, nsITarget * target, nsIPrivilege * newPrivilege)
{
/*
registerPrincipalAndSetPrivileges(useThisPrin, target, newPrivilege);
@ -538,7 +533,7 @@ nsPrivilegeManager::SetPermission(nsIPrincipal * useThisPrin, nsTarget * target,
void
nsPrivilegeManager::RegisterPrincipalAndSetPrivileges(nsIPrincipal * prin, nsTarget *target,
nsPrivilegeManager::RegisterPrincipalAndSetPrivileges(nsIPrincipal * prin, nsITarget *target,
nsIPrivilege * newPrivilege)
{
nsPrivilegeTable *privTable;
@ -556,14 +551,15 @@ nsPrivilegeManager::RegisterPrincipalAndSetPrivileges(nsIPrincipal * prin, nsTar
void
nsPrivilegeManager::UpdatePrivilegeTable(nsTarget *target, nsPrivilegeTable *privTable, nsIPrivilege * newPrivilege)
nsPrivilegeManager::UpdatePrivilegeTable(nsITarget * target, nsPrivilegeTable * privTable, nsIPrivilege * newPrivilege)
{
nsTargetArray * primitiveTargets = target->GetFlattenedTargetArray();
nsIPrivilege * oldPrivilege, * privilege;
nsTarget * primTarget;
nsTargetArray * primitiveTargets;
target->GetFlattenedTargetArray(& primitiveTargets);
nsIPrivilege * oldPrivilege, * privilege;
nsITarget * primTarget;
nsCaps_lock();
for (int i = primitiveTargets->GetSize(); i-- > 0;) {
primTarget = (nsTarget *)primitiveTargets->Get(i);
primTarget = (nsITarget *)primitiveTargets->Get(i);
oldPrivilege = privTable->Get(primTarget);
privilege = (oldPrivilege != NULL) ? nsPrivilegeManager::Add(oldPrivilege, newPrivilege) : newPrivilege;
privTable->Put(primTarget, privilege);
@ -572,19 +568,19 @@ nsPrivilegeManager::UpdatePrivilegeTable(nsTarget *target, nsPrivilegeTable *pri
}
PRBool
nsPrivilegeManager::CheckPrivilegeGranted(nsTarget *target, PRInt32 callerDepth)
nsPrivilegeManager::CheckPrivilegeGranted(nsITarget *target, PRInt32 callerDepth)
{
return this->CheckPrivilegeGranted(NULL, target, callerDepth, NULL);
}
PRBool
nsPrivilegeManager::CheckPrivilegeGranted(void* context, nsTarget *target, PRInt32 callerDepth)
nsPrivilegeManager::CheckPrivilegeGranted(void* context, nsITarget *target, PRInt32 callerDepth)
{
return this->CheckPrivilegeGranted(context, target, callerDepth, NULL);
}
PRBool
nsPrivilegeManager::CheckPrivilegeGranted(nsTarget *target, nsIPrincipal *prin, void *data)
nsPrivilegeManager::CheckPrivilegeGranted(nsITarget *target, nsIPrincipal *prin, void *data)
{
nsIPrivilege * privilege = this->GetPrincipalPrivilege(target, prin, data);
PRBool allowed;
@ -593,13 +589,13 @@ nsPrivilegeManager::CheckPrivilegeGranted(nsTarget *target, nsIPrincipal *prin,
}
PRBool
nsPrivilegeManager::CheckPrivilegeGranted(nsTarget *target, PRInt32 callerDepth, void *data)
nsPrivilegeManager::CheckPrivilegeGranted(nsITarget *target, PRInt32 callerDepth, void *data)
{
return CheckPrivilegeGranted(NULL, target, callerDepth, data);
}
PRBool
nsPrivilegeManager::CheckPrivilegeGranted(void* context, nsTarget *target, PRInt32 callerDepth, void *data)
nsPrivilegeManager::CheckPrivilegeGranted(void* context, nsITarget *target, PRInt32 callerDepth, void *data)
{
nsPrincipalArray* callerPrinArray = GetClassPrincipalsFromStack(context, callerDepth);
PRInt16 privilegeState = GetPrincipalPrivilege(target, callerPrinArray, data);
@ -887,7 +883,7 @@ nsPrivilegeManager::RemovePrincipalsPrivilege(char *prinName, char *targetDesc)
nsIPrincipal * prin = this->GetPrincipalFromString(prinName);
if (prin == NULL) return PR_FALSE;
/* targetDesc is passed to the admin UI in getPermissionsString */
nsTarget * target = nsTarget::GetTargetFromDescription(targetDesc);
nsITarget * target = nsTarget::GetTargetFromDescription(targetDesc);
if (target == NULL) return PR_FALSE;
this->Remove(prin, target);
return PR_TRUE;
@ -898,7 +894,7 @@ UpdatePrivileges(nsHashKey *aKey, void *aData, void* closure)
{
/* Admin UI */
TargetKey *targetKey = (TargetKey *) aKey;
nsTarget *target = targetKey->itsTarget;
nsITarget *target = targetKey->itsTarget;
nsPrivilege *priv = (nsPrivilege *)aData;
nsPrivilegeManager *mgr = nsPrivilegeManager::GetPrivilegeManager();
mgr->UpdatePrivilegeTable(target, gPrivilegeTable, priv);
@ -906,7 +902,7 @@ UpdatePrivileges(nsHashKey *aKey, void *aData, void* closure)
}
void
nsPrivilegeManager::Remove(nsIPrincipal * prin, nsTarget *target)
nsPrivilegeManager::Remove(nsIPrincipal * prin, nsITarget * target)
{
/* Admin UI */
nsCaps_lock();
@ -940,7 +936,7 @@ nsPrivilegeManager::Remove(nsIPrincipal * prin, nsTarget *target)
#define UNKNOWN_PRIN_KEY "52:4f:53:4b:49:4e:44:4a"
PRBool
nsPrivilegeManager::EnablePrivilegePrivate(void* context, nsTarget *target, nsIPrincipal * prefPrin,
nsPrivilegeManager::EnablePrivilegePrivate(void* context, nsITarget *target, nsIPrincipal * prefPrin,
PRInt32 callerDepth)
{
if (PR_FALSE == this->EnablePrincipalPrivilegeHelper(context, target, callerDepth,
@ -951,7 +947,7 @@ nsPrivilegeManager::EnablePrivilegePrivate(void* context, nsTarget *target, nsIP
}
PRInt16
nsPrivilegeManager::GetPrincipalPrivilege(nsTarget * target, nsPrincipalArray * callerPrinArray, void *data)
nsPrivilegeManager::GetPrincipalPrivilege(nsITarget * target, nsPrincipalArray * callerPrinArray, void *data)
{
nsIPrivilege * privilege;
nsIPrincipal * principal;
@ -972,7 +968,7 @@ nsPrivilegeManager::GetPrincipalPrivilege(nsTarget * target, nsPrincipalArray *
return (isAllowed) ? (PRInt16)nsIPrivilege::PrivilegeState_Allowed : (PRInt16)nsIPrivilege::PrivilegeState_Blank;
}
nsIPrivilege *
nsPrivilegeManager::GetPrincipalPrivilege(nsTarget *target, nsIPrincipal * prin, void *data)
nsPrivilegeManager::GetPrincipalPrivilege(nsITarget *target, nsIPrincipal * prin, void *data)
{
if ( (prin == NULL) || (target == NULL) )
return nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Blank, nsIPrivilege::PrivilegeDuration_Session);
@ -982,14 +978,14 @@ nsPrivilegeManager::GetPrincipalPrivilege(nsTarget *target, nsIPrincipal * prin,
nsPrivilegeTable *privTable = (nsPrivilegeTable *) itsPrinToPrivTable->Get(&prinKey);
if (privTable == NULL)
return nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Blank, nsIPrivilege::PrivilegeDuration_Session);
nsTarget * tempTarget = nsTarget::FindTarget(target);
nsITarget * tempTarget = nsTarget::FindTarget(target);
if (tempTarget != target)
return nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Blank, nsIPrivilege::PrivilegeDuration_Session);
return privTable->Get(target);
}
PRBool
nsPrivilegeManager::IsPermissionGranted(nsTarget *target,
nsPrivilegeManager::IsPermissionGranted(nsITarget *target,
nsPrincipalArray* callerPrinArray,
void *data)
{
@ -1294,7 +1290,7 @@ RDF_getPrincipal(JSec_Principal jsec_pr)
}
static JSec_Target
RDF_CreateTarget(nsTarget *target)
RDF_CreateTarget(nsITarget * target)
{
char *targetName = target->getName();
nsIPrincipal *prin = target->getPrincipal();
@ -1302,17 +1298,16 @@ RDF_CreateTarget(nsTarget *target)
return RDFJSec_NewTarget(targetName, pr);
}
static nsTarget *
static nsITarget *
RDF_getTarget(JSec_Target jsec_target)
{
char *targetName = RDFJSec_GetTargetName(jsec_target);
return nsTarget::findTarget(targetName);
char * targetName = RDFJSec_GetTargetName(jsec_target);
return nsTarget::FindTarget(targetName);
}
#endif /* ENABLE_RDF */
static PRBool
RDF_RemovePrincipalsPrivilege(nsIPrincipal * prin, nsTarget *target)
RDF_RemovePrincipalsPrivilege(nsIPrincipal * prin, nsITarget * target)
{
PRBool found = PR_FALSE;
#ifdef ENABLE_RDF
@ -1357,7 +1352,7 @@ RDF_RemovePrincipalsPrivilege(nsIPrincipal * prin, nsTarget *target)
/* The following methods are used to save and load the persistent store */
void
nsPrivilegeManager::Save(nsIPrincipal * prin, nsTarget *target, nsIPrivilege *newPrivilege)
nsPrivilegeManager::Save(nsIPrincipal * prin, nsITarget *target, nsIPrivilege *newPrivilege)
{
PRBool eq;
prin->Equals(this->GetSystemPrincipal(), &eq);
@ -1399,7 +1394,7 @@ nsPrivilegeManager::Load(void)
if (privilege_str == NULL) continue;
JSec_Target jsec_target = RDFJSec_TargetOfPrincipalUse(jsec_pr_use);
if (jsec_target == NULL) continue;
nsTarget *target = RDF_getTarget(jsec_target);
nsITarget *target = RDF_getTarget(jsec_target);
if (target == NULL) continue;
nsPrivilege *privilege = nsPrivilege::findPrivilege(privilege_str);
registerPrincipalAndSetPrivileges(prin, target, privilege);

Просмотреть файл

@ -1,105 +0,0 @@
/* -*- 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.
*/
#include "nsPrivilegeTable.h"
#include "nsPrivilegeManager.h"
nsPrivilegeTable::nsPrivilegeTable(void)
{
this->itsTable = NULL;
}
nsPrivilegeTable::~nsPrivilegeTable(void)
{
/* XXX: We need to incr and decr objects that we put into this hashtable.
* There is a big memory leak.
* We need to delete all the entries in the privilege Table
*/
if (this->itsTable) delete this->itsTable;
this->itsTable = NULL;
}
PRInt32
nsPrivilegeTable::Size(void)
{
return (this->itsTable != NULL) ? this->itsTable->Count() : 0;
}
PRBool
nsPrivilegeTable::IsEmpty(void)
{
return ((this->itsTable == NULL) && (this->itsTable->Count() == 0)) ? PR_TRUE : PR_FALSE;
}
nsIPrivilege *
nsPrivilegeTable::Get(nsTarget *target)
{
if (itsTable == NULL)
return nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Blank, nsIPrivilege::PrivilegeDuration_Session);
TargetKey targKey(target);
nsIPrivilege * priv = (nsIPrivilege *) this->itsTable->Get(& targKey);
return (priv == NULL)
? nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Blank, nsIPrivilege::PrivilegeDuration_Session)
: priv;
}
nsIPrivilege *
nsPrivilegeTable::Put(nsTarget * target, nsIPrivilege * priv)
{
nsCaps_lock();
if (itsTable == NULL) this->itsTable = new nsHashtable();
TargetKey targKey(target);
nsIPrivilege * priv2 = (nsIPrivilege *)this->itsTable->Put(& targKey, (void *)priv);
nsCaps_unlock();
return priv2;
}
nsIPrivilege *
nsPrivilegeTable::Remove(nsTarget * target)
{
if (itsTable == NULL) return NULL;
TargetKey targKey(target);
nsCaps_lock();
nsIPrivilege * priv = (nsIPrivilege *)this->itsTable->Remove(& targKey);
nsCaps_unlock();
return priv;
}
nsPrivilegeTable *
nsPrivilegeTable::Clone(void)
{
nsCaps_lock();
nsPrivilegeTable *newbie = new nsPrivilegeTable();
if (itsTable != NULL) newbie->itsTable = itsTable->Clone();
nsCaps_unlock();
return newbie;
}
void
nsPrivilegeTable::Clear(void)
{
/* XXX: free the entries also */
nsCaps_lock();
if (this->itsTable) delete this->itsTable;
nsCaps_unlock();
}
void
nsPrivilegeTable::Enumerate(nsHashtableEnumFunc aEnumFunc) {
if (itsTable != NULL) itsTable->Enumerate(aEnumFunc);
}

Просмотреть файл

@ -1,30 +0,0 @@
/* -*- 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.
*/
#include "nsSystemPrivilegeTable.h"
#include "nsPrivilegeManager.h"
nsSystemPrivilegeTable::nsSystemPrivilegeTable(void) : nsPrivilegeTable()
{
}
nsIPrivilege *
nsSystemPrivilegeTable::Get(nsTarget *a)
{
return nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Allowed, nsIPrivilege::PrivilegeDuration_Forever);
}

Просмотреть файл

@ -321,9 +321,9 @@ extern int CAPS_TARGET_URL_ALL_JS_PERMISSION;
#define TARGET_STR " Target: "
#define PRIN_STR " Principal: "
static nsHashtable *theTargetRegistry = new nsHashtable();
static nsHashtable *theSystemTargetRegistry = new nsHashtable();
static nsHashtable *theDescToTargetRegistry = new nsHashtable();
static nsHashtable * theTargetRegistry = new nsHashtable();
static nsHashtable * theSystemTargetRegistry = new nsHashtable();
static nsHashtable * theDescToTargetRegistry = new nsHashtable();
static PRBool AddToTargetArray(nsHashKey * aKey, void * aData, void * closure);
@ -334,36 +334,41 @@ extern "C" {
#include "jpermission.h"
PR_PUBLIC_API(void)
java_netscape_security_getTargetDetails(const char *charSetName,
char* targetName,
java_netscape_security_getTargetDetails(const char * charSetName, char * targetName,
char** details, char **risk)
{
if (!targetName) return;
nsTarget *target = nsTarget::GetTargetFromDescription(targetName);
*risk = target->GetRisk();
nsTargetArray *primitiveTargets = target->GetFlattenedTargetArray();
nsITarget * target = nsTarget::GetTargetFromDescription(targetName);
target->GetRisk(risk);
nsTargetArray * primitiveTargets;
target->GetFlattenedTargetArray(& primitiveTargets);
/* Count the length of string buffer to allocate */
int len=0;
int extra_len = strlen("<option>") + strlen(" (") + strlen(")");
int i;
for (i = primitiveTargets->GetSize(); i-- > 0;) {
nsTarget *primTarget = (nsTarget *)primitiveTargets->Get(i);
len += extra_len + strlen(primTarget->GetDescription()) +
strlen(primTarget->GetRisk());
nsTarget *primTarget = (nsTarget *)primitiveTargets->Get(i);
char * targetRisk, * targetDescription;
primTarget->GetDescription(& targetDescription);
primTarget->GetRisk(& targetRisk);
len += extra_len + strlen(targetDescription) + strlen(targetRisk);
}
char *desc = new char[len+1];
desc[0] = '\0';
for (i = primitiveTargets->GetSize(); i-- > 0;) {
nsTarget *primTarget = (nsTarget *)primitiveTargets->Get(i);
XP_STRCAT(desc, "<option>");
XP_STRCAT(desc, primTarget->GetDescription());
XP_STRCAT(desc, " (");
XP_STRCAT(desc, primTarget->GetRisk());
XP_STRCAT(desc, ")");
nsITarget *primTarget = (nsITarget *)primitiveTargets->Get(i);
char * targetRisk, * targetDescription;
primTarget->GetDescription(& targetDescription);
primTarget->GetRisk(& targetRisk);
XP_STRCAT(desc, "<option>");
XP_STRCAT(desc, targetDescription);
XP_STRCAT(desc, " (");
XP_STRCAT(desc, targetRisk);
XP_STRCAT(desc, ")");
}
*details = desc;
* details = desc;
// Should we consider caching the details desc?
}
@ -418,7 +423,7 @@ CreateSystemTargets(nsIPrincipal * sysPrin)
CAPS_TARGET_DESC_FILE_READ,
CAPS_TARGET_DETAIL_DESC_FILE_READ,
CAPS_TARGET_URL_FILE_READ);
FileReadTarg->RegisterTarget();
FileReadTarg->RegisterTarget(NULL,NULL);
FileWriteTarg = new nsUserTarget("UniversalFileWrite", sysPrin,
targetRiskHigh,
@ -426,35 +431,35 @@ CreateSystemTargets(nsIPrincipal * sysPrin)
CAPS_TARGET_DESC_FILE_WRITE,
CAPS_TARGET_DETAIL_DESC_FILE_WRITE,
CAPS_TARGET_URL_FILE_WRITE);
FileWriteTarg->RegisterTarget();
FileWriteTarg->RegisterTarget(NULL,NULL);
FileDeleteTarg = new nsUserTarget("UniversalFileDelete", sysPrin,
targetRiskHigh,
targetRiskColorHigh,
CAPS_TARGET_DESC_FILE_DELETE,
CAPS_TARGET_DETAIL_DESC_FILE_DELETE,
CAPS_TARGET_URL_FILE_DELETE);
FileDeleteTarg->RegisterTarget();
FileDeleteTarg->RegisterTarget(NULL,NULL);
ImpersonatorTarg = new nsTarget("Impersonator", sysPrin,
targetRiskHigh,
targetRiskColorHigh,
CAPS_TARGET_DESC_IMPERSONATOR,
CAPS_TARGET_DETAIL_DESC_IMPERSONATOR,
CAPS_TARGET_URL_IMPERSONATOR);
ImpersonatorTarg->RegisterTarget();
ImpersonatorTarg->RegisterTarget(NULL,NULL);
BrowserReadTarg = new nsUserTarget("UniversalBrowserRead", sysPrin,
targetRiskMedium,
targetRiskColorMedium,
CAPS_TARGET_DESC_BROWSER_READ,
CAPS_TARGET_DETAIL_DESC_BROWSER_READ,
CAPS_TARGET_URL_BROWSER_READ);
BrowserReadTarg->RegisterTarget();
BrowserReadTarg->RegisterTarget(NULL,NULL);
BrowserWriteTarg = new nsUserTarget("UniversalBrowserWrite", sysPrin,
targetRiskHigh,
targetRiskColorHigh,
CAPS_TARGET_DESC_BROWSER_WRITE,
CAPS_TARGET_DETAIL_DESC_BROWSER_WRITE,
CAPS_TARGET_URL_BROWSER_WRITE);
BrowserWriteTarg->RegisterTarget();
BrowserWriteTarg->RegisterTarget(NULL,NULL);
UniversalPreferencesReadTarg = new nsUserTarget("UniversalPreferencesRead",
sysPrin,
targetRiskMedium,
@ -462,7 +467,7 @@ CreateSystemTargets(nsIPrincipal * sysPrin)
CAPS_TARGET_DESC_PREFS_READ,
CAPS_TARGET_DETAIL_DESC_PREFS_READ,
CAPS_TARGET_URL_PREFS_READ);
UniversalPreferencesReadTarg->RegisterTarget();
UniversalPreferencesReadTarg->RegisterTarget(NULL,NULL);
UniversalPreferencesWriteTarg = new nsUserTarget("UniversalPreferencesWrite",
sysPrin,
targetRiskHigh,
@ -470,14 +475,14 @@ CreateSystemTargets(nsIPrincipal * sysPrin)
CAPS_TARGET_DESC_PREFS_WRITE,
CAPS_TARGET_DETAIL_DESC_PREFS_WRITE,
CAPS_TARGET_URL_PREFS_WRITE);
UniversalPreferencesWriteTarg->RegisterTarget();
UniversalPreferencesWriteTarg->RegisterTarget(NULL,NULL);
SendMailTarg = new nsUserTarget("UniversalSendMail", sysPrin,
targetRiskMedium,
targetRiskColorMedium,
CAPS_TARGET_DESC_SEND_MAIL,
CAPS_TARGET_DETAIL_DESC_SEND_MAIL,
CAPS_TARGET_URL_SEND_MAIL);
SendMailTarg->RegisterTarget();
SendMailTarg->RegisterTarget(NULL,NULL);
RegistryPrivateTarg = new nsUserTarget("PrivateRegistryAccess", sysPrin,
targetRiskLow,
@ -485,7 +490,7 @@ CreateSystemTargets(nsIPrincipal * sysPrin)
CAPS_TARGET_DESC_REG_PRIVATE,
CAPS_TARGET_DETAIL_DESC_REG_PRIVATE,
CAPS_TARGET_URL_REG_PRIVATE);
RegistryPrivateTarg->RegisterTarget();
RegistryPrivateTarg->RegisterTarget(NULL,NULL);
targetPtrArray = new nsTargetArray();
targetPtrArray->SetSize(1, 1);
@ -498,7 +503,7 @@ CreateSystemTargets(nsIPrincipal * sysPrin)
CAPS_TARGET_DETAIL_DESC_REG_STANDARD,
CAPS_TARGET_URL_REG_STANDARD,
targetPtrArray);
RegistryStandardTarg->RegisterTarget();
RegistryStandardTarg->RegisterTarget(NULL,NULL);
targetPtrArray = new nsTargetArray();
targetPtrArray->SetSize(1, 1);
i = 0;
@ -511,7 +516,7 @@ CreateSystemTargets(nsIPrincipal * sysPrin)
CAPS_TARGET_DETAIL_DESC_REG_ADMIN,
CAPS_TARGET_URL_REG_ADMIN,
targetPtrArray);
RegistryAdminTarg->RegisterTarget();
RegistryAdminTarg->RegisterTarget(NULL,NULL);
UninstallTarg = new nsUserTarget("Uninstall",
sysPrin,
targetRiskHigh,
@ -519,7 +524,7 @@ CreateSystemTargets(nsIPrincipal * sysPrin)
CAPS_TARGET_DESC_UNINSTALL,
CAPS_TARGET_DETAIL_DESC_UNINSTALL,
CAPS_TARGET_URL_UNINSTALL);
UninstallTarg->RegisterTarget();
UninstallTarg->RegisterTarget(NULL,NULL);
targetPtrArray = new nsTargetArray();
targetPtrArray->SetSize(4,1);
i=0;
@ -535,7 +540,7 @@ CreateSystemTargets(nsIPrincipal * sysPrin)
CAPS_TARGET_DETAIL_DESC_SOFTWAREINSTALL,
CAPS_TARGET_URL_SOFTWAREINSTALL,
targetPtrArray);
SoftwareInstallTarg->RegisterTarget();
SoftwareInstallTarg->RegisterTarget(NULL,NULL);
targetPtrArray = new nsTargetArray();
targetPtrArray->SetSize(1, 1);
@ -549,7 +554,7 @@ CreateSystemTargets(nsIPrincipal * sysPrin)
CAPS_TARGET_DETAIL_DESC_SILENTINSTALL,
CAPS_TARGET_URL_SILENTINSTALL,
targetPtrArray);
SilentInstallTarg->RegisterTarget();
SilentInstallTarg->RegisterTarget(NULL,NULL);
nsTarget *SiteArchiveTarget = new nsUserTarget("SiteArchiveTarget",
sysPrin,
targetRiskHigh,
@ -557,7 +562,7 @@ CreateSystemTargets(nsIPrincipal * sysPrin)
CAPS_TARGET_DESC_SAR,
CAPS_TARGET_DETAIL_DESC_SAR,
CAPS_TARGET_URL_SAR);
SiteArchiveTarget->RegisterTarget();
SiteArchiveTarget->RegisterTarget(NULL,NULL);
targetPtrArray = new nsTargetArray();
targetPtrArray->SetSize(1, 1);
i=0;
@ -569,7 +574,7 @@ CreateSystemTargets(nsIPrincipal * sysPrin)
CAPS_TARGET_DETAIL_DESC_CANVAS_ACCESS,
CAPS_TARGET_URL_CANVAS_ACCESS,
targetPtrArray);
userTarg->RegisterTarget();
userTarg->RegisterTarget(NULL,NULL);
targetPtrArray = new nsTargetArray();
targetPtrArray->SetSize(3, 1);
@ -585,14 +590,13 @@ CreateSystemTargets(nsIPrincipal * sysPrin)
CAPS_TARGET_DETAIL_DESC_FILE_ACCESS,
CAPS_TARGET_URL_FILE_ACCESS,
targetPtrArray);
UniversalFileAccessTarg->RegisterTarget();
UniversalFileAccessTarg->RegisterTarget(NULL,NULL);
targetPtrArray = new nsTargetArray();
targetPtrArray->SetSize(2, 1);
i=0;
targetPtrArray->Set(i++, (void *)BrowserReadTarg);
targetPtrArray->Set(i++, (void *)BrowserWriteTarg);
UniversalBrowserAccessTarg =
new nsUserTarget("UniversalBrowserAccess",
UniversalBrowserAccessTarg = new nsUserTarget("UniversalBrowserAccess",
sysPrin,
targetRiskHigh,
targetRiskColorHigh,
@ -600,7 +604,7 @@ CreateSystemTargets(nsIPrincipal * sysPrin)
CAPS_TARGET_DETAIL_DESC_BROWSER_ACCESS,
CAPS_TARGET_URL_BROWSER_ACCESS,
targetPtrArray);
UniversalBrowserAccessTarg->RegisterTarget();
UniversalBrowserAccessTarg->RegisterTarget(NULL,NULL);
// a macro Target for PE
targetPtrArray = new nsTargetArray();
@ -618,7 +622,7 @@ CreateSystemTargets(nsIPrincipal * sysPrin)
CAPS_TARGET_DETAIL_DESC_ACCOUNT_SETUP,
CAPS_TARGET_URL_ACCOUNT_SETUP,
targetPtrArray);
userTarg->RegisterTarget();
userTarg->RegisterTarget(NULL,NULL);
/* Permission to All privileges in Java */
@ -628,7 +632,7 @@ CreateSystemTargets(nsIPrincipal * sysPrin)
CAPS_TARGET_DESC_ALL_JAVA_PERMISSION,
CAPS_TARGET_DETAIL_DESC_ALL_JAVA_PERMISSION,
CAPS_TARGET_URL_ALL_JAVA_PERMISSION);
target->RegisterTarget();
target->RegisterTarget(NULL,NULL);
/* Permission to All privileges in Java */
targetPtrArray = new nsTargetArray();
targetPtrArray->SetSize(7, 1);
@ -648,15 +652,16 @@ CreateSystemTargets(nsIPrincipal * sysPrin)
CAPS_TARGET_DETAIL_DESC_ALL_JS_PERMISSION,
CAPS_TARGET_URL_ALL_JS_PERMISSION,
targetPtrArray);
target->RegisterTarget();
target->RegisterTarget(NULL,NULL);
return PR_TRUE;
}
// PUBLIC METHODS
//
// PUBLIC METHODS
//
static NS_DEFINE_IID(kITargetIID, NS_ITARGET_IID);
NS_IMPL_ISUPPORTS(nsTarget, kITargetIID);
nsTarget::nsTarget(char *name, nsIPrincipal * prin, PRInt32 risk, char * riskColor,
int desc_id, int detail_desc_id, int help_url_id, nsTargetArray * targetArray)
@ -674,7 +679,6 @@ nsTarget::nsTarget(char *name, nsIPrincipal * prin, PRInt32 risk, char * riskCol
XP_FREE(url);
}
nsTarget::~nsTarget(void)
{
if (itsName) delete []itsName;
@ -687,91 +691,83 @@ nsTarget::~nsTarget(void)
if (itsExpandedTargetArray) delete []itsExpandedTargetArray;
}
nsTarget *
nsTarget::RegisterTarget()
NS_IMETHODIMP
nsTarget::RegisterTarget(void * context, nsITarget * * targetResult)
{
return RegisterTarget(NULL);
}
nsTarget *
nsTarget::RegisterTarget(void *context)
{
nsTarget *targ;
nsITarget * targ;
nsCaps_lock();
TargetKey targKey(this);
if (!theTargetRegistry) theTargetRegistry = new nsHashtable();
targ = (nsTarget *) theTargetRegistry->Get(&targKey);
targ = (nsITarget *) theTargetRegistry->Get(& targKey);
if (targ != NULL) {
PR_ASSERT(this == targ);
nsCaps_unlock();
return targ;
PR_ASSERT(this == targ);
nsCaps_unlock();
targetResult = & targ;
return NS_OK;
}
nsPrivilegeManager *mgr = nsPrivilegeManager::GetPrivilegeManager();
nsPrivilegeManager * mgr = nsPrivilegeManager::GetPrivilegeManager();
if ((mgr != NULL) && (context != NULL) &&
(!mgr->CheckMatchPrincipal(context, itsPrincipal, 1))) {
nsCaps_unlock();
return NULL;
(!mgr->CheckMatchPrincipal(context, itsPrincipal, 1))) {
nsCaps_unlock();
targetResult = NULL;
return NS_OK;
}
//
// otherwise, add the target to the registry
//
// TODO: make sure the caller has the given principal -- you
// shouldn't be allowed to register a target under a principal
// you don't own.
//
theTargetRegistry->Put(&targKey, this); // hash table will "canonicalize" name
if (!theSystemTargetRegistry) theSystemTargetRegistry = new nsHashtable();
PRBool eq;
itsPrincipal->Equals(nsPrivilegeManager::GetSystemPrincipal(),&eq);
if (eq) {
IntegerKey ikey(PL_HashString(itsName));
theSystemTargetRegistry->Put(&ikey, this);
IntegerKey ikey(PL_HashString(itsName));
theSystemTargetRegistry->Put(&ikey, this);
}
// The following hash table is used by the Admin UI. It finds
// the actual target given a description
IntegerKey ikey(itsDescriptionHash);
if (!theDescToTargetRegistry) theDescToTargetRegistry = new nsHashtable();
theDescToTargetRegistry->Put(&ikey, this);
itsRegistered = PR_TRUE;
nsCaps_unlock();
return this;
* targetResult = this;
return NS_OK;
}
nsTarget *
nsTarget::FindTarget(nsTarget * target)
nsITarget *
nsTarget::FindTarget(nsITarget * target)
{
TargetKey targKey(target);
return (nsTarget *) theTargetRegistry->Get(&targKey);
return (nsITarget *) theTargetRegistry->Get(& targKey);
}
nsTarget *
nsITarget *
nsTarget::FindTarget(char * name)
{
IntegerKey ikey(PL_HashString(name));
return (nsTarget *)theSystemTargetRegistry->Get(&ikey);
return (nsITarget *)theSystemTargetRegistry->Get(&ikey);
}
nsTarget *
nsITarget *
nsTarget::FindTarget(char * name, nsIPrincipal * prin)
{
PRBool eq;
prin->Equals(nsPrivilegeManager::GetSystemPrincipal(),&eq);
if (eq) return nsTarget::FindTarget(name);
/* name and principal combination uniquely identfies a target */
nsTarget* targ = new nsTarget((char *)name, prin,
nsITarget * targ = new nsTarget((char *)name, prin,
nsRiskType_HighRisk,
JavaSecUI_getString(CAPS_TARGET_RISK_COLOR_HIGH),
(char*)NULL, (char*)NULL, (char*)NULL,
(nsTargetArray*)NULL);
nsTarget* ret_val = nsTarget::FindTarget(targ);
nsITarget* ret_val = nsTarget::FindTarget(targ);
delete targ;
return ret_val;
}
//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)
{
@ -790,13 +786,14 @@ nsTarget::CheckPrivilegeEnabled(nsIPrincipal *p, void *data)
return nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Blank, nsIPrivilege::PrivilegeDuration_Session);
}
nsIPrivilege *
nsTarget::EnablePrivilege(nsIPrincipal * prin, void *data)
NS_IMETHODIMP
nsTarget::EnablePrivilege(nsIPrincipal * prin, void * data, nsIPrivilege * * priv)
{
PRBool eq;
itsPrincipal->Equals(prin, & eq);
return (eq) ? nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Allowed, nsIPrivilege::PrivilegeDuration_Session)
* priv = (eq) ? nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Allowed, nsIPrivilege::PrivilegeDuration_Session)
: nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Blank, nsIPrivilege::PrivilegeDuration_Session);
return NS_OK;
}
nsIPrivilege *
@ -805,10 +802,14 @@ nsTarget::GetPrincipalPrivilege(nsIPrincipal * prin, void *data)
return nsPrivilegeManager::FindPrivilege(nsIPrivilege::PrivilegeState_Blank, nsIPrivilege::PrivilegeDuration_Session);
}
nsTargetArray *
nsTarget::GetFlattenedTargetArray(void)
NS_IMETHODIMP
nsTarget::GetFlattenedTargetArray(nsTargetArray ** targsResult)
{
if (itsExpandedTargetArray != NULL) return itsExpandedTargetArray;
if (itsExpandedTargetArray != NULL)
{
* targsResult = itsExpandedTargetArray;
return NS_OK;
}
// We must populate the cached value of the Expansion
nsHashtable *targetHash = new nsHashtable();
nsTargetArray *expandedTargetArray = new nsTargetArray();
@ -817,7 +818,8 @@ nsTarget::GetFlattenedTargetArray(void)
delete targetHash;
itsExpandedTargetArray = expandedTargetArray;
// expandedTargetArray->FreeExtra();
return itsExpandedTargetArray;
* targsResult = itsExpandedTargetArray;
return NS_OK;
}
void
@ -840,7 +842,7 @@ static PRBool
AddToTargetArray(nsHashKey * aKey, void * aData, void * closure)
{
TargetKey * targetKey = (TargetKey *) aKey;
nsTarget * target = targetKey->itsTarget;
nsITarget * target = targetKey->itsTarget;
nsTargetArray *targetArray = (nsTargetArray *) aData;
return (targetArray->Add((void *)target) >= 0) ? PR_TRUE : PR_FALSE;
}
@ -857,110 +859,123 @@ nsTarget::GetAllRegisteredTargets(void)
return NULL;
}
char *
nsTarget::GetRisk(void)
NS_IMETHODIMP
nsTarget::GetRisk(char * * risk)
{
return JavaSecUI_targetRiskStr(itsRisk);
* risk = JavaSecUI_targetRiskStr(itsRisk);
return NS_OK;
}
char *
nsTarget::GetRiskColor(void)
NS_IMETHODIMP
nsTarget::GetRiskColor(char * * result)
{
return itsRiskColorStr;
result = (itsRiskColorStr) ? & itsRiskColorStr : NULL;
return NS_OK;
}
char *
nsTarget::GetDescription(void)
NS_IMETHODIMP
nsTarget::GetDescription(char * * result)
{
return itsDescriptionStr;
result = (itsDescriptionStr) ? & itsDescriptionStr : NULL;
return NS_OK;
}
char *
nsTarget::GetDetailDescription(void)
NS_IMETHODIMP
nsTarget::GetDetailDescription(char * * result)
{
return itsDetailDescriptionStr;
result = (itsDetailDescriptionStr) ? & itsDetailDescriptionStr : NULL;
return NS_OK;
}
nsTarget *
nsITarget *
nsTarget::GetTargetFromDescription(char *a)
{
IntegerKey ikey(PL_HashString(a));
return (nsTarget *) theDescToTargetRegistry->Get(&ikey);
return (nsITarget *) theDescToTargetRegistry->Get(&ikey);
}
char *
nsTarget::GetHelpURL(void)
NS_IMETHODIMP
nsTarget::GetHelpURL(char * * result)
{
return itsURLStr;
result = (itsURLStr) ? & itsURLStr : NULL;
return NS_OK;
}
char *
nsTarget::GetDetailedInfo(void *a)
NS_IMETHODIMP
nsTarget::GetDetailedInfo(void * a, char * * dinfo)
{
return "";
* dinfo = "";
return NS_OK;
}
nsIPrincipal *
nsTarget::GetPrincipal(void)
NS_IMETHODIMP
nsTarget::GetPrincipal(nsIPrincipal * * prin)
{
return itsPrincipal;
prin = (itsPrincipal) ? & itsPrincipal : NULL;
return NS_OK;
}
char *
nsTarget::GetName(void)
NS_IMETHODIMP
nsTarget::GetName(char * * result)
{
return itsName;
result = (itsName) ? & itsName : NULL;
return NS_OK;
}
PRBool
nsTarget::Equals(nsTarget *obj)
NS_IMETHODIMP
nsTarget::Equals(nsITarget * other, PRBool * result)
{
PRBool bSameName, bSamePrin;
if (obj == this) return PR_TRUE;
bSameName = ((strcmp(itsName, obj->itsName) == 0) ? PR_TRUE : PR_FALSE);
if (other == this) * result = PR_TRUE;
char * otherName;
other->GetName(& otherName);
bSameName = ((strcmp(itsName, otherName) == 0) ? PR_TRUE : PR_FALSE);
nsIPrincipal * otherPrin;
other->GetPrincipal(& otherPrin);
(itsPrincipal == NULL)
? bSamePrin = ((obj->itsPrincipal == NULL) ? PR_TRUE : PR_FALSE)
: itsPrincipal->Equals(obj->itsPrincipal, & bSamePrin);
return (bSameName && bSamePrin) ? PR_TRUE : PR_FALSE;
? bSamePrin = ((otherPrin == NULL) ? PR_TRUE : PR_FALSE)
: itsPrincipal->Equals(otherPrin, & bSamePrin);
* result = (bSameName && bSamePrin) ? PR_TRUE : PR_FALSE;
return NS_OK;
}
PRInt32
nsTarget::HashCode(void)
{ PRUint32 code;
(itsPrincipal != NULL) ? itsPrincipal->HashCode(& code) : code = 0;
return PL_HashString(itsName) + code;
}
char *
nsTarget::ToString(void)
NS_IMETHODIMP
nsTarget::HashCode(PRUint32 * code)
{
if (itsString != NULL) return itsString;
const char * prinStr;
if (itsPrincipal != NULL) itsPrincipal->ToString((char * *)& prinStr);
else prinStr = "<none>";
char * itsString = new char [strlen(TARGET_STR) + strlen(itsName) +
strlen(PRIN_STR) + strlen(prinStr) + 1];
PRUint32 prinCode = 0;
if (itsPrincipal != NULL) itsPrincipal->HashCode(& prinCode);
* code = PL_HashString(itsName) + prinCode;
return NS_OK;
}
NS_IMETHODIMP
nsTarget::ToString(char * * result)
{
if (itsString != NULL) result = & itsString;
char * prinStr = "<none>";
if (itsPrincipal != NULL) itsPrincipal->ToString(& prinStr);
itsString = new char [strlen(TARGET_STR) + strlen(itsName) + strlen(PRIN_STR) + strlen(prinStr) + 1];
XP_STRCPY(itsString, TARGET_STR);
XP_STRCAT(itsString, itsName);
XP_STRCAT(itsString, PRIN_STR);
XP_STRCAT(itsString, prinStr);
return itsString;
result = & itsString;
return NS_OK;
}
PRBool
nsTarget::IsRegistered(void)
NS_IMETHODIMP
nsTarget::IsRegistered(PRBool * result)
{
return itsRegistered;
* result = itsRegistered;
return NS_OK;
}
//
// PRIVATE METHODS
//
// PRIVATE METHODS
void
nsTarget::Init(char *name, nsIPrincipal * prin, nsTargetArray * targetArray,
PRInt32 risk, char * riskColor, char * description,
char * detailDescription, char * url)
nsTarget::Init(char * name, nsIPrincipal * prin, nsTargetArray * targetArray,
PRInt32 risk, char * riskColor, char * description,
char * detailDescription, char * url)
{
PR_ASSERT(name != NULL);
PR_ASSERT(prin != NULL);
@ -1002,7 +1017,7 @@ nsTarget::Init(char *name, nsIPrincipal * prin, nsTargetArray * targetArray,
static PRBool initialize(void)
{
return PR_TRUE;
return PR_TRUE;
}
PRBool nsTarget::theInited = initialize();

Просмотреть файл

@ -18,8 +18,6 @@
#include "xp.h"
#include "nsUserTarget.h"
#include "nsPrivilegeManager.h"
#include "prtypes.h"
#ifdef __cplusplus