terminalsecurity/SCP/SCPServer/src/SCPServer.cpp
changeset 24 bf47f3b79154
parent 22 19fb38abab1d
child 32 5d0ec111abfc
equal deleted inserted replaced
22:19fb38abab1d 24:bf47f3b79154
    49 
    49 
    50 #include "SCPDebug.h"
    50 #include "SCPDebug.h"
    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 <DevEncSession.h>
    54 #include <DevEncSessionBase.h>
    55 
    55 
    56 // ==================== LOCAL FUNCTIONS ====================
    56 // ==================== LOCAL FUNCTIONS ====================
    57 
    57 
    58 // ---------------------------------------------------------
    58 // ---------------------------------------------------------
    59 // PanicServer Panics the server thread
    59 // PanicServer Panics the server thread
   112        
   112        
   113     iConfiguration.Initialize();
   113     iConfiguration.Initialize();
   114     
   114     
   115     // Assign default config flag
   115     // Assign default config flag
   116     iConfiguration.iConfigFlag = KSCPConfigUnknown;
   116     iConfiguration.iConfigFlag = KSCPConfigUnknown;
       
   117     iConfiguration.iConfigChecked = EFalse;
   117     
   118     
   118     // Assign the default codes
   119     // Assign the default codes
   119     iConfiguration.iSecCode.Zero();
   120     iConfiguration.iSecCode.Zero();
   120     iConfiguration.iSecCode.Append( KSCPDefaultSecCode );
   121     iConfiguration.iSecCode.Append( KSCPDefaultSecCode );
       
   122 
       
   123     // Assign the default codes
       
   124     iConfiguration.iCryptoCode.Zero();
       
   125     iConfiguration.iCryptoCode.Append( KSCPDefaultSecCode );
   121 
   126 
   122 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS 
   127 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS 
   123 if(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
   128 if(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
   124 {
   129 {
   125     // Reset code block parameters
   130     // Reset code block parameters
   162         }         
   167         }         
   163     else
   168     else
   164         {
   169         {
   165         Dprint( (_L("CSCPServer::ConstructL(): Configration read OK") ));
   170         Dprint( (_L("CSCPServer::ConstructL(): Configration read OK") ));
   166         }
   171         }
       
   172     
       
   173     
       
   174     //If Configuration is not validated already, validate it
       
   175     
       
   176     if (!iConfiguration.iConfigChecked)
       
   177         {
       
   178         TInt valerr = KErrNone;
       
   179         TRAP( valerr, ValidateConfigurationL( KSCPComplete ));
       
   180         if (valerr != KErrNone)
       
   181             {
       
   182             Dprint( (_L("CSCPServer::ConstructL(): Configuration Validation failed: %d"), valerr ));
       
   183             }
       
   184         else
       
   185             {
       
   186             Dprint( (_L("CSCPServer::ConstructL(): Configuration Validation Passed")));
       
   187             }
       
   188         }
       
   189     
       
   190         
   167         
   191         
   168     Dprint( (_L("CSCPServer::ConstructL(): Connecting to CenRep") ));
   192     Dprint( (_L("CSCPServer::ConstructL(): Connecting to CenRep") ));
   169     iALPeriodRep = CRepository::NewL( KCRUidSecuritySettings );        
   193     iALPeriodRep = CRepository::NewL( KCRUidSecuritySettings );        
   170     
   194     
   171     // Check for factory settings
   195     // Check for factory settings
   629 //	
   653 //	
   630 void CSCPServer::ValidateConfigurationL( TInt aMode )
   654 void CSCPServer::ValidateConfigurationL( TInt aMode )
   631     {
   655     {
   632     Dprint( (_L("--> CSCPServer::ValidateConfigurationL()") ));
   656     Dprint( (_L("--> CSCPServer::ValidateConfigurationL()") ));
   633     
   657     
   634     if ( iConfiguration.iConfigFlag == KSCPConfigOK )
   658 	RMobilePhone::TMobilePassword storedCode;
       
   659     storedCode.Zero();
       
   660     User::LeaveIfError(GetCode(storedCode));
       
   661     
       
   662     
       
   663 	Dprint( (_L("CSCPServer::ValidateConfigurationL(): Checking code: %s"), storedCode.PtrZ() ));
       
   664 	// Check that the ISA code is stored correctly
       
   665 	TRAPD( err, CheckISACodeL( storedCode ) );
       
   666 	 //Bool for the correction of Defaultlockcode cenrep
       
   667     TBool lCorrectDefaultlockcode = EFalse;
       
   668     
       
   669      Dprint( (_L("CSCPServer::ValidateConfigurationL(): iConfigFlag = %d, iConfigChecked = %d"), iConfiguration.iConfigFlag, iConfiguration.iConfigChecked));
       
   670      
       
   671     if ((iConfiguration.iConfigFlag == KSCPConfigOK)
       
   672             && (iConfiguration.iConfigChecked) && (err == KErrNone))
   635         {
   673         {
   636         // The configuration has already been checked, exit
   674         // The configuration has already been checked, exit
   637         Dprint( (_L("CSCPServer::ValidateConfigurationL(): Configuration is non-default.") ));
   675         Dprint( (_L("CSCPServer::ValidateConfigurationL(): Configuration is non-default.") ));
   638         return;
   676         User::Leave( KErrNone );
   639         }
   677         }
   640     else if ( aMode == KSCPInitial )
   678     else if ( aMode == KSCPInitial )
   641         {
   679         {
   642         // Return here, must be checked by complete mode
   680         // Return here, must be checked by complete mode
   643         User::Leave( KErrAccessDenied );
   681         User::Leave( KErrAccessDenied );
   644         }
   682         }
   645     
   683     
   646     RMobilePhone::TMobilePassword storedCode;
   684    
   647     storedCode.Zero();
       
   648     
       
   649     User::LeaveIfError( GetCode( storedCode ) );
       
   650     TInt hashedISAcode;
   685     TInt hashedISAcode;
   651     TSCPSecCode hashedCode;
   686     TSCPSecCode hashedCode;
   652 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS    
   687 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS    
   653 if(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
   688 if(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
   654 {
   689 {
   657     hashedCode.Zero();
   692     hashedCode.Zero();
   658     hashedCode.AppendNum( hashedISAcode );
   693     hashedCode.AppendNum( hashedISAcode );
   659 }
   694 }
   660 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS    
   695 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS    
   661             
   696             
   662     Dprint( (_L("CSCPServer::ValidateConfigurationL(): Checking code: %s"), storedCode.PtrZ() ));
   697     
   663     
   698     
   664     // Check that the ISA code is stored correctly
   699    
   665     TRAPD( err, CheckISACodeL( storedCode ) );
   700     if (err != KErrNone)
       
   701         {
       
   702         lCorrectDefaultlockcode = ETrue;
       
   703         }
   666     if ( err == KErrNone ) 
   704     if ( err == KErrNone ) 
   667         {
   705         {
   668         iConfiguration.iConfigFlag = KSCPConfigOK;
   706         iConfiguration.iConfigFlag = KSCPConfigOK;
   669         }
   707         }
   670     else if ( err == KErrAccessDenied )
   708     else if ( err == KErrAccessDenied )
   708                Storing hashed code(%d)"), hashedISAcode ));
   746                Storing hashed code(%d)"), hashedISAcode ));
   709                
   747                
   710             if ( StoreCode( hashedCode ) == KErrNone )
   748             if ( StoreCode( hashedCode ) == KErrNone )
   711                 {
   749                 {
   712                 iConfiguration.iConfigFlag = KSCPConfigOK;
   750                 iConfiguration.iConfigFlag = KSCPConfigOK;
       
   751                 lCorrectDefaultlockcode = ETrue;
   713                 }
   752                 }
   714             }        
   753             }        
   715         }
   754         }
   716 }
   755     
       
   756     //If Correction of Defaultlockcode cenrep is required for the mismatch between Config and ISA
       
   757         if (lCorrectDefaultlockcode)
       
   758             {
       
   759             TInt lDefCode = -1;
       
   760             CRepository* lRepository = CRepository::NewL(KCRUidSCPLockCode);
       
   761             CleanupStack::PushL(lRepository);
       
   762             TInt lRet = lRepository->Get(KSCPLockCodeDefaultLockCode,
       
   763                     lDefCode);
       
   764             if (lRet == KErrNone && lDefCode != -1)
       
   765                 {
       
   766                 if (lDefCode == 12345)
       
   767                     {
       
   768                     //Although lock code is already set, due to some unexpected condition
       
   769                     //like C drive wipe, cenrep status is wrongly shown. Correcting it here.
       
   770                     lRepository->Set(KSCPLockCodeDefaultLockCode, 0);
       
   771                     Dprint( (_L("RSCPClient::ValidateConfigurationL(): Corrected the Default lock code cenrep status to 0") ));
       
   772                     }
       
   773                 else if (lDefCode == 0)
       
   774                     {
       
   775                     //If only ISA side is formatted, then the lock code on ISA side is default; 
       
   776                     //Cenrep status remains wrongly as the lock code is already set. Correcting it here.
       
   777                     lRepository->Set(KSCPLockCodeDefaultLockCode, 12345);
       
   778                     Dprint( (_L("RSCPClient::ValidateConfigurationL(): Corrected the Default lock code cenrep status to 12345") ));
       
   779                     }
       
   780                 }
       
   781             CleanupStack::PopAndDestroy(lRepository);
       
   782             }
       
   783         }
   717 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS
   784 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS
       
   785     //Set the flag to True, after config is validated 
       
   786     iConfiguration.iConfigChecked = ETrue;
   718     
   787     
   719     TRAPD( err2, iConfiguration.WriteSetupL() );
   788     TRAPD( err2, iConfiguration.WriteSetupL() );
   720     if ( err2 != KErrNone )
   789     if ( err2 != KErrNone )
   721         {
   790         {
   722         Dprint( (_L("CSCPServer::ValidateConfigurationL(): WARNING: failed to write configuration\
   791         Dprint( (_L("CSCPServer::ValidateConfigurationL(): WARNING: failed to write configuration\
  1679                     }
  1748                     }
  1680                 } 
  1749                 } 
  1681             
  1750             
  1682             if ( getFromCommonStorage )
  1751             if ( getFromCommonStorage )
  1683                 {
  1752                 {
       
  1753                 Dprint(_L("[CSCPServer]-> Fetching from Common storage..."));
  1684                 // OK, no objection, so try to get the value from common storage
  1754                 // OK, no objection, so try to get the value from common storage
  1685                 ret = iPluginEventHandler->GetParameters().Get( aID, aValue );
  1755                 ret = iPluginEventHandler->GetParameters().Get( aID, aValue );
  1686                 }            
  1756                 }            
  1687             
  1757             
  1688             if ( repParams != NULL )
  1758             if ( repParams != NULL )
  1991 // Status : Approved
  2061 // Status : Approved
  1992 // ---------------------------------------------------------
  2062 // ---------------------------------------------------------
  1993 //  
  2063 //  
  1994 TInt CSCPServer::IsCorrectEnhCode( TDes& aCode, TInt aFlags )
  2064 TInt CSCPServer::IsCorrectEnhCode( TDes& aCode, TInt aFlags )
  1995     {
  2065     {
  1996     
  2066     Dprint( (_L("CSCPServer::IsCorrectEnhCode") ));
  1997     if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
  2067     if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
  1998     {
  2068     {
  1999     	return KErrNotSupported;
  2069     	return KErrNotSupported;
  2000     }
  2070     }
  2001     TInt ret = KErrAccessDenied;
  2071     TInt ret = KErrAccessDenied;
  2164             {
  2234             {
  2165             Dprint( (_L("CSCPServer::IsCorrectEnhCode(): WARNING:\
  2235             Dprint( (_L("CSCPServer::IsCorrectEnhCode(): WARNING:\
  2166                 failed to write configuration: %d"), err ));                                        
  2236                 failed to write configuration: %d"), err ));                                        
  2167             }                 
  2237             }                 
  2168         }
  2238         }
  2169         
  2239     Dprint( (_L("CSCPServer::IsCorrectEnhCode %d"), ret )); 
  2170     return ret;
  2240     return ret;
  2171     }
  2241     }
  2172     
  2242     
  2173 
  2243 
  2174 
  2244 
  2285 TInt CSCPServer::CheckAndChangeEnhCodeL( TDes& aOldPass, 
  2355 TInt CSCPServer::CheckAndChangeEnhCodeL( TDes& aOldPass, 
  2286                                         TDes& aNewPass,
  2356                                         TDes& aNewPass,
  2287                                         CSCPParamObject*& aRetParams,
  2357                                         CSCPParamObject*& aRetParams,
  2288                                         TSCPSecCode& aNewDOSCode )
  2358                                         TSCPSecCode& aNewDOSCode )
  2289     {        
  2359     {        
  2290     
  2360     Dprint(_L("CSCPServer::CheckAndChangeEnhCodeL >>"));
  2291     if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
  2361     if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
  2292     {
  2362     {
  2293     	return KErrNotSupported;
  2363     	return KErrNotSupported;
  2294     }
  2364     }
  2295     TInt ret = KErrNone;
  2365     TInt ret = KErrNone;
  2304         inParams->Set( KSCPParamStatus, KErrNone ); 
  2374         inParams->Set( KSCPParamStatus, KErrNone ); 
  2305         inParams->Set( KSCPParamContext, KSCPContextChangePsw );
  2375         inParams->Set( KSCPParamContext, KSCPContextChangePsw );
  2306         CSCPParamObject* repParams = 
  2376         CSCPParamObject* repParams = 
  2307             iPluginManager->PostEvent( KSCPEventAuthenticationAttempted, *inParams );
  2377             iPluginManager->PostEvent( KSCPEventAuthenticationAttempted, *inParams );
  2308         
  2378         
  2309         if ( repParams != NULL )            
  2379         if ( repParams != NULL ) {
       
  2380             // Ignore the return params at this point
       
  2381             delete repParams;
       
  2382        	}  
       
  2383 		
       
  2384         CleanupStack::PopAndDestroy(inParams);
       
  2385         
       
  2386         ret = ValidateLockcodeAgainstPoliciesL(aNewPass, aRetParams);
       
  2387         
       
  2388         if(ret != KErrNone) {
       
  2389             Dprint(_L("[CSCPServer]-> ValidateLockcodeAgainstPoliciesL() failed in CheckAndChangeEnhCodeL() ret=%d"), ret);
       
  2390             return ret;
       
  2391         }
       
  2392 
       
  2393 
       
  2394         if ( IsValidEnhCode( aNewPass ) )
       
  2395             {
       
  2396             ret = StoreEnhCode( aNewPass, &aNewDOSCode );
       
  2397             }                        
       
  2398         else
       
  2399             {
       
  2400             // Invalid code format! Should not happen at this point, but make sure.
       
  2401             ret = KErrArgument; 
       
  2402             }
       
  2403             
       
  2404         if ( ret == KErrNone )
       
  2405             {
       
  2406             CSCPParamObject* inParams = CSCPParamObject::NewL();
       
  2407             CleanupStack::PushL( inParams );
       
  2408             inParams->Set( KSCPParamPassword, aNewPass );
       
  2409     
       
  2410             CSCPParamObject* repParams = 
       
  2411                 iPluginManager->PostEvent( KSCPEventPasswordChanged, *inParams );
       
  2412     
       
  2413             CleanupStack::PopAndDestroy( inParams );
       
  2414         
       
  2415             if ( repParams != NULL )            
  2310                 {
  2416                 {
  2311                 // Ignore the return params at this point
  2417                 // Ignore the return params at this point
  2312                 delete repParams;
  2418                 delete repParams;
  2313                 }  
       
  2314                 
       
  2315         inParams->Reset();
       
  2316         
       
  2317         // Validate the code                
       
  2318         inParams->Set( KSCPParamPassword, aNewPass );
       
  2319         
       
  2320         repParams = iPluginManager->PostEvent( KSCPEventValidate, *inParams );
       
  2321         
       
  2322         CleanupStack::PopAndDestroy( inParams );
       
  2323         
       
  2324         if ( repParams != NULL )
       
  2325             {
       
  2326             // Check if the validation failed
       
  2327             TInt status;
       
  2328             if ( repParams->Get( KSCPParamStatus, status ) == KErrNone )
       
  2329                 {
       
  2330                 if ( status != KErrNone )
       
  2331                     {
       
  2332                     ret = status;
       
  2333                     }
       
  2334                 }
  2419                 }
  2335                 
       
  2336             aRetParams = repParams; // pointer ownership changed                           
       
  2337             }
       
  2338         
       
  2339         // Set the new code, if it was OK
       
  2340         if ( ret == KErrNone )
       
  2341             {
       
  2342             if ( IsValidEnhCode( aNewPass ) )
       
  2343                 {
       
  2344                 ret = StoreEnhCode( aNewPass, &aNewDOSCode );
       
  2345                 }                        
       
  2346             else
       
  2347                 {
       
  2348                 // Invalid code format! Should not happen at this point, but make sure.
       
  2349                 ret = KErrArgument; 
       
  2350                 }
       
  2351             
       
  2352             if ( ret == KErrNone )
       
  2353                 {
       
  2354                 CSCPParamObject* inParams = CSCPParamObject::NewL();
       
  2355                 CleanupStack::PushL( inParams );
       
  2356                 inParams->Set( KSCPParamPassword, aNewPass );
       
  2357         
       
  2358                 CSCPParamObject* repParams = 
       
  2359                     iPluginManager->PostEvent( KSCPEventPasswordChanged, *inParams );
       
  2360         
       
  2361                 CleanupStack::PopAndDestroy( inParams );
       
  2362             
       
  2363                 if ( repParams != NULL )            
       
  2364                     {
       
  2365                     // Ignore the return params at this point
       
  2366                     delete repParams;
       
  2367                     }
       
  2368                 }       
       
  2369             }
  2420             }
  2370         }    
  2421         }    
  2371     else
  2422     else
  2372         {
  2423         {
  2373         if ( ( ret == KErrAccessDenied ) || ( ret == KSCPErrCodeBlockStarted ) )
  2424         if ( ( ret == KErrAccessDenied ) || ( ret == KSCPErrCodeBlockStarted ) )
  2393                 {
  2444                 {
  2394         	    ret = KErrLocked; // Set this as the external error code
  2445         	    ret = KErrLocked; // Set this as the external error code
  2395                 }                            
  2446                 }                            
  2396             }
  2447             }
  2397         }
  2448         }
  2398                 
  2449     Dprint(_L("[CSCPServer]-> CheckAndChangeEnhCodeL ret=%d"), ret);           
  2399     return ret;    
  2450     return ret;    
  2400     }
  2451     }
  2401 
  2452 
  2402 
  2453 
  2403 
  2454 
  2427 // Status : Approved
  2478 // Status : Approved
  2428 // ---------------------------------------------------------
  2479 // ---------------------------------------------------------
  2429           
  2480           
  2430 TInt CSCPServer::IsPasswordChangeAllowedL( CSCPParamObject*& aRetParams )
  2481 TInt CSCPServer::IsPasswordChangeAllowedL( CSCPParamObject*& aRetParams )
  2431     {
  2482     {
  2432     
  2483     Dprint(_L("CSCPServer::IsPasswordChangeAllowedL >>"));
  2433     if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
  2484     if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
  2434     {
  2485     {
  2435     	return KErrNotSupported;
  2486     	return KErrNotSupported;
  2436     }
  2487     }
  2437     TInt ret = KErrNone;
  2488     TInt ret = KErrNone;
  2489     FeatureManager::UnInitializeLib();
  2540     FeatureManager::UnInitializeLib();
  2490  
  2541  
  2491     //If feature is supported, check if any drive is encrypted.
  2542     //If feature is supported, check if any drive is encrypted.
  2492     if (ret)
  2543     if (ret)
  2493         {
  2544         {
  2494         CDevEncSession* devEncSession = new CDevEncSession( EDriveC );
  2545         RLibrary library;   
  2495         
  2546         CDevEncSessionBase* devEncSession = NULL;
       
  2547         TInt err = library.Load(KDevEncCommonUtils);	 
       
  2548         
       
  2549         if (err != KErrNone)
       
  2550             {
       
  2551             Dprint(_L("Error in finding the library... %d"), err);
       
  2552             ret = EFalse;
       
  2553             }
       
  2554         else
       
  2555         	{
       
  2556 		       TLibraryFunction entry = library.Lookup(1);
       
  2557 					 
       
  2558 	        if (!entry)
       
  2559 	            {
       
  2560 	            Dprint(_L("Error in loading the library..."));
       
  2561 	            ret = EFalse;
       
  2562 	            }
       
  2563 	        else
       
  2564 	        	{
       
  2565 		        devEncSession = (CDevEncSessionBase*) entry();
       
  2566 		        Dprint(_L("Library is found and loaded successfully..."));
       
  2567 		      	}
       
  2568 	        }
       
  2569 
  2496         if (!devEncSession)
  2570         if (!devEncSession)
  2497             {
  2571             {
  2498             Dprint(_L("Can't instantiate device encryption session.."));
  2572             Dprint(_L("Can't instantiate device encryption session.."));
  2499             return EFalse;
       
  2500             }
       
  2501 
       
  2502         TInt err = devEncSession->Connect();
       
  2503         if (err == KErrNone)
       
  2504             {
       
  2505             //Session with device encryption is established. Check if any drive is encrypted
       
  2506             TInt encStatus (KErrNone);
       
  2507             TInt err = devEncSession->DiskStatus( encStatus );
       
  2508             Dprint(_L("err = %d, encstatus = %d"), err, encStatus);
       
  2509             if (  err == KErrNone && encStatus != EDecrypted )
       
  2510                 {
       
  2511                 Dprint(_L("Memory is encrypted"));
       
  2512                 ret = ETrue;
       
  2513                 }
       
  2514             else
       
  2515                 {
       
  2516                 Dprint(_L("Memory is not encrypted"));
       
  2517                 ret = EFalse;
       
  2518                 }
       
  2519             }
       
  2520         else
       
  2521             {
       
  2522             Dprint(_L("Error %d while establishing connection with device encryption engine"), err);
       
  2523             ret = EFalse;
  2573             ret = EFalse;
  2524             }
  2574             }
  2525         
  2575 			  else
  2526         delete devEncSession; devEncSession = NULL;
  2576 				  	{
  2527         }
  2577 						devEncSession->SetDrive( EDriveC );
       
  2578 		        TInt err = devEncSession->Connect();
       
  2579 		        if (err == KErrNone)
       
  2580 		            {
       
  2581 		            //Session with device encryption is established. Check if any drive is encrypted
       
  2582 		            TInt encStatus (KErrNone);
       
  2583 		            TInt err = devEncSession->DiskStatus( encStatus );
       
  2584 		            devEncSession->Close();
       
  2585 		            Dprint(_L("err = %d, encstatus = %d"), err, encStatus);
       
  2586 		            if (  err == KErrNone && encStatus != EDecrypted )
       
  2587 		                {
       
  2588 		                Dprint(_L("Memory is encrypted"));
       
  2589 		                ret = ETrue;
       
  2590 		                }
       
  2591 		            else
       
  2592 		                {
       
  2593 		                Dprint(_L("Memory is not encrypted"));
       
  2594 		                ret = EFalse;
       
  2595 		                }
       
  2596 		            }
       
  2597 		        else
       
  2598 		            {
       
  2599 		            Dprint(_L("Error %d while establishing connection with device encryption engine"), err);
       
  2600 		            ret = EFalse;
       
  2601 		            }
       
  2602 						}
       
  2603 				delete devEncSession; devEncSession = NULL;
       
  2604 
       
  2605         if (library.Handle())
       
  2606     	     library.Close();
       
  2607 		    }
  2528     
  2608     
  2529     Dprint(_L("CSCPServer::IsDeviceMemoryEncrypted, ret = %d <<"), ret);
  2609     Dprint(_L("CSCPServer::IsDeviceMemoryEncrypted, ret = %d <<"), ret);
  2530     return ret;
  2610     return ret;
  2531     }
  2611     }
  2532     
  2612     
  2539 *
  2619 *
  2540 * @return TInt: KErrNone is successful, otherwise a system error code
  2620 * @return TInt: KErrNone is successful, otherwise a system error code
  2541 */
  2621 */
  2542 TInt CSCPServer :: SetBestPolicyL( TInt aID, const TDesC& aValue, TUint32 aCallerIdentity, CSCPParamDBController* aParamDB ) {
  2622 TInt CSCPServer :: SetBestPolicyL( TInt aID, const TDesC& aValue, TUint32 aCallerIdentity, CSCPParamDBController* aParamDB ) {
  2543     Dprint( (_L("[CSCPServer]-> SetBestPolicyL() >>>")));
  2623     Dprint( (_L("[CSCPServer]-> SetBestPolicyL() >>>")));
  2544     Dprint( (_L("[CSCPServer]-> ParamID=%d "), aID, aValue));
       
  2545     Dprint( (_L("[CSCPServer]-> ParamValue=%d "), aValue));
       
  2546 
       
  2547     TBool lFirstTime(EFalse);
  2624     TBool lFirstTime(EFalse);
  2548     TInt32 lNumValue (-1);
  2625     TInt32 lNumValue (-1);
  2549     TInt32 lNumValDB (-1);
  2626     TInt32 lNumValDB (-1);
  2550     TInt32 lRetStatus = KErrNone;
  2627     TInt32 lRetStatus = KErrNone;
  2551 
  2628 
  2888     Dprint( (_L("[CSCPServer]-> PerformCleanupL() <<<")));
  2965     Dprint( (_L("[CSCPServer]-> PerformCleanupL() <<<")));
  2889     CleanupStack :: PopAndDestroy(4); // lParamIds lParamDB lBufReadStream lDefValueBuf
  2966     CleanupStack :: PopAndDestroy(4); // lParamIds lParamDB lBufReadStream lDefValueBuf
  2890     return (lSubOpsFailed) ? KErrGeneral : KErrNone;
  2967     return (lSubOpsFailed) ? KErrGeneral : KErrNone;
  2891 }
  2968 }
  2892 
  2969 
       
  2970 void CSCPServer :: GetPoliciesL(HBufC8* aAppIDBuffer, TUint32 aCallerIdentity) {
       
  2971     TInt lValue;
       
  2972     TInt lRet = KErrNone;
       
  2973     TBuf<25> lParamValBuf;
       
  2974     TPtr8 lBufPtr = aAppIDBuffer->Des();
       
  2975     RDesWriteStream lWriteStream(lBufPtr);
       
  2976     CleanupClosePushL(lWriteStream);
       
  2977     
       
  2978     lRet = GetAutolockPeriodL(lValue);
       
  2979     
       
  2980     if(lRet != KErrNone) {
       
  2981         User :: Leave(lRet);
       
  2982     }
       
  2983     
       
  2984     Dprint((_L("[CSCPServer]-> appending AutoLockPeriod value=%d"), lValue));
       
  2985     lWriteStream.WriteInt32L(lValue);    
       
  2986     
       
  2987     Dprint((_L("[CSCPServer]-> appending MaxAutoLockPeriod value=%d"), iConfiguration.iMaxTimeout));
       
  2988     lWriteStream.WriteInt32L(iConfiguration.iMaxTimeout);
       
  2989     
       
  2990     if(FeatureManager :: FeatureSupported(KFeatureIdSapDeviceLockEnhancements)) {
       
  2991         Dprint(_L("[CSCPServer]-> (FeatureManager :: FeatureSupported() complete. Fetching values now..."));
       
  2992         /* Fetch parameters starting from RTerminalControl3rdPartySession :: EPasscodeMinLength to 
       
  2993          * RTerminalControl3rdPartySession :: EPasscodeMinChangeInterval
       
  2994          */
       
  2995         TInt lPID = RTerminalControl3rdPartySession :: EPasscodeMinLength;
       
  2996         
       
  2997         for(; lPID <= RTerminalControl3rdPartySession :: EPasscodeDisallowSimple; lPID++) {
       
  2998             switch(lPID) {
       
  2999                 default:
       
  3000                     break;
       
  3001                 case RTerminalControl3rdPartySession :: EPasscodeCheckSpecificStrings:
       
  3002                 case RTerminalControl3rdPartySession :: EPasscodeAllowSpecific:
       
  3003                 case RTerminalControl3rdPartySession :: EPasscodeClearSpecificStrings:
       
  3004                     // No need to fetch these three parameters
       
  3005                     continue;
       
  3006                 case RTerminalControl3rdPartySession :: EPasscodeDisallowSpecific:
       
  3007                     Dprint(_L("[CSCPServer]-> appending EPasscodeDisallowSpecific value..."));
       
  3008                     // Get on EPasscodeDisallowSpecific returning -1 instead
       
  3009                     lWriteStream.WriteInt32L(-1);
       
  3010                     continue;
       
  3011                 case RTerminalControl3rdPartySession :: EPasscodeDisallowSimple:
       
  3012                     Dprint(_L("[CSCPServer]-> appending EPasscodeDisallowSimple value..."));
       
  3013                     lWriteStream.WriteInt32L(1);
       
  3014                     lWriteStream.WriteInt32L(1);
       
  3015                     continue;
       
  3016             }
       
  3017             
       
  3018             //lRet = GetParameterValueL(lPID, lParamValBuf, aCallerIdentity);
       
  3019             lRet = iPluginEventHandler->GetParameters().Get(lPID, lValue);
       
  3020             
       
  3021             switch(lRet) {
       
  3022                 
       
  3023                 
       
  3024                 case KErrNotFound: {
       
  3025                     switch(lPID) {
       
  3026                         case RTerminalControl3rdPartySession :: EPasscodeMinLength:
       
  3027                             lValue = KSCPPasscodeMinLength;
       
  3028                             break;
       
  3029                         case RTerminalControl3rdPartySession :: EPasscodeMaxLength:
       
  3030                             lValue = KSCPPasscodeMaxLength;
       
  3031                             break;
       
  3032                         default:
       
  3033                             lValue = 0;
       
  3034                             break;
       
  3035                     }
       
  3036                 }
       
  3037                 break;
       
  3038                 case KErrNone: {
       
  3039 //                    TLex lLex(lParamValBuf);
       
  3040 //                    lRet = lLex.Val(lValue);                    
       
  3041 //                    User :: LeaveIfError(lRet);
       
  3042                 }
       
  3043                 break;
       
  3044                 default:
       
  3045                     User :: Leave(lRet);
       
  3046             }
       
  3047             
       
  3048             Dprint((_L("[CSCPServer]-> appending value for lPID=%d"), lPID));
       
  3049             Dprint((_L("[CSCPServer]-> lValue=%d"), lValue));            
       
  3050             
       
  3051             switch(lPID) {
       
  3052                 default:
       
  3053                     lWriteStream.WriteInt32L(lValue);
       
  3054                     break;
       
  3055                 case RTerminalControl3rdPartySession :: EPasscodeDisallowSimple:
       
  3056                     lWriteStream.WriteInt32L(1);
       
  3057                     lWriteStream.WriteInt32L(1);
       
  3058                     break;
       
  3059             }
       
  3060         }
       
  3061     }
       
  3062     else {
       
  3063         Dprint(_L("[CSCPServer]-> (FeatureManager :: FeatureSupported() failed!!..."));
       
  3064     }
       
  3065     
       
  3066     CleanupStack :: PopAndDestroy(1); // lWriteStream
       
  3067 }
       
  3068 
       
  3069 TInt CSCPServer :: ValidateLockcodeAgainstPoliciesL(TDes& aLockcode, CSCPParamObject*& aRetParams) {
       
  3070     Dprint( (_L("[CSCPServer]-> ValidateLockcodeAgainstPoliciesL() >>>")));
       
  3071     
       
  3072     TInt ret = KErrNone;
       
  3073     CSCPParamObject* inParams = CSCPParamObject :: NewL();
       
  3074     inParams->Set(KSCPParamPassword, aLockcode);
       
  3075     CSCPParamObject* repParams = iPluginManager->PostEvent(KSCPEventValidate, *inParams);
       
  3076     delete inParams;
       
  3077     
       
  3078     if (repParams != NULL) {
       
  3079         // Check if the validation failed
       
  3080         TInt status;
       
  3081         
       
  3082         if (repParams->Get(KSCPParamStatus, status) == KErrNone) {
       
  3083             if (status != KErrNone) {
       
  3084                 ret = status;
       
  3085             }
       
  3086         }
       
  3087         
       
  3088         aRetParams = repParams; // pointer ownership changed
       
  3089     }
       
  3090     
       
  3091     Dprint( (_L("[CSCPServer]-> ValidateLockcodeAgainstPoliciesL() <<<")));
       
  3092     return ret;
       
  3093 }
       
  3094 
  2893 //#endif //  __SAP_DEVICE_LOCK_ENHANCEMENTS
  3095 //#endif //  __SAP_DEVICE_LOCK_ENHANCEMENTS
  2894 // <<<< ********************** NEW FEATURES ********************
  3096 // <<<< ********************** NEW FEATURES ********************
  2895 
  3097 
  2896 // ================= OTHER EXPORTED FUNCTIONS ==============
  3098 // ================= OTHER EXPORTED FUNCTIONS ==============
  2897 
  3099