|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "srvreqs.h" |
|
17 #include "backup.h" |
|
18 #include "srvsubsess.h" |
|
19 #include "log.h" |
|
20 #include "centralrepositoryinternal.h" |
|
21 #include <e32def_private.h> |
|
22 |
|
23 using namespace NCentralRepositoryConstants; |
|
24 |
|
25 CServerSubSession::CServerSubSession(CServerSession* aSession) |
|
26 : iSession(aSession), iInitialised(EFalse) |
|
27 { |
|
28 } |
|
29 |
|
30 CServerSubSession::~CServerSubSession() |
|
31 { |
|
32 #ifdef SRVSUBSESS_TRACE |
|
33 TUid uid = RepositoryUid(); |
|
34 |
|
35 __SRVSUBSESS_TRACE1("~CServerSubSession() UID: 0x%x\n",uid.iUid); |
|
36 #endif |
|
37 |
|
38 iRepository.Close(); |
|
39 iFindResult.Close(); |
|
40 iInitialised = EFalse; |
|
41 } |
|
42 |
|
43 // if session ServiceL Leaves, execution resumes in this method. |
|
44 // this allows us to panic clients using bad descriptors, to deal with OOM conditions |
|
45 // and to fail transactions with the correct reason: OOM etc. |
|
46 void CServerSubSession::ServiceError(TInt aError) |
|
47 { |
|
48 // ensure any transaction is failed for the reason aError |
|
49 iRepository.FailTransaction(aError, KUnspecifiedKey); |
|
50 } |
|
51 |
|
52 TInt CServerSubSession::ServiceL(const RMessage2& aMessage) |
|
53 { |
|
54 const TClientRequest msg(aMessage); |
|
55 |
|
56 struct SAction |
|
57 { |
|
58 TServerRequest req; |
|
59 TInt (CServerSubSession::*groupFuncL)(const TClientRequest&, TServerFunc); |
|
60 TServerFunc funcL; |
|
61 }; |
|
62 |
|
63 static const SAction actionTable[] = |
|
64 { |
|
65 {EInitialise, &CServerSubSession::GeneralOperationsL, &CServerSubSession::InitialiseL}, |
|
66 {ECreateInt, &CServerSubSession::WriteOperationsL, &CServerSubSession::CreateIntL}, |
|
67 {ECreateReal, &CServerSubSession::WriteOperationsL, &CServerSubSession::CreateRealL}, |
|
68 {ECreateString, &CServerSubSession::WriteOperationsL, &CServerSubSession::CreateStringL}, |
|
69 {EDelete, &CServerSubSession::WriteOperationsL, &CServerSubSession::DeleteL}, |
|
70 {EGetInt, &CServerSubSession::ReadOperationsL, &CServerSubSession::GetIntL}, |
|
71 {ESetInt, &CServerSubSession::WriteOperationsL, &CServerSubSession::SetIntL}, |
|
72 {EGetReal, &CServerSubSession::ReadOperationsL, &CServerSubSession::GetRealL}, |
|
73 {ESetReal, &CServerSubSession::WriteOperationsL, &CServerSubSession::SetRealL}, |
|
74 {EGetString, &CServerSubSession::ReadOperationsL, &CServerSubSession::GetStringL}, |
|
75 {ESetString, &CServerSubSession::WriteOperationsL, &CServerSubSession::SetStringL}, |
|
76 {EFind, &CServerSubSession::ReadOperationsL, &CServerSubSession::FindL}, |
|
77 {EFindEqInt, &CServerSubSession::ReadOperationsL, &CServerSubSession::FindEqIntL}, |
|
78 {EFindEqReal, &CServerSubSession::ReadOperationsL, &CServerSubSession::FindEqRealL}, |
|
79 {EFindEqString, &CServerSubSession::ReadOperationsL, &CServerSubSession::FindEqStringL}, |
|
80 {EFindNeqInt, &CServerSubSession::ReadOperationsL, &CServerSubSession::FindNeqIntL}, |
|
81 {EFindNeqReal, &CServerSubSession::ReadOperationsL, &CServerSubSession::FindNeqRealL}, |
|
82 {EFindNeqString, &CServerSubSession::ReadOperationsL, &CServerSubSession::FindNeqStringL}, |
|
83 {EGetFindResult, &CServerSubSession::ReadOperationsL, &CServerSubSession::GetFindResultL}, |
|
84 {ENotifyRequestCheck, &CServerSubSession::GeneralOperationsL, &CServerSubSession::NotifyRequestCheck}, |
|
85 {ENotifyRequest, &CServerSubSession::GeneralOperationsL, &CServerSubSession::NotifyRequest}, |
|
86 {ENotifyCancel, &CServerSubSession::GeneralOperationsL, &CServerSubSession::NotifyCancel}, |
|
87 {ENotifyCancelAll, &CServerSubSession::GeneralOperationsL, &CServerSubSession::NotifyCancelAll}, |
|
88 {EGroupNotifyRequest, &CServerSubSession::GeneralOperationsL, &CServerSubSession::GroupNotifyRequest}, |
|
89 {EGroupNotifyCancel, &CServerSubSession::GeneralOperationsL, &CServerSubSession::GroupNotifyCancel}, |
|
90 {EReset, &CServerSubSession::ResetOperationsL, &CServerSubSession::ResetL}, |
|
91 {EResetAll, &CServerSubSession::ResetOperationsL, &CServerSubSession::ResetAllL}, |
|
92 {ETransactionStart, &CServerSubSession::GeneralOperationsL, &CServerSubSession::TransactionStart}, |
|
93 {ETransactionCommit, &CServerSubSession::GeneralOperationsL, &CServerSubSession::TransactionCommitL}, |
|
94 {ETransactionCancel, &CServerSubSession::GeneralOperationsL, &CServerSubSession::TransactionCancel}, |
|
95 {EMove, &CServerSubSession::WriteOperationsL, &CServerSubSession::MoveL}, |
|
96 {ETransactionState, &CServerSubSession::GeneralOperationsL, &CServerSubSession::TransactionStateL}, |
|
97 {ETransactionFail, &CServerSubSession::GeneralOperationsL, &CServerSubSession::TransactionFail}, |
|
98 {EDeleteRange, &CServerSubSession::WriteOperationsL, &CServerSubSession::DeleteRangeL}, |
|
99 {EGetMeta, &CServerSubSession::ReadOperationsL, &CServerSubSession::GetMeta} |
|
100 }; |
|
101 |
|
102 #ifdef SRVSUBSESS_TRACE |
|
103 const TPtrC actionTableNames[] = |
|
104 { |
|
105 _L("EInitialize"), |
|
106 _L("ECreateInt"), |
|
107 _L("ECreateReal"), |
|
108 _L("ECreateString"), |
|
109 _L("EDelete"), |
|
110 _L("EGetInt"), |
|
111 _L("ESetInt"), |
|
112 _L("EGetReal"), |
|
113 _L("ESetReal"), |
|
114 _L("EGetString"), |
|
115 _L("ESetString"), |
|
116 _L("EFind"), |
|
117 _L("EFindEqInt"), |
|
118 _L("EFindEqReal"), |
|
119 _L("EFindEqString"), |
|
120 _L("EFindNeqInt"), |
|
121 _L("EFindNeqReal"), |
|
122 _L("EFindNeqString"), |
|
123 _L("EGetFindResult"), |
|
124 _L("ENotifyRequestCheck"), |
|
125 _L("ENotifyRequest"), |
|
126 _L("ENotifyCancel"), |
|
127 _L("ENotifyCancelAll"), |
|
128 _L("EGroupNotifyRequest"), |
|
129 _L("EGroupNotifyCancel"), |
|
130 _L("EReset"), |
|
131 _L("EResetAll"), |
|
132 _L("ETransactionStart"), |
|
133 _L("ETransactionCommit"), |
|
134 _L("ETransactionCancel"), |
|
135 _L("EMove"), |
|
136 _L("ETransactionState"), |
|
137 _L("ETransactionFail"), |
|
138 _L("EDeleteRange"), |
|
139 _L("EGetMeta") |
|
140 }; |
|
141 #endif |
|
142 |
|
143 TInt r; |
|
144 TServerRequest fn = static_cast<TServerRequest>(aMessage.Function()); |
|
145 |
|
146 __ASSERT_ALWAYS(iInitialised || fn==EInitialise, PanicClient(ESessionNotInitialised, msg)); |
|
147 // In this assert we use (ELastInTable - 1) rather than ELastInTable because EClose is handled in the session |
|
148 // rather than the subsession, consiquently the actionTable array is one element shorter than ELastInTable |
|
149 __ASSERT_ALWAYS((fn < (ELastInTable)) && (fn >= EInitialise), PanicClient(EBadMessageNumber, msg)); |
|
150 |
|
151 if (EInitialise != fn) |
|
152 { |
|
153 iRepository.AccessRepositoryL(); |
|
154 } |
|
155 #ifdef SRVSUBSESS_TRACE |
|
156 |
|
157 if (EInitialise != fn) |
|
158 { |
|
159 TUid uid = RepositoryUid(); |
|
160 |
|
161 __SRVSUBSESS_TRACE2("CServerSubSession::ServiceL - UID: 0x%x %S\n",uid.iUid,&actionTableNames[fn]); |
|
162 } |
|
163 else |
|
164 { |
|
165 __SRVSUBSESS_TRACE1("CServerSubSession::ServiceL - UID: 0x?? %S\n",&actionTableNames[fn]); |
|
166 } |
|
167 |
|
168 #endif |
|
169 // plus need to check we are initialised |
|
170 // this comment removes a false positive from the coverity output. if fn >= ELastInTable then this code |
|
171 // will assert (see above). but coverity doesn't consider this and therefore complains that there is a |
|
172 // posibility that actionTable could be indexed beyond it's length |
|
173 //coverity[overrun-local] |
|
174 r = (this->*actionTable[fn].groupFuncL)(aMessage, actionTable[fn].funcL); |
|
175 |
|
176 return r; |
|
177 } |
|
178 |
|
179 //method allows transactions and notify requests to get through during backup/restore |
|
180 //process to prevent them from being blocked. |
|
181 //Transactions being blocked would lead clients to be panicked |
|
182 //if they were trying to open a second transaction in the same session. |
|
183 // Notify cancels must be allowed through because they must always succeed. |
|
184 TInt CServerSubSession::GeneralOperationsL(const TClientRequest& aMessage, TServerFunc aFuncL) |
|
185 { |
|
186 ASSERT(aFuncL != NULL); |
|
187 return (this->*aFuncL)(aMessage); |
|
188 } |
|
189 |
|
190 // method allows read operations to share transaction-related tasks. |
|
191 // Read operations are allowed only during backup process. |
|
192 // During restore it fails transactions with KErrLocked and returns KErrAbort |
|
193 // and if it is a standalone read oparation it rejects it with KErrServerBusy. |
|
194 TInt CServerSubSession::ReadOperationsL(const TClientRequest& aMessage, TServerFunc aFuncL) |
|
195 { |
|
196 TInt backupStatus = CRepositoryBackupClient::GetBackupStatus(); |
|
197 |
|
198 if (iRepository.IsInFailedTransaction()) |
|
199 { |
|
200 return KErrAbort; |
|
201 } |
|
202 else if (iRepository.IsInTransaction() && (backupStatus == ERestoreInProgress) ) |
|
203 { |
|
204 iRepository.FailTransaction(KErrLocked,KUnspecifiedKey); |
|
205 return KErrAbort; |
|
206 } |
|
207 else if (backupStatus == ERestoreInProgress) |
|
208 { |
|
209 return KErrServerBusy; |
|
210 } |
|
211 |
|
212 ASSERT(aFuncL != NULL); |
|
213 return (this->*aFuncL)(aMessage); |
|
214 } |
|
215 |
|
216 // method allows write operations to share transaction-related tasks |
|
217 // All write operations are not allowed either during backup or restore process. |
|
218 // If backup or restore is in progress it fails transaction with KErrLocked, |
|
219 // returns KErrAbort or if it is a standalone operation it returns KErrServerBusy. |
|
220 TInt CServerSubSession::WriteOperationsL(const TClientRequest& aMessage, TServerFunc aFuncL) |
|
221 { |
|
222 TInt backupStatus = CRepositoryBackupClient::GetBackupStatus(); |
|
223 |
|
224 if (iRepository.IsInFailedTransaction()) |
|
225 { |
|
226 return KErrAbort; |
|
227 } |
|
228 else if (iRepository.IsInTransaction() && (backupStatus != ENoBackupActivty) ) |
|
229 { |
|
230 iRepository.FailTransaction(KErrLocked,KUnspecifiedKey); |
|
231 return KErrAbort; |
|
232 } |
|
233 else if (backupStatus != ENoBackupActivty) |
|
234 { |
|
235 return KErrServerBusy; |
|
236 } |
|
237 |
|
238 // if not already in a transaction, create a temporary concurrent read/write transaction |
|
239 const TBool tempTransaction = !iRepository.IsInTransaction(); |
|
240 if (tempTransaction) |
|
241 { |
|
242 // concurrent read/write transaction is guaranteed to start |
|
243 iRepository.StartTransaction(EConcurrentReadWriteTransaction); |
|
244 // to protect against Leaves: |
|
245 iRepository.CleanupCancelTransactionPushL(); |
|
246 } |
|
247 else |
|
248 { |
|
249 if (iRepository.IsInActiveReadTransaction()) |
|
250 { |
|
251 // must be a read/write transaction to continue |
|
252 iRepository.AttemptPromoteTransactionToReadWrite(); |
|
253 // Note we don't check the return value of the above and return it here. |
|
254 // Instead we call the next level write function and expect it to have the |
|
255 // following code: |
|
256 // if (iRepository.IsInActiveReadTransaction()) |
|
257 // { |
|
258 // return iRepository.FailTransaction(KErrLocked, key); |
|
259 // } |
|
260 // this ensures CommitTransaction reports the failing key. |
|
261 } |
|
262 // Note ServiceError will fail the transaction if write operation leaves |
|
263 } |
|
264 |
|
265 // call the server function |
|
266 ASSERT(aFuncL != NULL); |
|
267 TInt result = (this->*aFuncL)(aMessage); |
|
268 |
|
269 // commit the temporary transaction |
|
270 if (tempTransaction) |
|
271 { |
|
272 CleanupStack::Pop(); // remove cleanup item from earlier |
|
273 // absorb result and keyInfo from commit of temporary transaction |
|
274 TUint32 tempKeyInfo; |
|
275 User::LeaveIfError(iRepository.CommitTransaction(tempKeyInfo)); |
|
276 } |
|
277 return result; |
|
278 } |
|
279 |
|
280 TInt CServerSubSession::ResetOperationsL(const TClientRequest& aMessage, TServerFunc aFuncL) |
|
281 { |
|
282 // reset operations are not currently supported in transactions |
|
283 if (iRepository.IsInTransaction()) |
|
284 { |
|
285 // fail transaction otherwise client may be misled to believe operation worked |
|
286 return iRepository.FailTransaction(KErrNotSupported, KUnspecifiedKey); |
|
287 } |
|
288 //can't reset when backup or restore is in progress |
|
289 else if (CRepositoryBackupClient::GetBackupStatus() != ENoBackupActivty) |
|
290 { |
|
291 return KErrServerBusy; |
|
292 } |
|
293 ASSERT(aFuncL != NULL); |
|
294 return (this->*aFuncL)(aMessage); |
|
295 } |
|
296 |
|
297 TInt CServerSubSession::InitialiseL(const TClientRequest& aMessage) |
|
298 { |
|
299 __ASSERT_ALWAYS(!iInitialised, |
|
300 PanicClient(ESessionAlreadyInitialised, aMessage)); |
|
301 // We let anyone to open a repository... |
|
302 // it's not considered a breach of security to let people know |
|
303 // that a repository is there... |
|
304 TUid uid = TUid::Uid(aMessage.Int0()); |
|
305 |
|
306 __SRVSUBSESS_TRACE1("CServerSubSession::InitialiseL UID: 0x%x\n",uid.iUid); |
|
307 |
|
308 // Calls iObserver->AccessL internally |
|
309 iRepository.OpenL(uid, iNotifier); |
|
310 |
|
311 iInitialised = ETrue; |
|
312 |
|
313 return KErrNone; |
|
314 } |
|
315 |
|
316 TInt CServerSubSession::CreateIntL(const TClientRequest& aMessage) |
|
317 { |
|
318 TUint32 key = aMessage.Int0(); |
|
319 |
|
320 // cannot make changes in a read transaction - upgrade must have failed due to write lock being used |
|
321 if (iRepository.IsInActiveReadTransaction()) |
|
322 { |
|
323 return iRepository.FailTransaction(KErrLocked, key); |
|
324 } |
|
325 |
|
326 if(KErrNone != CheckPolicy(aMessage,iRepository.GetWriteAccessPolicy(key), |
|
327 __PLATSEC_DIAGNOSTIC_STRING("CenRep: CServerSubSession::CreateIntL - Attempt made to create a setting"))) |
|
328 return iRepository.FailTransaction(KErrPermissionDenied, key); |
|
329 |
|
330 TInt val = aMessage.Int1(); |
|
331 |
|
332 #ifdef SRVSUBSESS_TRACE |
|
333 TUid uid = RepositoryUid(); |
|
334 |
|
335 __SRVSUBSESS_TRACE2("CServerSubSession::CreateIntL UID: 0x%x Key=0x%x\n",uid.iUid,key); |
|
336 #endif |
|
337 |
|
338 TInt r = iRepository.TransactionCreateL(key, val, NULL); |
|
339 |
|
340 return r; |
|
341 } |
|
342 |
|
343 TInt CServerSubSession::CreateRealL(const TClientRequest& aMessage) |
|
344 { |
|
345 TUint32 key = aMessage.Int0(); |
|
346 |
|
347 // cannot make changes in a read transaction - upgrade must have failed due to write lock being used |
|
348 if (iRepository.IsInActiveReadTransaction()) |
|
349 { |
|
350 return iRepository.FailTransaction(KErrLocked, key); |
|
351 } |
|
352 |
|
353 if(KErrNone != CheckPolicy(aMessage,iRepository.GetWriteAccessPolicy(key), |
|
354 __PLATSEC_DIAGNOSTIC_STRING("CenRep: CServerSession::CreateRealL - Attempt made to create a setting"))) |
|
355 return iRepository.FailTransaction(KErrPermissionDenied, key); |
|
356 |
|
357 TReal val; |
|
358 TPckg<TReal> p(val); |
|
359 aMessage.ReadL(1, p); |
|
360 |
|
361 #ifdef SRVSUBSESS_TRACE |
|
362 TUid uid = RepositoryUid(); |
|
363 |
|
364 __SRVSUBSESS_TRACE2("CServerSubSession::CreateRealL UID: 0x%x Key=0x%x\n",uid.iUid,key); |
|
365 #endif |
|
366 TInt r = iRepository.TransactionCreateL(key, val, NULL); |
|
367 |
|
368 return r; |
|
369 } |
|
370 |
|
371 TInt CServerSubSession::CreateStringL(const TClientRequest& aMessage) |
|
372 { |
|
373 TUint32 key = aMessage.Int0(); |
|
374 |
|
375 // cannot make changes in a read transaction - upgrade must have failed due to write lock being used |
|
376 if (iRepository.IsInActiveReadTransaction()) |
|
377 { |
|
378 return iRepository.FailTransaction(KErrLocked, key); |
|
379 } |
|
380 |
|
381 // sometime: must ensure bad descriptor results in client being panic'd |
|
382 |
|
383 // check for descriptor-too-long was previously on the client side, |
|
384 // hence test code expects KErrArgument response before KErrPermissionDenied |
|
385 TInt length = aMessage.GetDesLengthL(1); |
|
386 if (length > KMaxBinaryLength) |
|
387 { |
|
388 return iRepository.FailTransaction(KErrArgument, key); |
|
389 } |
|
390 |
|
391 if(KErrNone != CheckPolicy(aMessage,iRepository.GetWriteAccessPolicy(key), |
|
392 __PLATSEC_DIAGNOSTIC_STRING("CenRep: CServerSession::CreateStringL - Attempt made to create a setting"))) |
|
393 return iRepository.FailTransaction(KErrPermissionDenied, key); |
|
394 |
|
395 TBuf8<KMaxBinaryLength> val; |
|
396 aMessage.ReadL(1, val); |
|
397 |
|
398 #ifdef SRVSUBSESS_TRACE |
|
399 TUid uid = RepositoryUid(); |
|
400 |
|
401 __SRVSUBSESS_TRACE2("CServerSubSession::CreateStringL UID: 0x%x Key=0x%x\n",uid.iUid,key); |
|
402 #endif |
|
403 |
|
404 TInt error = iRepository.TransactionCreateL(key, val, NULL); |
|
405 |
|
406 return error; |
|
407 } |
|
408 |
|
409 TInt CServerSubSession::DeleteL(const TClientRequest& aMessage) |
|
410 { |
|
411 TUint32 key = aMessage.Int0(); |
|
412 |
|
413 // cannot make changes in a read transaction - upgrade must have failed due to write lock being used |
|
414 if (iRepository.IsInActiveReadTransaction()) |
|
415 { |
|
416 return iRepository.FailTransaction(KErrLocked, key); |
|
417 } |
|
418 |
|
419 if(KErrNone != CheckPolicy(aMessage,iRepository.GetWriteAccessPolicy(key), |
|
420 __PLATSEC_DIAGNOSTIC_STRING("CenRep: CServerSession::DeleteL - Attempt made to delete a setting"))) |
|
421 return iRepository.FailTransaction(KErrPermissionDenied, key); |
|
422 |
|
423 #ifdef SRVSUBSESS_TRACE |
|
424 TUid uid = RepositoryUid(); |
|
425 |
|
426 __SRVSUBSESS_TRACE2("CServerSubSession::DeleteL UID: 0x%x Key=0x%x\n",uid.iUid,key); |
|
427 #endif |
|
428 |
|
429 TInt r = iRepository.TransactionDeleteL(key); |
|
430 |
|
431 return r; |
|
432 } |
|
433 |
|
434 TInt CServerSubSession::GetIntL(const TClientRequest& aMessage) |
|
435 { |
|
436 TUint32 key = aMessage.Int0(); |
|
437 |
|
438 if(KErrNone != CheckPolicy(aMessage,iRepository.GetReadAccessPolicy(key), |
|
439 __PLATSEC_DIAGNOSTIC_STRING("CenRep: CServerSession::GetIntL - Attempt made to read a setting"))) |
|
440 return KErrPermissionDenied; |
|
441 |
|
442 TInt val; |
|
443 TInt error = iRepository.Get(key, val); |
|
444 |
|
445 if (error == KErrNone) |
|
446 { |
|
447 TPckg<TInt> p(val); |
|
448 aMessage.WriteL(1, p); |
|
449 } |
|
450 |
|
451 #ifdef SRVSUBSESS_TRACE |
|
452 TUid uid = RepositoryUid(); |
|
453 |
|
454 if (error == KErrNone) |
|
455 { |
|
456 __SRVSUBSESS_TRACE3("CServerSubSession::GetIntL UID: 0x%x Key=0x%x Value=%d\n",uid.iUid,key,val); |
|
457 } |
|
458 else |
|
459 { |
|
460 __SRVSUBSESS_TRACE2("CServerSubSession::GetIntL **Failure** UID: 0x%x Key=0x%x\n",uid.iUid,key); |
|
461 } |
|
462 #endif |
|
463 |
|
464 return error; |
|
465 } |
|
466 |
|
467 TInt CServerSubSession::SetIntL(const TClientRequest& aMessage) |
|
468 { |
|
469 TUint32 key = aMessage.Int0(); |
|
470 |
|
471 // cannot make changes in a read transaction - upgrade must have failed due to write lock being used |
|
472 if (iRepository.IsInActiveReadTransaction()) |
|
473 { |
|
474 return iRepository.FailTransaction(KErrLocked, key); |
|
475 } |
|
476 |
|
477 if(KErrNone != CheckPolicy(aMessage,iRepository.GetWriteAccessPolicy(key), |
|
478 __PLATSEC_DIAGNOSTIC_STRING("CenRep: CServerSession::SetIntL - Attempt made to write a setting"))) |
|
479 return iRepository.FailTransaction(KErrPermissionDenied, key); |
|
480 |
|
481 TInt val = aMessage.Int1(); |
|
482 TInt error = iRepository.TransactionSetL(key, val); |
|
483 |
|
484 #ifdef SRVSUBSESS_TRACE |
|
485 TUid uid = RepositoryUid(); |
|
486 |
|
487 if (error == KErrNone) |
|
488 { |
|
489 __SRVSUBSESS_TRACE3("CServerSubSession::SetIntL UID: 0x%x Key=0x%x Value=%d\n",uid.iUid,key,val); |
|
490 } |
|
491 else |
|
492 { |
|
493 __SRVSUBSESS_TRACE3("CServerSubSession::SetIntL **Failure** UID: 0x%x Key=0x%x Value=%d\n",uid.iUid,key,val); |
|
494 } |
|
495 #endif |
|
496 return error; |
|
497 } |
|
498 |
|
499 TInt CServerSubSession::GetRealL(const TClientRequest& aMessage) |
|
500 { |
|
501 TUint32 key = aMessage.Int0(); |
|
502 |
|
503 if(KErrNone != CheckPolicy(aMessage,iRepository.GetReadAccessPolicy(key), |
|
504 __PLATSEC_DIAGNOSTIC_STRING("CenRep: CServerSession::GetRealL - Attempt made to read a setting"))) |
|
505 return KErrPermissionDenied; |
|
506 |
|
507 TReal val; |
|
508 TInt error = iRepository.Get(key, val); |
|
509 |
|
510 if(error==KErrNone) |
|
511 { |
|
512 TPckg<TReal> p(val); |
|
513 aMessage.WriteL(1, p); |
|
514 } |
|
515 |
|
516 #ifdef SRVSUBSESS_TRACE |
|
517 TUid uid = RepositoryUid(); |
|
518 |
|
519 if (error == KErrNone) |
|
520 { |
|
521 __SRVSUBSESS_TRACE3("CServerSubSession::GetRealL UID: 0x%x Key=0x%x Value=%d\n",uid.iUid,key,val); |
|
522 } |
|
523 else |
|
524 { |
|
525 __SRVSUBSESS_TRACE2("CServerSubSession::GetRealL **Failure** UID: 0x%x Key=0x%x\n",uid.iUid,key); |
|
526 } |
|
527 #endif |
|
528 return error; |
|
529 } |
|
530 |
|
531 TInt CServerSubSession::SetRealL(const TClientRequest& aMessage) |
|
532 { |
|
533 TUint32 key = aMessage.Int0(); |
|
534 |
|
535 // cannot make changes in a read transaction - upgrade must have failed due to write lock being used |
|
536 if (iRepository.IsInActiveReadTransaction()) |
|
537 { |
|
538 return iRepository.FailTransaction(KErrLocked, key); |
|
539 } |
|
540 |
|
541 if(KErrNone != CheckPolicy(aMessage,iRepository.GetWriteAccessPolicy(key), |
|
542 __PLATSEC_DIAGNOSTIC_STRING("CenRep: CServerSession::SetRealL - Attempt made to write a setting"))) |
|
543 return iRepository.FailTransaction(KErrPermissionDenied, key); |
|
544 |
|
545 TReal val; |
|
546 TPckg<TReal> p(val); |
|
547 aMessage.ReadL(1, p); |
|
548 |
|
549 TInt error = iRepository.TransactionSetL(key, val); |
|
550 |
|
551 #ifdef SRVSUBSESS_TRACE |
|
552 TUid uid = RepositoryUid(); |
|
553 |
|
554 if (error == KErrNone) |
|
555 { |
|
556 __SRVSUBSESS_TRACE3("CServerSubSession::SetRealL UID: 0x%x Key=0x%x Value=%d\n",uid.iUid,key,val); |
|
557 } |
|
558 else |
|
559 { |
|
560 __SRVSUBSESS_TRACE3("CServerSubSession::SetRealL **Failure** UID: 0x%x Key=0x%x Value=%d\n",uid.iUid,key,val); |
|
561 } |
|
562 #endif |
|
563 |
|
564 return error; |
|
565 } |
|
566 |
|
567 TInt CServerSubSession::GetStringL(const TClientRequest& aMessage) |
|
568 { |
|
569 TUint32 key = aMessage.Int0(); |
|
570 |
|
571 if(KErrNone != CheckPolicy(aMessage,iRepository.GetReadAccessPolicy(key), |
|
572 __PLATSEC_DIAGNOSTIC_STRING("CenRep: CServerSession::GetStringL - Attempt made to read a setting"))) |
|
573 return KErrPermissionDenied; |
|
574 |
|
575 TBuf8<KMaxBinaryLength> val; |
|
576 |
|
577 TInt error = iRepository.Get(key, val); |
|
578 |
|
579 if(error==KErrNone) |
|
580 { |
|
581 TInt clientMaxDescriptorLength; |
|
582 TPckg<TInt> pInt (clientMaxDescriptorLength); |
|
583 aMessage.Read(2, pInt); |
|
584 |
|
585 TInt descriptorLength = val.Length(); |
|
586 |
|
587 // write the descriptor length to aMessage |
|
588 TPckg<TInt> p(descriptorLength); |
|
589 error = aMessage.Write(2, p); |
|
590 |
|
591 if(error==KErrNone) |
|
592 { |
|
593 if(descriptorLength > clientMaxDescriptorLength) |
|
594 { |
|
595 // if it is, fill the descriptor up to its max length |
|
596 error = aMessage.Write(1, val.Left(clientMaxDescriptorLength)); |
|
597 |
|
598 // if client-side descriptor is too small to take the value, which it is, returns KErrOverflow |
|
599 if(error == KErrNone) |
|
600 { |
|
601 error = KErrOverflow; |
|
602 } |
|
603 } |
|
604 else |
|
605 { |
|
606 error = aMessage.Write(1, val); |
|
607 } |
|
608 |
|
609 #ifdef SRVSUBSESS_TRACE |
|
610 TUid uid = RepositoryUid(); |
|
611 |
|
612 if (error == KErrNone) |
|
613 { |
|
614 __SRVSUBSESS_TRACE3("CServerSubSession::GetStringL UID: 0x%x Key=0x%x Value=%S\n",uid.iUid,key,&val); |
|
615 } |
|
616 else |
|
617 { |
|
618 __SRVSUBSESS_TRACE2("CServerSubSession::GetStringL **Failure** UID: 0x%x Key=0x%x\n",uid.iUid,key); |
|
619 } |
|
620 #endif |
|
621 } |
|
622 |
|
623 // if error is KErrOverflow should not failing transaction |
|
624 if ((error != KErrNone) && (error != KErrOverflow)) |
|
625 { |
|
626 // ServiceError will fail transaction |
|
627 User::Leave(error); |
|
628 } |
|
629 } |
|
630 return error; |
|
631 } |
|
632 |
|
633 TInt CServerSubSession::SetStringL(const TClientRequest& aMessage) |
|
634 { |
|
635 TUint32 key = aMessage.Int0(); |
|
636 |
|
637 // cannot make changes in a read transaction - upgrade must have failed due to write lock being used |
|
638 if (iRepository.IsInActiveReadTransaction()) |
|
639 { |
|
640 return iRepository.FailTransaction(KErrLocked, key); |
|
641 } |
|
642 |
|
643 // check for descriptor-too-long was previously on the client side, |
|
644 // hence test code expects KErrArgument response before KErrPermissionDenied |
|
645 TInt length = aMessage.GetDesLengthL(1); |
|
646 if (length > KMaxBinaryLength) |
|
647 { |
|
648 return iRepository.FailTransaction(KErrArgument, key); |
|
649 } |
|
650 |
|
651 if(KErrNone != CheckPolicy(aMessage,iRepository.GetWriteAccessPolicy(key), |
|
652 __PLATSEC_DIAGNOSTIC_STRING("CenRep: CServerSession::SetStringL - Attempt made to write a setting"))) |
|
653 return iRepository.FailTransaction(KErrPermissionDenied, key); |
|
654 |
|
655 TBuf8<KMaxBinaryLength> val; |
|
656 aMessage.ReadL(1, val); // no error if too long, truncated instead |
|
657 |
|
658 TInt error = iRepository.TransactionSetL(key, val); |
|
659 |
|
660 #ifdef SRVSUBSESS_TRACE |
|
661 TUid uid = RepositoryUid(); |
|
662 |
|
663 if (error == KErrNone) |
|
664 { |
|
665 __SRVSUBSESS_TRACE3("CServerSubSession::SetStringL UID: 0x%x Key=0x%x Value=%S\n",uid.iUid,key,&val); |
|
666 } |
|
667 else |
|
668 { |
|
669 __SRVSUBSESS_TRACE2("CServerSubSession::SetStringL **Failure** UID: 0x%x Key=0x%x\n",uid.iUid,key); |
|
670 } |
|
671 #endif |
|
672 |
|
673 return error; |
|
674 } |
|
675 |
|
676 TInt CServerSubSession::GetMeta(const TClientRequest& aMessage) |
|
677 { |
|
678 TUint32 key = aMessage.Int0(); |
|
679 |
|
680 if(KErrNone != CheckPolicy(aMessage,iRepository.GetReadAccessPolicy(key), |
|
681 __PLATSEC_DIAGNOSTIC_STRING("CenRep: CServerSession::GetMeta - Attempt made to read a setting"))) |
|
682 return KErrPermissionDenied; |
|
683 |
|
684 TUint32 meta; |
|
685 TInt error = iRepository.GetMeta(key, meta); |
|
686 |
|
687 if (error == KErrNone) |
|
688 { |
|
689 TPckg<TUint32> p(meta); |
|
690 error = aMessage.Write(1, p); |
|
691 } |
|
692 |
|
693 #ifdef SRVSUBSESS_TRACE |
|
694 TUid uid = RepositoryUid(); |
|
695 |
|
696 if (error == KErrNone) |
|
697 { |
|
698 __SRVSUBSESS_TRACE3("CServerSubSession::GetMeta UID: 0x%x Key=0x%x Meta=0x%x\n",uid.iUid,key,meta); |
|
699 } |
|
700 else |
|
701 { |
|
702 __SRVSUBSESS_TRACE2("CServerSubSession::GetMeta **Failure** UID: 0x%x Key=0x%x\n",uid.iUid,key); |
|
703 } |
|
704 #endif |
|
705 |
|
706 return error; |
|
707 } |
|
708 |
|
709 TInt CServerSubSession::FindL(const TClientRequest& aMessage) |
|
710 { |
|
711 // PLATSEC NOTE: |
|
712 // There are no read policy checks on FindL. |
|
713 // Client is returned the full list of keys whether they have read permission or not. |
|
714 // They were able to find this out by brute force using FindL on single setting ranges |
|
715 // anyway (because it would return KErrPermissionDenied if it existed, KErrNotFound otherwise). |
|
716 // Revealing the existence of settings is not considered a breach of security. |
|
717 TKeyFilter keyIdentifier; |
|
718 TPckg<TKeyFilter> p(keyIdentifier); |
|
719 aMessage.Read(0, p); |
|
720 // we reset results first since we do not police GetResult |
|
721 // and this way we can guarantee no results are available if access not granted |
|
722 iFindResult.Reset(); |
|
723 |
|
724 RArray<TUint32> settingsToSend; |
|
725 CleanupClosePushL(settingsToSend); |
|
726 |
|
727 TInt error=KErrNone; |
|
728 TRAP(error,iRepository.FindL(keyIdentifier.iPartialId, keyIdentifier.iIdMask,settingsToSend,KCentRepFindBufSize,iFindResult)); |
|
729 if (error==KErrNone) |
|
730 { |
|
731 //write back the total number of settingsFound; |
|
732 TInt numSettings=settingsToSend.Count()+iFindResult.Count(); |
|
733 TPtrC8 count(reinterpret_cast<TUint8*>(&numSettings),sizeof(TUint32)); |
|
734 error=aMessage.Write(2,count); |
|
735 if (error==KErrNone) |
|
736 { |
|
737 TPtrC8 p(reinterpret_cast<TUint8*>(&(settingsToSend[0])), (settingsToSend.Count())*sizeof(TUint32)); |
|
738 error=aMessage.Write(2,p,4); |
|
739 } |
|
740 |
|
741 #ifdef SRVSUBSESS_TRACE |
|
742 TUid uid = RepositoryUid(); |
|
743 if (error == KErrNone) |
|
744 { |
|
745 __SRVSUBSESS_TRACE4("CServerSubSession::FindL UID: 0x%x Key=0x%x Mask=0x%x Value=%S\n",uid.iUid,keyIdentifier.iPartialId, |
|
746 keyIdentifier.iIdMask,&p); |
|
747 } |
|
748 else |
|
749 { |
|
750 __SRVSUBSESS_TRACE4("CServerSubSession::FindL (failed write) UID: 0x%x Key=0x%x Mask=0x%x Value=%S\n",uid.iUid,keyIdentifier.iPartialId, |
|
751 keyIdentifier.iIdMask,&p); |
|
752 } |
|
753 #endif |
|
754 } |
|
755 CleanupStack::PopAndDestroy(); //settingsToSend |
|
756 |
|
757 if (error != KErrNone) |
|
758 { |
|
759 iFindResult.Reset(); |
|
760 if ((error != KErrNone) && (error != KErrNotFound)) |
|
761 { |
|
762 // ServiceError will fail transaction |
|
763 User::Leave(error); |
|
764 } |
|
765 } |
|
766 return error; |
|
767 } |
|
768 |
|
769 TInt CServerSubSession::FindEqIntL(const TClientRequest& aMessage) |
|
770 { |
|
771 TInt val = aMessage.Int1(); |
|
772 // PlatSec check done in FindValueL |
|
773 return FindValueL(aMessage, val); |
|
774 } |
|
775 |
|
776 TInt CServerSubSession::FindEqRealL(const TClientRequest& aMessage) |
|
777 { |
|
778 TReal val; |
|
779 TPckg<TReal> p(val); |
|
780 aMessage.Read(1, p); |
|
781 // PlatSec check done in FindValueL |
|
782 return FindValueL(aMessage, val); |
|
783 } |
|
784 |
|
785 TInt CServerSubSession::FindEqStringL(const TClientRequest& aMessage) |
|
786 { |
|
787 TBuf8<KMaxBinaryLength> val; |
|
788 aMessage.ReadL(1, val); // no error if too long, truncated instead |
|
789 // PlatSec check done in FindValueL |
|
790 return FindValueL(aMessage, val); |
|
791 } |
|
792 |
|
793 TInt CServerSubSession::FindNeqIntL(const TClientRequest& aMessage) |
|
794 { |
|
795 TInt val = aMessage.Int1(); |
|
796 // PlatSec check done in FindValueL |
|
797 return FindValueL(aMessage, val, ENotEqual); |
|
798 } |
|
799 |
|
800 TInt CServerSubSession::FindNeqRealL(const TClientRequest& aMessage) |
|
801 { |
|
802 TReal val; |
|
803 TPckg<TReal> p(val); |
|
804 aMessage.Read(1, p); |
|
805 // PlatSec check done in FindValueL |
|
806 return FindValueL(aMessage, val, ENotEqual); |
|
807 } |
|
808 |
|
809 TInt CServerSubSession::FindNeqStringL(const TClientRequest& aMessage) |
|
810 { |
|
811 TBuf8<KMaxBinaryLength> val; |
|
812 aMessage.ReadL(1, val); // no error if too long, truncated instead |
|
813 // PlatSec check done in FindValueL |
|
814 return FindValueL(aMessage, val, ENotEqual); |
|
815 } |
|
816 |
|
817 template <class T> |
|
818 TInt CServerSubSession::FindValueL(const TClientRequest& aMessage, const T& aVal,TComparison aComparison) |
|
819 { |
|
820 // IMPORTANT PLATSEC NOTE: |
|
821 // MUST return KErrPermissionDenied if read policy of ANY setting in the search range not passed. |
|
822 // MUST NOT merely check read policy of matching entries, otherwise it is possible to determine |
|
823 // secret values by brute force: Using single-value ranges, cycling through the possible values and |
|
824 // confirming a match when it returns KErrPermissionDenied rather than KErrNotFound. |
|
825 TKeyFilter keyIdentifier; |
|
826 TPckg<TKeyFilter> p(keyIdentifier); |
|
827 aMessage.Read(0, p); |
|
828 // we reset results first since we do not police GetResult |
|
829 // and this way we can guarantee no results are available if access not granted |
|
830 iFindResult.Reset(); |
|
831 RSettingPointerArray settings; |
|
832 CleanupClosePushL(settings); |
|
833 TInt error = iRepository.FindSettings(keyIdentifier.iPartialId, keyIdentifier.iIdMask, settings); |
|
834 if (error == KErrNone) |
|
835 { |
|
836 //perform the read checking policies first |
|
837 TUint32 dummyErrId; |
|
838 error=iRepository.CheckPermissions(settings,aMessage, |
|
839 __PLATSEC_DIAGNOSTIC_STRING("CenRep: CServerSession::FindValueL - Attempt made to search settings"),ETrue,dummyErrId); |
|
840 if (error==KErrPermissionDenied) |
|
841 iFindResult.Reset(); |
|
842 |
|
843 //now if everything passes, do perform the FindValue |
|
844 if (error==KErrNone) |
|
845 { |
|
846 TRAP(error,iRepository.FindCompareL(settings,aVal,aComparison,iFindResult)); |
|
847 if (error==KErrNone) |
|
848 { |
|
849 const TInt numSettings = iFindResult.Count(); |
|
850 const TInt numInitial = numSettings > KCentRepFindBufSize ? KCentRepFindBufSize : numSettings; |
|
851 RArray<TUint32> settingsToSend; |
|
852 CleanupClosePushL(settingsToSend); |
|
853 |
|
854 //reserve memory for everything that needs to be added to the array |
|
855 settingsToSend.Reserve(numInitial); |
|
856 |
|
857 //first append the number of found settings |
|
858 settingsToSend.AppendL(numSettings); |
|
859 |
|
860 //now append up to KCentRepFindBufSize settings |
|
861 for(TInt i = 0; i < numInitial; i++) |
|
862 { |
|
863 settingsToSend.AppendL(iFindResult[0]); |
|
864 iFindResult.Remove(0); |
|
865 } |
|
866 |
|
867 if(iFindResult.Count() == 0) |
|
868 { |
|
869 iFindResult.Reset(); |
|
870 } |
|
871 |
|
872 //send: |
|
873 //1 - the count of total settings found |
|
874 //2 - the settings that fit in the buffer allocated for the first IPC |
|
875 TPtrC8 p(reinterpret_cast<TUint8*>(&(settingsToSend[0])), (numInitial+1)*sizeof(TUint32)); |
|
876 error = aMessage.Write(2, p); |
|
877 |
|
878 #ifdef SRVSUBSESS_TRACE |
|
879 TUid uid = RepositoryUid(); |
|
880 |
|
881 __SRVSUBSESS_TRACE4("CServerSubSession::FindValueL UID: 0x%x Key=0x%x Mask=0x%x Value=%S\n",uid.iUid,keyIdentifier.iPartialId, |
|
882 keyIdentifier.iIdMask,&p); |
|
883 #endif |
|
884 CleanupStack::PopAndDestroy(); //settingsToSend |
|
885 } |
|
886 } |
|
887 } |
|
888 if ((error != KErrNone) && (error != KErrNotFound) && (error != KErrPermissionDenied)) |
|
889 { |
|
890 iFindResult.Reset(); |
|
891 CleanupStack::PopAndDestroy(); //settings |
|
892 |
|
893 // ServiceError will fail transaction |
|
894 User::Leave(error); |
|
895 } |
|
896 #ifdef SRVSUBSESS_TRACE |
|
897 else |
|
898 { |
|
899 TUid uid = RepositoryUid(); |
|
900 |
|
901 __SRVSUBSESS_TRACE3("CServerSubSession::FindValueL **Failure** UID: 0x%x Key=0x%x Mask=0x%x\n",uid.iUid,keyIdentifier.iPartialId, |
|
902 keyIdentifier.iIdMask); |
|
903 } |
|
904 #endif |
|
905 |
|
906 CleanupStack::PopAndDestroy(); //settings |
|
907 return error; |
|
908 } |
|
909 |
|
910 TInt CServerSubSession::GetFindResultL(const TClientRequest& aMessage) |
|
911 { |
|
912 TInt n = iFindResult.Count(); |
|
913 if (n==0) |
|
914 { |
|
915 return KErrNotFound; |
|
916 } |
|
917 |
|
918 TPtrC8 p(reinterpret_cast<TUint8*>(&(iFindResult[0])), n*sizeof(TUint32)); |
|
919 TInt error = aMessage.Write(0, p); |
|
920 // Free up iFindResult - it's no longer needed |
|
921 iFindResult.Reset(); |
|
922 // ServiceError will fail transaction |
|
923 |
|
924 #ifdef SRVSUBSESS_TRACE |
|
925 TUid uid = RepositoryUid(); |
|
926 |
|
927 if (error == KErrNone) |
|
928 { |
|
929 __SRVSUBSESS_TRACE2("CServerSubSession::GetFindResultL UID: 0x%x Value=%S\n",uid.iUid,&p); |
|
930 } |
|
931 else |
|
932 { |
|
933 __SRVSUBSESS_TRACE1("CServerSubSession::GetFindResultL **Failure** UID: 0x%x\n",uid.iUid); |
|
934 } |
|
935 #endif |
|
936 return User::LeaveIfError(error); |
|
937 } |
|
938 |
|
939 TInt CServerSubSession::NotifyRequestCheck(const TClientRequest& aMessage) |
|
940 { |
|
941 TUint32 key = aMessage.Int0(); |
|
942 if(KErrNone != CheckPolicy(aMessage,iRepository.GetReadAccessPolicy(key), |
|
943 __PLATSEC_DIAGNOSTIC_STRING("CenRep: CServerSession::NotifyRequestCheck - Attempt made to check Notify request"))) |
|
944 return KErrPermissionDenied; |
|
945 |
|
946 TInt error = iRepository.GetPersistentSetting(key) ? KErrNone : KErrNotFound; |
|
947 |
|
948 #ifdef SRVSUBSESS_TRACE |
|
949 TUid uid = RepositoryUid(); |
|
950 |
|
951 if (error == KErrNone) |
|
952 { |
|
953 __SRVSUBSESS_TRACE2("CServerSubSession::NotifyRequestCheck UID: 0x%x Key=0x%x\n",uid.iUid,key); |
|
954 } |
|
955 else |
|
956 { |
|
957 __SRVSUBSESS_TRACE1("CServerSubSession::NotifyRequestCheck **Failure** UID: 0x%x\n",uid.iUid); |
|
958 } |
|
959 #endif |
|
960 return error; |
|
961 } |
|
962 |
|
963 TInt CServerSubSession::NotifyRequest(const TClientRequest& aMessage) |
|
964 { |
|
965 TUint32 key = aMessage.Int0(); |
|
966 if(KErrNone != CheckPolicy(aMessage,iRepository.GetReadAccessPolicy(key), |
|
967 __PLATSEC_DIAGNOSTIC_STRING("CenRep: CServerSession::NotifyRequest - Attempt made to register for Notify"))) |
|
968 return KErrPermissionDenied; |
|
969 TInt error = iNotifier.AddRequest(key, aMessage); |
|
970 |
|
971 #ifdef SRVSUBSESS_TRACE |
|
972 TUid uid = RepositoryUid(); |
|
973 |
|
974 if (error == KErrNone) |
|
975 { |
|
976 __SRVSUBSESS_TRACE2("CServerSubSession::NotifyRequest UID: 0x%x Key=0x%x\n",uid.iUid,key); |
|
977 } |
|
978 else |
|
979 { |
|
980 __SRVSUBSESS_TRACE1("CServerSubSession::NotifyRequest **Failure** UID: 0x%x\n",uid.iUid); |
|
981 } |
|
982 #endif |
|
983 |
|
984 return (error == KErrNone) ? KDontCompleteMessage : error; |
|
985 } |
|
986 |
|
987 TInt CServerSubSession::NotifyCancel(const TClientRequest& aMessage) |
|
988 { |
|
989 TUint32 key = aMessage.Int0(); |
|
990 |
|
991 #ifdef SRVSUBSESS_TRACE |
|
992 TUid uid = RepositoryUid(); |
|
993 |
|
994 __SRVSUBSESS_TRACE2("CServerSubSession::NotifyCancel UID: 0x%x Key=0x%x\n",uid.iUid,key); |
|
995 #endif |
|
996 |
|
997 return iNotifier.CancelRequest(key); |
|
998 } |
|
999 |
|
1000 TInt CServerSubSession::NotifyCancelAll(const TClientRequest& /*aMessage*/) |
|
1001 { |
|
1002 #ifdef SRVSUBSESS_TRACE |
|
1003 TUid uid = RepositoryUid(); |
|
1004 |
|
1005 __SRVSUBSESS_TRACE1("CServerSubSession::NotifyCancelAll UID: 0x%x\n",uid.iUid); |
|
1006 #endif |
|
1007 return iNotifier.CancelAllRequests(); |
|
1008 } |
|
1009 |
|
1010 TInt CServerSubSession::GroupNotifyRequest(const TClientRequest& aMessage) |
|
1011 { |
|
1012 TUint32 partialId = aMessage.Int0(); |
|
1013 TUint32 idMask = aMessage.Int1(); |
|
1014 RSettingPointerArray settings; |
|
1015 TInt error = iRepository.FindPersistentSettings(partialId, idMask, settings); |
|
1016 if (error == KErrNone) |
|
1017 { |
|
1018 TUint32 dummyErrId; |
|
1019 error = iRepository.CheckPermissions(settings, aMessage, |
|
1020 __PLATSEC_DIAGNOSTIC_STRING("CenRep: CServerSession::GroupNotifyRequest - Attempt made to register for group Notify"),ETrue,dummyErrId); |
|
1021 } |
|
1022 settings.Reset(); |
|
1023 if (error != KErrNone) |
|
1024 { |
|
1025 #ifdef SRVSUBSESS_TRACE |
|
1026 TUid uid = RepositoryUid(); |
|
1027 |
|
1028 __SRVSUBSESS_TRACE3("CServerSubSession::GroupNotifyRequest **Failure** UID: 0x%x\n PartialId=0x%x Mask=0x%x\n", |
|
1029 uid.iUid,partialId,idMask); |
|
1030 #endif |
|
1031 |
|
1032 return KErrPermissionDenied; |
|
1033 } |
|
1034 |
|
1035 error = iNotifier.AddRequest(partialId, idMask, aMessage); |
|
1036 |
|
1037 #ifdef SRVSUBSESS_TRACE |
|
1038 TUid uid = RepositoryUid(); |
|
1039 |
|
1040 if (error == KErrNone) |
|
1041 { |
|
1042 __SRVSUBSESS_TRACE3("CServerSubSession::GroupNotifyRequest UID: 0x%x PartialId=0x%x Mask=0x%x\n", |
|
1043 uid.iUid,partialId,idMask); |
|
1044 } |
|
1045 else |
|
1046 { |
|
1047 __SRVSUBSESS_TRACE3("CServerSubSession::GroupNotifyRequest **Failure** UID: 0x%x PartialId=0x%x Mask=0x%x\n",uid.iUid, |
|
1048 partialId,idMask); |
|
1049 } |
|
1050 #endif |
|
1051 |
|
1052 return error==KErrNone ? KDontCompleteMessage : error; |
|
1053 } |
|
1054 |
|
1055 TInt CServerSubSession::GroupNotifyCancel(const TClientRequest& aMessage) |
|
1056 { |
|
1057 TKeyFilter keyIdentifier; |
|
1058 TPckg<TKeyFilter> p(keyIdentifier); |
|
1059 aMessage.Read(0, p); |
|
1060 |
|
1061 RSettingPointerArray settings; |
|
1062 TInt error = iRepository.FindPersistentSettings(keyIdentifier.iPartialId, keyIdentifier.iIdMask, settings); |
|
1063 settings.Reset(); |
|
1064 if (error != KErrNone) |
|
1065 { |
|
1066 #ifdef SRVSUBSESS_TRACE |
|
1067 TUid uid = RepositoryUid(); |
|
1068 |
|
1069 __SRVSUBSESS_TRACE3("CServerSubSession::GroupNotifyCancel **Failure** UID: 0x%x\n PartialId=0x%x Mask=0x%x\n", |
|
1070 uid.iUid,keyIdentifier.iPartialId, keyIdentifier.iIdMask); |
|
1071 #endif |
|
1072 return error; |
|
1073 } |
|
1074 |
|
1075 error = iNotifier.CancelRequest(keyIdentifier.iPartialId, keyIdentifier.iIdMask); |
|
1076 |
|
1077 #ifdef SRVSUBSESS_TRACE |
|
1078 TUid uid = RepositoryUid(); |
|
1079 |
|
1080 if (error == KErrNone) |
|
1081 { |
|
1082 __SRVSUBSESS_TRACE3("CServerSubSession::GroupNotifyCancel UID: 0x%x PartialId=0x%x Mask=0x%x\n", |
|
1083 uid.iUid,keyIdentifier.iPartialId, keyIdentifier.iIdMask); |
|
1084 } |
|
1085 else |
|
1086 { |
|
1087 __SRVSUBSESS_TRACE3("CServerSubSession::GroupNotifyCancel **Failure** UID: 0x%x PartialId=0x%x Mask=0x%x\n",uid.iUid, |
|
1088 keyIdentifier.iPartialId, keyIdentifier.iIdMask); |
|
1089 } |
|
1090 #endif |
|
1091 |
|
1092 |
|
1093 return error; |
|
1094 } |
|
1095 |
|
1096 TInt CServerSubSession::ResetL(const TClientRequest& aMessage) |
|
1097 { |
|
1098 // individual setting reset is not yet supported in transactions |
|
1099 ASSERT(!iRepository.IsInTransaction()); |
|
1100 TUint32 key = aMessage.Int0(); |
|
1101 if(KErrNone != CheckPolicy(aMessage,iRepository.GetWriteAccessPolicy(key), |
|
1102 __PLATSEC_DIAGNOSTIC_STRING("CenRep: CServerSession::ResetL - Attempt made to reset a setting"))) |
|
1103 return iRepository.FailTransaction(KErrPermissionDenied, key); |
|
1104 |
|
1105 TInt error = iRepository.ResetL(key); |
|
1106 |
|
1107 #ifdef SRVSUBSESS_TRACE |
|
1108 TUid uid = RepositoryUid(); |
|
1109 |
|
1110 if (error == KErrNone) |
|
1111 { |
|
1112 __SRVSUBSESS_TRACE2("CServerSubSession::ResetL UID: 0x%x Key=0x%x\n", |
|
1113 uid.iUid,key); |
|
1114 } |
|
1115 else |
|
1116 { |
|
1117 __SRVSUBSESS_TRACE2("CServerSubSession::ResetL **Failure** UID: 0x%x Key=0x%x\n",uid.iUid,key); |
|
1118 } |
|
1119 #endif |
|
1120 |
|
1121 return error; |
|
1122 } |
|
1123 |
|
1124 TInt CServerSubSession::ResetAllL(const TClientRequest& aMessage) |
|
1125 { |
|
1126 // factory reset operation is not yet supported in transactions |
|
1127 ASSERT(!iRepository.IsInTransaction()); |
|
1128 if(KErrNone != CheckPolicy(aMessage,iRepository.GetDefaultWriteAccessPolicy(), |
|
1129 __PLATSEC_DIAGNOSTIC_STRING("CenRep: CServerSession::ResetAllL - Attempt made to reset repository"))) |
|
1130 return KErrPermissionDenied; |
|
1131 |
|
1132 iNotifier.IdReportingOff(); |
|
1133 TInt error = iRepository.ResetAllL(); |
|
1134 iNotifier.IdReportingOn(); |
|
1135 |
|
1136 if (error == KErrNone) |
|
1137 { |
|
1138 iRepository.CommitChangesL(); // temporary measure |
|
1139 } |
|
1140 |
|
1141 #ifdef SRVSUBSESS_TRACE |
|
1142 TUid uid = RepositoryUid(); |
|
1143 |
|
1144 if (error == KErrNone) |
|
1145 { |
|
1146 __SRVSUBSESS_TRACE1("CServerSubSession::ResetAllL UID: 0x%x\n",uid.iUid); |
|
1147 } |
|
1148 else |
|
1149 { |
|
1150 __SRVSUBSESS_TRACE1("CServerSubSession::ResetAllL **Failure** UID: 0x%x\n",uid.iUid); |
|
1151 } |
|
1152 #endif |
|
1153 |
|
1154 return error; |
|
1155 } |
|
1156 |
|
1157 TInt CServerSubSession::MoveL(const TClientRequest& aMessage) |
|
1158 { |
|
1159 if (iRepository.IsInActiveReadTransaction()) |
|
1160 { |
|
1161 TKeyFilter keyIdentifier; |
|
1162 TPckg<TKeyFilter> p(keyIdentifier); |
|
1163 aMessage.Read(0, p); |
|
1164 |
|
1165 #ifdef SRVSUBSESS_TRACE |
|
1166 TUid uid = RepositoryUid(); |
|
1167 |
|
1168 __SRVSUBSESS_TRACE3("CServerSubSession::MoveL **Failure** In Transaction UID: 0x%x PartialId=0x%x Mask=0x%x\n", |
|
1169 uid.iUid,keyIdentifier.iPartialId,keyIdentifier.iIdMask); |
|
1170 #endif |
|
1171 |
|
1172 // could not promote to read/write: fail & give the source partialKey as the error key |
|
1173 return iRepository.FailTransaction(KErrLocked, keyIdentifier.iPartialId); |
|
1174 } |
|
1175 |
|
1176 TUint32 errorKey = KUnspecifiedKey; |
|
1177 TInt result = iRepository.TransactionMoveL(aMessage, errorKey); |
|
1178 |
|
1179 #ifdef SRVSUBSESS_TRACE |
|
1180 TUid uid = RepositoryUid(); |
|
1181 |
|
1182 if (result == KErrNone) |
|
1183 { |
|
1184 __SRVSUBSESS_TRACE1("CServerSubSession::MoveL UID: 0x%x\n",uid.iUid); |
|
1185 } |
|
1186 else |
|
1187 { |
|
1188 __SRVSUBSESS_TRACE2("CServerSubSession::MoveL **Failure** UID: 0x%x Error=%d\n",uid.iUid,errorKey); |
|
1189 } |
|
1190 #endif |
|
1191 |
|
1192 if (result != KErrNone && result!=KErrNotFound) |
|
1193 { |
|
1194 iRepository.FailTransaction(result, errorKey); |
|
1195 TPckg<TUint32> p(errorKey); |
|
1196 aMessage.WriteL(2, p); |
|
1197 } |
|
1198 return result; |
|
1199 } |
|
1200 |
|
1201 TInt CServerSubSession::TransactionStart(const TClientRequest& aMessage) |
|
1202 { |
|
1203 // check if we are already in a transaction |
|
1204 TBool inTransactionAlready = iRepository.IsInTransaction(); |
|
1205 |
|
1206 // panic client if attempting to start a transaction when already in one |
|
1207 __ASSERT_ALWAYS(!inTransactionAlready, PanicClient(EStartAlreadyInTransaction, aMessage)); |
|
1208 |
|
1209 // if the client has been panicked then we don't want to continue. |
|
1210 // client session will already have been taken down so don't want to complete the message |
|
1211 if (inTransactionAlready) |
|
1212 { |
|
1213 #ifdef SRVSUBSESS_TRACE |
|
1214 TUid uid = RepositoryUid(); |
|
1215 |
|
1216 __SRVSUBSESS_TRACE1("CServerSubSession::TransactionStart **Failure** already in transaction UID=0x%x\n",uid.iUid); |
|
1217 #endif |
|
1218 |
|
1219 return KDontCompleteMessage; |
|
1220 } |
|
1221 |
|
1222 const TInt mode = aMessage.Int0(); |
|
1223 |
|
1224 TInt error = iRepository.StartTransaction(mode); |
|
1225 |
|
1226 #ifdef SRVSUBSESS_TRACE |
|
1227 |
|
1228 TUid uid = RepositoryUid(); |
|
1229 |
|
1230 // mode strings match transstate.h - if that is updated, this should be as well. |
|
1231 const TPtrC modeStrings[] = |
|
1232 { |
|
1233 _L("ENoTransaction"), // 0 |
|
1234 _L("EReadTransaction"), // EReadBit 1 |
|
1235 _L("EConcurrentReadWriteTransaction"), // EWriteBit 2 |
|
1236 _L("EReadWriteTransaction|EAllTransactionBits"), //EReadBit | EWriteBit 3 |
|
1237 _L("EFailedBit") // 4 |
|
1238 }; |
|
1239 |
|
1240 if (error == KErrNone) |
|
1241 { |
|
1242 __SRVSUBSESS_TRACE3("CServerSubSession::TransactionStart UID: 0x%x Mode=%d (%S)\n",uid.iUid,mode,&modeStrings[mode]); |
|
1243 } |
|
1244 else |
|
1245 { |
|
1246 __SRVSUBSESS_TRACE3("CServerSubSession::TransactionStart **Failure** UID: 0x%x Mode=%d (%S)\n",uid.iUid,mode,&modeStrings[mode]); |
|
1247 } |
|
1248 #endif |
|
1249 |
|
1250 return error; |
|
1251 } |
|
1252 |
|
1253 // serves as both rollback and async cancel |
|
1254 TInt CServerSubSession::TransactionCancel(const TClientRequest& /*aMessage*/) |
|
1255 { |
|
1256 #ifdef SRVSUBSESS_TRACE |
|
1257 TUid uid = RepositoryUid(); |
|
1258 |
|
1259 __SRVSUBSESS_TRACE1("CServerSubSession::TransactionCancel UID: 0x%x",uid.iUid); |
|
1260 #endif |
|
1261 iRepository.CancelTransaction(); |
|
1262 return KErrNone; |
|
1263 } |
|
1264 |
|
1265 TInt CServerSubSession::TransactionCommitL(const TClientRequest& aMessage) |
|
1266 { |
|
1267 // check if we are in a transaction |
|
1268 TBool inTransaction = iRepository.IsInTransaction(); |
|
1269 |
|
1270 // panic client if attempting to commit a transaction when we are not in one |
|
1271 __ASSERT_ALWAYS(inTransaction, PanicClient(ECommitNotInTransaction, aMessage)); |
|
1272 |
|
1273 // if the client has been panicked then we don't want to continue. |
|
1274 // client session will already have been taken down so don't want to complete the message |
|
1275 if (!inTransaction) |
|
1276 { |
|
1277 #ifdef SRVSUBSESS_TRACE |
|
1278 TUid uid = RepositoryUid(); |
|
1279 |
|
1280 __SRVSUBSESS_TRACE1("CServerSubSession::TransactionCommitL **Failure** In Transaction UID: 0x%x TransactionKey=%d\n",uid.iUid); |
|
1281 #endif |
|
1282 return KDontCompleteMessage; |
|
1283 } |
|
1284 |
|
1285 TUint32 keyInfo = KUnspecifiedKey; |
|
1286 TInt result = iRepository.CommitTransaction(keyInfo); |
|
1287 |
|
1288 TPckg<TUint32> p(keyInfo); |
|
1289 aMessage.WriteL(0, p); |
|
1290 |
|
1291 #ifdef SRVSUBSESS_TRACE |
|
1292 TUid uid = RepositoryUid(); |
|
1293 |
|
1294 if (result == KErrNone) |
|
1295 { |
|
1296 __SRVSUBSESS_TRACE2("CServerSubSession::TransactionCommitL UID: 0x%x TransactionKey=%d\n",uid.iUid,keyInfo); |
|
1297 } |
|
1298 else |
|
1299 { |
|
1300 __SRVSUBSESS_TRACE2("CServerSubSession::TransactionCommitL **Failure** UID: 0x%x TransactionKey=%d\n",uid.iUid,keyInfo); |
|
1301 } |
|
1302 #endif |
|
1303 return result; |
|
1304 } |
|
1305 |
|
1306 TInt CServerSubSession::DeleteRangeL(const TClientRequest& aMessage) |
|
1307 { |
|
1308 if (iRepository.IsInActiveReadTransaction()) |
|
1309 { |
|
1310 // could not promote to read/write: fail & give the partialKey as the error key |
|
1311 TUint32 partialKey = aMessage.Int0(); |
|
1312 return iRepository.FailTransaction(KErrLocked, partialKey); |
|
1313 } |
|
1314 TUint32 errorKey = KUnspecifiedKey; |
|
1315 TInt result = iRepository.TransactionDeleteRangeL(aMessage, errorKey); |
|
1316 if (result != KErrNone) |
|
1317 { |
|
1318 TPckg<TUint32> p(errorKey); |
|
1319 aMessage.WriteL(2, p); |
|
1320 } |
|
1321 |
|
1322 #ifdef SRVSUBSESS_TRACE |
|
1323 TUid uid = RepositoryUid(); |
|
1324 TUint32 partialKey = aMessage.Int0(); |
|
1325 TUint32 keyMask = aMessage.Int1(); |
|
1326 |
|
1327 if (result == KErrNone) |
|
1328 { |
|
1329 __SRVSUBSESS_TRACE3("CServerSubSession::DeleteRangeL UID: 0x%x Key=0x%x Mask=0x%x\n",uid.iUid,partialKey,keyMask); |
|
1330 } |
|
1331 else |
|
1332 { |
|
1333 __SRVSUBSESS_TRACE2("CServerSubSession::DeleteRangeL **Failure** UID: 0x%x ErrorKey=%d\n",uid.iUid,errorKey); |
|
1334 } |
|
1335 #endif |
|
1336 |
|
1337 return result; |
|
1338 } |
|
1339 |
|
1340 TInt CServerSubSession::TransactionStateL(const TClientRequest& aMessage) |
|
1341 { |
|
1342 TInt iState = iRepository.TransactionState(); |
|
1343 |
|
1344 TPckg<TInt> p(iState); |
|
1345 aMessage.WriteL(0, p); |
|
1346 |
|
1347 #ifdef SRVSUBSESS_TRACE |
|
1348 TUid uid = RepositoryUid(); |
|
1349 |
|
1350 __SRVSUBSESS_TRACE2("CServerSubSession::TransactionStateL UID: 0x%x State=%d\n",uid.iUid,iState); |
|
1351 #endif |
|
1352 |
|
1353 return KErrNone; |
|
1354 } |
|
1355 |
|
1356 TInt CServerSubSession::TransactionFail(const TClientRequest& aMessage) |
|
1357 { |
|
1358 #ifdef SRVSUBSESS_TRACE |
|
1359 TUid uid = RepositoryUid(); |
|
1360 |
|
1361 __SRVSUBSESS_TRACE1("CServerSubSession::TransactionFail UID: 0x%x",uid.iUid); |
|
1362 #endif |
|
1363 |
|
1364 iRepository.FailTransaction(aMessage.Int0(), KUnspecifiedKey); |
|
1365 return KErrNone; |
|
1366 } |
|
1367 |
|
1368 //Check the security policy against a RMessage. |
|
1369 TInt CServerSubSession::CheckPolicy(const TClientRequest& msg, |
|
1370 const TSecurityPolicy& aPolicy, |
|
1371 const char *aDiagnostic) |
|
1372 { |
|
1373 return msg.CheckPolicy(aPolicy,aDiagnostic) ? KErrNone : KErrPermissionDenied; |
|
1374 } |