sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // DBMS security policy - testing new APIs - utility functions sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include "t_dbplatsecutl.h" sl@0: sl@0: //Supply your a pointer to your cleanup function or NULL. sl@0: TDBSCUtils::TDBSCUtils(RTest& aTest, TCleanupFunc aFunc) : sl@0: iTest(aTest), sl@0: iFunc(aFunc) sl@0: { sl@0: } sl@0: sl@0: //Create a CDbColSet instance. The caller is responsible for deleting it. sl@0: CDbColSet* TDBSCUtils::CreateColSetLC(const TColDef* aColDef) sl@0: { sl@0: CDbColSet* set = CDbColSet::NewLC(); sl@0: for(;aColDef->iName;++aColDef) sl@0: { sl@0: TDbCol col(TPtrC(aColDef->iName), aColDef->iType); sl@0: col.iAttributes = aColDef->iAttributes; sl@0: set->AddL(col); sl@0: } sl@0: return set; sl@0: } sl@0: sl@0: //Create a CDbKey instance. The caller is responsible for deleting it. sl@0: CDbKey* TDBSCUtils::CreateKeyLC(const TDesC& aColName) sl@0: { sl@0: CDbKey* key = CDbKey::NewLC(); sl@0: key->AddL(aColName); sl@0: return key; sl@0: } sl@0: sl@0: //Create a DBMS table. sl@0: void TDBSCUtils::CreateTableL(RDbNamedDatabase& aDb, const TDesC& aTblName, const TColDef* aColDef) sl@0: { sl@0: CDbColSet* colset = TDBSCUtils::CreateColSetLC(aColDef); sl@0: TInt err = aDb.CreateTable(aTblName, *colset); sl@0: TEST2(err, KErrNone); sl@0: CleanupStack::PopAndDestroy(colset); sl@0: } sl@0: sl@0: // Create secure shared database. The caller is responsible for closing it. sl@0: RDbNamedDatabase TDBSCUtils::CreateDatabase(RDbs& aDbs, TUid aPolicyUid, const TDesC& aDbName) sl@0: { sl@0: _LIT(KSecure, "SECURE"); sl@0: TBuf<32> format; sl@0: format.Copy(KSecure); sl@0: format.Append(aPolicyUid.Name()); sl@0: RDbNamedDatabase db; sl@0: TInt err = db.Create(aDbs, aDbName, format); sl@0: TEST2(err, KErrNone); sl@0: return db; sl@0: } sl@0: sl@0: // Delete secure shared database. sl@0: TInt TDBSCUtils::DeleteDatabase(RDbs& aDbs, TUid aPolicyUid, const TDesC& aDbName) sl@0: { sl@0: RDebug::Print(_L("Deleting %X \"%S\" database.\n"), aPolicyUid.iUid, &aDbName); sl@0: TInt err = aDbs.DeleteDatabase(aDbName, aPolicyUid); sl@0: if(err != KErrNone && err != KErrNotFound) sl@0: { sl@0: RDebug::Print(_L("Error %d deleting \"%S\" database.\n"), err, &aDbName); sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: //Check if a secure shared database with "aDatabaseName" name exists. sl@0: //aDatabaseName format: . sl@0: TBool TDBSCUtils::IsDatabaseThereL(RDbs& aDbs, TUid aPolicyUid, TDriveNumber aDriveNumber, const TDesC& aDatabaseName) sl@0: { sl@0: CDbDatabaseNames* dbNames = aDbs.DatabaseNamesL(aDriveNumber, aPolicyUid); sl@0: TEST(dbNames != NULL); sl@0: TBool found = EFalse; sl@0: for(TInt i=0;iCount();++i) sl@0: { sl@0: const TDesC& dbName = (*dbNames)[i]; sl@0: if(aDatabaseName.CompareF(dbName) == 0) sl@0: { sl@0: found = ETrue; sl@0: break; sl@0: } sl@0: } sl@0: delete dbNames; sl@0: return found; sl@0: } sl@0: sl@0: //Check if the supplied aPolicy parameter has aCapability capability. sl@0: TBool TDBSCUtils::HasCapability(const TCompiledSecurityPolicy& aPolicy, TCapability aCapability) sl@0: { sl@0: TInt maxCount = 0; sl@0: if(aPolicy.Type() == TSecurityPolicy::ETypeS3 || sl@0: aPolicy.Type() == TSecurityPolicy::ETypeV3 || sl@0: aPolicy.Type() == TSecurityPolicy::ETypeC3) sl@0: { sl@0: maxCount = 3; sl@0: } sl@0: else if(aPolicy.Type() == TSecurityPolicy::ETypeC7) sl@0: { sl@0: maxCount = 7; sl@0: } sl@0: else sl@0: { sl@0: TEST(0); sl@0: } sl@0: for(TInt i=0;i