rtsecuritymanager/rtsecuritymanagerserver/inc/rtsecmgrpolicyparser.h
changeset 0 99ef825efeca
child 21 bcef26ca2be3
equal deleted inserted replaced
-1:000000000000 0:99ef825efeca
       
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:       Utility XML parser to parse trust and access policy files
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 #ifndef C_RTSECMGRPOLICYPARSER_H
       
    24 #define C_RTSECMGRPOLICYPARSER_H
       
    25 
       
    26 #include <e32base.h>
       
    27 #include <GMXMLParser.h>
       
    28 #include <GMXMLNode.h>
       
    29 #include <EscapeUtils.h>
       
    30 #include "rtsecmgrdata.h"
       
    31 #include "rtsecmgrcommondef.h"
       
    32 
       
    33 /*
       
    34  * Enumerations for policy parsing status codes
       
    35  * 
       
    36  */
       
    37 enum TParserErrCode
       
    38 {
       
    39 	EErrNone = 0, //zero for success , equivalent to KErrNone of symbian
       
    40 	EErrInvalidDocNode = KErrXMLBase,
       
    41 	EErrInvalidRootNode = EErrInvalidDocNode - 1,
       
    42 	EErrNoPolicyInfo   = EErrInvalidRootNode - 1,
       
    43 	EErrInvalidDomainName = EErrNoPolicyInfo - 1,
       
    44 	EErrRepeatedDomainTag = EErrInvalidDomainName - 1,
       
    45 	EErrJunkContent = EErrRepeatedDomainTag - 1,
       
    46 	EErrNoDefaultCondition = EErrJunkContent - 1,
       
    47 	EErrInvalidFormat = EErrNoDefaultCondition - 1,
       
    48 	EErrInvalidCapability = EErrInvalidFormat - 1,
       
    49 	EErrInvalidPermission = EErrInvalidCapability - 1,
       
    50 	EErrRepeatedCaps = EErrInvalidPermission - 1,
       
    51 	EErrRepeatedAliasTag = EErrRepeatedCaps - 1,
       
    52 	EErrInvalidAliasName = EErrRepeatedAliasTag - 1,
       
    53 	EErrMisplacedAlias = EErrInvalidAliasName
       
    54 };
       
    55 
       
    56 /*
       
    57  * Abstracts policy parsing logic.
       
    58  * 
       
    59  * Security access policy and trust policy are represented in
       
    60  * XML format. CPolicyParser uses native XML parser to parse
       
    61  * the policy files.
       
    62  * 
       
    63  *  
       
    64  * @see MMDXMLParserObserver
       
    65  * @see CMDXMLParser
       
    66  * @see CMDXMLElement
       
    67  * @see CProtectionDomain
       
    68  * @see CTrustInfo
       
    69  * @see TUserPromptOption
       
    70  * 
       
    71  * @exe rtsecmgrserver.exe
       
    72  */
       
    73 NONSHARABLE_CLASS(CPolicyParser) : public CBase, public MMDXMLParserObserver
       
    74 {
       
    75 public:
       
    76 	
       
    77 	/**
       
    78 	 * Two-phased constructor
       
    79 	 * 
       
    80 	 * Constructs a CPolicyParser instance
       
    81 	 * 
       
    82 	 * @return CPolicyParser* pointer to an instance of CPolicyParser
       
    83 	 */
       
    84 	static CPolicyParser* NewL();
       
    85 
       
    86 	/**
       
    87 	 * Two-phased constructor
       
    88 	 * 
       
    89 	 * Constructs a CPolicyParser instance and leaves the created instance
       
    90 	 * on the cleanupstack
       
    91 	 * 
       
    92 	 * @return CPolicyParser* pointer to an instance of CPolicyParser
       
    93 	 */
       
    94 	static CPolicyParser* NewLC();	
       
    95 
       
    96 
       
    97 	/**
       
    98 	 * Destructor
       
    99 	 * 
       
   100 	 */
       
   101 	~CPolicyParser();
       
   102 	
       
   103 	/**
       
   104 	 * Parses the security access policy file and populates
       
   105 	 * the input protection domain array
       
   106 	 * 
       
   107 	 * @param aSecPolicy RFile& Handle to security policy file
       
   108 	 * @param aPolicyInfo RProtectionDomains& input array of protection domains
       
   109 	 * 
       
   110 	 * @return EErrSuccess if there is no parsing error; Otherwise one of
       
   111 	 * error codes defined in TParserErrCode
       
   112 	 * 
       
   113 	 * @see TParserErrCode
       
   114 	 */
       
   115 	TInt GetPolicyInfo(RFile& aSecPolicy, RProtectionDomains& aPolicyInfo, RAliasGroup& aAliasGroup);	
       
   116 	
       
   117 	/**
       
   118 	 * Callback offered by MMDXMLParserObserver to notify the calling client that the XML 
       
   119 	 * parsing is completed and DOM data structure is available for 
       
   120 	 * navigation
       
   121 	 * 
       
   122 	 * @see MMDXMLParserObserver
       
   123 	 * 
       
   124 	 * This identifies whether the policy file is in the proper format
       
   125 	 * if not in proper format, parsing errors as defined in TParserErrCode are thrown
       
   126 	 * @see TParserErrCode
       
   127 	 */
       
   128 	void ParseFileCompleteL();	
       
   129 private:	
       
   130 	
       
   131 	//private default constructor
       
   132 	inline CPolicyParser();	
       
   133 	
       
   134 	/**
       
   135 	 * Gets the list of capability nodes provided the parent domain
       
   136 	 * node
       
   137 	 * 
       
   138 	 */
       
   139 	TInt GetCapsNode(CMDXMLElement* aParentDomainNode, 
       
   140 					 RPointerArray<CMDXMLElement>& aCapNodes, 
       
   141 					 const TDesC& aNodeName);
       
   142 	
       
   143 	/**
       
   144 	 * Overloaded version to get the list of capability nodes provided the parent domain
       
   145 	 * node
       
   146 	 * 
       
   147 	 */
       
   148 	CMDXMLElement* GetCapsNode(CMDXMLElement* aParentDomainNode, const TDesC& aNodeName);
       
   149 	
       
   150 
       
   151 	/**
       
   152 	 * Populates the permission set data structure with capability
       
   153 	 * information provided the parent capability node
       
   154 	 * 
       
   155 	 * @return EErrSuccess if there is no parsing error; Otherwise one of these error codes 
       
   156 	 * @return EErrRepeatedCaps if there are capabilities specified more than once in same domain
       
   157 	 * @return EErrInvalidCapability if the capability string is invalid
       
   158 	 * 
       
   159 	 * @see TParserErrCode
       
   160 	 * 
       
   161 	 */
       
   162 	TInt GetCapabilities(CMDXMLElement* aParentNode, 
       
   163 						 CPermissionSet& aCapInfo,
       
   164 				   	 	 TUserPromptOption aUpOpt=RTUserPrompt_UnDefined,
       
   165 				   	 	 TBool aUGCaps=EFalse,
       
   166 						 TUserPromptOption aDefUpOpt=RTUserPrompt_UnDefined);
       
   167 						 
       
   168 	/**
       
   169 	 * Gets the user prompt option provided the parent user node
       
   170 	 * 
       
   171 	 * @return EErrSuccess if there is no parsing error; Otherwise one of these error codes 
       
   172 	 * @return EErrInvalidPermission if prompt sessions specified are invalid
       
   173 	 */
       
   174 	TInt GetConditions(CMDXMLElement* aParentNode, TUserPromptOption& aUserPromptOpt);
       
   175 	
       
   176 	/**
       
   177 	 * Gets the default user prompt option provided the parent user node
       
   178 	 * 
       
   179 	 */
       
   180 	TUserPromptOption GetDefaultCondition(CMDXMLElement* aParentNode);
       
   181 	
       
   182 	/**
       
   183 	 * Utility to convert the stringified user prompt option text to
       
   184 	 * TCapability enumeration
       
   185 	 * 
       
   186 	 * @see TCapability
       
   187 	 * 
       
   188 	 */
       
   189 	TCapability GetCapability(const TDesC& aUserPromptOpt);
       
   190 	
       
   191 	/**
       
   192 	 * Utility to convert the stringified user prompt option to
       
   193 	 * TUserPromptOption structure
       
   194 	 * 
       
   195 	 */
       
   196 	TUserPromptOption GetUserPromptOption(const TDesC& aUserPromptOpt);		
       
   197 	
       
   198 	/**
       
   199 	 * Finds out if a domain node is present with the passed domain name
       
   200 	 * 
       
   201 	 */
       
   202 	TBool isDomainPresent(const TDesC& aDomainName);
       
   203 	
       
   204 	/**
       
   205 	 * Utility method to check if a capability is already part of 
       
   206 	 * unconditional permissions
       
   207 	 * 
       
   208 	 */
       
   209 	TBool IsPresent(const CPermissionSet& aCapInfo, TCapability aCap);
       
   210 	
       
   211 	/**
       
   212 	 * Utility method to check if a capability is already part of user
       
   213 	 * grantable permissions
       
   214 	 * 
       
   215 	 */
       
   216 	TBool IsUserGrantPresent(const CPermissionSet& aCapInfo, TCapability aCap);
       
   217 
       
   218 	
       
   219 	/**
       
   220 	 * Populates the permission set data structure with capability
       
   221 	 * information provided the parent capability node
       
   222 	 * 
       
   223 	 * @return EErrSuccess if there is no parsing error; Otherwise one of these error codes 
       
   224 	 * @return EErrRepeatedCaps if there are capabilities specified more than once in same domain
       
   225 	 * @return EErrInvalidCapability if the capability string is invalid
       
   226 	 * 
       
   227 	 * @see TParserErrCode
       
   228 	 * 
       
   229 	 * This is similar to GetCapabilities method except that this retrives the capability information for the Group
       
   230 	 */
       
   231 	TInt GetCapabilitiesForGroup(CMDXMLElement* aParentNode, 
       
   232 						 CPermissionSet& aCapInfo,
       
   233 						 CPermission& aAliasInfo,
       
   234 				   	 	 TUserPromptOption aUpOpt=RTUserPrompt_UnDefined,
       
   235 				   	 	 TBool aUGCaps=EFalse,
       
   236 						 TUserPromptOption aDefUpOpt=RTUserPrompt_UnDefined);
       
   237 						 
       
   238 	/**
       
   239 	 * Finds out if the passed capability is present in alias group
       
   240 	 * 
       
   241 	 */
       
   242 	TBool IsCapsAliasPresent(const CPermission& aAliasInfo, TCapability aCap);
       
   243 	
       
   244 	/**
       
   245 	 * Finds out if a domain node is present with the passed domain name
       
   246 	 * 
       
   247 	 */
       
   248 	TBool isAliasPresent(const TDesC& aAliasName);
       
   249 	
       
   250 		
       
   251 private:	
       
   252 	
       
   253 	//reference to undelying native symbian XML parser
       
   254 	CMDXMLParser* iDomParser;	
       
   255 	
       
   256 	//Completion status of parsing request made to XML parser.
       
   257 	TRequestStatus* iStatus;
       
   258 	CActiveSchedulerWait iWaitScheduler;
       
   259 	
       
   260 	//list of domains declared in the security access policy
       
   261 	RProtectionDomains iPolicyInfo;
       
   262 	
       
   263 	//list of trust information specified in the trust policy file
       
   264 	RTrustArray iTrustInfo;
       
   265 
       
   266 	//variable to initiate parsing for trust policy file
       
   267 	TBool isTrustInfo;
       
   268 	
       
   269 	//status code to store last parsing error
       
   270 	TInt iLastError;
       
   271 
       
   272 	
       
   273 	//Array of TPermissions - used for Capability Grouping
       
   274 	RAliasGroup iAliasGroup;
       
   275 
       
   276 };
       
   277 
       
   278 #endif  //C_RTSECMGRPOLICYPARSER_H
       
   279 
       
   280 // End of file
       
   281 
       
   282