authenticationservices/authenticationserver/test/tAuthSvr/src/step_base.cpp
changeset 102 deec7e509f66
parent 94 0e6c5a9328b5
child 108 ca9a0fc2f082
equal deleted inserted replaced
94:0e6c5a9328b5 102:deec7e509f66
     1 /*
       
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * CTestStep derived implementation
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "tAuthSvrStep.h"
       
    21 #include <test/testexecutelog.h>
       
    22 
       
    23 #ifndef __INIPARSER_H__
       
    24 	#include <cinidata.h>
       
    25 #endif // __INIPARSER_H__
       
    26 
       
    27 #include <s32file.h>
       
    28 #include <f32file.h>
       
    29 #include "authrepository.h"
       
    30 using namespace AuthServer;
       
    31 
       
    32 CTAuthSvrStepBase::CTAuthSvrStepBase()
       
    33 	{
       
    34 	}
       
    35 
       
    36 TInt CTAuthSvrStepBase::writeToNamedConfig(CIniData* aFile, const TDesC& aSectName,const TDesC& aKeyName,const TPtrC& aResult)
       
    37 	{
       
    38 	TInt retValue = KErrNone;
       
    39 	// Look for a key under a named section, retrieve text value	
       
    40 		
       
    41 	TInt ret = KErrNone;	//return value from FindVar functions
       
    42 	ret=aFile->SetValue(aSectName, aKeyName ,aResult);
       
    43 	if(ret != KErrNone)
       
    44 		{			
       
    45 		if(ret == KErrNotFound)
       
    46 			{
       
    47 			RDebug::Print(_L("Key not found. Unable to set value in ini file.  SectionName = %S, KeyName = %S, value = %S."),  &aSectName, &aKeyName, &aResult);
       
    48 			}
       
    49 		else
       
    50 			{
       
    51 			RDebug::Print(_L("Unable to set value in ini file. SectionName = %S, KeyName = %S, value = %S."), &aSectName, &aKeyName, &aResult);
       
    52 			}							
       
    53 		retValue = ret;
       
    54 		}
       
    55 	return retValue;	
       
    56 	}
       
    57 
       
    58 TInt CTAuthSvrStepBase::writeToNamedConfig(CIniData* aFile, const TDesC& aKeyName,const TPtrC& aResult)
       
    59 	{
       
    60 	
       
    61 	TInt retValue = KErrNone;
       
    62 	// Look for a key under no named section, retrieve text value	
       
    63 	
       
    64 	TInt ret = KErrNone;	//return value from FindVar functions
       
    65 	ret=aFile->SetValue(aKeyName ,aResult);
       
    66 	if(ret != KErrNone)
       
    67 		{
       
    68 		if(ret == KErrNotFound)
       
    69 			{
       
    70 			RDebug::Print(_L("Key not found. Unable to set value in ini file. KeyName = %S, value = %S."), &aKeyName, &aResult);
       
    71 			}			
       
    72 		else
       
    73 			{
       
    74 			RDebug::Print(_L("Unable to set value in ini file. KeyName = %S, value = %S."), &aKeyName, &aResult);
       
    75 			}
       
    76 		retValue = ret;
       
    77 		}
       
    78 	return retValue;	
       
    79 	}
       
    80 	
       
    81 TInt CTAuthSvrStepBase::readFromNamedConfigL(const TDesC& aFileName, const TDesC& aSectName,const TDesC& aKeyName, HBufC*& aResult)
       
    82 	{
       
    83 	TInt retValue = KErrNone;	
       
    84 	CIniData* file;
       
    85 	file = CIniData::NewL(aFileName);	
       
    86 	CleanupStack::PushL(file);
       
    87 	
       
    88 	// Look for a key under a named section, retrieve text value	
       
    89 	TBool ret=EFalse;	//return value from FindVar functions	
       
    90 	TPtrC resultPtr;
       
    91 	
       
    92 	ret=file->FindVar(aSectName, aKeyName ,resultPtr);	
       
    93 	if(ret == EFalse)
       
    94 		{		
       
    95 		RDebug::Print(_L("Unable to read value in ini file. Filename: %S, SectionName = %S, value = %S."), &aFileName, &aSectName, &aResult);
       
    96 		retValue = ret;
       
    97 		}
       
    98 	else
       
    99 		{
       
   100 		aResult = resultPtr.AllocL();
       
   101 		CleanupStack::PushL(aResult);
       
   102 		file->WriteToFileL(); //apply the implementation
       
   103 		CleanupStack::Pop(aResult);
       
   104 		}
       
   105 	CleanupStack::PopAndDestroy(file);
       
   106 
       
   107 	return retValue;
       
   108 	
       
   109 	}
       
   110 	
       
   111 TInt CTAuthSvrStepBase::readFromNamedConfigL(const TDesC& aFileName,const TDesC& aKeyName, HBufC*& aResult)
       
   112 	{
       
   113 	TInt retValue = KErrNone;	
       
   114 	CIniData* file=NULL;
       
   115 	file = CIniData::NewL(aFileName);	
       
   116 	CleanupStack::PushL(file);
       
   117 
       
   118 	TBool ret=EFalse;	//return value from FindVar functions
       
   119 	
       
   120 	TPtrC resultPtr;
       
   121 	ret=file->FindVar(aKeyName, resultPtr);
       
   122 	if(ret == EFalse)
       
   123 		{
       
   124 	    RDebug::Print(_L("Unable to read value in ini file. Filename: %S, SectionName = %S, value = %S."), &aFileName, &aKeyName, &aResult);
       
   125 		retValue = ret;
       
   126 		}
       
   127 	else
       
   128 		{			
       
   129 		aResult = resultPtr.AllocL();
       
   130 		CleanupStack::PushL(aResult);
       
   131 		file->WriteToFileL(); //apply the implementation
       
   132 		CleanupStack::Pop(aResult);
       
   133 		}	
       
   134 	CleanupStack::PopAndDestroy(file);
       
   135 
       
   136 	return retValue;
       
   137 	}
       
   138 
       
   139 
       
   140 
       
   141 void CTAuthSvrStepBase::SetDefaultPluginIdL(TInt aDefault)
       
   142 	{
       
   143 	//Read the default plugin value from the configuration file.
       
   144 	CRepository* repository = CRepository::NewL(KUidAuthServerRepository);
       
   145 	CleanupStack::PushL(repository);
       
   146 		
       
   147 	User::LeaveIfError(repository->Set(KAuthDefaultPlugin, aDefault));
       
   148 	
       
   149 	//Retrieve from file
       
   150 	TInt defaultPlugin(0);
       
   151 	User::LeaveIfError(repository->Get(KAuthDefaultPlugin, defaultPlugin));
       
   152 	INFO_PRINTF2(_L("Default plugin value set in cenrep to %d"),defaultPlugin);
       
   153 	
       
   154 	CleanupStack::PopAndDestroy(repository);
       
   155 		
       
   156 	}	
       
   157 /**
       
   158  Read data from testexecute ini file that will be used to initialise the Authentication Server
       
   159 */
       
   160 TInt CTAuthSvrStepBase::InitAuthServerFromFileL()
       
   161 	{
       
   162 
       
   163 	//Set a default plugin using an ini file. Read this value from a file if it is specified	
       
   164 	//Set this to be the default plugin (update the policy file) if the test case specifies it (in the script's ini file).
       
   165 	
       
   166 	TPtrC defaultPluginFromFile;
       
   167 	
       
   168 	TDriveUnit sysDrive (RFs::GetSystemDrive());
       
   169 	TDriveName sysDriveName (sysDrive.Name());
       
   170 	TBuf<128> fileName (sysDriveName);
       
   171 	fileName.Append(KAuthSvrPolicyFile);
       
   172 
       
   173 	CIniData* policyFile=NULL;
       
   174 	TRAPD(r,policyFile=CIniData::NewL(fileName));
       
   175 	CleanupStack::PushL(policyFile);
       
   176 
       
   177 	fileName.Copy(sysDriveName);
       
   178 	fileName.Append(KPluginIniFile);
       
   179 	
       
   180 	CIniData* pluginFile=NULL;
       
   181 	TRAP(r,pluginFile=CIniData::NewL(fileName));
       
   182 	CleanupStack::PushL(pluginFile);
       
   183 
       
   184 	fileName.Copy(sysDriveName);
       
   185 	fileName.Append(KPlugin3100File);
       
   186 	
       
   187 	CIniData* p3100File=NULL;
       
   188 	TRAP(r,p3100File=CIniData::NewL(fileName));
       
   189 	CleanupStack::PushL(p3100File);
       
   190 
       
   191 	fileName.Copy(sysDriveName);
       
   192 	fileName.Append(KPlugin3101File);
       
   193 	
       
   194 	CIniData* p3101File=NULL;
       
   195 	TRAP(r,p3101File=CIniData::NewL(fileName));
       
   196 	CleanupStack::PushL(p3101File);
       
   197 
       
   198 	fileName.Copy(sysDriveName);
       
   199 	fileName.Append(KPlugin3102File);
       
   200 	CIniData* p3102File=NULL;
       
   201 	TRAP(r,p3102File=CIniData::NewL(fileName));
       
   202 	CleanupStack::PushL(p3102File);
       
   203 
       
   204 	fileName.Copy(sysDriveName);
       
   205 	fileName.Append(KPlugin3103File);
       
   206 
       
   207 	CIniData* p3103File=NULL;
       
   208 	TRAP(r,p3103File=CIniData::NewL(fileName));
       
   209 	CleanupStack::PushL(p3103File);
       
   210 
       
   211 	fileName.Copy(sysDriveName);
       
   212 	fileName.Append(KPlugin3104File);
       
   213 	
       
   214 	CIniData* p3104File=NULL;
       
   215 	TRAP(r,p3104File=CIniData::NewL(fileName));
       
   216 	CleanupStack::PushL(p3104File);
       
   217 	
       
   218 	fileName.Copy(sysDriveName);
       
   219 	fileName.Append(KPlugin4100File);
       
   220 	
       
   221 	CIniData* p4100File=NULL;
       
   222 	TRAP(r,p4100File=CIniData::NewL(fileName));
       
   223 	CleanupStack::PushL(p4100File);
       
   224 	
       
   225 	if (GetStringFromConfig(ConfigSection(),_L("defaultPlugin"), defaultPluginFromFile) != EFalse) // the tag 'defaultPlugin' was present
       
   226 		{ 
       
   227 		//Write this value to the policy file
       
   228 		writeToNamedConfig(policyFile, KDefaultPluginTag, defaultPluginFromFile);
       
   229 	//	SetDefaultPluginIdL(defaultPluginFromFile);
       
   230 		}
       
   231 	TInt defaultPluginId(0);
       
   232 	if (GetIntFromConfig(ConfigSection(),_L("defaultPluginId"), defaultPluginId) != EFalse) // the tag 'defaultPlugin' was present
       
   233 		{ 
       
   234 		//Write this value to the policy file
       
   235 		//writeToNamedConfig(policyFile, KDefaultPluginTag, defaultPluginFromFile);
       
   236 		SetDefaultPluginIdL(defaultPluginId);
       
   237 		}
       
   238 	//Set whether a plugin supports default data. Read this value from a file if it is specified
       
   239 	_LIT(KTrueText,"true");
       
   240 	_LIT(KFalseText,"false");
       
   241 	
       
   242 	TBool iSupportsDefaultDataFromFile(ETrue);	//Default case - the plugin supports default data
       
   243 	
       
   244 	TBufC<16> trueBuf1(KTrueText);
       
   245 	TBufC<16> falseBuf1(KFalseText);
       
   246 	TPtr valueToWrite = trueBuf1.Des();			//Default case - the plugin supports default data
       
   247 	if (GetBoolFromConfig(ConfigSection(),_L("iSupportsDefaultData"), iSupportsDefaultDataFromFile) != EFalse) // the tag 'isTrusted' was present
       
   248 		{
       
   249 		//Set the value that will be picked up by the constructor of the plugin		
       
   250 		if (iSupportsDefaultDataFromFile)
       
   251 			{ valueToWrite = trueBuf1.Des();	}
       
   252 		else
       
   253 			{ valueToWrite = falseBuf1.Des();	}			
       
   254 		writeToNamedConfig(pluginFile, KPluginIniSection, _L("iSupportsDefaultData"), valueToWrite);	
       
   255 		writeToNamedConfig(p3100File, KPluginIniSection, _L("iSupportsDefaultData"), valueToWrite);
       
   256 		writeToNamedConfig(p3101File, KPluginIniSection, _L("iSupportsDefaultData"), valueToWrite);
       
   257 		writeToNamedConfig(p3102File, KPluginIniSection, _L("iSupportsDefaultData"), valueToWrite);
       
   258 		writeToNamedConfig(p3103File, KPluginIniSection, _L("iSupportsDefaultData"), valueToWrite);
       
   259 		writeToNamedConfig(p4100File, KPluginIniSection, _L("iSupportsDefaultData"), valueToWrite);
       
   260 		}
       
   261 	else
       
   262 		{
       
   263 		INFO_PRINTF1(_L("The iSupportsDefaultData tag was not specified in the testexecute ini file."));
       
   264 		//Use the default value of TRUE		
       
   265 		valueToWrite = trueBuf1.Des();
       
   266 		writeToNamedConfig(pluginFile, KPluginIniSection, _L("iSupportsDefaultData"), valueToWrite);
       
   267 		writeToNamedConfig(p3100File, KPluginIniSection, _L("iSupportsDefaultData"), valueToWrite);
       
   268 		writeToNamedConfig(p3101File, KPluginIniSection, _L("iSupportsDefaultData"), valueToWrite);
       
   269 		writeToNamedConfig(p3102File, KPluginIniSection, _L("iSupportsDefaultData"), valueToWrite);
       
   270 		writeToNamedConfig(p3103File, KPluginIniSection, _L("iSupportsDefaultData"), valueToWrite);
       
   271 		writeToNamedConfig(p4100File, KPluginIniSection, _L("iSupportsDefaultData"), valueToWrite);
       
   272 		}
       
   273 	
       
   274 	//Set a value for the training input that will be used by the CTPinAuthPlugin
       
   275 	//in the file AuthSvrPolicy.ini
       
   276 	TPtrC userPinInputFromFile;
       
   277 	TPtrC supportsDefaultFromFile;
       
   278 	TPtrC activeStateFromFile;
       
   279 
       
   280 	if (GetStringFromConfig(ConfigSection(),_L("Pin11113100InputId"), userPinInputFromFile) != EFalse) // the tag 'Pin11113100Input' was present
       
   281 		{ writeToNamedConfig(p3100File, KIdEnteredPinTag, userPinInputFromFile); }	
       
   282 	if (GetStringFromConfig(ConfigSection(),_L("Pin11113101InputId"), userPinInputFromFile) != EFalse) // the tag 'Pin11113101Input' was present
       
   283 		{ writeToNamedConfig(p3101File, KIdEnteredPinTag, userPinInputFromFile); }
       
   284 	if (GetStringFromConfig(ConfigSection(),_L("Pin11113102InputId"), userPinInputFromFile) != EFalse) // the tag 'Pin11113102Input' was present
       
   285 		{ writeToNamedConfig(p3102File, KIdEnteredPinTag, userPinInputFromFile); }
       
   286 	if (GetStringFromConfig(ConfigSection(),_L("Pin11113103InputId"), userPinInputFromFile) != EFalse) // the tag 'Pin11113103Input' was present
       
   287 		{ writeToNamedConfig(p3103File, KIdEnteredPinTag, userPinInputFromFile); }
       
   288 	if (GetStringFromConfig(ConfigSection(),_L("Pin11113104InputId"), userPinInputFromFile) != EFalse) // the tag 'Pin11113104Input' was present
       
   289 		{ writeToNamedConfig(p3104File, KIdEnteredPinTag, userPinInputFromFile); }
       
   290 	if (GetStringFromConfig(ConfigSection(),_L("Pin10234100InputId"), userPinInputFromFile) != EFalse) // the tag 'Pin10234100Input' was present
       
   291 		{ writeToNamedConfig(p4100File, KIdEnteredPinTag, userPinInputFromFile); }
       
   292 	
       
   293 	if (GetStringFromConfig(ConfigSection(),_L("Pin11113100InputTrain"), userPinInputFromFile) != EFalse) // the tag 'Pin11113100Input' was present
       
   294 		{ writeToNamedConfig(p3100File, KTrainEnteredPinTag, userPinInputFromFile); }	
       
   295 	if (GetStringFromConfig(ConfigSection(),_L("Pin11113101InputTrain"), userPinInputFromFile) != EFalse) // the tag 'Pin11113101Input' was present
       
   296 		{ writeToNamedConfig(p3101File, KTrainEnteredPinTag, userPinInputFromFile); }
       
   297 	if (GetStringFromConfig(ConfigSection(),_L("Pin11113102InputTrain"), userPinInputFromFile) != EFalse) // the tag 'Pin11113102Input' was present
       
   298 		{ writeToNamedConfig(p3102File, KTrainEnteredPinTag, userPinInputFromFile); }
       
   299 	if (GetStringFromConfig(ConfigSection(),_L("Pin11113103InputTrain"), userPinInputFromFile) != EFalse) // the tag 'Pin11113103Input' was present
       
   300 		{ writeToNamedConfig(p3103File, KTrainEnteredPinTag, userPinInputFromFile); }
       
   301 	if (GetStringFromConfig(ConfigSection(),_L("Pin11113104InputTrain"), userPinInputFromFile) != EFalse) // the tag 'Pin11113104Input' was present
       
   302 		{ writeToNamedConfig(p3104File, KTrainEnteredPinTag, userPinInputFromFile); }
       
   303 	if (GetStringFromConfig(ConfigSection(),_L("Pin10234100InputTrain"), userPinInputFromFile) != EFalse) // the tag 'Pin10234100Input' was present
       
   304 		{ writeToNamedConfig(p4100File, KTrainEnteredPinTag, userPinInputFromFile); }
       
   305 		
       
   306 	if (GetStringFromConfig(ConfigSection(),_L("Pin11113100Default"), supportsDefaultFromFile) != EFalse) // the tag 'Pin11113102Default' was present
       
   307 		{ writeToNamedConfig(p3100File, KSupportsDefaultTag, supportsDefaultFromFile); }	
       
   308 	if (GetStringFromConfig(ConfigSection(),_L("Pin11113101Default"), supportsDefaultFromFile) != EFalse) // the tag 'Pin11113101Default' was present
       
   309 		{ writeToNamedConfig(p3101File, KSupportsDefaultTag, supportsDefaultFromFile); }
       
   310 	if (GetStringFromConfig(ConfigSection(),_L("Pin11113102Default"), supportsDefaultFromFile) != EFalse) // the tag 'Pin11113102Default' was present
       
   311 		{ writeToNamedConfig(p3102File, KSupportsDefaultTag, supportsDefaultFromFile); }
       
   312 	if (GetStringFromConfig(ConfigSection(),_L("Pin11113104Default"), supportsDefaultFromFile) != EFalse) // the tag 'Pin11113104Default' was present
       
   313 		{ writeToNamedConfig(p3104File, KSupportsDefaultTag, supportsDefaultFromFile); }
       
   314 	if (GetStringFromConfig(ConfigSection(),_L("Pin10234100Default"), supportsDefaultFromFile) != EFalse) // the tag 'Pin10234100Default' was present
       
   315 		{ writeToNamedConfig(p4100File, KSupportsDefaultTag, supportsDefaultFromFile); }
       
   316 
       
   317 	if (GetStringFromConfig(ConfigSection(),_L("Pin11113103Default"), supportsDefaultFromFile) != EFalse) // the tag 'Pin11113103Default' was present
       
   318 		{ writeToNamedConfig(p3103File, KSupportsDefaultTag, supportsDefaultFromFile); }
       
   319 	else 
       
   320 		{ writeToNamedConfig(p3103File, KSupportsDefaultTag, falseBuf1.Des()); }	
       
   321 
       
   322 	
       
   323 	if (GetStringFromConfig(ConfigSection(),_L("Pin11113100Active"), activeStateFromFile) != EFalse) // the tag 'Pin11113100Active' was present
       
   324 		{ writeToNamedConfig(p3100File, KActiveStateTag, activeStateFromFile); }	
       
   325 	if (GetStringFromConfig(ConfigSection(),_L("Pin11113101Active"), activeStateFromFile) != EFalse) // the tag 'Pin11113101Active' was present
       
   326 		{ writeToNamedConfig(p3101File, KActiveStateTag, activeStateFromFile); }
       
   327 	if (GetStringFromConfig(ConfigSection(),_L("Pin11113102Active"), activeStateFromFile) != EFalse) // the tag 'Pin11113102Active' was present
       
   328 		{ writeToNamedConfig(p3102File, KActiveStateTag, activeStateFromFile); }	
       
   329 	if (GetStringFromConfig(ConfigSection(),_L("Pin11113104Active"), activeStateFromFile) != EFalse) // the tag 'Pin11113104Active' was present
       
   330 		{ writeToNamedConfig(p3104File, KActiveStateTag, activeStateFromFile); }	
       
   331 	if (GetStringFromConfig(ConfigSection(),_L("Pin10234100Active"), activeStateFromFile) != EFalse) // the tag 'Pin10234100Active' was present
       
   332 		{ writeToNamedConfig(p4100File, KActiveStateTag, activeStateFromFile); }	
       
   333 		
       
   334 	if (GetStringFromConfig(ConfigSection(),_L("Pin11113103Active"), activeStateFromFile) != EFalse) // the tag 'Pin11113103Active' was present
       
   335 		{ writeToNamedConfig(p3103File, KActiveStateTag, activeStateFromFile); }	
       
   336 	else 
       
   337 		{ writeToNamedConfig(p3103File, KActiveStateTag, falseBuf1.Des()); }	
       
   338 	
       
   339 	// ... Other PinPluginDb's can be added
       
   340 	//Else the data is set in the 'Defaultdata() function'
       
   341 
       
   342 	policyFile->WriteToFileL();
       
   343 	pluginFile->WriteToFileL();
       
   344 	p3100File->WriteToFileL();
       
   345 	p3101File->WriteToFileL();
       
   346 	p3102File->WriteToFileL();
       
   347 	p3103File->WriteToFileL();
       
   348 	p3104File->WriteToFileL();
       
   349 	p4100File->WriteToFileL();
       
   350 
       
   351 	CleanupStack::PopAndDestroy(8,policyFile);
       
   352 	return KErrNone;
       
   353 	}
       
   354 
       
   355 /**
       
   356  Read plugin input train data from testexecute ini file , when aInitTrainInput
       
   357  is set to true, or plugin input id when set to false.This data will be used to 
       
   358  initialise the Authentication Server.
       
   359   
       
   360 */	
       
   361 TInt CTAuthSvrStepBase::InitPluginDataFromFileL(TBool aInitTrainInput)
       
   362 	{
       
   363 	TDriveUnit sysDrive (RFs::GetSystemDrive());
       
   364 	TDriveName sysDriveName (sysDrive.Name());
       
   365 	TBuf<128> fileName (sysDriveName);
       
   366 	fileName.Append(KPlugin3100File);
       
   367 	
       
   368 	CIniData* p3100File = NULL;
       
   369 	TRAPD(r,p3100File = CIniData::NewL(fileName));
       
   370 	if(r != KErrNone)
       
   371 		{
       
   372 		RDebug::Print(_L("Unable to create CIniData object. Error = %d, File = %S"), r, &fileName);
       
   373 		return r;
       
   374 		}
       
   375 		
       
   376 	CleanupStack::PushL(p3100File);
       
   377 	
       
   378 	TPtrC userPinInputFromFile;
       
   379 	
       
   380 	if(aInitTrainInput)
       
   381 		{
       
   382 		if (GetStringFromConfig(ConfigSection(),_L("PinInputTrain"), userPinInputFromFile) != EFalse) // the tag 'Pin11113100Input' was present
       
   383 			{ writeToNamedConfig(p3100File, KTrainEnteredPinTag, userPinInputFromFile); }
       
   384 	
       
   385 		}
       
   386 		
       
   387 	else
       
   388 		{
       
   389 		if (GetStringFromConfig(ConfigSection(),_L("PinInputRetrain"), userPinInputFromFile) != EFalse) // the tag 'Pin11113100Input' was present
       
   390 			{ writeToNamedConfig(p3100File, KIdEnteredPinTag, userPinInputFromFile); }
       
   391 		
       
   392 		}
       
   393 		
       
   394 	p3100File->WriteToFileL();
       
   395 	CleanupStack::PopAndDestroy(p3100File);
       
   396 	return KErrNone;
       
   397 	}
       
   398 
       
   399 /**
       
   400  Wait for the server to shut down and so release the authentication database.
       
   401 */
       
   402 void CTAuthSvrStepBase::WaitForServerToReleaseDb()
       
   403 	{
       
   404 	TFullName name;
       
   405 	for (;;)
       
   406 		{
       
   407 		TFindServer find(::KAuthServerName);
       
   408 		if (find.Next(name) != KErrNone)
       
   409 			{
       
   410 			break;
       
   411 			}
       
   412 
       
   413 		// Wait for server to terminate
       
   414 		User::After(1 * 1000 * 1000);
       
   415 		}
       
   416 	}
       
   417 	
       
   418 /**
       
   419  	Remove any existing database file.
       
   420 */
       
   421 void CTAuthSvrStepBase::RemoveExistingDbL()
       
   422 	{
       
   423 	WaitForServerToReleaseDb();
       
   424 
       
   425 	TInt r = KErrNone;
       
   426 	
       
   427 	TBuf<80> dbName(AuthServer::KDbName);
       
   428 	dbName[0] = 'A' + static_cast<TInt>(RFs::GetSystemDrive());				
       
   429 	while ((r = iFs.Delete(dbName)) == KErrInUse)
       
   430 		{
       
   431 		User::After(50000);
       
   432 		}
       
   433 	if ((KErrPathNotFound == r) || (KErrNotFound == r))  //-12 or -1
       
   434 		{
       
   435 		INFO_PRINTF1(_L("The database file was absent when I tried to delete it. \
       
   436 			Ignoring..."));
       
   437 		r = KErrNone;	//Not Important
       
   438 		}
       
   439 		User::LeaveIfError(r);
       
   440 
       
   441 	
       
   442 		
       
   443 	TBuf<80> pinDbName(_L("!:\\private\\102740FC\\plugin.store"));
       
   444 	pinDbName[0] = 'A' + static_cast<TInt>(RFs::GetSystemDrive());				
       
   445 	while ((r = iFs.Delete(pinDbName)) == KErrInUse)
       
   446 		{
       
   447 		User::After(50000);
       
   448 		}
       
   449 	
       
   450 	if ((KErrPathNotFound == r) || (KErrNotFound == r))  //-12 or -1
       
   451 		{
       
   452 		INFO_PRINTF1(_L("The pin plugin database file was absent when I tried to delete it. \
       
   453 					Ignoring..."));
       
   454 		r = KErrNone;	//Not Important
       
   455 		}
       
   456 	User::LeaveIfError(r);
       
   457 			
       
   458 	TBuf<80> pinDbName1(_L("!:\\t_pinplugindlg_in.dat"));
       
   459 	pinDbName1[0] = 'A' + static_cast<TInt>(RFs::GetSystemDrive());				
       
   460 	while ((r = iFs.Delete(pinDbName1)) == KErrInUse)
       
   461 		{
       
   462 	User::After(50000);
       
   463 		}
       
   464 			
       
   465 	if ((KErrPathNotFound == r) || (KErrNotFound == r))  //-12 or -1
       
   466 		{
       
   467 		INFO_PRINTF1(_L("The pin plugin database file (t_pinplugindlg_in.dat)was absent when I tried to delete it. \
       
   468 						Ignoring..."));
       
   469 		r = KErrNone;	//Not Important
       
   470 	}
       
   471 	User::LeaveIfError(r);
       
   472 		
       
   473 			
       
   474 	TBuf<80> pinDbName2(_L("!:\\t_pinplugindlg_out.dat"));
       
   475 	pinDbName2[0] = 'A' + static_cast<TInt>(RFs::GetSystemDrive());				
       
   476 	while ((r = iFs.Delete(pinDbName2)) == KErrInUse)
       
   477 		{
       
   478 		User::After(50000);
       
   479 		}
       
   480 				
       
   481 	if ((KErrPathNotFound == r) || (KErrNotFound == r))  //-12 or -1
       
   482 		{
       
   483 		INFO_PRINTF1(_L("The pin plugin database file (t_pinplugindlg_out.dat)was absent when I tried to delete it. \
       
   484 						Ignoring..."));
       
   485 		r = KErrNone;	//Not Important
       
   486 		}
       
   487 	User::LeaveIfError(r);
       
   488 		
       
   489 	
       
   490 	//Reset the data 'AllUserID&PinValues' in AuthSvrPolicy.ini & the 
       
   491 	// individual plugin Db files
       
   492 	TBufC<16> initPinDbBuffer(KInitPinDatabaseValue);
       
   493 	TPtr valueToWrite = initPinDbBuffer.Des();
       
   494 	
       
   495 	TBufC<16> initEnteredPinBuffer(KDefaultInput);
       
   496 	TPtr defaultInputValue = initEnteredPinBuffer.Des();
       
   497 	
       
   498 	TBuf<2> noIdentityVal;
       
   499 	_LIT16(KFormatLastAuth,"%u");
       
   500 	
       
   501 	noIdentityVal.Format(KFormatLastAuth, KErrNone); //generates:
       
   502 
       
   503 	TDriveUnit sysDrive (RFs::GetSystemDrive());
       
   504 	TDriveName sysDriveName (sysDrive.Name());
       
   505 	TBuf<128> fileName (sysDriveName);
       
   506 	fileName.Append(KAuthSvrPolicyFile);
       
   507 	
       
   508 	CIniData* policyFile=NULL;
       
   509 	TRAP(r,policyFile=CIniData::NewL(fileName));
       
   510 	CleanupStack::PushL(policyFile);
       
   511 	
       
   512 	fileName.Copy(sysDriveName);
       
   513 	fileName.Append(KPlugin3100File);
       
   514 	
       
   515 	CIniData* p3100File=NULL;
       
   516 	TRAP(r,p3100File=CIniData::NewL(fileName));
       
   517 	CleanupStack::PushL(p3100File);
       
   518 	
       
   519 	fileName.Copy(sysDriveName);
       
   520 	fileName.Append(KPlugin3101File);
       
   521 	
       
   522 	CIniData* p3101File=NULL;
       
   523 	TRAP(r,p3101File=CIniData::NewL(fileName));
       
   524 	CleanupStack::PushL(p3101File);
       
   525 	
       
   526 	fileName.Copy(sysDriveName);
       
   527 	fileName.Append(KPlugin3102File);
       
   528 	
       
   529 	CIniData* p3102File=NULL;
       
   530 	TRAP(r,p3102File=CIniData::NewL(fileName));
       
   531 	CleanupStack::PushL(p3102File);
       
   532 	
       
   533 	fileName.Copy(sysDriveName);
       
   534 	fileName.Append(KPlugin3103File);
       
   535 	
       
   536 	CIniData* p3103File=NULL;
       
   537 	TRAP(r,p3103File=CIniData::NewL(fileName));
       
   538 	CleanupStack::PushL(p3103File);
       
   539 	
       
   540 	fileName.Copy(sysDriveName);
       
   541 	fileName.Append(KPlugin3104File);
       
   542 
       
   543 	CIniData* p3104File=NULL;
       
   544 	TRAP(r,p3104File=CIniData::NewL(fileName));
       
   545 	CleanupStack::PushL(p3104File);
       
   546 
       
   547 	fileName.Copy(sysDriveName);
       
   548 	fileName.Append(KPlugin4100File);
       
   549 
       
   550 	CIniData* p4100File=NULL;
       
   551 	TRAP(r,p4100File=CIniData::NewL(fileName));
       
   552 	CleanupStack::PushL(p4100File);
       
   553 	
       
   554 	writeToNamedConfig(policyFile, KLastAuthIdTag, noIdentityVal);
       
   555 	writeToNamedConfig(policyFile, KTotalDbTag, valueToWrite);
       
   556 	writeToNamedConfig(p3100File, KPinDbTag, valueToWrite); 
       
   557 	writeToNamedConfig(p3101File, KPinDbTag, valueToWrite); 
       
   558 	writeToNamedConfig(p3102File, KPinDbTag, valueToWrite); 
       
   559 	writeToNamedConfig(p3103File, KPinDbTag, valueToWrite); 
       
   560 	writeToNamedConfig(p3104File, KPinDbTag, valueToWrite);
       
   561 	writeToNamedConfig(p4100File, KPinDbTag, valueToWrite);
       
   562 	writeToNamedConfig(p3100File, KIdEnteredPinTag, defaultInputValue);
       
   563 	writeToNamedConfig(p3101File, KIdEnteredPinTag, defaultInputValue);
       
   564 	writeToNamedConfig(p3102File, KIdEnteredPinTag, defaultInputValue);
       
   565 	writeToNamedConfig(p3103File, KIdEnteredPinTag, defaultInputValue);
       
   566 	writeToNamedConfig(p3104File, KIdEnteredPinTag, defaultInputValue);
       
   567 	writeToNamedConfig(p4100File, KIdEnteredPinTag, defaultInputValue);
       
   568 	writeToNamedConfig(p3100File, KTrainEnteredPinTag, defaultInputValue);
       
   569 	writeToNamedConfig(p3101File, KTrainEnteredPinTag, defaultInputValue);
       
   570 	writeToNamedConfig(p3102File, KTrainEnteredPinTag, defaultInputValue);
       
   571 	writeToNamedConfig(p3103File, KTrainEnteredPinTag, defaultInputValue);
       
   572 	writeToNamedConfig(p3104File, KTrainEnteredPinTag, defaultInputValue);
       
   573 	writeToNamedConfig(p4100File, KTrainEnteredPinTag, defaultInputValue);
       
   574 	
       
   575 	policyFile->WriteToFileL();
       
   576 	p3100File->WriteToFileL();
       
   577 	p3101File->WriteToFileL();
       
   578 	p3102File->WriteToFileL();
       
   579 	p3103File->WriteToFileL();
       
   580 	p3104File->WriteToFileL();
       
   581 	p4100File->WriteToFileL();
       
   582 
       
   583 	CleanupStack::PopAndDestroy(7,policyFile);
       
   584 	}
       
   585 	
       
   586 /**
       
   587  	Utility function coverting HexString to Integer
       
   588 */
       
   589 TInt CTAuthSvrStepBase::HexString2Num(const TDesC8& aStr)
       
   590   {
       
   591   	TInt data = 0;
       
   592 	TInt char2hex = 0;
       
   593 	TInt c = 0;
       
   594 	for (TInt i = 0 ; i < aStr.Length() ; ++i)
       
   595 	  {
       
   596 	  c = aStr[i];
       
   597 	  
       
   598 	  if (c < 'A')
       
   599 	    {
       
   600 	    char2hex='0';
       
   601 	    }
       
   602 	  else if (c < 'a')
       
   603 	    {
       
   604 	    char2hex='A';
       
   605 	    }
       
   606 	  else
       
   607 	    {
       
   608 	    char2hex='a';
       
   609 	    }
       
   610 	  data = data << 4;      
       
   611 	  data += aStr[i]-char2hex; 
       
   612 	  }
       
   613 	return data;
       
   614   }
       
   615 
       
   616 
       
   617 /**
       
   618  Utility function to Update the Global Db by removing the training data 
       
   619  that is associated with a given Id. The removal will not happen if 
       
   620  the identity is not present in this list, however, this is not expected
       
   621  Called at the same time as RAuthMgrClient::RemoveIdentityL(aId)
       
   622  Returns KErrNone, or some error code
       
   623 */
       
   624 TInt CTAuthSvrStepBase::RemoveIdFromGlobalDbL (TUint32 aId)
       
   625 	{
       
   626 	
       
   627 	TBuf8<500> totalDbFileContents, totalDbFileContents2;
       
   628 	TInt retValue = KErrNone;
       
   629 	CIniData* file=NULL;
       
   630 	
       
   631 	TDriveUnit sysDrive (RFs::GetSystemDrive());
       
   632 	TDriveName sysDriveName (sysDrive.Name());
       
   633 	TBuf<128> fileName (sysDriveName);
       
   634 	fileName.Append(KAuthSvrPolicyFile);
       
   635 	
       
   636 	TRAPD(r,file=CIniData::NewL(fileName));	
       
   637 	if(r!=KErrNone)
       
   638 		{
       
   639 		RDebug::Print(_L("Unable to create CIniData object. Error = %d, File = %S"), r, &fileName);
       
   640 		retValue = r;
       
   641 		}	
       
   642 	else
       
   643 		{
       
   644 		// Look for a key under a named section, retrieve text value	
       
   645 		TPtrC result;		
       
   646 		TBool ret=EFalse;	//return value from FindVar functions		
       
   647 				
       
   648 		ret=file->FindVar(KPluginIniSection, KTotalDbTag,result);
       
   649 		if(!ret)
       
   650 			{
       
   651 			RDebug::Print(_L("Unable to find the %S key in the file %S."), &KTotalDbTag, &fileName);
       
   652 			retValue = KErrNotFound;		
       
   653 			}
       
   654 		else
       
   655 			{
       
   656 			//Copy the data from the named section in the file, and see if any previous user has used this input string
       
   657 			totalDbFileContents.Copy(result);
       
   658 			
       
   659 			//Format the searchstring as defined in the file so that it starts with a ',' and ends with a ':'.
       
   660 			_LIT8(KFormatValue3, ",%d:");
       
   661 			TBuf8<20> searchString;
       
   662 			searchString.Format(KFormatValue3, aId);
       
   663 			TInt searchResult;			
       
   664 			searchResult = totalDbFileContents.Find(searchString);
       
   665 			
       
   666 			if (searchResult)	// the tag was found
       
   667 			{				
       
   668 				//Extract the rest of the pinFileContents string before the start of the PIN (before the ':')
       
   669 				totalDbFileContents2 = totalDbFileContents.Left(searchResult);
       
   670 				
       
   671 				//The userId starts at the first ',' from the end of pinFileContents2, 
       
   672 				// where p2 is the portion of p1 to the left of searchResult
       
   673 				TInt userIdStartPos = totalDbFileContents2.LocateReverse(',');
       
   674 				
       
   675 				//Find where the PIN ends
       
   676 				TInt PinEndPos = searchResult + searchString.Length() - 1;
       
   677 								
       
   678 				//remove the found (total) string from the list
       
   679 				totalDbFileContents.Delete(userIdStartPos, (PinEndPos - userIdStartPos) );
       
   680 				
       
   681 				//Update the file
       
   682 				//For the purpose of writing the data to a file, i'll create a 16-bit version of pinFileContents
       
   683 					TInt ret2 = 0;
       
   684 					HBufC* buf;
       
   685 					buf = HBufC::NewL(500);	
       
   686 					buf->Des().Copy(totalDbFileContents);
       
   687 								
       
   688 				ret2 = file->SetValue(KPluginIniSection, KTotalDbTag, *buf);
       
   689 				
       
   690 				TRAPD(r,file->WriteToFileL());
       
   691 				if (KErrNone != r)
       
   692 					{
       
   693 					RDebug::Print(_L("Error occurred while writing to the file. Filename = %S, KeyName = AllUserID&PinValues, value = %S."), &fileName, buf);
       
   694 					}
       
   695 				delete buf;		//Memory cleanup. This string was only needed for the above Print function
       
   696 				
       
   697 				if (KErrNone !=ret2)
       
   698 					{
       
   699 					RDebug::Print(_L("Error occurred in WriteToFileL(). Error = %d. Filename= %S"), ret2, &fileName);						
       
   700 					retValue = ret2;
       
   701 					}
       
   702 				else
       
   703 					{
       
   704 					retValue = KErrNone;		
       
   705 					}				
       
   706 				}
       
   707 				else // The identity was not found in the Db. 											
       
   708 				{				
       
   709 				RDebug::Print(_L("RemoveIdFromGlobalDb: The specified ID was not found in the totalDbFile"));
       
   710 				retValue = KErrAuthServIdentityNotFound;									
       
   711 				}
       
   712 			}//End check for key&section search in file
       
   713 		delete file;
       
   714 		}//End check for safe file access
       
   715 	return retValue;
       
   716 	}
       
   717 
       
   718 /**
       
   719 Returns EPass or EFail
       
   720 */
       
   721 TVerdict CTAuthSvrStepBase::checkAndSetUserNameL(AuthServer::RAuthClient& authClient1, TInt idPosition)
       
   722 	{	
       
   723 	TBool retValue = ETrue;
       
   724 	TPtrC initNameValue;
       
   725 	TPtrC finalNameValue;
       
   726 	//Check that the user has specified the initial and later userNames for the identity 
       
   727 	
       
   728 	if( (GetStringFromConfig(ConfigSection(),_L("finalUserName"), finalNameValue)) 
       
   729 			!= EFalse) // the tags 'initUserName' and finalUserName are present
       
   730 		{
       
   731 		//Get a list of all the present identities
       
   732 		RIdentityIdArray ids;
       
   733 		authClient1.IdentitiesL(ids);
       
   734 		CleanupClosePushL(ids);
       
   735 		
       
   736 		//Check the userName of particular identity that was mentioned in the function call
       
   737 		HBufC* idName = authClient1.IdentityStringL(ids[idPosition]);
       
   738 		CleanupStack::PushL(idName);
       
   739 		
       
   740 		//Change the userName to what is desired
       
   741 		authClient1.SetIdentityStringL(ids[idPosition], finalNameValue);
       
   742 		
       
   743 		//Compare to the expected final value of the userName
       
   744 		
       
   745 		HBufC* idNameFinal = authClient1.IdentityStringL(ids[idPosition]);
       
   746 		
       
   747 		if (idNameFinal->Compare(finalNameValue) != 0)
       
   748 			{
       
   749 			INFO_PRINTF4(_L("Id %d has the Final name %S instead of %S"), idPosition, idNameFinal, &finalNameValue);
       
   750 			retValue = EFalse;
       
   751 			}
       
   752 		else
       
   753 			{
       
   754 			INFO_PRINTF4(_L("Id %d had the initial name %S and the Final name %S"), idPosition, idName, idNameFinal);	
       
   755 			retValue = ETrue;
       
   756 			}		
       
   757 		delete idNameFinal;			
       
   758 		CleanupStack::PopAndDestroy(2, &ids);	//idName, ids
       
   759 		}
       
   760 	else
       
   761 		{
       
   762 		INFO_PRINTF1(_L("finalUserName tag is absent in the script file"));		
       
   763 		}
       
   764 		
       
   765 	if (retValue)
       
   766 		{SetTestStepResult(EPass);}
       
   767 	else
       
   768 		{SetTestStepResult(EFail);}	
       
   769 	
       
   770 	return TestStepResult();
       
   771 	}
       
   772 
       
   773 
       
   774 //
       
   775 void CTAuthSvrStepBase::CheckSpecifiedPluginStatusL ()
       
   776 	{
       
   777 	//If the pluginId is quoted in the ini file, check it's training status
       
   778 	TInt plugin1IdValue = 0;
       
   779 	if (GetHexFromConfig(ConfigSection(),_L("plugin1Id"), plugin1IdValue) != EFalse) // the tag 'pluginId1' was present
       
   780 		{
       
   781 		AuthServer::RAuthClient ac;
       
   782 		User::LeaveIfError(ac.Connect());
       
   783 		CleanupClosePushL(ac);
       
   784 		// Get the status of the specified plugin
       
   785 		TInt plugin1StatusValue;
       
   786 		if (GetIntFromConfig(ConfigSection(),_L("plugin1Status"), plugin1StatusValue) != EFalse) 
       
   787 			{
       
   788 			TAuthTrainingStatus plugin1Status;// = plugin1StatusValue;
       
   789 			switch (plugin1StatusValue)
       
   790 				{
       
   791 				case EAuthUntrained:
       
   792 					plugin1Status = EAuthUntrained;
       
   793 					break;
       
   794 				case EAuthTrained:
       
   795 					plugin1Status = EAuthTrained;
       
   796 					break;
       
   797 				case EAuthFullyTrained:
       
   798 					plugin1Status = EAuthFullyTrained;
       
   799 					break;
       
   800 				default:
       
   801 					ERR_PRINTF2(_L("Error receiving a value of the pluginIdStatus. Value in file : %d "), plugin1StatusValue);
       
   802 					plugin1Status = EAuthUntrained;
       
   803 					break;
       
   804 				}				
       
   805 			
       
   806 			
       
   807 			RPluginDescriptions pluginList1;
       
   808 			TCleanupItem cleanup(CleanupEComArray, &pluginList1);
       
   809 			CleanupStack::PushL(cleanup);				
       
   810 			ac.PluginsL(pluginList1);
       
   811 						
       
   812 			TInt numPlugins = pluginList1.Count();
       
   813 			for(TInt i = 0; i < numPlugins; i++)
       
   814 				{
       
   815 				TInt presentPluginIdVal = pluginList1[i]->Id();
       
   816 								
       
   817 				if (presentPluginIdVal == plugin1IdValue)
       
   818 					{
       
   819 					TInt presentPluginStatus = pluginList1[i]->TrainingStatus();
       
   820 					if (presentPluginStatus == plugin1Status)
       
   821 						{
       
   822 						INFO_PRINTF3(_L("PluginId=%x has the expected status =%i"), presentPluginIdVal, presentPluginStatus);
       
   823 						SetTestStepResult(EPass);
       
   824 						}
       
   825 					else
       
   826 						{
       
   827 						ERR_PRINTF4(_L("PluginId=%x has status =%i, instead of %i"), 
       
   828 							presentPluginIdVal, presentPluginStatus, plugin1Status);
       
   829 						SetTestStepResult(EFail);
       
   830 						}
       
   831 					break;	//Don't check any other plugins	
       
   832 					}
       
   833 				else
       
   834 					{
       
   835 					SetTestStepResult(EFail);	//After this, check others
       
   836 					}
       
   837 				}
       
   838 			if(numPlugins == 0) 				
       
   839 				{
       
   840 				ERR_PRINTF1(_L("No plugins in the system"));
       
   841 				SetTestStepResult(EFail);					
       
   842 				}
       
   843 				
       
   844 			if (TestStepResult() == EFail)
       
   845 				{
       
   846 				ERR_PRINTF3(_L("PluginId=%x does not have the expected status %i"), 
       
   847 					plugin1IdValue, plugin1StatusValue);
       
   848 				}
       
   849 				
       
   850 			CleanupStack::PopAndDestroy(&pluginList1); //infoArray, results in a call to CleanupEComArray
       
   851 			}
       
   852 		else
       
   853 			{
       
   854 			INFO_PRINTF1(_L("plugin1Status was not specified in the ini file"));
       
   855 			}
       
   856 		CleanupStack::PopAndDestroy(&ac);	// ac	
       
   857 		}
       
   858 	else
       
   859 		{
       
   860 		INFO_PRINTF1(_L("plugin1Id was not specified in the ini file"));	
       
   861 		}
       
   862 	}
       
   863 
       
   864 
       
   865 
       
   866 enum TOp
       
   867     {
       
   868     ENone =0,
       
   869     EOr = 1,
       
   870     EAnd = 2
       
   871     };
       
   872     
       
   873 enum TState
       
   874     {
       
   875     EFirstToken  = 0,
       
   876     ESecondToken = 1,
       
   877     EThirdToken  = 2,
       
   878     ENumTokens = 3
       
   879     };
       
   880     
       
   881 AuthServer::CAuthExpression* CTAuthSvrStepBase::CreateAuthExprLC (const TDesC& aString)
       
   882     {
       
   883    
       
   884     TLex  input(aString);
       
   885     
       
   886     _LIT(KKnowledge,"K");    
       
   887     _LIT(KBiometric,"B");
       
   888     _LIT(KToken,"T");  
       
   889     _LIT(KDefault,"D");
       
   890     _LIT(KAnd,"&");
       
   891     _LIT(KOr,"|");
       
   892     _LIT(KUnexpected, "Unexpected '%S' token while parsing authexpression");
       
   893     
       
   894     AuthServer::CAuthExpression* result = 0;
       
   895     TState state = EFirstToken;
       
   896     TOp op = ENone;
       
   897     TBool err;
       
   898     TPluginId plugin = 0;
       
   899     
       
   900     if (aString == KNullDesC)
       
   901        	{
       
   902        	result = AuthExpr();
       
   903        	CleanupStack::PushL(result);
       
   904        	return result;
       
   905        	}
       
   906     for (TPtrC token = input.NextToken(); token.Size() > 0 ; 
       
   907          token.Set(input.NextToken()))
       
   908         { 
       
   909         AuthServer::CAuthExpression* newExpr = 0; 
       
   910         INFO_PRINTF3(_L("Token %S Size = %d"), &token, token.Size()); 
       
   911         if (token.Length() > 1)
       
   912             {
       
   913             TLex lexer(token);
       
   914             if (lexer.Val(plugin,EHex) == KErrNone)
       
   915                 {
       
   916                 err = (state != EFirstToken && state != EThirdToken );
       
   917                 if (err) ERR_PRINTF2(KUnexpected, &token);
       
   918                 newExpr = AuthExpr(plugin);
       
   919                 }
       
   920             else
       
   921                 {
       
   922                 err = true;
       
   923                 ERR_PRINTF2(KUnexpected, &token);
       
   924                 }
       
   925             }
       
   926         else if (token.CompareF(KKnowledge) == 0)
       
   927             {
       
   928             err = (state != EFirstToken && state != EThirdToken );
       
   929             if (err) ERR_PRINTF2(KUnexpected, &token);
       
   930             newExpr = AuthExpr(EAuthKnowledge);
       
   931             }
       
   932         else if (token.CompareF(KBiometric) == 0)
       
   933             {   
       
   934             err = (state != EFirstToken && state != EThirdToken );
       
   935             if (err) ERR_PRINTF2(KUnexpected, &token);
       
   936             newExpr = AuthExpr(EAuthBiometric);    
       
   937             }
       
   938         else if (token.CompareF(KToken) == 0)
       
   939             {
       
   940             err = (state != EFirstToken && state != EThirdToken );
       
   941             if (err) ERR_PRINTF2(KUnexpected, &token);
       
   942             newExpr = AuthExpr(EAuthToken);
       
   943             }
       
   944         else if (token.CompareF(KDefault) == 0)
       
   945             {
       
   946             err = (state != EFirstToken && state != EThirdToken );
       
   947             if (err) ERR_PRINTF2(KUnexpected, &token);
       
   948             newExpr = AuthExpr(EAuthDefault);
       
   949             }
       
   950         else if (token.CompareF(KAnd) == 0)
       
   951             {
       
   952             err = state != ESecondToken;
       
   953             if (err) ERR_PRINTF2(KUnexpected, &token);
       
   954             op = EAnd;
       
   955             }
       
   956         else if (token.CompareF(KOr) == 0)
       
   957             {
       
   958             err = state != ESecondToken;
       
   959             if (err) ERR_PRINTF2(KUnexpected, &token);
       
   960             op = EOr;
       
   961             }
       
   962         else 
       
   963             {
       
   964             err = true;
       
   965             ERR_PRINTF2(_L("Unknown '%S' token while parsing authexpression"), &token);
       
   966             }
       
   967             
       
   968         if (err) 
       
   969             {
       
   970             User::Leave(KErrGeneral);
       
   971             }
       
   972         switch (state)    
       
   973             {
       
   974             case EFirstToken:
       
   975                 if ( result == 0 && op == ENone)
       
   976                     {
       
   977                     result = newExpr;
       
   978                     CleanupStack::PushL(result);
       
   979                     }
       
   980                 else 
       
   981                     {
       
   982                     //err?
       
   983                     }
       
   984                 state = ESecondToken;
       
   985                 break;
       
   986             case ESecondToken:
       
   987                 state = EThirdToken;
       
   988                 break;
       
   989             case EThirdToken:
       
   990                 if (op == EOr)
       
   991                     {
       
   992                     CleanupStack::Pop(result);
       
   993                     result =  AuthOr(result, newExpr);
       
   994                     CleanupStack::PushL(result);
       
   995     
       
   996                     }
       
   997                 else
       
   998                     {
       
   999                     CleanupStack::Pop(result);
       
  1000                     result =  AuthAnd(result, newExpr);
       
  1001                     CleanupStack::PushL(result);
       
  1002                     }
       
  1003                 op = ENone;
       
  1004                 state = ESecondToken;
       
  1005             }
       
  1006         }
       
  1007     if (state == EThirdToken)
       
  1008         {
       
  1009         ERR_PRINTF1(_L("Unexpected end of stream while parsing authexpression"));
       
  1010         User::Leave(KErrGeneral);
       
  1011         }
       
  1012     return result;
       
  1013     }
       
  1014     
       
  1015 void CTAuthSvrStepBase::CheckSpecifiedPluginStatusConnectedL (AuthServer::RAuthClient& ac)
       
  1016 	{
       
  1017 	//If the pluginId is quoted in the ini file, check it's training status
       
  1018 	TInt plugin1IdValue = 0;
       
  1019 	if (GetHexFromConfig(ConfigSection(),_L("plugin1Id"), plugin1IdValue) != EFalse) // the tag 'pluginId1' was present
       
  1020 		{
       
  1021 		// Get the status of the specified plugin
       
  1022 		TInt plugin1StatusValue = 0;
       
  1023 		if (GetIntFromConfig(ConfigSection(),_L("plugin1Status"), plugin1StatusValue) != EFalse) 
       
  1024 			{
       
  1025 			TAuthTrainingStatus plugin1Status;// = plugin1StatusValue;
       
  1026 			switch (plugin1StatusValue)
       
  1027 				{
       
  1028 				case EAuthUntrained:
       
  1029 					plugin1Status = EAuthUntrained;
       
  1030 					break;
       
  1031 				case EAuthTrained:
       
  1032 					plugin1Status = EAuthTrained;
       
  1033 					break;
       
  1034 				case EAuthFullyTrained:
       
  1035 					plugin1Status = EAuthFullyTrained;
       
  1036 					break;
       
  1037 				default:
       
  1038 					ERR_PRINTF2(_L("Error receiving a value of the pluginIdStatus. Value in file : %d "), plugin1StatusValue);
       
  1039 					plugin1Status = EAuthUntrained;
       
  1040 					break;
       
  1041 				}				
       
  1042 			
       
  1043 			
       
  1044 			RPluginDescriptions pluginList1;
       
  1045 			TCleanupItem cleanup(CleanupEComArray, &pluginList1);
       
  1046 			CleanupStack::PushL(cleanup);						
       
  1047 			ac.PluginsL(pluginList1);
       
  1048 						
       
  1049 			TInt numPlugins = pluginList1.Count();
       
  1050 			for(TInt i = 0; i < numPlugins; i++)
       
  1051 				{
       
  1052 				TInt presentPluginIdVal = pluginList1[i]->Id();
       
  1053 								
       
  1054 				if (presentPluginIdVal == plugin1IdValue)
       
  1055 					{
       
  1056 					TInt presentPluginStatus = pluginList1[i]->TrainingStatus();
       
  1057 					if (presentPluginStatus == plugin1Status)
       
  1058 						{
       
  1059 						INFO_PRINTF3(_L("PluginId=%x has the expected status =%i"), presentPluginIdVal, presentPluginStatus);
       
  1060 						SetTestStepResult(EPass);
       
  1061 						}
       
  1062 					else
       
  1063 						{
       
  1064 						ERR_PRINTF4(_L("PluginId=%x has status =%i, instead of %i"), 
       
  1065 							presentPluginIdVal, presentPluginStatus, plugin1Status);
       
  1066 						SetTestStepResult(EFail);
       
  1067 						}
       
  1068 					break;	//Don't check any other plugins	
       
  1069 					}
       
  1070 				else
       
  1071 					{
       
  1072 					SetTestStepResult(EFail);	//After this, check others
       
  1073 					}
       
  1074 				}
       
  1075 			if(numPlugins == 0) 				
       
  1076 				{
       
  1077 				ERR_PRINTF1(_L("No plugins in the system"));
       
  1078 				SetTestStepResult(EFail);					
       
  1079 				}
       
  1080 				
       
  1081 			if (TestStepResult() == EFail)
       
  1082 				{
       
  1083 				ERR_PRINTF3(_L("PluginId=%x does not have the expected status %i"), 
       
  1084 					plugin1IdValue, plugin1StatusValue);
       
  1085 				}
       
  1086 				
       
  1087 			CleanupStack::PopAndDestroy(&pluginList1); //infoArray, results in a call to CleanupEComArray
       
  1088 			}
       
  1089 		else
       
  1090 			{
       
  1091 			INFO_PRINTF1(_L("plugin1Status was not specified in the ini file"));
       
  1092 			}		
       
  1093 		}
       
  1094 	else
       
  1095 		{
       
  1096 		INFO_PRINTF1(_L("plugin1Id was not specified in the ini file"));	
       
  1097 		}	
       
  1098 	}
       
  1099 
       
  1100 TBool CTAuthSvrStepBase::CheckPluginStatusAllL (AuthServer::RAuthClient& ac)
       
  1101 	{
       
  1102 	TBool retValue = EFalse;
       
  1103 	
       
  1104 	//Get a list of all the present plugins
       
  1105 	RPluginDescriptions pluginList1;
       
  1106 	TCleanupItem cleanup(CleanupEComArray, &pluginList1);
       
  1107 	CleanupStack::PushL(cleanup);	
       
  1108 	ac.PluginsL(pluginList1);
       
  1109 	
       
  1110 	//Get a list of all the present identities
       
  1111 	RIdentityIdArray ids;
       
  1112 	ac.IdentitiesL(ids);
       
  1113 	CleanupClosePushL(ids);
       
  1114 	TInt actualNumIdsFromServer = ids.Count();
       
  1115 	CleanupStack::PopAndDestroy(&ids);
       
  1116 	
       
  1117 	//Get the number of identities that has been trained for each of my 3 plugins
       
  1118 	TInt numIdsTrained;
       
  1119 
       
  1120 	TInt numPlugins = pluginList1.Count();
       
  1121 	for(TInt i = 0; i < numPlugins; i++)
       
  1122 		{
       
  1123 		TInt presentPluginStatus = pluginList1[i]->TrainingStatus();
       
  1124 		TInt presentPluginId = pluginList1[i]->Id();
       
  1125 		TInt expectedStatus = 0;
       
  1126 		
       
  1127 		TDriveUnit sysDrive (RFs::GetSystemDrive());
       
  1128 		TDriveName sysDriveName (sysDrive.Name());
       
  1129 		TBuf<128> fileName (sysDriveName);
       
  1130 		
       
  1131 		switch (presentPluginId)
       
  1132 			{
       
  1133 			case 0x11113100:
       
  1134 				{
       
  1135 				fileName.Append(KPlugin3100File);
       
  1136 				numIdsTrained = GetNumIdsFromPluginDbL(fileName);
       
  1137 				break;
       
  1138 				}
       
  1139 			
       
  1140 			case 0x11113101:
       
  1141 				{
       
  1142 				fileName.Append(KPlugin3101File);
       
  1143 				numIdsTrained = GetNumIdsFromPluginDbL(fileName);
       
  1144 				break;
       
  1145 				}
       
  1146 				
       
  1147 			case 0x11113102:
       
  1148 				{
       
  1149 				fileName.Append(KPlugin3102File);
       
  1150 				numIdsTrained = GetNumIdsFromPluginDbL(fileName);
       
  1151 				break;
       
  1152 				}
       
  1153 				
       
  1154 			case 0x10234100:
       
  1155 				{
       
  1156 				fileName.Append(KPlugin4100File);
       
  1157 				numIdsTrained = GetNumIdsFromPluginDbL(fileName);
       
  1158 				break;
       
  1159 				}
       
  1160 				
       
  1161 			case 0x200032E5:
       
  1162 				{
       
  1163 				numIdsTrained = actualNumIdsFromServer - 1;
       
  1164 				}
       
  1165 				
       
  1166 			default:				
       
  1167 				numIdsTrained = KErrNotFound;
       
  1168 				break;
       
  1169 			}
       
  1170 		if (KErrNotFound != numIdsTrained)
       
  1171 			{
       
  1172 			//We are only considering the 3 specified Ids
       
  1173 			if (0 == numIdsTrained)
       
  1174 				{ expectedStatus = EAuthUntrained; }
       
  1175 			else if(actualNumIdsFromServer == numIdsTrained)
       
  1176 				{ expectedStatus = EAuthFullyTrained; }
       
  1177 			else if (actualNumIdsFromServer > numIdsTrained)
       
  1178 				{ expectedStatus = EAuthTrained; }
       
  1179 			else 
       
  1180 				{
       
  1181 				ERR_PRINTF2(_L("Error!! PluginId=%x has an unexpected Number of Ids in the Database = %i"), 
       
  1182 						numIdsTrained);
       
  1183 				ERR_PRINTF2(_L("Actual number of Ids registered by the authServer = %i"), 
       
  1184 						actualNumIdsFromServer);				
       
  1185 				}
       
  1186 			
       
  1187 			//Final check
       
  1188 			if (presentPluginStatus != expectedStatus)
       
  1189 				{
       
  1190 				ERR_PRINTF4(_L("Present PluginStatus of plugin %x is not as expected. It is %i instead of %i"), 
       
  1191 							presentPluginId, presentPluginStatus, expectedStatus);
       
  1192 				retValue = EFalse;
       
  1193 				}
       
  1194 			else
       
  1195 				{
       
  1196 				retValue = ETrue;	
       
  1197 				}
       
  1198 			}
       
  1199 		}//End of for loop
       
  1200 	CleanupStack::PopAndDestroy(&pluginList1); //infoArray, results in a call to CleanupEComArray
       
  1201 	return retValue;	
       
  1202 	}
       
  1203 
       
  1204 TInt CTAuthSvrStepBase::GetNumIdsFromPluginDbL(const TDesC& aFileName)
       
  1205 	{
       
  1206 	TBuf8<500> pluginDbFileContents;
       
  1207 	TInt numIds = 0;	
       
  1208 	CIniData* file=NULL;
       
  1209 	file = CIniData::NewL(aFileName);	
       
  1210 	CleanupStack::PushL(file);
       
  1211 	
       
  1212 	// Look for a key under a named section, retrieve text value	
       
  1213 	TBool ret=EFalse;	//return value from FindVar functions	
       
  1214 	TPtrC resultPtr;
       
  1215 	
       
  1216 	ret=file->FindVar(KPluginIniSection, KPinDbTag, resultPtr);	
       
  1217 	if(ret == EFalse)
       
  1218 		{		
       
  1219 		RDebug::Print(_L("Unable to read value in ini file. Filename: %S, SectionName = %S, value = %S."), &aFileName, &KPluginIniSection, &KPinDbTag);
       
  1220 		numIds = ret;
       
  1221 		}
       
  1222 	else
       
  1223 		{
       
  1224 		pluginDbFileContents.Copy(resultPtr);
       
  1225 		_LIT8(KMarker, ":");
       
  1226 		TBuf8<3> searchString;		
       
  1227 		searchString = KMarker;
       
  1228 		
       
  1229 		TInt dBLen = pluginDbFileContents.Length();
       
  1230 		for (TInt i = 0; i < dBLen; i++)
       
  1231 			{
       
  1232 			if (pluginDbFileContents[i] == ':')
       
  1233 				{
       
  1234 				numIds++;
       
  1235 				}
       
  1236 			}//End for
       
  1237 		}//End check
       
  1238 	CleanupStack::PopAndDestroy(file);
       
  1239 	return numIds;
       
  1240 	}
       
  1241 
       
  1242 void CTAuthSvrStepBase::CreatePinPluginInputFileL(TPinPluginDialogOperation aOperation, TPinValue aPinValue)
       
  1243 	{
       
  1244 	RFileWriteStream stream;
       
  1245 	RFs fs;
       
  1246 	User::LeaveIfError(fs.Connect());
       
  1247 	TInt err = stream.Replace(fs, KInputFile, EFileWrite | EFileShareExclusive);
       
  1248 	User::LeaveIfError(err);
       
  1249 	stream.PushL();
       
  1250 	
       
  1251 	MStreamBuf* streamBuf = stream.Sink();
       
  1252 	streamBuf->SeekL(MStreamBuf::EWrite, EStreamEnd);
       
  1253 	stream.WriteInt32L(aOperation);
       
  1254 	stream.WriteInt32L(aPinValue.Length());
       
  1255 	stream.WriteL(aPinValue);
       
  1256 	stream.WriteInt32L(0);
       
  1257 	stream.WriteInt32L(4);
       
  1258 	TPinPluginDialogResult cmdResult = EOk;
       
  1259 	stream.WriteInt32L(cmdResult);
       
  1260 	aOperation = EPinPluginInfo;
       
  1261 	stream.WriteInt32L(aOperation);
       
  1262 	TPinPluginDialogResult cmdFinalResult = EOk;
       
  1263 	stream.WriteInt32L(cmdFinalResult);
       
  1264 	stream.WriteInt32L(2);
       
  1265 	stream.CommitL();
       
  1266 	CleanupStack::PopAndDestroy(); // stream
       
  1267 	
       
  1268 	}
       
  1269 
       
  1270 TPinValue CTAuthSvrStepBase::GetPinFromOutputFileL()
       
  1271 	{
       
  1272 	RFileReadStream stream;
       
  1273 	RFs fs;
       
  1274 	TPinValue pinValue;
       
  1275 	
       
  1276 	User::LeaveIfError(fs.Connect());
       
  1277 	TInt err = stream.Open(fs, KOutputFile, EFileRead | EFileShareExclusive);
       
  1278 	if(err == KErrNotFound)
       
  1279 		{
       
  1280 		pinValue.Copy(_L("11111"));
       
  1281 		return pinValue;
       
  1282 		}
       
  1283 	
       
  1284 	User::LeaveIfError(err);
       
  1285 	stream.PushL();
       
  1286 
       
  1287 	MStreamBuf* streamBuf = stream.Source();
       
  1288 	
       
  1289 	stream.ReadInt32L();
       
  1290 	TInt pinValueLength = stream.ReadInt32L();
       
  1291 	HBufC8* pinValueBuf = HBufC8::NewMaxLC(pinValueLength);
       
  1292 	TPtr8 pinValuePtr(pinValueBuf->Des());
       
  1293 	stream.ReadL(pinValuePtr, pinValueLength);
       
  1294 	pinValue.Copy(pinValuePtr);
       
  1295 	
       
  1296 	CleanupStack::PopAndDestroy(2, &stream);	
       
  1297 
       
  1298 	return pinValue;
       
  1299 	}
       
  1300 
       
  1301 AuthServer::TIdentityId CTAuthSvrStepBase::getLastAuthId()
       
  1302 /**
       
  1303 	Retrieve the last Identity that was authenticated from the Global Db file
       
  1304 	@return		The last authenticated Identity
       
  1305  */
       
  1306 	{
       
  1307 	TIdentityId lastId;
       
  1308 	lastId = 0;
       
  1309 		
       
  1310 	HBufC* valueFromFile;
       
  1311 	TInt ret = 0;
       
  1312 	TInt err = 0;
       
  1313 	
       
  1314 	TDriveUnit sysDrive (RFs::GetSystemDrive());
       
  1315 	TBuf<128> authSvrPolicyFile (sysDrive.Name());
       
  1316 	authSvrPolicyFile.Append(KAuthSvrPolicyFile);
       
  1317 	
       
  1318 	TRAP(err, ret = readFromNamedConfigL(authSvrPolicyFile, KLastAuthIdTag, valueFromFile));
       
  1319 	
       
  1320 	if (KErrNotFound == ret)
       
  1321 		{		
       
  1322 		ERR_PRINTF3(_L("Error while getting last AuthId. Tag %S not found in %S file"), KLastAuthIdTag, &authSvrPolicyFile);
       
  1323 		}
       
  1324 	else
       
  1325 		{		
       
  1326 		TLex input (*valueFromFile);
       
  1327 		TRadix aRadix = EDecimal;
       
  1328 		input.Val(lastId, aRadix);
       
  1329 		RDebug::Print(_L("UserId that is retrieved from file = %u"), lastId);
       
  1330 		}
       
  1331 		
       
  1332 	delete valueFromFile;		
       
  1333 	
       
  1334 	return lastId;
       
  1335 	}
       
  1336 	
       
  1337 	
       
  1338 void CTAuthSvrStepBase::ClientMessage(TBool aIsMessage, const TDesC& aDisplayString)
       
  1339 	{
       
  1340 	TDriveUnit sysDrive (RFs::GetSystemDrive());
       
  1341 	TDriveName sysDriveName (sysDrive.Name());
       
  1342 	TBuf<128> fileName (sysDriveName);
       
  1343 	
       
  1344 	fileName.Append(KAuthSvrPolicyFile);
       
  1345 	CIniData* file=NULL;
       
  1346 	TRAPD(r,file=CIniData::NewL(fileName));	
       
  1347 	CleanupStack::PushL(file);
       
  1348 	if(r!=KErrNone)
       
  1349 	{
       
  1350 	RDebug::Print(_L("Unable to create CIniData object. Error = %d, File = %S"), r, &fileName);
       
  1351 	}	
       
  1352 	
       
  1353 	if(aIsMessage)
       
  1354 		{
       
  1355 		TBool ret=file->SetValue(KPluginIniSection, KDisplayMessage, aDisplayString);
       
  1356 		file->WriteToFileL();
       
  1357 		}
       
  1358 	else
       
  1359 		{
       
  1360 		TBool ret=file->SetValue(KPluginIniSection, KDisplayMessage, KNullDesC());	
       
  1361 		}
       
  1362 	file->WriteToFileL();
       
  1363 	CleanupStack::PopAndDestroy(file);
       
  1364 	}
       
  1365 
       
  1366 //Implementation of member functions for CTStepActSch
       
  1367 
       
  1368 TVerdict CTStepActSch::doTestStepPreambleL()
       
  1369 /**
       
  1370 	Override CTestStep by allocating an active scheduler which is available to the subclass.	
       
  1371 	@return					This test step's result, which isn't actually used by ThreadStepExecutionL.
       
  1372  */
       
  1373 	{
       
  1374 	CTAuthSvrStepBase::doTestStepPreambleL();
       
  1375 	iActSchd = new(ELeave) CActiveScheduler;
       
  1376 	return TestStepResult();
       
  1377 	}
       
  1378 
       
  1379 
       
  1380 TVerdict CTStepActSch::doTestStepPostambleL()
       
  1381 /**
       
  1382 	Override CTestStep by deleting the active scheduler which allocated in doTestStepPreambleL.
       
  1383 	@return					This test step's result, which isn't actually used by ThreadStepExecutionL.
       
  1384  */
       
  1385 	{
       
  1386 	CTAuthSvrStepBase::doTestStepPostambleL();
       
  1387 	delete iActSchd;
       
  1388 	return TestStepResult();
       
  1389 	}
       
  1390 
       
  1391 /**
       
  1392  Utility clean up function used when working with locally declared arrays
       
  1393  */
       
  1394 void CleanupEComArray(TAny* aArrayOfPlugins)
       
  1395 	{	
       
  1396 	(static_cast<RImplInfoPtrArray*> (aArrayOfPlugins))->ResetAndDestroy();
       
  1397 	(static_cast<RImplInfoPtrArray*> (aArrayOfPlugins))->Close();	
       
  1398 	}