DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Untracked file

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
/* -*- 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_MANAGER_H_
#define _NS_PRIVILEGE_MANAGER_H_

#include "prtypes.h"
#include "prio.h"
#include "prmon.h"
#include "nsHashtable.h"

#include "nsVector.h"
#include "nsCaps.h"
#include "nsTarget.h"
#include "nsPrincipal.h"
#include "nsPrivilege.h"
#include "nsPrivilegeTable.h"
#include "nsSystemPrivilegeTable.h"
#include "nsCapsEnums.h"

extern PRBool nsCaps_lock(void);
extern void nsCaps_unlock(void);

PR_BEGIN_EXTERN_C
PRBool CMGetBoolPref(char * pref_name);
PR_END_EXTERN_C

PRBool nsPrivilegeManagerInitialize(void);

struct nsPrivilegeManager {

public:
	/* Public Methods */

	nsPrivilegeManager(void);
	virtual ~nsPrivilegeManager(void);

	void registerSystemPrincipal(nsPrincipal *principal);

	void registerPrincipal(nsPrincipal *principal);

	PRBool unregisterPrincipal(nsPrincipal *principal);

	PRBool isPrivilegeEnabled(nsTarget *target, PRInt32 callerDepth);

	PRBool isPrivilegeEnabled(void* context, nsTarget *target, 
                              PRInt32 callerDepth);

	PRBool enablePrivilege(nsTarget *target, PRInt32 callerDepth);

	PRBool enablePrivilege(void* context, nsTarget *target, PRInt32 callerDepth);

	PRBool enablePrivilege(nsTarget *target, nsPrincipal *preferredPrincipal, 
                           PRInt32 callerDepth);

	PRBool enablePrivilege(void* context, nsTarget *target, 
                           nsPrincipal *preferredPrincipal, 
                           PRInt32 callerDepth);

	PRBool revertPrivilege(nsTarget *target, PRInt32 callerDepth);

	PRBool revertPrivilege(void* context, nsTarget *target, PRInt32 callerDepth);

	PRBool disablePrivilege(nsTarget *target, PRInt32 callerDepth);

	PRBool disablePrivilege(void* context, nsTarget *target, PRInt32 callerDepth);

	PRBool enablePrincipalPrivilegeHelper(nsTarget *target, PRInt32 callerDepth, 
                                          nsPrincipal *preferredPrin, void * data,
                                          nsTarget *impersonator);

	PRBool enablePrincipalPrivilegeHelper(void* context, nsTarget *target, 
                                          PRInt32 callerDepth, 
                                          nsPrincipal *preferredPrin, 
                                          void * data, 
                                          nsTarget *impersonator);

	nsPrivilegeTable *enableScopePrivilegeHelper(nsTarget *target, 
                                                 PRInt32 callerDepth, 
                                                 void *data, 
                                                 PRBool helpingSetScopePrivilege, 
                                                 nsPrincipal *prefPrin);

	nsPrivilegeTable *enableScopePrivilegeHelper(void* context, nsTarget *target, 
                                                 PRInt32 callerDepth, void *data, 
                                                 PRBool helpingSetScopePrivilege, 
                                                 nsPrincipal *prefPrin);

	PRBool AskPermission(nsPrincipal* useThisPrin, nsTarget* target, void* data);

	void SetPermission(nsPrincipal *useThisPrin, nsTarget *target, 
                       nsPrivilege *newPrivilege);

	void registerPrincipalAndSetPrivileges(nsPrincipal *principal, 
                                           nsTarget *target, 
                                           nsPrivilege *newPrivilege);

	void updatePrivilegeTable(nsTarget *target, 
                              nsPrivilegeTable *privTable, 
                              nsPrivilege *newPrivilege);

	PRBool checkPrivilegeGranted(nsTarget *target, PRInt32 callerDepth);

	PRBool checkPrivilegeGranted(void* context, nsTarget *target, 
                                 PRInt32 callerDepth);

	PRBool checkPrivilegeGranted(nsTarget *target, nsPrincipal *principal, 
                                 void *data);

	PRBool checkPrivilegeGranted(nsTarget *target, PRInt32 callerDepth, 
                                 void *data);

	PRBool checkPrivilegeGranted(void* context, nsTarget *target, 
                                 PRInt32 callerDepth, void *data);

	nsPrivilege *getPrincipalPrivilege(nsTarget *target, nsPrincipal *prin, 
                                       void *data);

	static nsPrivilegeManager * getPrivilegeManager(void);

	static nsPrincipalArray* getMyPrincipals(PRInt32 callerDepth);

	static nsPrincipalArray* getMyPrincipals(void* context, PRInt32 callerDepth);

	static nsPrincipal * getSystemPrincipal(void);

	static PRBool hasSystemPrincipal(nsPrincipalArray *prinArray);

	static nsPrincipal* getUnsignedPrincipal(void);

	static nsPrincipal* getUnknownPrincipal(void);

	nsSetComparisonType comparePrincipalArray(nsPrincipalArray* prin1Array, 
                                              nsPrincipalArray* prin2Array);

	nsPrincipalArray* intersectPrincipalArray(nsPrincipalArray* prin1Array, 
                                              nsPrincipalArray* prin2Array);

	PRBool canExtendTrust(nsPrincipalArray* prin1Array, 
                          nsPrincipalArray* prin2Array);

	PRBool checkMatchPrincipal(nsPrincipal *principal, PRInt32 callerDepth);

	PRBool checkMatchPrincipal(void* context, nsPrincipal *principal, 
                               PRInt32 callerDepth);

    /* Helper functions for ADMIN UI */
	const char * getAllPrincipalsString(void);

	nsPrincipal * getPrincipalFromString(char *prinName);

	void getTargetsWithPrivileges(char *prinName, char** forever, 
                                  char** session, char **denied);

	PRBool removePrincipal(char *prinName);

	PRBool removePrincipalsPrivilege(char *prinName, char *targetName);

	void remove(nsPrincipal *prin, nsTarget *target);

	/* The following are old native methods */
	char * checkPrivilegeEnabled(nsTargetArray* targetArray, 
                                 PRInt32 callerDepth, void *data);

	char * checkPrivilegeEnabled(void* context, nsTargetArray* targetArray, 
                                 PRInt32 callerDepth, void *data);

	nsPrincipalArray* getClassPrincipalsFromStack(PRInt32 callerDepth);

	nsPrincipalArray* getClassPrincipalsFromStack(void* context, 
                                                  PRInt32 callerDepth);

	nsPrivilegeTable * getPrivilegeTableFromStack(PRInt32 callerDepth, 
                                                  PRBool createIfNull);

	nsPrivilegeTable * getPrivilegeTableFromStack(void* context, 
                                                  PRInt32 callerDepth, 
                                                  PRBool createIfNull);

	/* End of native methods */

private:

	nsHashtable *itsPrinToPrivTable;
	nsHashtable *itsPrinToMacroTargetPrivTable;
	nsHashtable *itsPrinNameToPrincipalTable;

	static PRBool theSecurityInited;

	static char * SignedAppletDBName;

	static PRBool theInited;

	/* Private Field Accessors */

	/* Private Methods */

	void addToPrinNameToPrincipalTable(nsPrincipal *prin);

	PRBool enablePrivilegePrivate(void* context, nsTarget *target, 
                                  nsPrincipal *preferredPrincipal, 
                                  PRInt32 callerDepth);

	nsPermissionState getPrincipalPrivilege(nsTarget *target, 
                                            nsPrincipalArray* callerPrinArray, 
                                            void *data);

	PRBool isPermissionGranted(nsTarget *target, 
                               nsPrincipalArray* callerPrinArray, 
                               void *data);


  /* The following methods are used to save and load the persistent store */
	void save(nsPrincipal *prin, nsTarget *target, nsPrivilege *newPrivilege);

	void load(void);

};


#endif /* _NS_PRIVILEGE_MANAGER_H_ */