1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/dbms/security/SC_Policy.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,259 @@
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 +// CPolicyBase, CDbPolicy, CTblPolicy, CPolicyDomain,
1.18 +// TPolicyDomainBuilder, TPolicyDomainReader classes.
1.19 +// MPolicyDomainPersister, MPolicyDomainLoader interfaces
1.20 +//
1.21 +//
1.22 +
1.23 +#ifndef __SC_POLICY_H__
1.24 +#define __SC_POLICY_H__
1.25 +
1.26 +#include <e32base.h> //CBase
1.27 +#include "D32Security.h"
1.28 +
1.29 +namespace DBSC
1.30 +{
1.31 +
1.32 +//Forward declarations
1.33 +class CPolicyDomain;
1.34 +
1.35 +/**
1.36 +CPolicyBase class implements MPolicy interface.
1.37 +It describes an object that manages a set of TSecurityPolicy objects.
1.38 +CPolicyBase::iPOType data member gives an information access to what kind of
1.39 +database object (database or table) is controlled by the set of security policies.
1.40 +CPolicyBase::Check() can be used to check caller access rights against specified policy type.
1.41 +@see MPolicy
1.42 +@internalComponent
1.43 +*/
1.44 +NONSHARABLE_CLASS(CPolicyBase) : public CBase, public MPolicy
1.45 + {
1.46 +public:
1.47 + struct TPolicy
1.48 + {
1.49 + TPolicyType iType;
1.50 + TSecurityPolicy iData;
1.51 + };
1.52 + typedef RArray<TPolicy> RPolicyCollection;
1.53 + typedef enum {EPCNotFound, EPCPassed, EPCNotPassed} TPolicyCheckResult;
1.54 +
1.55 +public:
1.56 + virtual ~CPolicyBase();
1.57 + virtual TBool Check(const RMessage2& aMessage, TPolicyType aPolicyType) const = 0;
1.58 + virtual TInt Get(TPolicyType aPolicyType, TSecurityPolicy& aPolicy) const;
1.59 + virtual void InvariantL() const;
1.60 + DECLARE_DB_INVARIANT()
1.61 + inline const RPolicyCollection& PolicyCollection() const;
1.62 +
1.63 +protected:
1.64 + inline CPolicyBase();
1.65 + void ConstructL(const RPolicyCollection& aPolicyCollection);
1.66 + const TSecurityPolicy* Policy(TPolicyType aPolicyType) const;
1.67 + TPolicyCheckResult DoCheck(const RMessage2& aMessage, TPolicyType aPolicyType) const;
1.68 + DECLARE_DB_DUMP2(aFile)
1.69 +
1.70 +private:
1.71 + RPolicyCollection iPolicyCollection;
1.72 +
1.73 + };
1.74 +
1.75 +/**
1.76 +CDbPolicy class describes an object that manages the access to all databases, which
1.77 +have the same format UID.
1.78 +@see CPolicyBase
1.79 +@see MPolicy
1.80 +@internalComponent
1.81 +*/
1.82 +NONSHARABLE_CLASS(CDbPolicy) : public CPolicyBase
1.83 + {
1.84 +public:
1.85 + static CDbPolicy* NewLC(const RPolicyCollection& aPolicyCollection);
1.86 + inline static CDbPolicy* NewL(const RPolicyCollection& aPolicyCollection);
1.87 + virtual ~CDbPolicy();
1.88 + virtual TBool Check(const RMessage2& aMessage, TPolicyType aPolicyType) const;
1.89 + virtual void InvariantL() const;
1.90 + DECLARE_DB_DUMP2(aFile)
1.91 +
1.92 +private:
1.93 + inline CDbPolicy();
1.94 +
1.95 + };
1.96 +
1.97 +/**
1.98 +CTblPolicy class describes an object that manages the access to all tables, which
1.99 +have particular format UID and particular name.
1.100 +@see CPolicyBase
1.101 +@see MPolicy
1.102 +@internalComponent
1.103 +*/
1.104 +NONSHARABLE_CLASS(CTblPolicy) : public CPolicyBase
1.105 + {
1.106 +public:
1.107 + static CTblPolicy* NewLC(const TDesC& aTblName,
1.108 + const RPolicyCollection& aPolicyCollection,
1.109 + const CDbPolicy* aDbPolicy);
1.110 + inline static CTblPolicy* NewL(const TDesC& aTblName,
1.111 + const RPolicyCollection& aPolicyCollection,
1.112 + const CDbPolicy* aDbPolicy);
1.113 + virtual ~CTblPolicy();
1.114 + virtual TBool Check(const RMessage2& aMessage, TPolicyType aPolicyType) const;
1.115 + virtual TInt Get(TPolicyType aPolicyType, TSecurityPolicy& aPolicy) const;
1.116 + virtual void InvariantL() const;
1.117 + inline const TDesC& TableName() const;
1.118 + DECLARE_DB_DUMP2(aFile)
1.119 +
1.120 +private:
1.121 + inline CTblPolicy(const CDbPolicy* aDbPolicy);
1.122 + void ConstructL(const TDesC& aTblName, const RPolicyCollection& aPolicyCollection);
1.123 +
1.124 +private:
1.125 + HBufC* iTblName;
1.126 + const CDbPolicy* iDbPolicy;
1.127 +
1.128 + };
1.129 +
1.130 +/**
1.131 +TPolicyDomainBuilder class describes an object that can be used during the initialization
1.132 +to initialize CPolicyDomain objects. It is used by MPolicyDomainLoader interface.
1.133 +@internalComponent
1.134 +*/
1.135 +class TPolicyDomainBuilder
1.136 + {
1.137 +public:
1.138 + inline TPolicyDomainBuilder(CPolicyDomain& aPolicyDomain);
1.139 + void SetDbPolicyL(CDbPolicy* aDbPolicy);
1.140 + inline void AddTblPolicyL(CTblPolicy* aTblPolicy);
1.141 + inline void SetBackupSID(TSecureId& aSecureId);
1.142 +private:
1.143 + CPolicyDomain& iPolicyDomain;
1.144 + };
1.145 +
1.146 +/**
1.147 +TPolicyDomainBuilder class describes an object that can be used to explore the content of
1.148 +CPolicyDomain objects. It is used by MPolicyDomainPersister interface.
1.149 +@internalComponent
1.150 +*/
1.151 +class TPolicyDomainReader
1.152 + {
1.153 +public:
1.154 + inline TPolicyDomainReader(const CPolicyDomain& aPolicyDomain);
1.155 + inline TUid Uid() const;
1.156 + inline const CDbPolicy& DbPolicy() const;
1.157 + inline void ResetTblPos() const;
1.158 + inline TInt TblPolicyCount() const;
1.159 + inline const CTblPolicy* NextTblPolicy() const;
1.160 + inline TSecureId BackupSID() const;
1.161 +private:
1.162 + const CPolicyDomain& iPolicyDomain;
1.163 + mutable TInt iIndex;
1.164 + };
1.165 +
1.166 +/**
1.167 +MPolicyDomainPersister interface has to be implemented by DBSC clients, who want to store
1.168 +the information from CPolicyDomain objects (set of security policies) somewhere - text files,
1.169 +streams, ... It uses TPolicyDomainReader class to traverse CPolicyDomain collection of
1.170 +security policies.
1.171 +@see TPolicyDomainReader
1.172 +@internalComponent
1.173 +*/
1.174 +class MPolicyDomainPersister
1.175 + {
1.176 +public:
1.177 + virtual void RunL(const TPolicyDomainReader& aPolicyDomainReader) = 0;
1.178 + };
1.179 +
1.180 +/**
1.181 +MPolicyDomainPersister interface has to be implemented by DBSC clients, who want to load
1.182 +set of security policies to CPolicyDomain objects from somewhere - text files,
1.183 +streams, ... It uses TPolicyDomainBuilder class to add to CPolicyDomain collection new
1.184 +security policies.
1.185 +@see TPolicyDomainBuilder
1.186 +@internalComponent
1.187 +*/
1.188 +class MPolicyDomainLoader
1.189 + {
1.190 +public:
1.191 + virtual void RunL(TPolicyDomainBuilder& aPolicyDomainBuilder) = 0;
1.192 + };
1.193 +
1.194 +/**
1.195 +CPolicyDomain object describes a set of all security policies related to particular format UID.
1.196 +It describes only a collection of security policies and offers some functionality for
1.197 +retrieving particular database/table MPolicy interfaces.
1.198 +The responsibility for adding new items to secirity policy collection is delegated to
1.199 +TPolicyDomainBuilder class.
1.200 +The responsibility for traversing secirity policy collection is delegated to
1.201 +TPolicyDomainReader class.
1.202 +Both, TPolicyDomainBuilder and TPolicyDomainReader classes are not used directly by
1.203 +the CPolicyDomain class implementation. CPolicyDomain instances are created using
1.204 +MPolicyDomainLoader interface and externalized using MPolicyDomainPersister interface and
1.205 +they (the interfaces) use TPolicyDomainBuilder and TPolicyDomainReader respectively.
1.206 +The delegation of responsibilities for creation/traversing of CPolicyDomain security policy collection
1.207 +was done because CPolicyDomain class is a part of shared sources used in DBMS server implementation
1.208 +and DbSpConv tool implementation.
1.209 +DBMS server creates CPolicyDomain security policy collection from a binary policy files using
1.210 +TPDStreamLoader class (which implements MPolicyDomainLoader) and TPolicyDomainBuilder class
1.211 +to insert created CDbPolicy and CTblPolicy instances into CPolicyDomain collection.
1.212 +The rest of the possibilities: creating CPolicyDomain collection from a text policy file,
1.213 +exporting CPolicyDomain collection to a binary policy file,
1.214 +exporting CPolicyDomain collection to a text policy file, are used by the DbSpConv tool.
1.215 +So, CPolicyDomain class uses interfaces for its loading/storing, but their
1.216 +implementations are part of separate exe-s - no waste of production code.
1.217 +@see MPolicy
1.218 +@see CDbPolicy
1.219 +@see CTblPolicy
1.220 +@see TPolicyDomainBuilder
1.221 +@see TPolicyDomainReader
1.222 +@see MPolicyDomainLoader
1.223 +@see MPolicyDomainPersister
1.224 +@internalComponent
1.225 +*/
1.226 +NONSHARABLE_CLASS(CPolicyDomain) : public CBase
1.227 + {
1.228 + friend class TPolicyDomainBuilder;
1.229 + friend class TPolicyDomainReader;
1.230 +public:
1.231 + static CPolicyDomain* NewLC(TUid aUid, MPolicyDomainLoader& aPDLoader);
1.232 + inline static CPolicyDomain* NewL(TUid aUid, MPolicyDomainLoader& aPDLoader);
1.233 + virtual ~CPolicyDomain();
1.234 + void ExternalizeL(MPolicyDomainPersister& aPDPersister) const;
1.235 +
1.236 + inline TUid Uid() const;
1.237 + const MPolicy* DbPolicy() const;
1.238 + const MPolicy* TblPolicy(const TDesC& aTblName) const;
1.239 + inline TSecureId BackupSID() const;
1.240 +
1.241 + virtual void InvariantL() const;
1.242 + DECLARE_DB_DUMP3(aFile)
1.243 +
1.244 +private:
1.245 + inline CPolicyDomain(TUid aUid);
1.246 + void InternalizeL(MPolicyDomainLoader& aPDLoader);
1.247 + void Destroy();
1.248 + DECLARE_DB_INVARIANT2()
1.249 +
1.250 +private:
1.251 + TUid iUid;
1.252 + CDbPolicy* iDbPolicy;
1.253 + RPointerArray<CTblPolicy> iTPCollection;
1.254 + TSecureId iBackupSID;
1.255 +
1.256 + };
1.257 +
1.258 +} //end of - namespace DBSC
1.259 +
1.260 +#include "SC_Policy.inl"
1.261 +
1.262 +#endif//__SC_POLICY_H__