eapol/eapol_framework/eapol_symbian/am/type/securid/symbian/plugin/src/EapSecurIDDbUtils.cpp
branchRCL_3
changeset 18 bad0cc58d154
parent 2 1c7bc153c08e
child 19 c74b3d9f6b9e
equal deleted inserted replaced
17:30e048a7b597 18:bad0cc58d154
    14 * Description:  EAP and WLAN authentication protocols.
    14 * Description:  EAP and WLAN authentication protocols.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 /*
    18 /*
    19 * %version: 14.1.2 %
    19 * %version: 29 %
    20 */
    20 */
    21 
    21 
    22 // This is enumeration of EAPOL source code.
    22 // This is enumeration of EAPOL source code.
    23 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
    23 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
    24 	#undef EAP_FILE_NUMBER_ENUM
    24 	#undef EAP_FILE_NUMBER_ENUM
    32 
    32 
    33 #include "EapSecurIDDbUtils.h"
    33 #include "EapSecurIDDbUtils.h"
    34 #include "EapSecurIDDbDefaults.h"
    34 #include "EapSecurIDDbDefaults.h"
    35 #include "EapSecurIDDbParameterNames.h"
    35 #include "EapSecurIDDbParameterNames.h"
    36 
    36 
    37 #include "eap_am_trace_symbian.h"
    37 #include <EapTraceSymbian.h>
       
    38 #include "EapPluginTools.h"
    38 
    39 
    39 const TUint KMaxSqlQueryLength = 512;
    40 const TUint KMaxSqlQueryLength = 512;
    40 
    41 
    41 // ================= MEMBER FUNCTIONS =======================
    42 // ================= MEMBER FUNCTIONS =======================
    42 
    43 
    43 void EapSecurIDDbUtils::OpenDatabaseL(RDbNamedDatabase& aDatabase, RDbs& aSession, const TIndexType aIndexType,
    44 void EapSecurIDDbUtils::OpenDatabaseL(
    44 	const TInt aIndex, const eap_type_value_e aTunnelingType)
    45 	RDbNamedDatabase& aDatabase,
       
    46 	RFs& aFileServerSession,
       
    47 	const TIndexType aIndexType,
       
    48 	const TInt aIndex,
       
    49 	const eap_type_value_e aTunnelingType)
    45 {
    50 {
    46 #ifdef USE_EAP_EXPANDED_TYPES
    51 	EAP_TRACE_DEBUG_SYMBIAN(
       
    52 		(_L("EapSecurIDDbUtils::OpenDatabaseL(): - Start - aIndexType=%d, aIndex=%d, aTunnelingType=0xfe%06x%08x\n"),
       
    53 		aIndexType,
       
    54 		aIndex,
       
    55 		aTunnelingType.get_vendor_id(),
       
    56 		aTunnelingType.get_vendor_type()));
    47 
    57 
    48 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
    58     EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: EapSecurIDDbUtils::OpenDatabaseL()\n"));
    49 
       
    50 #else
       
    51 
       
    52 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
       
    53 
       
    54 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
    55 
    59 
    56 	// 1. Open/create a database	
    60 	// 1. Open/create a database	
    57 	
       
    58 	// Connect to the DBMS server.
       
    59 	User::LeaveIfError(aSession.Connect());		
       
    60 	CleanupClosePushL(aSession);	
       
    61 	// aSession and aDatabase are pushed to the cleanup stack even though they may be member
       
    62 	// variables of the calling class and would be closed in the destructor anyway. This ensures
       
    63 	// that if they are not member variables they will be closed. Closing the handle twice
       
    64 	// does no harm.	
       
    65 	
       
    66 #ifdef SYMBIAN_SECURE_DBMS
       
    67 	
       
    68 	// Create the secure shared database with the specified secure policy.
       
    69 	// Database will be created in the data caging path for DBMS (C:\private\100012a5).
       
    70 	
       
    71 	TInt err = aDatabase.Create(aSession, KDatabaseName, KSecureUIDFormat);
       
    72 
    61 
    73 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapSecurIDDbUtils::OpenDatabaseL - Created Secure DB for eapsecurid.dat. err=%d\n"), err));
    62 	TInt error(KErrNone);
       
    63 	TFileName aPrivateDatabasePathName;
    74 
    64 
    75 	
    65 	EapPluginTools::CreateDatabaseLC(
    76 	if(err == KErrNone)
    66 		aDatabase,
       
    67 		aFileServerSession,
       
    68 		error,
       
    69 		KSecurIDDatabaseName,
       
    70 		aPrivateDatabasePathName);
       
    71 
       
    72 	if(error == KErrNone)
    77 	{
    73 	{
    78 		aDatabase.Close();
    74 		aDatabase.Close();
    79 		
    75 	}
    80 	} else if (err != KErrAlreadyExists) 
    76 	else if (error != KErrAlreadyExists) 
    81 	{
    77 	{
    82 		User::LeaveIfError(err);
    78 		User::LeaveIfError(error);
    83 	}
    79 	}
    84 	
    80 	
    85 	User::LeaveIfError(aDatabase.Open(aSession, KDatabaseName, KSecureUIDFormat));
    81 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapSecurIDDbUtils::OpenDatabaseL(): - calls aDatabase.Open()\n")));
    86 	CleanupClosePushL(aDatabase);		
    82 
    87 		
    83 	error = aDatabase.Open(aFileServerSession, aPrivateDatabasePathName);
    88 #else
    84 
    89 	// For non-secured database. The database will be created in the old location (c:\system\data).
    85 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapSecurIDDbUtils::OpenDatabaseL(): - Opened private DB for EAP-SecurID. error=%d\n"), error));
    90 	
    86 
    91 	RFs fsSession;		
    87 	User::LeaveIfError(error);
    92 	User::LeaveIfError(fsSession.Connect());
       
    93 	CleanupClosePushL(fsSession);	
       
    94 	TInt err = aDatabase.Create(fsSession, KDatabaseName);
       
    95 	
       
    96 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapSecurIDDbUtils::OpenDatabaseL - Created Non-Secure DB for eapsecurid.dat. err=%d\n"), err));
       
    97 	
       
    98 	
       
    99 	if(err == KErrNone)
       
   100 	{
       
   101 		aDatabase.Close();
       
   102 		
       
   103 	} else if (err != KErrAlreadyExists) 
       
   104 	{
       
   105 		User::LeaveIfError(err);
       
   106 	}
       
   107 	CleanupStack::PopAndDestroy(); // close fsSession
       
   108 	
       
   109 	User::LeaveIfError(aDatabase.Open(aSession, KDatabaseName));
       
   110 	CleanupClosePushL(aDatabase);		
       
   111 	    
       
   112 #endif // #ifdef SYMBIAN_SECURE_DBMS
       
   113 
    88 
   114 	// 2. Create the eap-securid table to database (ignore error if exists)
    89 	// 2. Create the eap-securid table to database (ignore error if exists)
   115 	// Table columns:
    90 	// Table columns:
   116 	//// NAME ///////////////////////////////////////////////// TYPE ////////////// Constant /////////
    91 	//// NAME ///////////////////////////////////////////////// TYPE ////////////// Constant /////////
   117 	//| ServiceType											| UNSIGNED INTEGER | KServiceType      |//
    92 	//| ServiceType											| UNSIGNED INTEGER | KServiceType      |//
   118 	//| ServiceIndex										| UNSIGNED INTEGER | KServiceIndex     |//
    93 	//| ServiceIndex										| UNSIGNED INTEGER | KServiceIndex     |//
       
    94 	//| TunnelingTypeVendorId                               | UNSIGNED INTEGER  | KTunnelingTypeVendorId    |//
   119 	//| TunnelingType										| UNSIGNED INTEGER | KTunnelingType    |//
    95 	//| TunnelingType										| UNSIGNED INTEGER | KTunnelingType    |//
   120 	//| EAP_SECURID_identity				        		| VARCHAR(255)     | cf_str_EAP_SECURID_identity_literal         |//
    96 	//| EAP_SECURID_identity				        		| VARCHAR(255)     | cf_str_EAP_SECURID_identity_literal         |//
   121 	//////////////////////////////////////////////////////////////////////////////////////////////////
    97 	//////////////////////////////////////////////////////////////////////////////////////////////////
   122 
    98 
   123 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
    99 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   124 	TPtr sqlStatement = buf->Des();
   100 	TPtr sqlStatement = buf->Des();
   125 
   101 
   126 	_LIT(KSQLCreateTable1, "CREATE TABLE %S (%S UNSIGNED INTEGER, \
   102 	_LIT(KSQLCreateTable1, "CREATE TABLE %S \
   127 											 %S UNSIGNED INTEGER, \
   103 		(%S UNSIGNED INTEGER, \
   128 											 %S UNSIGNED INTEGER, \
   104 		 %S UNSIGNED INTEGER, \
   129 											 %S VARCHAR(255))");
   105 		 %S UNSIGNED INTEGER, \
   130 	sqlStatement.Format(KSQLCreateTable1, &KSecurIDTableName, &KServiceType, &KServiceIndex, &KTunnelingType, &cf_str_EAP_SECURID_identity_literal);
   106 		 %S UNSIGNED INTEGER, \
   131 	err = aDatabase.Execute(sqlStatement);
   107 		 %S VARCHAR(255))");
   132 	if (err != KErrNone && err != KErrAlreadyExists)
   108 
       
   109 	sqlStatement.Format(KSQLCreateTable1,
       
   110 		&KSecurIDTableName,
       
   111 		&KServiceType,
       
   112 		&KServiceIndex,
       
   113 		&KTunnelingTypeVendorId,
       
   114 		&KTunnelingType,
       
   115 		&cf_str_EAP_SECURID_identity_literal);
       
   116 
       
   117 	error = aDatabase.Execute(sqlStatement);
       
   118 	if (error != KErrNone && error != KErrAlreadyExists)
   133 	{
   119 	{
   134 		User::Leave(err);
   120 		User::Leave(error);
   135 	}
   121 	}
   136 
   122 
   137 	// 4. Check if database table contains a row for this service type and id  
   123 	// 4. Check if database table contains a row for this service type and id  
   138 	
   124 	
   139 	_LIT(KSQLQueryRow, "SELECT %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
   125 	_LIT(KSQLQueryRow, "SELECT %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
   140 	sqlStatement.Format(KSQLQueryRow, &cf_str_EAP_SECURID_identity_literal, &KSecurIDTableName, 
   126 
   141 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
   127 	sqlStatement.Format(KSQLQueryRow,
       
   128 		&cf_str_EAP_SECURID_identity_literal,
       
   129 		&KSecurIDTableName, 
       
   130 		&KServiceType,
       
   131 		aIndexType,
       
   132 		&KServiceIndex,
       
   133 		aIndex,
       
   134 		&KTunnelingTypeVendorId,
       
   135 		aTunnelingType.get_vendor_id(),
       
   136 		&KTunnelingType, 
       
   137 		aTunnelingType.get_vendor_type());
       
   138 
   142 	RDbView view;
   139 	RDbView view;
   143 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
   140 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
   144 	// View must be closed when no longer needed
   141 	// View must be closed when no longer needed
   145 	CleanupClosePushL(view);
   142 	CleanupClosePushL(view);
   146 	User::LeaveIfError(view.EvaluateAll());
   143 	User::LeaveIfError(view.EvaluateAll());
   147 	// 5. If row is not found then add it
   144 	// 5. If row is not found then add it
   148 	TInt rows = view.CountL();
   145 	TInt rows = view.CountL();
   149 	CleanupStack::PopAndDestroy(); // view
   146 	CleanupStack::PopAndDestroy(&view);
   150 	if (rows == 0)
   147 	if (rows == 0)
   151 	{
   148 	{
   152 		_LIT(KSQLInsert, "SELECT * FROM %S");
   149 		_LIT(KSQLInsert, "SELECT * FROM %S");
   153 		sqlStatement.Format(KSQLInsert, &KSecurIDTableName);		
   150 		sqlStatement.Format(KSQLInsert, &KSecurIDTableName);		
   154 		
   151 		
   160 		CleanupStack::PushL(colSet);
   157 		CleanupStack::PushL(colSet);
   161 		
   158 		
   162 		view.InsertL();
   159 		view.InsertL();
   163 		view.SetColL(colSet->ColNo(KServiceType), static_cast<TInt> (aIndexType));
   160 		view.SetColL(colSet->ColNo(KServiceType), static_cast<TInt> (aIndexType));
   164 		view.SetColL(colSet->ColNo(KServiceIndex), aIndex);
   161 		view.SetColL(colSet->ColNo(KServiceIndex), aIndex);
   165 		view.SetColL(colSet->ColNo(KTunnelingType), aTunnelingVendorType);
   162 		view.SetColL(colSet->ColNo(KTunnelingTypeVendorId), aTunnelingType.get_vendor_id());
       
   163 		view.SetColL(colSet->ColNo(KTunnelingType), aTunnelingType.get_vendor_type());
   166 		view.SetColL(colSet->ColNo(cf_str_EAP_SECURID_identity_literal), default_EAP_SECURID_identity);
   164 		view.SetColL(colSet->ColNo(cf_str_EAP_SECURID_identity_literal), default_EAP_SECURID_identity);
   167 		view.PutL();
   165 		view.PutL();
   168 		
   166 		
   169 		CleanupStack::PopAndDestroy( colSet ); // Delete colSet.
   167 		CleanupStack::PopAndDestroy( colSet ); // Delete colSet.
   170 		
   168 		
   171 		CleanupStack::PopAndDestroy( &view ); // Close view.
   169 		CleanupStack::PopAndDestroy( &view ); // Close view.
   172 	} 
   170 	} 
   173 	
   171 	
   174 	CleanupStack::PopAndDestroy(); // sqlStatement
       
   175 	CleanupStack::Pop(2); // database, session
       
   176 	aDatabase.Compact();
   172 	aDatabase.Compact();
       
   173 
       
   174 	CleanupStack::PopAndDestroy( buf );
       
   175 	CleanupStack::Pop( &aDatabase );	
       
   176 	CleanupStack::Pop( &aFileServerSession );
   177 }
   177 }
   178 
   178 
   179 // End of File
   179 // End of File