policymanagement/policyengine/policyengineserver/src/PolicyEngineServer.cpp
changeset 0 b497e44ab2fc
child 13 06f47423ecee
child 66 08c8318ec9cb
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2000 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 // INCLUDES
       
    20 
       
    21 #include "PolicyEngineServer.h"
       
    22 #include "PolicyParser.h"
       
    23 #include "TrustedSession.h"
       
    24 #include "PolicyStorage.h"
       
    25 #include "PolicyManager.h"
       
    26 #include "PolicyProcessor.h"
       
    27 #include "PolicyEngineClientServerDefs.h"
       
    28 #include "debug.h"
       
    29 
       
    30 #include <e32svr.h>
       
    31 #include <f32file.h>
       
    32 #include "DMUtilClient.h"
       
    33 
       
    34 
       
    35 CPolicyEngineServer* CPolicyEngineServer::iServer = 0;
       
    36 
       
    37 #ifdef _DEBUG
       
    38 namespace DebugUtility
       
    39 {
       
    40 	_LIT( PolicyCheckFile, "c:\\policy_check_off_file.txt");
       
    41 	
       
    42 	TBool PolicyCheckActive()
       
    43 	{
       
    44 		TBool response = ETrue;
       
    45 	
       
    46 		RFs rfs;
       
    47 		TInt err = rfs.Connect();
       
    48 		if( err != KErrNone )
       
    49 			{
       
    50 			return EFalse;
       
    51 			}
       
    52 			
       
    53 		RFile file;
       
    54 		
       
    55 		//Check is file exist
       
    56 		if ( KErrNone == file.Open( rfs, PolicyCheckFile, EFileRead))
       
    57 		{
       
    58 			response = EFalse;
       
    59 		}
       
    60 		
       
    61 		file.Close();
       
    62 		rfs.Close();
       
    63 		
       
    64 		return response;
       
    65 	}
       
    66 }
       
    67 #endif
       
    68 
       
    69 
       
    70 // ----------------------------------------------------------------------------------------
       
    71 // Server startup code
       
    72 // ----------------------------------------------------------------------------------------
       
    73 
       
    74 static void RunServerL()
       
    75 	{
       
    76 	// naming the server thread after the server helps to debug panics
       
    77 	User::LeaveIfError(User::RenameThread(KPolicyEngineServerName)); 
       
    78 
       
    79 	// create and install the active scheduler
       
    80 	CActiveScheduler* s=new(ELeave) CActiveScheduler;
       
    81 	CleanupStack::PushL(s);
       
    82 	CActiveScheduler::Install(s);
       
    83 	
       
    84 	// create the server (leave it on the cleanup stack)
       
    85 	CPolicyEngineServer::NewLC();
       
    86 	// Initialisation complete, now signal the client
       
    87 
       
    88 	RProcess::Rendezvous(KErrNone);
       
    89 
       
    90 	// Ready to run
       
    91 	RDEBUG("Policy engine server is running");
       
    92 	
       
    93 	CActiveScheduler::Start();
       
    94 	
       
    95 	// Cleanup the server and scheduler
       
    96 	CleanupStack::PopAndDestroy(2);
       
    97 	}
       
    98 
       
    99 // Server process entry-point
       
   100 TInt E32Main()
       
   101 	{
       
   102 	__UHEAP_MARK;
       
   103 	RDEBUG( "PolicyEngineServer: E32Main");
       
   104 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
   105 	TInt r=KErrNoMemory;
       
   106 	if (cleanup)
       
   107 		{
       
   108 		TRAP(r,RunServerL());
       
   109 		delete cleanup;
       
   110 		}
       
   111 	__UHEAP_MARKEND;
       
   112 	return r;
       
   113 	}
       
   114     
       
   115 // ----------------------------------------------------------------------------------------
       
   116 // PanicClient
       
   117 // ----------------------------------------------------------------------------------------
       
   118     
       
   119 void PanicClient(const RMessagePtr2& aMessage,TPolicyEnginePanic aPanic)
       
   120 	{
       
   121 	_LIT(KPanic,"PolicyEngineServer");
       
   122 	aMessage.Panic(KPanic,aPanic);
       
   123 	}
       
   124 
       
   125 // ----------------------------------------------------------------------------------------
       
   126 // CShutDown::CShutdown()
       
   127 // ----------------------------------------------------------------------------------------
       
   128 
       
   129 inline CShutdown::CShutdown()
       
   130 	:CTimer(-1)
       
   131 	{
       
   132 	CActiveScheduler::Add(this);
       
   133 	}
       
   134 	
       
   135 // ----------------------------------------------------------------------------------------
       
   136 // CShutDown::ConstructL()
       
   137 // ----------------------------------------------------------------------------------------
       
   138 
       
   139 inline void CShutdown::ConstructL()
       
   140 	{
       
   141 	CTimer::ConstructL();
       
   142 	}
       
   143 
       
   144 // ----------------------------------------------------------------------------------------
       
   145 // CShutDown::Start()
       
   146 // ----------------------------------------------------------------------------------------
       
   147 
       
   148 inline void CShutdown::Start()
       
   149 	{
       
   150 	RDEBUG("PolicyEngineServer: starting selfcheck timeout");
       
   151 	iSelfCheckCounter = 0;
       
   152 	After( KPolicyEngineSelfCheckDelay);
       
   153 	}
       
   154 
       
   155 // ----------------------------------------------------------------------------------------
       
   156 // CShutDown::RunL()
       
   157 // ----------------------------------------------------------------------------------------
       
   158 
       
   159 void CShutdown::RunL()
       
   160 {
       
   161 	RDEBUG("Policy engine server selfcheck timeout...");
       
   162 	iSelfCheckCounter++;
       
   163 	
       
   164 	
       
   165 	if ( iSelfCheckCounter == KPolicyEngineReleaseElementsDelay)
       
   166 	{
       
   167 		RDEBUG("PolicyEngineServer: Release cache elements...");
       
   168 		CPolicyStorage::PolicyStorage()->ReleaseElements();
       
   169 	} 
       
   170 	
       
   171 	if ( iSelfCheckCounter >= KPolicyEngineShutdownDelay)
       
   172 	{
       
   173 		RDEBUG("PolicyEngineServer: Shutdown...");
       
   174 		CActiveScheduler::Stop();
       
   175 	}
       
   176 	else
       
   177 	{
       
   178 		After( KPolicyEngineSelfCheckDelay);
       
   179 	}
       
   180 	
       
   181 }
       
   182 
       
   183 // ----------------------------------------------------------------------------------------
       
   184 // CPolicyEngineServer::CPolicyEngineServer
       
   185 // ----------------------------------------------------------------------------------------
       
   186 
       
   187 inline CPolicyEngineServer::CPolicyEngineServer()
       
   188 	: CPolicyServer(0, KPolicyEngineSecurityPolicy, ESharableSessions)
       
   189 	{
       
   190 		CPolicyEngineServer::iServer = this;
       
   191 	}
       
   192 
       
   193 // ----------------------------------------------------------------------------------------
       
   194 // CPolicyEngineServer::~CPolicyEngineServer
       
   195 // ----------------------------------------------------------------------------------------
       
   196 	
       
   197 CPolicyEngineServer::~CPolicyEngineServer()
       
   198 {
       
   199 	RDEBUG("CPolicyEngineServer::~CPolicyEngineServer()");
       
   200 	delete iPolicyStorage;
       
   201 	delete iCertificateMaps;
       
   202 	delete iFlags;
       
   203 	delete iContainerIndex;
       
   204 	
       
   205 	iActiveObjectCancelList.Close();
       
   206 }
       
   207 
       
   208 // ----------------------------------------------------------------------------------------
       
   209 // CPolicyEngineServer::NewLC()
       
   210 // ----------------------------------------------------------------------------------------
       
   211 	
       
   212 CServer2* CPolicyEngineServer::NewLC()
       
   213 {
       
   214 	RDEBUG("PolicyEngineServer: CPolicyEngineServer::NewLC");
       
   215 
       
   216 	CPolicyEngineServer* self=new(ELeave) CPolicyEngineServer;
       
   217 	CleanupStack::PushL(self);
       
   218 
       
   219 	self->ConstructL();
       
   220 	return self;
       
   221 }
       
   222 
       
   223 // ----------------------------------------------------------------------------------------
       
   224 // CPolicyEngineServer::ConstructL()
       
   225 // ----------------------------------------------------------------------------------------
       
   226 
       
   227 void CPolicyEngineServer::ConstructL()
       
   228 	{
       
   229 	RDEBUG("CPolicyEngineServer::ConstructL() begin");
       
   230 	// 2nd phase construction - ensure the timer and server objects are running
       
   231 
       
   232 	StartL (KPolicyEngineServerName);
       
   233 	iContainerIndex = CObjectConIx::NewL();
       
   234 	//create storage and set static reference
       
   235 	iPolicyStorage = CPolicyStorage::NewL();
       
   236 	CPolicyStorage::iPolicyStorage = iPolicyStorage;
       
   237 	
       
   238 	iCertificateMaps = CCertificateMaps::NewL();
       
   239 	iFlags = new (ELeave) CServerStatusFlags();
       
   240 	iFlags->iUiActive =EFalse;
       
   241 	iFlags->iManagementActive =EFalse;
       
   242 	iFlags->iProcessorActive =EFalse;
       
   243 
       
   244 	iShutdown.ConstructL();
       
   245 	// ensure that the server still exits even if the 1st client fails to connect
       
   246 	iShutdown.Start();
       
   247 	RDEBUG("CPolicyEngineServer::ConstructL() end");
       
   248 	}
       
   249 
       
   250 // ----------------------------------------------------------------------------------------
       
   251 // CPolicyEngineServer::NewSessionL()
       
   252 // ----------------------------------------------------------------------------------------
       
   253 
       
   254 CSession2* CPolicyEngineServer::NewSessionL( const TVersion&, const RMessage2&) const
       
   255 	{
       
   256 		// Create a new client session. This should really check the version number	
       
   257 		
       
   258 		RDEBUG("PolicyEngineServer: CPolicyEngineServer::NewSessionL");
       
   259 		
       
   260 		return new (ELeave) CPolicyEngineSession();
       
   261 	}
       
   262 
       
   263 // ----------------------------------------------------------------------------------------
       
   264 // CPolicyEngineServer::AddSession()
       
   265 // ----------------------------------------------------------------------------------------
       
   266 
       
   267 void CPolicyEngineServer::AddSession()
       
   268 {
       
   269 	// A new session is being created
       
   270 	RDEBUG("PolicyEngineServer: CPolicyEngineServer::AddSession");
       
   271 	++iSessionCount;
       
   272 	
       
   273 	// Cancel the shutdown timer if it was running
       
   274 	iShutdown.Cancel();
       
   275 }
       
   276 
       
   277 
       
   278 // ----------------------------------------------------------------------------------------
       
   279 // CPolicyEngineServer::DropSession()
       
   280 // ----------------------------------------------------------------------------------------
       
   281 
       
   282 void CPolicyEngineServer::DropSession()
       
   283 {
       
   284 	// A session is being destroyed
       
   285 	RDEBUG("PolicyEngineServer: CPolicyEngineServer::DropSession");
       
   286 
       
   287 	// Start the shutdown timer if it is the last session
       
   288 	if (--iSessionCount==0)
       
   289 	{
       
   290 		iShutdown.Start();
       
   291 	}
       
   292 }
       
   293 
       
   294 // ----------------------------------------------------------------------------------------
       
   295 // CPolicyEngineServer::DropSession()
       
   296 // ----------------------------------------------------------------------------------------
       
   297 
       
   298 CServerStatusFlags* CPolicyEngineServer::StatusFlags()
       
   299 {
       
   300 	return CPolicyEngineServer::iServer->iFlags;
       
   301 }
       
   302 
       
   303 // ----------------------------------------------------------------------------------------
       
   304 // CPolicyEngineServer::NewContainerL()
       
   305 // ----------------------------------------------------------------------------------------
       
   306 
       
   307 CObjectCon* CPolicyEngineServer::NewContainerL()
       
   308 {
       
   309 	//create new container and return pointer
       
   310 	return iContainerIndex->CreateL();
       
   311 }
       
   312 
       
   313 
       
   314 // ----------------------------------------------------------------------------------------
       
   315 // CPolicyEngineServer::CertificateMaps()
       
   316 // ----------------------------------------------------------------------------------------
       
   317 CCertificateMaps * CPolicyEngineServer::CertificateMaps()
       
   318 {
       
   319 	//return pointer to global certificate maps instance
       
   320 	return CPolicyEngineServer::iServer->iCertificateMaps;
       
   321 }
       
   322 
       
   323 
       
   324 // ----------------------------------------------------------------------------------------
       
   325 // CPolicyEngineServer::SetActiveSubSession()
       
   326 // ----------------------------------------------------------------------------------------
       
   327 void CPolicyEngineServer::SetActiveSubSession( const CBase* iBase)
       
   328 {
       
   329 	RDEBUG("CPolicyEngineServer::SetActiveSubSession()");
       
   330 	CPolicyEngineServer::iServer->iSubSessionObjects = 0;
       
   331 	
       
   332 	CPolicyEngineServer::iServer->iSessionIter.SetToFirst();
       
   333 	for ( ; CPolicyEngineServer::iServer->iSessionIter != 0 ; CPolicyEngineServer::iServer->iSessionIter++)
       
   334 	{
       
   335 		CSession2 * session = CPolicyEngineServer::iServer->iSessionIter;
       
   336 		CPolicyEngineSession* policyenginesession = (CPolicyEngineSession*) session;
       
   337 		CSubSessionObjects* objects = policyenginesession->GetSubSessionObjects( iBase);
       
   338 		
       
   339 		if ( objects )
       
   340 		{
       
   341 			CPolicyEngineServer::iServer->iSubSessionObjects = objects;
       
   342 			break;
       
   343 		}
       
   344 	}
       
   345 }
       
   346 
       
   347 
       
   348 
       
   349 
       
   350 
       
   351 // ----------------------------------------------------------------------------------------
       
   352 // CPolicyEngineServer::AddActiveObjectL()
       
   353 // ----------------------------------------------------------------------------------------
       
   354 void CPolicyEngineServer::AddActiveObjectL( CActive* aActiveObject)
       
   355 {
       
   356 	CPolicyEngineServer::iServer->iActiveObjectCancelList.AppendL( aActiveObject);
       
   357 }
       
   358 
       
   359 // ----------------------------------------------------------------------------------------
       
   360 // CPolicyEngineServer::RemoveActiveObject()
       
   361 // ----------------------------------------------------------------------------------------
       
   362 void CPolicyEngineServer::RemoveActiveObject( CActive* aActiveObject)
       
   363 {
       
   364 	for ( TInt i(0); i < CPolicyEngineServer::iServer->iActiveObjectCancelList.Count(); i++)
       
   365 	{
       
   366 		if ( aActiveObject == CPolicyEngineServer::iServer->iActiveObjectCancelList[i])
       
   367 		{
       
   368 			CPolicyEngineServer::iServer->iActiveObjectCancelList.Remove( i);
       
   369 			break;
       
   370 		}
       
   371 	}
       
   372 }
       
   373 
       
   374 
       
   375 // ----------------------------------------------------------------------------------------
       
   376 // CPolicyEngineServer::RemoveActiveObject()
       
   377 // ----------------------------------------------------------------------------------------
       
   378 void CPolicyEngineServer::StopAllPendingRequests()
       
   379 {
       
   380 	RDEBUG("CPolicyEngineServer::StopAllPendingRequests()");
       
   381 	for ( TInt i(0); i < CPolicyEngineServer::iServer->iActiveObjectCancelList.Count(); i++)
       
   382 	{
       
   383 		TInt count = CPolicyEngineServer::iServer->iActiveObjectCancelList.Count();
       
   384 		CPolicyEngineServer::iServer->iActiveObjectCancelList[i]->Cancel();
       
   385 		
       
   386 		//if request cancelling has caused some changes in active object list, then start list from beginning
       
   387 		if ( CPolicyEngineServer::iServer->iActiveObjectCancelList.Count() != count)
       
   388 		{
       
   389 			i = 0;
       
   390 		}
       
   391 	}
       
   392 }
       
   393 
       
   394 
       
   395 
       
   396 // ----------------------------------------------------------------------------------------
       
   397 // CPolicyEngineServer::CustomSecurityCheckL()
       
   398 // ----------------------------------------------------------------------------------------
       
   399 CPolicyServer::TCustomResult CPolicyEngineServer::CustomSecurityCheckL(const RMessage2& aMsg, TInt& /*aAction*/, TSecurityInfo& /*aMissing*/)
       
   400 {
       
   401 	RDEBUG("PolicyEngineServer: Custom security check");
       
   402 
       
   403 	//Three custom check function...
       
   404 	__ASSERT_ALWAYS( aMsg.Function() == ECreateManagementSubSession ||
       
   405 					 aMsg.Function() == ECloseManagementSubSession ||
       
   406 					 aMsg.Function() == EExecuteOperation ||
       
   407 					 aMsg.Function() == RMessage2::EConnect, User::Panic( KPolicyEngineServerName,EPanicIllegalFunction));
       
   408 
       
   409 	CPolicyServer::TCustomResult customResult = EFail;
       
   410 
       
   411 	if ( aMsg.HasCapability( ECapabilityWriteDeviceData)  && aMsg.HasCapability( ECapabilityReadDeviceData))
       
   412 	{
       
   413 		RDEBUG("PolicyEngineServer: Client has CapabilityWriteDeviceData & ECapabilityReadDeviceData - ok");
       
   414 		RDEBUG_3("PolicyEngineServer: Client SID: %d & VID %d",aMsg.SecureId().iId,aMsg.VendorId().iId);
       
   415 		
       
   416 		customResult = EPass;	//Every process can try to make policy management, valid SIDs are 
       
   417 								//defined in policies. Certificate usega is allowed only for DM process (check from platformsecuritypolicies.h)
       
   418 	}
       
   419 	else
       
   420 	{
       
   421 		RDEBUG("PolicyEngineServer: PlatSec failed! Missing cababilities!");
       
   422 		customResult = EFail;
       
   423 	}
       
   424 
       
   425 	return customResult;
       
   426 }
       
   427 
       
   428 
       
   429 
       
   430 
       
   431 
       
   432 // ----------------------------------------------------------------------------------------
       
   433 // CPolicyEngineSession::CPolicyEngineSession()
       
   434 // ----------------------------------------------------------------------------------------
       
   435 
       
   436 inline CPolicyEngineSession::CPolicyEngineSession()
       
   437 	{
       
   438 	RDEBUG("CPolicyEngineSession::CPolicyEngineSession");
       
   439 	}
       
   440 
       
   441 
       
   442 // ----------------------------------------------------------------------------------------
       
   443 // CPolicyEngineSession::Server()
       
   444 // ----------------------------------------------------------------------------------------
       
   445 	
       
   446 inline CPolicyEngineServer& CPolicyEngineSession::Server()
       
   447 {
       
   448 	//return pointer to Server instance
       
   449 	return *static_cast<CPolicyEngineServer*>(const_cast<CServer2*>(CSession2::Server()));
       
   450 }
       
   451 
       
   452 // ----------------------------------------------------------------------------------------
       
   453 // CPolicyEngineSession::CreateL()
       
   454 // ----------------------------------------------------------------------------------------
       
   455 
       
   456 void CPolicyEngineSession::CreateL()
       
   457 {
       
   458 	// 2nd phase construct for sessions
       
   459 	RDEBUG("PolicyEngineSession: CPolicyEngineSession::CreateL");
       
   460 	
       
   461 	//create session specific objects
       
   462 	iSessionsObjects = CObjectIx::NewL();
       
   463 	iContainer = Server().NewContainerL();
       
   464 	
       
   465 	//add session to server
       
   466 	Server().AddSession();
       
   467 }
       
   468 
       
   469 // ----------------------------------------------------------------------------------------
       
   470 // CPolicyEngineSession::~CPolicyEngineSession()
       
   471 // ----------------------------------------------------------------------------------------
       
   472 
       
   473 CPolicyEngineSession::~CPolicyEngineSession()
       
   474 {
       
   475 	RDEBUG("CPolicyEngineSession::~CPolicyEngineSession");
       
   476 	
       
   477 	delete iSessionsObjects;
       
   478 	
       
   479 	Server().DropSession();
       
   480 }
       
   481 
       
   482 // ----------------------------------------------------------------------------------------
       
   483 // CPolicyEngineSession::ServiceL()
       
   484 // ----------------------------------------------------------------------------------------
       
   485 
       
   486 void CPolicyEngineSession::ServiceL( const RMessage2& aMessage)
       
   487 {
       
   488 	RDEBUG("CPolicyEngineSession::ServiceL");
       
   489 	TRAPD(err,DispatchMessageL(aMessage));
       
   490 
       
   491 	RDEBUG_2("CPolicyEngineSession::ServiceL, Error status: %d", err);
       
   492 	
       
   493 	//only KErrGeneral errors 
       
   494 	if ( err != KErrNone && err != KErrNotFound )
       
   495 	{
       
   496 		err = KErrGeneral;
       
   497 	}
       
   498 	
       
   499 	//no completion for asynch methods
       
   500 	switch (aMessage.Function())
       
   501 	{
       
   502 		case EExecuteOperation:
       
   503 		case EPolicyRequest:
       
   504 			//No completion
       
   505 		break;
       
   506 		default:
       
   507 			aMessage.Complete(err);
       
   508 		break;		
       
   509 	}
       
   510 
       
   511 }
       
   512 
       
   513 // ----------------------------------------------------------------------------------------
       
   514 // CPolicyEngineSession::DispatchMessageL()
       
   515 // ----------------------------------------------------------------------------------------
       
   516 
       
   517 void CPolicyEngineSession::DispatchMessageL(const RMessage2& aMessage)
       
   518 	{
       
   519 	RDEBUG_2("CPolicyEngineSession::DispatchMessageL: %d",aMessage.Function());
       
   520 	
       
   521 	//Subsession management
       
   522 	switch (aMessage.Function())
       
   523 	{
       
   524 		case ECreateRequestSubSession:
       
   525 		case ECreateManagementSubSession:
       
   526 		{
       
   527 			NewSubSessionL( aMessage);
       
   528 			return;
       
   529 		}
       
   530 		case ECloseManagementSubSession:
       
   531 		case ECloseRequestSubSessio:
       
   532 		{
       
   533 			DeleteSubSession( aMessage);
       
   534 			return;
       
   535 		}
       
   536 		case EPerformPMRFS :
       
   537 		{
       
   538 			PerformRFSL();	
       
   539 			return;
       
   540 		}
       
   541 	}
       
   542 
       
   543 	//Trusted session operations
       
   544 	CSubSessionObjects * subSession = SubSessionFromHandle( aMessage);
       
   545 		
       
   546 	switch (aMessage.Function())
       
   547 	{
       
   548 		case EExecuteOperation :
       
   549 		{
       
   550 			subSession->iPolicyManager->ExecuteOperation( subSession->iTrustedSession, aMessage);
       
   551 		}
       
   552 		break;
       
   553 		case EGetElementListLength:
       
   554 		case EReadElementList:
       
   555 		{
       
   556 			subSession->iPolicyManager->GetElementListL( aMessage);
       
   557 		}
       
   558 		break;		
       
   559 		case EGetElementDescriptionAndChildListLength :
       
   560 		case EReadElementAndChildList :
       
   561 		{
       
   562 			subSession->iPolicyManager->GetElementInfoL( aMessage);
       
   563 		}
       
   564 		break;		
       
   565 		case EGetElementXACMLLength :
       
   566 		case EReadElementXACML :
       
   567 		{
       
   568 			subSession->iPolicyManager->GetElementXACMLDescriptionL( aMessage);
       
   569 		}
       
   570 		break;		
       
   571 		case EPolicyRequest :
       
   572 		{
       
   573 			subSession->iPolicyProcessor->ExecuteRequestL( aMessage);	
       
   574 		}
       
   575 		break;
       
   576 		case EAddSessionTrust :
       
   577 		{
       
   578 			subSession->iTrustedSession->MakeSessionTrustL( aMessage);	
       
   579 		}
       
   580 		break;
       
   581 		case EIsServerIdValid :
       
   582 		{
       
   583 			subSession->iPolicyManager->IsServerIdValidL( aMessage);	
       
   584 			return;
       
   585 		}
       
   586 		case ECertificateRole :
       
   587 		{
       
   588 			subSession->iPolicyManager->GetCertificateRoleL( aMessage);	
       
   589 		}
       
   590 		break;
       
   591 		default:
       
   592 		break;	
       
   593 	}
       
   594 	
       
   595 }
       
   596 	
       
   597 // ----------------------------------------------------------------------------------------
       
   598 // CPolicyEngineSession::PerformRFS()
       
   599 // ----------------------------------------------------------------------------------------
       
   600 
       
   601 void CPolicyEngineSession::PerformRFSL()
       
   602 {
       
   603 	RDEBUG("PolicyEngineServer: Restory factory setting operation started");
       
   604 	//RFS steps in Policy Management subsystem
       
   605 	// 1. Remove policy files (RAM) from PolicyEngineServers private directory
       
   606 	// 2. Remove backup files (RAM) from PolicyEngineServers private directory
       
   607 	// 3. Remove Central Repository (RAM), handled by CentralRepository
       
   608 	
       
   609 	//stop all requests...
       
   610 	CPolicyEngineServer::StopAllPendingRequests();
       
   611 	
       
   612 	//clean private directory
       
   613 	RFs rfs;
       
   614 	User::LeaveIfError( rfs.Connect() );
       
   615 	CleanupClosePushL( rfs);
       
   616 	
       
   617 	TBuf<100> privatePath;
       
   618 	TInt err = rfs.PrivatePath( privatePath);
       
   619 	
       
   620 	if ( err == KErrNone)
       
   621 	{
       
   622 		//remove files from private directory, also backups
       
   623 		CFileMan* file = CFileMan::NewL( rfs);
       
   624 		
       
   625 		privatePath.Append(_L("*.*"));
       
   626 		err = file->Delete( privatePath, CFileMan::ERecurse);
       
   627 		delete file;
       
   628 	}
       
   629 	
       
   630 	
       
   631 	CleanupStack::PopAndDestroy( &rfs);
       
   632 	
       
   633 	RDEBUG("PolicyEngineServer: Restory factory setting operation finished");
       
   634 }
       
   635 		
       
   636 	
       
   637 // ----------------------------------------------------------------------------------------
       
   638 // CPolicyEngineSession::GetSubSessionObjects()
       
   639 // ----------------------------------------------------------------------------------------
       
   640 
       
   641 CSubSessionObjects* CPolicyEngineSession::GetSubSessionObjects( const CBase* iBase)
       
   642 {
       
   643 	CSubSessionObjects* retVal = 0;
       
   644 
       
   645 	
       
   646 	for ( TInt i(0); i < iSessionsObjects->ActiveCount() ; i++)
       
   647 	{
       
   648 		CSubSessionObjects* objects = (CSubSessionObjects*)((*iSessionsObjects)[i]);
       
   649 		
       
   650 		if ( objects->iPolicyProcessor == iBase ||
       
   651  		 	 objects->iPolicyManager == iBase ||
       
   652 			 objects->iTrustedSession == iBase)
       
   653 		{
       
   654 			retVal = objects;
       
   655 			break;
       
   656 		}
       
   657 			
       
   658 	}
       
   659 	
       
   660 	return retVal;
       
   661 }
       
   662 
       
   663 
       
   664 	
       
   665 // ----------------------------------------------------------------------------------------
       
   666 // CPolicyEngineSession::CSubSessionObjects()
       
   667 // ----------------------------------------------------------------------------------------
       
   668 
       
   669 CSubSessionObjects* CPolicyEngineSession::SubSessionFromHandle( const RMessage2& aMessage)
       
   670 {
       
   671     //return pointer to trusted session from handle
       
   672    	CSubSessionObjects* subSession = (CSubSessionObjects*)iSessionsObjects->At(aMessage.Int3());
       
   673 	
       
   674 	if ( subSession == NULL)
       
   675 	{
       
   676 		PanicClient( aMessage, EBadSubsessionHandle); 
       
   677 	}
       
   678 	
       
   679 	CPolicyEngineServer::iServer->iSubSessionObjects = subSession;
       
   680 	
       
   681 	return subSession;
       
   682 }
       
   683 
       
   684 // ----------------------------------------------------------------------------------------
       
   685 // CPolicyEngineSession::NewSubSessionL()
       
   686 // ----------------------------------------------------------------------------------------
       
   687 
       
   688 void CPolicyEngineSession::NewSubSessionL( const RMessage2& aMessage)
       
   689 	{
       
   690 	//add new session objects object into container and object index
       
   691 	CPolicyProcessor * policyProcessor = CPolicyProcessor::NewL(); 
       
   692 	CTrustedSession * trustedSession = CTrustedSession::NewL();
       
   693 	trustedSession->AddSessionSIDL( aMessage.SecureId());
       
   694 	policyProcessor->SetSessionTrust( trustedSession);
       
   695 	CPolicyManager * policyManager = NULL;
       
   696 	
       
   697  	if ( aMessage.Function() == ECreateManagementSubSession)
       
   698  	{
       
   699  		policyManager = CPolicyManager::NewL( policyProcessor);
       
   700  	}	
       
   701 	
       
   702 	//Create new subsession object for subsession
       
   703 	CSubSessionObjects * subSessionObjects = CSubSessionObjects::NewL( policyProcessor, policyManager, trustedSession); 
       
   704 
       
   705 	iContainer->AddL( subSessionObjects);
       
   706 	TInt handle = iSessionsObjects->AddL( subSessionObjects);
       
   707 
       
   708 	//transmit handle to client 
       
   709 	TPckg<TInt> handlePckg(handle);
       
   710 	TRAPD( r, aMessage.WriteL(3, handlePckg))
       
   711 
       
   712 	if ( r != KErrNone)
       
   713 	{
       
   714 		iSessionsObjects->Remove(handle);
       
   715 		PanicClient( aMessage, EBadDescriptor);
       
   716 		return;
       
   717 	}
       
   718 		
       
   719 	iSubsessionCount++;	
       
   720 	}
       
   721 	
       
   722 // ----------------------------------------------------------------------------------------
       
   723 // CPolicyEngineSession::DeleteSubSession()
       
   724 // ----------------------------------------------------------------------------------------
       
   725 	
       
   726 void CPolicyEngineSession::DeleteSubSession( const RMessage2& aMessage)
       
   727 {
       
   728 	// panic if bad handle
       
   729 	CSubSessionObjects* subSessionObjects = (CSubSessionObjects*)iSessionsObjects->At(aMessage.Int3());
       
   730 	
       
   731 	if ( subSessionObjects == NULL)
       
   732 	{
       
   733 		PanicClient( aMessage, EBadSubsessionHandle); 
       
   734 	}
       
   735 	
       
   736 	iSessionsObjects->Remove(aMessage.Int3());	
       
   737 	iSubsessionCount--;
       
   738 }
       
   739 
       
   740 // ----------------------------------------------------------------------------------------
       
   741 // CPolicyEngineSession::ServiceError()
       
   742 // ----------------------------------------------------------------------------------------
       
   743 
       
   744 void CPolicyEngineSession::ServiceError(const RMessage2& aMessage,TInt aError)
       
   745 {
       
   746 	// Handle an error from CPolicyEngineSession::ServiceL()
       
   747 	RDEBUG_2("CPolicyEngineSession::ServiceError %d",aError);
       
   748 
       
   749 	CSession2::ServiceError(aMessage,aError);
       
   750 }
       
   751 
       
   752 
       
   753 // ----------------------------------------------------------------------------------------
       
   754 // CSubSessionObjects::CSubSessionObjects()
       
   755 // ----------------------------------------------------------------------------------------
       
   756 
       
   757 CSubSessionObjects::CSubSessionObjects( CPolicyProcessor * aPolicyProcessor, 
       
   758 															  CPolicyManager * aPolicyManager,
       
   759 										  					  CTrustedSession * aTrustedSession)
       
   760 	: iPolicyProcessor( aPolicyProcessor), iPolicyManager( aPolicyManager), iTrustedSession( aTrustedSession)
       
   761 {
       
   762 	
       
   763 }
       
   764 
       
   765 
       
   766 // ----------------------------------------------------------------------------------------
       
   767 // CSubSessionObjects::NewL()
       
   768 // ----------------------------------------------------------------------------------------
       
   769 
       
   770 CSubSessionObjects * CSubSessionObjects::NewL( CPolicyProcessor * aPolicyProcessor, 
       
   771 			      			  						        CPolicyManager * aPolicyManager,
       
   772 					  						   				CTrustedSession * aTrustedSession)
       
   773 {
       
   774 	return new (ELeave) CSubSessionObjects( aPolicyProcessor, aPolicyManager, aTrustedSession);
       
   775 }
       
   776 
       
   777 // ----------------------------------------------------------------------------------------
       
   778 // CSubSessionObjects::~CSubSessionObjects()
       
   779 // ----------------------------------------------------------------------------------------
       
   780 
       
   781 CSubSessionObjects::~CSubSessionObjects()
       
   782 {
       
   783 	delete iPolicyProcessor;
       
   784 	delete iPolicyManager;
       
   785 	delete iTrustedSession;
       
   786 }
       
   787 
       
   788 
       
   789 // ----------------------------------------------------------------------------------------
       
   790 // CSubSessionObjects::~CSubSessionObjects()
       
   791 // ----------------------------------------------------------------------------------------
       
   792 
       
   793 CASyncHandler::CASyncHandler()
       
   794 	: CActive( EPriorityStandard)
       
   795 {
       
   796 	RDEBUG("PolicyEngineServer: CASyncHandler constructor( EPriorityStandard) ");
       
   797 }
       
   798 
       
   799 CASyncHandler::~CASyncHandler()
       
   800 {
       
   801 	CPolicyEngineServer::RemoveActiveObject( this);	
       
   802 }
       
   803 
       
   804 
       
   805 CASyncHandler* CASyncHandler::NewLC()
       
   806 {
       
   807 	CASyncHandler* self = new (ELeave) CASyncHandler();	
       
   808 	CleanupStack::PushL( self);
       
   809 
       
   810 	RDEBUG("PolicyEngineServer: CASyncHandler created");
       
   811 	CPolicyEngineServer::AddActiveObjectL( self);
       
   812 	
       
   813 	return self;
       
   814 }
       
   815 
       
   816 
       
   817 TRequestStatus& CASyncHandler::GetRequestStatus()
       
   818 {
       
   819 	RDEBUG("PolicyEngineServer: CASyncHandler::GetRequestStatus()");
       
   820 	return iStatus;
       
   821 }
       
   822 
       
   823 void CASyncHandler::WaitForRequest()
       
   824 {
       
   825 	RDEBUG("PolicyEngineServer: CASyncHandler::WaitForRequest()");
       
   826 
       
   827 	CActiveScheduler::Add( this);
       
   828 	SetActive();	
       
   829 	
       
   830 	RDEBUG("PolicyEngineServer: CASyncHandler - WaitScheduler start");
       
   831 	iWaitScheduler.Start();
       
   832 	RDEBUG("PolicyEngineServer: CASyncHandler - WaitScheduler stopped");
       
   833 }
       
   834 
       
   835 
       
   836 void CASyncHandler::RunL()
       
   837 {
       
   838 	RDEBUG("PolicyEngineServer: CASyncHandler::RunL - Stop WaitScheduler!");
       
   839 	iWaitScheduler.AsyncStop();
       
   840 }
       
   841 
       
   842 void CASyncHandler::DoCancel()
       
   843 {
       
   844 	RDEBUG("PolicyEngineServer: CASyncHandler::DoCancel()");
       
   845 	iWaitScheduler.AsyncStop();
       
   846 }
       
   847 
       
   848