os/persistentdata/persistentstorage/dbms/security/SC_PolicySpace.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/dbms/security/SC_PolicySpace.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,211 @@
     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 +// CPolicySpace class
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <s32file.h>
    1.22 +#include "D32Strings.h"
    1.23 +#include "D32Map.h"
    1.24 +#include "SC_Policy.h"
    1.25 +#include "SC_StrmIn.h"
    1.26 +#include "SC_PassAllPolicy.h"
    1.27 +#include "SC_DomainLoader.h"
    1.28 +#include "SC_PolicySpace.h"
    1.29 +
    1.30 +namespace DBSC
    1.31 +{
    1.32 +
    1.33 +/**
    1.34 +*/
    1.35 +inline CPolicySpace::CPolicySpace() :
    1.36 +	iPDCollection(TLinearOrder< TPair<TInt, CPolicyDomain*> > (&Compare<TInt, CPolicyDomain*>))
    1.37 +	{
    1.38 +	}
    1.39 +
    1.40 +/**
    1.41 +Standard phase-one CPolicySpace factory method
    1.42 +@param aFs A reference to a file server session object
    1.43 +@param aPrivatePath A reference to the DBMS server private directory.
    1.44 +@return A pointer to just created CPolicySpace instance.
    1.45 +@leave System-wide error codes, including KErrNoMemory
    1.46 +*/
    1.47 +CPolicySpace* CPolicySpace::NewL(RFs& aFs, const TDesC& aPrivatePath)
    1.48 +	{
    1.49 +	CPolicySpace* self = new (ELeave) CPolicySpace;
    1.50 +	CleanupReleasePushL(*self);
    1.51 +	self->ConstructL(aFs, aPrivatePath);
    1.52 +	CleanupStack::Pop(self);
    1.53 +	return self;
    1.54 +	}
    1.55 +
    1.56 +/**
    1.57 +Standard phase-two CPolicySpace construction method
    1.58 +@param aFs A reference to a file server session object
    1.59 +@param aPrivatePath A reference to the DBMS server private directory.
    1.60 +@leave System-wide error codes, including KErrNoMemory
    1.61 +*/
    1.62 +void CPolicySpace::ConstructL(RFs& aFs, const TDesC& aPrivatePath)
    1.63 +	{
    1.64 +	iPassAllDbPolicy = new (ELeave) CPassAllPolicy(EPOTDatabase);
    1.65 +	iPassAllTblPolicy = new (ELeave) CPassAllPolicy(EPOTTable);
    1.66 +	TBuf<KMaxPath>* policyDir = new (ELeave) TFileName;
    1.67 +	CleanupStack::PushL(policyDir);
    1.68 +	policyDir->Copy(aPrivatePath);
    1.69 +	policyDir->Append(KSecurityPolicyDir);
    1.70 +	TRAPD(err, LoadPolicyDomainsL(aFs, *policyDir));
    1.71 +	if(err != KErrNone && err != KErrNotFound) //it's not an error, if there are no policy files
    1.72 +		{
    1.73 +		__LEAVE(err);
    1.74 +		}
    1.75 +	CleanupStack::PopAndDestroy(policyDir);
    1.76 +	}
    1.77 +
    1.78 +/**
    1.79 +The method creates a policy domain object for each binary policy file found in the system.
    1.80 +The created objects will be added to iPDCollection collection of policy domain objects.
    1.81 +@param aFs A reference to a file server session object
    1.82 +@param aPrivatePath A reference to the DBMS server private directory.
    1.83 +@leave System-wide error codes, including KErrNoMemory
    1.84 +*/
    1.85 +void CPolicySpace::LoadPolicyDomainsL(RFs& aFs, const TDesC& aPolicyDir)
    1.86 +	{
    1.87 +	CPolicyDomainLoader* loader = CPolicyDomainLoader::NewLC(aFs, aPolicyDir, iPDCollection);
    1.88 +	loader->RunL();
    1.89 +	CleanupStack::PopAndDestroy(loader);
    1.90 +	}
    1.91 +
    1.92 +/**
    1.93 +The method returns the related with aDomainUid parameter CPolicyDomain object.
    1.94 +@param aDomainUid Domain UID
    1.95 +@return A pointer to the related with aDomainUid parameter CPolicyDomain object.
    1.96 +*/
    1.97 +CPolicyDomain* CPolicySpace::PolicyDomain(TUid aDomainUid) const
    1.98 +	{
    1.99 +	__ASSERT(aDomainUid != KNullUid);
   1.100 +	CPolicyDomain* domain = NULL;
   1.101 +	if(iPDCollection.Find(aDomainUid.iUid, domain) == KErrNone)
   1.102 +		{
   1.103 +		__ASSERT(domain);
   1.104 +		__ASSERT(domain->Uid() == aDomainUid);
   1.105 +		}
   1.106 +	return domain;
   1.107 +	}
   1.108 +
   1.109 +/**
   1.110 +*/
   1.111 +CPolicySpace::~CPolicySpace()
   1.112 +	{
   1.113 +	TMapIterator<TInt, CPolicyDomain*> it(iPDCollection);
   1.114 +	TPair<TInt, CPolicyDomain*> pair;
   1.115 +	while(it.Next(pair))
   1.116 +		{
   1.117 +		delete pair.iData;
   1.118 +		}
   1.119 +	iPDCollection.Close();
   1.120 +	delete iPassAllTblPolicy;
   1.121 +	delete iPassAllDbPolicy;
   1.122 +	}
   1.123 +
   1.124 +/**
   1.125 +Implements MPolicySpace::Release().
   1.126 +Use this method when want to destroy particular CPolicySpace object.
   1.127 +*/
   1.128 +void CPolicySpace::Release()
   1.129 +	{
   1.130 +	delete this;
   1.131 +	}
   1.132 +
   1.133 +/**
   1.134 +Implements MPolicySpace::DbPolicyL().
   1.135 +@param aDbPolicyRequest Request params: request type (secure/non-secure) and domain UID
   1.136 +@return A const pointer to the related with the request UID policy object.
   1.137 +*/
   1.138 +const MPolicy* CPolicySpace::DbPolicyL(const TDbPolicyRequest& aDbPolicyRequest) const
   1.139 +	{
   1.140 +	const MPolicy* policy = NULL;
   1.141 +	if(aDbPolicyRequest.iAccessType == EATNonSecure)
   1.142 +		{
   1.143 +		policy = iPassAllDbPolicy;
   1.144 +		}
   1.145 +	else//Secure shared database access
   1.146 +		{
   1.147 +		__ASSERT(aDbPolicyRequest.iUid != KNullUid);
   1.148 +		CPolicyDomain* domain = PolicyDomain(aDbPolicyRequest.iUid);
   1.149 +		if(domain)
   1.150 +			{
   1.151 +			policy = domain->DbPolicy();
   1.152 +			}
   1.153 +		}
   1.154 +	if(aDbPolicyRequest.iAccessType == EATSecure && !policy)
   1.155 +		{//there is no security policy associated with the supplied uid.
   1.156 +		__LEAVE(KErrArgument);
   1.157 +		}
   1.158 +	__ASSERT(policy);
   1.159 +	return policy;
   1.160 +	}
   1.161 +
   1.162 +/**
   1.163 +Implements MPolicySpace::TblPolicyL().
   1.164 +@param aDbPolicyRequest Request params: request type (secure/non-secure) and domain UID
   1.165 +@param aTblName Database table name
   1.166 +@return A const pointer to the related with the request table policy object.
   1.167 +*/
   1.168 +const MPolicy* CPolicySpace::TblPolicyL(const TDbPolicyRequest& aDbPolicyRequest, 
   1.169 +										const TDesC& aTblName) const
   1.170 +	{
   1.171 +	const MPolicy* policy = NULL;
   1.172 +	if(aDbPolicyRequest.iAccessType == EATNonSecure)
   1.173 +		{
   1.174 +		policy = iPassAllTblPolicy;
   1.175 +		}
   1.176 +	else//Secure shared database access
   1.177 +		{
   1.178 +		CPolicyDomain* domain = PolicyDomain(aDbPolicyRequest.iUid);
   1.179 +		if(domain)
   1.180 +			{
   1.181 +			policy = domain->TblPolicy(aTblName);
   1.182 +			if(!policy)
   1.183 +				{
   1.184 +				policy = domain->DbPolicy();
   1.185 +				}
   1.186 +			}
   1.187 +		}
   1.188 +	if(aDbPolicyRequest.iAccessType == EATSecure && !policy)
   1.189 +		{//there is no security policy associated with the supplied uid.
   1.190 +		__LEAVE(KErrArgument);
   1.191 +		}
   1.192 +	__ASSERT(policy);
   1.193 +	return policy;
   1.194 +	}
   1.195 +
   1.196 +/**
   1.197 +Implements MPolicySpace::BackupSIDL().
   1.198 +Returns backup&restore SID for the databases, the access to which is controlled by the
   1.199 +security policy, identified by aDbUid parameter.
   1.200 +@param aDbUid Domain UID
   1.201 +@return Backup&restore SID for the supplied domain UID
   1.202 +@leave KErrArgument if there is no security policy domain for the supplied UID.
   1.203 +*/
   1.204 +TSecureId CPolicySpace::BackupSIDL(TUid aDbUid) const
   1.205 +	{
   1.206 +	CPolicyDomain* domain = PolicyDomain(aDbUid);
   1.207 +	if(!domain)
   1.208 +		{
   1.209 +		__LEAVE(KErrArgument);
   1.210 +		}
   1.211 +	return domain->BackupSID();
   1.212 +	}
   1.213 +	
   1.214 +} //end of - namespace DBSC