rtsecuritymanager/rtsecuritymanagerclient/src/rtsecmgrscriptsession.cpp
changeset 18 a7062f7f0b79
parent 0 99ef825efeca
child 27 bcef26ca2be3
equal deleted inserted replaced
15:947415ec7603 18:a7062f7f0b79
    38 #include <rtsecmgrscriptsession.h>
    38 #include <rtsecmgrscriptsession.h>
    39 #include <rtsecmgrscript.h>
    39 #include <rtsecmgrscript.h>
    40 #include "rtsecmgrclient.h"
    40 #include "rtsecmgrclient.h"
    41 #include "rtsecmgrdef.h"
    41 #include "rtsecmgrdef.h"
    42 
    42 
       
    43 #define FIRST_RESOURCE_ID(x) ((x)+2);
       
    44 
    43 //security manager resource file literal
    45 //security manager resource file literal
    44 _LIT(KSecMgrResourceFile, "RTSecManager.RSC");
    46 _LIT(KSecMgrResourceFile, "RTSecManager.RSC");
    45 
    47 
    46 //constant for descriptor array granularity
    48 //constant for descriptor array granularity
    47 const TInt KDescArrayInit = 6;
    49 const TInt KDescArrayInit = 6;
    48 const TInt KMaxBuf=256;
    50 const TInt KMaxBuf=255;
       
    51 
    49 
    52 
    50 //typedef of selection index array
    53 //typedef of selection index array
    51 typedef RArray<TInt> RSelIdxArray;
    54 typedef RArray<TInt> RSelIdxArray;
    52 
    55 
    53 //static resource IDs for capability text display in default prompt
    56 //static resource IDs for capability text display in default prompt
   157 // ---------------------------------------------------------------------------
   160 // ---------------------------------------------------------------------------
   158 // Defintiion of default private constructor
   161 // Defintiion of default private constructor
   159 // ---------------------------------------------------------------------------
   162 // ---------------------------------------------------------------------------
   160 //
   163 //
   161 CRTSecMgrScriptSession::CRTSecMgrScriptSession(MSecMgrPromptHandler* aPromptHdlr) :
   164 CRTSecMgrScriptSession::CRTSecMgrScriptSession(MSecMgrPromptHandler* aPromptHdlr) :
   162 	iPermBits(KDefaultNullBit), iDeniedBits(KDefaultNullBit),
   165 				iPromptHdlr(aPromptHdlr), iUIPromptOption(RTPROMPTUI_DEFAULT), isCustomPrompt(EFalse)
   163 			iPromptHdlr(aPromptHdlr), iUIPromptOption(RTPROMPTUI_DEFAULT), isCustomPrompt(EFalse)
   166 	{
   164 	{
   167 	iSessionData = NULL;
   165 	_sessionInfo.AllowedCaps = KDefaultNullBit;
   168 	}
   166 	_sessionInfo.DeniedCaps = KDefaultNullBit;
       
   167 }
       
   168 
   169 
   169 // ---------------------------------------------------------------------------
   170 // ---------------------------------------------------------------------------
   170 // Defintiion of second-phase constructor
   171 // Defintiion of second-phase constructor
   171 // ---------------------------------------------------------------------------
   172 // ---------------------------------------------------------------------------
   172 //
   173 //
   208 	if ( !iPromptHdlr)
   209 	if ( !iPromptHdlr)
   209 	    {
   210 	    {
   210 	    iPromptHdlr = this; //default prompt handler	
   211 	    iPromptHdlr = this; //default prompt handler	
   211 	    isCustomPrompt = ETrue ;
   212 	    isCustomPrompt = ETrue ;
   212 	    }
   213 	    }
   213 				
   214 	_permanentInfo = new(ELeave) TPermanentInfo;			
   214 
   215 	_sessionData.sessionInfo = new(ELeave) TSessionInfo;
   215 	}
   216 	_sessionData.sessionInfo->AllowedCaps = KDefaultNullBit;
   216 
   217     _sessionData.sessionInfo->DeniedCaps = KDefaultNullBit;
       
   218     _sessionData.sessionInfo->AllowedProviders.Reset();
       
   219     _sessionData.sessionInfo->DeniedProviders.Reset();
       
   220     _permanentInfo->iAllowedBits = KDefaultNullBit;
       
   221     _permanentInfo->iDeniedBits = KDefaultNullBit;
       
   222     _permanentInfo->iAllowedProviders.Reset();
       
   223     _permanentInfo->iDeniedProviders.Reset();
       
   224     iResourceOffsetArray.Reset();
       
   225 	}
       
   226 
       
   227 //---------------------------------------------------------------------------------
       
   228 //Method to add the resource files to CONE environment.
       
   229 //---------------------------------------------------------------------------------
   217 void CRTSecMgrScriptSession::AddResourceFiles()
   230 void CRTSecMgrScriptSession::AddResourceFiles()
   218     {
   231     {
   219         if(iCoeEnv)
   232         if(iCoeEnv)
   220         {
   233         {            
   221             
       
   222         CDesCArray* diskList = new (ELeave) CDesCArrayFlat(KDescArrayInit);
   234         CDesCArray* diskList = new (ELeave) CDesCArrayFlat(KDescArrayInit);
   223         CleanupStack::PushL (diskList);
   235         CleanupStack::PushL (diskList);
   224 
   236 
   225         BaflUtils::GetDiskListL (iCoeEnv->FsSession (), *diskList);
   237         BaflUtils::GetDiskListL (iCoeEnv->FsSession (), *diskList);
   226         for (TInt idx(0); idx<diskList->Count ();++idx)
   238         for (TInt idx(0); idx<diskList->Count ();++idx)
   234             resFile.Append (KDC_APP_RESOURCE_DIR);
   246             resFile.Append (KDC_APP_RESOURCE_DIR);
   235             resFile.Append (KSecMgrResourceFile);
   247             resFile.Append (KSecMgrResourceFile);
   236             BaflUtils::NearestLanguageFile (iCoeEnv->FsSession (), resFile);
   248             BaflUtils::NearestLanguageFile (iCoeEnv->FsSession (), resFile);
   237             if ( BaflUtils::FileExists (iCoeEnv->FsSession (), resFile))
   249             if ( BaflUtils::FileExists (iCoeEnv->FsSession (), resFile))
   238                 {
   250                 {
   239                 TRAPD (err, iResourceOffset = iCoeEnv->AddResourceFileL (resFile));
   251                 TRAPD (err, iResourceOffsetArray.Append(iCoeEnv->AddResourceFileL (resFile)));
   240                 User::LeaveIfError (err);
   252                 User::LeaveIfError (err);
   241                 break;
   253                 break;
   242                 }
   254                 }
   243             }
   255             }
   244 
       
   245         CleanupStack::PopAndDestroy (diskList);
   256         CleanupStack::PopAndDestroy (diskList);
   246         }        
   257         }        
   247     }
   258     }
   248 
   259 
       
   260 //---------------------------------------------------------------------------------------
       
   261 //Method to add provider resource files into the CONE environment
       
   262 //Returns the first resource identifier which has the prompt string
       
   263 //---------------------------------------------------------------------------------------
       
   264 TInt CRTSecMgrScriptSession::AddProviderResourceFile(TFileName aResourceFileName)
       
   265     {
       
   266     RResourceFile resFile;
       
   267     TInt resID(KErrNone);
       
   268     if(iCoeEnv)
       
   269         {            
       
   270         CDesCArray* diskList = new (ELeave) CDesCArrayFlat(KDescArrayInit);
       
   271         CleanupStack::PushL (diskList);
       
   272                     
       
   273         BaflUtils::GetDiskListL (iCoeEnv->FsSession (), *diskList);
       
   274         for (TInt idx(0); idx<diskList->Count ();++idx)
       
   275             {
       
   276             TInt intDrive;
       
   277             TChar ch = ((*diskList)[idx])[0];
       
   278             RFs::CharToDrive (ch, intDrive);
       
   279             TDriveUnit curDrive(intDrive);
       
   280 
       
   281             TFileName resFileName(curDrive.Name ());
       
   282             resFileName.Append (KDC_APP_RESOURCE_DIR);
       
   283             resFileName.Append (aResourceFileName);
       
   284             BaflUtils::NearestLanguageFile (iCoeEnv->FsSession (), resFileName);
       
   285             if ( BaflUtils::FileExists (iCoeEnv->FsSession (), resFileName))
       
   286                 {
       
   287                 TRAPD(err,resFile.OpenL(iCoeEnv->FsSession(),resFileName));
       
   288                 if(err == KErrNone)
       
   289                     {
       
   290                     resFile.ConfirmSignatureL(0);
       
   291                     resID = FIRST_RESOURCE_ID(resFile.Offset());
       
   292                     resFile.Close();
       
   293                     iResourceOffsetArray.Append(iCoeEnv->AddResourceFileL (resFileName));
       
   294                     break;
       
   295                     }
       
   296                 }
       
   297             }
       
   298         CleanupStack::PopAndDestroy(diskList);
       
   299         }
       
   300     return resID;
       
   301     }
       
   302 
       
   303 //--------------------------------------------------------------------------------------------
       
   304 //Close the resource files previously added 
       
   305 //--------------------------------------------------------------------------------------------
   249 void CRTSecMgrScriptSession::CloseResourceFiles()
   306 void CRTSecMgrScriptSession::CloseResourceFiles()
   250     {
   307     {
   251     if ( iResourceOffset && iCoeEnv)
   308     if (iCoeEnv)
   252             iCoeEnv->DeleteResourceFile (iResourceOffset);
   309         {
   253 	iResourceOffset = 0;
   310         for(TInt i(0); i < iResourceOffsetArray.Count(); i++)
       
   311             iCoeEnv->DeleteResourceFile (iResourceOffsetArray[i]);
       
   312         iResourceOffsetArray.Reset();
       
   313         }
   254     }
   314     }
   255 // ---------------------------------------------------------------------------
   315 // ---------------------------------------------------------------------------
   256 // Destructor
   316 // Destructor
   257 // Closes script sub-session handle
   317 // Closes script sub-session handle
   258 // ---------------------------------------------------------------------------
   318 // ---------------------------------------------------------------------------
   259 //
   319 //
   260 EXPORT_C CRTSecMgrScriptSession::~CRTSecMgrScriptSession()
   320 EXPORT_C CRTSecMgrScriptSession::~CRTSecMgrScriptSession()
   261 	{
   321 	{
       
   322 	_permanentInfo->iAllowedProviders.Close();
       
   323 	_permanentInfo->iDeniedProviders.Close();
       
   324 	_sessionData.sessionInfo->AllowedProviders.Close();
       
   325 	_sessionData.sessionInfo->DeniedProviders.Close();
       
   326 	delete _permanentInfo;
       
   327 	delete _sessionData.sessionInfo;
       
   328 	if(iSessionData)
       
   329 	    {
       
   330 	    delete iSessionData;
       
   331 	    iSessionData = NULL;
       
   332 	    }
   262 	Close ();
   333 	Close ();
   263 	}
   334 	}
   264 
   335 
   265 // ---------------------------------------------------------------------------
   336 // ---------------------------------------------------------------------------
   266 // Opens script session, in turn opening client-side sub-session handle
   337 // Opens script session, in turn opening client-side sub-session handle
   277 	
   348 	
   278 	iScript = CScript::NewL (aPolicyID, aExecID);
   349 	iScript = CScript::NewL (aPolicyID, aExecID);
   279 
   350 
   280 	TInt ret((*iSubSessionProxy)->Open (aParentSession, *iScript, aPolicyID));
   351 	TInt ret((*iSubSessionProxy)->Open (aParentSession, *iScript, aPolicyID));
   281 	if ( KErrNone==ret)
   352 	if ( KErrNone==ret)
   282 		{
   353 	    {
   283 		iPermBits = iScript->PermGranted ();
   354         _permanentInfo->iAllowedBits = iScript->PermGranted ();
   284 		iDeniedBits = iScript->PermDenied ();
   355         _permanentInfo->iDeniedBits = iScript->PermDenied ();
   285 		}
   356         iScript->PermGranted(_permanentInfo->iAllowedProviders);
       
   357         iScript->PermDenied(_permanentInfo->iDeniedProviders);		    
       
   358 	    }
   286 
   359 
   287 	return ret;
   360 	return ret;
   288 	}
   361 	}
   289 
   362 
   290 // ---------------------------------------------------------------------------
   363 // ---------------------------------------------------------------------------
   302 	
   375 	
   303 	iScript = CScript::NewL (aPolicyID, aExecID);
   376 	iScript = CScript::NewL (aPolicyID, aExecID);
   304 	TInt ret((*iSubSessionProxy)->Open (aParentSession, *iScript, aPolicyID, aHashValue));
   377 	TInt ret((*iSubSessionProxy)->Open (aParentSession, *iScript, aPolicyID, aHashValue));
   305 	if ( KErrNone==ret)
   378 	if ( KErrNone==ret)
   306 		{
   379 		{
   307 		iPermBits = iScript->PermGranted ();
   380         _permanentInfo->iAllowedBits = iScript->PermGranted ();
   308 		iDeniedBits = iScript->PermDenied ();
   381         _permanentInfo->iDeniedBits = iScript->PermDenied ();
       
   382         iScript->PermGranted(_permanentInfo->iAllowedProviders);
       
   383         iScript->PermDenied(_permanentInfo->iDeniedProviders);            
   309 		}
   384 		}
   310 
   385 
   311 	return ret;
   386 	return ret;
   312 	}
   387 	}
   313 
   388 
   326 	
   401 	
   327 	iScript = CScript::NewL (aPolicyID, aExecID);
   402 	iScript = CScript::NewL (aPolicyID, aExecID);
   328 	TInt ret((*iSubSessionProxy)->Open (aParentSession, *iScript, aPolicyID, aTrustInfo));
   403 	TInt ret((*iSubSessionProxy)->Open (aParentSession, *iScript, aPolicyID, aTrustInfo));
   329 
   404 
   330 	if ( KErrNone==ret)
   405 	if ( KErrNone==ret)
   331 		{
   406 		{		
   332 		iPermBits = iScript->PermGranted ();
   407         _permanentInfo->iAllowedBits = iScript->PermGranted ();
   333 		iDeniedBits = iScript->PermDenied ();
   408         _permanentInfo->iDeniedBits = iScript->PermDenied ();    
       
   409         iScript->PermGranted(_permanentInfo->iAllowedProviders);
       
   410         iScript->PermDenied(_permanentInfo->iDeniedProviders);            
   334 		}
   411 		}
   335 
   412 
   336 	return ret;
   413 	return ret;
   337 	}
   414 	}
   338 
   415 
   389 		AddCapability (capToCheck, aCapabilitiesToCheck[i]);
   466 		AddCapability (capToCheck, aCapabilitiesToCheck[i]);
   390 
   467 
   391 	capToCheck &= ~(iScript->PermissionSet().UnconditionalCaps());
   468 	capToCheck &= ~(iScript->PermissionSet().UnconditionalCaps());
   392 	
   469 	
   393 	/* Check if a;ready denied. No point in going forward */
   470 	/* Check if a;ready denied. No point in going forward */
   394 	if(capToCheck & _sessionInfo.DeniedCaps || capToCheck & iDeniedBits)
   471 	if(capToCheck & _sessionData.sessionInfo->DeniedCaps || capToCheck & _permanentInfo->iDeniedBits)
   395 	        return EAccessNok;
   472 	        return EAccessNok;
   396 	
   473 	
   397 	TCapabilityBitSet allowedCaps(KDefaultNullBit);
   474 	TCapabilityBitSet allowedCaps(KDefaultNullBit);
   398 	allowedCaps |= _sessionInfo.AllowedCaps; //for session allowed
   475 	allowedCaps |= _sessionData.sessionInfo->AllowedCaps; //for session allowed
   399 	allowedCaps &= ~iDeniedBits;
   476 	allowedCaps &= ~_permanentInfo->iDeniedBits;
   400 	allowedCaps |= iPermBits; //for permanently allowed
   477 	allowedCaps |= _permanentInfo->iAllowedBits; //for permanently allowed
   401 	
   478 	
   402 	//In case if all the capabilities required by the service provider
   479 	//In case if all the capabilities required by the service provider
   403 	//are allowed without prompting
   480 	//are allowed without prompting
   404 	TCapabilityBitSet original_capToCheck = capToCheck;
   481 	TCapabilityBitSet original_capToCheck = capToCheck;
   405 	capToCheck &= allowedCaps;
   482 	capToCheck &= allowedCaps;
   426 			tempCapToCheck |= LOWBIT << cap;
   503 			tempCapToCheck |= LOWBIT << cap;
   427 			}
   504 			}
   428 		capToCheck &= tempCapToCheck;
   505 		capToCheck &= tempCapToCheck;
   429 		if ( capToCheck )
   506 		if ( capToCheck )
   430 			{
   507 			{
   431 			if ( capToCheck & iDeniedBits) //check if permanently disabled
   508 			if ( capToCheck & _permanentInfo->iDeniedBits) //check if permanently disabled
   432 				{
   509 				{
   433 				allowedCaps &= ~tempCapToCheck; //just in case...
   510 				allowedCaps &= ~tempCapToCheck; //just in case...
   434 				_sessionInfo.DeniedCaps &= ~tempCapToCheck; //just in case...
   511 				_sessionData.sessionInfo->DeniedCaps &= ~tempCapToCheck; //just in case...
   435 				}
   512 				}
   436 			else
   513 			else
   437 				if ( capToCheck & _sessionInfo.DeniedCaps) //not necessary to do this check...
   514 				if ( capToCheck & _sessionData.sessionInfo->DeniedCaps) //not necessary to do this check...
   438 					{
   515 					{
   439 					allowedCaps &= ~tempCapToCheck; //just in case...	
   516 					allowedCaps &= ~tempCapToCheck; //just in case...	
   440 					}
   517 					}
   441 				else
   518 				else
   442 					if ((capToCheck & allowedCaps) != capToCheck) //check if it's already allowed
   519 					if ((capToCheck & allowedCaps) != capToCheck) //check if it's already allowed
   447 						temp ^= capToCheck;
   524 						temp ^= capToCheck;
   448 						capToCheck = temp;
   525 						capToCheck = temp;
   449 						if ( (perm->Condition() & RTUserPrompt_OneShot) ||(perm->Condition() & RTUserPrompt_Session) ||((perm->Condition() & RTUserPrompt_Permanent) &&
   526 						if ( (perm->Condition() & RTUserPrompt_OneShot) ||(perm->Condition() & RTUserPrompt_Session) ||((perm->Condition() & RTUserPrompt_Permanent) &&
   450 								(iScript->ScriptID()!=KAnonymousScript)))
   527 								(iScript->ScriptID()!=KAnonymousScript)))
   451 							{
   528 							{
   452 							if ( !(_sessionInfo.AllowedCaps & capToCheck))
   529 							if ( !(_sessionData.sessionInfo->AllowedCaps & capToCheck))
   453 								{
   530 								{
   454 								//check if it's denied for this session
   531 								//check if it's denied for this session
   455 								if ( !(_sessionInfo.DeniedCaps & capToCheck))
   532 								if ( !(_sessionData.sessionInfo->DeniedCaps & capToCheck))
   456 									{
   533 									{
   457 									CPromptData* promptData = CPromptData::NewL();//should write NewL Function
   534 									CPromptData* promptData = CPromptData::NewL();//should write NewL Function
   458 									promptData->SetPermissions(*perm);
   535 									promptData->SetPermissions(*perm);
   459 									promptData->SetUserSelection(perm->Default ()) ;
   536 									promptData->SetUserSelection(perm->Default ()) ;
   460 									aPromptDataList.Append (promptData);
   537 									aPromptDataList.Append (promptData);
   500 			}
   577 			}
   501 
   578 
   502 		if ( (iScript->ScriptID()!=KAnonymousScript)&&(isPermGrantModified))
   579 		if ( (iScript->ScriptID()!=KAnonymousScript)&&(isPermGrantModified))
   503 			UpdatePermGrant ();//commit perm grant change 
   580 			UpdatePermGrant ();//commit perm grant change 
   504 
   581 
   505 		finalCaps |= iPermBits ;
   582 		finalCaps |= _permanentInfo->iAllowedBits ;
   506 		
   583 		
   507 		if((finalCaps & NetworkServices_CAP) && isCustomPrompt)
   584 		if((finalCaps & NetworkServices_CAP) && isCustomPrompt)
   508 		    PromptCostL() ;
   585 		    PromptCostL() ;
   509 		
   586 		
   510 		finalCaps |= _sessionInfo.AllowedCaps ;
   587 		finalCaps |= _sessionData.sessionInfo->AllowedCaps ;
   511 		
   588 		
   512 	
   589 	
   513 		if ( KErrNone == ((finalCaps & original_capToCheck) ^ original_capToCheck))
   590 		if ( KErrNone == ((finalCaps & original_capToCheck) ^ original_capToCheck))
   514 			return EAccessOk;
   591 			return EAccessOk;
   515 		else
   592 		else
  1097 	{
  1174 	{
  1098 	TUserPromptOption optionChosen = aPromptData->iUserSelection;
  1175 	TUserPromptOption optionChosen = aPromptData->iUserSelection;
  1099 	
  1176 	
  1100 	if ( RTUserPrompt_OneShot==optionChosen)
  1177 	if ( RTUserPrompt_OneShot==optionChosen)
  1101 		{
  1178 		{
  1102 		_sessionInfo.AllowedCaps &= ~aCapBitSet;
  1179 		_sessionData.sessionInfo->AllowedCaps &= ~aCapBitSet;
  1103 		aAllowedCaps = aCapBitSet;
  1180 		aAllowedCaps = aCapBitSet;
  1104 		}
  1181 		}
  1105 	else
  1182 	else
  1106 		if ( RTUserPrompt_Denied==optionChosen) //one-shot denied
  1183 		if ( RTUserPrompt_Denied==optionChosen) //one-shot denied
  1107 			{
  1184 			{
  1108 			aAllowedCaps &= ~aCapBitSet;
  1185 			aAllowedCaps &= ~aCapBitSet;
  1109 			_sessionInfo.AllowedCaps &= ~aCapBitSet; //disable in session pattern too...	
  1186 			_sessionData.sessionInfo->AllowedCaps &= ~aCapBitSet; //disable in session pattern too...	
  1110 			}
  1187 			}
  1111 		else
  1188 		else
  1112 			if ( RTUserPrompt_Session==optionChosen)
  1189 			if ( RTUserPrompt_Session==optionChosen)
  1113 				{
  1190 				{
  1114 				_sessionInfo.AllowedCaps |= aCapBitSet;//Enable in _sessionInfo.Allowed & allowed
  1191 				_sessionData.sessionInfo->AllowedCaps |= aCapBitSet;//Enable in _sessionData.Allowed & allowed
  1115 				aAllowedCaps = aCapBitSet;
  1192 				aAllowedCaps = aCapBitSet;
  1116 				}
  1193 				}
  1117 			else
  1194 			else
  1118 				if ( RTUserPrompt_SessionDenied==optionChosen) //session denied
  1195 				if ( RTUserPrompt_SessionDenied==optionChosen) //session denied
  1119 					{
  1196 					{
  1120 					aAllowedCaps &= ~aCapBitSet;
  1197 					aAllowedCaps &= ~aCapBitSet;
  1121 					_sessionInfo.AllowedCaps &= ~aCapBitSet; //disable in session pattern too...
  1198 					_sessionData.sessionInfo->AllowedCaps &= ~aCapBitSet; //disable in session pattern too...
  1122 					_sessionInfo.DeniedCaps |= aCapBitSet; //enable denied in session bit
  1199 					_sessionData.sessionInfo->DeniedCaps |= aCapBitSet; //enable denied in session bit
  1123 					}
  1200 					}
  1124 				else
  1201 				else
  1125 					if ( RTUserPrompt_Permanent==optionChosen)
  1202 					if ( RTUserPrompt_Permanent==optionChosen)
  1126 						{
  1203 						{
  1127 						aIsPermGrantModified = ETrue; //to commit the change to persistent store
  1204 						aIsPermGrantModified = ETrue; //to commit the change to persistent store
  1128 						_sessionInfo.AllowedCaps |= aCapBitSet;
  1205 						_sessionData.sessionInfo->AllowedCaps |= aCapBitSet;
  1129 						aAllowedCaps = aCapBitSet;
  1206 						aAllowedCaps = aCapBitSet;
  1130 						iPermBits |= aCapBitSet;
  1207 						_permanentInfo->iAllowedBits |= aCapBitSet;
  1131 						iDeniedBits &= ~aCapBitSet; //just in case....
  1208 						_permanentInfo->iDeniedBits &= ~aCapBitSet; //just in case....
  1132 						}
  1209 						}
  1133 					else
  1210 					else
  1134 						if ( RTUserPrompt_PermDenied==optionChosen) //permanent denied
  1211 						if ( RTUserPrompt_PermDenied==optionChosen) //permanent denied
  1135 							{
  1212 							{
  1136 							aIsPermGrantModified = ETrue;
  1213 							aIsPermGrantModified = ETrue;
  1137 							aAllowedCaps &= ~aCapBitSet;
  1214 							aAllowedCaps &= ~aCapBitSet;
  1138 							_sessionInfo.AllowedCaps &= ~aCapBitSet; //disable in session pattern too...
  1215 							_sessionData.sessionInfo->AllowedCaps &= ~aCapBitSet; //disable in session pattern too...
  1139 							_sessionInfo.DeniedCaps |= aCapBitSet; //enable denied in session bit 
  1216 							_sessionData.sessionInfo->DeniedCaps |= aCapBitSet; //enable denied in session bit 
  1140 							iPermBits &= ~aCapBitSet; //disable in perm bits
  1217 							_permanentInfo->iAllowedBits &= ~aCapBitSet; //disable in perm bits
  1141 							iDeniedBits |= aCapBitSet; //enable in perm denied bit pattern
  1218 							_permanentInfo->iDeniedBits |= aCapBitSet; //enable in perm denied bit pattern
  1142 							//Commit the change to persistent store...
  1219 							//Commit the change to persistent store...
  1143 							}
  1220 							}
  1144 	}
  1221 	}
  1145 
  1222 
  1146 // ---------------------------------------------------------------------------
  1223 // ---------------------------------------------------------------------------
  1147 // Updates blanket permission data
  1224 // Updates blanket permission data
  1148 // ---------------------------------------------------------------------------
  1225 // ---------------------------------------------------------------------------
  1149 //
  1226 //
  1150 void CRTSecMgrScriptSession::UpdatePermGrant()
  1227 void CRTSecMgrScriptSession::UpdatePermGrant()
  1151 	{
  1228 	{
  1152 	(*iSubSessionProxy)->UpdatePermGrant (iScript->ScriptID (), iPermBits,
  1229 	if(iUIPromptOption == RTPROMPTUI_PROVIDER)
  1153 			iDeniedBits);
  1230 	    (*iSubSessionProxy)->UpdatePermGrant (iScript->ScriptID (),_permanentInfo->iAllowedProviders, _permanentInfo->iDeniedProviders);
       
  1231 	else
       
  1232 	    (*iSubSessionProxy)->UpdatePermGrant (iScript->ScriptID (), _permanentInfo->iAllowedBits,_permanentInfo->iDeniedBits);
  1154 	}
  1233 	}
  1155 
  1234 
  1156 //
  1235 //
  1157 // Conversion utility to convert a single 32-bit value to the list of
  1236 // Conversion utility to convert a single 32-bit value to the list of
  1158 // capabilities (RArray<TCapability>)
  1237 // capabilities (RArray<TCapability>)
  1186  * Closes the script sub-session
  1265  * Closes the script sub-session
  1187  * 
  1266  * 
  1188  */
  1267  */
  1189 void CRTSecMgrScriptSession::Close()
  1268 void CRTSecMgrScriptSession::Close()
  1190 	{
  1269 	{
  1191 	if ( iResourceOffset && iCoeEnv)
  1270 	if (iCoeEnv)
  1192 		iCoeEnv->DeleteResourceFile (iResourceOffset);
  1271 	    for(TInt i(0); i < iResourceOffsetArray.Count(); i++)
       
  1272 	        iCoeEnv->DeleteResourceFile (iResourceOffsetArray[i]);
  1193 
  1273 
  1194 	if ( iScript)
  1274 	if ( iScript)
  1195 		{
  1275 		{
  1196 		delete iScript;
  1276 		delete iScript;
  1197 		iScript = NULL;
  1277 		iScript = NULL;
  1211 	{
  1291 	{
  1212 	TCallbackParam *cb = (TCallbackParam*)aCallbackParam;
  1292 	TCallbackParam *cb = (TCallbackParam*)aCallbackParam;
  1213 	(cb->iRTSecMgrScriptSession)->MoreInfoL(*(cb->iPromptData));
  1293 	(cb->iRTSecMgrScriptSession)->MoreInfoL(*(cb->iPromptData));
  1214 	return KErrNone;
  1294 	return KErrNone;
  1215 	}
  1295 	}
       
  1296 
       
  1297 //---------------------------------------------------------------------------------------------------
       
  1298 //Overloaded IsAllowed method for provider based prompting
       
  1299 //---------------------------------------------------------------------------------------------------
       
  1300 EXPORT_C TInt CRTSecMgrScriptSession::IsAllowed(const RCapabilityArray& aCapabilitiesToCheck,
       
  1301                                                 TProviderUid aProviderUid, 
       
  1302                                                 TFileName aResourceFileName)
       
  1303 {
       
  1304     if ( aCapabilitiesToCheck.Count () <= 0)
       
  1305         {
       
  1306         return EAccessOk; //if no capabilities are required, safely return
       
  1307         }
       
  1308     if ( aCapabilitiesToCheck.Find(ECapabilityTCB) != KErrNotFound)
       
  1309         return EAccessNok;
       
  1310         
       
  1311     if((aProviderUid.iUid <= KErrNone) || ((aResourceFileName.Compare(KNullDesC))==KErrNone))
       
  1312         return ErrInvalidParameters;    
       
  1313     
       
  1314     TInt stackResCnt(0);
       
  1315     TCapabilityBitSet capToCheck(KDefaultNullBit);
       
  1316     for (TInt i(0); i!=aCapabilitiesToCheck.Count (); ++i)
       
  1317         AddCapability (capToCheck, aCapabilitiesToCheck[i]);
       
  1318 
       
  1319     capToCheck &= ~(iScript->PermissionSet().UnconditionalCaps());
       
  1320     if (!capToCheck)
       
  1321         return EAccessOk;
       
  1322     if((_sessionData.sessionInfo->DeniedProviders.Find(aProviderUid) != KErrNotFound) || (_permanentInfo->iDeniedProviders.Find(aProviderUid) != KErrNotFound))
       
  1323         return EAccessNok;
       
  1324     
       
  1325     if((_sessionData.sessionInfo->AllowedProviders.Find(aProviderUid) != KErrNotFound)|| (_permanentInfo->iAllowedProviders.Find(aProviderUid) != KErrNotFound))
       
  1326         return EAccessOk;
       
  1327         
       
  1328     TBool isPermGrantModified(EFalse);
       
  1329     RPermissions perms = iScript->PermissionSet().Permissions();
       
  1330     TCapabilityBitSet tempCapToCheck(KDefaultNullBit);
       
  1331     
       
  1332     //All the capabilities allowed for the domain
       
  1333     for (TInt permIdx(0); permIdx!=perms.Count();++permIdx)
       
  1334         {
       
  1335         tempCapToCheck |= perms[permIdx]->PermissionData();
       
  1336         }
       
  1337     
       
  1338     //If the capabilities is allowed with prompting
       
  1339     if((tempCapToCheck & capToCheck) == capToCheck)
       
  1340         {
       
  1341         /*TODO: Changes based on the decision on what needs 
       
  1342         to be done of the default capability is different 
       
  1343         for capabilities required by the provider. Presently taking least duration*/
       
  1344         TUserPromptOption defaultOption(RTUserPrompt_OneShot);
       
  1345         for(TInt i=0; i < perms.Count(); i++)
       
  1346             {
       
  1347             if((perms[i]->Default() == RTUserPrompt_OneShot) && (perms[i]->PermissionData() & capToCheck))
       
  1348                 {
       
  1349                 defaultOption = RTUserPrompt_OneShot;
       
  1350                 break;
       
  1351                 }
       
  1352             else if((perms[i]->Default() == RTUserPrompt_Session) && (perms[i]->PermissionData() & capToCheck))
       
  1353                 {
       
  1354                 defaultOption = RTUserPrompt_Session;
       
  1355                 }
       
  1356             else if((perms[i]->Default() == RTUserPrompt_Permanent) && (perms[i]->PermissionData() & capToCheck) && (defaultOption != RTUserPrompt_Session))
       
  1357                 {
       
  1358                 defaultOption = RTUserPrompt_Permanent;
       
  1359                 }
       
  1360             }
       
  1361          //= perms[0]->Default();
       
  1362         //TUserPromptOption defaultOption(RTUserPrompt_Session);
       
  1363         AddResourceFiles();
       
  1364         TInt resID(KErrNone);
       
  1365         resID = AddProviderResourceFile(aResourceFileName);
       
  1366         
       
  1367         if(resID <= KErrNone)
       
  1368             return KErrNotFound;
       
  1369         
       
  1370         HBufC* messageBody = NULL;
       
  1371         
       
  1372         //Get the application name. If not set use the default name
       
  1373         if(iSessionData != NULL )
       
  1374             {
       
  1375             TPtr appNamePtr = iSessionData->Des();
       
  1376             messageBody = StringLoader::LoadL( resID, appNamePtr, iCoeEnv );
       
  1377             CleanupStack::PushL(messageBody);
       
  1378             ++stackResCnt;
       
  1379             }
       
  1380         else
       
  1381             {
       
  1382             HBufC* defaultName = iCoeEnv->AllocReadResourceLC(R_DEFAULT_APPLICATION_NAME);
       
  1383             TPtr defaultNamePtr = defaultName->Des();
       
  1384             messageBody = StringLoader::LoadL( resID, defaultNamePtr, iCoeEnv );
       
  1385             CleanupStack::PopAndDestroy(defaultName);
       
  1386             CleanupStack::PushL(messageBody);
       
  1387             ++stackResCnt;            
       
  1388             }
       
  1389         
       
  1390         CAknMessageQueryDialog* queryDialog = new(ELeave) CAknMessageQueryDialog();
       
  1391         CleanupStack::PushL (queryDialog);
       
  1392         ++stackResCnt;
       
  1393     
       
  1394         queryDialog->PrepareLC (R_ADVPROMPT_MESSAGE_QUERY);
       
  1395         
       
  1396         queryDialog->SetMessageTextL(messageBody->Des());
       
  1397         
       
  1398         HBufC* headerText(NULL);
       
  1399         CAknPopupHeadingPane* heading = queryDialog->QueryHeading ();
       
  1400         if ( heading)
       
  1401             {
       
  1402             heading->SetLayout (CAknPopupHeadingPane::EMessageQueryHeadingPane);
       
  1403             headerText = iCoeEnv->AllocReadResourceLC (R_RTSECMGR_PROMPT_QUERY_HEADER);
       
  1404             heading->SetTextL (headerText->Des ());
       
  1405             ++stackResCnt;
       
  1406             }
       
  1407         
       
  1408         TInt ret(EAccessNok);
       
  1409         TBool costPromptRequired(EFalse);
       
  1410         CleanupStack::Pop (stackResCnt);
       
  1411         TInt queryOk = queryDialog->RunLD ();
       
  1412         if ( queryOk == EAknSoftkeyYes)
       
  1413             {
       
  1414             
       
  1415             if ( defaultOption & RTUserPrompt_OneShot)
       
  1416                 {
       
  1417                 ret = EAccessOk;
       
  1418                 }
       
  1419             else if ( defaultOption& RTUserPrompt_Session)
       
  1420                 {
       
  1421                 _sessionData.sessionInfo->AllowedProviders.Append(aProviderUid); //session allow 
       
  1422                 ret = EAccessOk;
       
  1423                 }
       
  1424             else if ( defaultOption& RTUserPrompt_Permanent)
       
  1425                 {
       
  1426                 _sessionData.sessionInfo->AllowedProviders.Append(aProviderUid); //session allow
       
  1427                 _permanentInfo->iAllowedProviders.Append(aProviderUid);          //permanent allow
       
  1428                 isPermGrantModified = ETrue;                                     //Flag for server update 
       
  1429                 ret = EAccessOk;
       
  1430                 }
       
  1431             else
       
  1432                 {
       
  1433                 ret = EAccessNok;
       
  1434                 }
       
  1435             }
       
  1436         else
       
  1437             {
       
  1438             if ( defaultOption & RTUserPrompt_OneShot)
       
  1439                 {
       
  1440                 ret = EAccessNok;
       
  1441                 }
       
  1442             else if ( defaultOption& RTUserPrompt_Session)
       
  1443                 {
       
  1444                 _sessionData.sessionInfo->DeniedProviders.Append(aProviderUid);  //session deny
       
  1445                 ret = EAccessNok;
       
  1446                 }
       
  1447             else if ( defaultOption& RTUserPrompt_Permanent)
       
  1448                 {
       
  1449                 _sessionData.sessionInfo->DeniedProviders.Append(aProviderUid);  //session deny                         
       
  1450                 _permanentInfo->iDeniedProviders.Append(aProviderUid);           //permanent deny
       
  1451                 isPermGrantModified = ETrue;                                     //Flag for server update 
       
  1452                 ret = EAccessNok;
       
  1453                 }            
       
  1454             }
       
  1455         CloseResourceFiles();
       
  1456         
       
  1457         /* If its a pre-registered script and perm grant is modified update server */
       
  1458         if(isPermGrantModified && (iScript->ScriptID() != KAnonymousScript))
       
  1459             UpdatePermGrant();          
       
  1460         
       
  1461         if(messageBody)
       
  1462             delete messageBody;
       
  1463         
       
  1464         if(headerText)
       
  1465             delete headerText;
       
  1466         
       
  1467         return ret;
       
  1468         }
       
  1469     return EAccessNok;
       
  1470     }
       
  1471 
       
  1472 //---------------------------------------------------------------------------------------------
       
  1473 //Method to set the application name. 
       
  1474 //Called by the runtimes to set the name of the widget/flash content
       
  1475 //---------------------------------------------------------------------------------------------
       
  1476 EXPORT_C void CRTSecMgrScriptSession::SetApplicationNameL(const TDesC& aName)
       
  1477         {
       
  1478         if(iSessionData)
       
  1479             {
       
  1480             delete iSessionData;
       
  1481             iSessionData = NULL;
       
  1482             }
       
  1483         /* Limit on the length of the application name */
       
  1484         /*if(aName.Length() > KMaxAppName)
       
  1485             User::Leave(KErrOverflow);*/
       
  1486         iSessionData = aName.AllocL();
       
  1487         }