|
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: Definition of security manager persistent store class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 #ifndef C_RTSECMGRSTORE_H |
|
24 #define C_RTSECMGRSTORE_H |
|
25 |
|
26 #include <e32std.h> |
|
27 #include <badesca.h> |
|
28 #include <d32dbms.h> |
|
29 #include <f32file.h> |
|
30 #include <s32file.h> |
|
31 #include "rtsecmgrcommondef.h" |
|
32 #include "rtsecmgrserverdef.h" |
|
33 #include "rtsecmgrdata.h" |
|
34 |
|
35 /* |
|
36 * Abstracts the underlying security manager persistent storage |
|
37 * type. |
|
38 * |
|
39 * Provides methods to store and retrieve security policy data |
|
40 * and script related data. |
|
41 * |
|
42 * @see CProtectionDomain |
|
43 * @see CScript |
|
44 * |
|
45 * @exe rtsecmgrserver.exe |
|
46 */ |
|
47 NONSHARABLE_CLASS(CSecMgrStore) : public CBase |
|
48 { |
|
49 public: |
|
50 |
|
51 /** |
|
52 * Two-phased constructor |
|
53 * |
|
54 * Constructs a CSecMgrStore instance |
|
55 * |
|
56 * @return CSecMgrStore* pointer to an instance of CSecMgrStore |
|
57 */ |
|
58 static CSecMgrStore* NewL(); |
|
59 |
|
60 /** |
|
61 * Two-phased constructor |
|
62 * |
|
63 * Constructs a CSecMgrStore instance and leaves the created |
|
64 * instance on the cleanupstack |
|
65 * |
|
66 * @return CSecMgrStore* pointer to an instance of CSecMgrStore |
|
67 */ |
|
68 static CSecMgrStore* NewLC(); |
|
69 |
|
70 /** |
|
71 * Destructor |
|
72 * |
|
73 * Closes file session connection |
|
74 * |
|
75 */ |
|
76 inline ~CSecMgrStore(); |
|
77 |
|
78 /** |
|
79 * Updates policy data to the stream. |
|
80 * |
|
81 * This method creates a new policy file with the name equivalent to |
|
82 * policy identifier under security manager servers private directory. |
|
83 * |
|
84 * The policy data are serialized to the newly created policy file. |
|
85 * |
|
86 * If policy file already exists, the content will be overwritten. |
|
87 * |
|
88 * @param aPolicyID TPolicyID policy identifier |
|
89 * @param aPolicies const RProtectionDomains& list of domains to serialize |
|
90 * |
|
91 */ |
|
92 void StorePolicyL(const CPolicy& aPolicy); |
|
93 |
|
94 /** |
|
95 * Removes policy file from the persistent storage. |
|
96 * |
|
97 * This method looks for an existing policy file with the name equivalent to |
|
98 * policy identifier under security manager servers private directory. If policy |
|
99 * file is found, the file will be deleted from file system. |
|
100 * |
|
101 * @param aPolicyID TPolicyID policy identifier of the policy to be removed |
|
102 * |
|
103 * @return KErrNone if policy file removal corresponding to policy identifier passed is successful; |
|
104 * Otherwise, one of system wide error codes |
|
105 * |
|
106 */ |
|
107 TInt RemovePolicy(TPolicyID aPolicyID); |
|
108 |
|
109 /** |
|
110 * Restores policy data from the stream. |
|
111 * |
|
112 * This method internalizes the policy data from the persistent |
|
113 * storage. |
|
114 * |
|
115 * @param aPolicies RPolicies& Input policy data to be internalized |
|
116 * |
|
117 */ |
|
118 void RestorePoliciesL(RPolicies& aPolicies); |
|
119 |
|
120 /** |
|
121 * Registers a script with security manager persistent store. |
|
122 * |
|
123 * This method creates a new script file externalizing the script |
|
124 * data to the persistent stream. |
|
125 * |
|
126 * @param aExecID TExecutableID script identifier |
|
127 * @param aPolicyID TPolicyID policy identifier of the script |
|
128 * @param aScript const CScript& script data to be serialized |
|
129 * |
|
130 */ |
|
131 void RegisterScriptL(TExecutableID aExecID, const CScript& aScript); |
|
132 |
|
133 /** |
|
134 * UnRegisters a script with security manager persistent store. |
|
135 * |
|
136 * This method removes an existing script file from the persistent stream. |
|
137 * |
|
138 * @param aExecID TExecutableID script identifier to be removed |
|
139 * |
|
140 */ |
|
141 void UnRegisterScriptL(TExecutableID aExecID); |
|
142 |
|
143 /** |
|
144 * Internalizes the script data structure with script |
|
145 * information read from the persistent store |
|
146 * |
|
147 * @param aExecID TExecutableID script identifier |
|
148 * @param aScriptInfo CScript& script data to be internalized |
|
149 * |
|
150 */ |
|
151 TInt ReadScriptInfo(TExecutableID aExecID, CScript& aScriptInfo); |
|
152 |
|
153 /** |
|
154 * Utility method to get the script file name given the script identifier. |
|
155 * |
|
156 * @param aExecID TExecutableID script identifier |
|
157 * @param aScriptFile TDes& output file name to be returned |
|
158 * |
|
159 * @return KErrNone if script file name is found; Otherwise one of |
|
160 * system wide error codes |
|
161 * |
|
162 */ |
|
163 TInt GetScriptFile(TExecutableID aExecID,TDes& aScriptFile); |
|
164 |
|
165 /** |
|
166 * Externalizes the script data structure with script |
|
167 * information read to the persistent store |
|
168 * |
|
169 * @param aExecID TExecutableID script identifier |
|
170 * @param aScriptInfo CScript& script data to be externalized |
|
171 * |
|
172 */ |
|
173 void WriteScriptInfoL(TExecutableID aExecID, CScript& aScriptInfo); |
|
174 |
|
175 /** |
|
176 * Reads the script identifier from security manager configuration |
|
177 * repository |
|
178 * |
|
179 * @param aExecID TExecutableID& output script identifier |
|
180 * |
|
181 * @return KErrNone if reading of identifier is successful; Otherwise |
|
182 * one of system wide error codes |
|
183 */ |
|
184 TInt ReadCounter(TExecutableID& aExecID); |
|
185 |
|
186 /** |
|
187 * Writes the script identifier to security manager configuration |
|
188 * repository |
|
189 * |
|
190 * @param aExecID TExecutableID script identifier to be externalized |
|
191 * |
|
192 * @return KErrNone if writing of identifier is successful; Otherwise |
|
193 * one of system wide error codes |
|
194 */ |
|
195 TInt WriteCounter(TExecutableID aExecID); |
|
196 |
|
197 /* |
|
198 * Utility method to create a backup for the policy file |
|
199 * |
|
200 * @param aPolicyID TPolicyID policy identifier for the file |
|
201 * getting backed up |
|
202 * @return KErrNone if backupfile is successsfully created |
|
203 * |
|
204 */ |
|
205 |
|
206 TInt BackupFile(TPolicyID aPolicyID); |
|
207 |
|
208 /* |
|
209 * Utility method to remove the backup file created |
|
210 * |
|
211 * @param aPolicyID TPolicyID policy identifier for the file |
|
212 * whose backup is getting removed |
|
213 * @return KErrNone if backup file is successsfully removed |
|
214 * |
|
215 */ |
|
216 TInt RemoveTempPolicy(TPolicyID aPolicyID); |
|
217 |
|
218 /* |
|
219 * Utility method to restore the backup file created if update fails |
|
220 * |
|
221 * @param aPolicyID TPolicyID policy identifier for the file |
|
222 * which is restored back |
|
223 * @return KErrNone if backup file is successsfully restored |
|
224 * |
|
225 */ |
|
226 TInt RestoreTempPolicy(TPolicyID aPolicyID); |
|
227 |
|
228 private: |
|
229 |
|
230 /* |
|
231 * Default private constructor |
|
232 */ |
|
233 inline CSecMgrStore(); |
|
234 |
|
235 /* |
|
236 * Two-phased constructor |
|
237 * |
|
238 */ |
|
239 inline void ConstructL(); |
|
240 |
|
241 /* |
|
242 * Utility method to get security manager's private path |
|
243 * |
|
244 */ |
|
245 TInt GetPrivatePath(TDes& aPrivatePath); |
|
246 |
|
247 /* |
|
248 * Utility method to get security manager's configuration file |
|
249 * |
|
250 */ |
|
251 TInt GetConfigFile(TDes& aPrivatePath); |
|
252 |
|
253 /* |
|
254 * Utility method to get security manager's policy file |
|
255 * name |
|
256 * |
|
257 */ |
|
258 TInt GetPolicyPath(TDes& aFile); |
|
259 |
|
260 /* |
|
261 * Utility method to get security manager's script file |
|
262 * storage path |
|
263 * |
|
264 */ |
|
265 TInt GetScriptPath(TDes& aFile); |
|
266 |
|
267 /* |
|
268 * Utility method to get security manager's script file |
|
269 * name given a script identifier |
|
270 * |
|
271 */ |
|
272 TInt GetScriptFile(TDes& aFile,TExecutableID aExecID); |
|
273 |
|
274 |
|
275 |
|
276 /* |
|
277 * Utility method to get security manager's policy file |
|
278 * name given the policy identifier |
|
279 * |
|
280 */ |
|
281 TInt GetPolicyFile(TDes& aFile,TPolicyID aPolicyID); |
|
282 |
|
283 |
|
284 private: |
|
285 |
|
286 //underlying file session |
|
287 RFs iFsSession; |
|
288 }; |
|
289 |
|
290 #include "rtsecmgrstore.inl" |
|
291 |
|
292 #endif |