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: Defines runtime security manager script session class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 #include <aknlistquerydialog.h> |
|
24 #include <AknQueryDialog.h> |
|
25 #include <aknmessagequerycontrol.h> |
|
26 #include <aknmessagequerydialog.h> |
|
27 #include <badesca.h> |
|
28 #include <bautils.h> |
|
29 #include <coemain.h> |
|
30 #include <data_caging_path_literals.hrh> |
|
31 #include <eikenv.h> |
|
32 #include <eikfrlb.h> |
|
33 #include <eikfrlbd.h> |
|
34 #include <pathinfo.h> |
|
35 #include <StringLoader.h> |
|
36 |
|
37 #include <rtsecmanager.h> |
|
38 #include <rtsecmgrscriptsession.h> |
|
39 #include <rtsecmgrscript.h> |
|
40 #include "rtsecmgrclient.h" |
|
41 #include "rtsecmgrdef.h" |
|
42 |
|
43 #define FIRST_RESOURCE_ID(x) ((x)+2); |
|
44 |
|
45 //security manager resource file literal |
|
46 _LIT(KSecMgrResourceFile, "RTSecManager.RSC"); |
|
47 |
|
48 //constant for descriptor array granularity |
|
49 const TInt KDescArrayInit = 6; |
|
50 const TInt KMaxBuf=255; |
|
51 |
|
52 |
|
53 //typedef of selection index array |
|
54 typedef RArray<TInt> RSelIdxArray; |
|
55 |
|
56 //static resource IDs for capability text display in default prompt |
|
57 static const TInt CAPABILITY_RESOURCEID[KCapabilitySize] = |
|
58 { |
|
59 0, //ECapabilityTCB (0) |
|
60 R_RTSECMGR_COMMDD, //ECapabilityCommDD (1) |
|
61 R_RTSECMGR_POWERMGMT, //ECapabilityPowerMgmt (2) |
|
62 R_RTSECMGR_MMEDIADD, //ECapabilityMultimediaDD (3) |
|
63 R_RTSECMGR_READDEVICEDATA, //ECapabilityReadDeviceData (4) |
|
64 R_RTSECMGR_WRITEDEVICEDATA, //ECapabilityWriteDeviceData (5) |
|
65 R_RTSECMGR_DRM, //ECapabilityDRM (6) |
|
66 R_RTSECMGR_TRUSTEDUI, //ECapabilityTrustedUI (7) |
|
67 R_RTSECMGR_PROTSERV, //ECapabilityProtServ (8) |
|
68 R_RTSECMGR_DISKADMIN, //ECapabilityDiskAdmin (9) |
|
69 R_RTSECMGR_NWCONTROL, //ECapabilityNetworkControl (10) |
|
70 R_RTSECMGR_ALLFILES, //ECapabilityAllFiles (11) |
|
71 R_RTSECMGR_SWEVENT, //ECapabilitySwEvent (12) |
|
72 R_RTSECMGR_NWSERVICES, //ECapabilityNetworkServices (13) |
|
73 R_RTSECMGR_LOCALSERVICES, //ECapabilityLocalServices (14) |
|
74 R_RTSECMGR_READUSERDATA, //ECapabilityReadUserData (15) |
|
75 R_RTSECMGR_WRITEUSERDATA, //ECapabilityWriteUserData (16) |
|
76 R_RTSECMGR_LOCATION, //ECapabilityLocation (17) |
|
77 R_RTSECMGR_SURRDD, //ECapabilitySurroundingsDD (18) |
|
78 R_RTSECMGR_USERENV //ECapabilityUserEnvironment (19) |
|
79 }; |
|
80 |
|
81 static const TInt MOREINFO_CAP_RESOURCEID[KCapabilitySize] = |
|
82 { |
|
83 0, //ECapabilityTCB (0) |
|
84 R_RTSECMGR_MORE_INFO_COMMDD, //ECapabilityCommDD (1) |
|
85 R_RTSECMGR_POWERMGMT, //ECapabilityPowerMgmt (2) |
|
86 R_RTSECMGR_MORE_INFO_MMEDIADD, //ECapabilityMultimediaDD (3) |
|
87 R_RTSECMGR_MORE_INFO_READDEVICEDATA, //ECapabilityReadDeviceData (4) |
|
88 R_RTSECMGR_MORE_INFO_WRITEDEVICEDATA, //ECapabilityWriteDeviceData (5) |
|
89 0, //ECapabilityDRM (6) |
|
90 0, //ECapabilityTrustedUI (7) |
|
91 0, //ECapabilityProtServ (8) |
|
92 0, //ECapabilityDiskAdmin (9) |
|
93 R_RTSECMGR_MORE_INFO_NWCONTROL, //ECapabilityNetworkControl (10) |
|
94 0, //ECapabilityAllFiles (11) |
|
95 R_RTSECMGR_MORE_INFO_SWEVENT, //ECapabilitySwEvent (12) |
|
96 R_RTSECMGR_MORE_INFO_NWSERVICES, //ECapabilityNetworkServices (13) |
|
97 R_RTSECMGR_MORE_INFO_LOCALSERVICES, //ECapabilityLocalServices (14) |
|
98 R_RTSECMGR_MORE_INFO_READ_USERDATA, //ECapabilityReadUserData |
|
99 R_RTSECMGR_MORE_INFO_WRITE_USERDATA,//ECapabilityWriteUserData |
|
100 R_RTSECMGR_MORE_INFO_LOCATION,//ECapabilityLocation |
|
101 R_RTSECMGR_MORE_INFO_SURRDD, //ECapabilitySurroundingsDD |
|
102 R_RTSECMGR_MORE_INFO_USERENV //ECapabilityUserEnvironment |
|
103 }; |
|
104 |
|
105 struct TCallbackParam |
|
106 { |
|
107 CRTSecMgrScriptSession* iRTSecMgrScriptSession; |
|
108 CPromptData *iPromptData; |
|
109 }; |
|
110 |
|
111 /** |
|
112 * Proxy delegate class for runtime security manager client-side |
|
113 * sub-session handle. |
|
114 * |
|
115 * @lib rtsecmgrclient.lib |
|
116 */ |
|
117 class CRTSecMgrSubSessionProxy : public CBase |
|
118 { |
|
119 public: |
|
120 |
|
121 static CRTSecMgrSubSessionProxy* NewL() |
|
122 { |
|
123 CRTSecMgrSubSessionProxy* self = CRTSecMgrSubSessionProxy::NewLC (); |
|
124 CleanupStack::Pop (self); |
|
125 return self; |
|
126 } |
|
127 |
|
128 static CRTSecMgrSubSessionProxy* NewLC() |
|
129 { |
|
130 CRTSecMgrSubSessionProxy* self = new (ELeave) CRTSecMgrSubSessionProxy(); |
|
131 CleanupStack::PushL (self); |
|
132 self->ConstructL (); |
|
133 return self; |
|
134 } |
|
135 |
|
136 virtual ~CRTSecMgrSubSessionProxy() |
|
137 { |
|
138 iSubSession.Close (); |
|
139 } |
|
140 |
|
141 inline RSecMgrSubSession& SubSession() |
|
142 { |
|
143 return iSubSession; |
|
144 } |
|
145 RSecMgrSubSession* operator ->() |
|
146 { |
|
147 return &iSubSession; |
|
148 } |
|
149 private: |
|
150 inline CRTSecMgrSubSessionProxy() |
|
151 { |
|
152 } |
|
153 void ConstructL() |
|
154 { |
|
155 } |
|
156 |
|
157 RSecMgrSubSession iSubSession; |
|
158 }; |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // Defintiion of default private constructor |
|
162 // --------------------------------------------------------------------------- |
|
163 // |
|
164 CRTSecMgrScriptSession::CRTSecMgrScriptSession(MSecMgrPromptHandler* aPromptHdlr) : |
|
165 iPromptHdlr(aPromptHdlr), iUIPromptOption(RTPROMPTUI_DEFAULT), isCustomPrompt(EFalse) |
|
166 { |
|
167 iSessionData = NULL; |
|
168 } |
|
169 |
|
170 // --------------------------------------------------------------------------- |
|
171 // Defintiion of second-phase constructor |
|
172 // --------------------------------------------------------------------------- |
|
173 // |
|
174 CRTSecMgrScriptSession* CRTSecMgrScriptSession::NewL( |
|
175 MSecMgrPromptHandler* aPromptHdlr) |
|
176 { |
|
177 CRTSecMgrScriptSession* self = CRTSecMgrScriptSession::NewLC (aPromptHdlr); |
|
178 CleanupStack::Pop (self); |
|
179 return self; |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // Defintiion of second-phase constructor |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 CRTSecMgrScriptSession* CRTSecMgrScriptSession::NewLC( |
|
187 MSecMgrPromptHandler* aPromptHdlr) |
|
188 { |
|
189 CRTSecMgrScriptSession* self = new (ELeave) CRTSecMgrScriptSession(aPromptHdlr); |
|
190 CleanupStack::PushL (self); |
|
191 self->ConstructL (); |
|
192 return self; |
|
193 } |
|
194 |
|
195 // --------------------------------------------------------------------------- |
|
196 // Defintiion of second-phase constructor |
|
197 // This method instantiates client side sub-session proxy instance. |
|
198 // In addition, this method loads the security manager resource |
|
199 // --------------------------------------------------------------------------- |
|
200 // |
|
201 void CRTSecMgrScriptSession::ConstructL() |
|
202 { |
|
203 iCoeEnv = CCoeEnv::Static (); |
|
204 if ( !iCoeEnv && !iPromptHdlr) |
|
205 User::Leave (KErrNotSupported); |
|
206 |
|
207 iSubSessionProxy = CRTSecMgrSubSessionProxy::NewL (); |
|
208 |
|
209 if ( !iPromptHdlr) |
|
210 { |
|
211 iPromptHdlr = this; //default prompt handler |
|
212 isCustomPrompt = ETrue ; |
|
213 } |
|
214 _permanentInfo = new(ELeave) TPermanentInfo; |
|
215 _sessionData.sessionInfo = new(ELeave) TSessionInfo; |
|
216 _sessionData.sessionInfo->AllowedCaps = KDefaultNullBit; |
|
217 _sessionData.sessionInfo->DeniedCaps = KDefaultNullBit; |
|
218 _sessionData.sessionInfo->AllowedProviders.Reset(); |
|
219 _sessionData.sessionInfo->DeniedProviders.Reset(); |
|
220 _permanentInfo->iAllowedBits = KDefaultNullBit; |
|
221 _permanentInfo->iDeniedBits = KDefaultNullBit; |
|
222 _permanentInfo->iAllowedProviders.Reset(); |
|
223 _permanentInfo->iDeniedProviders.Reset(); |
|
224 iResourceOffsetArray.Reset(); |
|
225 } |
|
226 |
|
227 //--------------------------------------------------------------------------------- |
|
228 //Method to add the resource files to CONE environment. |
|
229 //--------------------------------------------------------------------------------- |
|
230 void CRTSecMgrScriptSession::AddResourceFiles() |
|
231 { |
|
232 if(iCoeEnv) |
|
233 { |
|
234 CDesCArray* diskList = new (ELeave) CDesCArrayFlat(KDescArrayInit); |
|
235 CleanupStack::PushL (diskList); |
|
236 |
|
237 BaflUtils::GetDiskListL (iCoeEnv->FsSession (), *diskList); |
|
238 for (TInt idx(0); idx<diskList->Count ();++idx) |
|
239 { |
|
240 TInt intDrive; |
|
241 TChar ch = ((*diskList)[idx])[0]; |
|
242 RFs::CharToDrive (ch, intDrive); |
|
243 TDriveUnit curDrive(intDrive); |
|
244 |
|
245 TFileName resFile(curDrive.Name ()); |
|
246 resFile.Append (KDC_APP_RESOURCE_DIR); |
|
247 resFile.Append (KSecMgrResourceFile); |
|
248 BaflUtils::NearestLanguageFile (iCoeEnv->FsSession (), resFile); |
|
249 if ( BaflUtils::FileExists (iCoeEnv->FsSession (), resFile)) |
|
250 { |
|
251 TRAPD (err, iResourceOffsetArray.Append(iCoeEnv->AddResourceFileL (resFile))); |
|
252 User::LeaveIfError (err); |
|
253 break; |
|
254 } |
|
255 } |
|
256 CleanupStack::PopAndDestroy (diskList); |
|
257 } |
|
258 } |
|
259 |
|
260 //--------------------------------------------------------------------------------------- |
|
261 //Method to add provider resource files into the CONE environment |
|
262 //Returns the first resource identifier which has the prompt string |
|
263 //--------------------------------------------------------------------------------------- |
|
264 TInt CRTSecMgrScriptSession::AddProviderResourceFile(TFileName aResourceFileName) |
|
265 { |
|
266 RResourceFile resFile; |
|
267 TInt resID(KErrNone); |
|
268 if(iCoeEnv) |
|
269 { |
|
270 CDesCArray* diskList = new (ELeave) CDesCArrayFlat(KDescArrayInit); |
|
271 CleanupStack::PushL (diskList); |
|
272 |
|
273 BaflUtils::GetDiskListL (iCoeEnv->FsSession (), *diskList); |
|
274 for (TInt idx(0); idx<diskList->Count ();++idx) |
|
275 { |
|
276 TInt intDrive; |
|
277 TChar ch = ((*diskList)[idx])[0]; |
|
278 RFs::CharToDrive (ch, intDrive); |
|
279 TDriveUnit curDrive(intDrive); |
|
280 |
|
281 TFileName resFileName(curDrive.Name ()); |
|
282 resFileName.Append (KDC_APP_RESOURCE_DIR); |
|
283 resFileName.Append (aResourceFileName); |
|
284 BaflUtils::NearestLanguageFile (iCoeEnv->FsSession (), resFileName); |
|
285 if ( BaflUtils::FileExists (iCoeEnv->FsSession (), resFileName)) |
|
286 { |
|
287 TRAPD(err,resFile.OpenL(iCoeEnv->FsSession(),resFileName)); |
|
288 if(err == KErrNone) |
|
289 { |
|
290 resFile.ConfirmSignatureL(0); |
|
291 resID = FIRST_RESOURCE_ID(resFile.Offset()); |
|
292 resFile.Close(); |
|
293 iResourceOffsetArray.Append(iCoeEnv->AddResourceFileL (resFileName)); |
|
294 break; |
|
295 } |
|
296 } |
|
297 } |
|
298 CleanupStack::PopAndDestroy(diskList); |
|
299 } |
|
300 return resID; |
|
301 } |
|
302 |
|
303 //-------------------------------------------------------------------------------------------- |
|
304 //Close the resource files previously added |
|
305 //-------------------------------------------------------------------------------------------- |
|
306 void CRTSecMgrScriptSession::CloseResourceFiles() |
|
307 { |
|
308 if (iCoeEnv) |
|
309 { |
|
310 for(TInt i(0); i < iResourceOffsetArray.Count(); i++) |
|
311 iCoeEnv->DeleteResourceFile (iResourceOffsetArray[i]); |
|
312 iResourceOffsetArray.Reset(); |
|
313 } |
|
314 } |
|
315 // --------------------------------------------------------------------------- |
|
316 // Destructor |
|
317 // Closes script sub-session handle |
|
318 // --------------------------------------------------------------------------- |
|
319 // |
|
320 EXPORT_C CRTSecMgrScriptSession::~CRTSecMgrScriptSession() |
|
321 { |
|
322 _permanentInfo->iAllowedProviders.Close(); |
|
323 _permanentInfo->iDeniedProviders.Close(); |
|
324 _sessionData.sessionInfo->AllowedProviders.Close(); |
|
325 _sessionData.sessionInfo->DeniedProviders.Close(); |
|
326 delete _permanentInfo; |
|
327 delete _sessionData.sessionInfo; |
|
328 if(iSessionData) |
|
329 { |
|
330 delete iSessionData; |
|
331 iSessionData = NULL; |
|
332 } |
|
333 Close (); |
|
334 } |
|
335 |
|
336 // --------------------------------------------------------------------------- |
|
337 // Opens script session, in turn opening client-side sub-session handle |
|
338 // --------------------------------------------------------------------------- |
|
339 // |
|
340 TInt CRTSecMgrScriptSession::Open(const RSessionBase& aParentSession, |
|
341 TPolicyID aPolicyID, TExecutableID aExecID) |
|
342 { |
|
343 if (iScript) |
|
344 { |
|
345 delete iScript; |
|
346 iScript = NULL; |
|
347 } |
|
348 |
|
349 iScript = CScript::NewL (aPolicyID, aExecID); |
|
350 |
|
351 TInt ret((*iSubSessionProxy)->Open (aParentSession, *iScript, aPolicyID)); |
|
352 if ( KErrNone==ret) |
|
353 { |
|
354 _permanentInfo->iAllowedBits = iScript->PermGranted (); |
|
355 _permanentInfo->iDeniedBits = iScript->PermDenied (); |
|
356 iScript->PermGranted(_permanentInfo->iAllowedProviders); |
|
357 iScript->PermDenied(_permanentInfo->iDeniedProviders); |
|
358 } |
|
359 |
|
360 return ret; |
|
361 } |
|
362 |
|
363 // --------------------------------------------------------------------------- |
|
364 // Opens script session, in turn opening client-side sub-session handle |
|
365 // --------------------------------------------------------------------------- |
|
366 // |
|
367 TInt CRTSecMgrScriptSession::Open(const RSessionBase& aParentSession, |
|
368 TPolicyID aPolicyID, TExecutableID aExecID, const TDesC& aHashValue) |
|
369 { |
|
370 if (iScript) |
|
371 { |
|
372 delete iScript; |
|
373 iScript = NULL; |
|
374 } |
|
375 |
|
376 iScript = CScript::NewL (aPolicyID, aExecID); |
|
377 TInt ret((*iSubSessionProxy)->Open (aParentSession, *iScript, aPolicyID, aHashValue)); |
|
378 if ( KErrNone==ret) |
|
379 { |
|
380 _permanentInfo->iAllowedBits = iScript->PermGranted (); |
|
381 _permanentInfo->iDeniedBits = iScript->PermDenied (); |
|
382 iScript->PermGranted(_permanentInfo->iAllowedProviders); |
|
383 iScript->PermDenied(_permanentInfo->iDeniedProviders); |
|
384 } |
|
385 |
|
386 return ret; |
|
387 } |
|
388 |
|
389 // --------------------------------------------------------------------------- |
|
390 // Opens script session, in turn opening client-side sub-session handle |
|
391 // --------------------------------------------------------------------------- |
|
392 // |
|
393 TInt CRTSecMgrScriptSession::Open(const RSessionBase& aParentSession, |
|
394 TPolicyID aPolicyID, TExecutableID aExecID, const CTrustInfo& aTrustInfo) |
|
395 { |
|
396 if (iScript) |
|
397 { |
|
398 delete iScript; |
|
399 iScript = NULL; |
|
400 } |
|
401 |
|
402 iScript = CScript::NewL (aPolicyID, aExecID); |
|
403 TInt ret((*iSubSessionProxy)->Open (aParentSession, *iScript, aPolicyID, aTrustInfo)); |
|
404 |
|
405 if ( KErrNone==ret) |
|
406 { |
|
407 _permanentInfo->iAllowedBits = iScript->PermGranted (); |
|
408 _permanentInfo->iDeniedBits = iScript->PermDenied (); |
|
409 iScript->PermGranted(_permanentInfo->iAllowedProviders); |
|
410 iScript->PermDenied(_permanentInfo->iDeniedProviders); |
|
411 } |
|
412 |
|
413 return ret; |
|
414 } |
|
415 |
|
416 // --------------------------------------------------------------------------- |
|
417 // Performs access permission check, returns unmatched capabilities if any |
|
418 // --------------------------------------------------------------------------- |
|
419 // |
|
420 EXPORT_C TInt CRTSecMgrScriptSession::IsAllowed(const RCapabilityArray& aCapabilitiesToCheck,RCapabilityArray& aUnMatchedCapabilities) |
|
421 { |
|
422 RPromptDataList promptDataList; |
|
423 TCapabilityBitSet unMatchedCapBits(KDefaultNullBit); |
|
424 TInt ret(IsAllowed(aCapabilitiesToCheck,promptDataList,unMatchedCapBits)); |
|
425 |
|
426 promptDataList.ResetAndDestroy(); |
|
427 |
|
428 if(KDefaultNullBit!=unMatchedCapBits) |
|
429 BuildCapsL(unMatchedCapBits,aUnMatchedCapabilities); |
|
430 return ret; |
|
431 } |
|
432 |
|
433 // --------------------------------------------------------------------------- |
|
434 // Performs access permission check |
|
435 // --------------------------------------------------------------------------- |
|
436 // |
|
437 EXPORT_C TInt CRTSecMgrScriptSession::IsAllowed(const RCapabilityArray& aCapabilitiesToCheck) |
|
438 { |
|
439 RPromptDataList promptDataList; |
|
440 TCapabilityBitSet unMatchedCapBits(KDefaultNullBit); |
|
441 TInt ret(IsAllowed(aCapabilitiesToCheck,promptDataList,unMatchedCapBits)); |
|
442 promptDataList.ResetAndDestroy(); |
|
443 return ret; |
|
444 } |
|
445 |
|
446 // --------------------------------------------------------------------------- |
|
447 // Private implementation to perform access perform access check. |
|
448 // This function is the real task master |
|
449 // --------------------------------------------------------------------------- |
|
450 // |
|
451 TInt CRTSecMgrScriptSession::IsAllowed( |
|
452 const RCapabilityArray& aCapabilitiesToCheck, |
|
453 RPromptDataList& aPromptDataList, TCapabilityBitSet& aUnMatchedCaps) |
|
454 { |
|
455 if ( aCapabilitiesToCheck.Count ()<=0) |
|
456 { |
|
457 return EAccessOk; //if no capabilities are required, safely return |
|
458 } |
|
459 if ( aCapabilitiesToCheck.Find(ECapabilityTCB) != KErrNotFound) |
|
460 return EAccessNok; |
|
461 aPromptDataList.Reset (); |
|
462 |
|
463 TCapabilityBitSet capToCheck(KDefaultNullBit); |
|
464 TCapabilityBitSet finalCaps(KDefaultNullBit); |
|
465 for (TInt i(0); i!=aCapabilitiesToCheck.Count (); ++i) |
|
466 AddCapability (capToCheck, aCapabilitiesToCheck[i]); |
|
467 |
|
468 capToCheck &= ~(iScript->PermissionSet().UnconditionalCaps()); |
|
469 |
|
470 /* Check if a;ready denied. No point in going forward */ |
|
471 if(capToCheck & _sessionData.sessionInfo->DeniedCaps || capToCheck & _permanentInfo->iDeniedBits) |
|
472 return EAccessNok; |
|
473 |
|
474 TCapabilityBitSet allowedCaps(KDefaultNullBit); |
|
475 allowedCaps |= _sessionData.sessionInfo->AllowedCaps; //for session allowed |
|
476 allowedCaps &= ~_permanentInfo->iDeniedBits; |
|
477 allowedCaps |= _permanentInfo->iAllowedBits; //for permanently allowed |
|
478 |
|
479 //In case if all the capabilities required by the service provider |
|
480 //are allowed without prompting |
|
481 TCapabilityBitSet original_capToCheck = capToCheck; |
|
482 capToCheck &= allowedCaps; |
|
483 if(original_capToCheck == capToCheck) |
|
484 return EAccessOk; |
|
485 |
|
486 capToCheck ^= original_capToCheck ; |
|
487 TBool isPermGrantModified(EFalse); |
|
488 |
|
489 RPermissions perms = iScript->PermissionSet().Permissions (); |
|
490 |
|
491 for (TInt i(0); (i!=perms.Count ())&& capToCheck ;++i) |
|
492 { |
|
493 CPermission* perm = CPermission::NewLC(*perms[i]); |
|
494 |
|
495 TCapabilityBitSet tempCapToCheck(KDefaultNullBit); |
|
496 |
|
497 RCapabilityArray capabilities; |
|
498 perm->Capabilitilites (capabilities); |
|
499 |
|
500 for (TInt capsIdx(0); capsIdx!=capabilities.Count();++capsIdx) |
|
501 { |
|
502 TCapability cap(capabilities[capsIdx]); |
|
503 tempCapToCheck |= LOWBIT << cap; |
|
504 } |
|
505 capToCheck &= tempCapToCheck; |
|
506 if ( capToCheck ) |
|
507 { |
|
508 if ( capToCheck & _permanentInfo->iDeniedBits) //check if permanently disabled |
|
509 { |
|
510 allowedCaps &= ~tempCapToCheck; //just in case... |
|
511 _sessionData.sessionInfo->DeniedCaps &= ~tempCapToCheck; //just in case... |
|
512 } |
|
513 else |
|
514 if ( capToCheck & _sessionData.sessionInfo->DeniedCaps) //not necessary to do this check... |
|
515 { |
|
516 allowedCaps &= ~tempCapToCheck; //just in case... |
|
517 } |
|
518 else |
|
519 if ((capToCheck & allowedCaps) != capToCheck) //check if it's already allowed |
|
520 { |
|
521 //capToCheck &= allowedCaps; |
|
522 TCapabilityBitSet temp = capToCheck; |
|
523 temp &= allowedCaps; |
|
524 temp ^= capToCheck; |
|
525 capToCheck = temp; |
|
526 if ( (perm->Condition() & RTUserPrompt_OneShot) ||(perm->Condition() & RTUserPrompt_Session) ||((perm->Condition() & RTUserPrompt_Permanent) && |
|
527 (iScript->ScriptID()!=KAnonymousScript))) |
|
528 { |
|
529 if ( !(_sessionData.sessionInfo->AllowedCaps & capToCheck)) |
|
530 { |
|
531 //check if it's denied for this session |
|
532 if ( !(_sessionData.sessionInfo->DeniedCaps & capToCheck)) |
|
533 { |
|
534 CPromptData* promptData = CPromptData::NewL();//should write NewL Function |
|
535 promptData->SetPermissions(*perm); |
|
536 promptData->SetUserSelection(perm->Default ()) ; |
|
537 aPromptDataList.Append (promptData); |
|
538 } |
|
539 |
|
540 } |
|
541 else |
|
542 { |
|
543 allowedCaps |= tempCapToCheck; //enable in allowed |
|
544 } |
|
545 } |
|
546 } |
|
547 } |
|
548 capToCheck ^= original_capToCheck; |
|
549 capabilities.Close (); |
|
550 CleanupStack::PopAndDestroy(perm); |
|
551 }//for loop |
|
552 |
|
553 if ( aPromptDataList.Count ()>0) |
|
554 { |
|
555 //TInt ret = EPromptOk; |
|
556 TInt ret = iPromptHdlr->Prompt (aPromptDataList , iScript->ScriptID()); |
|
557 |
|
558 //Iterate over promptDataList and check the user selection |
|
559 RCapabilityArray capArray; |
|
560 for (TInt i(0); i!=aPromptDataList.Count ();++i) |
|
561 { |
|
562 CPermission *perm = (aPromptDataList[i])->iPermission; |
|
563 perm->Capabilitilites(capArray); |
|
564 TCapabilityBitSet tempCapToCheck(KDefaultEnableBit); |
|
565 TCapabilityBitSet userSelectedCaps = 0; |
|
566 for(TInt idx(0); idx != capArray.Count(); idx++) |
|
567 userSelectedCaps |= tempCapToCheck <<capArray[idx]; |
|
568 |
|
569 capArray.Close(); |
|
570 HandleGrantChosen (aPromptDataList[i], userSelectedCaps, allowedCaps, isPermGrantModified); |
|
571 finalCaps |= allowedCaps ; |
|
572 } |
|
573 |
|
574 if ( EPromptOk!=ret) |
|
575 { |
|
576 return EAccessNok; |
|
577 } |
|
578 |
|
579 if ( (iScript->ScriptID()!=KAnonymousScript)&&(isPermGrantModified)) |
|
580 UpdatePermGrant ();//commit perm grant change |
|
581 |
|
582 finalCaps |= _permanentInfo->iAllowedBits ; |
|
583 |
|
584 if((finalCaps & NetworkServices_CAP) && isCustomPrompt) |
|
585 PromptCostL() ; |
|
586 |
|
587 finalCaps |= _sessionData.sessionInfo->AllowedCaps ; |
|
588 |
|
589 |
|
590 if ( KErrNone == ((finalCaps & original_capToCheck) ^ original_capToCheck)) |
|
591 return EAccessOk; |
|
592 else |
|
593 { |
|
594 aUnMatchedCaps = (finalCaps & original_capToCheck) ^ original_capToCheck; |
|
595 return EAccessNok; |
|
596 } |
|
597 } |
|
598 else |
|
599 { |
|
600 return EAccessNok; |
|
601 } |
|
602 |
|
603 } |
|
604 |
|
605 // --------------------------------------------------------------------------- |
|
606 // Default prompt handler implementation |
|
607 // --------------------------------------------------------------------------- |
|
608 // |
|
609 TInt CRTSecMgrScriptSession::Prompt(RPromptDataList& aPromptDataList,TExecutableID /*aExecID*/) |
|
610 { |
|
611 AddResourceFiles(); |
|
612 TInt ret(EPromptOk); |
|
613 TInt promptCount = aPromptDataList.Count (); |
|
614 |
|
615 for (TInt i(0); i<promptCount; ++i) |
|
616 { |
|
617 ret = Prompt (aPromptDataList[i]); |
|
618 if ( EPromptOk!=ret) |
|
619 { |
|
620 for(TInt inLoopCnt(promptCount-1); inLoopCnt>=i; --inLoopCnt) |
|
621 { |
|
622 TUserPromptOption selected = aPromptDataList[inLoopCnt]->iUserSelection; |
|
623 if(!(selected == RTUserPrompt_Denied || selected == RTUserPrompt_SessionDenied || selected == RTUserPrompt_PermDenied)) |
|
624 { |
|
625 delete aPromptDataList[inLoopCnt]; |
|
626 aPromptDataList.Remove(inLoopCnt); |
|
627 } |
|
628 } |
|
629 break; |
|
630 } |
|
631 |
|
632 |
|
633 } |
|
634 CloseResourceFiles(); |
|
635 return ret; |
|
636 } |
|
637 |
|
638 // --------------------------------------------------------------------------- |
|
639 // Private default prompt handler implementation |
|
640 // --------------------------------------------------------------------------- |
|
641 // |
|
642 TInt CRTSecMgrScriptSession::Prompt(CPromptData* aPromptData) |
|
643 { |
|
644 if ( RTPROMPTUI_DEFAULT!=iUIPromptOption) |
|
645 return PromptAdvanced (aPromptData); |
|
646 |
|
647 TInt ret(EPromptOk); |
|
648 TInt stackResCnt(0); |
|
649 |
|
650 CDesCArray* settingPageText = new(ELeave) CDesCArrayFlat(KDescArrayInit); |
|
651 CleanupStack::PushL(settingPageText); |
|
652 |
|
653 HBufC* oneShotOptionText= NULL; |
|
654 HBufC* oneShotDenyText= NULL; |
|
655 HBufC* sessionOptionText= NULL; |
|
656 HBufC* sessionDenyOption= NULL; |
|
657 HBufC* permGrantOptionText= NULL; |
|
658 HBufC* permDenyOption= NULL; |
|
659 |
|
660 TInt selIndex(PROMPT_SELIDX_ZERO); |
|
661 RSelIdxArray selIdxArray; |
|
662 CleanupClosePushL (selIdxArray); |
|
663 |
|
664 if ( (RTUserPrompt_Permanent & (aPromptData->iPermission->Default ())) || (RTUserPrompt_Permanent & (aPromptData->iPermission->Condition ()))) |
|
665 { |
|
666 permGrantOptionText = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_PROMPT_PERM_YES); |
|
667 settingPageText->AppendL (permGrantOptionText->Des ()); |
|
668 ++stackResCnt; |
|
669 |
|
670 selIdxArray.Append (R_RTSECMGR_PROMPT_PERM_YES); |
|
671 |
|
672 if ( RTUserPrompt_Permanent&aPromptData->iPermission->Default ()) |
|
673 selIndex = selIdxArray.Count ()-1; |
|
674 |
|
675 /* permDenyOption = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_PROMPT_PERM_NO); |
|
676 ++stackResCnt; |
|
677 */ |
|
678 } |
|
679 |
|
680 if ( (RTUserPrompt_Session & (aPromptData->iPermission->Default ())) || (RTUserPrompt_Session & (aPromptData->iPermission->Condition ()))) |
|
681 { |
|
682 sessionOptionText = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_PROMPT_SESSION_YES); |
|
683 settingPageText->AppendL (sessionOptionText->Des()); |
|
684 ++stackResCnt; |
|
685 |
|
686 selIdxArray.Append (R_RTSECMGR_PROMPT_SESSION_YES); |
|
687 |
|
688 TUserPromptOption def = aPromptData->iPermission->Default (); |
|
689 if ( RTUserPrompt_Session&def) |
|
690 selIndex = selIdxArray.Count()-1; |
|
691 |
|
692 /* if ( !permDenyOption) |
|
693 { |
|
694 sessionDenyOption = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_PROMPT_SESSION_NO); |
|
695 ++stackResCnt; |
|
696 }*/ |
|
697 } |
|
698 |
|
699 if ( (RTUserPrompt_OneShot & aPromptData->iPermission->Default ()) || (RTUserPrompt_OneShot & aPromptData->iPermission->Condition ())) |
|
700 { |
|
701 oneShotOptionText = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_PROMPT_ONESHOT_YES); |
|
702 settingPageText->AppendL (oneShotOptionText->Des ()); |
|
703 ++stackResCnt; |
|
704 |
|
705 selIdxArray.Append (R_RTSECMGR_PROMPT_ONESHOT_YES); |
|
706 |
|
707 TUserPromptOption def = aPromptData->iPermission->Default (); |
|
708 if ( RTUserPrompt_OneShot&def) |
|
709 selIndex = selIdxArray.Count()-1; |
|
710 /* if ( !permDenyOption && !sessionDenyOption) |
|
711 { |
|
712 oneShotDenyText = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_PROMPT_ONESHOT_NO); |
|
713 ++stackResCnt; |
|
714 }*/ |
|
715 } |
|
716 |
|
717 |
|
718 if ( (RTUserPrompt_OneShot & (aPromptData->iPermission->Default ())) || (RTUserPrompt_OneShot & (aPromptData->iPermission->Condition ()))) |
|
719 { |
|
720 oneShotDenyText = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_PROMPT_ONESHOT_NO); |
|
721 ++stackResCnt; |
|
722 |
|
723 } |
|
724 |
|
725 if ( (RTUserPrompt_Session & (aPromptData->iPermission->Default ())) || (RTUserPrompt_Session & (aPromptData->iPermission->Condition ()))) |
|
726 { |
|
727 if ( !oneShotDenyText) |
|
728 { |
|
729 sessionDenyOption = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_PROMPT_SESSION_NO); |
|
730 ++stackResCnt; |
|
731 } |
|
732 } |
|
733 |
|
734 if ( (RTUserPrompt_Permanent & aPromptData->iPermission->Default ()) || (RTUserPrompt_Permanent & aPromptData->iPermission->Condition ())) |
|
735 { |
|
736 if ( !oneShotDenyText && !sessionDenyOption) |
|
737 { |
|
738 permDenyOption = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_PROMPT_PERM_NO); |
|
739 ++stackResCnt; |
|
740 } |
|
741 } |
|
742 |
|
743 if ( oneShotDenyText) |
|
744 { |
|
745 settingPageText->AppendL (oneShotDenyText->Des ()); |
|
746 selIdxArray.Append (R_RTSECMGR_PROMPT_ONESHOT_NO); |
|
747 } |
|
748 |
|
749 if ( sessionDenyOption) |
|
750 { |
|
751 settingPageText->AppendL (sessionDenyOption->Des ()); |
|
752 selIdxArray.Append (R_RTSECMGR_PROMPT_SESSION_NO); |
|
753 } |
|
754 |
|
755 if ( permDenyOption) |
|
756 { |
|
757 settingPageText->AppendL (permDenyOption->Des ()); |
|
758 selIdxArray.Append (R_RTSECMGR_PROMPT_PERM_NO); |
|
759 } |
|
760 |
|
761 HBufC* body(NULL); |
|
762 HBufC *moreInfo(NULL); |
|
763 |
|
764 if(((aPromptData->iPermission->PermName()).Compare(KNullDesC)) != KErrNone) |
|
765 { |
|
766 if(((aPromptData->iPermission->PermName()).Compare(_L("UserDataGroup"))) == KErrNone ) |
|
767 { |
|
768 body = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_USERDATA_GROUP); |
|
769 ++stackResCnt; |
|
770 } |
|
771 else if(((aPromptData->iPermission->PermName()).Compare(_L("DeviceResourcesGroup"))) == KErrNone ) |
|
772 { |
|
773 body = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_DEVICERESOURCES_GROUP); |
|
774 ++stackResCnt; |
|
775 } |
|
776 else if(((aPromptData->iPermission->PermName()).Compare(_L("NetworkGroup"))) == KErrNone ) |
|
777 { |
|
778 body = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_NETWORK_GROUP); |
|
779 ++stackResCnt; |
|
780 } |
|
781 } |
|
782 else if ( (aPromptData->iPermission->Capability()<KCapabilitySize) && (aPromptData->iPermission->Capability()>ECapabilityTCB)) |
|
783 { |
|
784 TInt textResID(CAPABILITY_RESOURCEID[aPromptData->iPermission->Capability()]); |
|
785 if(KErrNone!=textResID) |
|
786 { |
|
787 body = iCoeEnv->AllocReadResourceLC (textResID); |
|
788 ++stackResCnt; |
|
789 } |
|
790 } |
|
791 |
|
792 if(((aPromptData->iPermission->PermName()).Compare(KNullDesC)) != KErrNone) |
|
793 { |
|
794 moreInfo = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_ITEM_MORE_INFO); |
|
795 ++stackResCnt; |
|
796 if( moreInfo ) |
|
797 { |
|
798 settingPageText->AppendL (moreInfo->Des ()); |
|
799 selIdxArray.Append (R_RTSECMGR_ITEM_MORE_INFO); |
|
800 } |
|
801 } |
|
802 |
|
803 CAknListQueryDialog* queryDialog = new (ELeave) CAknListQueryDialog(&selIndex); |
|
804 CleanupStack::PushL (queryDialog); |
|
805 ++stackResCnt; |
|
806 |
|
807 queryDialog->PrepareLC (R_LIST_QUERY_MSGBOX); |
|
808 |
|
809 queryDialog->SetItemTextArray (settingPageText); |
|
810 queryDialog->SetOwnershipType(ELbmDoesNotOwnItemArray); |
|
811 |
|
812 CAknMessageQueryControl* msgBox = queryDialog->MessageBox (); |
|
813 if ( msgBox && body ) |
|
814 msgBox->SetMessageTextL (body); |
|
815 |
|
816 CAknPopupHeadingPane* heading = queryDialog->QueryHeading (); |
|
817 HBufC* headerText(NULL); |
|
818 if ( heading) |
|
819 { |
|
820 heading->SetLayout (CAknPopupHeadingPane::EMessageQueryHeadingPane); |
|
821 headerText = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_PROMPT_QUERY_HEADER); |
|
822 heading->SetTextL (headerText->Des ()); |
|
823 ++stackResCnt; |
|
824 } |
|
825 |
|
826 if(moreInfo) |
|
827 { |
|
828 TListItemProperties moreInfoProperties; |
|
829 moreInfoProperties.SetUnderlined(ETrue); |
|
830 queryDialog->ListControl()->Listbox()->ItemDrawer()->SetPropertiesL(settingPageText->Count()-1,moreInfoProperties); |
|
831 } |
|
832 |
|
833 CleanupStack::Pop (stackResCnt); |
|
834 |
|
835 queryDialog->ListBox()->SetCurrentItemIndex(selIndex); |
|
836 |
|
837 TInt queryOk = queryDialog->RunLD (); |
|
838 if ( queryOk == EAknSoftkeyOk) |
|
839 { |
|
840 if ( (selIndex>=0) && (selIndex<selIdxArray.Count())) |
|
841 { |
|
842 if ( R_RTSECMGR_PROMPT_ONESHOT_YES==selIdxArray[selIndex]) |
|
843 aPromptData->iUserSelection = RTUserPrompt_OneShot; |
|
844 |
|
845 else if ( R_RTSECMGR_PROMPT_ONESHOT_NO==selIdxArray[selIndex]) |
|
846 { |
|
847 aPromptData->iUserSelection = RTUserPrompt_Denied; |
|
848 ret = EPromptCancel; |
|
849 } |
|
850 |
|
851 else if ( R_RTSECMGR_PROMPT_SESSION_YES==selIdxArray[selIndex]) |
|
852 aPromptData->iUserSelection = RTUserPrompt_Session; |
|
853 |
|
854 else if ( R_RTSECMGR_PROMPT_SESSION_NO==selIdxArray[selIndex]) |
|
855 { |
|
856 aPromptData->iUserSelection = RTUserPrompt_SessionDenied; |
|
857 ret = EPromptCancel; |
|
858 } |
|
859 |
|
860 else if ( R_RTSECMGR_PROMPT_PERM_YES==selIdxArray[selIndex]) |
|
861 aPromptData->iUserSelection = RTUserPrompt_Permanent; |
|
862 |
|
863 else if ( R_RTSECMGR_PROMPT_PERM_NO==selIdxArray[selIndex]) |
|
864 { |
|
865 aPromptData->iUserSelection = RTUserPrompt_PermDenied; |
|
866 ret = EPromptCancel; |
|
867 } |
|
868 |
|
869 else if ( R_RTSECMGR_ITEM_MORE_INFO == selIdxArray[selIndex]) |
|
870 { |
|
871 ret = MoreInfoL(*aPromptData); |
|
872 } |
|
873 } |
|
874 } |
|
875 else |
|
876 { |
|
877 ret = EPromptCancel; |
|
878 } |
|
879 |
|
880 if ( headerText) |
|
881 delete headerText; |
|
882 |
|
883 if ( body) |
|
884 delete body; |
|
885 |
|
886 if ( oneShotOptionText) |
|
887 delete oneShotOptionText; |
|
888 |
|
889 if ( sessionOptionText) |
|
890 delete sessionOptionText; |
|
891 |
|
892 if ( permGrantOptionText) |
|
893 delete permGrantOptionText; |
|
894 |
|
895 if ( oneShotDenyText) |
|
896 delete oneShotDenyText; |
|
897 |
|
898 if ( sessionDenyOption) |
|
899 delete sessionDenyOption; |
|
900 |
|
901 if ( permDenyOption) |
|
902 delete permDenyOption; |
|
903 |
|
904 if (moreInfo) |
|
905 delete moreInfo; |
|
906 |
|
907 CleanupStack::PopAndDestroy ();//settingPageText |
|
908 CleanupStack::PopAndDestroy ();//selIdxArray |
|
909 return ret; |
|
910 } |
|
911 |
|
912 |
|
913 |
|
914 // --------------------------------------------------------------------------- |
|
915 // Private default prompt handler implementation for advanced prompt UI |
|
916 // --------------------------------------------------------------------------- |
|
917 // |
|
918 TInt CRTSecMgrScriptSession::PromptAdvanced(CPromptData* aPromptData) |
|
919 { |
|
920 TInt ret(EPromptOk); |
|
921 TInt selIndex(PROMPT_SELIDX_ZERO); //R_RTSECMGR_PROMPT_ONESHOT_YES |
|
922 TInt stackResCnt(0); |
|
923 |
|
924 HBufC* msgText(NULL); |
|
925 HBufC* moreInfo(NULL); |
|
926 TBuf<256> LinkText; |
|
927 |
|
928 if(((aPromptData->iPermission->PermName()).Compare(KNullDesC)) != KErrNone) |
|
929 { |
|
930 if(((aPromptData->iPermission->PermName()).Compare(_L("UserDataGroup"))) == KErrNone ) |
|
931 { |
|
932 msgText = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_USERDATA_GROUP); |
|
933 LinkText.Append(msgText->Des()); |
|
934 ++stackResCnt; |
|
935 } |
|
936 else if(((aPromptData->iPermission->PermName()).Compare(_L("DeviceResourcesGroup"))) == KErrNone ) |
|
937 { |
|
938 msgText = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_DEVICERESOURCES_GROUP); |
|
939 LinkText.Append(msgText->Des()); |
|
940 ++stackResCnt; |
|
941 } |
|
942 else if(((aPromptData->iPermission->PermName()).Compare(_L("NetworkGroup"))) == KErrNone ) |
|
943 { |
|
944 msgText = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_NETWORK_GROUP); |
|
945 LinkText.Append(msgText->Des()); |
|
946 ++stackResCnt; |
|
947 } |
|
948 } |
|
949 else if ((aPromptData->iPermission->Capability()<KCapabilitySize) && (aPromptData->iPermission->Capability()>ECapabilityTCB)) |
|
950 { |
|
951 TInt textResID(CAPABILITY_RESOURCEID[aPromptData->iPermission->Capability()]); |
|
952 if(KErrNone!=textResID) |
|
953 { |
|
954 msgText = iCoeEnv->AllocReadResourceLC (textResID); |
|
955 ++stackResCnt; |
|
956 LinkText.Append(msgText->Des()); |
|
957 } |
|
958 } |
|
959 |
|
960 if(((aPromptData->iPermission->PermName()).Compare(KNullDesC)) != KErrNone) |
|
961 { |
|
962 moreInfo = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_LINK_MORE_INFO); |
|
963 ++stackResCnt; |
|
964 |
|
965 LinkText.Append(_L("\n\n")); |
|
966 LinkText.Append(_L("<AknMessageQuery Link>")); |
|
967 LinkText.Append(moreInfo->Des()); |
|
968 LinkText.Append(_L("</AknMessageQuery Link>")); |
|
969 } |
|
970 |
|
971 CAknMessageQueryDialog* queryDialog = new(ELeave) CAknMessageQueryDialog(); |
|
972 CleanupStack::PushL (queryDialog); |
|
973 ++stackResCnt; |
|
974 |
|
975 queryDialog->PrepareLC (R_ADVPROMPT_MESSAGE_QUERY); |
|
976 |
|
977 queryDialog->SetMessageTextL(LinkText); |
|
978 HBufC* headerText(NULL); |
|
979 CAknPopupHeadingPane* heading = queryDialog->QueryHeading (); |
|
980 if ( heading) |
|
981 { |
|
982 heading->SetLayout (CAknPopupHeadingPane::EMessageQueryHeadingPane); |
|
983 headerText = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_PROMPT_QUERY_HEADER); |
|
984 heading->SetTextL (headerText->Des ()); |
|
985 ++stackResCnt; |
|
986 } |
|
987 |
|
988 if(moreInfo) |
|
989 { |
|
990 TCallBack callback; |
|
991 TCallbackParam callbackParam; |
|
992 |
|
993 callbackParam.iPromptData = aPromptData; |
|
994 callbackParam.iRTSecMgrScriptSession = this; |
|
995 callback.iFunction = LinkCallback; |
|
996 callback.iPtr = &callbackParam; |
|
997 |
|
998 queryDialog->SetLink(callback); |
|
999 } |
|
1000 |
|
1001 CleanupStack::Pop (stackResCnt); |
|
1002 TInt queryOk = queryDialog->RunLD (); |
|
1003 if ( queryOk == EAknSoftkeyYes) |
|
1004 { |
|
1005 if ( selIndex==0) |
|
1006 { |
|
1007 if ( aPromptData->iPermission->Default ()& RTUserPrompt_OneShot) |
|
1008 { |
|
1009 aPromptData->SetUserSelection(RTUserPrompt_OneShot); |
|
1010 } |
|
1011 else |
|
1012 if ( aPromptData->iPermission->Default ()& RTUserPrompt_Session) |
|
1013 { |
|
1014 aPromptData->SetUserSelection(RTUserPrompt_Session); |
|
1015 } |
|
1016 else |
|
1017 if ( aPromptData->iPermission->Default ()& RTUserPrompt_Permanent) |
|
1018 { |
|
1019 aPromptData->SetUserSelection(RTUserPrompt_Permanent); |
|
1020 } |
|
1021 } |
|
1022 else |
|
1023 { |
|
1024 aPromptData->SetUserSelection(RTUserPrompt_Denied); |
|
1025 } |
|
1026 } |
|
1027 else |
|
1028 { |
|
1029 ret = EPromptCancel; |
|
1030 } |
|
1031 |
|
1032 if ( headerText) |
|
1033 delete headerText; |
|
1034 |
|
1035 if ( msgText) |
|
1036 delete msgText; |
|
1037 |
|
1038 if ( moreInfo) |
|
1039 delete moreInfo; |
|
1040 |
|
1041 return ret; |
|
1042 } |
|
1043 // --------------------------------------------------------------------------- |
|
1044 // Pops up a new query dialog when the user clicks on more info. |
|
1045 // --------------------------------------------------------------------------- |
|
1046 // |
|
1047 TInt CRTSecMgrScriptSession::MoreInfoL(CPromptData& aPromptData) |
|
1048 { |
|
1049 TInt ret(EPromptOk); |
|
1050 TInt stackResCnt = 0; |
|
1051 HBufC *msgText = NULL; |
|
1052 HBufC *body = NULL; |
|
1053 TBuf<KMaxBuf> message; |
|
1054 RCapabilityArray Caps; |
|
1055 |
|
1056 msgText = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_MORE_INFO_QUERY); |
|
1057 ++stackResCnt; |
|
1058 message.Append(msgText->Des()); |
|
1059 |
|
1060 aPromptData.Permission()->Capabilitilites(Caps); |
|
1061 for(TInt i = 0; i != Caps.Count(); ++i) |
|
1062 { |
|
1063 TInt textResID(MOREINFO_CAP_RESOURCEID[Caps[i]]); |
|
1064 body = iCoeEnv->AllocReadResourceLC (textResID); |
|
1065 message.Append(_L("\n")); |
|
1066 message.Append(body->Des()); |
|
1067 if(body) |
|
1068 CleanupStack :: PopAndDestroy(body); |
|
1069 } |
|
1070 Caps.Close(); |
|
1071 |
|
1072 CAknMessageQueryDialog* queryDialog = new(ELeave) CAknMessageQueryDialog(); |
|
1073 CleanupStack::PushL (queryDialog); |
|
1074 ++stackResCnt; |
|
1075 |
|
1076 queryDialog->PrepareLC (R_MOREINFO_MESSAGE_QUERY); |
|
1077 |
|
1078 queryDialog->SetMessageTextL(message); |
|
1079 |
|
1080 HBufC* headerText(NULL); |
|
1081 CAknPopupHeadingPane* heading = queryDialog->QueryHeading (); |
|
1082 if ( heading) |
|
1083 { |
|
1084 heading->SetLayout (CAknPopupHeadingPane::EMessageQueryHeadingPane); |
|
1085 |
|
1086 if(((aPromptData.iPermission->PermName()).Compare(_L("UserDataGroup"))) == KErrNone ) |
|
1087 { |
|
1088 headerText = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_MORE_INFO_HEADER_USERDATA); |
|
1089 } |
|
1090 else if(((aPromptData.iPermission->PermName()).Compare(_L("DeviceResourcesGroup"))) == KErrNone ) |
|
1091 { |
|
1092 headerText = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_MORE_INFO_HEADER_DEVICERESOURCES); |
|
1093 } |
|
1094 else if(((aPromptData.iPermission->PermName()).Compare(_L("NetworkGroup"))) == KErrNone ) |
|
1095 { |
|
1096 headerText = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_MORE_INFO_HEADER_NETWORK); |
|
1097 } |
|
1098 |
|
1099 // headerText = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_PROMPT_QUERY_HEADER); |
|
1100 heading->SetTextL (headerText->Des ()); |
|
1101 ++stackResCnt; |
|
1102 } |
|
1103 |
|
1104 CleanupStack::Pop(stackResCnt); |
|
1105 |
|
1106 TInt queryOk = queryDialog->RunLD (); |
|
1107 |
|
1108 if(headerText) |
|
1109 delete headerText; |
|
1110 |
|
1111 if(msgText) |
|
1112 delete msgText; |
|
1113 |
|
1114 if(iUIPromptOption!=RTPROMPTUI_ADVANCED) |
|
1115 ret = Prompt(&aPromptData); |
|
1116 |
|
1117 return ret; |
|
1118 } |
|
1119 |
|
1120 |
|
1121 // --------------------------------------------------------------------------- |
|
1122 // Pops up a new query dialog when the user clicks on more info. |
|
1123 // --------------------------------------------------------------------------- |
|
1124 // |
|
1125 void CRTSecMgrScriptSession::PromptCostL() |
|
1126 { |
|
1127 AddResourceFiles(); |
|
1128 TInt stackResCnt = 0; |
|
1129 HBufC *msgText = NULL; |
|
1130 TBuf<KMaxBuf> message; |
|
1131 RCapabilityArray Caps; |
|
1132 |
|
1133 |
|
1134 msgText = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_COST_INFO); |
|
1135 ++stackResCnt; |
|
1136 message.Append(msgText->Des()); |
|
1137 |
|
1138 CAknMessageQueryDialog* queryDialog = new(ELeave) CAknMessageQueryDialog(); |
|
1139 CleanupStack::PushL (queryDialog); |
|
1140 ++stackResCnt; |
|
1141 |
|
1142 queryDialog->PrepareLC (R_MOREINFO_MESSAGE_QUERY); |
|
1143 |
|
1144 queryDialog->SetMessageTextL(message); |
|
1145 |
|
1146 HBufC* headerText(NULL); |
|
1147 CAknPopupHeadingPane* heading = queryDialog->QueryHeading (); |
|
1148 if ( heading) |
|
1149 { |
|
1150 heading->SetLayout (CAknPopupHeadingPane::EMessageQueryHeadingPane); |
|
1151 headerText = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_PROMPT_QUERY_HEADER); |
|
1152 heading->SetTextL (headerText->Des ()); |
|
1153 ++stackResCnt; |
|
1154 } |
|
1155 |
|
1156 CleanupStack::Pop(stackResCnt); |
|
1157 |
|
1158 TInt queryOk = queryDialog->RunLD (); |
|
1159 |
|
1160 if(headerText) |
|
1161 delete headerText; |
|
1162 |
|
1163 if(msgText) |
|
1164 delete msgText; |
|
1165 CloseResourceFiles(); |
|
1166 } |
|
1167 // --------------------------------------------------------------------------- |
|
1168 // Handles the prompt option chosen by the user through default prompt UI |
|
1169 // --------------------------------------------------------------------------- |
|
1170 // |
|
1171 void CRTSecMgrScriptSession::HandleGrantChosen(CPromptData* aPromptData, |
|
1172 TCapabilityBitSet aCapBitSet, TCapabilityBitSet& aAllowedCaps, |
|
1173 TBool& aIsPermGrantModified) |
|
1174 { |
|
1175 TUserPromptOption optionChosen = aPromptData->iUserSelection; |
|
1176 |
|
1177 if ( RTUserPrompt_OneShot==optionChosen) |
|
1178 { |
|
1179 _sessionData.sessionInfo->AllowedCaps &= ~aCapBitSet; |
|
1180 aAllowedCaps = aCapBitSet; |
|
1181 } |
|
1182 else |
|
1183 if ( RTUserPrompt_Denied==optionChosen) //one-shot denied |
|
1184 { |
|
1185 aAllowedCaps &= ~aCapBitSet; |
|
1186 _sessionData.sessionInfo->AllowedCaps &= ~aCapBitSet; //disable in session pattern too... |
|
1187 } |
|
1188 else |
|
1189 if ( RTUserPrompt_Session==optionChosen) |
|
1190 { |
|
1191 _sessionData.sessionInfo->AllowedCaps |= aCapBitSet;//Enable in _sessionData.Allowed & allowed |
|
1192 aAllowedCaps = aCapBitSet; |
|
1193 } |
|
1194 else |
|
1195 if ( RTUserPrompt_SessionDenied==optionChosen) //session denied |
|
1196 { |
|
1197 aAllowedCaps &= ~aCapBitSet; |
|
1198 _sessionData.sessionInfo->AllowedCaps &= ~aCapBitSet; //disable in session pattern too... |
|
1199 _sessionData.sessionInfo->DeniedCaps |= aCapBitSet; //enable denied in session bit |
|
1200 } |
|
1201 else |
|
1202 if ( RTUserPrompt_Permanent==optionChosen) |
|
1203 { |
|
1204 aIsPermGrantModified = ETrue; //to commit the change to persistent store |
|
1205 _sessionData.sessionInfo->AllowedCaps |= aCapBitSet; |
|
1206 aAllowedCaps = aCapBitSet; |
|
1207 _permanentInfo->iAllowedBits |= aCapBitSet; |
|
1208 _permanentInfo->iDeniedBits &= ~aCapBitSet; //just in case.... |
|
1209 } |
|
1210 else |
|
1211 if ( RTUserPrompt_PermDenied==optionChosen) //permanent denied |
|
1212 { |
|
1213 aIsPermGrantModified = ETrue; |
|
1214 aAllowedCaps &= ~aCapBitSet; |
|
1215 _sessionData.sessionInfo->AllowedCaps &= ~aCapBitSet; //disable in session pattern too... |
|
1216 _sessionData.sessionInfo->DeniedCaps |= aCapBitSet; //enable denied in session bit |
|
1217 _permanentInfo->iAllowedBits &= ~aCapBitSet; //disable in perm bits |
|
1218 _permanentInfo->iDeniedBits |= aCapBitSet; //enable in perm denied bit pattern |
|
1219 //Commit the change to persistent store... |
|
1220 } |
|
1221 } |
|
1222 |
|
1223 // --------------------------------------------------------------------------- |
|
1224 // Updates blanket permission data |
|
1225 // --------------------------------------------------------------------------- |
|
1226 // |
|
1227 void CRTSecMgrScriptSession::UpdatePermGrant() |
|
1228 { |
|
1229 if(iUIPromptOption == RTPROMPTUI_PROVIDER) |
|
1230 (*iSubSessionProxy)->UpdatePermGrant (iScript->ScriptID (),_permanentInfo->iAllowedProviders, _permanentInfo->iDeniedProviders); |
|
1231 else |
|
1232 (*iSubSessionProxy)->UpdatePermGrant (iScript->ScriptID (), _permanentInfo->iAllowedBits,_permanentInfo->iDeniedBits); |
|
1233 } |
|
1234 |
|
1235 // |
|
1236 // Conversion utility to convert a single 32-bit value to the list of |
|
1237 // capabilities (RArray<TCapability>) |
|
1238 // |
|
1239 void CRTSecMgrScriptSession::BuildCapsL(TCapabilityBitSet aCapBitSet, |
|
1240 RCapabilityArray& aInOutTCapList) |
|
1241 { |
|
1242 TInt idx(KErrNotFound); |
|
1243 |
|
1244 while (++idx!=KCapabilitySize) |
|
1245 { |
|
1246 TCapabilityBitSet temp(KDefaultEnableBit); |
|
1247 temp = temp << idx; |
|
1248 if ( aCapBitSet & temp) |
|
1249 aInOutTCapList.AppendL ((TCapability)(idx+1)); |
|
1250 } |
|
1251 } |
|
1252 |
|
1253 // |
|
1254 // Conversion utility to generate a single 32-bit value from a list of |
|
1255 // capabilities (RArray<TCapability>) |
|
1256 // |
|
1257 void CRTSecMgrScriptSession::AddCapability(TCapabilityBitSet& aInOutCapBitSet, |
|
1258 TCapability aCapToSet) |
|
1259 { |
|
1260 if ( aCapToSet>=0) |
|
1261 aInOutCapBitSet = aInOutCapBitSet | (LOWBIT << aCapToSet); |
|
1262 } |
|
1263 |
|
1264 /* |
|
1265 * Closes the script sub-session |
|
1266 * |
|
1267 */ |
|
1268 void CRTSecMgrScriptSession::Close() |
|
1269 { |
|
1270 if (iCoeEnv) |
|
1271 for(TInt i(0); i < iResourceOffsetArray.Count(); i++) |
|
1272 iCoeEnv->DeleteResourceFile (iResourceOffsetArray[i]); |
|
1273 |
|
1274 if ( iScript) |
|
1275 { |
|
1276 delete iScript; |
|
1277 iScript = NULL; |
|
1278 } |
|
1279 |
|
1280 if ( iSubSessionProxy) |
|
1281 { |
|
1282 delete iSubSessionProxy; |
|
1283 iSubSessionProxy = NULL; |
|
1284 } |
|
1285 } |
|
1286 |
|
1287 //--------------------------------------------------------------------------- |
|
1288 // Callback function called from moreinfo link in advanced prompt |
|
1289 //--------------------------------------------------------------------------- |
|
1290 TInt CRTSecMgrScriptSession::LinkCallback(TAny * aCallbackParam) |
|
1291 { |
|
1292 TCallbackParam *cb = (TCallbackParam*)aCallbackParam; |
|
1293 (cb->iRTSecMgrScriptSession)->MoreInfoL(*(cb->iPromptData)); |
|
1294 return KErrNone; |
|
1295 } |
|
1296 |
|
1297 //--------------------------------------------------------------------------------------------------- |
|
1298 //Overloaded IsAllowed method for provider based prompting |
|
1299 //--------------------------------------------------------------------------------------------------- |
|
1300 EXPORT_C TInt CRTSecMgrScriptSession::IsAllowed(const RCapabilityArray& aCapabilitiesToCheck, |
|
1301 TProviderUid aProviderUid, |
|
1302 TFileName aResourceFileName) |
|
1303 { |
|
1304 if ( aCapabilitiesToCheck.Count () <= 0) |
|
1305 { |
|
1306 return EAccessOk; //if no capabilities are required, safely return |
|
1307 } |
|
1308 if ( aCapabilitiesToCheck.Find(ECapabilityTCB) != KErrNotFound) |
|
1309 return EAccessNok; |
|
1310 |
|
1311 if((aProviderUid.iUid <= KErrNone) || ((aResourceFileName.Compare(KNullDesC))==KErrNone)) |
|
1312 return ErrInvalidParameters; |
|
1313 |
|
1314 TInt stackResCnt(0); |
|
1315 TCapabilityBitSet capToCheck(KDefaultNullBit); |
|
1316 for (TInt i(0); i!=aCapabilitiesToCheck.Count (); ++i) |
|
1317 AddCapability (capToCheck, aCapabilitiesToCheck[i]); |
|
1318 |
|
1319 capToCheck &= ~(iScript->PermissionSet().UnconditionalCaps()); |
|
1320 if (!capToCheck) |
|
1321 return EAccessOk; |
|
1322 if((_sessionData.sessionInfo->DeniedProviders.Find(aProviderUid) != KErrNotFound) || (_permanentInfo->iDeniedProviders.Find(aProviderUid) != KErrNotFound)) |
|
1323 return EAccessNok; |
|
1324 |
|
1325 if((_sessionData.sessionInfo->AllowedProviders.Find(aProviderUid) != KErrNotFound)|| (_permanentInfo->iAllowedProviders.Find(aProviderUid) != KErrNotFound)) |
|
1326 return EAccessOk; |
|
1327 |
|
1328 TBool isPermGrantModified(EFalse); |
|
1329 RPermissions perms = iScript->PermissionSet().Permissions(); |
|
1330 TCapabilityBitSet tempCapToCheck(KDefaultNullBit); |
|
1331 |
|
1332 //All the capabilities allowed for the domain |
|
1333 for (TInt permIdx(0); permIdx!=perms.Count();++permIdx) |
|
1334 { |
|
1335 tempCapToCheck |= perms[permIdx]->PermissionData(); |
|
1336 } |
|
1337 |
|
1338 //If the capabilities is allowed with prompting |
|
1339 if((tempCapToCheck & capToCheck) == capToCheck) |
|
1340 { |
|
1341 /*TODO: Changes based on the decision on what needs |
|
1342 to be done of the default capability is different |
|
1343 for capabilities required by the provider. Presently taking least duration*/ |
|
1344 TUserPromptOption defaultOption(RTUserPrompt_OneShot); |
|
1345 for(TInt i=0; i < perms.Count(); i++) |
|
1346 { |
|
1347 if((perms[i]->Default() == RTUserPrompt_OneShot) && (perms[i]->PermissionData() & capToCheck)) |
|
1348 { |
|
1349 defaultOption = RTUserPrompt_OneShot; |
|
1350 break; |
|
1351 } |
|
1352 else if((perms[i]->Default() == RTUserPrompt_Session) && (perms[i]->PermissionData() & capToCheck)) |
|
1353 { |
|
1354 defaultOption = RTUserPrompt_Session; |
|
1355 } |
|
1356 else if((perms[i]->Default() == RTUserPrompt_Permanent) && (perms[i]->PermissionData() & capToCheck) && (defaultOption != RTUserPrompt_Session)) |
|
1357 { |
|
1358 defaultOption = RTUserPrompt_Permanent; |
|
1359 } |
|
1360 } |
|
1361 //= perms[0]->Default(); |
|
1362 //TUserPromptOption defaultOption(RTUserPrompt_Session); |
|
1363 AddResourceFiles(); |
|
1364 TInt resID(KErrNone); |
|
1365 resID = AddProviderResourceFile(aResourceFileName); |
|
1366 |
|
1367 if(resID <= KErrNone) |
|
1368 return KErrNotFound; |
|
1369 |
|
1370 HBufC* messageBody = NULL; |
|
1371 |
|
1372 //Get the application name. If not set use the default name |
|
1373 if(iSessionData != NULL ) |
|
1374 { |
|
1375 TPtr appNamePtr = iSessionData->Des(); |
|
1376 messageBody = StringLoader::LoadL( resID, appNamePtr, iCoeEnv ); |
|
1377 CleanupStack::PushL(messageBody); |
|
1378 ++stackResCnt; |
|
1379 } |
|
1380 else |
|
1381 { |
|
1382 HBufC* defaultName = iCoeEnv->AllocReadResourceLC(R_DEFAULT_APPLICATION_NAME); |
|
1383 TPtr defaultNamePtr = defaultName->Des(); |
|
1384 messageBody = StringLoader::LoadL( resID, defaultNamePtr, iCoeEnv ); |
|
1385 CleanupStack::PopAndDestroy(defaultName); |
|
1386 CleanupStack::PushL(messageBody); |
|
1387 ++stackResCnt; |
|
1388 } |
|
1389 |
|
1390 CAknMessageQueryDialog* queryDialog = new(ELeave) CAknMessageQueryDialog(); |
|
1391 CleanupStack::PushL (queryDialog); |
|
1392 ++stackResCnt; |
|
1393 |
|
1394 queryDialog->PrepareLC (R_ADVPROMPT_MESSAGE_QUERY); |
|
1395 |
|
1396 queryDialog->SetMessageTextL(messageBody->Des()); |
|
1397 |
|
1398 HBufC* headerText(NULL); |
|
1399 CAknPopupHeadingPane* heading = queryDialog->QueryHeading (); |
|
1400 if ( heading) |
|
1401 { |
|
1402 heading->SetLayout (CAknPopupHeadingPane::EMessageQueryHeadingPane); |
|
1403 headerText = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_PROMPT_QUERY_HEADER); |
|
1404 heading->SetTextL (headerText->Des ()); |
|
1405 ++stackResCnt; |
|
1406 } |
|
1407 |
|
1408 TInt ret(EAccessNok); |
|
1409 TBool costPromptRequired(EFalse); |
|
1410 CleanupStack::Pop (stackResCnt); |
|
1411 TInt queryOk = queryDialog->RunLD (); |
|
1412 if ( queryOk == EAknSoftkeyYes) |
|
1413 { |
|
1414 |
|
1415 if ( defaultOption & RTUserPrompt_OneShot) |
|
1416 { |
|
1417 ret = EAccessOk; |
|
1418 } |
|
1419 else if ( defaultOption& RTUserPrompt_Session) |
|
1420 { |
|
1421 _sessionData.sessionInfo->AllowedProviders.Append(aProviderUid); //session allow |
|
1422 ret = EAccessOk; |
|
1423 } |
|
1424 else if ( defaultOption& RTUserPrompt_Permanent) |
|
1425 { |
|
1426 _sessionData.sessionInfo->AllowedProviders.Append(aProviderUid); //session allow |
|
1427 _permanentInfo->iAllowedProviders.Append(aProviderUid); //permanent allow |
|
1428 isPermGrantModified = ETrue; //Flag for server update |
|
1429 ret = EAccessOk; |
|
1430 } |
|
1431 else |
|
1432 { |
|
1433 ret = EAccessNok; |
|
1434 } |
|
1435 } |
|
1436 else |
|
1437 { |
|
1438 if ( defaultOption & RTUserPrompt_OneShot) |
|
1439 { |
|
1440 ret = EAccessNok; |
|
1441 } |
|
1442 else if ( defaultOption& RTUserPrompt_Session) |
|
1443 { |
|
1444 _sessionData.sessionInfo->DeniedProviders.Append(aProviderUid); //session deny |
|
1445 ret = EAccessNok; |
|
1446 } |
|
1447 else if ( defaultOption& RTUserPrompt_Permanent) |
|
1448 { |
|
1449 _sessionData.sessionInfo->DeniedProviders.Append(aProviderUid); //session deny |
|
1450 _permanentInfo->iDeniedProviders.Append(aProviderUid); //permanent deny |
|
1451 isPermGrantModified = ETrue; //Flag for server update |
|
1452 ret = EAccessNok; |
|
1453 } |
|
1454 } |
|
1455 CloseResourceFiles(); |
|
1456 |
|
1457 /* If its a pre-registered script and perm grant is modified update server */ |
|
1458 if(isPermGrantModified && (iScript->ScriptID() != KAnonymousScript)) |
|
1459 UpdatePermGrant(); |
|
1460 |
|
1461 if(messageBody) |
|
1462 delete messageBody; |
|
1463 |
|
1464 if(headerText) |
|
1465 delete headerText; |
|
1466 |
|
1467 return ret; |
|
1468 } |
|
1469 return EAccessNok; |
|
1470 } |
|
1471 |
|
1472 //--------------------------------------------------------------------------------------------- |
|
1473 //Method to set the application name. |
|
1474 //Called by the runtimes to set the name of the widget/flash content |
|
1475 //--------------------------------------------------------------------------------------------- |
|
1476 EXPORT_C void CRTSecMgrScriptSession::SetApplicationNameL(const TDesC& aName) |
|
1477 { |
|
1478 if(iSessionData) |
|
1479 { |
|
1480 delete iSessionData; |
|
1481 iSessionData = NULL; |
|
1482 } |
|
1483 /* Limit on the length of the application name */ |
|
1484 /*if(aName.Length() > KMaxAppName) |
|
1485 User::Leave(KErrOverflow);*/ |
|
1486 iSessionData = aName.AllocL(); |
|
1487 } |
|