Esempio n. 1
0
/**
@SYMTestCaseID SYSLIB-DBMS-CT-0015
@SYMTestCaseDesc OPen table test.
				 This test app has "PowerMgmt" (TABLE A: READ) capability, which allows it to
				 read data from table A. B and C tables can be read too, because they do
				 not have read security policy. The attempts to open A, B and C tables in
				 insert/update mode must fail.
@SYMTestPriority High
@SYMTestActions  Open table test.
@SYMTestExpectedResults The test must not fail.
@SYMREQ REQ2429
                 DBMS shall provide an API to apply security policies to database tables.
*/
static void TblOpenL()
	{
	TheTest.Printf(_L("An attempt to open table A\n"));
	//The test must fail, because the test app cannot satisfy table A, policy W.
	TInt err = TheTbl.Open(TheDb, KTblNameA);
	TEST2(err, KErrPermissionDenied);
	//The test must pass, because the test app can satisfy table A, policy R.
	err = TheTbl.Open(TheDb, KTblNameA, RDbRowSet::EReadOnly);
	TEST2(err, KErrNone);
	TheTbl.Close();

	TheTest.Printf(_L("An attempt to open table B\n"));
	//The test must fail, because the test app cannot satisfy table B, policy W.
	err = TheTbl.Open(TheDb, KTblNameB);
	TEST2(err, KErrPermissionDenied);
	//The test must pass, because table B has no R policy.
	err = TheTbl.Open(TheDb, KTblNameB, RDbRowSet::EReadOnly);
	TEST2(err, KErrNone);
	TheTbl.Close();

	TheTest.Printf(_L("An attempt to open table C\n"));
	//The test must fail, because the test app cannot satisfy table C, policy W.
	err = TheTbl.Open(TheDb, KTblNameC);
	TEST2(err, KErrPermissionDenied);
	//The test must pass, because table C has no R policy.
	err = TheTbl.Open(TheDb, KTblNameC, RDbRowSet::EReadOnly);
	TEST2(err, KErrNone);
	TheTbl.Close();
	}
Esempio n. 2
0
TInt E32Main()
    {
	__UHEAP_MARK;
	CTrapCleanup* tc = CTrapCleanup::New();
	TEST(tc != NULL);

	TInt err = TheDbs.Connect();
	TEST2(err, KErrNone);

	TBuf<32> format;
	TheTest.Printf(_L("Open database\n"));
	format.Copy(KSecure);
	format.Append(KSecureDbUid.Name());
	err = TheDb.Open(TheDbs, KDbName, format);
	TEST2(err, KErrNone);

	TRAP(err, DoTestL());
	TEST2(err, KErrNone);

	TheView.Close();
	TheTbl.Close();
	TheDb.Close();
	TheDbs.Close();

	TheTest.End();
	TheTest.Close();

	delete tc;

	__UHEAP_MARKEND;
	User::Heap().Check();
	return KErrNone;
    }
Esempio n. 3
0
static void CleanupTest()
	{
	TheView.Close();
	TheTbl.Close();
	TheDb.Close();
	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDbName);
	TheDbs.Close();
	}
Esempio n. 4
0
// --------------------------------
// CNSmlRoamTable::ConstructL()
// Second constructor
// --------------------------------
//
void CNSmlRoamTable::ConstructL()
	{
	RDbTable dbTable;
	CleanupClosePushL( dbTable );

	TInt result = dbTable.Open(iDatabase, KTable);

	if (result != KErrNone)
		{
		User::LeaveIfError( iDatabase.Execute( KSQLCreateTable ) );		
		User::LeaveIfError( iDatabase.Execute( KSQLCreateIndex ) );
		User::LeaveIfError( dbTable.Open(iDatabase, KTable) );
		}

	iColSet = dbTable.ColSetL();

	CleanupStack::PopAndDestroy(); //dbTable

	}
Esempio n. 5
0
char* CAppConfig::LoadGameL(midend *aME, const game *aGame) {
    TPtrC8 name((const TUint8*)aGame->name);
    RDbTable table;
    TDbSeekKey seekKey(name);
    char *errmsg = "";
    
    User::LeaveIfError(table.Open(iDb, KAutosaveTable, table.EReadOnly));

    CleanupClosePushL(table);

    User::LeaveIfError(table.SetIndex(KAutosaveIndex));
    
    CDbColSet* colSet = table.ColSetL();
    CleanupStack::PushL(colSet);
    
    TInt saveColNo = colSet->ColNo(KAutosaveSaveCol);
    
    if (table.SeekL(seekKey)) {
        table.GetL();
        RDbColReadStream stream;
        stream.OpenLC(table,saveColNo);
        
        errmsg = midend_deserialise(aME, read_game, &stream);
        
        CleanupStack::PopAndDestroy(&stream);
    }
    
    CleanupStack::PopAndDestroy(colSet);
    CleanupStack::PopAndDestroy(&table);
    
    return errmsg;
}
Esempio n. 6
0
void CAppConfig::GetConfigL(const TDesC &aKey, const TConfig &aConfig) {
    RDbTable table;
    TDbSeekKey seekKey(aKey);
    
    User::LeaveIfError(table.Open(iDb, KConfigTable, table.EReadOnly));

    CleanupClosePushL(table);

    User::LeaveIfError(table.SetIndex(KConfigIndex));
    
    CDbColSet* colSet = table.ColSetL();
    CleanupStack::PushL(colSet);
    
    TInt valueColNo = colSet->ColNo(KConfigValueCol);
    
    if (table.SeekL(seekKey)) {
        table.GetL();
        TPtrC value = table.ColDes(valueColNo);
        
        switch (aConfig.iType) {
            case EConfigBool:
                *aConfig.iValue.iBool = value.Compare(KBoolTrue) == 0 ? ETrue : EFalse;
                break;
                
            case EConfigInt: {
                TLex lex(value);
                TInt lvalue;
                if (lex.Val(lvalue) == KErrNone) {
                    *aConfig.iValue.iInt = lvalue;
                }
                break;
            }
            
            case EConfigText:
                if (aConfig.iValue.iText->MaxLength() > value.Length()) {
                    aConfig.iValue.iText->Copy(value.Left(aConfig.iValue.iText->MaxLength()));
                } else {
                    aConfig.iValue.iText->Copy(value);
                }
                break;
                
            case EConfigText8:
                if (aConfig.iValue.iText8->MaxLength() > value.Length()) {
                    aConfig.iValue.iText8->Copy(value.Left(aConfig.iValue.iText8->MaxLength()));
                } else {
                    aConfig.iValue.iText8->Copy(value);
                }
                break;
        }
    }
    
    CleanupStack::PopAndDestroy(colSet);
    CleanupStack::PopAndDestroy(&table);
}
Esempio n. 7
0
/**
@SYMTestCaseID SYSLIB-DBMS-CT-0010
@SYMTestCaseDesc Table R/w operations. The caller has a set of capabilities which satisfy database's
                 schema security policy only. The test checks that the capapbility checking
				 on the DBMS server side works properly. Some of the R/W table operations won't be
				 executed and the returned error will be KErrPermisssionDenied.
@SYMTestPriority High
@SYMTestActions  Attempts to execute RDbTable::Insert()/RDbTable::Update()/RDbTable::FirstL()
                 on different tables from the test database.
@SYMTestExpectedResults The test must not fail.
@SYMREQ REQ2429
                 DBMS shall provide an API to apply security policies to database tables.
*/
static void TblRWL()
	{
	TheTest.Printf(_L("An attempt to write in table B\n"));
	TInt err = TheTbl.Open(TheDb, KTblNameB, RDbRowSet::EReadOnly);
	TEST2(err, KErrNone);
	//"Write table B" test must fail, because the test app has no capabilities
	//to satisfy table B, policy W.
	TRAP(err, TheTbl.InsertL());
	TEST2(err, KErrPermissionDenied);
	TRAP(err, TheTbl.UpdateL());
	TEST2(err, KErrPermissionDenied);

	TheTest.Printf(_L("An attempt to read from table B\n"));
	//"Read table B" test must pass, because table B has no R policy
	TBool res = TheTbl.FirstL();
	TEST(!res);

	TheTbl.Close();

	TheTest.Printf(_L("An attempt to write in table C\n"));
	//"Write table C" test must fail, because the test app has no capabilities
	//to satisfy table C, policy W.
	err = TheTbl.Open(TheDb, KTblNameC, RDbRowSet::EReadOnly);
	TEST2(err, KErrNone);
	TRAP(err, TheTbl.InsertL());
	TEST2(err, KErrPermissionDenied);
	TRAP(err, TheTbl.UpdateL());
	TEST2(err, KErrPermissionDenied);

	TheTest.Printf(_L("An attempt to read from table C\n"));
	//"Read table C" test must pass, because table C has no R policy
	res = TheTbl.FirstL();
	TEST(!res);

	TheTbl.Close();
	}
Esempio n. 8
0
//Adds some data to the test table
static void AddTestDataL(RDbNamedDatabase& aDb)
	{
	RDbTable tbl;
	CleanupClosePushL(tbl);
	TEST2(tbl.Open(aDb, KTestTableName, RDbRowSet::EUpdatable), KErrNone);
	for(TInt i=0;i<KTestRecordsCount;++i)
		{
		tbl.InsertL();
		tbl.SetColL(2, _L8("1ABCDEFGHI2ABCDEFGHI3ABCDEFGHI4ABCDEFGHI5ABCDEFGHI6ABCDEFGHI7ABCDEFGHI8ABCDEFGHI9ABCDEFGHI0ABCDEFGHI"));
		tbl.PutL();
		}
	TEST(tbl.CountL() == KTestRecordsCount);
	CleanupStack::PopAndDestroy(&tbl);
	}
void CNSmlDSSettings::CreateDatabaseL(const TDesC& aFullName)
	{
	// 50 is the extra length neede for integer lengths
	HBufC* createProfileTable = HBufC::NewLC( KDSCreateProfilesTable().Length() + 50);
	TPtr profileTablePtr = createProfileTable->Des();

	profileTablePtr.Format(KDSCreateProfilesTable,KNSmlMaxProfileNameLength,KNSmlMaxUsernameLength,KNSmlMaxPasswordLength,KNSmlMaxURLLength,KNSmlMaxServerIdLength,KNSmlMaxHttpAuthUsernameLength,KNSmlMaxHttpAuthPasswordLength, KNSmlDSVisibilityArraySize );

	// 25 is the extra length neede for integer lengths
	HBufC* createAdaptersTable = HBufC::NewLC( KDSCreateAdaptersTable().Length() + 25);
	TPtr adaptersTablePtr = createAdaptersTable->Des();
	adaptersTablePtr.Format(KDSCreateAdaptersTable,KNSmlMaxAdapterDisplayNameLength,KNSmlMaxRemoteNameLength, KNSmlMaxLocalNameLength );

    User::LeaveIfError( iDatabase.Create( this->iRdbSession, aFullName, KNSmlDBMSSecureSOSServerID ) );  
	
	iDatabase.Begin();

	iDatabase.Execute( *createProfileTable );
	iDatabase.Execute( *createAdaptersTable );

	CDbColSet* colSet = CDbColSet::NewLC();
	colSet->AddL(TDbCol(KNSmlVersionColumnMajor(), EDbColUint16));
	colSet->AddL(TDbCol(KNSmlVersionColumnMinor(), EDbColUint16));
	User::LeaveIfError(iDatabase.CreateTable(KNSmlTableVersion(), *colSet));
	CleanupStack::PopAndDestroy(  ); //colset

	RDbTable table;
	User::LeaveIfError(table.Open(iDatabase, KNSmlTableVersion()));
	CleanupClosePushL(table);
	colSet = table.ColSetL();
	CleanupStack::PushL(colSet);
	table.InsertL();
	table.SetColL(colSet->ColNo(KNSmlVersionColumnMajor), KNSmlSettingsCurrentVersionMajor);
	table.SetColL(colSet->ColNo(KNSmlVersionColumnMinor), KNSmlSettingsCurrentVersionMinor);
	table.PutL();
	
	iDatabase.Commit();
	
	CreateHiddenProfilesL();

	TInt keyVal;
	TRAPD (err ,ReadRepositoryL(KNsmlDsCustomProfiles, keyVal));
	if (err == KErrNone && keyVal)
	{
		TBool aRestore = EFalse;
		CreateXMLProfilesL(aRestore);
	}
	iDatabase.Close();
	CleanupStack::PopAndDestroy( 4 ); // createAdaptersTable, createProfileTable, colSet, table
	}
Esempio n. 10
0
LOCAL_C void CreateTableL()
	{
	TheDatabase.Begin();
	test(TheDatabase.Execute(KCreateTable)==KErrNone);
	RDbTable table;
	test(table.Open(TheDatabase,KTableName,table.EInsertOnly)==KErrNone);
	for (TInt ii=0;ii<KRecords;++ii)
		{
		table.InsertL();
		table.SetColL(1,ii);
		table.PutL();
		}
	table.Close();
	test(TheDatabase.Execute(KCreateIndex)==KErrNone);
	test (TheDatabase.Commit()==KErrNone);
	}
Esempio n. 11
0
/**
@SYMTestCaseID SYSLIB-DBMS-CT-0018
@SYMTestCaseDesc Open table test.
				 This test app has no capabilities and it is restricted to be able to
				 open tables B and C in read-only mode.
@SYMTestPriority High
@SYMTestActions  Open table test.
@SYMTestExpectedResults The test must not fail.
@SYMREQ REQ2429
                 DBMS shall provide an API to apply security policies to database tables.
*/
static void Test1L()
	{
	TheTest.Printf(_L("An attempt to open tables in update/insert mode\n"));
	//The test must fail, because the test app cannot satisfy table A, B, C, policy W.
	TInt err = TheTbl.Open(TheDb, KTblNameA);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameB);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameC);
	TEST2(err, KErrPermissionDenied);

	TheTest.Printf(_L("An attempt to open tables in read-only mode\n"));
	//The test must pass for table B & C, but the test app cannot satisfy table A, policy R.
	err = TheTbl.Open(TheDb, KTblNameA, RDbRowSet::EReadOnly);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameB, RDbRowSet::EReadOnly);
	TEST2(err, KErrNone);
	TheTbl.Close();
	err = TheTbl.Open(TheDb, KTblNameC, RDbRowSet::EReadOnly);
	TEST2(err, KErrNone);
	TheTbl.Close();

	TheTest.Printf(_L("An attempt to read tables\n"));
	//The test must pass for table B & C, but the test app cannot satisfy table A, policy R.
	err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM A")));
	TEST2(err, KErrPermissionDenied);
	err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM B")));
	TEST2(err, KErrNone);
	TInt cnt = TheView.CountL();
	TEST(cnt > 0);
	TheView.Close();
	err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM C")));
	TEST2(err, KErrNone);
	cnt = TheView.CountL();
	TEST(cnt > 0);
	TheView.Close();
	}
Esempio n. 12
0
//Deletes some records from the test table using "delete" transaction.
//Do not put TEST or TEST2 macro calls here (except for record count checks)!
//The method must leave if some of the calls inside fail.
static void DeleteRecordsL()
	{
	RDbTable tbl;
	CleanupClosePushL(tbl);
	LEAVE_IF_ERROR(tbl.Open(TheDb, KTestTableName, RDbRowSet::EUpdatable));
	TEST(tbl.CountL() == KTestRecordsCount);
	TheDb.Begin();
	tbl.FirstL();
	for(TInt i=0;i<(KTestRecordsCount/2);++i)
		{
		tbl.DeleteL();
		tbl.NextL();
		}
	TInt err = TheDb.Commit();
	if(err != KErrNone)
		{
		TheDb.Rollback();
		LEAVE(err);
		}
	TEST(tbl.CountL() == (KTestRecordsCount / 2));
	CleanupStack::PopAndDestroy(&tbl);
	}
Esempio n. 13
0
// ---------------------------------------------------------------------------
// CIRNmsLogDb:AddNmsLogStartL()
// adds the NmsLog log entry into data base
// ---------------------------------------------------------------------------
//
void CIRNmsLogDb::AddNmsLogStartL( CIRNmsLogger& aNmsLog )
    {
    IRLOG_DEBUG( "CIRNmsLogDb::AddNmsLogStartL" );
    OpenDbL();
    RDbTable nmsLogtable;
    TInt error=nmsLogtable.Open( iNmsLogDb, KNmsLogTable, nmsLogtable.
        EUpdatable );
    CleanupClosePushL( nmsLogtable );
    if ( error )
        {
        CloseDb();
        User::LeaveIfError( error );    
        }
    
    //! arrange the presets in incresing order of index
    nmsLogtable.SetIndex( KNmsLogIndex );
    nmsLogtable.Reset();

    //if NmsLog log is greater or equal to than 5
    if ( nmsLogtable.CountL() >= KMaxNoNmsLog )
        {
        //first row is selected
        nmsLogtable.FirstL();
        //the current row is selected
        nmsLogtable.GetL();
        //delete that entry
        nmsLogtable.DeleteL();
        }    
    CleanupStack::PopAndDestroy( &nmsLogtable );
    //Algorithm : else condition need not handle seperatly
    //Algorithm : add NmsLogid and informations like
    //starttime,connectedfrom,NmsLogid,connectiontype,channelid
    //currentnetwork,homenetwork,NmsLogtable 
    //Algorithm: if no. of NmsLog is greater than 5

    _LIT( query, "SELECT * FROM %S" );    
    HBufC* sqlStr=HBufC::NewLC( query().Length() + KNmsLogTable().Length() );
    sqlStr->Des().Format( query, &KNmsLogTable );
    
    // Create a view on the database
    RDbView view;     
    error = view.Prepare( iNmsLogDb, *sqlStr );
    if ( error )
        {
        CloseDb();
        User::LeaveIfError( error );    
        }
    CleanupStack::PopAndDestroy( sqlStr );     
    CleanupClosePushL( view );
    error = view.EvaluateAll();
    if ( error )
        {
        CloseDb();
        User::LeaveIfError( error );    
        }
    CDbColSet* columns = view.ColSetL();
    CleanupStack::PushL( columns );
    
    RDbColWriteStream writeStream;
    TRAP( error, //trap start
       // Insert a row. Column order matches sql select statement
        view.InsertL();
        //get index
        view.SetColL( columns->ColNo( KID ), aNmsLog.NmsLogId() );    
        //!open stream
        writeStream.OpenLC( view, columns->ColNo( KNmsLogCol ) );
        aNmsLog.ExternalizeL( writeStream );
        writeStream.CommitL();
        CleanupStack::PopAndDestroy( &writeStream );
         );
Esempio n. 14
0
void CAppConfig::SetConfigL(const TDesC &aKey, const TConfig &aConfig) {
    TBuf<KConfigValueMaxLength> value;
    switch (aConfig.iType) {
        case EConfigBool:
            if (*aConfig.iValue.iBool) {
                value.Copy(KBoolTrue);
            } else {
                value.Copy(KBoolFalse);
            }
            break;
        case EConfigInt:
            value.Num(*aConfig.iValue.iInt);
            break;
        case EConfigText:
            value.Copy(*aConfig.iValue.iText);
            break;
        case EConfigText8:
            value.Copy(*aConfig.iValue.iText8);
            break;
    }
    
    RDbTable table;
    TDbSeekKey seekKey(aKey);
    
    User::LeaveIfError(table.Open(iDb, KConfigTable, table.EUpdatable));
    
    CleanupClosePushL(table);
    
    User::LeaveIfError(table.SetIndex(KConfigIndex));
    
    CDbColSet* colSet = table.ColSetL();
    CleanupStack::PushL(colSet);
    
    TInt keyColNo = colSet->ColNo(KConfigKeyCol);
    TInt valueColNo = colSet->ColNo(KConfigValueCol);
    
    if (table.SeekL(seekKey)) {
        table.GetL();
        table.UpdateL();
        table.SetColL(valueColNo, value);
    } else {
        table.InsertL();
        table.SetColL(keyColNo, aKey);
        table.SetColL(valueColNo, value);
    }
    table.PutL();
    
    CleanupStack::PopAndDestroy(colSet);
    CleanupStack::PopAndDestroy(&table);
}
Esempio n. 15
0
/**
@SYMTestCaseID SYSLIB-DBMS-CT-0009
@SYMTestCaseDesc Opening table test. The caller has a set of capabilities which satisfy database's
                 schema security policy only. The test checks that the capapbility checking
				 on the DBMS server side works properly. Some of the initiated open table
				 operations won't executed and the returned error will be KErrPermisssionDenied.
@SYMTestPriority High
@SYMTestActions  Attempts to execute RDbTable::Open() on different tables from the test database.
@SYMTestExpectedResults The test must not fail.
@SYMREQ REQ2429
                 DBMS shall provide an API to apply security policies to database tables.
*/
static void TblOpenL()
	{
	TheTest.Printf(_L("Create tables\n"));
	//The test must pass, because the test app has "SCHEMA" capability
	CDbColSet* colset = TDBSCUtils::CreateColSetLC(KColumns);
	TInt err = TheDb.CreateTable(KTblNameA, *colset);//R: PowerMgmt, W: WriteUserData
	TEST2(err, KErrNone);
	err = TheDb.CreateTable(KTblNameB, *colset);//R: None, W: WriteUserData WriteDeviceData
	TEST2(err, KErrNone);
	err = TheDb.CreateTable(KTblNameC, *colset);//R: None, W: WriteUserData
	TEST2(err, KErrNone);
	CleanupStack::PopAndDestroy(colset);

	TheTest.Printf(_L("An attempt to open table A\n"));
	//The test must fail, because the test app has no capabilities to satisfy
	//R/W policies of table A
	err = TheTbl.Open(TheDb, KTblNameA);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameA, RDbRowSet::EUpdatable);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameA, RDbRowSet::EReadOnly);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameA, RDbRowSet::EInsertOnly);
	TEST2(err, KErrPermissionDenied);

	TheTest.Printf(_L("An attempt to open table B\n"));
	//Open table B in insert/update mode - the test must fail, because the test app has no
	//capabilities to satisfy table B, policy W.
	//Open table B in read-only mode - the test must pass, because table B has no R policy.
	err = TheTbl.Open(TheDb, KTblNameB);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameB, RDbRowSet::EUpdatable);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameB, RDbRowSet::EInsertOnly);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameB, RDbRowSet::EReadOnly);
	TEST2(err, KErrNone);
	TheTbl.Close();

	TheTest.Printf(_L("An attempt to open table C\n"));
	//Open table C in insert/update mode - the test must fail, because the test app has no
	//capabilities to satisfy table C, policy W.
	//Open table C in read-only mode - the test must pass, because table C has no R policy.
	err = TheTbl.Open(TheDb, KTblNameC);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameC, RDbRowSet::EUpdatable);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameC, RDbRowSet::EInsertOnly);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameC, RDbRowSet::EReadOnly);
	TEST2(err, KErrNone);
	TheTbl.Close();
	}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
//
void CPosLmNameIndex::LoadL()
    {
    // Skip index loading for empty databases
    TInt numLandmarks = PosLmServerUtility::TotalLandmarkCountL( iDbAccess );
    if ( numLandmarks == 0 )
        {
        iTimeStamp.UniversalTime();
        iStatus = KErrNone;
        return;
        }
    
    RDbTable table;
    TInt err = table.Open( iDatabase, KPosLmIndexTable, RDbRowSet::EReadOnly );
    if ( err )
        {
        LOG("NameIndex::LoadL: index table not found"); 
        User::Leave( err );
        }
    CleanupClosePushL( table );

    table.FirstL();
    if ( table.AtEnd() )
        {
        LOG("NameIndex::LoadL: index not found"); 
        User::Leave( KErrNotFound  );
        }

    table.GetL();

    // verify that index is valid for current language
    if ( !table.IsColNull( EPosLmIncLanguageCol ) )
        {
        TLanguage lang = (TLanguage) table.ColInt32( EPosLmIncLanguageCol );
        if ( User::Language() != lang ) 
            {
            LOG2("NameIndex::LoadL: index not valid, lang %d, current lang %d", 
                lang, User::Language() );
            User::Leave( KErrCorrupt );
            }
        }
    else
        {
        LOG("NameIndex::LoadL: index lang not found"); 
        User::Leave( KErrCorrupt );
        }

    // read the index
    if ( !table.IsColNull( EPosLmIncIndexDataCol ) )
        {
        RDbColReadStream readStream;
        readStream.OpenL( table, EPosLmIncIndexDataCol );
        CleanupClosePushL( readStream );
        InternalizeL( readStream );
        CleanupStack::PopAndDestroy( &readStream );

        // basic check for the index
        if ( Count() != numLandmarks )
            {
            LOG2("NameIndex::LoadL: index not valid, count %d, landmarks in db %d", 
                Count(), numLandmarks );
            User::Leave( KErrCorrupt );
            }
        }
    else
        {
        LOG("NameIndex::LoadL: index data not found"); 
        User::Leave( KErrCorrupt );
        }

    // read the time stamp
    iTimeStamp.UniversalTime();
    if ( !table.IsColNull( EPosLmIncTimestampCol ) )
        {
        iTimeStamp = table.ColTime( EPosLmIncTimestampCol );
        }
    else
        {
        LOG("NameIndex::LoadL: index timestamp not found"); 
        User::Leave( KErrCorrupt );
        }

    CleanupStack::PopAndDestroy ( &table );

    // index is valid
    iStatus = KErrNone;
    }
Esempio n. 17
0
/**
@SYMTestCaseID SYSLIB-DBMS-CT-0016
@SYMTestCaseDesc R/W operations at a table level.
				 This test app has "PowerMgmt" (TABLE A: READ) capability, which allows it to
				 read data from table A. B and C tables can be read too, because they do
				 not have read security policy.
@SYMTestPriority High
@SYMTestActions  R/W table operations.
@SYMTestExpectedResults The test must not fail.
@SYMREQ REQ2429
                 DBMS shall provide an API to apply security policies to database tables.
*/
static void TblRWL()
	{
	TheTest.Printf(_L("Table A - Write\n"));
	TInt err = TheTbl.Open(TheDb, KTblNameA, RDbRowSet::EReadOnly);
	TEST2(err, KErrNone);
	//The test must fail, because the test app cannot satisfy table A, policy W.
	TRAP(err, TheTbl.InsertL());
	TEST2(err, KErrPermissionDenied);
	err = TheDb.Execute(_L("UPDATE A SET DATA1 = 400 WHERE ID < 10"));
	TEST2(err, KErrPermissionDenied);

	TheTest.Printf(_L("Table A - Read\n"));
	//The test must pass, because the test app can satisfy table A, policy R.
	TBool res = EFalse;
	TRAP(err, res = TheTbl.FirstL());
	TEST2(err, KErrNone);
	TEST(res);
	TInt cnt = TheTbl.CountL();
	TEST(cnt > 0);
	err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM A")));
	TEST2(err, KErrNone);
	cnt = TheView.CountL();
	TEST(cnt > 0);
	TheView.Close();

	TheTbl.Close();

	TheTest.Printf(_L("Table B - Write\n"));
	err = TheTbl.Open(TheDb, KTblNameB, RDbRowSet::EReadOnly);
	TEST2(err, KErrNone);
	//The test must fail, because the test app cannot satisfy table B, policy W.
	TRAP(err, TheTbl.InsertL());
	TEST2(err, KErrPermissionDenied);
	err = TheDb.Execute(_L("INSERT INTO B (DATA2) VALUES (45)"));
	TEST2(err, KErrPermissionDenied);

	TheTest.Printf(_L("Table B - Read\n"));
	//The test must pass, because table B has no R policy.
	TRAP(err, res = TheTbl.FirstL());
	TEST2(err, KErrNone);
	TEST(res);
	cnt = TheTbl.CountL();
	TEST(cnt > 0);
	err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM B")));
	TEST2(err, KErrNone);
	cnt = TheView.CountL();
	TEST(cnt > 0);
	TheView.Close();

	TheTbl.Close();

	TheTest.Printf(_L("Table C - Write\n"));
	err = TheTbl.Open(TheDb, KTblNameC);
	//The test must fail, because the test app cannot satisfy table C, policy W.
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameC, RDbRowSet::EReadOnly);
	TEST2(err, KErrNone);
	TRAP(err, TheTbl.InsertL());
	TEST2(err, KErrPermissionDenied);
	err = TheDb.Execute(_L("UPDATE C SET DATA1 = 400 WHERE ID < 10"));
	TEST2(err, KErrPermissionDenied);

	TheTest.Printf(_L("Table C - Read\n"));
	//The test must pass, because table C has no R policy.
	TRAP(err, res = TheTbl.FirstL());
	TEST2(err, KErrNone);
	TEST(res);
	cnt = TheTbl.CountL();
	TEST(cnt > 0);
	err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM C")));
	TEST2(err, KErrNone);
	cnt = TheView.CountL();
	TEST(cnt > 0);
	TheView.Close();

	TheTbl.Close();
	}
Esempio n. 18
0
/**
@SYMTestCaseID          SYSLIB-DBMS-CT-0581
@SYMTestCaseDesc        Tests the database definition and enquiry functions
@SYMTestPriority        Medium
@SYMTestActions        	Tests for bookmark which saves the current location of a rowset.
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
LOCAL_C void TestBookmark()
	{
	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0581 creating alien bookmark "));
	CDbColSet* cs=CDbColSet::NewLC();
	TDbCol col(_L("column"),EDbColUint8);
	col.iAttributes=TDbCol::ENotNull+TDbCol::EAutoIncrement;
	cs->AddL(col);
	test (TheDatabase.CreateTable(KOtherTable,*cs)==KErrNone);
	CleanupStack::PopAndDestroy();
	RDbTable extra;
	test (extra.Open(TheDatabase,KOtherTable)==KErrNone);
	extra.InsertL();
	extra.PutL();
	TDbBookmark alien=extra.Bookmark();
	extra.Close();
//
	test.Next(_L("Alien bookmark"));
	test (TheTable.Open(TheDatabase,KTableName)==KErrNone);
	TRAPD(r,TheTable.GotoL(alien));
	test (r==KErrNotFound);
	test (TheTable.SetIndex(KIndexInt)==KErrNone);
	TRAP(r,TheTable.GotoL(alien));
	test (r==KErrNotFound);
	test (TheTable.SetIndex(KIndexText)==KErrNone);
	TRAP(r,TheTable.GotoL(alien));
	test (r==KErrNotFound);
//
	test.Next(_L("Cross-view bookmarks"));
	TheTable.LastL();	// indexed view
	TheTable.PreviousL();
	TDbBookmark mark=TheTable.Bookmark();
	test (extra.Open(TheDatabase,KTableName)==KErrNone);
	TRAP(r,extra.GotoL(mark));
	test (r==KErrNone);
	test (extra.PreviousL());
	TRAP(r,TheTable.GotoL(extra.Bookmark()));
	test (r==KErrNone);
	extra.Close();
//
	test.Next(_L("Bookmark persistence"));
	TheTable.Close();
	test (TheTable.Open(TheDatabase,KTableName)==KErrNone);
	TRAP(r,TheTable.GotoL(mark));
	test (r==KErrNone);
	TheTable.Close();
//
	test.Next(_L("Delete alien record"));
	test (extra.Open(TheDatabase,KOtherTable)==KErrNone);
	TRAP(r, extra.GotoL(mark));
	test (r==KErrNotFound);
	TRAP(r,extra.GotoL(alien));
	test (r==KErrNone);
	extra.DeleteL();
	TRAP(r,extra.GotoL(alien));
	test (r==KErrNotFound);
	extra.Close();
//
	test.Next(_L("Delete extra table"));
	test (TheDatabase.DropTable(KOtherTable)==KErrNone);
	test (TheTable.Open(TheDatabase,KTableName)==KErrNone);
	TRAP(r,TheTable.GotoL(alien));
	test (r==KErrNotFound);
	TheTable.Close();
//
	test.End();
	}
Esempio n. 19
0
// -----------------------------------------------------------------------------
// CLogTask::DoExecuteL
// Helper to executes the task.
// (other items were commented in a header).
// -----------------------------------------------------------------------------
//
void CLogTask::DoExecuteL()
    {
    RDbs dbSession;
    User::LeaveIfError( dbSession.Connect() );
    CleanupClosePushL( dbSession );

    // Construct the db format string
    HBufC* formatString = HBufC::NewLC( KLogSecureFormat().Length() + 
                                        KLogAccessPolicyUid.Name().Length() );
    TPtr ptr( formatString->Des() );
    TUidName uidStr = KLogAccessPolicyUid.Name();    
    ptr.Format( KLogSecureFormat, &uidStr );        

    RDbNamedDatabase dbs;
    // Try to open the db
    TInt err = dbs.Open( dbSession, KLogDatabaseName, *formatString );
    if ( err == KErrNotFound )
        {
        // DB not exist, create it               
        User::LeaveIfError( dbs.Create( dbSession, KLogDatabaseName, *formatString ) );
        }
    else if ( err != KErrNone )
        {
        User::Leave( err );       
        }
    CleanupClosePushL( dbs );    
    
    // See if the log table already exists
    TBool needCompact( EFalse );    
    RDbTable table;
    err = table.Open( dbs, KLogTableName );
    if ( err != KErrNone )
        {
        // Table does not exist
        // Create the table
        User::LeaveIfError( dbs.Execute( KLogCreateTableSQL ) );
        }
    else
        {
        // Check that we don't have too many rows
        CleanupClosePushL( table );        
        if ( table.CountL( RDbTable::EQuick ) >= KMaxLogEntryCount )
            {
            // Delete the first row
            table.FirstL();
            table.DeleteL();    
            needCompact = ETrue;            
            }        
        CleanupStack::PopAndDestroy( &table );        
        }        
    
    // Add entry to the table

    // Time
    HBufC* timeString = HBufC::NewLC( KMaxTimeStringLength );
    TPtr timePtr( timeString->Des() );
    timePtr.Num( iLogEntry.iTime.Int64() );

    // Version
    HBufC* version = ConstructVersionStringLC( iLogEntry.iVersion.iMajor, 
                                               iLogEntry.iVersion.iMinor,
                                               iLogEntry.iVersion.iBuild );   

    // Construct the sql query
    HBufC* sqlQuery = HBufC::NewLC( KLogInsertSQLFormat().Length() + 
                                    KMaxLogNameLength + 
                                    KMaxLogVendorLength + 
                                    version->Length() +
                                    timeString->Length() +
                                    KExtraCharsInSql );
    TPtr sqlPtr( sqlQuery->Des() );
    sqlPtr.Format( KLogInsertSQLFormat, timeString, iLogEntry.iUid.iUid, &(iLogEntry.iName), 
                   &(iLogEntry.iVendor), version, iLogEntry.iAction, iLogEntry.iIsStartup );

    // Execute the query
    User::LeaveIfError( dbs.Execute( *sqlQuery ) );

    // Compact the db if needed
    if ( needCompact )
        {
        dbs.Compact();
        }

    CleanupStack::PopAndDestroy( 6 );  // sqlQuery, version, timeString, dbs, formatString, dbSession
    }
//--------------------------------------------------------------------
//--------------------------------------------------------------------
//
void CPosLmNameIndex::SaveL( TChar aDrive )
    {
    RDbTable table;
    TInt err = table.Open( iDatabase, KPosLmIndexTable, RDbRowSet::EUpdatable );
    if ( err == KErrNotFound )
        {
        PosLmDatabaseManager::CreateIndexTableL( iDatabase );
        err = table.Open( iDatabase, KPosLmIndexTable, RDbRowSet::EUpdatable );
        }
    User::LeaveIfError( err );
    CleanupClosePushL( table );

    TInt currentSize = 0;
    table.FirstL();
    if ( table.AtEnd() )
        {
        table.InsertL();
        }
    else
        {
        table.GetL();
        currentSize = table.ColSize( EPosLmIncIndexDataCol ); 
        table.UpdateL();
        }
    
    if ( currentSize < DataSize() )
        {
        // check disk size
        CPosLmDiskUtilities* diskUtilities = CPosLmDiskUtilities::NewL();
        CleanupStack::PushL( diskUtilities );
    
        TInt bytesToWrite = DataSize() - currentSize;
        diskUtilities->DiskSpaceBelowCriticalLevelL( bytesToWrite, aDrive );
    
        CleanupStack::PopAndDestroy( diskUtilities );
        }
    
    // current language
    table.SetColL( EPosLmIncLanguageCol, User::Language() );
    
    // index data
    RDbColWriteStream writeStream;
    writeStream.OpenL( table, EPosLmIncIndexDataCol );
    CleanupClosePushL( writeStream );
    ExternalizeL( writeStream );
    CleanupStack::PopAndDestroy( &writeStream );
    
    // index timestamp
    TTime now;
    now.UniversalTime();
    table.SetColL( EPosLmIncTimestampCol, now );

#ifdef _DEBUG  
    TBuf<64> mtime;
    now.FormatL( mtime, KPosLmTimeFormat );
    LOG1( "NameIndex: Saving index timestamp %S", &mtime); 
#endif    

    table.PutL();
    CleanupStack::PopAndDestroy ( &table );
    
    iTimeStamp = now;
    }
Esempio n. 21
0
void CAppConfig::SaveGameL(midend *aME, const game *aGame) {
    TPtrC8 name((const TUint8*)aGame->name);
    RDbTable table;
    TDbSeekKey seekKey(name);
    
    User::LeaveIfError(table.Open(iDb, KAutosaveTable, table.EUpdatable));
    
    CleanupClosePushL(table);
    
    User::LeaveIfError(table.SetIndex(KAutosaveIndex));
    
    CDbColSet* colSet = table.ColSetL();
    CleanupStack::PushL(colSet);
    
    TInt nameColNo = colSet->ColNo(KAutosaveNameCol);
    TInt saveColNo = colSet->ColNo(KAutosaveSaveCol);
    TInt dateColNo = colSet->ColNo(KAutosaveDateCol);
    
    if (table.SeekL(seekKey)) {
        table.GetL();
        table.UpdateL();
    } else {
        table.InsertL();
        table.SetColL(nameColNo, name);
    }
    TTime now;
    now.HomeTime();
    table.SetColL(dateColNo, now);
    
    RDbColWriteStream stream;
    stream.OpenL(table, saveColNo);
    CleanupClosePushL(stream);
    
    midend_serialise(aME, save_game, &stream);
    CleanupStack::PopAndDestroy(&stream);
    
    table.PutL();
    
    CleanupStack::PopAndDestroy(colSet);
    CleanupStack::PopAndDestroy(&table);
    
    iDb.Compact();
}