1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/dbms/security/SC_StrmIn.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,101 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// TPDStreamLoader class
1.18 +//
1.19 +//
1.20 +
1.21 +#include <s32file.h>
1.22 +#include "SC_Defs.h"
1.23 +#include "SC_StrmIn.h"
1.24 +
1.25 +namespace DBSC
1.26 +{
1.27 +
1.28 +/**
1.29 +MPolicyDomainLoader::RunL() implementation, which is used to load security policies
1.30 +from a binary file, create the related security policy objects and add them
1.31 +to CPolicyDomain instance, controlled by aPolicyDomainBuilder object.
1.32 +It is not called directly, but will be called back.
1.33 +@param aPolicyDomainBuilder TPolicyDomainBuilder instance, which will be used to add
1.34 + created security policy objects to the controlled by it collection.
1.35 +@leave System-wide error codes
1.36 +*/
1.37 +void TPDStreamLoader::RunL(TPolicyDomainBuilder& aPolicyDomainBuilder)
1.38 + {
1.39 + //Load policy file version
1.40 + TVersion fileVer;
1.41 + iStream >> fileVer.iMajor;
1.42 + iStream >> fileVer.iMinor;
1.43 + iStream >> fileVer.iBuild;
1.44 + //Check policy file version against the software version
1.45 + TInt fileVersion = CVERSION(fileVer.iMajor, fileVer.iMinor);
1.46 + if(KDBSCVersion < fileVersion)
1.47 + {
1.48 + __LEAVE(KErrNotSupported);
1.49 + }
1.50 + //
1.51 + CPolicyBase::RPolicyCollection policyColl;
1.52 + CleanupClosePushL(policyColl);
1.53 + //Load database policy
1.54 + LoadPolicyCollectionL(policyColl);
1.55 + CDbPolicy* dbPolicy = CDbPolicy::NewLC(policyColl);
1.56 + aPolicyDomainBuilder.SetDbPolicyL(dbPolicy);
1.57 + CleanupStack::Pop(dbPolicy);
1.58 + //Load all table policies
1.59 + TInt16 tblCnt;
1.60 + iStream >> tblCnt;
1.61 + for(TInt i=0;i<TInt(tblCnt);++i)
1.62 + {
1.63 + TBuf<KMaxFileName> tblName;
1.64 + iStream >> tblName;
1.65 + LoadPolicyCollectionL(policyColl);
1.66 + CTblPolicy* tblPolicy = CTblPolicy::NewLC(tblName, policyColl, dbPolicy);
1.67 + aPolicyDomainBuilder.AddTblPolicyL(tblPolicy);
1.68 + CleanupStack::Pop(tblPolicy);
1.69 + }
1.70 + CleanupStack::PopAndDestroy(&policyColl);
1.71 + //Load backup&restore SID (supported after version 1.1 (including 1.1)).
1.72 + if(fileVersion >= CVERSION(KDBSCMajorVersion1, KDBSCMinorVersion1_1))
1.73 + {
1.74 + TSecureId backupSID;
1.75 + iStream >> backupSID.iId;
1.76 + aPolicyDomainBuilder.SetBackupSID(backupSID);
1.77 + }
1.78 + }
1.79 +
1.80 +/**
1.81 +Loads security policies collection from a binary file
1.82 +@param aPolicyColl A reference to a security policy collection object which has
1.83 + to be filled with the loaded security policies.
1.84 +@leave System-wide error codes
1.85 +*/
1.86 +void TPDStreamLoader::LoadPolicyCollectionL(CPolicyBase::RPolicyCollection& aPolicyColl)
1.87 + {
1.88 + aPolicyColl.Reset();
1.89 + TInt8 cnt;
1.90 + iStream >> cnt;
1.91 + for(TInt i=0;i<TInt(cnt);++i)
1.92 + {
1.93 + CPolicyBase::TPolicy policy;
1.94 + TInt8 type;
1.95 + iStream >> type;
1.96 + policy.iType = static_cast <TPolicyType> (type);
1.97 + TBuf8<sizeof(TSecurityPolicy)> buf;
1.98 + iStream >> buf;
1.99 + __LEAVE_IF_ERROR(policy.iData.Set(buf));
1.100 + __LEAVE_IF_ERROR(aPolicyColl.Append(policy));
1.101 + }
1.102 + }
1.103 +
1.104 +} //end of - namespace DBSC