terminalsecurity/SCP/SCPServer/src/SCPServer.cpp
branchRCL_3
changeset 25 b183ec05bd8c
parent 24 13d7c31c74e0
child 26 19bba8228ff0
equal deleted inserted replaced
24:13d7c31c74e0 25:b183ec05bd8c
    51 #include <featmgr.h>
    51 #include <featmgr.h>
    52 // For Device encryption
    52 // For Device encryption
    53 #include <DevEncEngineConstants.h>
    53 #include <DevEncEngineConstants.h>
    54 #include <DevEncSessionBase.h>
    54 #include <DevEncSessionBase.h>
    55 #include <startupdomainpskeys.h>
    55 #include <startupdomainpskeys.h>
    56 /*
       
    57 #ifdef _DEBUG
       
    58 #define __SCP_DEBUG
       
    59 #endif // _DEBUG
       
    60 
       
    61 // Define this so the precompiler in CW 3.1 won't complain about token pasting,
       
    62 // the warnings are not valid
       
    63 #pragma warn_illtokenpasting off
       
    64 
       
    65 #ifdef __SCP_DEBUG
       
    66 #define Dprint(a) RDebug::Print##a
       
    67 #else
       
    68 #define Dprint(a)
       
    69 #endif // _DEBUG*/
       
    70 
    56 
    71 // ==================== LOCAL FUNCTIONS ====================
    57 // ==================== LOCAL FUNCTIONS ====================
    72 
    58 
    73 // ---------------------------------------------------------
    59 // ---------------------------------------------------------
    74 // PanicServer Panics the server thread
    60 // PanicServer Panics the server thread
   127        
   113        
   128     iConfiguration.Initialize();
   114     iConfiguration.Initialize();
   129     
   115     
   130     // Assign default config flag
   116     // Assign default config flag
   131     iConfiguration.iConfigFlag = KSCPConfigUnknown;
   117     iConfiguration.iConfigFlag = KSCPConfigUnknown;
   132     
   118     iConfiguration.iConfigChecked = EFalse;
   133     
   119     
   134     // Assign the default codes
   120     // Assign the default codes
   135     iConfiguration.iSecCode.Zero();
   121     iConfiguration.iSecCode.Zero();
   136     iConfiguration.iSecCode.Append( KSCPDefaultSecCode );
   122     iConfiguration.iSecCode.Append( KSCPDefaultSecCode );
   137 
   123 
   167     CleanupStack::PopAndDestroy( codeHBuf );
   153     CleanupStack::PopAndDestroy( codeHBuf );
   168 }
   154 }
   169 //#endif
   155 //#endif
   170    
   156    
   171     // Assign the default max timeout
   157     // Assign the default max timeout
   172     iConfiguration.iMaxTimeout = 0;
   158     iConfiguration.iMaxTimeout = KSCPDefaultMaxTO;
   173    	iConfiguration.iBlockedInOOS = 0;
   159    	iConfiguration.iBlockedInOOS = 0;
   174    
   160    
   175     // Read the configuration, overwriting the default values
   161     // Read the configuration, overwriting the default values
   176     TInt ret = KErrNone;
   162     TInt ret = KErrNone;
   177     TRAPD( err, ret = iConfiguration.ReadSetupL() );
   163     TRAPD( err, ret = iConfiguration.ReadSetupL() );
   184         {
   170         {
   185         Dprint( (_L("CSCPServer::ConstructL(): Configration read OK") ));
   171         Dprint( (_L("CSCPServer::ConstructL(): Configration read OK") ));
   186         }
   172         }
   187     
   173     
   188     
   174     
   189    
   175     //If Configuration is not validated already, validate it
   190 
   176     
       
   177     if (!iConfiguration.iConfigChecked)
       
   178         {
       
   179         TInt valerr = KErrNone;
       
   180         TRAP( valerr, ValidateConfigurationL( KSCPComplete ));
       
   181         if (valerr != KErrNone)
       
   182             {
       
   183             Dprint( (_L("CSCPServer::ConstructL(): Configuration Validation failed: %d"), valerr ));
       
   184             }
       
   185         else
       
   186             {
       
   187             Dprint( (_L("CSCPServer::ConstructL(): Configuration Validation Passed")));
       
   188             }
       
   189         }
       
   190     
       
   191         
       
   192         
   191     Dprint( (_L("CSCPServer::ConstructL(): Connecting to CenRep") ));
   193     Dprint( (_L("CSCPServer::ConstructL(): Connecting to CenRep") ));
   192     iALPeriodRep = CRepository::NewL( KCRUidSecuritySettings );        
   194     iALPeriodRep = CRepository::NewL( KCRUidSecuritySettings );        
   193     
   195     
   194     // Check for factory settings
   196     // Check for factory settings
   195     CheckIfRfsPerformedL();
   197     CheckIfRfsPerformedL();
   650 // Status : Approved
   652 // Status : Approved
   651 // ---------------------------------------------------------
   653 // ---------------------------------------------------------
   652 //	
   654 //	
   653 void CSCPServer::ValidateConfigurationL( TInt aMode )
   655 void CSCPServer::ValidateConfigurationL( TInt aMode )
   654     {
   656     {
   655     if (aMode == KSCPInitial) {
   657     Dprint( (_L("--> CSCPServer::ValidateConfigurationL()") ));
   656         // Return here, must be checked by complete mode
   658     RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()"));
   657         RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@@aMode == KSCPInitial "));
   659     TInt startupReason(ENormalStartup);
   658         User::Leave(KErrAccessDenied);
   660     RProperty::Get(KPSUidStartup, KPSStartupReason, startupReason);
   659     }
   661     Dprint( (_L("CSCPServer::ValidateConfigurationL(): startupReason = %d"), startupReason));
   660     
   662      if((startupReason == ENormalRFSReset)||(startupReason ==  EDeepRFSReset)||(startupReason == EFirmwareUpdate)||(iConfiguration.iConfigFlag == KSCPConfigUnknown))
   661     RMobilePhone::TMobilePassword storedCode;
   663          {
       
   664     
       
   665 	RMobilePhone::TMobilePassword storedCode;
   662     storedCode.Zero();
   666     storedCode.Zero();
   663     User::LeaveIfError(GetCode(storedCode));
   667     User::LeaveIfError(GetCode(storedCode));
   664     TBool isDefaultLockcode = ETrue;
   668     
   665     TInt err = KErrNone;
   669     
   666     
   670 	Dprint( (_L("CSCPServer::ValidateConfigurationL(): Checking code: %s"), storedCode.PtrZ() ));
   667     RMobilePhone::TMobilePassword defaultLockcode;
   671 	// Check that the ISA code is stored correctly
   668     defaultLockcode.Zero();
   672 	TRAPD( err, CheckISACodeL( storedCode ) );
   669     defaultLockcode.Copy(KSCPDefaultSecCode);
   673 	 //Bool for the correction of Defaultlockcode cenrep
   670     if (storedCode.Compare(KSCPDefaultSecCode) == 0) {
   674     TBool lCorrectDefaultlockcode = EFalse;
   671         RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@config has KSCPDefaultSecCode "));
   675     
   672         TRAP( err, CheckISACodeL( defaultLockcode ) );
   676      Dprint( (_L("CSCPServer::ValidateConfigurationL(): iConfigFlag = %d, iConfigChecked = %d"), iConfiguration.iConfigFlag, iConfiguration.iConfigChecked));
   673         if (err == KErrNone) {
   677      
   674             RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@ISA also has KSCPDefaultSecCode "));
   678     if ((iConfiguration.iConfigFlag == KSCPConfigOK)
   675             iConfiguration.iConfigFlag = KSCPConfigOK;
   679             && (iConfiguration.iConfigChecked) && (err == KErrNone))
   676             isDefaultLockcode = ETrue;
   680         {
   677         }
   681         // The configuration has already been checked, exit
   678         else {
   682         Dprint( (_L("CSCPServer::ValidateConfigurationL(): Configuration is non-default.") ));
   679             RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@ISA doesn't has KSCPDefaultSecCode "));
   683         User::Leave( KErrNone );
   680             iConfiguration.iConfigFlag = KSCPConfigInvalid;
   684         }
   681             iConfiguration.iFailedAttempts++;
   685     else if ( aMode == KSCPInitial )
   682             isDefaultLockcode = EFalse;
   686         {
   683         }
   687         // Return here, must be checked by complete mode
   684     }
   688         User::Leave( KErrAccessDenied );
   685     else {
   689         }
   686         RDebug::Print(_L("CSCPServer::CheckISACodeL(): config lock code %s"), storedCode.PtrZ());
   690     
   687         TRAP( err, CheckISACodeL( storedCode ) );
   691    
   688         if (err == KErrNone) {
   692     TInt hashedISAcode;
   689             RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@ISA and config are in SYNC !! "));
   693     TSCPSecCode hashedCode;
   690             iConfiguration.iConfigFlag = KSCPConfigOK;
   694 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS    
   691             isDefaultLockcode = EFalse;
   695 if(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
   692         }
   696 {
   693         else {
   697 	/*TInt*/ hashedISAcode = HashISACode( iConfiguration.iEnhSecCode );
   694             iConfiguration.iSecCode.Zero();
   698    // TSCPSecCode hashedCode;
   695             iConfiguration.iSecCode.Append(KSCPDefaultSecCode);
   699     hashedCode.Zero();
   696             RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@May be ISA has KSCPDefaultSecCode "));
   700     hashedCode.AppendNum( hashedISAcode );
   697             TRAP(err,ChangeISACodeL(storedCode));
   701 }
   698             if (err == KErrNone) {
   702 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS    
   699                 RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()chnaged ISA code with config value "));
   703             
       
   704     
       
   705     
       
   706    
       
   707     if (err != KErrNone)
       
   708         {
       
   709         lCorrectDefaultlockcode = ETrue;
       
   710         }
       
   711     if ( err == KErrNone ) 
       
   712         {
       
   713         iConfiguration.iConfigFlag = KSCPConfigOK;
       
   714         }
       
   715     else if ( err == KErrAccessDenied )
       
   716         {        
       
   717         iConfiguration.iConfigFlag = KSCPConfigInvalid;
       
   718         }
       
   719     else if ( err == KErrLocked )
       
   720         {
       
   721         Dprint( (_L("CSCPServer::ValidateConfigurationL(): ISA code locked.") ));
       
   722         }
       
   723     else
       
   724         {
       
   725         Dprint( (_L("CSCPServer::ValidateConfigurationL(): ERROR in validation.") ));
       
   726         }
       
   727 
       
   728 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS         
       
   729 if(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
       
   730 {
       
   731     if ( err == KErrNone )
       
   732         {
       
   733         // Check that the codes are in-sync with each other. Especially the default ISA code must
       
   734         // be changed according to the default enhanced code.        
       
   735         if ( storedCode.Compare( hashedCode ) != 0 )
       
   736             {
       
   737             Dprint( (_L("CSCPServer::ValidateConfigurationL(): Correct ISA code stored.\
       
   738                Changing ISA code to match enhanced code => %d"), hashedISAcode ));
       
   739                
       
   740             storedCode.Copy( hashedCode );
       
   741             // Change the ISA code to match the hashed code
       
   742             ChangeISACodeL( storedCode );
       
   743             }
       
   744         }
       
   745     else if ( ( err == KErrAccessDenied ) && ( storedCode.Compare( hashedCode ) != 0 ) )
       
   746         {
       
   747         // Try again with the hashed code
       
   748         TRAP( err, CheckISACodeL( hashedCode ) );
       
   749         
       
   750         if ( err == KErrNone )
       
   751             {            
       
   752             Dprint( (_L("CSCPServer::ValidateConfigurationL(): Hashed code is correct.\
       
   753                Storing hashed code(%d)"), hashedISAcode ));
       
   754                
       
   755             if ( StoreCode( hashedCode ) == KErrNone )
       
   756                 {
   700                 iConfiguration.iConfigFlag = KSCPConfigOK;
   757                 iConfiguration.iConfigFlag = KSCPConfigOK;
   701                 isDefaultLockcode = EFalse;
   758                 lCorrectDefaultlockcode = ETrue;
   702             }
   759                 }
   703             else
   760             }        
   704             {
   761         }
   705                 RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()it shouldn't reach this :( "));
   762     
   706             }
   763     //If Correction of Defaultlockcode cenrep is required for the mismatch between Config and ISA
   707         }
   764         if (lCorrectDefaultlockcode)
   708     }
   765             {
   709 
   766             TInt lDefCode = -1;
   710     CRepository* repository = CRepository::NewL(KCRUidSCPLockCode);
   767             CRepository* lRepository = CRepository::NewL(KCRUidSCPLockCode);
   711     CleanupStack::PushL(repository);
   768             CleanupStack::PushL(lRepository);
   712     if (isDefaultLockcode ) {
   769             TInt lRet = lRepository->Get(KSCPLockCodeDefaultLockCode,
   713         RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()setting def. lockcode to 12345 "));
   770                     lDefCode);
   714         repository->Set(KSCPLockCodeDefaultLockCode, 12345);
   771             if (lRet == KErrNone && lDefCode != -1)
   715     }
   772                 {
   716     else {
   773                 if (lDefCode == 12345)
   717         RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()setting def. lockcode to 0 "));
   774                     {
   718         repository->Set(KSCPLockCodeDefaultLockCode, 0);
   775                     //Although lock code is already set, due to some unexpected condition
   719     }
   776                     //like C drive wipe, cenrep status is wrongly shown. Correcting it here.
   720     CleanupStack::PopAndDestroy(repository);
   777                     lRepository->Set(KSCPLockCodeDefaultLockCode, 0);
   721     
   778                     Dprint( (_L("RSCPClient::ValidateConfigurationL(): Corrected the Default lock code cenrep status to 0") ));
   722     TRAP( err, iConfiguration.WriteSetupL() );
   779                     }
   723     if (err != KErrNone) {
   780                 else if (lDefCode == 0)
       
   781                     {
       
   782                     //If only ISA side is formatted, then the lock code on ISA side is default; 
       
   783                     //Cenrep status remains wrongly as the lock code is already set. Correcting it here.
       
   784                     lRepository->Set(KSCPLockCodeDefaultLockCode, 12345);
       
   785                     Dprint( (_L("RSCPClient::ValidateConfigurationL(): Corrected the Default lock code cenrep status to 12345") ));
       
   786                     }
       
   787                 }
       
   788             CleanupStack::PopAndDestroy(lRepository);
       
   789             }
       
   790         }
       
   791 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS
       
   792     //Set the flag to True, after config is validated 
       
   793     iConfiguration.iConfigChecked = ETrue;
       
   794     
       
   795     TRAPD( err2, iConfiguration.WriteSetupL() );
       
   796     if ( err2 != KErrNone )
       
   797         {
   724         Dprint( (_L("CSCPServer::ValidateConfigurationL(): WARNING: failed to write configuration\
   798         Dprint( (_L("CSCPServer::ValidateConfigurationL(): WARNING: failed to write configuration\
   725                 : %d"), err ));
   799             : %d"), err2 ));        
   726     }
   800         } 
   727 
   801     
   728     if (iConfiguration.iConfigFlag == KSCPConfigOK) {
   802     User::LeaveIfError( err );
   729         RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@iConfigFlag == KSCPConfigOK "));
   803          }
   730         err = KErrNone;
   804     Dprint( (_L("<-- CSCPServer::ValidateConfigurationL()") ));
   731     }
   805     }
   732     else {
       
   733         RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@iConfigFlag == KErrAccessDenied "));
       
   734         err = KErrAccessDenied;
       
   735     }
       
   736 
       
   737     User::LeaveIfError(err);
       
   738 }
       
   739 
       
   740 
   806 
   741         
   807         
   742     
   808     
   743     
   809     
   744 // ---------------------------------------------------------
   810 // ---------------------------------------------------------
   755 #ifdef __WINS__    
   821 #ifdef __WINS__    
   756     
   822     
   757     (void)aCode;    
   823     (void)aCode;    
   758 
   824 
   759 #endif // __WINS__
   825 #endif // __WINS__
   760 
   826    
   761 
       
   762 Dprint( (_L("CSCPServer::CheckISACodeL(): current lock code %s"), aCode.PtrZ() ));
       
   763 RDebug::Print(_L("CSCPServer::CheckISACodeL(): current lock code %s"), aCode.PtrZ());
       
   764     RMobilePhone::TMobilePhoneSecurityCode secCodeType;
   827     RMobilePhone::TMobilePhoneSecurityCode secCodeType;
   765     secCodeType = RMobilePhone::ESecurityCodePhonePassword;
   828     secCodeType = RMobilePhone::ESecurityCodePhonePassword;
   766     
   829     
   767     RMobilePhone::TMobilePassword required_fourth;
   830     RMobilePhone::TMobilePassword required_fourth;
   768                 
   831                 
   794             Dprint( (_L("CSCPServer::CheckISACodeL(): ISA code NOT OK") ));
   857             Dprint( (_L("CSCPServer::CheckISACodeL(): ISA code NOT OK") ));
   795             if (iConfiguration.iBlockedInOOS == 1)
   858             if (iConfiguration.iBlockedInOOS == 1)
   796 	         {
   859 	         {
   797 	            	iConfiguration.iBlockedInOOS = 0;
   860 	            	iConfiguration.iBlockedInOOS = 0;
   798    	            	Dprint( (_L("CSCPServer::CheckISACodeL():iBlockedInOOS = 0, KErrAccessDenied") ));
   861    	            	Dprint( (_L("CSCPServer::CheckISACodeL():iBlockedInOOS = 0, KErrAccessDenied") ));
   799    	            	RDebug::Print(_L("--> CSCPServer::CheckISACodeL()@@iBlockedInOOS = 0, KErrAccessDenie"));
       
   800 	         }            
   862 	         }            
   801             ret = KErrAccessDenied;             
   863             ret = KErrAccessDenied;             
   802             }
   864             }
   803         else if ( ( ret == KErrGsmSSPasswordAttemptsViolation ) || ( ret == KErrLocked ) )
   865         else if ( ( ret == KErrGsmSSPasswordAttemptsViolation ) || ( ret == KErrLocked ) )
   804             {
   866             {
   805             Dprint( (_L("CSCPServer::CheckISACodeL(): ISA code BLOCKED") ));            
   867             Dprint( (_L("CSCPServer::CheckISACodeL(): ISA code BLOCKED") ));            
   806             if (ret==KErrGsmSSPasswordAttemptsViolation)
   868             if (ret==KErrGsmSSPasswordAttemptsViolation)
   807             {
   869             {
   808             	Dprint( (_L("CSCPServer::CheckISACodeL(): KErrGsmSSPasswordAttemptsViolation") ));  
   870             	Dprint( (_L("CSCPServer::CheckISACodeL(): KErrGsmSSPasswordAttemptsViolation") ));            	
   809             	RDebug::Print(_L("--> CSCPServer::CheckISACodeL()@@KErrGsmSSPasswordAttemptsViolation"));
       
   810             }
   871             }
   811             else
   872             else
   812             {
   873             {
   813             	Dprint( (_L("CSCPServer::CheckISACodeL(): KErrLocked") ));
   874             	Dprint( (_L("CSCPServer::CheckISACodeL(): KErrLocked") ));
   814             	RDebug::Print(_L("--> CSCPServer::CheckISACodeL()@@KErrLocked"));
       
   815             }	            
   875             }	            
   816             ret = KErrLocked;
   876             ret = KErrLocked;
   817             if (iConfiguration.iBlockedInOOS == 0)
   877             if (iConfiguration.iBlockedInOOS == 0)
   818         	 {
   878         	 {
   819             	iConfiguration.iBlockedInOOS = 1;
   879             	iConfiguration.iBlockedInOOS = 1;
   820             	Dprint( (_L("CSCPServer::CheckISACodeL():iBlockedInOOS = 1, KSCPErrCodeBlockStarted") ));
   880             	Dprint( (_L("CSCPServer::CheckISACodeL():iBlockedInOOS = 1, KSCPErrCodeBlockStarted") ));
   821             	RDebug::Print(_L("--> CSCPServer::CheckISACodeL()@@@@@"));
       
   822             	ret = KSCPErrCodeBlockStarted;	
   881             	ret = KSCPErrCodeBlockStarted;	
   823         	 }
   882         	 }
   824             }            
   883             }            
   825         else
   884         else
   826             {
   885             {
   827             Dprint( (_L("CSCPServer::CheckISACodeL(): ERROR reply checking ISA code: %d"),
   886             Dprint( (_L("CSCPServer::CheckISACodeL(): ERROR reply checking ISA code: %d"),
   828                 status.Int() ));
   887                 status.Int() ));
   829                 RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()"));
       
   830             }            
   888             }            
   831         }
   889         }
   832         TRAPD( err, iConfiguration.WriteSetupL() );
   890         TRAPD( err, iConfiguration.WriteSetupL() );
   833         if ( err != KErrNone )
   891         if ( err != KErrNone )
   834             {
   892             {
   942     		 * already set
  1000     		 * already set
   943     		 * */
  1001     		 * */
   944     		TRAP(err, repository = CRepository :: NewL(KCRUidSCPLockCode));
  1002     		TRAP(err, repository = CRepository :: NewL(KCRUidSCPLockCode));
   945     		
  1003     		
   946     		if(err == KErrNone) {
  1004     		if(err == KErrNone) {
   947     			RDebug::Print(_L("<-- CSCPServer::StoreEnhCode()  setting KSCPLockCodeDefaultLockCode to 0"));
       
   948                 err = repository->Set(KSCPLockCodeDefaultLockCode, 0);
  1005                 err = repository->Set(KSCPLockCodeDefaultLockCode, 0);
   949                 delete repository;
  1006                 delete repository;
   950     		}
  1007     		}
   951         	}    
  1008         	}    
   952         }
  1009         }
  1278 #endif // __SCP_DEBUG    
  1335 #endif // __SCP_DEBUG    
  1279     
  1336     
  1280     TInt lRetStatus(KErrNone);
  1337     TInt lRetStatus(KErrNone);
  1281     Dprint(_L("[CSCPServer]-> Initiating branching on parameter..."));
  1338     Dprint(_L("[CSCPServer]-> Initiating branching on parameter..."));
  1282     
  1339     
  1283     switch(aID) {
  1340     switch ( aID )
  1284         case ESCPAutolockPeriod:
  1341         {
  1285         case ESCPMaxAutolockPeriod: {
  1342         case ( ESCPAutolockPeriod ):
       
  1343         // Flow through            
       
  1344         case ( ESCPMaxAutolockPeriod ):
       
  1345             {
  1286             // Convert the value, and set it
  1346             // Convert the value, and set it
  1287             TInt value;
  1347             TInt value;
  1288             TLex lex(aValue);
  1348             TLex lex(aValue);
  1289             lRetStatus = lex.Val(value);
  1349             lRetStatus = lex.Val(value);
       
  1350              
  1290 
  1351 
  1291             if((lRetStatus != KErrNone ) || ( value < 0) || ( value > KSCPAutolockPeriodMaximum )) {
  1352             if((lRetStatus != KErrNone ) || ( value < 0) || ( value > KSCPAutolockPeriodMaximum )) {
  1292                 lRetStatus = KErrArgument;
  1353                 lRetStatus = KErrArgument;
  1293                 break;
  1354                 break;
  1294             }
  1355                 }
  1295                   
  1356                   
  1296             //Check if the device memory is encrypted or not.
  1357             //Check if the device memory is encrypted or not.
  1297             TBool encryptionEnabled = IsDeviceMemoryEncrypted();
  1358             TBool encryptionEnabled = IsDeviceMemoryEncrypted();
  1298             CSCPParamDBController* lParamDB = CSCPParamDBController :: NewLC();
       
  1299             
  1359             
  1300             // Value OK
  1360             // Value OK
  1301             if(aID == ESCPMaxAutolockPeriod) {
  1361             if(aID == ESCPMaxAutolockPeriod) 
  1302                 if( encryptionEnabled ) {
  1362 						{
  1303                     Dprint(_L("[CSCPServer]-> Memory is encrypted"));
  1363 						   if (  encryptionEnabled )
       
  1364                   {
       
  1365                   Dprint(_L("Memory is encrypted"));
       
  1366                   if (( 0 == value) || value > KMaxAutolockPeriod)
       
  1367                       {
       
  1368                       Dprint((_L("Denying setting of max auto lock as value is %d"), value));
       
  1369                       User::Leave( KErrPermissionDenied );
       
  1370                       }
       
  1371                       
       
  1372                   }
       
  1373                 else
       
  1374                     {
       
  1375                     Dprint(_L("Memory is decrypted, hence no restrictions to max autolock"));
       
  1376                     }
  1304                     
  1377                     
  1305                     if(( 0 == value) || value > KMaxAutolockPeriod) {
  1378                 Dprint(_L("[CSCPServer]-> Branched to ESCPMaxAutolockPeriod..."));
  1306                         Dprint((_L("[CSCPServer]-> Denying setting of max auto lock as value is %d"), value));
  1379                 CSCPParamDBController* lParamDB = CSCPParamDBController :: NewLC();
  1307                         User :: Leave( KErrPermissionDenied );
       
  1308                     }
       
  1309                 }
       
  1310                 else {
       
  1311                     Dprint(_L("Memory is decrypted, hence no restrictions to max autolock"));
       
  1312                 }
       
  1313                     
       
  1314                 Dprint(_L("[CSCPServer]-> Branched to ESCPMaxAutolockPeriod..."));                
       
  1315                 lRetStatus = SetBestPolicyL(RTerminalControl3rdPartySession :: EMaxTimeout, aValue, aCallerIdentity, lParamDB);
  1380                 lRetStatus = SetBestPolicyL(RTerminalControl3rdPartySession :: EMaxTimeout, aValue, aCallerIdentity, lParamDB);
  1316 
  1381 
  1317                 if(lRetStatus == KErrNone) {
  1382                 if(lRetStatus == KErrNone) 
       
  1383 								{
  1318                     // Do we have to change the Autolock period as well?
  1384                     // Do we have to change the Autolock period as well?
  1319                     TInt currentALperiod;
  1385                     TInt currentALperiod;
  1320                     lRetStatus = GetAutolockPeriodL(currentALperiod);
  1386                     lRetStatus = GetAutolockPeriodL(currentALperiod);
  1321 
  1387 
  1322                     if(lRetStatus == KErrNone) {
  1388                     if(lRetStatus == KErrNone) 
  1323                         if( (iConfiguration.iMaxTimeout > 0) && 
  1389 										{
  1324                             ((iConfiguration.iMaxTimeout < currentALperiod) ||
  1390                         if((iConfiguration.iMaxTimeout > 0) && ((iConfiguration.iMaxTimeout < currentALperiod) || (currentALperiod == 0))) 
  1325                             (currentALperiod == 0))) {
  1391 												{
  1326                         
       
  1327                            Dprint((_L("[CSCPServer]-> Changing AL period to Max. AL period (Current ALP: %d, Max. ALP: %d)"), currentALperiod, value));
  1392                            Dprint((_L("[CSCPServer]-> Changing AL period to Max. AL period (Current ALP: %d, Max. ALP: %d)"), currentALperiod, value));
  1328                            //lRetStatus = SetAutolockPeriodL(value);                           
  1393                            lRetStatus = SetAutolockPeriodL(value);
  1329                            /*
       
  1330                             * Call to SetBestPolicyL will not check for Stronger/Weaker. The value of ETimeout just gets stored in 
       
  1331                             * both the internal DB and the CenRep
       
  1332                            */
       
  1333                            lRetStatus = SetBestPolicyL(RTerminalControl3rdPartySession :: ETimeout, aValue, aCallerIdentity, lParamDB);
       
  1334                         }
  1394                         }
  1335                     }
  1395                     }
  1336                     else {
  1396                     else 
       
  1397 										{
  1337                         Dprint((_L("[CSCPServer]-> ERROR: Couldn't get the Autolock period: %d"), lRetStatus));
  1398                         Dprint((_L("[CSCPServer]-> ERROR: Couldn't get the Autolock period: %d"), lRetStatus));
  1338                     }
  1399                     }
  1339                 }
  1400                 }
  1340             }
  1401 
  1341             // Autolock Period
  1402                 CleanupStack :: PopAndDestroy(); //lParamDB
  1342             else {
  1403             }
  1343                 //Code is commented as it is already taken care by the below condition #1343 irrespective of the drive encryption state.
  1404             
  1344                 /*  if ( 0 == value ) {
  1405             else 
  1345                     if(encryptionEnabled) {
  1406             { // Autolock Period
       
  1407             	
       
  1408             			//Code is commented as it is already taken care by the below condition #1343 irrespective of the drive encryption state.
       
  1409             	     /*  if ( 0 == value )
       
  1410                     {
       
  1411                     if ( encryptionEnabled )
       
  1412                         {
  1346                         Dprint(_L("Permission denied!"));
  1413                         Dprint(_L("Permission denied!"));
  1347                         User :: Leave(KErrPermissionDenied);
  1414                         User::Leave( KErrPermissionDenied );
  1348                     }
  1415                         }
  1349                 }*/
  1416                     }*/
  1350 
  1417                     
  1351                 Dprint(_L("[CSCPServer]-> Branched to ESCPAutolockPeriod..."));
  1418                 Dprint(_L("[CSCPServer]-> Branched to ESCPAutolockPeriod..."));
  1352                 //  Check if this value is not allowed by the Max. Autolock period
  1419                 //  Check if this value is not allowed by the Max. Autolock period
  1353                 if ((iConfiguration.iMaxTimeout > 0) && ((iConfiguration.iMaxTimeout < value) || (value == 0))) {
  1420                 if ((iConfiguration.iMaxTimeout > 0) && ((iConfiguration.iMaxTimeout < value) || (value == 0))) {
  1354                     Dprint((_L("[CSCPServer]-> ERROR: The value %d for AL period not allowed (Max. AL period: %d)"), value, iConfiguration.iMaxTimeout));
  1421                     Dprint((_L("[CSCPServer]-> ERROR: The value %d for AL period not allowed (Max. AL period: %d)"), value, iConfiguration.iMaxTimeout));
  1355 
  1422 
  1356                     lRetStatus = KErrArgument;
  1423                     lRetStatus = KErrArgument;
  1357                 }
  1424                 }
  1358                 else {
  1425                 else {
  1359                     //lRetStatus = SetAutolockPeriodL(value);
  1426                     lRetStatus = SetAutolockPeriodL(value);
  1360                     /*
       
  1361                      * Call to SetBestPolicyL will not check for Stronger/Weaker. The value of ETimeout just gets stored in 
       
  1362                      * both the internal DB and the CenRep
       
  1363                     */
       
  1364                     lRetStatus = SetBestPolicyL(RTerminalControl3rdPartySession :: ETimeout, aValue, aCallerIdentity, lParamDB);
       
  1365 
  1427 
  1366                     if(lRetStatus != KErrNone) {
  1428                     if(lRetStatus != KErrNone) {
  1367                         Dprint((_L("[CSCPServer]-> ERROR: Couldn't set the Autolock period: %d"), lRetStatus));
  1429                         Dprint((_L("[CSCPServer]-> ERROR: Couldn't set the Autolock period: %d"), lRetStatus));
  1368                     }
  1430                     }
  1369                 }
  1431                 }
  1370             }
  1432             }
  1371             
       
  1372             CleanupStack :: PopAndDestroy(); //lParamDB
       
  1373         }
  1433         }
  1374         break;
  1434         break;
  1375         case ESCPCodeChangePolicy:
  1435         case ESCPCodeChangePolicy:
  1376             Dprint(_L("[CSCPServer]-> Branched to ESCPCodeChangePolicy..."));
  1436             Dprint(_L("[CSCPServer]-> Branched to ESCPCodeChangePolicy..."));
  1377             lRetStatus = ChangeCodePolicy( aValue );
  1437             lRetStatus = ChangeCodePolicy( aValue );
  1695                     }
  1755                     }
  1696                 } 
  1756                 } 
  1697             
  1757             
  1698             if ( getFromCommonStorage )
  1758             if ( getFromCommonStorage )
  1699                 {
  1759                 {
       
  1760                 Dprint(_L("[CSCPServer]-> Fetching from Common storage..."));
  1700                 // OK, no objection, so try to get the value from common storage
  1761                 // OK, no objection, so try to get the value from common storage
  1701                 ret = iPluginEventHandler->GetParameters().Get( aID, aValue );
  1762                 ret = iPluginEventHandler->GetParameters().Get( aID, aValue );
  1702                 }            
  1763                 }            
  1703             
  1764             
  1704             if ( repParams != NULL )
  1765             if ( repParams != NULL )
  2007 // Status : Approved
  2068 // Status : Approved
  2008 // ---------------------------------------------------------
  2069 // ---------------------------------------------------------
  2009 //  
  2070 //  
  2010 TInt CSCPServer::IsCorrectEnhCode( TDes& aCode, TInt aFlags )
  2071 TInt CSCPServer::IsCorrectEnhCode( TDes& aCode, TInt aFlags )
  2011     {
  2072     {
  2012     Dprint( (_L("CSCPServer::IsCorrectEnhCode(): ") ));
  2073     Dprint( (_L("CSCPServer::IsCorrectEnhCode") ));
  2013     if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
  2074     if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
  2014     {
  2075     {
  2015     	return KErrNotSupported;
  2076     	return KErrNotSupported;
  2016     }
  2077     }
  2017     TInt ret = KErrAccessDenied;
  2078     TInt ret = KErrAccessDenied;
  2018    
  2079     
  2019     // Hash the code
  2080     // Hash the code
  2020     TBuf<KSCPMaxHashLength> hashBuf;
  2081     TBuf<KSCPMaxHashLength> hashBuf;
  2021     hashBuf.Zero();
  2082     hashBuf.Zero();
  2022     iPluginEventHandler->HashInput( aCode, hashBuf );
  2083     iPluginEventHandler->HashInput( aCode, hashBuf );
  2023         
  2084         
  2028     pswCandidate.AppendNum( ISACode );
  2089     pswCandidate.AppendNum( ISACode );
  2029         
  2090         
  2030     TBool enhancedCodeMatches = EFalse;
  2091     TBool enhancedCodeMatches = EFalse;
  2031     if ( hashBuf.Compare( iConfiguration.iEnhSecCode ) == 0 )
  2092     if ( hashBuf.Compare( iConfiguration.iEnhSecCode ) == 0 )
  2032         {
  2093         {
  2033         	Dprint( (_L("CSCPServer::IsCorrectEnhCode(): enh code matches.") ));
       
  2034         enhancedCodeMatches = ETrue;
  2094         enhancedCodeMatches = ETrue;
  2035         }
  2095         }
  2036         
  2096         
  2037     // Check if the code is blocked (don't check if we're out-of-sync)
  2097     // Check if the code is blocked (don't check if we're out-of-sync)
  2038     if ( ( iConfiguration.iConfigFlag == KSCPConfigOK ) && ( IsCodeBlocked() ) )
  2098     if ( ( iConfiguration.iConfigFlag == KSCPConfigOK ) && ( IsCodeBlocked() ) )
  2039         {
  2099         {
  2040         	Dprint( (_L("CSCPServer::IsCorrectEnhCode(): 1") ));
       
  2041         if ( aFlags & KSCPEtelRequest )
  2100         if ( aFlags & KSCPEtelRequest )
  2042             {
  2101             {
  2043             	Dprint( (_L("CSCPServer::IsCorrectEnhCode(): 2") ));
       
  2044             // Check if the code is correct
  2102             // Check if the code is correct
  2045             if ( enhancedCodeMatches )
  2103             if ( enhancedCodeMatches )
  2046                 {
  2104                 {
  2047                 // Mess-up the code                 
  2105                 // Mess-up the code                 
  2048                 RMobilePhone::TMobilePassword codeToSend;
  2106                 RMobilePhone::TMobilePassword codeToSend;
  2052                 SendInvalidDOSCode( codeToSend );
  2110                 SendInvalidDOSCode( codeToSend );
  2053                 }
  2111                 }
  2054             else 
  2112             else 
  2055                 {
  2113                 {
  2056                 // OK, the code is already invalid
  2114                 // OK, the code is already invalid
  2057                 Dprint( (_L("CSCPServer::IsCorrectEnhCode(): 3") ));
       
  2058                 SendInvalidDOSCode( pswCandidate );
  2115                 SendInvalidDOSCode( pswCandidate );
  2059                 }
  2116                 }
  2060             }
  2117             }
  2061         return KErrLocked;
  2118         return KErrLocked;
  2062         }       
  2119         }       
  2065     
  2122     
  2066     if ( iConfiguration.iConfigFlag == KSCPConfigOK )
  2123     if ( iConfiguration.iConfigFlag == KSCPConfigOK )
  2067         {
  2124         {
  2068         // Normal situation: we have the correct code stored.
  2125         // Normal situation: we have the correct code stored.
  2069         // Compare the hashes (hashing error will result in EFalse )
  2126         // Compare the hashes (hashing error will result in EFalse )
  2070         Dprint( (_L("CSCPServer::IsCorrectEnhCode(): 4") ));
       
  2071         if ( enhancedCodeMatches )
  2127         if ( enhancedCodeMatches )
  2072             {
  2128             {
  2073             ret = KErrNone;
  2129             ret = KErrNone;
  2074             
  2130             
  2075             if ( aFlags & KSCPEtelRequest )
  2131             if ( aFlags & KSCPEtelRequest )
  2076                 {
  2132                 {
  2077                 // Send the correct code to DOS side
  2133                 // Send the correct code to DOS side
  2078                 Dprint( (_L("CSCPServer::IsCorrectEnhCode(): 5") ));
       
  2079                 TRAP( ret, CheckISACodeL( pswCandidate ) );
  2134                 TRAP( ret, CheckISACodeL( pswCandidate ) );
  2080                 }  
  2135                 }  
  2081                 
  2136                 
  2082             if ( ret == KErrNone )
  2137             if ( ret == KErrNone )
  2083                 {
  2138                 {
  2084                 if ( iConfiguration.iFailedAttempts > 0 )
  2139                 if ( iConfiguration.iFailedAttempts > 0 )
  2085                     {
  2140                     {
  2086                     iConfiguration.iFailedAttempts = 0;  
  2141                     iConfiguration.iFailedAttempts = 0;  
  2087                     Dprint( (_L("CSCPServer::IsCorrectEnhCode():: iFailedAttempts (%d)."), iConfiguration.iFailedAttempts ));
  2142                     Dprint( (_L("CSCPServer::IsCorrectEnhCode():KErrAccessDenied: iFailedAttempts (%d)."), iConfiguration.iFailedAttempts ));
  2088                     writeSetup = ETrue;
  2143                     writeSetup = ETrue;
  2089                     }                
  2144                     }                
  2090                 }
  2145                 }
  2091             else
  2146             else
  2092                 {
  2147                 {
  2097         else
  2152         else
  2098             {
  2153             {
  2099             ret = KErrAccessDenied;
  2154             ret = KErrAccessDenied;
  2100             
  2155             
  2101             iConfiguration.iFailedAttempts++;
  2156             iConfiguration.iFailedAttempts++;
  2102             Dprint( (_L("CSCPServer::IsCorrectEnhCode():@@@: iFailedAttempts (%d)."), iConfiguration.iFailedAttempts ));
  2157             Dprint( (_L("CSCPServer::IsCorrectEnhCode():KErrAccessDenied: iFailedAttempts (%d)."), iConfiguration.iFailedAttempts ));
  2103             writeSetup = ETrue;
  2158             writeSetup = ETrue;
  2104             
  2159             
  2105             if ( iConfiguration.iFailedAttempts == KSCPCodeBlockLimit )
  2160             if ( iConfiguration.iFailedAttempts == KSCPCodeBlockLimit )
  2106                 {
  2161                 {
  2107                 	Dprint( (_L("CSCPServer::IsCorrectEnhCode(): KSCPCodeBlockLimit  ") ));
       
  2108                 // Block the code
  2162                 // Block the code
  2109                 TTime curTime;
  2163                 TTime curTime;
  2110                 curTime.UniversalTime();
  2164                 curTime.UniversalTime();
  2111                 
  2165                 
  2112                 iConfiguration.iBlockedAtTime.Zero();
  2166                 iConfiguration.iBlockedAtTime.Zero();
  2123             }
  2177             }
  2124         }
  2178         }
  2125     else 
  2179     else 
  2126         {
  2180         {
  2127         // iConfiguration.iConfigFlag == KSCPConfigInvalid or KSCPConfigUnknown
  2181         // iConfiguration.iConfigFlag == KSCPConfigInvalid or KSCPConfigUnknown
  2128 
  2182         
  2129         // We might be out-of-sync, no idea about the real code.
  2183         // We might be out-of-sync, no idea about the real code.
  2130         // Check if the DOS code hashed from the given code is correct.
  2184         // Check if the DOS code hashed from the given code is correct.
  2131         Dprint( (_L("CSCPServer::IsCorrectEnhCode(): Attempting to correct OoS situation.") ));
  2185         Dprint( (_L("CSCPServer::IsCorrectEnhCode(): Attempting to correct OoS situation.") ));
  2132         if (IsCodeBlocked()) {
  2186                 
  2133             Dprint( (_L("CSCPServer::IsCorrectEnhCode(): OOS ->KErrLocked  ") ));
       
  2134             return KErrLocked;
       
  2135         }
       
  2136         TRAP( ret, CheckISACodeL( pswCandidate ) );
  2187         TRAP( ret, CheckISACodeL( pswCandidate ) );
  2137 
  2188 
  2138         if (ret == KErrNone) {
  2189         if ( ret == KErrNone )
       
  2190             {
  2139             // OK, we must assume that this is the correct code, since
  2191             // OK, we must assume that this is the correct code, since
  2140             // the hashed DOS code is correct. Save the codes, and return OK.
  2192             // the hashed DOS code is correct. Save the codes, and return OK.
  2141 
  2193 
  2142             Dprint( (_L("CSCPServer::IsCorrectEnhCode(): Given code has the correct hash (%d)\
  2194             Dprint( (_L("CSCPServer::IsCorrectEnhCode(): Given code has the correct hash (%d)\
  2143                 , saving codes."), ISACode ));
  2195                 , saving codes."), ISACode ));
  2144 
  2196                 
  2145             iConfiguration.iEnhSecCode.Zero();
  2197             iConfiguration.iEnhSecCode.Zero();
  2146             iConfiguration.iEnhSecCode.Copy(hashBuf);
  2198             iConfiguration.iEnhSecCode.Copy( hashBuf );
  2147 
  2199 
  2148             iConfiguration.iSecCode.Zero();
  2200             iConfiguration.iSecCode.Zero();
  2149             iConfiguration.iSecCode.AppendNum(ISACode);
  2201             iConfiguration.iSecCode.AppendNum( ISACode );
  2150 
  2202             
  2151             // Unset the invalid configuration flag
  2203             // Unset the invalid configuration flag
  2152             iConfiguration.iConfigFlag = KSCPConfigOK;
  2204             iConfiguration.iConfigFlag = KSCPConfigOK;
  2153             writeSetup = ETrue;
  2205             writeSetup = ETrue;
  2154         }
  2206             }
  2155         else {
  2207         else
  2156             ret = KErrAccessDenied;
  2208             {
  2157 
  2209 				
  2158             iConfiguration.iFailedAttempts++;
  2210             Dprint( (_L("CSCPServer::IsCorrectEnhCode(): Given code does not have the \
  2159             Dprint( (_L("CSCPServer::IsCorrectEnhCode():@@@: iFailedAttempts (%d)."), iConfiguration.iFailedAttempts ));
  2211                 correct hash: ret; %d user enter password: %d"), ret ));
       
  2212 			TRAP( ret, CheckISACodeL( aCode ) );
       
  2213 			if (ret == KErrNone)
       
  2214 			{
       
  2215 				//store this code in our interal storage as it is used as oldpassword while changing at ISA side in next command
       
  2216 				//ChangeISACodeL. 
       
  2217 				iConfiguration.iSecCode.Zero();
       
  2218 				iConfiguration.iSecCode.Append( aCode );
       
  2219 				TRAP(ret,ChangeISACodeL(pswCandidate));
       
  2220 			}
       
  2221 			if (ret == KErrNone)
       
  2222 			{
       
  2223 			iConfiguration.iEnhSecCode.Zero();
       
  2224             iConfiguration.iEnhSecCode.Copy( hashBuf );
       
  2225 
       
  2226             iConfiguration.iSecCode.Zero();
       
  2227             iConfiguration.iSecCode.AppendNum( ISACode );
       
  2228             
       
  2229             // Unset the invalid configuration flag
       
  2230             iConfiguration.iConfigFlag = KSCPConfigOK;
  2160             writeSetup = ETrue;
  2231             writeSetup = ETrue;
  2161 
  2232 			}
  2162             if (iConfiguration.iFailedAttempts == KSCPCodeBlockLimit) {
  2233             }
  2163                 Dprint( (_L("CSCPServer::IsCorrectEnhCode(): KSCPCodeBlockLimit  ") ));
  2234         }
  2164                 // Block the code
       
  2165                 TTime curTime;
       
  2166                 curTime.UniversalTime();
       
  2167 
       
  2168                 iConfiguration.iBlockedAtTime.Zero();
       
  2169                 iConfiguration.iBlockedAtTime.AppendNum(curTime.Int64());
       
  2170 
       
  2171                 // The code will be blocked for now on
       
  2172                 ret = KSCPErrCodeBlockStarted;
       
  2173             }
       
  2174         }
       
  2175 
       
  2176     }
       
  2177     
  2235     
  2178     // Write setup if needed
  2236     // Write setup if needed
  2179     if ( writeSetup )
  2237     if ( writeSetup )
  2180         {
  2238         {
  2181         	Dprint( (_L("CSCPServer::IsCorrectEnhCode(): 7  ") ));
       
  2182         TRAPD( err, iConfiguration.WriteSetupL() );
  2239         TRAPD( err, iConfiguration.WriteSetupL() );
  2183         if ( err != KErrNone )
  2240         if ( err != KErrNone )
  2184             {
  2241             {
  2185             Dprint( (_L("CSCPServer::IsCorrectEnhCode(): WARNING:\
  2242             Dprint( (_L("CSCPServer::IsCorrectEnhCode(): WARNING:\
  2186                 failed to write configuration: %d"), err ));                                        
  2243                 failed to write configuration: %d"), err ));                                        
  2187             }                 
  2244             }                 
  2188         }
  2245         }
  2189         
  2246     Dprint( (_L("CSCPServer::IsCorrectEnhCode %d"), ret )); 
  2190     return ret;
  2247     return ret;
  2191     }
  2248     }
  2192     
  2249     
  2193 
  2250 
  2194 
  2251 
  2305 TInt CSCPServer::CheckAndChangeEnhCodeL( TDes& aOldPass, 
  2362 TInt CSCPServer::CheckAndChangeEnhCodeL( TDes& aOldPass, 
  2306                                         TDes& aNewPass,
  2363                                         TDes& aNewPass,
  2307                                         CSCPParamObject*& aRetParams,
  2364                                         CSCPParamObject*& aRetParams,
  2308                                         TSCPSecCode& aNewDOSCode )
  2365                                         TSCPSecCode& aNewDOSCode )
  2309     {        
  2366     {        
  2310     
  2367     Dprint(_L("CSCPServer::CheckAndChangeEnhCodeL >>"));
  2311     if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
  2368     if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
  2312     {
  2369     {
  2313     	return KErrNotSupported;
  2370     	return KErrNotSupported;
  2314     }
  2371     }
  2315     TInt ret = KErrNone;
  2372     TInt ret = KErrNone;
  2324         inParams->Set( KSCPParamStatus, KErrNone ); 
  2381         inParams->Set( KSCPParamStatus, KErrNone ); 
  2325         inParams->Set( KSCPParamContext, KSCPContextChangePsw );
  2382         inParams->Set( KSCPParamContext, KSCPContextChangePsw );
  2326         CSCPParamObject* repParams = 
  2383         CSCPParamObject* repParams = 
  2327             iPluginManager->PostEvent( KSCPEventAuthenticationAttempted, *inParams );
  2384             iPluginManager->PostEvent( KSCPEventAuthenticationAttempted, *inParams );
  2328         
  2385         
  2329         if ( repParams != NULL )            
  2386         if ( repParams != NULL ) {
       
  2387             // Ignore the return params at this point
       
  2388             delete repParams;
       
  2389        	}  
       
  2390 		
       
  2391         CleanupStack::PopAndDestroy(inParams);
       
  2392         
       
  2393         ret = ValidateLockcodeAgainstPoliciesL(aNewPass, aRetParams);
       
  2394         
       
  2395         if(ret != KErrNone) {
       
  2396             Dprint(_L("[CSCPServer]-> ValidateLockcodeAgainstPoliciesL() failed in CheckAndChangeEnhCodeL() ret=%d"), ret);
       
  2397             return ret;
       
  2398         }
       
  2399 
       
  2400 
       
  2401         if ( IsValidEnhCode( aNewPass ) )
       
  2402             {
       
  2403             ret = StoreEnhCode( aNewPass, &aNewDOSCode );
       
  2404             }                        
       
  2405         else
       
  2406             {
       
  2407             // Invalid code format! Should not happen at this point, but make sure.
       
  2408             ret = KErrArgument; 
       
  2409             }
       
  2410             
       
  2411         if ( ret == KErrNone )
       
  2412             {
       
  2413             CSCPParamObject* inParams = CSCPParamObject::NewL();
       
  2414             CleanupStack::PushL( inParams );
       
  2415             inParams->Set( KSCPParamPassword, aNewPass );
       
  2416     
       
  2417             CSCPParamObject* repParams = 
       
  2418                 iPluginManager->PostEvent( KSCPEventPasswordChanged, *inParams );
       
  2419     
       
  2420             CleanupStack::PopAndDestroy( inParams );
       
  2421         
       
  2422             if ( repParams != NULL )            
  2330                 {
  2423                 {
  2331                 // Ignore the return params at this point
  2424                 // Ignore the return params at this point
  2332                 delete repParams;
  2425                 delete repParams;
  2333                 }  
       
  2334                 
       
  2335         inParams->Reset();
       
  2336         
       
  2337         // Validate the code                
       
  2338         inParams->Set( KSCPParamPassword, aNewPass );
       
  2339         
       
  2340         repParams = iPluginManager->PostEvent( KSCPEventValidate, *inParams );
       
  2341         
       
  2342         CleanupStack::PopAndDestroy( inParams );
       
  2343         
       
  2344         if ( repParams != NULL )
       
  2345             {
       
  2346             // Check if the validation failed
       
  2347             TInt status;
       
  2348             if ( repParams->Get( KSCPParamStatus, status ) == KErrNone )
       
  2349                 {
       
  2350                 if ( status != KErrNone )
       
  2351                     {
       
  2352                     ret = status;
       
  2353                     }
       
  2354                 }
  2426                 }
  2355                 
       
  2356             aRetParams = repParams; // pointer ownership changed                           
       
  2357             }
       
  2358         
       
  2359         // Set the new code, if it was OK
       
  2360         if ( ret == KErrNone )
       
  2361             {
       
  2362             if ( IsValidEnhCode( aNewPass ) )
       
  2363                 {
       
  2364                 ret = StoreEnhCode( aNewPass, &aNewDOSCode );
       
  2365                 }                        
       
  2366             else
       
  2367                 {
       
  2368                 // Invalid code format! Should not happen at this point, but make sure.
       
  2369                 ret = KErrArgument; 
       
  2370                 }
       
  2371             
       
  2372             if ( ret == KErrNone )
       
  2373                 {
       
  2374                 CSCPParamObject* inParams = CSCPParamObject::NewL();
       
  2375                 CleanupStack::PushL( inParams );
       
  2376                 inParams->Set( KSCPParamPassword, aNewPass );
       
  2377         
       
  2378                 CSCPParamObject* repParams = 
       
  2379                     iPluginManager->PostEvent( KSCPEventPasswordChanged, *inParams );
       
  2380         
       
  2381                 CleanupStack::PopAndDestroy( inParams );
       
  2382             
       
  2383                 if ( repParams != NULL )            
       
  2384                     {
       
  2385                     // Ignore the return params at this point
       
  2386                     delete repParams;
       
  2387                     }
       
  2388                 }       
       
  2389             }
  2427             }
  2390         }    
  2428         }    
  2391     else
  2429     else
  2392         {
  2430         {
  2393         if ( ( ret == KErrAccessDenied ) || ( ret == KSCPErrCodeBlockStarted ) )
  2431         if ( ( ret == KErrAccessDenied ) || ( ret == KSCPErrCodeBlockStarted ) )
  2413                 {
  2451                 {
  2414         	    ret = KErrLocked; // Set this as the external error code
  2452         	    ret = KErrLocked; // Set this as the external error code
  2415                 }                            
  2453                 }                            
  2416             }
  2454             }
  2417         }
  2455         }
  2418                 
  2456     Dprint(_L("[CSCPServer]-> CheckAndChangeEnhCodeL ret=%d"), ret);           
  2419     return ret;    
  2457     return ret;    
  2420     }
  2458     }
  2421 
  2459 
  2422 
  2460 
  2423 
  2461 
  2447 // Status : Approved
  2485 // Status : Approved
  2448 // ---------------------------------------------------------
  2486 // ---------------------------------------------------------
  2449           
  2487           
  2450 TInt CSCPServer::IsPasswordChangeAllowedL( CSCPParamObject*& aRetParams )
  2488 TInt CSCPServer::IsPasswordChangeAllowedL( CSCPParamObject*& aRetParams )
  2451     {
  2489     {
  2452     
  2490     Dprint(_L("CSCPServer::IsPasswordChangeAllowedL >>"));
  2453     if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
  2491     if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
  2454     {
  2492     {
  2455     	return KErrNotSupported;
  2493     	return KErrNotSupported;
  2456     }
  2494     }
  2457     TInt ret = KErrNone;
  2495     TInt ret = KErrNone;
  2493 // Checks if phone memory is encrypted or not. 
  2531 // Checks if phone memory is encrypted or not. 
  2494 // ---------------------------------------------------------
  2532 // ---------------------------------------------------------
  2495 TBool CSCPServer::IsDeviceMemoryEncrypted()
  2533 TBool CSCPServer::IsDeviceMemoryEncrypted()
  2496     {
  2534     {
  2497     Dprint(_L("CSCPServer::IsDeviceMemoryEncrypted >>"));
  2535     Dprint(_L("CSCPServer::IsDeviceMemoryEncrypted >>"));
       
  2536     
  2498     TBool ret(EFalse);
  2537     TBool ret(EFalse);
       
  2538     
  2499     //First check if the feature is supported on device
  2539     //First check if the feature is supported on device
  2500     TRAPD(ferr, FeatureManager::InitializeLibL());
  2540     TRAPD(ferr, FeatureManager::InitializeLibL());
  2501     if (ferr != KErrNone)
  2541     if (ferr != KErrNone)
  2502         {
  2542         {
  2503         Dprint(_L("feature mgr initialization error, %d"), ferr);
  2543         Dprint(_L("feature mgr initialization error, %d"), ferr);
  2505         }
  2545         }
  2506     ret = FeatureManager::FeatureSupported( KFeatureIdFfDeviceEncryptionFeature);
  2546     ret = FeatureManager::FeatureSupported( KFeatureIdFfDeviceEncryptionFeature);
  2507     FeatureManager::UnInitializeLib();
  2547     FeatureManager::UnInitializeLib();
  2508  
  2548  
  2509     //If feature is supported, check if any drive is encrypted.
  2549     //If feature is supported, check if any drive is encrypted.
  2510 
       
  2511     
       
  2512             
       
  2513     if (ret)
  2550     if (ret)
  2514         {
  2551         {
  2515         RLibrary library;   
  2552         RLibrary library;   
  2516         CDevEncSessionBase* devEncSession = NULL;
  2553         CDevEncSessionBase* devEncSession = NULL;
  2517         TInt err = library.Load(KDevEncCommonUtils);	 
  2554         TInt err = library.Load(KDevEncCommonUtils);	 
  2589 *
  2626 *
  2590 * @return TInt: KErrNone is successful, otherwise a system error code
  2627 * @return TInt: KErrNone is successful, otherwise a system error code
  2591 */
  2628 */
  2592 TInt CSCPServer :: SetBestPolicyL( TInt aID, const TDesC& aValue, TUint32 aCallerIdentity, CSCPParamDBController* aParamDB ) {
  2629 TInt CSCPServer :: SetBestPolicyL( TInt aID, const TDesC& aValue, TUint32 aCallerIdentity, CSCPParamDBController* aParamDB ) {
  2593     Dprint( (_L("[CSCPServer]-> SetBestPolicyL() >>>")));
  2630     Dprint( (_L("[CSCPServer]-> SetBestPolicyL() >>>")));
  2594     Dprint( (_L("[CSCPServer]-> ParamID=%d "), aID, aValue));
       
  2595     Dprint( (_L("[CSCPServer]-> ParamValue=%d "), aValue));
       
  2596 
       
  2597     TBool lFirstTime(EFalse);
  2631     TBool lFirstTime(EFalse);
  2598     TInt32 lNumValue (-1);
  2632     TInt32 lNumValue (-1);
  2599     TInt32 lNumValDB (-1);
  2633     TInt32 lNumValDB (-1);
  2600     TInt lRetStatus = KErrNone;
  2634     TInt32 lRetStatus = KErrNone;
  2601 
  2635 
  2602     switch(aID) {
  2636     switch(aID) {
  2603         case RTerminalControl3rdPartySession :: ETimeout:
       
  2604         case RTerminalControl3rdPartySession :: EMaxTimeout:
  2637         case RTerminalControl3rdPartySession :: EMaxTimeout:
  2605         case RTerminalControl3rdPartySession :: EPasscodeMinLength:
  2638         case RTerminalControl3rdPartySession :: EPasscodeMinLength:
  2606         case RTerminalControl3rdPartySession :: EPasscodeMaxLength:
  2639         case RTerminalControl3rdPartySession :: EPasscodeMaxLength:
  2607         case RTerminalControl3rdPartySession :: EPasscodeRequireUpperAndLower:
  2640         case RTerminalControl3rdPartySession :: EPasscodeRequireUpperAndLower:
  2608         case RTerminalControl3rdPartySession :: EPasscodeRequireCharsAndNumbers:
  2641         case RTerminalControl3rdPartySession :: EPasscodeRequireCharsAndNumbers:
  2640         lRetStatus = aParamDB->DropValuesL(aID);
  2673         lRetStatus = aParamDB->DropValuesL(aID);
  2641     }
  2674     }
  2642     else {
  2675     else {
  2643         // Fetch the previous value of the parameter from the private database
  2676         // Fetch the previous value of the parameter from the private database
  2644         switch(aID) {
  2677         switch(aID) {
  2645             case RTerminalControl3rdPartySession :: ETimeout:
       
  2646                 // No need to fetch previous value for ETimeout since Stronger/Weaker check is not required for it.
       
  2647                 break;
       
  2648             case RTerminalControl3rdPartySession :: EMaxTimeout:
  2678             case RTerminalControl3rdPartySession :: EMaxTimeout:
  2649             case RTerminalControl3rdPartySession :: EPasscodeMinLength:
  2679             case RTerminalControl3rdPartySession :: EPasscodeMinLength:
  2650             case RTerminalControl3rdPartySession :: EPasscodeMaxLength:
  2680             case RTerminalControl3rdPartySession :: EPasscodeMaxLength:
  2651             case RTerminalControl3rdPartySession :: EPasscodeRequireUpperAndLower:
  2681             case RTerminalControl3rdPartySession :: EPasscodeRequireUpperAndLower:
  2652             case RTerminalControl3rdPartySession :: EPasscodeRequireCharsAndNumbers:
  2682             case RTerminalControl3rdPartySession :: EPasscodeRequireCharsAndNumbers:
  2711 
  2741 
  2712         lRetStatus = KErrNone;
  2742         lRetStatus = KErrNone;
  2713 
  2743 
  2714         // Decision code that verifies if policy is strongest
  2744         // Decision code that verifies if policy is strongest
  2715         switch(aID) {
  2745         switch(aID) {
  2716         case RTerminalControl3rdPartySession :: ETimeout:
       
  2717             /* 
       
  2718              * No need to check stronger/weaker for ETimeout. The value just has to be maintained in both
       
  2719              * DB and the CenRep
       
  2720             */
       
  2721             break;
       
  2722         case RTerminalControl3rdPartySession :: EMaxTimeout:
  2746         case RTerminalControl3rdPartySession :: EMaxTimeout:
  2723         case RTerminalControl3rdPartySession :: EPasscodeMaxRepeatedCharacters:
  2747         case RTerminalControl3rdPartySession :: EPasscodeMaxRepeatedCharacters:
  2724         case RTerminalControl3rdPartySession :: EPasscodeExpiration:
  2748         case RTerminalControl3rdPartySession :: EPasscodeExpiration:
  2725         case RTerminalControl3rdPartySession :: EPasscodeMinChangeTolerance:
  2749         case RTerminalControl3rdPartySession :: EPasscodeMinChangeTolerance:
  2726         case RTerminalControl3rdPartySession :: EPasscodeMinChangeInterval:
  2750         case RTerminalControl3rdPartySession :: EPasscodeMinChangeInterval:
  2770      * from iPluginEventHandler->GetParameters() fails.
  2794      * from iPluginEventHandler->GetParameters() fails.
  2771      * (WriteToFileL() is called in some destructor when the SCPServer terminates) 
  2795      * (WriteToFileL() is called in some destructor when the SCPServer terminates) 
  2772     */
  2796     */
  2773     if (lRetStatus == KErrNone) {
  2797     if (lRetStatus == KErrNone) {
  2774         switch (aID) {
  2798         switch (aID) {
  2775         case RTerminalControl3rdPartySession :: ETimeout:
       
  2776             lRetStatus = SetAutolockPeriodL(TInt(lNumValue));
       
  2777             Dprint(_L("[CSCPServer]-> After setting ETimeout lRetStatus = %d "), lRetStatus);
       
  2778             break;
       
  2779 			
       
  2780         case RTerminalControl3rdPartySession :: EMaxTimeout:
  2799         case RTerminalControl3rdPartySession :: EMaxTimeout:
  2781             iConfiguration.iMaxTimeout = lNumValue;
  2800             iConfiguration.iMaxTimeout = lNumValue;
  2782             lRetStatus = iConfiguration.WriteSetupL();
  2801             lRetStatus = iConfiguration.WriteSetupL();
  2783             Dprint(_L("[CSCPServer]-> After setting EMaxTimeout lRetStatus = %d "), lRetStatus);
  2802             Dprint(_L("[CSCPServer]-> After setting EMaxTimeout lRetStatus = %d "), lRetStatus);
  2784             break;
  2803             break;
  2785 			
       
  2786         default:
  2804         default:
  2787             TUint16* ptr = const_cast<TUint16*>(aValue.Ptr());
  2805             TUint16* ptr = const_cast<TUint16*>(aValue.Ptr());
  2788             TPtr valBuf(ptr, aValue.Length(), aValue.Length());
  2806             TPtr valBuf(ptr, aValue.Length(), aValue.Length());
  2789             lRetStatus = iPluginEventHandler->GetParameters().Set(aID, valBuf);
  2807             lRetStatus = iPluginEventHandler->GetParameters().Set(aID, valBuf);
  2790             Dprint(_L("[CSCPServer]-> After setting (%d ) lRetStatus = %d "), aID, lRetStatus);
  2808             Dprint(_L("[CSCPServer]-> After setting (%d ) lRetStatus = %d "), aID, lRetStatus);
  2875                 lParamIds[lMinTolIndex] = RTerminalControl3rdPartySession :: EPasscodeHistoryBuffer;
  2893                 lParamIds[lMinTolIndex] = RTerminalControl3rdPartySession :: EPasscodeHistoryBuffer;
  2876                 Dprint(_L("[CSCPServer]-> Switching the cleanup order of EPasscodeHistoryBuffer and EPasscodeMinChangeTolerance"));
  2894                 Dprint(_L("[CSCPServer]-> Switching the cleanup order of EPasscodeHistoryBuffer and EPasscodeMinChangeTolerance"));
  2877                 Dprint(_L("[CSCPServer]-> Old Index of EPasscodeHistoryBuffer=%d"), lHistBuffIndex);
  2895                 Dprint(_L("[CSCPServer]-> Old Index of EPasscodeHistoryBuffer=%d"), lHistBuffIndex);
  2878                 Dprint(_L("[CSCPServer]-> Old Index of EPasscodeMinChangeTolerance=%d"), lMinTolIndex);
  2896                 Dprint(_L("[CSCPServer]-> Old Index of EPasscodeMinChangeTolerance=%d"), lMinTolIndex);
  2879             }
  2897             }
  2880 			
       
  2881             /*
       
  2882              * If both ETimeout and EMaxTimeout are marked for cleanup then interchange the cleanup order of 
       
  2883              * ETimeout and EMaxTimeout since AutoLock (ETimeout) cannot be disabled
       
  2884              * if MaxAutolock (EMaxTimeout) is still enabled
       
  2885              */
       
  2886             if( lParamIds[0] == RTerminalControl3rdPartySession :: ETimeout &&
       
  2887                 lParamIds[1] == RTerminalControl3rdPartySession :: EMaxTimeout) {
       
  2888             
       
  2889                 lParamIds[0] = RTerminalControl3rdPartySession :: EMaxTimeout;
       
  2890                 lParamIds[1] = RTerminalControl3rdPartySession :: ETimeout;
       
  2891             }
       
  2892        	}
  2898        	}
  2893 
  2899 
  2894         for(TInt j=0; j < lCount; j++) {
  2900         for(TInt j=0; j < lCount; j++) {
  2895             TInt lCurrParamID = lParamIds[j];            
  2901             TInt lCurrParamID = lParamIds[j];            
  2896             lDefValueBuf->Des().Zero();
  2902             lDefValueBuf->Des().Zero();
  2897             lDefValueBuf->Des().Format(_L("%d "), 0);
  2903             lDefValueBuf->Des().Format(_L("%d "), 0);
  2898 			
       
  2899             // Initialize the default values here...
  2904             // Initialize the default values here...
  2900             switch(lCurrParamID) {
  2905             switch(lCurrParamID) {
  2901                 case RTerminalControl3rdPartySession :: ETimeout:
       
  2902                     // lDefValueBuf already has the default value, 0 initialized...
       
  2903                     lCurrParamID = ESCPAutolockPeriod;
       
  2904                     break;
       
  2905                 case RTerminalControl3rdPartySession :: EMaxTimeout:
  2906                 case RTerminalControl3rdPartySession :: EMaxTimeout:
  2906                     // lDefValueBuf already has the default value, 0 initialized...
  2907                     // lDefValueBuf already has the default value, 0 initialized...
  2907                     lCurrParamID = ESCPMaxAutolockPeriod;
  2908                     lCurrParamID = ESCPMaxAutolockPeriod;
  2908                     break;
  2909                     break;
  2909                 case RTerminalControl3rdPartySession :: EPasscodeMinLength:
  2910                 case RTerminalControl3rdPartySession :: EPasscodeMinLength:
  2928                         iOverrideForCleanup = ETrue;
  2929                         iOverrideForCleanup = ETrue;
  2929                     TInt lDesCount = lDesArr.Count();
  2930                     TInt lDesCount = lDesArr.Count();
  2930                         
  2931                         
  2931                         for(TInt k=0; k < lDesCount; k++) {
  2932                         for(TInt k=0; k < lDesCount; k++) {
  2932                             TRAP(lStatus, lStatus = SetParameterValueL(lCurrParamID, lDesArr[k]->Des(), lAppID));
  2933                             TRAP(lStatus, lStatus = SetParameterValueL(lCurrParamID, lDesArr[k]->Des(), lAppID));
  2933 							
       
  2934                             if(KErrNone != lStatus) {
  2934                             if(KErrNone != lStatus) {
  2935                                 Dprint(_L("[CSCPServer]-> ERROR: Unable to cleanup parameter %d error %d"), lParamIds[j], lStatus);
  2935                                 Dprint(_L("[CSCPServer]-> ERROR: Unable to cleanup parameter %d error %d"), lParamIds[j], lStatus);
  2936                                 lSubOpsFailed = ETrue;
  2936                                 lSubOpsFailed = ETrue;
  2937                             }
  2937                             }
  2938                         }
  2938                         }
  2942                     
  2942                     
  2943                     lDesArr.ResetAndDestroy();
  2943                     lDesArr.ResetAndDestroy();
  2944                     CleanupStack :: PopAndDestroy(1); // lDesArray
  2944                     CleanupStack :: PopAndDestroy(1); // lDesArray
  2945                 }
  2945                 }
  2946                 break;
  2946                 break;
  2947 				
       
  2948                 case ESCPAutolockPeriod: {
       
  2949                     TInt32 lParamValueDB(0);
       
  2950                     TInt lParamValueCenRep(0);
       
  2951                     TInt32 lCurrParamOwner(0);
       
  2952 					
       
  2953                     lStatus = lParamDB->GetValueL(RTerminalControl3rdPartySession :: ETimeout, lParamValueDB, lCurrParamOwner);
       
  2954 					
       
  2955                     if(lStatus != KErrNone) {
       
  2956                         Dprint(_L("[CSCPServer]-> ERROR: Unable to get current value of ETimeout from DB..."));
       
  2957                         lSubOpsFailed = ETrue;
       
  2958                         break;
       
  2959                     }
       
  2960 					
       
  2961                     lStatus = GetAutolockPeriodL(lParamValueCenRep);
       
  2962 					
       
  2963                     if(lStatus != KErrNone) {
       
  2964                         Dprint(_L("[CSCPServer]-> ERROR: Unable to get current value of ETimeout from CenRep..."));
       
  2965                         lSubOpsFailed = ETrue;
       
  2966                         break;
       
  2967                     }
       
  2968                     
       
  2969                     /*
       
  2970                      *  It is possible that AutoLock set from UI is different. In that case internal DB and CenRep 
       
  2971                      *  are not in sync. Compare the two values and if they are same assume that the values are in sync.
       
  2972                      *  Limitation is that if the user sets the AutoLock with the same value as set by the current app then
       
  2973                      *  AutoLock will get disabled.
       
  2974                      *  
       
  2975                     */
       
  2976                     if(lParamValueCenRep != lParamValueDB) {
       
  2977                         break;
       
  2978                     }
       
  2979                 }
       
  2980 				
       
  2981                 default: {
  2947                 default: {
  2982                     iOverrideForCleanup = ETrue;
  2948                     iOverrideForCleanup = ETrue;
  2983                     TRAP(lStatus, lStatus = SetParameterValueL(lCurrParamID, lDefValueBuf->Des(), lAppID));
  2949                     TRAP(lStatus, lStatus = SetParameterValueL(lCurrParamID, lDefValueBuf->Des(), lAppID));
  2984                     iOverrideForCleanup = EFalse;
  2950                     iOverrideForCleanup = EFalse;
  2985     
  2951     
  2992                         
  2958                         
  2993                         // No need to destroy lTmpBuffer, it will be cleaned up by the caller (on cleanup of aParamValArray)
  2959                         // No need to destroy lTmpBuffer, it will be cleaned up by the caller (on cleanup of aParamValArray)
  2994                         aParamValArray.AppendL(lTmpBuffer);
  2960                         aParamValArray.AppendL(lTmpBuffer);
  2995                     }
  2961                     }
  2996                 }
  2962                 }
  2997                 break;
  2963             }
  2998             };
       
  2999             
  2964             
  3000             if(KErrNone != lStatus) {
  2965             if(KErrNone != lStatus) {
  3001                 Dprint(_L("[CSCPServer]-> ERROR: Unable to cleanup parameter %d error %d"), lParamIds[j], lStatus);
  2966                 Dprint(_L("[CSCPServer]-> ERROR: Unable to cleanup parameter %d error %d"), lParamIds[j], lStatus);
  3002                 lSubOpsFailed = ETrue;
  2967                 lSubOpsFailed = ETrue;
  3003             }
  2968             }
  3007     Dprint( (_L("[CSCPServer]-> PerformCleanupL() <<<")));
  2972     Dprint( (_L("[CSCPServer]-> PerformCleanupL() <<<")));
  3008     CleanupStack :: PopAndDestroy(4); // lParamIds lParamDB lBufReadStream lDefValueBuf
  2973     CleanupStack :: PopAndDestroy(4); // lParamIds lParamDB lBufReadStream lDefValueBuf
  3009     return (lSubOpsFailed) ? KErrGeneral : KErrNone;
  2974     return (lSubOpsFailed) ? KErrGeneral : KErrNone;
  3010 }
  2975 }
  3011 
  2976 
       
  2977 void CSCPServer :: GetPoliciesL(HBufC8* aAppIDBuffer, TUint32 aCallerIdentity) {
       
  2978     TInt lValue;
       
  2979     TInt lRet = KErrNone;
       
  2980     TBuf<25> lParamValBuf;
       
  2981     TPtr8 lBufPtr = aAppIDBuffer->Des();
       
  2982     RDesWriteStream lWriteStream(lBufPtr);
       
  2983     CleanupClosePushL(lWriteStream);
       
  2984     
       
  2985     lRet = GetAutolockPeriodL(lValue);
       
  2986     
       
  2987     if(lRet != KErrNone) {
       
  2988         User :: Leave(lRet);
       
  2989     }
       
  2990     
       
  2991     Dprint((_L("[CSCPServer]-> appending AutoLockPeriod value=%d"), lValue));
       
  2992     lWriteStream.WriteInt32L(lValue);    
       
  2993     
       
  2994     Dprint((_L("[CSCPServer]-> appending MaxAutoLockPeriod value=%d"), iConfiguration.iMaxTimeout));
       
  2995     lWriteStream.WriteInt32L(iConfiguration.iMaxTimeout);
       
  2996     
       
  2997     if(FeatureManager :: FeatureSupported(KFeatureIdSapDeviceLockEnhancements)) {
       
  2998         Dprint(_L("[CSCPServer]-> (FeatureManager :: FeatureSupported() complete. Fetching values now..."));
       
  2999         /* Fetch parameters starting from RTerminalControl3rdPartySession :: EPasscodeMinLength to 
       
  3000          * RTerminalControl3rdPartySession :: EPasscodeMinChangeInterval
       
  3001          */
       
  3002         TInt lPID = RTerminalControl3rdPartySession :: EPasscodeMinLength;
       
  3003         
       
  3004         for(; lPID <= RTerminalControl3rdPartySession :: EPasscodeDisallowSimple; lPID++) {
       
  3005             switch(lPID) {
       
  3006                 default:
       
  3007                     break;
       
  3008                 case RTerminalControl3rdPartySession :: EPasscodeCheckSpecificStrings:
       
  3009                 case RTerminalControl3rdPartySession :: EPasscodeAllowSpecific:
       
  3010                 case RTerminalControl3rdPartySession :: EPasscodeClearSpecificStrings:
       
  3011                     // No need to fetch these three parameters
       
  3012                     continue;
       
  3013                 case RTerminalControl3rdPartySession :: EPasscodeDisallowSpecific:
       
  3014                     Dprint(_L("[CSCPServer]-> appending EPasscodeDisallowSpecific value..."));
       
  3015                     // Get on EPasscodeDisallowSpecific returning -1 instead
       
  3016                     lWriteStream.WriteInt32L(-1);
       
  3017                     continue;
       
  3018                 case RTerminalControl3rdPartySession :: EPasscodeDisallowSimple:
       
  3019                     Dprint(_L("[CSCPServer]-> appending EPasscodeDisallowSimple value..."));
       
  3020                     lWriteStream.WriteInt32L(1);
       
  3021                     lWriteStream.WriteInt32L(1);
       
  3022                     continue;
       
  3023             }
       
  3024             
       
  3025             //lRet = GetParameterValueL(lPID, lParamValBuf, aCallerIdentity);
       
  3026             lRet = iPluginEventHandler->GetParameters().Get(lPID, lValue);
       
  3027             
       
  3028             switch(lRet) {
       
  3029                 
       
  3030                 
       
  3031                 case KErrNotFound: {
       
  3032                     switch(lPID) {
       
  3033                         case RTerminalControl3rdPartySession :: EPasscodeMinLength:
       
  3034                             lValue = KSCPPasscodeMinLength;
       
  3035                             break;
       
  3036                         case RTerminalControl3rdPartySession :: EPasscodeMaxLength:
       
  3037                             lValue = KSCPPasscodeMaxLength;
       
  3038                             break;
       
  3039                         default:
       
  3040                             lValue = 0;
       
  3041                             break;
       
  3042                     }
       
  3043                 }
       
  3044                 break;
       
  3045                 case KErrNone: {
       
  3046 //                    TLex lLex(lParamValBuf);
       
  3047 //                    lRet = lLex.Val(lValue);                    
       
  3048 //                    User :: LeaveIfError(lRet);
       
  3049                 }
       
  3050                 break;
       
  3051                 default:
       
  3052                     User :: Leave(lRet);
       
  3053             }
       
  3054             
       
  3055             Dprint((_L("[CSCPServer]-> appending value for lPID=%d"), lPID));
       
  3056             Dprint((_L("[CSCPServer]-> lValue=%d"), lValue));            
       
  3057             
       
  3058             switch(lPID) {
       
  3059                 default:
       
  3060                     lWriteStream.WriteInt32L(lValue);
       
  3061                     break;
       
  3062                 case RTerminalControl3rdPartySession :: EPasscodeDisallowSimple:
       
  3063                     lWriteStream.WriteInt32L(1);
       
  3064                     lWriteStream.WriteInt32L(1);
       
  3065                     break;
       
  3066             }
       
  3067         }
       
  3068     }
       
  3069     else {
       
  3070         Dprint(_L("[CSCPServer]-> (FeatureManager :: FeatureSupported() failed!!..."));
       
  3071     }
       
  3072     
       
  3073     CleanupStack :: PopAndDestroy(1); // lWriteStream
       
  3074 }
       
  3075 
       
  3076 TInt CSCPServer :: ValidateLockcodeAgainstPoliciesL(TDes& aLockcode, CSCPParamObject*& aRetParams) {
       
  3077     Dprint( (_L("[CSCPServer]-> ValidateLockcodeAgainstPoliciesL() >>>")));
       
  3078     
       
  3079     TInt ret = KErrNone;
       
  3080     CSCPParamObject* inParams = CSCPParamObject :: NewL();
       
  3081     inParams->Set(KSCPParamPassword, aLockcode);
       
  3082     CSCPParamObject* repParams = iPluginManager->PostEvent(KSCPEventValidate, *inParams);
       
  3083     delete inParams;
       
  3084     
       
  3085     if (repParams != NULL) {
       
  3086         // Check if the validation failed
       
  3087         TInt status;
       
  3088         
       
  3089         if (repParams->Get(KSCPParamStatus, status) == KErrNone) {
       
  3090             if (status != KErrNone) {
       
  3091                 ret = status;
       
  3092             }
       
  3093         }
       
  3094         
       
  3095         aRetParams = repParams; // pointer ownership changed
       
  3096     }
       
  3097     
       
  3098     Dprint( (_L("[CSCPServer]-> ValidateLockcodeAgainstPoliciesL() <<<")));
       
  3099     return ret;
       
  3100 }
       
  3101 
  3012 //#endif //  __SAP_DEVICE_LOCK_ENHANCEMENTS
  3102 //#endif //  __SAP_DEVICE_LOCK_ENHANCEMENTS
  3013 // <<<< ********************** NEW FEATURES ********************
  3103 // <<<< ********************** NEW FEATURES ********************
  3014 
  3104 
  3015 // ================= OTHER EXPORTED FUNCTIONS ==============
  3105 // ================= OTHER EXPORTED FUNCTIONS ==============
  3016 
  3106