os/persistentdata/persistentstorage/dbms/security/SC_PolicySpace.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// CPolicySpace class
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <s32file.h>
sl@0
    19
#include "D32Strings.h"
sl@0
    20
#include "D32Map.h"
sl@0
    21
#include "SC_Policy.h"
sl@0
    22
#include "SC_StrmIn.h"
sl@0
    23
#include "SC_PassAllPolicy.h"
sl@0
    24
#include "SC_DomainLoader.h"
sl@0
    25
#include "SC_PolicySpace.h"
sl@0
    26
sl@0
    27
namespace DBSC
sl@0
    28
{
sl@0
    29
sl@0
    30
/**
sl@0
    31
*/
sl@0
    32
inline CPolicySpace::CPolicySpace() :
sl@0
    33
	iPDCollection(TLinearOrder< TPair<TInt, CPolicyDomain*> > (&Compare<TInt, CPolicyDomain*>))
sl@0
    34
	{
sl@0
    35
	}
sl@0
    36
sl@0
    37
/**
sl@0
    38
Standard phase-one CPolicySpace factory method
sl@0
    39
@param aFs A reference to a file server session object
sl@0
    40
@param aPrivatePath A reference to the DBMS server private directory.
sl@0
    41
@return A pointer to just created CPolicySpace instance.
sl@0
    42
@leave System-wide error codes, including KErrNoMemory
sl@0
    43
*/
sl@0
    44
CPolicySpace* CPolicySpace::NewL(RFs& aFs, const TDesC& aPrivatePath)
sl@0
    45
	{
sl@0
    46
	CPolicySpace* self = new (ELeave) CPolicySpace;
sl@0
    47
	CleanupReleasePushL(*self);
sl@0
    48
	self->ConstructL(aFs, aPrivatePath);
sl@0
    49
	CleanupStack::Pop(self);
sl@0
    50
	return self;
sl@0
    51
	}
sl@0
    52
sl@0
    53
/**
sl@0
    54
Standard phase-two CPolicySpace construction method
sl@0
    55
@param aFs A reference to a file server session object
sl@0
    56
@param aPrivatePath A reference to the DBMS server private directory.
sl@0
    57
@leave System-wide error codes, including KErrNoMemory
sl@0
    58
*/
sl@0
    59
void CPolicySpace::ConstructL(RFs& aFs, const TDesC& aPrivatePath)
sl@0
    60
	{
sl@0
    61
	iPassAllDbPolicy = new (ELeave) CPassAllPolicy(EPOTDatabase);
sl@0
    62
	iPassAllTblPolicy = new (ELeave) CPassAllPolicy(EPOTTable);
sl@0
    63
	TBuf<KMaxPath>* policyDir = new (ELeave) TFileName;
sl@0
    64
	CleanupStack::PushL(policyDir);
sl@0
    65
	policyDir->Copy(aPrivatePath);
sl@0
    66
	policyDir->Append(KSecurityPolicyDir);
sl@0
    67
	TRAPD(err, LoadPolicyDomainsL(aFs, *policyDir));
sl@0
    68
	if(err != KErrNone && err != KErrNotFound) //it's not an error, if there are no policy files
sl@0
    69
		{
sl@0
    70
		__LEAVE(err);
sl@0
    71
		}
sl@0
    72
	CleanupStack::PopAndDestroy(policyDir);
sl@0
    73
	}
sl@0
    74
sl@0
    75
/**
sl@0
    76
The method creates a policy domain object for each binary policy file found in the system.
sl@0
    77
The created objects will be added to iPDCollection collection of policy domain objects.
sl@0
    78
@param aFs A reference to a file server session object
sl@0
    79
@param aPrivatePath A reference to the DBMS server private directory.
sl@0
    80
@leave System-wide error codes, including KErrNoMemory
sl@0
    81
*/
sl@0
    82
void CPolicySpace::LoadPolicyDomainsL(RFs& aFs, const TDesC& aPolicyDir)
sl@0
    83
	{
sl@0
    84
	CPolicyDomainLoader* loader = CPolicyDomainLoader::NewLC(aFs, aPolicyDir, iPDCollection);
sl@0
    85
	loader->RunL();
sl@0
    86
	CleanupStack::PopAndDestroy(loader);
sl@0
    87
	}
sl@0
    88
sl@0
    89
/**
sl@0
    90
The method returns the related with aDomainUid parameter CPolicyDomain object.
sl@0
    91
@param aDomainUid Domain UID
sl@0
    92
@return A pointer to the related with aDomainUid parameter CPolicyDomain object.
sl@0
    93
*/
sl@0
    94
CPolicyDomain* CPolicySpace::PolicyDomain(TUid aDomainUid) const
sl@0
    95
	{
sl@0
    96
	__ASSERT(aDomainUid != KNullUid);
sl@0
    97
	CPolicyDomain* domain = NULL;
sl@0
    98
	if(iPDCollection.Find(aDomainUid.iUid, domain) == KErrNone)
sl@0
    99
		{
sl@0
   100
		__ASSERT(domain);
sl@0
   101
		__ASSERT(domain->Uid() == aDomainUid);
sl@0
   102
		}
sl@0
   103
	return domain;
sl@0
   104
	}
sl@0
   105
sl@0
   106
/**
sl@0
   107
*/
sl@0
   108
CPolicySpace::~CPolicySpace()
sl@0
   109
	{
sl@0
   110
	TMapIterator<TInt, CPolicyDomain*> it(iPDCollection);
sl@0
   111
	TPair<TInt, CPolicyDomain*> pair;
sl@0
   112
	while(it.Next(pair))
sl@0
   113
		{
sl@0
   114
		delete pair.iData;
sl@0
   115
		}
sl@0
   116
	iPDCollection.Close();
sl@0
   117
	delete iPassAllTblPolicy;
sl@0
   118
	delete iPassAllDbPolicy;
sl@0
   119
	}
sl@0
   120
sl@0
   121
/**
sl@0
   122
Implements MPolicySpace::Release().
sl@0
   123
Use this method when want to destroy particular CPolicySpace object.
sl@0
   124
*/
sl@0
   125
void CPolicySpace::Release()
sl@0
   126
	{
sl@0
   127
	delete this;
sl@0
   128
	}
sl@0
   129
sl@0
   130
/**
sl@0
   131
Implements MPolicySpace::DbPolicyL().
sl@0
   132
@param aDbPolicyRequest Request params: request type (secure/non-secure) and domain UID
sl@0
   133
@return A const pointer to the related with the request UID policy object.
sl@0
   134
*/
sl@0
   135
const MPolicy* CPolicySpace::DbPolicyL(const TDbPolicyRequest& aDbPolicyRequest) const
sl@0
   136
	{
sl@0
   137
	const MPolicy* policy = NULL;
sl@0
   138
	if(aDbPolicyRequest.iAccessType == EATNonSecure)
sl@0
   139
		{
sl@0
   140
		policy = iPassAllDbPolicy;
sl@0
   141
		}
sl@0
   142
	else//Secure shared database access
sl@0
   143
		{
sl@0
   144
		__ASSERT(aDbPolicyRequest.iUid != KNullUid);
sl@0
   145
		CPolicyDomain* domain = PolicyDomain(aDbPolicyRequest.iUid);
sl@0
   146
		if(domain)
sl@0
   147
			{
sl@0
   148
			policy = domain->DbPolicy();
sl@0
   149
			}
sl@0
   150
		}
sl@0
   151
	if(aDbPolicyRequest.iAccessType == EATSecure && !policy)
sl@0
   152
		{//there is no security policy associated with the supplied uid.
sl@0
   153
		__LEAVE(KErrArgument);
sl@0
   154
		}
sl@0
   155
	__ASSERT(policy);
sl@0
   156
	return policy;
sl@0
   157
	}
sl@0
   158
sl@0
   159
/**
sl@0
   160
Implements MPolicySpace::TblPolicyL().
sl@0
   161
@param aDbPolicyRequest Request params: request type (secure/non-secure) and domain UID
sl@0
   162
@param aTblName Database table name
sl@0
   163
@return A const pointer to the related with the request table policy object.
sl@0
   164
*/
sl@0
   165
const MPolicy* CPolicySpace::TblPolicyL(const TDbPolicyRequest& aDbPolicyRequest, 
sl@0
   166
										const TDesC& aTblName) const
sl@0
   167
	{
sl@0
   168
	const MPolicy* policy = NULL;
sl@0
   169
	if(aDbPolicyRequest.iAccessType == EATNonSecure)
sl@0
   170
		{
sl@0
   171
		policy = iPassAllTblPolicy;
sl@0
   172
		}
sl@0
   173
	else//Secure shared database access
sl@0
   174
		{
sl@0
   175
		CPolicyDomain* domain = PolicyDomain(aDbPolicyRequest.iUid);
sl@0
   176
		if(domain)
sl@0
   177
			{
sl@0
   178
			policy = domain->TblPolicy(aTblName);
sl@0
   179
			if(!policy)
sl@0
   180
				{
sl@0
   181
				policy = domain->DbPolicy();
sl@0
   182
				}
sl@0
   183
			}
sl@0
   184
		}
sl@0
   185
	if(aDbPolicyRequest.iAccessType == EATSecure && !policy)
sl@0
   186
		{//there is no security policy associated with the supplied uid.
sl@0
   187
		__LEAVE(KErrArgument);
sl@0
   188
		}
sl@0
   189
	__ASSERT(policy);
sl@0
   190
	return policy;
sl@0
   191
	}
sl@0
   192
sl@0
   193
/**
sl@0
   194
Implements MPolicySpace::BackupSIDL().
sl@0
   195
Returns backup&restore SID for the databases, the access to which is controlled by the
sl@0
   196
security policy, identified by aDbUid parameter.
sl@0
   197
@param aDbUid Domain UID
sl@0
   198
@return Backup&restore SID for the supplied domain UID
sl@0
   199
@leave KErrArgument if there is no security policy domain for the supplied UID.
sl@0
   200
*/
sl@0
   201
TSecureId CPolicySpace::BackupSIDL(TUid aDbUid) const
sl@0
   202
	{
sl@0
   203
	CPolicyDomain* domain = PolicyDomain(aDbUid);
sl@0
   204
	if(!domain)
sl@0
   205
		{
sl@0
   206
		__LEAVE(KErrArgument);
sl@0
   207
		}
sl@0
   208
	return domain->BackupSID();
sl@0
   209
	}
sl@0
   210
	
sl@0
   211
} //end of - namespace DBSC