rtsecuritymanager/rtsecuritymanagerclient/src/rtsecmgrclient.cpp
changeset 57 61b27eec6533
parent 45 7aa6007702af
equal deleted inserted replaced
45:7aa6007702af 57:61b27eec6533
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:       Defines security manager client side session and sub-session classes
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 #include <coemain.h>
       
    25 #include <bautils.h>
       
    26 #include <s32file.h>
       
    27 #include <eikenv.h>
       
    28 #include <rtsecmgrscript.h>
       
    29 #include "rtsecmgrmsg.h"
       
    30 #include "rtsecmgrdef.h"
       
    31 #include "rtsecmgrclient.h"
       
    32 #include "rtsecmgrtracer.h"
       
    33 
       
    34 #ifdef _DEBUG
       
    35 _LIT(KServerStartFailed, "Security manager server starting failed");
       
    36 #endif
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // Defintiion of default private constructor
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 RSecMgrSession::RSecMgrSession()
       
    43 	{	
       
    44 	}
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // Connects to the runtime security manager server
       
    48 //
       
    49 // This function attemtps to kick start security manager server if
       
    50 // it is not running already. The number of attempts is currently 2.
       
    51 // The number of message slot is defaulted to 4.
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 /*TInt RSecMgrSession::Connect()
       
    55 	{
       
    56 	RTSecMgrTraceFunction("RSecMgrSession::Connect()") ;
       
    57 	TInt retry(KSecSrvClientTryCount); // Try this twice
       
    58 	TInt err(KErrNone);
       
    59 	while (retry>KErrNone)
       
    60 		{
       
    61 		// Try to create a Server session
       
    62 		err = CreateSession ( KSecServerProcessName, Version (),
       
    63 				KDefaultMessageSlots);
       
    64 
       
    65 		if ( err != KErrNotFound && err != KErrServerTerminated)
       
    66 			{
       
    67 			// KErrNone or unrecoverable error
       
    68 			if ( err != KErrNone)
       
    69 				{
       
    70 #ifdef _DEBUG
       
    71 				RDebug::Print(KServerStartFailed);
       
    72 #endif
       
    73 				}
       
    74 			retry = 0;
       
    75 			}
       
    76 		else
       
    77 			{
       
    78 			// Return code was KErrNotFound or KErrServerTerminated.
       
    79 			// Try to start a new security manager server instance
       
    80 			err = StartSecManagerServer ();
       
    81 			if ( err != KErrNone && err != KErrAlreadyExists)
       
    82 				{
       
    83 				// Unrecoverable error
       
    84 #ifdef _DEBUG
       
    85 				RDebug::Print(KServerStartFailed);
       
    86 #endif
       
    87 				retry = 0;
       
    88 				}
       
    89 			}
       
    90 
       
    91 		retry--;
       
    92 		}
       
    93 	return (err);
       
    94 	}*/
       
    95 
       
    96 TInt RSecMgrSession::Connect()
       
    97     {
       
    98     RTSecMgrTraceFunction("RSecMgrSession::Connect()") ;
       
    99     TInt err(KErrNone);
       
   100         // Try to create a Server session
       
   101     err = CreateSession ( KSecServerProcessName, Version (),
       
   102             KDefaultMessageSlots);
       
   103 
       
   104     if ( err != KErrNotFound && err != KErrServerTerminated)
       
   105         {
       
   106         // KErrNone or unrecoverable error
       
   107         if ( err != KErrNone)
       
   108             {
       
   109 #ifdef _DEBUG
       
   110             RDebug::Print(KServerStartFailed);
       
   111 #endif
       
   112             }
       
   113         
       
   114         }
       
   115     else
       
   116         {
       
   117         // Return code was KErrNotFound or KErrServerTerminated.
       
   118         // Try to start a new security manager server instance
       
   119         TInt retry(KSecSrvClientTryCount);
       
   120         while(retry > 0)
       
   121             {
       
   122             err = StartSecManagerServer ();
       
   123             if ( err != KErrNone && err != KErrAlreadyExists)
       
   124                 {
       
   125                 // Unrecoverable error
       
   126                 #ifdef _DEBUG
       
   127                             RDebug::Print(KServerStartFailed);
       
   128                 #endif
       
   129                 retry = 0;
       
   130                 }
       
   131             else
       
   132                 {
       
   133                 err = CreateSession ( KSecServerProcessName, Version (),
       
   134                                                 KDefaultMessageSlots);
       
   135                 if(err != KErrNotFound && err != KErrServerTerminated)
       
   136                     {
       
   137                     if ( err != KErrNone)
       
   138                                 {
       
   139                     #ifdef _DEBUG
       
   140                                 RDebug::Print(KServerStartFailed);
       
   141                     #endif
       
   142                                 }
       
   143                     retry = 0;
       
   144                     }
       
   145                 }
       
   146             retry--;
       
   147             }
       
   148         }       
       
   149     return (err);
       
   150     }
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // Starts runtime security manager server
       
   154 //
       
   155 // ---------------------------------------------------------------------------
       
   156 //
       
   157 TInt RSecMgrSession::StartSecManagerServer() const
       
   158 	{
       
   159 	RTSecMgrTraceFunction("RSecMgrSession::StartSecManagerServer()") ;
       
   160 	RProcess server;
       
   161 	const TUidType serverUid( KNullUid, KSecMgrServerUid2, KNullUid);
       
   162 	TInt err = server.Create ( ServerLocation (), 
       
   163 			KNullDesC, 
       
   164 			serverUid, 
       
   165 			EOwnerProcess);
       
   166 
       
   167 	// Return error code if we the process couldn't be created
       
   168 	if ( KErrNone == err)
       
   169 		{
       
   170 		// Rendezvous is used to detect server start
       
   171 		TRequestStatus status;
       
   172 		server.Rendezvous ( status);
       
   173 		if ( status != KRequestPending)
       
   174 			{
       
   175 			// Log Abort Error
       
   176 #ifdef _DEBUG
       
   177 			RDebug::Print(KServerStartFailed);
       
   178 #endif			
       
   179 			server.Kill ( 0); // Abort startup
       
   180 			}
       
   181 		else
       
   182 			{
       
   183 			server.Resume (); // Logon OK - start the server
       
   184 			}
       
   185 		User::WaitForRequest (status); // Wait for start or death
       
   186 
       
   187 		if ( server.ExitType ()== EExitPanic)
       
   188 			{
       
   189 #ifdef _DEBUG
       
   190 			RDebug::Print(KServerStartFailed);
       
   191 #endif
       
   192 			err = KErrGeneral;
       
   193 			}
       
   194 		else
       
   195 			{
       
   196 			err = status.Int ();
       
   197 			}
       
   198 
       
   199 		// We can close the handle now
       
   200 		server.Close ();
       
   201 		}
       
   202 	return err;
       
   203 	}
       
   204 
       
   205 // ---------------------------------------------------------------------------
       
   206 // Returns runtime security manager server location
       
   207 //
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 TFullName RSecMgrSession::ServerLocation() const
       
   211 	{
       
   212 	TFullName fullPathAndName;
       
   213 	fullPathAndName.Append ( KSecMgrServerExeName);
       
   214 	return fullPathAndName;
       
   215 	}
       
   216 
       
   217 // ---------------------------------------------------------------------------
       
   218 // Returns the earliest version number of the security manager server
       
   219 //
       
   220 // ---------------------------------------------------------------------------
       
   221 //
       
   222 TVersion RSecMgrSession::Version(void) const
       
   223 	{
       
   224 	return (TVersion(KRTSecMgrServMajorVersionNumber,KRTSecMgrServMinorVersionNumber,KRTSecMgrServBuildVersionNumber));
       
   225 	}
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // A request to close the session.
       
   229 //
       
   230 // It makes a call to the server, which deletes the object container and object index
       
   231 // for this session, before calling Close() on the base class.
       
   232 // ---------------------------------------------------------------------------
       
   233 //
       
   234 void RSecMgrSession::Close()
       
   235 	{
       
   236 	if(iHandle)
       
   237 		{		
       
   238 		SendReceive (ESecServCloseSession);
       
   239 		RSessionBase::Close();
       
   240 		}
       
   241 	}
       
   242 
       
   243 //
       
   244 // Registers the runtime security policy with security manager. This method
       
   245 // packs the message parameters required for registering the policy. 
       
   246 // 
       
   247 // The various parameters required for SetPolicy operation are :
       
   248 // 	
       
   249 //  Operation Code  : ESetPolicy
       
   250 // 	IPC Argument[0] : Policy Identifier (as inOut parameter)
       
   251 //  IPC Argument[1] : SecurityPolicy FileHandle
       
   252 //  IPC Argument[2] : SecurityPolicy FileSession object
       
   253 //  IPC Argument[3] : none
       
   254 // 
       
   255 TInt RSecMgrSession::SetPolicy(const RFile& aSecPolicy)
       
   256 	{
       
   257 	TPckgBuf<TInt> pckgPId;
       
   258 	TIpcArgs args(&pckgPId);
       
   259 
       
   260 	TInt ret = aSecPolicy.TransferToServer (args, EMsgArgOne,
       
   261 			EMsgArgTwo);
       
   262 
       
   263 	if ( KErrNone==ret)
       
   264 		{
       
   265 		ret = SendReceive (ESetPolicy, args);
       
   266 
       
   267 		if ( KErrNone==ret)
       
   268 			return pckgPId (); // Extract the policyID returned from the server. 
       
   269 		}
       
   270 
       
   271 	return ret;
       
   272 	}
       
   273 
       
   274 TPolicyID RSecMgrSession::SetPolicy(const TDesC8& aPolicyBuffer)
       
   275 	{	
       
   276 	TInt ret(ErrInvalidParameters);
       
   277 	if(0==aPolicyBuffer.CompareC(KNullDesC8))
       
   278 		{
       
   279 		return ret;
       
   280 		}
       
   281 		
       
   282 		TFileName tempDirPath;
       
   283 		TFileName tempPath;
       
   284 	
       
   285 		{
       
   286 		RFs fileSession;
       
   287 		if ( KErrNone==fileSession.Connect ())
       
   288 			{
       
   289 			fileSession.PrivatePath (tempDirPath);
       
   290 			BaflUtils::EnsurePathExistsL (fileSession, tempDirPath);
       
   291 
       
   292 			RFile secPolicyFile;
       
   293 			secPolicyFile.Temp (fileSession, tempDirPath, tempPath, EFileWrite);
       
   294 			secPolicyFile.Write(aPolicyBuffer);
       
   295 			secPolicyFile.Close();			
       
   296 			}		
       
   297 		fileSession.Close();
       
   298 		}
       
   299 		
       
   300 	RFs fileSession;
       
   301 	if ( KErrNone==fileSession.Connect ())
       
   302 		{
       
   303 		CleanupClosePushL (fileSession);
       
   304 		if ( KErrNone==fileSession.ShareProtected ())
       
   305 			{
       
   306 			RFile secPolicyFile;
       
   307 					
       
   308 			if(KErrNone == secPolicyFile.Open(fileSession,tempPath,EFileRead))
       
   309 				{
       
   310 				ret = SetPolicy (secPolicyFile);
       
   311 			
       
   312 				secPolicyFile.Close();
       
   313 					
       
   314 				}
       
   315 			
       
   316 			fileSession.Delete (tempPath);
       
   317 			}
       
   318 		
       
   319 		CleanupStack::PopAndDestroy (&fileSession);//fileSession
       
   320 		}
       
   321 
       
   322 	fileSession.Close();
       
   323 	
       
   324 	return ret;
       
   325 	}
       
   326 
       
   327 //
       
   328 // UnRegisters a registered security policy. Runtimes should call this function
       
   329 // to de-register the already registered security policy.
       
   330 // 
       
   331 // The various parameters required for UnSetPolicy operation are :
       
   332 // 	
       
   333 // Operation Code  : EUnsetPolicy
       
   334 // IPC Argument[0] : Policy Identifier to un-register
       
   335 // IPC Argument[1] : Successcode (as inOut parameter)
       
   336 // IPC Argument[2] : none
       
   337 // IPC Argument[3] : none
       
   338 // 
       
   339 TInt RSecMgrSession::UnSetPolicy(TPolicyID aPolicyID)
       
   340 	{
       
   341 	if ( aPolicyID<=KErrNone)
       
   342 		return ErrInvalidPolicyID;
       
   343 
       
   344 	TPckgBuf<TInt> sucess(KErrNone);
       
   345 	TIpcArgs args(aPolicyID, &sucess);
       
   346 
       
   347 	TInt ret = SendReceive (EUnsetPolicy, args);
       
   348 
       
   349 	if ( KErrNone==ret)
       
   350 		return sucess (); // Extract the value returned from the server. 
       
   351 
       
   352 	return ret;
       
   353 	}
       
   354 
       
   355 //
       
   356 // Updates an already registered security policy. Runtimes should call this function
       
   357 // to update their policy.
       
   358 // 
       
   359 // The various parameters required for UpdatePolicy operation are :
       
   360 // 	
       
   361 // Operation Code  : EUpdatePolicy
       
   362 // IPC Argument[0] : Policy Identifier
       
   363 // IPC Argument[1] : SecurityPolicy FileHandle
       
   364 // IPC Argument[2] : SecurityPolicy FileSession object
       
   365 // IPC Argument[3] : none
       
   366 // 
       
   367 TPolicyID RSecMgrSession::UpdatePolicy(TPolicyID aPolicyID,
       
   368 		const RFile& aSecPolicy)
       
   369 	{
       
   370 	if ( aPolicyID<=KErrNone)
       
   371 		{
       
   372 		return ErrInvalidPolicyID;
       
   373 		}
       
   374 
       
   375 	TPckgBuf<TInt> pckgPID(aPolicyID);
       
   376 	TIpcArgs args(&pckgPID);
       
   377 
       
   378 	TInt ret = aSecPolicy.TransferToServer (args, EMsgArgOne,
       
   379 			EMsgArgTwo);
       
   380 
       
   381 	if ( KErrNone==ret)
       
   382 		{
       
   383 		ret = SendReceive (EUpdatePolicy, args);
       
   384 
       
   385 		if ( KErrNone==ret)
       
   386 			ret = pckgPID ();
       
   387 		}
       
   388 
       
   389 	return ret;
       
   390 	}
       
   391 
       
   392 TPolicyID RSecMgrSession::UpdatePolicy(TPolicyID aPolicyID,
       
   393 		const TDesC8& aPolicyBuffer)
       
   394 	{
       
   395 	TInt ret(ErrInvalidParameters);
       
   396 	if(0==aPolicyBuffer.CompareC(KNullDesC8))
       
   397 		{
       
   398 		return ret;
       
   399 		}
       
   400 		
       
   401 		TFileName tempDirPath;
       
   402 		TFileName tempPath;
       
   403 	
       
   404 		{
       
   405 		RFs fileSession;
       
   406 		if ( KErrNone==fileSession.Connect ())
       
   407 			{
       
   408 			fileSession.PrivatePath (tempDirPath);
       
   409 			BaflUtils::EnsurePathExistsL (fileSession, tempDirPath);
       
   410 
       
   411 			RFile secPolicyFile;
       
   412 			secPolicyFile.Temp (fileSession, tempDirPath, tempPath, EFileWrite);
       
   413 			secPolicyFile.Write(aPolicyBuffer);
       
   414 			secPolicyFile.Close();			
       
   415 			}		
       
   416 		fileSession.Close();
       
   417 		}
       
   418 		
       
   419 	RFs fileSession;
       
   420 	if ( KErrNone==fileSession.Connect ())
       
   421 		{
       
   422 		CleanupClosePushL (fileSession);
       
   423 		if ( KErrNone==fileSession.ShareProtected ())
       
   424 			{
       
   425 			RFile secPolicyFile;
       
   426 					
       
   427 			if(KErrNone == secPolicyFile.Open(fileSession,tempPath,EFileRead))
       
   428 				{
       
   429 				
       
   430 				ret = UpdatePolicy (aPolicyID, secPolicyFile);
       
   431 			
       
   432 				secPolicyFile.Close();
       
   433 			
       
   434 				}
       
   435 
       
   436 			fileSession.Delete (tempPath);
       
   437 			}
       
   438 		
       
   439 		CleanupStack::PopAndDestroy (&fileSession);//fileSession
       
   440 		}
       
   441 
       
   442 	fileSession.Close();
       
   443 	
       
   444 	return ret;
       
   445 	}
       
   446 
       
   447 //
       
   448 // Registers a script/executable. Runtimes should specify the trust information
       
   449 // of the script to be registered. 
       
   450 // 
       
   451 // Operation Code  : ERegisterScript
       
   452 // IPC Argument[0] : Policy Identifier
       
   453 // IPC Argument[1] : Script Identifier (as inOut Parameter)
       
   454 // IPC Argument[2] : none
       
   455 // IPC Argument[3] : none 
       
   456 // 
       
   457 TExecutableID RSecMgrSession::RegisterScript(TPolicyID aPolicyID, const CTrustInfo& /*aTrustInfo*/)
       
   458 	{
       
   459 	if ( aPolicyID<KErrNone)
       
   460 		return ErrInvalidPolicyID;
       
   461 
       
   462 	TPckgBuf<TInt> scriptID(KAnonymousScript);
       
   463 	TIpcArgs args(aPolicyID, &scriptID);
       
   464 
       
   465 	TInt result = SendReceive (ERegisterScript, args);
       
   466 
       
   467 	if ( KErrNone==result)
       
   468 		result=scriptID ();
       
   469 
       
   470 	return result;
       
   471 	}
       
   472 
       
   473 //
       
   474 // Registers a script/executable. Runtimes should specify the trust information
       
   475 // of the script to be registered. 
       
   476 // 
       
   477 // Operation Code  : ERegisterScript
       
   478 // IPC Argument[0] : Policy Identifier
       
   479 // IPC Argument[1] : Script Identifier (as inOut Parameter)
       
   480 // IPC Argument[2] : Hash value of script
       
   481 // IPC Argument[3] : none
       
   482 // 
       
   483 TExecutableID RSecMgrSession::RegisterScript(TPolicyID aPolicyID,
       
   484 		const TDesC& aHashMarker, const CTrustInfo& /*aTrustInfo*/)
       
   485 	{
       
   486 	__UHEAP_MARK;
       
   487 
       
   488 	if(!(aHashMarker.Compare(KNullDesC)))
       
   489 		return ErrInvalidParameters;
       
   490 	CRTSecMgrRegisterScriptMsg* scriptMsg = CRTSecMgrRegisterScriptMsg::NewL (
       
   491 			aPolicyID, aHashMarker);
       
   492  
       
   493 	HBufC8* dataDes(NULL);
       
   494 	TRAPD(ret, dataDes = scriptMsg->PackMsgL());
       
   495 	if ( dataDes)
       
   496 		{
       
   497 		TExecutableID scriptID(KAnonymousScript);
       
   498 		TPckgBuf<TInt> scriptIDBuf(scriptID);
       
   499 		TIpcArgs args(dataDes, &scriptIDBuf);
       
   500 		
       
   501 		ret = SendReceive (ERegisterScriptWithHash, args);
       
   502 		delete dataDes;
       
   503 		
       
   504 		if(KErrNone==ret)
       
   505 			ret = scriptIDBuf();
       
   506 		}
       
   507 
       
   508 	delete scriptMsg;
       
   509 
       
   510 	__UHEAP_MARKEND;
       
   511 
       
   512 	return ret;
       
   513 	}
       
   514 
       
   515 //
       
   516 // De-Registers a script/executable. Runtimes should pass the previously registered
       
   517 // script identifier corresponding to the script to be de-registered.
       
   518 // 
       
   519 // Operation Code  : EUnRegisterScript
       
   520 // IPC Argument[0] : Script Identifier
       
   521 // IPC Argument[1] : Policy Identifier
       
   522 // IPC Argument[2] : Success code (as inOut parameter)
       
   523 // IPC Argument[3] : none 
       
   524 //  
       
   525 TInt RSecMgrSession::UnRegisterScript(TExecutableID aExeID, TPolicyID aPolicyID)
       
   526 	{
       
   527 	if (aExeID<=KErrNone) 
       
   528 		return ErrInvalidScriptID;
       
   529 	if (aPolicyID<=KErrNone)
       
   530 		return ErrInvalidPolicyID;
       
   531 
       
   532 	TPckgBuf<TInt> errCode(KErrNone);
       
   533 	TIpcArgs args(aExeID, aPolicyID, &errCode);
       
   534 
       
   535 	TInt result = SendReceive (EUnRegisterScript, args);
       
   536 
       
   537 	if ( KErrNone==result)
       
   538 		return errCode ();
       
   539 
       
   540 	return result;
       
   541 	}
       
   542 
       
   543 RSecMgrSubSession::RSecMgrSubSession()
       
   544 	{	
       
   545 	
       
   546 	}
       
   547 //
       
   548 // Opens client-side sub-session for a registered script. The script session is modelled as a
       
   549 // client side sub-session with a peer server side sub-session.
       
   550 // 
       
   551 TInt RSecMgrSubSession::Open(const RSessionBase& aSession,
       
   552 		CScript& aScriptInfo, TPolicyID aPolicyID, const TDesC& aHashValue)
       
   553 	{
       
   554 	TIpcArgs args(aScriptInfo.ScriptID (), aPolicyID);
       
   555 
       
   556 	TInt errCode(KErrNone);
       
   557 	errCode = iFs.Connect();
       
   558 	if(errCode == KErrNone)
       
   559     	{
       
   560     	if ( KAnonymousScript==aScriptInfo.ScriptID ())
       
   561     		errCode = CreateSubSession (aSession, EGetTrustedUnRegScriptSession,
       
   562     				args);
       
   563     	else
       
   564     		errCode = CreateSubSession (aSession, EGetScriptSession, args);
       
   565     
       
   566     	if ( errCode==KErrNone)
       
   567     		{
       
   568     		// Retrieve the RFs and RFile handles from the server
       
   569     		TPckgBuf<TInt> fh; // sub-session (RFile) handle
       
   570     		TIpcArgs args(&fh);
       
   571     
       
   572     		RFile file;
       
   573     		CleanupClosePushL(file);
       
   574     
       
   575     		if ( KErrNone==errCode)
       
   576     			{
       
   577     			iFs.ShareProtected ();
       
   578     
       
   579     			TFileName tempDirPath;
       
   580     			TFileName tempPath;
       
   581     
       
   582     			iFs.PrivatePath (tempDirPath);
       
   583     			BaflUtils::EnsurePathExistsL (iFs, tempDirPath);
       
   584     
       
   585     			errCode = file.Temp (iFs, tempDirPath, tempPath, EFileWrite);
       
   586     
       
   587     			if ( KErrNone==errCode)
       
   588     				{
       
   589     				file.TransferToServer (args, EMsgArgOne, EMsgArgTwo);
       
   590     				errCode = SendReceive (EGetScriptFile, args);
       
   591     
       
   592     				if ( KErrNone==errCode)
       
   593     					{
       
   594     					RFileReadStream rfs(file);
       
   595     					CleanupClosePushL(rfs);
       
   596     					aScriptInfo.InternalizeL (rfs);
       
   597     					TBufC<KMaxPath> hashValue(aScriptInfo.Hash());
       
   598     					if(0 != hashValue.Compare(KNullDesC))
       
   599     						{
       
   600     						if(!aScriptInfo.HashMatch(aHashValue))
       
   601     							{
       
   602     							//hash check failed
       
   603     							errCode = KErrNotFound;
       
   604     							}						
       
   605     						}
       
   606     					
       
   607     					CleanupStack::PopAndDestroy(&rfs);
       
   608     					}
       
   609     				}
       
   610     			iFs.Delete (tempPath);
       
   611     			}
       
   612     
       
   613     		CleanupStack::PopAndDestroy(&file);
       
   614     		}
       
   615     	}
       
   616 	return errCode;
       
   617 	}
       
   618 
       
   619 //
       
   620 // Opens client-side sub-session for an un-registered trusted script. The script session is modelled as a
       
   621 // client side sub-session with a peer server side sub-session.
       
   622 // 
       
   623 TInt RSecMgrSubSession::Open(const RSessionBase& aSession,
       
   624 		CScript& aScriptInfo, TPolicyID aPolicyID, const CTrustInfo& /*aTrustInfo*/)
       
   625 	{	
       
   626 	return Open (aSession, aScriptInfo, aPolicyID);
       
   627 	}
       
   628 
       
   629 //
       
   630 // Updates the blanket permission data of the script
       
   631 // 
       
   632 TInt RSecMgrSubSession::UpdatePermGrant(TExecutableID aScriptID,
       
   633 		TPermGrant aPermGrant, TPermGrant aPermDenied) const
       
   634 	{
       
   635 	TIpcArgs args(aScriptID, (TInt)aPermGrant, (TInt)aPermDenied);
       
   636 	return SendReceive (EUpdatePermanentGrant, args);
       
   637 	}
       
   638 
       
   639 //
       
   640 //Updates the blanket permission data of the script
       
   641 //
       
   642 TInt RSecMgrSubSession::UpdatePermGrant(TExecutableID aScriptID,
       
   643         RProviderArray aAllowedProviders, RProviderArray aDeniedProviders) const
       
   644     {
       
   645     CRTPermGrantMessage* msg = CRTPermGrantMessage::NewL(aAllowedProviders , aDeniedProviders , aScriptID);
       
   646     HBufC8* buffer = msg->PackMessageL();
       
   647     TIpcArgs args(buffer);
       
   648     TInt ret = SendReceive (EUpdatePermanentGrantProvider, args);
       
   649     delete buffer;
       
   650     delete msg;
       
   651     return ret;
       
   652     }
       
   653 //
       
   654 // Close the subsession.
       
   655 //
       
   656 void RSecMgrSubSession::Close()
       
   657 	{
       
   658 	iFs.Close();
       
   659 	RSubSessionBase::CloseSubSession (ECloseScriptSession);
       
   660 	}
       
   661