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 |
// CPolicyProxy class
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "SD_STD.H"
|
sl@0
|
19 |
#include "Sd_PolicyProxy.h"
|
sl@0
|
20 |
#include "D32SQL.H"
|
sl@0
|
21 |
|
sl@0
|
22 |
using namespace DBSC;
|
sl@0
|
23 |
|
sl@0
|
24 |
/**
|
sl@0
|
25 |
TDbsFunction enum value is used as an index in KDbsFunc2SecurityPolicyMask array.
|
sl@0
|
26 |
For each TDbsFunction enum value there is a set of security policies,
|
sl@0
|
27 |
which have to be satisified by the caller capabilities (at least one of them) -
|
sl@0
|
28 |
before the related operation to be executed.
|
sl@0
|
29 |
@internalComponent
|
sl@0
|
30 |
*/
|
sl@0
|
31 |
static const TUint8 KDbsFunc2SecurityPolicyMask[EDbsLast] =
|
sl@0
|
32 |
{
|
sl@0
|
33 |
/*EDbsResourceMark*/ EPTNone,
|
sl@0
|
34 |
/*EDbsResourceCheck*/ EPTNone,
|
sl@0
|
35 |
/*EDbsResourceCount*/ EPTNone,
|
sl@0
|
36 |
/*EDbsSetHeapFailure*/ EPTNone,
|
sl@0
|
37 |
/*EDbsOpenDatabase*/ EPTRead | EPTWrite | EPTSchema, //---The caller capabilities will be asserted later, when the db security uid is known
|
sl@0
|
38 |
/*EDbsClose*/ EPTNone, //---EDbsClose may be used to close every possible type of server side dbms object
|
sl@0
|
39 |
/*EDbsDatabaseAuthenticate*/EPTNone, //---Not supported for secure shared databases
|
sl@0
|
40 |
/*EDbsDatabaseDestroy*/ EPTSchema, //---Only admin can destroy the database
|
sl@0
|
41 |
/*EDbsDatabaseBegin*/ EPTRead | EPTWrite | EPTSchema, //---Begin transaction, which makes sense if the caller wants to change the database schema or to insert/delete/update database tables or to protect its "read" operations
|
sl@0
|
42 |
/*EDbsDatabaseCommit*/ EPTRead | EPTWrite | EPTSchema, //---Commit transaction, which makes sense if the caller wants to change the database schema or to insert/delete/update database tables or to protect its "read" operations
|
sl@0
|
43 |
/*EDbsDatabaseRollback*/ EPTRead | EPTWrite | EPTSchema, //---Rollback transaction, which makes sense if the caller wants to change the database schema or to insert/delete/update database tables or to protect its "read" operations
|
sl@0
|
44 |
/*EDbsDatabaseProperty*/ EPTNone,
|
sl@0
|
45 |
/*EDbsDatabaseCreateTable*/ EPTSchema,
|
sl@0
|
46 |
/*EDbsDatabaseTables*/ EPTNone,
|
sl@0
|
47 |
/*EDbsDatabaseColumns*/ EPTNone,
|
sl@0
|
48 |
/*EDbsDatabaseIndexes*/ EPTNone,
|
sl@0
|
49 |
/*EDbsDatabaseKeys*/ EPTNone,
|
sl@0
|
50 |
/*EDbsDatabaseOpenObserver*/EPTNone,
|
sl@0
|
51 |
/*EDbsDatabaseOpenUtility*/ EPTWrite, //---Compact/Recover operations
|
sl@0
|
52 |
/*EDbsDatabaseOpenDropTable*/EPTSchema,
|
sl@0
|
53 |
/*EDbsDatabaseOpenAlterTable*/EPTSchema,
|
sl@0
|
54 |
/*EDbsDatabaseOpenCreateIndex*/EPTSchema,
|
sl@0
|
55 |
/*EDbsDatabaseOpenDropIndex*/EPTSchema,
|
sl@0
|
56 |
/*EDbsDatabaseExecute*/ EPTWrite | EPTSchema, //---either CREATE/DROP/ALTER database operations or INSERT/UPDATE/DELETE table operations. An additional caller capabilities check will be made after the parsing of the sql string.
|
sl@0
|
57 |
/*EDbsDatabasePrepareView*/ EPTRead, //---"SELECT" sql string
|
sl@0
|
58 |
/*EDbsDatabaseOpenTable*/ EPTRead | EPTWrite, //---If the caller neither have capabilities for read or write table security policies, then the the caller cannot open the table.
|
sl@0
|
59 |
/*EDbsObserverNotify*/ EPTNone,
|
sl@0
|
60 |
/*EDbsObserverCancel*/ EPTNone,
|
sl@0
|
61 |
/*EDbsIncrementalNext*/ EPTNone,
|
sl@0
|
62 |
/*EDbsCursorColumnTypes*/ EPTNone,
|
sl@0
|
63 |
/*EDbsCursorReset*/ EPTNone, //---Moves the cursor at the beginning of the table/dataset
|
sl@0
|
64 |
/*EDbsCursorEvaluate*/ EPTNone,
|
sl@0
|
65 |
/*EDbsCursorUnevaluated*/ EPTNone,
|
sl@0
|
66 |
/*EDbsCursorSetIndex*/ EPTRead,
|
sl@0
|
67 |
/*EDbsCursorSeek*/ EPTRead,
|
sl@0
|
68 |
/*EDbsCursorAtBeginning*/ EPTNone,
|
sl@0
|
69 |
/*EDbsCursorAtEnd*/ EPTNone,
|
sl@0
|
70 |
/*EDbsCursorAtRow*/ EPTNone,
|
sl@0
|
71 |
/*EDbsCursorCount*/ EPTRead | EPTWrite,
|
sl@0
|
72 |
/*EDbsCursorGotoPos*/ EPTRead,
|
sl@0
|
73 |
/*EDbsCursorBookmark*/ EPTRead,
|
sl@0
|
74 |
/*EDbsCursorGotoBookmark*/ EPTRead,
|
sl@0
|
75 |
/*EDbsCursorGet*/ EPTRead,
|
sl@0
|
76 |
/*EDbsCursorInsert*/ EPTWrite,
|
sl@0
|
77 |
/*EDbsCursorUpdate*/ EPTWrite,
|
sl@0
|
78 |
/*EDbsCursorRetrieveRow*/ EPTNone, //---Used by "Insert" operations sometime
|
sl@0
|
79 |
/*EDbsCursorCancel*/ EPTNone,
|
sl@0
|
80 |
/*EDbsCursorPut*/ EPTWrite,
|
sl@0
|
81 |
/*EDbsCursorDelete*/ EPTWrite,
|
sl@0
|
82 |
/*EDbsCursorColumns*/ EPTNone,
|
sl@0
|
83 |
/*EDbsCursorColumnDef*/ EPTNone,
|
sl@0
|
84 |
/*EDbsCursorSetNull*/ EPTWrite,
|
sl@0
|
85 |
/*EDbsCursorColumnSize*/ EPTNone,
|
sl@0
|
86 |
/*EDbsCursorColumnSource*/ EPTRead, //---Used for large BLOB fields - read ops
|
sl@0
|
87 |
/*EDbsCursorColumnSink*/ EPTWrite, //---Used for large BLOB fields - write ops
|
sl@0
|
88 |
/*EDbsCursorOpenConstraint*/EPTRead,
|
sl@0
|
89 |
/*EDbsCursorMatch*/ EPTRead,
|
sl@0
|
90 |
/*EDbsCursorFind*/ EPTRead,
|
sl@0
|
91 |
/*EDbsStreamRead*/ EPTNone,
|
sl@0
|
92 |
/*EDbsStreamWrite*/ EPTNone,
|
sl@0
|
93 |
/*EDbsStreamSize*/ EPTNone,
|
sl@0
|
94 |
/*EDbsStreamSynch*/ EPTNone,
|
sl@0
|
95 |
/*EDbsCreateDatabase*/ EPTSchema,
|
sl@0
|
96 |
/*EDbsDatabaseList*/ EPTNone,
|
sl@0
|
97 |
/*EDbsCopyDatabase*/ EPTSchema,
|
sl@0
|
98 |
/*EDbsDeleteDatabase*/ EPTSchema,
|
sl@0
|
99 |
/*EDbsGetSecurityPolicy*/ EPTNone,
|
sl@0
|
100 |
/*EDbsReserveDriveSpace*/ EPTNone,
|
sl@0
|
101 |
/*EDbsFreeReservedSpace*/ EPTNone,
|
sl@0
|
102 |
/*EDbsReserveGetAccess*/ EPTNone,
|
sl@0
|
103 |
/*EDbsReserveReleaseAccess*/EPTNone,
|
sl@0
|
104 |
/*EDbsGetBackupPath*/ EPTNone,
|
sl@0
|
105 |
/*EDbsGetBackupPaths*/ EPTNone
|
sl@0
|
106 |
};
|
sl@0
|
107 |
|
sl@0
|
108 |
/**
|
sl@0
|
109 |
This function returns bit-field mask value, containing security policies types (R/W/S)
|
sl@0
|
110 |
Each security policy contains a set of Capabilities/SID/VID.
|
sl@0
|
111 |
In order particular database operation to be executed, the caller Capabilities/SID/VID have
|
sl@0
|
112 |
to be checked against security policy Capabilities/SID/VID.
|
sl@0
|
113 |
Don't forget to map new DBMS functions here!
|
sl@0
|
114 |
@param aFunction DBMS server function code
|
sl@0
|
115 |
@return An integer mask with a set of security policy types. The caller has to satisfy at least
|
sl@0
|
116 |
one of of them.
|
sl@0
|
117 |
*/
|
sl@0
|
118 |
static TUint DbsFunction2PolicyMask(TDbsFunction aFunction)
|
sl@0
|
119 |
{
|
sl@0
|
120 |
__ASSERT(aFunction < EDbsLast);
|
sl@0
|
121 |
return KDbsFunc2SecurityPolicyMask[aFunction];
|
sl@0
|
122 |
}
|
sl@0
|
123 |
|
sl@0
|
124 |
/**
|
sl@0
|
125 |
Extracts DBMS server function code from aMessage argument.
|
sl@0
|
126 |
@param aMessage DBMS server message
|
sl@0
|
127 |
@return DBMS server function code
|
sl@0
|
128 |
@internalComponent
|
sl@0
|
129 |
*/
|
sl@0
|
130 |
static TDbsFunction Message2Function(const RMessage2& aMessage)
|
sl@0
|
131 |
{
|
sl@0
|
132 |
TDbsFunction func = ::DbsFunction(aMessage.Function());
|
sl@0
|
133 |
return static_cast <TDbsFunction> (func & ~KDbsObjectReturn);
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
/**
|
sl@0
|
137 |
*/
|
sl@0
|
138 |
inline CPolicyProxy::CPolicyProxy(RFs& aFs):iFs(aFs)
|
sl@0
|
139 |
{
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
/**
|
sl@0
|
143 |
Standard phase-one factory method for CPolicyProxy instances.
|
sl@0
|
144 |
@param aFs A file server session instance
|
sl@0
|
145 |
@param aPrivatePath DBMS server private data path
|
sl@0
|
146 |
@return A pointer to the created CPolicyProxy instance.
|
sl@0
|
147 |
@leave KErrNoMemory
|
sl@0
|
148 |
*/
|
sl@0
|
149 |
CPolicyProxy* CPolicyProxy::NewL(RFs& aFs,const TDesC& aPrivatePath)
|
sl@0
|
150 |
{
|
sl@0
|
151 |
CPolicyProxy* self = new (ELeave) CPolicyProxy(aFs);
|
sl@0
|
152 |
CleanupStack::PushL(self);
|
sl@0
|
153 |
self->ConstructL(aPrivatePath);
|
sl@0
|
154 |
CleanupStack::Pop(self);
|
sl@0
|
155 |
return self;
|
sl@0
|
156 |
}
|
sl@0
|
157 |
|
sl@0
|
158 |
/**
|
sl@0
|
159 |
*/
|
sl@0
|
160 |
CPolicyProxy::~CPolicyProxy()
|
sl@0
|
161 |
{
|
sl@0
|
162 |
if(iPolicySpace) //iPolicySpace can be NULL in OOM tests
|
sl@0
|
163 |
{
|
sl@0
|
164 |
iPolicySpace->Release();
|
sl@0
|
165 |
}
|
sl@0
|
166 |
}
|
sl@0
|
167 |
|
sl@0
|
168 |
/**
|
sl@0
|
169 |
Returns requested database security policy interface, which cannot be NULL.
|
sl@0
|
170 |
@param aDbPolicyRequest Request params: request type (secure/non-secure) and domain UID
|
sl@0
|
171 |
@return A const pointer to the related UID security policy object.
|
sl@0
|
172 |
*/
|
sl@0
|
173 |
const MPolicy* CPolicyProxy::DbPolicyL(const TDbPolicyRequest& aDbPolicyRequest)
|
sl@0
|
174 |
{
|
sl@0
|
175 |
return iPolicySpace->DbPolicyL(aDbPolicyRequest);
|
sl@0
|
176 |
}
|
sl@0
|
177 |
|
sl@0
|
178 |
/**
|
sl@0
|
179 |
Returns requested table security policy interface, which cannot be NULL.
|
sl@0
|
180 |
@param aDbPolicyRequest Request params: request type (secure/non-secure) and domain UID
|
sl@0
|
181 |
@param aTblName Database table name
|
sl@0
|
182 |
@return A const pointer to the related table security policy object.
|
sl@0
|
183 |
*/
|
sl@0
|
184 |
const MPolicy* CPolicyProxy::TblPolicyL(const TDbPolicyRequest& aDbPolicyRequest,
|
sl@0
|
185 |
const TDesC& aTblName)
|
sl@0
|
186 |
{
|
sl@0
|
187 |
return iPolicySpace->TblPolicyL(aDbPolicyRequest, aTblName);
|
sl@0
|
188 |
}
|
sl@0
|
189 |
|
sl@0
|
190 |
/**
|
sl@0
|
191 |
This method is used to get the SQL related MPolicy interface and the related security
|
sl@0
|
192 |
policy type.
|
sl@0
|
193 |
If aUPRequest.iRqAccess is EATNonSecure, then the default security policy will be returned.
|
sl@0
|
194 |
Currently the DBMS can process the following SQL strings:
|
sl@0
|
195 |
1)DDL - CREATE/DROP/ALTER SQL statements - EPTSchema database access level.
|
sl@0
|
196 |
2)DML - INSERT/UPDATE/DELETE SQL statements. Only one table can be put after the "FROM"
|
sl@0
|
197 |
SQL keyword. EPTWrite table access level.
|
sl@0
|
198 |
3)QUERY- SELECT SQL statements. Only one table can be out after the "FROM" SQL keyword.
|
sl@0
|
199 |
EPTRead table access level.
|
sl@0
|
200 |
@param aDbPolicyRequest A const reference to an object packing security policy uid and the request type:
|
sl@0
|
201 |
secure/non-secure.
|
sl@0
|
202 |
@param aSql SQL string
|
sl@0
|
203 |
@param aPolicyType An output parameter, referencing the location, where the policy type will be stored.
|
sl@0
|
204 |
@return A const pointer to the related policy interface. It cannot be NULL, and must not be deleted.
|
sl@0
|
205 |
@leave One of the system-wide error codes.
|
sl@0
|
206 |
*/
|
sl@0
|
207 |
const MPolicy* CPolicyProxy::SqlPolicyL(const TDbPolicyRequest& aDbPolicyRequest, const TDesC& aSql,
|
sl@0
|
208 |
TPolicyType& aPolicyType)
|
sl@0
|
209 |
{
|
sl@0
|
210 |
const MPolicy* policy = NULL;
|
sl@0
|
211 |
aPolicyType = EPTNone;
|
sl@0
|
212 |
//Get table name and sql type.
|
sl@0
|
213 |
TSqlParser2 sqlParser;
|
sl@0
|
214 |
sqlParser.ParseL(aSql);
|
sl@0
|
215 |
Sql::TStatementType sqlType = sqlParser.StatementType();
|
sl@0
|
216 |
//Reinitialize aSqlSecurityPolicyData, which is sql type dependent.
|
sl@0
|
217 |
switch(sqlType)
|
sl@0
|
218 |
{
|
sl@0
|
219 |
case Sql::EDDL:
|
sl@0
|
220 |
//Database EPTSchema access level
|
sl@0
|
221 |
policy = DbPolicyL(aDbPolicyRequest);
|
sl@0
|
222 |
aPolicyType = EPTSchema;
|
sl@0
|
223 |
break;
|
sl@0
|
224 |
case Sql::EDML:
|
sl@0
|
225 |
default:
|
sl@0
|
226 |
{//Table access level - EPTRead or EPTWrite.
|
sl@0
|
227 |
const TDesC& tblName = sqlParser.TableName();
|
sl@0
|
228 |
__ASSERT(tblName.Length() > 0);
|
sl@0
|
229 |
TBuf<KDbMaxName> tblNameBuf;
|
sl@0
|
230 |
tblNameBuf.Copy(tblName);
|
sl@0
|
231 |
policy = TblPolicyL(aDbPolicyRequest, tblNameBuf);
|
sl@0
|
232 |
aPolicyType = sqlType == Sql::EDML ? EPTWrite : EPTRead;
|
sl@0
|
233 |
}
|
sl@0
|
234 |
break;
|
sl@0
|
235 |
}
|
sl@0
|
236 |
__ASSERT(policy);
|
sl@0
|
237 |
return policy;
|
sl@0
|
238 |
}
|
sl@0
|
239 |
|
sl@0
|
240 |
/**
|
sl@0
|
241 |
Returns backup&restore SID for the databases, the access to which is controlled by the
|
sl@0
|
242 |
security policy, identified by aDbUid parameter.
|
sl@0
|
243 |
@param aDbUid Domain UID
|
sl@0
|
244 |
@return Backup&restore SID for the supplied domain UID
|
sl@0
|
245 |
@leave KErrArgument if there is no security policy domain for the supplied UID.
|
sl@0
|
246 |
*/
|
sl@0
|
247 |
TSecureId CPolicyProxy::BackupSIDL(TUid aDbUid) const
|
sl@0
|
248 |
{
|
sl@0
|
249 |
return iPolicySpace->BackupSIDL(aDbUid);
|
sl@0
|
250 |
}
|
sl@0
|
251 |
|
sl@0
|
252 |
/**
|
sl@0
|
253 |
Asserts caller capabilities/SID/VID, packed in aMessage parameter against the security policy
|
sl@0
|
254 |
managed by aPolicy parameter. The caller has to satisfy at least one of the related to
|
sl@0
|
255 |
the message security policies.
|
sl@0
|
256 |
@param aMessage An object whith caller capabilities/SID/VID, which has to be checked.
|
sl@0
|
257 |
@param aPolicy A const reference to the security policy object.
|
sl@0
|
258 |
@leave KErrPermissionDenied The caller has no enough rights for the requested DBMS operation
|
sl@0
|
259 |
*/
|
sl@0
|
260 |
void CPolicyProxy::CheckL(const RMessage2& aMessage, const MPolicy& aPolicy) const
|
sl@0
|
261 |
{
|
sl@0
|
262 |
TDbsFunction func = ::Message2Function(aMessage);
|
sl@0
|
263 |
TUint mask = ::DbsFunction2PolicyMask(func);
|
sl@0
|
264 |
if(mask != EPTNone)
|
sl@0
|
265 |
{
|
sl@0
|
266 |
for(TInt c=0;c<KPolicyTypesCount;++c)
|
sl@0
|
267 |
{
|
sl@0
|
268 |
TPolicyType policyType = static_cast <TPolicyType> (1 << c);
|
sl@0
|
269 |
if(policyType & mask)
|
sl@0
|
270 |
{
|
sl@0
|
271 |
if(aPolicy.Check(aMessage, policyType))
|
sl@0
|
272 |
{
|
sl@0
|
273 |
return;
|
sl@0
|
274 |
}
|
sl@0
|
275 |
}
|
sl@0
|
276 |
}
|
sl@0
|
277 |
__LEAVE(KErrPermissionDenied);
|
sl@0
|
278 |
}
|
sl@0
|
279 |
}
|
sl@0
|
280 |
|
sl@0
|
281 |
/**
|
sl@0
|
282 |
Asserts caller capabilities/SID/VID, packed in aMessage parameter against the security policy
|
sl@0
|
283 |
managed by aPolicy parameter.
|
sl@0
|
284 |
@param aPolicyType The policy type, against which the check has to be done.
|
sl@0
|
285 |
@param aMessage An object whith caller capabilities/SID/VID, which has to be checked.
|
sl@0
|
286 |
@param aPolicy A const reference to the security policy object.
|
sl@0
|
287 |
@leave KErrPermissionDenied The caller has no enough rights for the requested DBMS operation
|
sl@0
|
288 |
*/
|
sl@0
|
289 |
void CPolicyProxy::CheckL(TPolicyType aPolicyType, const RMessage2& aMessage, const MPolicy& aPolicy) const
|
sl@0
|
290 |
{
|
sl@0
|
291 |
if(aPolicyType != EPTNone)
|
sl@0
|
292 |
{
|
sl@0
|
293 |
if(!aPolicy.Check(aMessage, aPolicyType))
|
sl@0
|
294 |
{
|
sl@0
|
295 |
__LEAVE(KErrPermissionDenied);
|
sl@0
|
296 |
}
|
sl@0
|
297 |
}
|
sl@0
|
298 |
}
|
sl@0
|
299 |
|
sl@0
|
300 |
/**
|
sl@0
|
301 |
Standard phase-two construction method for CPolicyProxy instances.
|
sl@0
|
302 |
@param aPrivatePath DBMS server private data path
|
sl@0
|
303 |
@leave KErrNoMemory
|
sl@0
|
304 |
*/
|
sl@0
|
305 |
void CPolicyProxy::ConstructL(const TDesC& aPrivatePath)
|
sl@0
|
306 |
{
|
sl@0
|
307 |
iPolicySpace = TPolicySpaceFactory::NewPolicySpaceL(iFs, aPrivatePath);
|
sl@0
|
308 |
}
|
sl@0
|
309 |
|