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