|
1 /* |
|
2 * Copyright (c) 2002-2004 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 "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: Implementation of policymanagement components |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CentRepToolServer.h" |
|
20 #include "RepositorySession.h" |
|
21 #include "debug.h" |
|
22 |
|
23 #include "CentRepToolClientServer.h" |
|
24 #include <e32svr.h> |
|
25 |
|
26 |
|
27 // ---------------------------------------------------------------------------------------- |
|
28 // Server startup code |
|
29 // ---------------------------------------------------------------------------------------- |
|
30 |
|
31 static void RunServerL() |
|
32 { |
|
33 // naming the server thread after the server helps to debug panics |
|
34 User::LeaveIfError(User::RenameThread(KCentRepToolServerName)); |
|
35 |
|
36 // create and install the active scheduler |
|
37 CActiveScheduler* s=new(ELeave) CActiveScheduler; |
|
38 CleanupStack::PushL(s); |
|
39 CActiveScheduler::Install(s); |
|
40 |
|
41 // create the server (leave it on the cleanup stack) |
|
42 CCentRepToolServer::NewLC(); |
|
43 // Initialisation complete, now signal the client |
|
44 |
|
45 RProcess::Rendezvous(KErrNone); |
|
46 |
|
47 // Ready to run |
|
48 RDEBUG("Centrep tool server is running"); |
|
49 CActiveScheduler::Start(); |
|
50 |
|
51 // Cleanup the server and scheduler |
|
52 CleanupStack::PopAndDestroy(2); |
|
53 } |
|
54 |
|
55 // Server process entry-point |
|
56 TInt E32Main() |
|
57 { |
|
58 __UHEAP_MARK; |
|
59 RDEBUG( "CentRepToolServer: E32Main"); |
|
60 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
61 TInt r=KErrNoMemory; |
|
62 if (cleanup) |
|
63 { |
|
64 TRAP(r,RunServerL()); |
|
65 delete cleanup; |
|
66 } |
|
67 __UHEAP_MARKEND; |
|
68 return r; |
|
69 } |
|
70 |
|
71 // RMessagePtr2::Panic() also completes the message. This is: |
|
72 // (a) important for efficient cleanup within the kernel |
|
73 // (b) a problem if the message is completed a second time |
|
74 void PanicClient(const RMessagePtr2& aMessage, TCentRepToolServerPanic aPanic) |
|
75 { |
|
76 RDEBUG("CentRepTool PanicClient"); |
|
77 aMessage.Panic( IniConstants::KCentRepToolPanic,aPanic); |
|
78 } |
|
79 |
|
80 |
|
81 // ---------------------------------------------------------------------------------------- |
|
82 // CShutDown |
|
83 // ---------------------------------------------------------------------------------------- |
|
84 inline CShutdown::CShutdown() |
|
85 :CTimer(-1) |
|
86 { |
|
87 CActiveScheduler::Add(this); |
|
88 } |
|
89 |
|
90 inline void CShutdown::ConstructL() |
|
91 { |
|
92 CTimer::ConstructL(); |
|
93 } |
|
94 |
|
95 inline void CShutdown::Start() |
|
96 { |
|
97 RDEBUG("CentRepToolServer: starting shutdown timeout"); |
|
98 After(KPolicyEngineShutdownDelay); |
|
99 } |
|
100 |
|
101 void CShutdown::RunL() |
|
102 { |
|
103 RDEBUG("CentRepToolServer timeout ... closing"); |
|
104 CActiveScheduler::Stop(); |
|
105 } |
|
106 |
|
107 // ---------------------------------------------------------------------------------------- |
|
108 // CPolicyEngineServer |
|
109 // ---------------------------------------------------------------------------------------- |
|
110 inline CCentRepToolServer::CCentRepToolServer() |
|
111 :CPolicyServer(0, CentRepToolSecurityPolicy,ESharableSessions) |
|
112 { |
|
113 } |
|
114 |
|
115 CServer2* CCentRepToolServer::NewLC() |
|
116 { |
|
117 CentRepToolSecurityPolicy.iOnConnect = KCentRepToolSecurityElementsIndex[2]; //Specifis that only policy engine may connect to server |
|
118 CentRepToolSecurityPolicy.iRangeCount = KCentRepToolRangeCount; //number of ranges |
|
119 CentRepToolSecurityPolicy.iRanges = KCentRepToolRanges; |
|
120 CentRepToolSecurityPolicy.iElementsIndex = KCentRepToolSecurityElementsIndex; |
|
121 CentRepToolSecurityPolicy.iElements = KCentRepToolSecurityElements; |
|
122 |
|
123 RDEBUG("CentRepToolServer: CentRepToolServer::NewLC"); |
|
124 |
|
125 CCentRepToolServer* self=new(ELeave) CCentRepToolServer; |
|
126 CleanupStack::PushL(self); |
|
127 self->ConstructL(); |
|
128 return self; |
|
129 } |
|
130 |
|
131 CCentRepToolServer::~CCentRepToolServer() |
|
132 { |
|
133 delete iContainerIndex; |
|
134 } |
|
135 |
|
136 // 2nd phase construction - ensure the timer and server objects are running |
|
137 void CCentRepToolServer::ConstructL() |
|
138 { |
|
139 StartL(KCentRepToolServerName); |
|
140 |
|
141 iContainerIndex = CObjectConIx::NewL(); |
|
142 |
|
143 iShutdown.ConstructL(); |
|
144 // ensure that the server still exits even if the 1st client fails to connect |
|
145 iShutdown.Start(); |
|
146 } |
|
147 |
|
148 |
|
149 // Create a new client session. This should really check the version number. |
|
150 CSession2* CCentRepToolServer::NewSessionL(const TVersion&,const RMessage2&) const |
|
151 { |
|
152 RDEBUG("CentRepToolServer: CCentRepToolServer::NewSessionL"); |
|
153 return new (ELeave) CCentRepToolSession(); |
|
154 } |
|
155 |
|
156 // A new session is being created |
|
157 // Cancel the shutdown timer if it was running |
|
158 void CCentRepToolServer::AddSession() |
|
159 { |
|
160 RDEBUG("CentRepToolServer: CPolicyEngineServer::AddSession"); |
|
161 ++iSessionCount; |
|
162 iShutdown.Cancel(); |
|
163 } |
|
164 |
|
165 // A session is being destroyed |
|
166 // Start the shutdown timer if it is the last session. |
|
167 void CCentRepToolServer::DropSession() |
|
168 { |
|
169 RDEBUG("CentRepToolServer: CPolicyEngineServer::DropSession"); |
|
170 if (--iSessionCount==0) |
|
171 iShutdown.Start(); |
|
172 } |
|
173 |
|
174 CObjectCon* CCentRepToolServer::NewContainerL() |
|
175 { |
|
176 return iContainerIndex->CreateL(); |
|
177 } |
|
178 |
|
179 inline CCentRepToolSession::CCentRepToolSession() |
|
180 { |
|
181 RDEBUG("CentRepToolServer: CCentRepToolSession::CCentRepToolSession"); |
|
182 } |
|
183 |
|
184 inline CCentRepToolServer& CCentRepToolSession::Server() |
|
185 { |
|
186 return *static_cast<CCentRepToolServer*>(const_cast<CServer2*>(CSession2::Server())); |
|
187 } |
|
188 |
|
189 // 2nd phase construct for sessions - called by the CServer framework |
|
190 void CCentRepToolSession::CreateL() |
|
191 { |
|
192 RDEBUG("CentRepTool Server: CCentRepToolSession::CreateL"); |
|
193 |
|
194 iRepositorySessions = CObjectIx::NewL(); |
|
195 iContainer = Server().NewContainerL(); |
|
196 |
|
197 Server().AddSession(); |
|
198 } |
|
199 |
|
200 CCentRepToolSession::~CCentRepToolSession() |
|
201 { |
|
202 RDEBUG("CentRepTool Server: CCentRepToolSession::~CCentRepToolSession"); |
|
203 |
|
204 delete iRepositorySessions; |
|
205 |
|
206 Server().DropSession(); |
|
207 } |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 void CCentRepToolSession::ServiceL(const RMessage2& aMessage) |
|
215 { |
|
216 iCurrentSession = 0; |
|
217 TRAPD(err,DispatchMessageL(aMessage)); |
|
218 |
|
219 aMessage.Complete(err); |
|
220 } |
|
221 |
|
222 void CCentRepToolSession::DispatchMessageL(const RMessage2& aMessage) |
|
223 { |
|
224 //Subsession management |
|
225 switch (aMessage.Function()) |
|
226 { |
|
227 case ECreateRepositorySubSession: |
|
228 case ECreateCheckAccessSession: |
|
229 { |
|
230 RDEBUG("CentRepTool: New repository session"); |
|
231 NewRepositorySessionL( aMessage); |
|
232 return; |
|
233 } |
|
234 case ECloseRepositorySubSession: |
|
235 case ECloseCheckAcceessSession: |
|
236 { |
|
237 RDEBUG("CentRepTool: Close repository session"); |
|
238 DeleteRepositorySession( aMessage); |
|
239 return; |
|
240 } |
|
241 case ECheckCommitState : |
|
242 { |
|
243 RDEBUG("CentRepTool: Check last commit state"); |
|
244 CRepositorySession::CheckCommitStateL(); |
|
245 return; |
|
246 } |
|
247 case EPerformCentRepToolRFS : |
|
248 { |
|
249 RDEBUG("CentRepTool: Perform RFS"); |
|
250 PerformRFSL(); |
|
251 return; |
|
252 } |
|
253 } |
|
254 |
|
255 //Trusted session operations |
|
256 CRepositorySession * repositorySession = RepositorySessionFromHandle( aMessage); |
|
257 iCurrentSession = repositorySession; |
|
258 |
|
259 switch (aMessage.Function()) |
|
260 { |
|
261 case EInitRepositorySession: |
|
262 { |
|
263 RDEBUG("CentRepTool: Init repository session"); |
|
264 repositorySession->InitRepositorySessionL(); |
|
265 } |
|
266 break; |
|
267 case ESetSIDWRForSetting : |
|
268 { |
|
269 RDEBUG("CentRepTool: Add SID for individual setting"); |
|
270 repositorySession->SetSecurityIdForSettingL( aMessage); |
|
271 } |
|
272 break; |
|
273 case ESetSIDWRForRange: |
|
274 { |
|
275 RDEBUG("CentRepTool: Add SID for range"); |
|
276 repositorySession->SetSecurityIdForRangeL( aMessage); |
|
277 } |
|
278 break; |
|
279 case ERestoreSetting : |
|
280 { |
|
281 RDEBUG("CentRepTool: Restore individual setting"); |
|
282 repositorySession->RestoreSettingL( aMessage); |
|
283 } |
|
284 break; |
|
285 case ERestoreRange : |
|
286 { |
|
287 RDEBUG("CentRepTool: Restore range"); |
|
288 repositorySession->RestoreRangeL( aMessage); |
|
289 } |
|
290 break; |
|
291 case EAddSIDWRForDefaults : |
|
292 { |
|
293 RDEBUG("CentRepTool: Add SID for all settings (default, range, mask)"); |
|
294 repositorySession->AddSidForDefaultsL( aMessage); |
|
295 } |
|
296 break; |
|
297 case ERestoreDefaults : |
|
298 { |
|
299 RDEBUG("CentRepTool: "); |
|
300 RDEBUG("CentRepTool: Remove SID from all settings (default, range, mask)"); |
|
301 repositorySession->RestoreDefaultsL( aMessage); |
|
302 } |
|
303 break; |
|
304 case EFlushRepository : |
|
305 { |
|
306 RDEBUG("CentRepTool: Commit security changes in repository"); |
|
307 repositorySession->CommitRepositoryL(); |
|
308 } |
|
309 break; |
|
310 case ESetSIDWRForMask : |
|
311 { |
|
312 RDEBUG("CentRepTool: Set SID for mask setting"); |
|
313 repositorySession->SetSecurityIdForMaskL( aMessage); |
|
314 } |
|
315 break; |
|
316 case ERestoreMask : |
|
317 { |
|
318 RDEBUG("CentRepTool: Restore mask setting"); |
|
319 repositorySession->RestoreMaskL( aMessage); |
|
320 } |
|
321 break; |
|
322 case ERemoveBackupFlagForMask: |
|
323 { |
|
324 RDEBUG("CentRepTool: Set backup flag for mask"); |
|
325 repositorySession->RemoveBackupForMaskL( aMessage); |
|
326 } |
|
327 break; |
|
328 case ERestoreBackupFlagForMask: |
|
329 { |
|
330 RDEBUG("CentRepTool: Restore backup flag for mask"); |
|
331 repositorySession->RestoreMaskBackupL( aMessage); |
|
332 } |
|
333 break; |
|
334 case ERemoveBackupFlagForDefaults: |
|
335 { |
|
336 RDEBUG("CentRepTool: Set backup flag for defaults"); |
|
337 repositorySession->RemoveDefaultBackup(); |
|
338 } |
|
339 break; |
|
340 case ERestoreBackupFlagForDefaults: |
|
341 { |
|
342 RDEBUG("CentRepTool: Restore backup flag for defaults"); |
|
343 repositorySession->RestoreDefaultBackupL(); |
|
344 } |
|
345 break; |
|
346 case ERemoveBackupFlagForRange: |
|
347 { |
|
348 RDEBUG("CentRepTool: Set backup flag for range"); |
|
349 repositorySession->RemoveBackupForRangeL( aMessage); |
|
350 } |
|
351 break; |
|
352 case ERestoreBackupFlagForRange: |
|
353 { |
|
354 RDEBUG("CentRepTool: Restore backup flag for range"); |
|
355 repositorySession->RestoreRangeBackupL( aMessage); |
|
356 } |
|
357 break; |
|
358 case ECheckAccess: |
|
359 { |
|
360 RDEBUG("CentRepTool: Check access"); |
|
361 repositorySession->CheckAccessL( aMessage); |
|
362 } |
|
363 break; |
|
364 default: |
|
365 break; |
|
366 } |
|
367 |
|
368 } |
|
369 |
|
370 void CCentRepToolSession::PerformRFSL() |
|
371 { |
|
372 RDEBUG("CentRepToolSession: Restore factory setting operation started"); |
|
373 //RFS tasks in centrep tool |
|
374 // 1. restory setting enforcements |
|
375 // 2. remove backup and temp files from private directory |
|
376 |
|
377 |
|
378 //clean private directory |
|
379 RFs rfs; |
|
380 TInt err = rfs.Connect(); |
|
381 if( err != KErrNone ) |
|
382 { |
|
383 RDEBUG_2("**** CCentRepToolSession::PerformRFSL() - failed to connect to RFs: %d", err ); |
|
384 return; |
|
385 } |
|
386 |
|
387 CleanupClosePushL( rfs); |
|
388 |
|
389 TBuf<100> privatePath; |
|
390 err = rfs.PrivatePath( privatePath); |
|
391 |
|
392 if ( err == KErrNone) |
|
393 { |
|
394 //remove files from private directory, also backups |
|
395 CFileMan* file = CFileMan::NewL( rfs); |
|
396 |
|
397 privatePath.Append(_L("*.*")); |
|
398 err = file->Delete( privatePath, CFileMan::ERecurse); |
|
399 delete file; |
|
400 } |
|
401 |
|
402 CleanupStack::PopAndDestroy( &rfs); |
|
403 |
|
404 RDEBUG("CentRepToolSession: Restore factory setting operation finished"); |
|
405 } |
|
406 |
|
407 |
|
408 CRepositorySession* CCentRepToolSession::RepositorySessionFromHandle( const RMessage2& aMessage) |
|
409 { |
|
410 CRepositorySession* repositorySession = (CRepositorySession*)iRepositorySessions->At(aMessage.Int3()); |
|
411 |
|
412 if (repositorySession == NULL) |
|
413 { |
|
414 PanicClient( aMessage, EBadSubsessionHandle); |
|
415 } |
|
416 |
|
417 return repositorySession; |
|
418 } |
|
419 |
|
420 |
|
421 // Create a new counter; pass back its handle via the message |
|
422 void CCentRepToolSession::NewRepositorySessionL( const RMessage2& aMessage) |
|
423 { |
|
424 |
|
425 TUid repositoryUid; |
|
426 TPckg<TUid> repositoryUidPack( repositoryUid); |
|
427 aMessage.ReadL(0, repositoryUidPack); |
|
428 |
|
429 //add new CTrustedSession object into container and object index |
|
430 CRepositorySession * repositorySession = CRepositorySession::NewL( repositoryUid); |
|
431 |
|
432 iContainer->AddL( repositorySession); |
|
433 TInt handle = iRepositorySessions->AddL( repositorySession); |
|
434 |
|
435 //transmit handle to client |
|
436 TPckg<TInt> handlePckg(handle); |
|
437 TRAPD( r, aMessage.WriteL(3, handlePckg)) |
|
438 |
|
439 if ( r != KErrNone) |
|
440 { |
|
441 iRepositorySessions->Remove(handle); |
|
442 PanicClient( aMessage, EBadDescriptor); |
|
443 return; |
|
444 } |
|
445 |
|
446 iSubsessionCount++; |
|
447 } |
|
448 |
|
449 void CCentRepToolSession::DeleteRepositorySession( const RMessage2& aMessage) |
|
450 { |
|
451 // panic if bad handle |
|
452 CRepositorySession* repositorySession = (CRepositorySession*)iRepositorySessions->At(aMessage.Int3()); |
|
453 if (repositorySession == NULL) |
|
454 PanicClient( aMessage, EBadSubsessionHandle); |
|
455 iRepositorySessions->Remove(aMessage.Int3()); |
|
456 |
|
457 iSubsessionCount--; |
|
458 } |
|
459 |
|
460 |
|
461 // Handle an error from CentRepTool::ServiceL() |
|
462 void CCentRepToolSession::ServiceError(const RMessage2& aMessage,TInt aError) |
|
463 { |
|
464 RDEBUG_2("CentRepTool: CentRepTool::ServiceError %d",aError); |
|
465 CSession2::ServiceError(aMessage,aError); |
|
466 } |