0
|
1 |
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32test\secure\t_polsvr.cpp
|
|
15 |
// Overview:
|
|
16 |
// Policy Server Tests
|
|
17 |
// API Information:
|
|
18 |
// CPolicyServer
|
|
19 |
// Details:
|
|
20 |
// - Perform various policy server tests:
|
|
21 |
// Server1 has implementations of CustomSecurityCheckL and
|
|
22 |
// CustomFailureActionL This is the test for all the paths in a policy servers
|
|
23 |
// implementations -- not all connect paths though
|
|
24 |
// This test also ensures that every path through the binary search is
|
|
25 |
// covered.
|
|
26 |
// Policy2,3,4,5,6, are bad policies that should cause the server to panic
|
|
27 |
// in debug mode. In release, they'll just pass, however, if you later tried
|
|
28 |
// to use them, something would go horribly wrong
|
|
29 |
// Policies 7,8,9 check various types of connect policies.
|
|
30 |
// Server 1,2,3 are used here all with policy 8 because you can only test 1
|
|
31 |
// type of connect policy per server.
|
|
32 |
// Sever2 does not have implementations of CustomSecurityCheckL and
|
|
33 |
// CustomFailureActionL. When these functions are called it should crash
|
|
34 |
// Server4 is used for checking what happens when the custom functions use
|
|
35 |
// another active object. This test encompasses leaving due to OOM, and
|
|
36 |
// cancellation.
|
|
37 |
// Platforms/Drives/Compatibility:
|
|
38 |
// All.
|
|
39 |
// Assumptions/Requirement/Pre-requisites:
|
|
40 |
// Failures and causes:
|
|
41 |
// Base Port information:
|
|
42 |
//
|
|
43 |
//
|
|
44 |
|
|
45 |
#include <e32test.h>
|
|
46 |
#include <e32debug.h>
|
|
47 |
|
|
48 |
LOCAL_D RTest test(_L("T_POLSVR"));
|
|
49 |
|
|
50 |
_LIT(KPolSvr, "T_POLSVR");
|
|
51 |
|
|
52 |
#define Debug(x) RDebug::Print(_L(x))
|
|
53 |
|
|
54 |
const TUint32 KTestCapabilities =(1<<ECapabilityTCB)
|
|
55 |
|(1<<ECapabilityPowerMgmt)
|
|
56 |
|(1<<ECapabilityReadDeviceData)
|
|
57 |
|(1<<ECapabilityDRM)
|
|
58 |
|(1<<ECapabilityProtServ)
|
|
59 |
|(1<<ECapabilityNetworkControl)
|
|
60 |
|(1<<ECapabilitySwEvent)
|
|
61 |
|(1<<ECapabilityLocalServices)
|
|
62 |
|(1<<ECapabilityWriteUserData);
|
|
63 |
|
|
64 |
const TInt KCustomCheckMask = 0x01000000;
|
|
65 |
const TInt KCustomActionMask = 0x02000000;
|
|
66 |
const TInt KServiceLMask = 0x04000000;
|
|
67 |
const TInt KActiveCheckMask = 0x08000000;
|
|
68 |
const TInt KActiveActionMask = 0x00100000;
|
|
69 |
const TInt KActiveRunLMask = 0x00200000;
|
|
70 |
const TInt KActiveRunErrorMask = 0x00400000;
|
|
71 |
const TInt KActiveDoCancelMask = 0x00800000;
|
|
72 |
const TInt KServiceErrorMask = 0x00010000;
|
|
73 |
|
|
74 |
//Ideally this constant should go in your derived server. However, I couldn't
|
|
75 |
//be bothered to put the same constant in every one of the derived servers in
|
|
76 |
//this test code
|
|
77 |
const TInt KQueryUser = -1;
|
|
78 |
|
|
79 |
void OrInFlags(const RMessage2& aMsg, TUint aMask)
|
|
80 |
{
|
|
81 |
TBuf8<4> flags(0);
|
|
82 |
TInt r = aMsg.Read(0, flags);
|
|
83 |
test(r == KErrNone);
|
|
84 |
(*(TUint32*)(flags.Ptr())) |= aMask;
|
|
85 |
flags.SetLength(4);
|
|
86 |
r = aMsg.Write(0, flags);
|
|
87 |
test(r == KErrNone);
|
|
88 |
}
|
|
89 |
|
|
90 |
void SetFlags(TDes8& aDes, TUint aValue)
|
|
91 |
{
|
|
92 |
(*(TUint32*)(aDes.Ptr())) = aValue;
|
|
93 |
}
|
|
94 |
|
|
95 |
TUint FlagsValue(const TDes8& aDes)
|
|
96 |
{
|
|
97 |
return (*(TUint32*)(aDes.Ptr()));
|
|
98 |
}
|
|
99 |
|
|
100 |
enum TTestProcessFunctions
|
|
101 |
{
|
|
102 |
ETestProcessPolicyServer,
|
|
103 |
};
|
|
104 |
|
|
105 |
enum TTestServerIndex
|
|
106 |
{
|
|
107 |
ETestServer1=0,
|
|
108 |
ETestServer2,
|
|
109 |
ETestServer3,
|
|
110 |
ETestServer4,
|
|
111 |
};
|
|
112 |
|
|
113 |
enum TServerPolicyIndex
|
|
114 |
{
|
|
115 |
EPolicy1=0,
|
|
116 |
EPolicy2,
|
|
117 |
EPolicy3,
|
|
118 |
EPolicy4,
|
|
119 |
EPolicy5,
|
|
120 |
EPolicy6,
|
|
121 |
EPolicy7,
|
|
122 |
EPolicy8,
|
|
123 |
EPolicy9,
|
|
124 |
EPolicy10,
|
|
125 |
EPolicy11,
|
|
126 |
EPolicy12,
|
|
127 |
};
|
|
128 |
|
|
129 |
//
|
|
130 |
// EPolicy1
|
|
131 |
//
|
|
132 |
|
|
133 |
const TUint gServerPolicy1RangeCount = 12;
|
|
134 |
const TInt gServerPolicy1Ranges[gServerPolicy1RangeCount] = {
|
|
135 |
0, //ENotSupported
|
|
136 |
1, //ECustomCheck
|
|
137 |
6, //EAlwaysPass
|
|
138 |
7, //ENotSupported
|
|
139 |
8, //->0
|
|
140 |
9, //->1
|
|
141 |
10, //->2
|
|
142 |
11, //->3
|
|
143 |
12, //->3
|
|
144 |
13, //ENotSupported
|
|
145 |
100, //EAlwaysPass -> Shutdown
|
|
146 |
101, //ENotSupported
|
|
147 |
};
|
|
148 |
|
|
149 |
const TUint8 gServerPolicy1ElementsIndex[] = {
|
|
150 |
CPolicyServer::ENotSupported,
|
|
151 |
CPolicyServer::ECustomCheck,
|
|
152 |
CPolicyServer::EAlwaysPass,
|
|
153 |
CPolicyServer::ENotSupported,
|
|
154 |
0, //RequireNetworkControl or EFail
|
|
155 |
1, //RequireNetworkControl or EQueryUser
|
|
156 |
2, //RequireDiskAdmin or EFail
|
|
157 |
3, //RequireDiskAdmin or EQueryUser
|
|
158 |
3, //RequireDiskAdmin or EQueryUser
|
|
159 |
CPolicyServer::ENotSupported,
|
|
160 |
CPolicyServer::EAlwaysPass,
|
|
161 |
CPolicyServer::ENotSupported,
|
|
162 |
};
|
|
163 |
|
|
164 |
const CPolicyServer::TPolicyElement gServerPolicy1Elements[] =
|
|
165 |
{
|
|
166 |
{_INIT_SECURITY_POLICY_C1(ECapabilityNetworkControl),CPolicyServer::EFailClient},
|
|
167 |
{_INIT_SECURITY_POLICY_C1(ECapabilityNetworkControl),KQueryUser},
|
|
168 |
{_INIT_SECURITY_POLICY_C1(ECapabilityDiskAdmin),CPolicyServer::EFailClient},
|
|
169 |
{_INIT_SECURITY_POLICY_C1(ECapabilityDiskAdmin),KQueryUser},
|
|
170 |
};
|
|
171 |
|
|
172 |
const CPolicyServer::TPolicy gServerPolicy1 =
|
|
173 |
{
|
|
174 |
CPolicyServer::EAlwaysPass,gServerPolicy1RangeCount,
|
|
175 |
gServerPolicy1Ranges,
|
|
176 |
gServerPolicy1ElementsIndex,
|
|
177 |
gServerPolicy1Elements,
|
|
178 |
};
|
|
179 |
|
|
180 |
//
|
|
181 |
//EPolicy2
|
|
182 |
//
|
|
183 |
|
|
184 |
const TUint gServerPolicy2RangeCount = 1;
|
|
185 |
//Invalid Policy -- doesn't start with 0
|
|
186 |
const TInt gServerPolicy2Ranges[gServerPolicy2RangeCount] = {
|
|
187 |
1, //KErrNotSupported
|
|
188 |
};
|
|
189 |
|
|
190 |
const TUint8 gServerPolicy2ElementsIndex[] = {
|
|
191 |
CPolicyServer::ENotSupported,
|
|
192 |
};
|
|
193 |
|
|
194 |
const CPolicyServer::TPolicyElement gServerPolicy2Elements[] =
|
|
195 |
{
|
|
196 |
{_INIT_SECURITY_POLICY_FAIL,CPolicyServer::EFailClient},
|
|
197 |
};
|
|
198 |
|
|
199 |
const CPolicyServer::TPolicy gServerPolicy2 =
|
|
200 |
{
|
|
201 |
0,gServerPolicy2RangeCount,
|
|
202 |
gServerPolicy2Ranges,
|
|
203 |
gServerPolicy2ElementsIndex,
|
|
204 |
gServerPolicy2Elements
|
|
205 |
};
|
|
206 |
|
|
207 |
//
|
|
208 |
//EPolicy3
|
|
209 |
//
|
|
210 |
|
|
211 |
const TUint gServerPolicy3RangeCount = 12;
|
|
212 |
//Invalid Policy -- range values not increasing
|
|
213 |
const TInt gServerPolicy3Ranges[gServerPolicy3RangeCount] = {
|
|
214 |
0, //ECustomCheck
|
|
215 |
6, //EAlwaysPass
|
|
216 |
7, //ENotSupported
|
|
217 |
8, //->0
|
|
218 |
9, //->1
|
|
219 |
10, //->2
|
|
220 |
11, //->3
|
|
221 |
12, //->3
|
|
222 |
13, //ENotSupported
|
|
223 |
100, //EAlwaysPass -> Shutdown
|
|
224 |
101, //ENotSupported
|
|
225 |
99, //EAlwaysPass
|
|
226 |
};
|
|
227 |
|
|
228 |
const TUint8 gServerPolicy3ElementsIndex[] = {
|
|
229 |
CPolicyServer::ECustomCheck,
|
|
230 |
CPolicyServer::EAlwaysPass,
|
|
231 |
CPolicyServer::ENotSupported,
|
|
232 |
0, //RequireNetworkControl or EFail
|
|
233 |
1, //RequireNetworkControl or EQueryUser
|
|
234 |
2, //RequireDiskAdmin or EFail
|
|
235 |
3, //RequireDiskAdmin or EQueryUser
|
|
236 |
3, //RequireDiskAdmin or EQueryUser
|
|
237 |
CPolicyServer::ENotSupported,
|
|
238 |
CPolicyServer::EAlwaysPass,
|
|
239 |
CPolicyServer::ENotSupported,
|
|
240 |
CPolicyServer::EAlwaysPass,
|
|
241 |
};
|
|
242 |
|
|
243 |
const CPolicyServer::TPolicyElement gServerPolicy3Elements[] =
|
|
244 |
{
|
|
245 |
{_INIT_SECURITY_POLICY_C1(ECapabilityNetworkControl),CPolicyServer::EFailClient},
|
|
246 |
{_INIT_SECURITY_POLICY_C1(ECapabilityNetworkControl),KQueryUser},
|
|
247 |
{_INIT_SECURITY_POLICY_C1(ECapabilityDiskAdmin),CPolicyServer::EFailClient},
|
|
248 |
{_INIT_SECURITY_POLICY_C1(ECapabilityDiskAdmin),KQueryUser},
|
|
249 |
};
|
|
250 |
|
|
251 |
const CPolicyServer::TPolicy gServerPolicy3 =
|
|
252 |
{
|
|
253 |
0,gServerPolicy3RangeCount,
|
|
254 |
gServerPolicy3Ranges,
|
|
255 |
gServerPolicy3ElementsIndex,
|
|
256 |
gServerPolicy3Elements
|
|
257 |
};
|
|
258 |
|
|
259 |
//
|
|
260 |
//EPolicy4
|
|
261 |
//
|
|
262 |
|
|
263 |
const TUint gServerPolicy4RangeCount = 1;
|
|
264 |
//Invalid Policy -- Elements Index has invalid values
|
|
265 |
const TInt gServerPolicy4Ranges[gServerPolicy4RangeCount] = {
|
|
266 |
0, //Invalid value
|
|
267 |
};
|
|
268 |
|
|
269 |
const TUint8 gServerPolicy4ElementsIndex[] = {
|
|
270 |
CPolicyServer::ESpecialCaseHardLimit,
|
|
271 |
};
|
|
272 |
|
|
273 |
const CPolicyServer::TPolicyElement gServerPolicy4Elements[] =
|
|
274 |
{
|
|
275 |
{_INIT_SECURITY_POLICY_FAIL,CPolicyServer::EFailClient},
|
|
276 |
};
|
|
277 |
|
|
278 |
const CPolicyServer::TPolicy gServerPolicy4 =
|
|
279 |
{
|
|
280 |
0,gServerPolicy4RangeCount,
|
|
281 |
gServerPolicy4Ranges,
|
|
282 |
gServerPolicy4ElementsIndex,
|
|
283 |
gServerPolicy4Elements
|
|
284 |
};
|
|
285 |
|
|
286 |
//
|
|
287 |
//EPolicy5
|
|
288 |
//
|
|
289 |
|
|
290 |
const TUint gServerPolicy5RangeCount = 1;
|
|
291 |
//Invalid Policy -- Elements Index has invalid values
|
|
292 |
const TInt gServerPolicy5Ranges[gServerPolicy5RangeCount] = {
|
|
293 |
0, //uses Invalid value
|
|
294 |
};
|
|
295 |
|
|
296 |
const TUint8 gServerPolicy5ElementsIndex[] = {
|
|
297 |
//Uses invalid value
|
|
298 |
CPolicyServer::ESpecialCaseLimit,
|
|
299 |
};
|
|
300 |
|
|
301 |
const CPolicyServer::TPolicyElement gServerPolicy5Elements[] =
|
|
302 |
{
|
|
303 |
{_INIT_SECURITY_POLICY_FAIL,CPolicyServer::EFailClient},
|
|
304 |
};
|
|
305 |
|
|
306 |
const CPolicyServer::TPolicy gServerPolicy5 =
|
|
307 |
{
|
|
308 |
0,gServerPolicy5RangeCount,
|
|
309 |
gServerPolicy5Ranges,
|
|
310 |
gServerPolicy5ElementsIndex,
|
|
311 |
gServerPolicy5Elements
|
|
312 |
};
|
|
313 |
|
|
314 |
//
|
|
315 |
//EPolicy6
|
|
316 |
//
|
|
317 |
|
|
318 |
const TUint gServerPolicy6RangeCount = 1;
|
|
319 |
//Invalid Policy -- Elements Index has invalid values
|
|
320 |
const TInt gServerPolicy6Ranges[gServerPolicy6RangeCount] = {
|
|
321 |
0,
|
|
322 |
};
|
|
323 |
|
|
324 |
const TUint8 gServerPolicy6ElementsIndex[] = {
|
|
325 |
CPolicyServer::ENotSupported,
|
|
326 |
};
|
|
327 |
|
|
328 |
const CPolicyServer::TPolicyElement gServerPolicy6Elements[] =
|
|
329 |
{
|
|
330 |
{_INIT_SECURITY_POLICY_FAIL,CPolicyServer::EFailClient},
|
|
331 |
};
|
|
332 |
|
|
333 |
const CPolicyServer::TPolicy gServerPolicy6 =
|
|
334 |
{
|
|
335 |
//Uses invalid value for iOnConnect
|
|
336 |
CPolicyServer::ESpecialCaseHardLimit,gServerPolicy6RangeCount,
|
|
337 |
gServerPolicy6Ranges,
|
|
338 |
gServerPolicy6ElementsIndex,
|
|
339 |
gServerPolicy6Elements
|
|
340 |
};
|
|
341 |
|
|
342 |
//
|
|
343 |
//EPolicy7
|
|
344 |
//
|
|
345 |
// Connect not supported
|
|
346 |
const TUint gServerPolicy7RangeCount = 1;
|
|
347 |
const TInt gServerPolicy7Ranges[gServerPolicy7RangeCount] = {
|
|
348 |
0,
|
|
349 |
};
|
|
350 |
|
|
351 |
const TUint8 gServerPolicy7ElementsIndex[] = {
|
|
352 |
0
|
|
353 |
};
|
|
354 |
|
|
355 |
const CPolicyServer::TPolicyElement gServerPolicy7Elements[] =
|
|
356 |
{
|
|
357 |
{_INIT_SECURITY_POLICY_FAIL,CPolicyServer::EFailClient},
|
|
358 |
};
|
|
359 |
|
|
360 |
const CPolicyServer::TPolicy gServerPolicy7 =
|
|
361 |
{
|
|
362 |
CPolicyServer::ENotSupported,gServerPolicy7RangeCount,
|
|
363 |
gServerPolicy7Ranges,
|
|
364 |
gServerPolicy7ElementsIndex,
|
|
365 |
gServerPolicy7Elements
|
|
366 |
};
|
|
367 |
|
|
368 |
//
|
|
369 |
//EPolicy8
|
|
370 |
//
|
|
371 |
// Connect Custom Check
|
|
372 |
const TUint gServerPolicy8RangeCount = 1;
|
|
373 |
const TInt gServerPolicy8Ranges[gServerPolicy8RangeCount] = {
|
|
374 |
0,
|
|
375 |
};
|
|
376 |
|
|
377 |
const TUint8 gServerPolicy8ElementsIndex[] = {
|
|
378 |
0
|
|
379 |
};
|
|
380 |
|
|
381 |
const CPolicyServer::TPolicyElement gServerPolicy8Elements[] =
|
|
382 |
{
|
|
383 |
{_INIT_SECURITY_POLICY_FAIL,CPolicyServer::EPanicClient},
|
|
384 |
};
|
|
385 |
|
|
386 |
const CPolicyServer::TPolicy gServerPolicy8 =
|
|
387 |
{
|
|
388 |
CPolicyServer::ECustomCheck,gServerPolicy8RangeCount,
|
|
389 |
gServerPolicy8Ranges,
|
|
390 |
gServerPolicy8ElementsIndex,
|
|
391 |
gServerPolicy8Elements
|
|
392 |
};
|
|
393 |
|
|
394 |
//
|
|
395 |
//EPolicy9
|
|
396 |
//
|
|
397 |
// Connect has a static policy but it fails.
|
|
398 |
const TUint gServerPolicy9RangeCount = 1;
|
|
399 |
const TInt gServerPolicy9Ranges[gServerPolicy9RangeCount] = {
|
|
400 |
0,
|
|
401 |
};
|
|
402 |
|
|
403 |
const TUint8 gServerPolicy9ElementsIndex[] = {
|
|
404 |
0
|
|
405 |
};
|
|
406 |
|
|
407 |
const CPolicyServer::TPolicyElement gServerPolicy9Elements[] =
|
|
408 |
{
|
|
409 |
{_INIT_SECURITY_POLICY_FAIL,CPolicyServer::EFailClient},
|
|
410 |
};
|
|
411 |
|
|
412 |
const CPolicyServer::TPolicy gServerPolicy9 =
|
|
413 |
{
|
|
414 |
0,gServerPolicy9RangeCount,
|
|
415 |
gServerPolicy9Ranges,
|
|
416 |
gServerPolicy9ElementsIndex,
|
|
417 |
gServerPolicy9Elements
|
|
418 |
};
|
|
419 |
|
|
420 |
//
|
|
421 |
// EPolicy10
|
|
422 |
//
|
|
423 |
|
|
424 |
const TUint gServerPolicy10RangeCount = 13;
|
|
425 |
const TInt gServerPolicy10Ranges[gServerPolicy10RangeCount] = {
|
|
426 |
0, //ECustomCheck
|
|
427 |
5, //EAlwaysPass
|
|
428 |
6, //ENotSupported
|
|
429 |
8, //->0
|
|
430 |
9, //->3
|
|
431 |
10, //->2
|
|
432 |
11, //->1
|
|
433 |
12, //ENotSupported
|
|
434 |
55, //->3
|
|
435 |
58, //ENotSupported
|
|
436 |
100, //EAlwaysPass -> Shutdown
|
|
437 |
101, //ENotSupported
|
|
438 |
KMaxTInt, //EAlways Pass
|
|
439 |
};
|
|
440 |
|
|
441 |
const TUint8 gServerPolicy10ElementsIndex[] = {
|
|
442 |
CPolicyServer::ECustomCheck,
|
|
443 |
CPolicyServer::EAlwaysPass,
|
|
444 |
CPolicyServer::ENotSupported,
|
|
445 |
0, //RequireNetworkControl or EFail
|
|
446 |
3, //RequireDiskAdmin or EQueryUser
|
|
447 |
2, //RequireDiskAdmin or EFail
|
|
448 |
1, //RequireNetworkControl or EQueryUser
|
|
449 |
CPolicyServer::ENotSupported,
|
|
450 |
3,
|
|
451 |
CPolicyServer::ENotSupported,
|
|
452 |
CPolicyServer::EAlwaysPass,
|
|
453 |
CPolicyServer::ENotSupported,
|
|
454 |
CPolicyServer::EAlwaysPass,
|
|
455 |
};
|
|
456 |
|
|
457 |
const CPolicyServer::TPolicyElement gServerPolicy10Elements[] =
|
|
458 |
{
|
|
459 |
{_INIT_SECURITY_POLICY_C1(ECapabilityNetworkControl),CPolicyServer::EFailClient},
|
|
460 |
{_INIT_SECURITY_POLICY_C1(ECapabilityNetworkControl),KQueryUser},
|
|
461 |
{_INIT_SECURITY_POLICY_C1(ECapabilityDiskAdmin),CPolicyServer::EFailClient},
|
|
462 |
{_INIT_SECURITY_POLICY_C1(ECapabilityDiskAdmin),KQueryUser},
|
|
463 |
};
|
|
464 |
|
|
465 |
const CPolicyServer::TPolicy gServerPolicy10 =
|
|
466 |
{
|
|
467 |
CPolicyServer::EAlwaysPass,gServerPolicy10RangeCount,
|
|
468 |
gServerPolicy10Ranges,
|
|
469 |
gServerPolicy10ElementsIndex,
|
|
470 |
gServerPolicy10Elements,
|
|
471 |
};
|
|
472 |
|
|
473 |
|
|
474 |
//A list of all the global policies
|
|
475 |
const CPolicyServer::TPolicy* gPolicyIndex[] = {
|
|
476 |
&gServerPolicy1,
|
|
477 |
&gServerPolicy2,
|
|
478 |
&gServerPolicy3,
|
|
479 |
&gServerPolicy4,
|
|
480 |
&gServerPolicy5,
|
|
481 |
&gServerPolicy6,
|
|
482 |
&gServerPolicy7,
|
|
483 |
&gServerPolicy8,
|
|
484 |
&gServerPolicy9,
|
|
485 |
&gServerPolicy10,
|
|
486 |
};
|
|
487 |
|
|
488 |
|
|
489 |
#include "testprocess.h"
|
|
490 |
|
|
491 |
TInt StartServer(const CPolicyServer::TPolicy& aPolicy, TUint aServerIndex);
|
|
492 |
|
|
493 |
TInt DoTestProcess(TInt aTestNum,TInt aArg1,TInt aArg2)
|
|
494 |
{
|
|
495 |
switch(aTestNum)
|
|
496 |
{
|
|
497 |
|
|
498 |
case ETestProcessPolicyServer:
|
|
499 |
{
|
|
500 |
__ASSERT_ALWAYS(aArg1 >= 0 && aArg1 < (TInt)sizeof(gPolicyIndex)>>2, User::Panic(KPolSvr, KErrArgument));
|
|
501 |
const CPolicyServer::TPolicy& policy = *(gPolicyIndex[aArg1]);
|
|
502 |
__ASSERT_ALWAYS(aArg2 >= 0, User::Panic(KPolSvr, KErrArgument));
|
|
503 |
TInt r;
|
|
504 |
r=StartServer(policy, TUint(aArg2));
|
|
505 |
if(r==KErrAlreadyExists)
|
|
506 |
{
|
|
507 |
User::After(2*1000*1000);
|
|
508 |
r=StartServer(policy, TUint(aArg2));
|
|
509 |
}
|
|
510 |
return r;
|
|
511 |
}
|
|
512 |
|
|
513 |
default:
|
|
514 |
User::Panic(_L("T_POLSVR"),1);
|
|
515 |
}
|
|
516 |
|
|
517 |
return KErrNone;
|
|
518 |
}
|
|
519 |
|
|
520 |
|
|
521 |
//
|
|
522 |
// RTestThread
|
|
523 |
//
|
|
524 |
|
|
525 |
class RTestThread : public RThread
|
|
526 |
{
|
|
527 |
public:
|
|
528 |
void Create(TThreadFunction aFunction,TAny* aArg=0);
|
|
529 |
};
|
|
530 |
|
|
531 |
void RTestThread::Create(TThreadFunction aFunction,TAny* aArg)
|
|
532 |
{
|
|
533 |
TInt r=RThread::Create(_L(""),aFunction,KDefaultStackSize,KDefaultStackSize,KDefaultStackSize,aArg);
|
|
534 |
test(r==KErrNone);
|
|
535 |
}
|
|
536 |
|
|
537 |
//
|
|
538 |
// CTestSession1
|
|
539 |
//
|
|
540 |
|
|
541 |
class CTestSession1 : public CSession2
|
|
542 |
{
|
|
543 |
public:
|
|
544 |
enum {EShutdown=100};
|
|
545 |
public:
|
|
546 |
CTestSession1();
|
|
547 |
virtual void ServiceL(const RMessage2& aMsg);
|
|
548 |
public:
|
|
549 |
};
|
|
550 |
|
|
551 |
CTestSession1::CTestSession1()
|
|
552 |
: CSession2()
|
|
553 |
{}
|
|
554 |
|
|
555 |
|
|
556 |
void CTestSession1::ServiceL(const RMessage2& aMsg)
|
|
557 |
{
|
|
558 |
OrInFlags(aMsg, KServiceLMask);
|
|
559 |
TInt fn = aMsg.Function();
|
|
560 |
switch(fn)
|
|
561 |
{
|
|
562 |
case 2:
|
|
563 |
case 4:
|
|
564 |
case 5:
|
|
565 |
case 6:
|
|
566 |
case 8:
|
|
567 |
case 9:
|
|
568 |
case 12:
|
|
569 |
case KMaxTInt:
|
|
570 |
aMsg.Complete(KErrNone);
|
|
571 |
break;
|
|
572 |
|
|
573 |
case CTestSession1::EShutdown:
|
|
574 |
CActiveScheduler::Stop();
|
|
575 |
aMsg.Complete(KErrNone);
|
|
576 |
break;
|
|
577 |
default:
|
|
578 |
//If we get here we have an unhandled condition in the test code.
|
|
579 |
//The test code is specifically setup to try and catch all branches
|
|
580 |
//through the policy server. If you get, there is some problem in
|
|
581 |
//the setup.
|
|
582 |
test(0);
|
|
583 |
break;
|
|
584 |
}
|
|
585 |
}
|
|
586 |
|
|
587 |
//
|
|
588 |
// CTestPolicyServer1
|
|
589 |
//
|
|
590 |
|
|
591 |
class CTestPolicyServer1 : public CPolicyServer
|
|
592 |
{
|
|
593 |
public:
|
|
594 |
CTestPolicyServer1(TInt aPriority, const TPolicy& aPolicy);
|
|
595 |
virtual CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMsg) const;
|
|
596 |
virtual TCustomResult CustomSecurityCheckL(const RMessage2& aMsg, TInt& aAction, TSecurityInfo& aMissing);
|
|
597 |
virtual TCustomResult CustomFailureActionL(const RMessage2& aMsg, TInt aAction, const TSecurityInfo& aMissing);
|
|
598 |
};
|
|
599 |
|
|
600 |
CTestPolicyServer1::CTestPolicyServer1(TInt aPriority, const TPolicy& aPolicy)
|
|
601 |
: CPolicyServer(aPriority, aPolicy)
|
|
602 |
{
|
|
603 |
}
|
|
604 |
|
|
605 |
CSession2* CTestPolicyServer1::NewSessionL(const TVersion& /*aVersion*/,const RMessage2& /*aMsg*/) const
|
|
606 |
{
|
|
607 |
return new (ELeave) CTestSession1();
|
|
608 |
}
|
|
609 |
|
|
610 |
CPolicyServer::TCustomResult CTestPolicyServer1::CustomSecurityCheckL(const RMessage2& aMsg, TInt& aAction, TSecurityInfo& aMissing)
|
|
611 |
{
|
|
612 |
TInt fn = aMsg.Function();
|
|
613 |
if(fn >= 0)
|
|
614 |
{
|
|
615 |
//Connect messages don't use this debugging system
|
|
616 |
OrInFlags(aMsg, KCustomCheckMask);
|
|
617 |
}
|
|
618 |
if(fn == -1) //Connect
|
|
619 |
{
|
|
620 |
return EPass;
|
|
621 |
}
|
|
622 |
else if(fn == 1)
|
|
623 |
{
|
|
624 |
aMissing.iCaps.AddCapability(ECapabilityCommDD);
|
|
625 |
return EFail;
|
|
626 |
}
|
|
627 |
else if(fn == 2)
|
|
628 |
{
|
|
629 |
return EPass;
|
|
630 |
}
|
|
631 |
else if(fn == 3)
|
|
632 |
{
|
|
633 |
aMissing.iCaps.AddCapability(ECapabilityCommDD);
|
|
634 |
aAction = KQueryUser;
|
|
635 |
return EFail;
|
|
636 |
}
|
|
637 |
else if(fn == 4)
|
|
638 |
{
|
|
639 |
aMissing.iCaps.AddCapability(ECapabilityCommDD);
|
|
640 |
aAction = KQueryUser;
|
|
641 |
return EFail;
|
|
642 |
}
|
|
643 |
else if(fn == 5)
|
|
644 |
{
|
|
645 |
//Since we are returning ETrue here, setting the action shouldn't affect
|
|
646 |
//anything. This should result in the same as 2.
|
|
647 |
aAction = KQueryUser;
|
|
648 |
return EPass;
|
|
649 |
}
|
|
650 |
//If we get here we have an unhandled condition in the test code. The test
|
|
651 |
//code is specifically setup to try and catch all branches through the
|
|
652 |
//policy server. If you get, there is some problem in the setup.
|
|
653 |
test(0);
|
|
654 |
return EFail;
|
|
655 |
}
|
|
656 |
|
|
657 |
CPolicyServer::TCustomResult CTestPolicyServer1::CustomFailureActionL(const RMessage2& aMsg, TInt aAction, const TSecurityInfo& aMissing)
|
|
658 |
{
|
|
659 |
(void)aMissing;
|
|
660 |
(void)aMsg;
|
|
661 |
(void)aAction;
|
|
662 |
TInt fn = aMsg.Function();
|
|
663 |
if(fn >= 0)
|
|
664 |
{
|
|
665 |
//Connect messages don't use this debugging system
|
|
666 |
OrInFlags(aMsg, KCustomActionMask);
|
|
667 |
}
|
|
668 |
switch(fn)
|
|
669 |
{
|
|
670 |
case 3:
|
|
671 |
return EFail;
|
|
672 |
case 4:
|
|
673 |
return EPass;
|
|
674 |
case 11:
|
|
675 |
return EFail;
|
|
676 |
case 12:
|
|
677 |
return EPass;
|
|
678 |
default:
|
|
679 |
break;
|
|
680 |
}
|
|
681 |
|
|
682 |
//If we get here we have an unhandled condition in the test code. The test
|
|
683 |
//code is specifically setup to try and catch all branches through the
|
|
684 |
//policy server. If you get, there is some problem in the setup.
|
|
685 |
test(0);
|
|
686 |
return EFail;
|
|
687 |
}
|
|
688 |
|
|
689 |
//
|
|
690 |
// CTestPolicyServer2
|
|
691 |
//
|
|
692 |
|
|
693 |
class CTestPolicyServer2 : public CPolicyServer
|
|
694 |
{
|
|
695 |
public:
|
|
696 |
CTestPolicyServer2(TInt aPriority, const TPolicy& aPolicy);
|
|
697 |
virtual CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMsg) const;
|
|
698 |
//virtual TBool CustomSecurityCheckL(const RMessage2& aMsg, TInt& aAction);
|
|
699 |
//virtual TBool CustomFailureActionL(const TSecurityPolicy* aPolicy, const RMessage2& aMsg, TInt aAction);
|
|
700 |
};
|
|
701 |
|
|
702 |
//
|
|
703 |
// CTestSession2
|
|
704 |
//
|
|
705 |
|
|
706 |
class CTestSession2 : public CSession2
|
|
707 |
{
|
|
708 |
public:
|
|
709 |
enum {EShutdown=100};
|
|
710 |
public:
|
|
711 |
CTestSession2();
|
|
712 |
virtual void ServiceL(const RMessage2& aMsg);
|
|
713 |
public:
|
|
714 |
};
|
|
715 |
|
|
716 |
CTestSession2::CTestSession2()
|
|
717 |
: CSession2()
|
|
718 |
{
|
|
719 |
}
|
|
720 |
|
|
721 |
void CTestSession2::ServiceL(const RMessage2& aMsg)
|
|
722 |
{
|
|
723 |
TInt fn = aMsg.Function();
|
|
724 |
switch(fn)
|
|
725 |
{
|
|
726 |
case CTestSession2::EShutdown:
|
|
727 |
CActiveScheduler::Stop();
|
|
728 |
aMsg.Complete(KErrNone);
|
|
729 |
break;
|
|
730 |
default:
|
|
731 |
//If we get here we have an unhandled condition in the test code.
|
|
732 |
//The test code is specifically setup to try and catch all branches
|
|
733 |
//through the policy server. If you get, there is some problem in
|
|
734 |
//the setup.
|
|
735 |
test(0);
|
|
736 |
break;
|
|
737 |
}
|
|
738 |
}
|
|
739 |
|
|
740 |
CTestPolicyServer2::CTestPolicyServer2(TInt aPriority, const TPolicy& aPolicy)
|
|
741 |
: CPolicyServer(aPriority, aPolicy)
|
|
742 |
{
|
|
743 |
}
|
|
744 |
|
|
745 |
CSession2* CTestPolicyServer2::NewSessionL(const TVersion& /*aVersion*/,const RMessage2& /*aMsg*/) const
|
|
746 |
{
|
|
747 |
return new (ELeave) CTestSession2();
|
|
748 |
}
|
|
749 |
|
|
750 |
//
|
|
751 |
// CTestPolicyServer3
|
|
752 |
//
|
|
753 |
|
|
754 |
class CTestPolicyServer3 : public CPolicyServer
|
|
755 |
{
|
|
756 |
public:
|
|
757 |
CTestPolicyServer3(TInt aPriority, const TPolicy& aPolicy);
|
|
758 |
virtual CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMsg) const;
|
|
759 |
virtual TCustomResult CustomSecurityCheckL(const RMessage2& aMsg, TInt& aAction, TSecurityInfo&);
|
|
760 |
virtual TCustomResult CustomFailureActionL(const RMessage2& aMsg, TInt aAction, const TSecurityInfo& aMissing);
|
|
761 |
};
|
|
762 |
|
|
763 |
CPolicyServer::TCustomResult CTestPolicyServer3::CustomSecurityCheckL(const RMessage2& aMsg, TInt& aAction, TSecurityInfo& aMissing)
|
|
764 |
{
|
|
765 |
(void)aAction;
|
|
766 |
(void)aMsg;
|
|
767 |
(void)aMissing;
|
|
768 |
//If we get here we have an unhandled condition in the test code. The test
|
|
769 |
//code is specifically setup to try and catch all branches through the
|
|
770 |
//policy server. If you get, there is some problem in the setup.
|
|
771 |
test(0);
|
|
772 |
return EFail;
|
|
773 |
}
|
|
774 |
|
|
775 |
CPolicyServer::TCustomResult CTestPolicyServer3::CustomFailureActionL(const RMessage2& aMsg, TInt aAction, const TSecurityInfo& aMissing)
|
|
776 |
{
|
|
777 |
(void)aMissing;
|
|
778 |
(void)aMsg;
|
|
779 |
(void)aAction;
|
|
780 |
TInt fn = aMsg.Function();
|
|
781 |
switch(fn)
|
|
782 |
{
|
|
783 |
case -1:
|
|
784 |
return EPass;
|
|
785 |
default:
|
|
786 |
break;
|
|
787 |
}
|
|
788 |
|
|
789 |
//If we get here we have an unhandled condition in the test code. The test
|
|
790 |
//code is specifically setup to try and catch all branches through the
|
|
791 |
//policy server. If you get, there is some problem in the setup.
|
|
792 |
test(0);
|
|
793 |
return EFail;
|
|
794 |
}
|
|
795 |
|
|
796 |
//
|
|
797 |
// CTestSession3
|
|
798 |
//
|
|
799 |
|
|
800 |
class CTestSession3 : public CSession2
|
|
801 |
{
|
|
802 |
public:
|
|
803 |
enum {EShutdown=100};
|
|
804 |
public:
|
|
805 |
CTestSession3();
|
|
806 |
virtual void ServiceL(const RMessage2& aMsg);
|
|
807 |
public:
|
|
808 |
};
|
|
809 |
|
|
810 |
CTestSession3::CTestSession3()
|
|
811 |
: CSession2()
|
|
812 |
{
|
|
813 |
}
|
|
814 |
|
|
815 |
void CTestSession3::ServiceL(const RMessage2& aMsg)
|
|
816 |
{
|
|
817 |
TInt fn = aMsg.Function();
|
|
818 |
switch(fn)
|
|
819 |
{
|
|
820 |
case CTestSession3::EShutdown:
|
|
821 |
CActiveScheduler::Stop();
|
|
822 |
aMsg.Complete(KErrNone);
|
|
823 |
break;
|
|
824 |
default:
|
|
825 |
//If we get here we have an unhandled condition in the test code.
|
|
826 |
//The test code is specifically setup to try and catch all branches
|
|
827 |
//through the policy server. If you get, there is some problem in
|
|
828 |
//the setup.
|
|
829 |
test(0);
|
|
830 |
break;
|
|
831 |
}
|
|
832 |
}
|
|
833 |
|
|
834 |
CTestPolicyServer3::CTestPolicyServer3(TInt aPriority, const TPolicy& aPolicy)
|
|
835 |
: CPolicyServer(aPriority, aPolicy)
|
|
836 |
{
|
|
837 |
}
|
|
838 |
|
|
839 |
CSession2* CTestPolicyServer3::NewSessionL(const TVersion& /*aVersion*/,const RMessage2& /*aMsg*/) const
|
|
840 |
{
|
|
841 |
return new (ELeave) CTestSession3();
|
|
842 |
}
|
|
843 |
|
|
844 |
_LIT(KCustomActive, "CCustomActive");
|
|
845 |
//
|
|
846 |
// CCustomActive
|
|
847 |
//
|
|
848 |
|
|
849 |
class CCustomActive : public CActive
|
|
850 |
{
|
|
851 |
public:
|
|
852 |
static CCustomActive* NewL(CPolicyServer& aServer);
|
|
853 |
void RunL();
|
|
854 |
TInt RunError(TInt aError);
|
|
855 |
void DoCancel();
|
|
856 |
void CustomSecurityCheckL(const RMessage2& aMsg, TInt aAction);
|
|
857 |
void CustomFailureActionL(const RMessage2& aMsg, TInt aAction);
|
|
858 |
protected:
|
|
859 |
void HandleSecurityCheckResultL();
|
|
860 |
void HandleFailureActionResultL();
|
|
861 |
void ConstructL();
|
|
862 |
private:
|
|
863 |
CCustomActive(CPolicyServer& aServer);
|
|
864 |
RTimer iTimer;
|
|
865 |
CPolicyServer& iServer;
|
|
866 |
const RMessage2* iMsg;
|
|
867 |
enum TState {
|
|
868 |
ECustomSecurityCheck,
|
|
869 |
EFailureAction,
|
|
870 |
};
|
|
871 |
TState iState;
|
|
872 |
TInt iAction;
|
|
873 |
TSecurityInfo iMissing;
|
|
874 |
};
|
|
875 |
|
|
876 |
CCustomActive::CCustomActive(CPolicyServer& aServer)
|
|
877 |
: CActive(0), iServer(aServer), iMsg(0), iState(ECustomSecurityCheck)
|
|
878 |
{
|
|
879 |
CActiveScheduler::Add(this);
|
|
880 |
}
|
|
881 |
|
|
882 |
CCustomActive* CCustomActive::NewL(CPolicyServer& aServer)
|
|
883 |
{
|
|
884 |
CCustomActive* self = new(ELeave)CCustomActive(aServer);
|
|
885 |
CleanupStack::PushL(self);
|
|
886 |
self->ConstructL();
|
|
887 |
CleanupStack::Pop(self);
|
|
888 |
return self;
|
|
889 |
}
|
|
890 |
|
|
891 |
void CCustomActive::ConstructL()
|
|
892 |
{
|
|
893 |
User::LeaveIfError(iTimer.CreateLocal());
|
|
894 |
memset(&iMissing, 0, sizeof(TSecurityInfo));
|
|
895 |
}
|
|
896 |
|
|
897 |
void CCustomActive::HandleSecurityCheckResultL()
|
|
898 |
{
|
|
899 |
TInt fn = iMsg->Function();
|
|
900 |
switch(fn)
|
|
901 |
{
|
|
902 |
case 0:
|
|
903 |
iStatus = KErrGeneral;
|
|
904 |
break;
|
|
905 |
case 1: //pass
|
|
906 |
case 4:
|
|
907 |
break;
|
|
908 |
case 2:
|
|
909 |
case 3:
|
|
910 |
iStatus = KErrGeneral;
|
|
911 |
iAction = KQueryUser;
|
|
912 |
break;
|
|
913 |
default:
|
|
914 |
test(0);
|
|
915 |
}
|
|
916 |
if(iStatus == KErrNone)
|
|
917 |
{
|
|
918 |
iServer.ProcessL(*iMsg);
|
|
919 |
iMsg=0;
|
|
920 |
}
|
|
921 |
else
|
|
922 |
{
|
|
923 |
const RMessage2* ptr = iMsg;
|
|
924 |
iMsg=0;
|
|
925 |
iServer.CheckFailedL(*ptr, iAction, iMissing);
|
|
926 |
}
|
|
927 |
}
|
|
928 |
|
|
929 |
void CCustomActive::HandleFailureActionResultL()
|
|
930 |
{
|
|
931 |
TInt fn = iMsg->Function();
|
|
932 |
switch(fn)
|
|
933 |
{
|
|
934 |
case 2:
|
|
935 |
iStatus = KErrGeneral;
|
|
936 |
break;
|
|
937 |
case 3: //pass
|
|
938 |
case 9:
|
|
939 |
case 57: //passes through so ServiceL can leave with NoMem
|
|
940 |
break;
|
|
941 |
case 56:
|
|
942 |
User::Leave(KErrNoMemory);
|
|
943 |
break;
|
|
944 |
|
|
945 |
default:
|
|
946 |
test(0);
|
|
947 |
}
|
|
948 |
if(iStatus == KErrNone)
|
|
949 |
iServer.ProcessL(*iMsg);
|
|
950 |
else
|
|
951 |
iMsg->Complete(KErrPermissionDenied);
|
|
952 |
iMsg=0;
|
|
953 |
}
|
|
954 |
|
|
955 |
void CCustomActive::RunL()
|
|
956 |
{
|
|
957 |
OrInFlags(*iMsg, KActiveRunLMask);
|
|
958 |
|
|
959 |
switch(iState)
|
|
960 |
{
|
|
961 |
case ECustomSecurityCheck:
|
|
962 |
HandleSecurityCheckResultL();
|
|
963 |
break;
|
|
964 |
case EFailureAction:
|
|
965 |
HandleFailureActionResultL();
|
|
966 |
break;
|
|
967 |
default:
|
|
968 |
//Invalid state
|
|
969 |
User::Panic(KCustomActive, 11);
|
|
970 |
break;
|
|
971 |
}
|
|
972 |
}
|
|
973 |
|
|
974 |
TInt CCustomActive::RunError(TInt aError)
|
|
975 |
{
|
|
976 |
OrInFlags(*iMsg, KActiveRunErrorMask);
|
|
977 |
if(iMsg)
|
|
978 |
{
|
|
979 |
iServer.ProcessError(*iMsg, aError);
|
|
980 |
iMsg = 0;
|
|
981 |
iAction = CPolicyServer::EFailClient;
|
|
982 |
return KErrNone;
|
|
983 |
}
|
|
984 |
else
|
|
985 |
return aError;
|
|
986 |
}
|
|
987 |
|
|
988 |
void CCustomActive::DoCancel()
|
|
989 |
{
|
|
990 |
OrInFlags(*iMsg, KActiveDoCancelMask);
|
|
991 |
iTimer.Cancel();
|
|
992 |
if(iMsg)
|
|
993 |
{
|
|
994 |
iMsg->Complete(KErrCancel);
|
|
995 |
}
|
|
996 |
iMsg = 0;
|
|
997 |
iAction = CPolicyServer::EFailClient;
|
|
998 |
}
|
|
999 |
|
|
1000 |
void CCustomActive::CustomSecurityCheckL(const RMessage2& aMsg, TInt aAction)
|
|
1001 |
{
|
|
1002 |
__ASSERT_ALWAYS(!IsActive(), User::Panic(KCustomActive, 1));
|
|
1003 |
__ASSERT_ALWAYS(iMsg == 0, User::Panic(KCustomActive, 2));
|
|
1004 |
|
|
1005 |
OrInFlags(aMsg, KActiveCheckMask);
|
|
1006 |
|
|
1007 |
iTimer.After(iStatus, 100000);
|
|
1008 |
SetActive();
|
|
1009 |
iMsg = &aMsg;
|
|
1010 |
iState = ECustomSecurityCheck;
|
|
1011 |
iAction = aAction;
|
|
1012 |
}
|
|
1013 |
|
|
1014 |
void CCustomActive::CustomFailureActionL(const RMessage2& aMsg, TInt aAction)
|
|
1015 |
{
|
|
1016 |
__ASSERT_ALWAYS(!IsActive(), User::Panic(KCustomActive, 3));
|
|
1017 |
__ASSERT_ALWAYS(iMsg == 0, User::Panic(KCustomActive, 4));
|
|
1018 |
|
|
1019 |
OrInFlags(aMsg, KActiveActionMask);
|
|
1020 |
|
|
1021 |
iTimer.After(iStatus, 50000);
|
|
1022 |
SetActive();
|
|
1023 |
iMsg = &aMsg;
|
|
1024 |
iState = EFailureAction;
|
|
1025 |
iAction = aAction;
|
|
1026 |
|
|
1027 |
if(aMsg.Function() == 55)
|
|
1028 |
{
|
|
1029 |
Cancel();
|
|
1030 |
}
|
|
1031 |
}
|
|
1032 |
|
|
1033 |
//
|
|
1034 |
// CTestPolicyServer4
|
|
1035 |
//
|
|
1036 |
|
|
1037 |
class CTestPolicyServer4 : public CPolicyServer
|
|
1038 |
{
|
|
1039 |
public:
|
|
1040 |
static CTestPolicyServer4* NewL(TInt aPriority, const TPolicy& aPolicy);
|
|
1041 |
CTestPolicyServer4(TInt aPriority, const TPolicy& aPolicy);
|
|
1042 |
virtual CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMsg) const;
|
|
1043 |
virtual TCustomResult CustomSecurityCheckL(const RMessage2& aMsg, TInt& aAction, TSecurityInfo& aMissing);
|
|
1044 |
virtual TCustomResult CustomFailureActionL(const RMessage2& aMsg, TInt aAction, const TSecurityInfo& aMissing);
|
|
1045 |
CCustomActive* iActiveCheck;
|
|
1046 |
protected:
|
|
1047 |
void ConstructL();
|
|
1048 |
};
|
|
1049 |
|
|
1050 |
CTestPolicyServer4* CTestPolicyServer4::NewL(TInt aPriority, const TPolicy& aPolicy)
|
|
1051 |
{
|
|
1052 |
CTestPolicyServer4* self = new(ELeave)CTestPolicyServer4(aPriority, aPolicy);
|
|
1053 |
CleanupStack::PushL(self);
|
|
1054 |
self->ConstructL();
|
|
1055 |
CleanupStack::Pop(self);
|
|
1056 |
return self;
|
|
1057 |
}
|
|
1058 |
|
|
1059 |
void CTestPolicyServer4::ConstructL()
|
|
1060 |
{
|
|
1061 |
iActiveCheck = CCustomActive::NewL(*this);
|
|
1062 |
}
|
|
1063 |
|
|
1064 |
CPolicyServer::TCustomResult CTestPolicyServer4::CustomSecurityCheckL(const RMessage2& aMsg, TInt& aAction, TSecurityInfo& aMissing)
|
|
1065 |
{
|
|
1066 |
(void)aMissing;
|
|
1067 |
OrInFlags(aMsg, KCustomCheckMask);
|
|
1068 |
iActiveCheck->CustomSecurityCheckL(aMsg, aAction);
|
|
1069 |
return EAsync;
|
|
1070 |
}
|
|
1071 |
|
|
1072 |
CPolicyServer::TCustomResult CTestPolicyServer4::CustomFailureActionL(const RMessage2& aMsg, TInt aAction, const TSecurityInfo& aMissing)
|
|
1073 |
{
|
|
1074 |
(void)aMissing;
|
|
1075 |
OrInFlags(aMsg, KCustomActionMask);
|
|
1076 |
iActiveCheck->CustomFailureActionL(aMsg, aAction);
|
|
1077 |
return EAsync;
|
|
1078 |
}
|
|
1079 |
|
|
1080 |
//
|
|
1081 |
// CTestSession4
|
|
1082 |
//
|
|
1083 |
|
|
1084 |
class CTestSession4 : public CSession2
|
|
1085 |
{
|
|
1086 |
public:
|
|
1087 |
enum {EShutdown=100};
|
|
1088 |
public:
|
|
1089 |
CTestSession4();
|
|
1090 |
virtual void ServiceL(const RMessage2& aMsg);
|
|
1091 |
virtual void ServiceError(const RMessage2& aMsg, TInt aError);
|
|
1092 |
public:
|
|
1093 |
};
|
|
1094 |
|
|
1095 |
CTestSession4::CTestSession4()
|
|
1096 |
: CSession2()
|
|
1097 |
{
|
|
1098 |
}
|
|
1099 |
|
|
1100 |
void CTestSession4::ServiceL(const RMessage2& aMsg)
|
|
1101 |
{
|
|
1102 |
TInt fn = aMsg.Function();
|
|
1103 |
OrInFlags(aMsg, KServiceLMask);
|
|
1104 |
switch(fn)
|
|
1105 |
{
|
|
1106 |
case 1:
|
|
1107 |
case 3:
|
|
1108 |
case 4:
|
|
1109 |
case 5:
|
|
1110 |
case 8:
|
|
1111 |
case 9:
|
|
1112 |
case 11:
|
|
1113 |
aMsg.Complete(KErrNone);
|
|
1114 |
break;
|
|
1115 |
case 57:
|
|
1116 |
User::Leave(KErrNoMemory);
|
|
1117 |
break;
|
|
1118 |
case CTestSession4::EShutdown:
|
|
1119 |
CActiveScheduler::Stop();
|
|
1120 |
aMsg.Complete(KErrNone);
|
|
1121 |
break;
|
|
1122 |
case KMaxTInt:
|
|
1123 |
//KMaxTInt would otherwise interfere with the OrInFlags value, so
|
|
1124 |
//we return our location this way instead.
|
|
1125 |
aMsg.Complete(KMaxTInt);
|
|
1126 |
break;
|
|
1127 |
default:
|
|
1128 |
//If we get here we have an unhandled condition in the test code.
|
|
1129 |
//The test code is specifically setup to try and catch all branches
|
|
1130 |
//through the policy server. If you get, there is some problem in
|
|
1131 |
//the setup.
|
|
1132 |
test(0);
|
|
1133 |
break;
|
|
1134 |
}
|
|
1135 |
}
|
|
1136 |
|
|
1137 |
void CTestSession4::ServiceError(const RMessage2& aMsg, TInt aError)
|
|
1138 |
{
|
|
1139 |
OrInFlags(aMsg, KServiceErrorMask);
|
|
1140 |
if(!aMsg.IsNull())
|
|
1141 |
aMsg.Complete(aError);
|
|
1142 |
}
|
|
1143 |
|
|
1144 |
CTestPolicyServer4::CTestPolicyServer4(TInt aPriority, const TPolicy& aPolicy)
|
|
1145 |
: CPolicyServer(aPriority, aPolicy)
|
|
1146 |
{
|
|
1147 |
}
|
|
1148 |
|
|
1149 |
CSession2* CTestPolicyServer4::NewSessionL(const TVersion& /*aVersion*/,const RMessage2& /*aMsg*/) const
|
|
1150 |
{
|
|
1151 |
return new (ELeave) CTestSession4();
|
|
1152 |
}
|
|
1153 |
|
|
1154 |
|
|
1155 |
//
|
|
1156 |
// CTestActiveScheduler
|
|
1157 |
//
|
|
1158 |
|
|
1159 |
class CTestActiveScheduler : public CActiveScheduler
|
|
1160 |
{
|
|
1161 |
public:
|
|
1162 |
virtual void Error(TInt anError) const;
|
|
1163 |
};
|
|
1164 |
|
|
1165 |
void CTestActiveScheduler::Error(TInt anError) const
|
|
1166 |
{
|
|
1167 |
User::Panic(_L("TestServer Error"),anError);
|
|
1168 |
}
|
|
1169 |
|
|
1170 |
|
|
1171 |
|
|
1172 |
//
|
|
1173 |
// Server thread
|
|
1174 |
//
|
|
1175 |
|
|
1176 |
_LIT(KServerName,"T_POLSVR-server");
|
|
1177 |
const TInt KServerRendezvous = KRequestPending+1;
|
|
1178 |
|
|
1179 |
void DoStartServer(const CPolicyServer::TPolicy& aPolicy, TUint aServerIndex)
|
|
1180 |
{
|
|
1181 |
CTestActiveScheduler* activeScheduler = new (ELeave) CTestActiveScheduler;
|
|
1182 |
CActiveScheduler::Install(activeScheduler);
|
|
1183 |
CleanupStack::PushL(activeScheduler);
|
|
1184 |
|
|
1185 |
CPolicyServer* server = 0;
|
|
1186 |
switch(aServerIndex)
|
|
1187 |
{
|
|
1188 |
case 0:
|
|
1189 |
server = new (ELeave) CTestPolicyServer1(0,aPolicy);
|
|
1190 |
break;
|
|
1191 |
case 1:
|
|
1192 |
server = new (ELeave) CTestPolicyServer2(0,aPolicy);
|
|
1193 |
break;
|
|
1194 |
case 2:
|
|
1195 |
server = new (ELeave) CTestPolicyServer3(0,aPolicy);
|
|
1196 |
break;
|
|
1197 |
case 3:
|
|
1198 |
server = CTestPolicyServer4::NewL(0,aPolicy);
|
|
1199 |
break;
|
|
1200 |
default:
|
|
1201 |
User::Panic(KPolSvr, KErrArgument);
|
|
1202 |
}
|
|
1203 |
CleanupStack::PushL(server);
|
|
1204 |
|
|
1205 |
User::LeaveIfError(server->Start(KServerName));
|
|
1206 |
|
|
1207 |
RProcess::Rendezvous(KServerRendezvous);
|
|
1208 |
|
|
1209 |
CActiveScheduler::Start();
|
|
1210 |
|
|
1211 |
CleanupStack::PopAndDestroy(2);
|
|
1212 |
}
|
|
1213 |
|
|
1214 |
TInt StartServer(const CPolicyServer::TPolicy& aPolicy, TUint aServerIndex)
|
|
1215 |
{
|
|
1216 |
CTrapCleanup* cleanupStack = CTrapCleanup::New();
|
|
1217 |
if(!cleanupStack)
|
|
1218 |
return KErrNoMemory;
|
|
1219 |
TRAPD(leaveError,DoStartServer(aPolicy,aServerIndex))
|
|
1220 |
delete cleanupStack;
|
|
1221 |
return leaveError;
|
|
1222 |
}
|
|
1223 |
|
|
1224 |
|
|
1225 |
|
|
1226 |
//
|
|
1227 |
// RTestSession
|
|
1228 |
//
|
|
1229 |
|
|
1230 |
class RTestSession : public RSessionBase
|
|
1231 |
{
|
|
1232 |
public:
|
|
1233 |
inline TInt Connect()
|
|
1234 |
{ return CreateSession(KServerName,TVersion());}
|
|
1235 |
// inline TInt Send(TInt aFunction)
|
|
1236 |
// { return RSessionBase::SendReceive(aFunction); }
|
|
1237 |
inline TInt Send(TInt aFunction,const TIpcArgs& aArgs)
|
|
1238 |
{ return RSessionBase::SendReceive(aFunction,aArgs); }
|
|
1239 |
inline void Send(TInt aFunction,TRequestStatus& aStatus)
|
|
1240 |
{ RSessionBase::SendReceive(aFunction,aStatus); }
|
|
1241 |
inline void Send(TInt aFunction,const TIpcArgs& aArgs,TRequestStatus& aStatus)
|
|
1242 |
{ RSessionBase::SendReceive(aFunction,aArgs,aStatus); }
|
|
1243 |
};
|
|
1244 |
|
|
1245 |
|
|
1246 |
|
|
1247 |
RTestSession Session;
|
|
1248 |
|
|
1249 |
#include <e32svr.h>
|
|
1250 |
|
|
1251 |
void TestServer1WithPolicy1()
|
|
1252 |
{
|
|
1253 |
RTestProcess server;
|
|
1254 |
TRequestStatus rendezvous;
|
|
1255 |
server.Create(~KTestCapabilities,ETestProcessPolicyServer,EPolicy1,ETestServer1);
|
|
1256 |
server.Rendezvous(rendezvous);
|
|
1257 |
server.Resume();
|
|
1258 |
User::WaitForRequest(rendezvous);
|
|
1259 |
test(rendezvous==KServerRendezvous);
|
|
1260 |
|
|
1261 |
test.Next(_L("Server 1, Policy 1"));
|
|
1262 |
TInt r = Session.Connect();
|
|
1263 |
test(r==KErrNone);
|
|
1264 |
|
|
1265 |
TBuf8<4> flags(4);
|
|
1266 |
|
|
1267 |
//case 0: Not Supported, returned from policy server level.
|
|
1268 |
SetFlags(flags, 0);
|
|
1269 |
r = Session.Send(0, TIpcArgs(&flags));
|
|
1270 |
test(r==KErrNotSupported);
|
|
1271 |
test(FlagsValue(flags) == (0));
|
|
1272 |
|
|
1273 |
//case 1: Custom Check, fails with KErrPermissionDenied
|
|
1274 |
SetFlags(flags, 1);
|
|
1275 |
r = Session.Send(1, TIpcArgs(&flags));
|
|
1276 |
test(r==KErrPermissionDenied);
|
|
1277 |
test(FlagsValue(flags) == (1 | KCustomCheckMask) );
|
|
1278 |
|
|
1279 |
//case 2: Custom Check passes.
|
|
1280 |
SetFlags(flags, 2);
|
|
1281 |
r = Session.Send(2, TIpcArgs(&flags));
|
|
1282 |
test(r==KErrNone);
|
|
1283 |
test(FlagsValue(flags) == (2 | KCustomCheckMask | KServiceLMask) );
|
|
1284 |
|
|
1285 |
//case 3: Custom Check fails but action set to EQueryUser, query
|
|
1286 |
//subsequently fails
|
|
1287 |
SetFlags(flags, 3);
|
|
1288 |
r = Session.Send(3, TIpcArgs(&flags));
|
|
1289 |
test(r==KErrPermissionDenied);
|
|
1290 |
test(FlagsValue(flags) == (3 | KCustomCheckMask | KCustomActionMask ));
|
|
1291 |
|
|
1292 |
//case 4: Custom Check fails but action set to EQueryUser, query
|
|
1293 |
//subsequently passes
|
|
1294 |
SetFlags(flags, 4);
|
|
1295 |
r = Session.Send(4, TIpcArgs(&flags));
|
|
1296 |
test(r==KErrNone);
|
|
1297 |
test(FlagsValue(flags) == (4 | KCustomCheckMask | KCustomActionMask | KServiceLMask ));
|
|
1298 |
|
|
1299 |
//case 5: Custom Check passes and action is set. Action set shouldn't make
|
|
1300 |
//a difference. Should be same result as case 2.
|
|
1301 |
SetFlags(flags, 5);
|
|
1302 |
r = Session.Send(5, TIpcArgs(&flags));
|
|
1303 |
test(r==KErrNone);
|
|
1304 |
test(FlagsValue(flags) == (5 | KCustomCheckMask | KServiceLMask ));
|
|
1305 |
|
|
1306 |
//case 6: Always passes at the policy server level.
|
|
1307 |
SetFlags(flags, 6);
|
|
1308 |
r = Session.Send(6, TIpcArgs(&flags));
|
|
1309 |
test(r==KErrNone);
|
|
1310 |
test(FlagsValue(flags) == (6 | KServiceLMask) );
|
|
1311 |
|
|
1312 |
//case 7: Not Supported, returned from policy server level.
|
|
1313 |
SetFlags(flags, 7);
|
|
1314 |
r = Session.Send(7, TIpcArgs(&flags));
|
|
1315 |
test(r==KErrNotSupported);
|
|
1316 |
test(FlagsValue(flags) == (7));
|
|
1317 |
|
|
1318 |
//case 8: Requires NetworkControl, which we have, so it passes.
|
|
1319 |
SetFlags(flags, 8);
|
|
1320 |
r = Session.Send(8, TIpcArgs(&flags));
|
|
1321 |
test(r==KErrNone);
|
|
1322 |
test(FlagsValue(flags) == (8 | KServiceLMask));
|
|
1323 |
|
|
1324 |
//case 9: Requires NetworkControl -> pass. Thrown in a EQueryUser to see
|
|
1325 |
//if it causes any problems -> it shouldn't. Should be same as case 8.
|
|
1326 |
SetFlags(flags, 9);
|
|
1327 |
r = Session.Send(9, TIpcArgs(&flags));
|
|
1328 |
test(r==KErrNone);
|
|
1329 |
test(FlagsValue(flags) == (9 | KServiceLMask));
|
|
1330 |
|
|
1331 |
//case 10: Requires DiskAdmin which we don't have.
|
|
1332 |
SetFlags(flags, 10);
|
|
1333 |
r = Session.Send(10, TIpcArgs(&flags));
|
|
1334 |
test(r==KErrPermissionDenied);
|
|
1335 |
test(FlagsValue(flags) == (10));
|
|
1336 |
|
|
1337 |
//case 11: Requires DiskAdmin, which we don't have. EQueryUser is set, and
|
|
1338 |
//it fails.
|
|
1339 |
SetFlags(flags, 11);
|
|
1340 |
r = Session.Send(11, TIpcArgs(&flags));
|
|
1341 |
test(r==KErrPermissionDenied);
|
|
1342 |
test(FlagsValue(flags) == (11 | KCustomActionMask));
|
|
1343 |
|
|
1344 |
//case 12: Requires DiskAdmin, which we don't have. EQueryUser is set, and
|
|
1345 |
//it passes.
|
|
1346 |
SetFlags(flags, 12);
|
|
1347 |
r = Session.Send(12, TIpcArgs(&flags));
|
|
1348 |
test(r==KErrNone);
|
|
1349 |
test(FlagsValue(flags) == (12 | KCustomActionMask | KServiceLMask));
|
|
1350 |
|
|
1351 |
//case 13: Not Supported, returned from policy server level.
|
|
1352 |
SetFlags(flags, 13);
|
|
1353 |
r = Session.Send(13, TIpcArgs(&flags));
|
|
1354 |
test(r==KErrNotSupported);
|
|
1355 |
test(FlagsValue(flags) == (13));
|
|
1356 |
|
|
1357 |
//case 14: Not Supported, returned from policy server level.
|
|
1358 |
SetFlags(flags, 14);
|
|
1359 |
r = Session.Send(14, TIpcArgs(&flags));
|
|
1360 |
test(r==KErrNotSupported);
|
|
1361 |
test(FlagsValue(flags) == (14));
|
|
1362 |
|
|
1363 |
//case 55: Not Supported, returned from policy server level.
|
|
1364 |
SetFlags(flags, 55);
|
|
1365 |
r = Session.Send(55, TIpcArgs(&flags));
|
|
1366 |
test(r==KErrNotSupported);
|
|
1367 |
test(FlagsValue(flags) == (55));
|
|
1368 |
|
|
1369 |
//case 86: Not Supported, returned from policy server level.
|
|
1370 |
SetFlags(flags, 86);
|
|
1371 |
r = Session.Send(86, TIpcArgs(&flags));
|
|
1372 |
test(r==KErrNotSupported);
|
|
1373 |
test(FlagsValue(flags) == (86));
|
|
1374 |
|
|
1375 |
//case 99: Not Supported, returned from policy server level.
|
|
1376 |
SetFlags(flags, 99);
|
|
1377 |
r = Session.Send(99, TIpcArgs(&flags));
|
|
1378 |
test(r==KErrNotSupported);
|
|
1379 |
test(FlagsValue(flags) == (99));
|
|
1380 |
|
|
1381 |
//case 101: Not Supported, returned from policy server level.
|
|
1382 |
SetFlags(flags, 101);
|
|
1383 |
r = Session.Send(101, TIpcArgs(&flags));
|
|
1384 |
test(r==KErrNotSupported);
|
|
1385 |
test(FlagsValue(flags) == (101));
|
|
1386 |
|
|
1387 |
//case 1000191: Not Supported, returned from policy server level.
|
|
1388 |
SetFlags(flags, 1000191);
|
|
1389 |
r = Session.Send(1000191, TIpcArgs(&flags));
|
|
1390 |
test(r==KErrNotSupported);
|
|
1391 |
test(FlagsValue(flags) == (1000191));
|
|
1392 |
|
|
1393 |
//case 1000848: Not Supported, returned from policy server level.
|
|
1394 |
SetFlags(flags, 1000848);
|
|
1395 |
r = Session.Send(1000848, TIpcArgs(&flags));
|
|
1396 |
test(r==KErrNotSupported);
|
|
1397 |
test(FlagsValue(flags) == (1000848));
|
|
1398 |
|
|
1399 |
//case KMaxTInt-1: Not Supported, returned from policy server level.
|
|
1400 |
SetFlags(flags, KMaxTInt-1);
|
|
1401 |
r = Session.Send(KMaxTInt-1, TIpcArgs(&flags));
|
|
1402 |
test(r==KErrNotSupported);
|
|
1403 |
test(FlagsValue(flags) == (KMaxTInt-1));
|
|
1404 |
|
|
1405 |
//case KMaxTInt: Not Supported, returned from policy server level.
|
|
1406 |
SetFlags(flags, KMaxTInt);
|
|
1407 |
r = Session.Send(KMaxTInt, TIpcArgs(&flags));
|
|
1408 |
test(r==KErrNotSupported);
|
|
1409 |
test(FlagsValue(flags) == (TUint)(KMaxTInt));
|
|
1410 |
|
|
1411 |
r = Session.Send(CTestSession1::EShutdown, TIpcArgs(&flags));
|
|
1412 |
test.Printf(_L("r = %d\n"),r);
|
|
1413 |
test(r==KErrNone);
|
|
1414 |
|
|
1415 |
Session.Close();
|
|
1416 |
CLOSE_AND_WAIT(server);
|
|
1417 |
}
|
|
1418 |
|
|
1419 |
#include <e32panic.h>
|
|
1420 |
|
|
1421 |
void TestServer1WithPolicy2()
|
|
1422 |
{
|
|
1423 |
test.Next(_L("Server 1, Policy 2"));
|
|
1424 |
RTestProcess server;
|
|
1425 |
TRequestStatus rendezvous;
|
|
1426 |
server.Create(~KTestCapabilities,ETestProcessPolicyServer,EPolicy2,ETestServer1);
|
|
1427 |
server.Rendezvous(rendezvous);
|
|
1428 |
server.Resume();
|
|
1429 |
User::WaitForRequest(rendezvous);
|
|
1430 |
#ifdef _DEBUG
|
|
1431 |
//Debug mode does a policy integrity check
|
|
1432 |
test(rendezvous==EPolSvr1stRangeNotZero);
|
|
1433 |
#else
|
|
1434 |
test(rendezvous==KServerRendezvous);
|
|
1435 |
server.Terminate(0);
|
|
1436 |
#endif
|
|
1437 |
CLOSE_AND_WAIT(server);
|
|
1438 |
}
|
|
1439 |
|
|
1440 |
void TestServer1WithPolicy3()
|
|
1441 |
{
|
|
1442 |
test.Next(_L("Server 1, Policy 3"));
|
|
1443 |
RTestProcess server;
|
|
1444 |
TRequestStatus rendezvous;
|
|
1445 |
server.Create(~KTestCapabilities,ETestProcessPolicyServer,EPolicy3,ETestServer1);
|
|
1446 |
server.Rendezvous(rendezvous);
|
|
1447 |
server.Resume();
|
|
1448 |
User::WaitForRequest(rendezvous);
|
|
1449 |
#ifdef _DEBUG
|
|
1450 |
//Debug mode does a policy integrity check
|
|
1451 |
test(rendezvous==EPolSvrRangesNotIncreasing);
|
|
1452 |
#else
|
|
1453 |
test(rendezvous==KServerRendezvous);
|
|
1454 |
server.Terminate(0);
|
|
1455 |
#endif
|
|
1456 |
CLOSE_AND_WAIT(server);
|
|
1457 |
}
|
|
1458 |
|
|
1459 |
void TestServer1WithPolicy4()
|
|
1460 |
{
|
|
1461 |
test.Next(_L("Server 1, Policy 4"));
|
|
1462 |
RTestProcess server;
|
|
1463 |
TRequestStatus rendezvous;
|
|
1464 |
server.Create(~KTestCapabilities,ETestProcessPolicyServer,EPolicy4,ETestServer1);
|
|
1465 |
server.Rendezvous(rendezvous);
|
|
1466 |
server.Resume();
|
|
1467 |
User::WaitForRequest(rendezvous);
|
|
1468 |
#ifdef _DEBUG
|
|
1469 |
//Debug mode does a policy integrity check
|
|
1470 |
test(rendezvous==EPolSvrElementsIndexValueInvalid);
|
|
1471 |
#else
|
|
1472 |
test(rendezvous==KServerRendezvous);
|
|
1473 |
server.Terminate(0);
|
|
1474 |
#endif
|
|
1475 |
CLOSE_AND_WAIT(server);
|
|
1476 |
}
|
|
1477 |
|
|
1478 |
void TestServer1WithPolicy5()
|
|
1479 |
{
|
|
1480 |
test.Next(_L("Server 1, Policy 5"));
|
|
1481 |
RTestProcess server;
|
|
1482 |
TRequestStatus rendezvous;
|
|
1483 |
server.Create(~KTestCapabilities,ETestProcessPolicyServer,EPolicy5,ETestServer1);
|
|
1484 |
server.Rendezvous(rendezvous);
|
|
1485 |
server.Resume();
|
|
1486 |
User::WaitForRequest(rendezvous);
|
|
1487 |
#ifdef _DEBUG
|
|
1488 |
//Debug mode does a policy integrity check
|
|
1489 |
test(rendezvous==EPolSvrElementsIndexValueInvalid);
|
|
1490 |
#else
|
|
1491 |
test(rendezvous==KServerRendezvous);
|
|
1492 |
server.Terminate(0);
|
|
1493 |
#endif
|
|
1494 |
CLOSE_AND_WAIT(server);
|
|
1495 |
}
|
|
1496 |
|
|
1497 |
void TestServer1WithPolicy6()
|
|
1498 |
{
|
|
1499 |
test.Next(_L("Server 1, Policy 6"));
|
|
1500 |
RTestProcess server;
|
|
1501 |
TRequestStatus rendezvous;
|
|
1502 |
server.Create(~KTestCapabilities,ETestProcessPolicyServer,EPolicy6,ETestServer1);
|
|
1503 |
server.Rendezvous(rendezvous);
|
|
1504 |
server.Resume();
|
|
1505 |
User::WaitForRequest(rendezvous);
|
|
1506 |
#ifdef _DEBUG
|
|
1507 |
//Debug mode does a policy integrity check
|
|
1508 |
test(rendezvous==EPolSvrIOnConnectValueInvalid);
|
|
1509 |
#else
|
|
1510 |
test(rendezvous==KServerRendezvous);
|
|
1511 |
server.Terminate(0);
|
|
1512 |
#endif
|
|
1513 |
CLOSE_AND_WAIT(server);
|
|
1514 |
}
|
|
1515 |
|
|
1516 |
void TestServer1WithPolicy7()
|
|
1517 |
{
|
|
1518 |
test.Next(_L("Server 1, Policy 7"));
|
|
1519 |
RTestProcess server;
|
|
1520 |
TRequestStatus rendezvous;
|
|
1521 |
server.Create(~KTestCapabilities,ETestProcessPolicyServer,EPolicy7,ETestServer1);
|
|
1522 |
server.Rendezvous(rendezvous);
|
|
1523 |
server.Resume();
|
|
1524 |
User::WaitForRequest(rendezvous);
|
|
1525 |
test(rendezvous==KServerRendezvous);
|
|
1526 |
|
|
1527 |
TInt r = Session.Connect();
|
|
1528 |
test(r==KErrNotSupported);
|
|
1529 |
|
|
1530 |
//We can do this because we have power management
|
|
1531 |
server.Terminate(KErrGeneral);
|
|
1532 |
CLOSE_AND_WAIT(server);
|
|
1533 |
}
|
|
1534 |
|
|
1535 |
void TestServer1WithPolicy8()
|
|
1536 |
{
|
|
1537 |
test.Next(_L("Server 1, Policy 8"));
|
|
1538 |
RTestProcess server;
|
|
1539 |
TRequestStatus rendezvous;
|
|
1540 |
server.Create(~KTestCapabilities,ETestProcessPolicyServer,EPolicy8,ETestServer1);
|
|
1541 |
server.Rendezvous(rendezvous);
|
|
1542 |
server.Resume();
|
|
1543 |
User::WaitForRequest(rendezvous);
|
|
1544 |
test(rendezvous==KServerRendezvous);
|
|
1545 |
|
|
1546 |
//This will be calling through CustomSecurityCheckL (server1 will return
|
|
1547 |
//pass), but there is no easy way to determine that it has followed the
|
|
1548 |
//correct path.
|
|
1549 |
TInt r = Session.Connect();
|
|
1550 |
test(r==KErrNone);
|
|
1551 |
|
|
1552 |
server.Terminate(KErrGeneral);
|
|
1553 |
Session.Close();
|
|
1554 |
CLOSE_AND_WAIT(server);
|
|
1555 |
}
|
|
1556 |
|
|
1557 |
void TestServer2WithPolicy8()
|
|
1558 |
{
|
|
1559 |
test.Next(_L("Server 2, Policy 8"));
|
|
1560 |
RTestProcess server;
|
|
1561 |
TRequestStatus rendezvous;
|
|
1562 |
TRequestStatus logon;
|
|
1563 |
server.Create(~KTestCapabilities,ETestProcessPolicyServer,EPolicy8,ETestServer2);
|
|
1564 |
server.Rendezvous(rendezvous);
|
|
1565 |
server.Logon(logon);
|
|
1566 |
server.Resume();
|
|
1567 |
User::WaitForRequest(rendezvous);
|
|
1568 |
test(rendezvous==KServerRendezvous);
|
|
1569 |
|
|
1570 |
TInt r = Session.Connect();
|
|
1571 |
test(r==KErrServerTerminated);
|
|
1572 |
|
|
1573 |
//This is a simple way of testing that CustomSecurityCheckL is called for a
|
|
1574 |
//connect custom check. Server2 doesn't have an implementation of CustomSecurityCheckL
|
|
1575 |
User::WaitForRequest(logon);
|
|
1576 |
test(logon == EPolSvrCallingBaseImplementation);
|
|
1577 |
|
|
1578 |
Session.Close();
|
|
1579 |
CLOSE_AND_WAIT(server);
|
|
1580 |
}
|
|
1581 |
|
|
1582 |
void TestServer3WithPolicy8()
|
|
1583 |
{
|
|
1584 |
test.Next(_L("Server 3, Policy 8"));
|
|
1585 |
RTestProcess server;
|
|
1586 |
TRequestStatus rendezvous;
|
|
1587 |
server.Create(~KTestCapabilities,ETestProcessPolicyServer,EPolicy8,ETestServer1);
|
|
1588 |
server.Rendezvous(rendezvous);
|
|
1589 |
server.Resume();
|
|
1590 |
User::WaitForRequest(rendezvous);
|
|
1591 |
test(rendezvous==KServerRendezvous);
|
|
1592 |
|
|
1593 |
//This will be calling through CustomSecurityCheckL
|
|
1594 |
//(server3::CustomSecurityCheckL will fail this, but set the action to
|
|
1595 |
//EQueryUser, which will call CustomFailureActionL which should will in
|
|
1596 |
//this case pass) but there is no easy way to determine that it has
|
|
1597 |
//followed the correct path.
|
|
1598 |
TInt r = Session.Connect();
|
|
1599 |
test(r==KErrNone);
|
|
1600 |
|
|
1601 |
//This policy doesn't have any IPC's that work. Only way to shutdown
|
|
1602 |
//server is to kill it.
|
|
1603 |
server.Terminate(KErrGeneral);
|
|
1604 |
Session.Close();
|
|
1605 |
CLOSE_AND_WAIT(server);
|
|
1606 |
}
|
|
1607 |
|
|
1608 |
|
|
1609 |
void TestServer1WithPolicy9()
|
|
1610 |
{
|
|
1611 |
test.Next(_L("Server 1, Policy 9"));
|
|
1612 |
RTestProcess server;
|
|
1613 |
TRequestStatus rendezvous;
|
|
1614 |
server.Create(~KTestCapabilities,ETestProcessPolicyServer,EPolicy9,ETestServer1);
|
|
1615 |
server.Rendezvous(rendezvous);
|
|
1616 |
server.Resume();
|
|
1617 |
User::WaitForRequest(rendezvous);
|
|
1618 |
test(rendezvous==KServerRendezvous);
|
|
1619 |
|
|
1620 |
TInt r = Session.Connect();
|
|
1621 |
test(r==KErrPermissionDenied);
|
|
1622 |
|
|
1623 |
//We can do this because we have power management
|
|
1624 |
server.Terminate(KErrGeneral);
|
|
1625 |
CLOSE_AND_WAIT(server);
|
|
1626 |
}
|
|
1627 |
|
|
1628 |
void TestServer2WithPolicy1()
|
|
1629 |
{
|
|
1630 |
test.Next(_L("Server 2, Policy 1"));
|
|
1631 |
RTestProcess server;
|
|
1632 |
TRequestStatus rendezvous;
|
|
1633 |
server.Create(~KTestCapabilities,ETestProcessPolicyServer,EPolicy1,ETestServer2);
|
|
1634 |
server.Rendezvous(rendezvous);
|
|
1635 |
server.Resume();
|
|
1636 |
User::WaitForRequest(rendezvous);
|
|
1637 |
test(rendezvous==KServerRendezvous);
|
|
1638 |
|
|
1639 |
TInt r = Session.Connect();
|
|
1640 |
test(r==KErrNone);
|
|
1641 |
|
|
1642 |
TBuf8<4> flags(4);
|
|
1643 |
r = Session.Send(CTestSession2::EShutdown, TIpcArgs(&flags));
|
|
1644 |
test(r == KErrNone);
|
|
1645 |
Session.Close();
|
|
1646 |
CLOSE_AND_WAIT(server);
|
|
1647 |
}
|
|
1648 |
|
|
1649 |
void TestServer4WithPolicy10()
|
|
1650 |
{
|
|
1651 |
test.Next(_L("Server 4, Policy 10"));
|
|
1652 |
RTestProcess server;
|
|
1653 |
TRequestStatus rendezvous;
|
|
1654 |
server.Create(~KTestCapabilities,ETestProcessPolicyServer,EPolicy10,ETestServer4);
|
|
1655 |
server.Rendezvous(rendezvous);
|
|
1656 |
server.Resume();
|
|
1657 |
User::WaitForRequest(rendezvous);
|
|
1658 |
test(rendezvous==KServerRendezvous);
|
|
1659 |
|
|
1660 |
TInt r = Session.Connect();
|
|
1661 |
test(r==KErrNone);
|
|
1662 |
|
|
1663 |
TBuf8<4> flags(4);
|
|
1664 |
|
|
1665 |
//case 0: Custom Check, fails with KErrPermissionDenied
|
|
1666 |
SetFlags(flags, 0);
|
|
1667 |
r = Session.Send(0, TIpcArgs(&flags));
|
|
1668 |
test(r==KErrPermissionDenied);
|
|
1669 |
test(FlagsValue(flags) == (0 | KCustomCheckMask | KActiveCheckMask | KActiveRunLMask) );
|
|
1670 |
|
|
1671 |
//case 1: Custom Check passes.
|
|
1672 |
SetFlags(flags, 1);
|
|
1673 |
r = Session.Send(1, TIpcArgs(&flags));
|
|
1674 |
test(r==KErrNone);
|
|
1675 |
test(FlagsValue(flags) == (1 | KCustomCheckMask | KActiveCheckMask | KActiveRunLMask | KServiceLMask) );
|
|
1676 |
|
|
1677 |
//case 2: Custom Check fails but action set to EQueryUser, query
|
|
1678 |
//subsequently fails
|
|
1679 |
SetFlags(flags, 2);
|
|
1680 |
r = Session.Send(2, TIpcArgs(&flags));
|
|
1681 |
test(r==KErrPermissionDenied);
|
|
1682 |
test(FlagsValue(flags) == (2 | KCustomCheckMask | KActiveCheckMask | KActiveRunLMask | KCustomActionMask | KActiveActionMask ));
|
|
1683 |
|
|
1684 |
//case 3: Custom Check fails but action set to EQueryUser, query
|
|
1685 |
//subsequently passes
|
|
1686 |
SetFlags(flags, 3);
|
|
1687 |
r = Session.Send(3, TIpcArgs(&flags));
|
|
1688 |
test(r==KErrNone);
|
|
1689 |
test(FlagsValue(flags) == (3 | KCustomCheckMask | KActiveCheckMask | KActiveRunLMask | KCustomActionMask | KActiveActionMask | KServiceLMask ));
|
|
1690 |
|
|
1691 |
//case 4: Custom Check passes and action is set. Action set shouldn't make
|
|
1692 |
//a difference. Should be same result as case 1.
|
|
1693 |
SetFlags(flags, 4);
|
|
1694 |
r = Session.Send(4, TIpcArgs(&flags));
|
|
1695 |
test(r==KErrNone);
|
|
1696 |
test(FlagsValue(flags) == (4 | KCustomCheckMask | KActiveCheckMask | KActiveRunLMask | KServiceLMask) );
|
|
1697 |
|
|
1698 |
//case 5: Always passes at the policy server level.
|
|
1699 |
SetFlags(flags, 5);
|
|
1700 |
r = Session.Send(5, TIpcArgs(&flags));
|
|
1701 |
test(r==KErrNone);
|
|
1702 |
test(FlagsValue(flags) == (5 | KServiceLMask) );
|
|
1703 |
|
|
1704 |
//case 6: Not Supported, returned from policy server level.
|
|
1705 |
SetFlags(flags, 6);
|
|
1706 |
r = Session.Send(6, TIpcArgs(&flags));
|
|
1707 |
test(r==KErrNotSupported);
|
|
1708 |
test(FlagsValue(flags) == (6));
|
|
1709 |
|
|
1710 |
//case 7: Not Supported, returned from policy server level.
|
|
1711 |
SetFlags(flags, 7);
|
|
1712 |
r = Session.Send(7, TIpcArgs(&flags));
|
|
1713 |
test(r==KErrNotSupported);
|
|
1714 |
test(FlagsValue(flags) == (7));
|
|
1715 |
|
|
1716 |
//case 8: Requires NetworkControl, which we have, so it passes.
|
|
1717 |
SetFlags(flags, 8);
|
|
1718 |
r = Session.Send(8, TIpcArgs(&flags));
|
|
1719 |
test(r==KErrNone);
|
|
1720 |
test(FlagsValue(flags) == (8 | KServiceLMask));
|
|
1721 |
|
|
1722 |
//case 9: Requires DiskAdmin, which we don't have. EQueryUser is set, and
|
|
1723 |
//it passes.
|
|
1724 |
SetFlags(flags, 9);
|
|
1725 |
r = Session.Send(9, TIpcArgs(&flags));
|
|
1726 |
test(r==KErrNone);
|
|
1727 |
test(FlagsValue(flags) == (9 | KCustomActionMask | KActiveActionMask | KActiveRunLMask | KServiceLMask));
|
|
1728 |
|
|
1729 |
//case 10: Requires DiskAdmin which we don't have.
|
|
1730 |
SetFlags(flags, 10);
|
|
1731 |
r = Session.Send(10, TIpcArgs(&flags));
|
|
1732 |
test(r==KErrPermissionDenied);
|
|
1733 |
test(FlagsValue(flags) == (10));
|
|
1734 |
|
|
1735 |
//case 11: Requires NetworkControl -> pass. Thrown in a EQueryUser to see
|
|
1736 |
//if it causes any problems -> it shouldn't. Should be same as case 8.
|
|
1737 |
SetFlags(flags, 11);
|
|
1738 |
r = Session.Send(11, TIpcArgs(&flags));
|
|
1739 |
test(r==KErrNone);
|
|
1740 |
test(FlagsValue(flags) == (11 | KServiceLMask));
|
|
1741 |
|
|
1742 |
//case 12: Not Supported, returned from policy server level.
|
|
1743 |
SetFlags(flags, 12);
|
|
1744 |
r = Session.Send(12, TIpcArgs(&flags));
|
|
1745 |
test(r==KErrNotSupported);
|
|
1746 |
test(FlagsValue(flags) == (12));
|
|
1747 |
|
|
1748 |
//case 13: Not Supported, returned from policy server level.
|
|
1749 |
SetFlags(flags, 13);
|
|
1750 |
r = Session.Send(13, TIpcArgs(&flags));
|
|
1751 |
test(r==KErrNotSupported);
|
|
1752 |
test(FlagsValue(flags) == (13));
|
|
1753 |
|
|
1754 |
//case 54: Not Supported, returned from policy server level.
|
|
1755 |
SetFlags(flags, 54);
|
|
1756 |
r = Session.Send(54, TIpcArgs(&flags));
|
|
1757 |
test(r==KErrNotSupported);
|
|
1758 |
test(FlagsValue(flags) == (54));
|
|
1759 |
|
|
1760 |
//case 55: Requires DiskAdmin -> Fail. But then we query user, and then we
|
|
1761 |
//cancel that.
|
|
1762 |
SetFlags(flags, 55);
|
|
1763 |
r = Session.Send(55, TIpcArgs(&flags));
|
|
1764 |
test(r==KErrCancel);
|
|
1765 |
test(FlagsValue(flags) == (55 | KCustomActionMask | KActiveActionMask | KActiveDoCancelMask));
|
|
1766 |
|
|
1767 |
//case 56: Requires DiskAdmin -> Fail. But then we query user which leaves.
|
|
1768 |
SetFlags(flags, 56);
|
|
1769 |
r = Session.Send(56, TIpcArgs(&flags));
|
|
1770 |
test(r==KErrNoMemory);
|
|
1771 |
test(FlagsValue(flags) == (56 | KCustomActionMask | KActiveActionMask | KActiveRunLMask | KActiveRunErrorMask));
|
|
1772 |
|
|
1773 |
//case 57: Requires DiskAdmin -> Fail. But then we query user which passes
|
|
1774 |
//and then we leave in the ServiceL
|
|
1775 |
SetFlags(flags, 57);
|
|
1776 |
r = Session.Send(57, TIpcArgs(&flags));
|
|
1777 |
test(r==KErrNoMemory);
|
|
1778 |
test(FlagsValue(flags) == (57 | KCustomActionMask | KActiveActionMask | KActiveRunLMask | KServiceLMask | KActiveRunErrorMask | KServiceErrorMask ));
|
|
1779 |
|
|
1780 |
//case 58: Not Supported, returned from policy server level.
|
|
1781 |
SetFlags(flags, 58);
|
|
1782 |
r = Session.Send(58, TIpcArgs(&flags));
|
|
1783 |
test(r==KErrNotSupported);
|
|
1784 |
test(FlagsValue(flags) == (58));
|
|
1785 |
|
|
1786 |
//case 86: Not Supported, returned from policy server level.
|
|
1787 |
SetFlags(flags, 86);
|
|
1788 |
r = Session.Send(86, TIpcArgs(&flags));
|
|
1789 |
test(r==KErrNotSupported);
|
|
1790 |
test(FlagsValue(flags) == (86));
|
|
1791 |
|
|
1792 |
//case 99: Not Supported, returned from policy server level.
|
|
1793 |
SetFlags(flags, 99);
|
|
1794 |
r = Session.Send(99, TIpcArgs(&flags));
|
|
1795 |
test(r==KErrNotSupported);
|
|
1796 |
test(FlagsValue(flags) == (99));
|
|
1797 |
|
|
1798 |
//case 101: Not Supported, returned from policy server level.
|
|
1799 |
SetFlags(flags, 101);
|
|
1800 |
r = Session.Send(101, TIpcArgs(&flags));
|
|
1801 |
test(r==KErrNotSupported);
|
|
1802 |
test(FlagsValue(flags) == (101));
|
|
1803 |
|
|
1804 |
//case 5000: Not Supported, returned from policy server level.
|
|
1805 |
SetFlags(flags, 5000);
|
|
1806 |
r = Session.Send(5000, TIpcArgs(&flags));
|
|
1807 |
test(r==KErrNotSupported);
|
|
1808 |
test(FlagsValue(flags) == (5000));
|
|
1809 |
|
|
1810 |
//case KMaxTInt-1: Not Supported, returned from policy server level.
|
|
1811 |
SetFlags(flags, KMaxTInt-1);
|
|
1812 |
r = Session.Send(KMaxTInt-1, TIpcArgs(&flags));
|
|
1813 |
test(r==KErrNotSupported);
|
|
1814 |
test(FlagsValue(flags) == (KMaxTInt-1));
|
|
1815 |
|
|
1816 |
//case KMaxTInt: Always pass from policy framework
|
|
1817 |
//This also tests another exit condition from the binary search
|
|
1818 |
SetFlags(flags, 0);
|
|
1819 |
r = Session.Send(KMaxTInt, TIpcArgs(&flags));
|
|
1820 |
//Instead of KErrNone we return KMaxTInt as we can't fit the KMaxTInt in
|
|
1821 |
//the flags without overwriting stuff
|
|
1822 |
test(r==KMaxTInt);
|
|
1823 |
test(FlagsValue(flags) == (0 | KServiceLMask ));
|
|
1824 |
|
|
1825 |
r = Session.Send(CTestSession2::EShutdown, TIpcArgs(&flags));
|
|
1826 |
test(r == KErrNone);
|
|
1827 |
Session.Close();
|
|
1828 |
CLOSE_AND_WAIT(server);
|
|
1829 |
}
|
|
1830 |
|
|
1831 |
GLDEF_C TInt E32Main()
|
|
1832 |
{
|
|
1833 |
TBuf16<512> cmd;
|
|
1834 |
User::CommandLine(cmd);
|
|
1835 |
if(cmd.Length() && TChar(cmd[0]).IsDigit())
|
|
1836 |
{
|
|
1837 |
TInt function = -1;
|
|
1838 |
TInt arg1 = -1;
|
|
1839 |
TInt arg2 = -1;
|
|
1840 |
TLex lex(cmd);
|
|
1841 |
|
|
1842 |
lex.Val(function);
|
|
1843 |
lex.SkipSpace();
|
|
1844 |
lex.Val(arg1);
|
|
1845 |
lex.SkipSpace();
|
|
1846 |
lex.Val(arg2);
|
|
1847 |
return DoTestProcess(function,arg1,arg2);
|
|
1848 |
}
|
|
1849 |
|
|
1850 |
test.Title();
|
|
1851 |
|
|
1852 |
if(!PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement))
|
|
1853 |
{
|
|
1854 |
test.Start(_L("TESTS NOT RUN - EPlatSecEnforcement is OFF"));
|
|
1855 |
test.End();
|
|
1856 |
return 0;
|
|
1857 |
}
|
|
1858 |
|
|
1859 |
test.Start(_L("Policy Server Tests"));
|
|
1860 |
|
|
1861 |
/* Server1 has implementations of CustomSecurityCheckL and
|
|
1862 |
CustomFailureActionL This is the test for all the paths in a policy servers
|
|
1863 |
implementations -- not all connect paths though
|
|
1864 |
This test also ensures that every path through the binary search is
|
|
1865 |
covered. */
|
|
1866 |
TestServer1WithPolicy1();
|
|
1867 |
|
|
1868 |
/* Policy2,3,4,5,6, are bad policies that should cause the server to panic
|
|
1869 |
in debug mode. In release, they'll just pass, however, if you later tried
|
|
1870 |
to use them, something would go horribly wrong */
|
|
1871 |
TestServer1WithPolicy2();
|
|
1872 |
TestServer1WithPolicy3();
|
|
1873 |
TestServer1WithPolicy4();
|
|
1874 |
TestServer1WithPolicy5();
|
|
1875 |
TestServer1WithPolicy6();
|
|
1876 |
|
|
1877 |
/* Policies 7,8,9 check various types of connect policies. */
|
|
1878 |
TestServer1WithPolicy7();
|
|
1879 |
// Server 1,2,3 are used here all with policy 8 because you can only test 1
|
|
1880 |
// type of connect policy per server.
|
|
1881 |
TestServer1WithPolicy8();
|
|
1882 |
TestServer2WithPolicy8();
|
|
1883 |
TestServer3WithPolicy8();
|
|
1884 |
TestServer1WithPolicy9();
|
|
1885 |
|
|
1886 |
/* Sever2 does not have implementations of CustomSecurityCheckL and
|
|
1887 |
CustomFailureActionL. When these functions are called it should crash */
|
|
1888 |
TestServer2WithPolicy1();
|
|
1889 |
|
|
1890 |
/* Server4 is used for checking what happens when the custom functions use
|
|
1891 |
another active object. This test encompasses leaving due to OOM, and
|
|
1892 |
cancellation. */
|
|
1893 |
TestServer4WithPolicy10();
|
|
1894 |
|
|
1895 |
test.End();
|
|
1896 |
return(0);
|
|
1897 |
}
|
|
1898 |
|