|
1 /* |
|
2 * Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of policymanagement components |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "SettingEnforcementManager.h" |
|
22 #include "PolicyEngineServer.h" |
|
23 #include "EMailEnforcement.h" |
|
24 #include "CommsDatEnforcement.h" |
|
25 #include "IMEnforcement.h" |
|
26 #include "datasyncmlenforcement.h" |
|
27 #include "ElementBase.h" |
|
28 #include "PolicyStorage.h" |
|
29 #include "elements.h" |
|
30 #include "DataTypes.h" |
|
31 |
|
32 #include "XACMLconstants.h" |
|
33 #include "ErrorCodes.h" |
|
34 #include "debug.h" |
|
35 |
|
36 // EXTERNAL DATA STRUCTURES |
|
37 // EXTERNAL FUNCTION PROTOTYPES |
|
38 // CONSTANTS |
|
39 // MACROS |
|
40 // LOCAL CONSTANTS AND MACROS |
|
41 // MODULE DATA STRUCTURES |
|
42 // LOCAL FUNCTION PROTOTYPES |
|
43 |
|
44 |
|
45 // ==================== LOCAL FUNCTIONS ==================== |
|
46 |
|
47 // ================= MEMBER FUNCTIONS ======================= |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CSettingEnforcementManager::CSettingEnforcementManager() |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 |
|
54 CSettingEnforcementManager::CSettingEnforcementManager() |
|
55 : CActive( EPriorityLow) |
|
56 { |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CSettingEnforcementManager::~CSettingEnforcementManager() |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 CSettingEnforcementManager::~CSettingEnforcementManager() |
|
64 { |
|
65 iEnforcementElements.ResetAndDestroy(); |
|
66 iEnforcementElements.Close(); |
|
67 |
|
68 iValidEditorsForSetting.ResetAndDestroy(); |
|
69 iValidEditorsForSetting.Close(); |
|
70 |
|
71 delete iActiveEnforcementBase; |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CSettingEnforcementManager::NewL() |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 CSettingEnforcementManager* CSettingEnforcementManager::NewL() |
|
79 { |
|
80 return new (ELeave) CSettingEnforcementManager(); |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // CSettingEnforcementManager::StartEnforcementSessionL() |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 void CSettingEnforcementManager::StartEnforcementSessionL( TRequestStatus& aRequestStatus, const TCertInfo& aCertInfo) |
|
88 { |
|
89 //reset context |
|
90 iEnforcementElements.ResetAndDestroy(); |
|
91 iValidEditorsForSetting.ResetAndDestroy(); |
|
92 |
|
93 iExternalRequestStatus = &aRequestStatus; |
|
94 aRequestStatus = KRequestPending; |
|
95 |
|
96 iCertInfo = aCertInfo; |
|
97 |
|
98 //Add object to active scheduler |
|
99 if ( !IsAdded()) |
|
100 { |
|
101 CActiveScheduler::Add( this); |
|
102 } |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CSettingEnforcementManager::AddModifiedElementL() |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 void CSettingEnforcementManager::AddModifiedElementL( const CElementBase* aElement) |
|
110 { |
|
111 using namespace PolicyLanguage::Constants; |
|
112 |
|
113 __ASSERT_ALWAYS( aElement, User::Panic( Panics::SettingEnforcementManagerPanic, KErrAbort)); |
|
114 |
|
115 HBufC8 * elementName = aElement->ExternalId(); |
|
116 |
|
117 //If element has external id |
|
118 if ( elementName) |
|
119 { |
|
120 //and if element is enforcement element |
|
121 if ( CEmailEnforcement::ValidEnforcementElement( *elementName) || |
|
122 CCommsDatEnforcement::ValidEnforcementElement( *elementName) || |
|
123 CDataSyncMLEnforcement::ValidEnforcementElement( *elementName) || |
|
124 CImEnforcement::ValidEnforcementElement(*elementName)) |
|
125 { |
|
126 iEnforcementElements.AppendL( elementName->Alloc()); |
|
127 } |
|
128 } |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CSettingEnforcementManager::ExecuteEnforcementSessionL() |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 void CSettingEnforcementManager::ExecuteEnforcementSessionL() |
|
136 { |
|
137 //Reset operation state |
|
138 iOperationCounter = 0; |
|
139 iOperationState = 0; |
|
140 |
|
141 //Start scheduling |
|
142 SetActive(); |
|
143 TRequestStatus * status = &iStatus; |
|
144 User::RequestComplete( status, KErrNone); |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CSettingEnforcementManager::CommitChanges() |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 void CSettingEnforcementManager::CommitChanges() |
|
152 { |
|
153 //Commit changes.... |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // CSettingEnforcementManager::EndEnforcementSessionL() |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 void CSettingEnforcementManager::EndEnforcementSession( TBool aFlushSettings) |
|
161 { |
|
162 //finish active enforcement base |
|
163 if ( iActiveEnforcementBase) |
|
164 { |
|
165 iActiveEnforcementBase->FinishEnforcementL( aFlushSettings); |
|
166 delete iActiveEnforcementBase; |
|
167 iActiveEnforcementBase = 0; |
|
168 } |
|
169 |
|
170 //destroy editor list (this must be valid until FinishEnforcementL is called for enforcementbase) |
|
171 iValidEditorsForSetting.ResetAndDestroy(); |
|
172 } |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // CSettingEnforcementManager::RunL() |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 void CSettingEnforcementManager::RunL() |
|
179 { |
|
180 using namespace PolicyLanguage::Constants; |
|
181 |
|
182 if ( iStatus.Int() != KErrNone) |
|
183 { |
|
184 User::RequestComplete( iExternalRequestStatus, iStatus.Int()); |
|
185 return; |
|
186 } |
|
187 |
|
188 |
|
189 if ( iOperationCounter < iEnforcementElements.Count()) |
|
190 { |
|
191 TBool requested = ETrue; |
|
192 TInt requestStatus = KErrNone; |
|
193 |
|
194 switch ( iOperationState ) |
|
195 { |
|
196 case 0: |
|
197 if ( iOperationState == 0) |
|
198 { |
|
199 //reset arrays and get new editors for setting |
|
200 iValidEditorsForSetting.ResetAndDestroy(); |
|
201 |
|
202 iActivelementName = iEnforcementElements[ iOperationCounter]; |
|
203 TUint32 elementId = CPolicyStorage::PolicyStorage()->MapRealIdL( *iActivelementName, EFalse ); |
|
204 |
|
205 if ( elementId != 0) |
|
206 { |
|
207 ResolveValidEditorsForSettingL( elementId); |
|
208 } |
|
209 |
|
210 requested = EFalse; |
|
211 iOperationState++; |
|
212 |
|
213 //select active enforment base |
|
214 __ASSERT_ALWAYS( iActivelementName, User::Panic( Panics::SettingEnforcementManagerPanic, KErrAbort)); |
|
215 SetActiveEnforcementBaseL( *iActivelementName); |
|
216 } |
|
217 break; |
|
218 case 1: |
|
219 if ( iOperationState == 1) |
|
220 { |
|
221 if ( iActiveEnforcementBase->InitReady()) |
|
222 { |
|
223 requested = EFalse; |
|
224 iOperationState++; |
|
225 } |
|
226 else |
|
227 { |
|
228 iActiveEnforcementBase->InitEnforcementL( iStatus); |
|
229 } |
|
230 } |
|
231 break; |
|
232 case 2: |
|
233 if ( iOperationState == 2) |
|
234 { |
|
235 if ( iActiveEnforcementBase->EnforcementReady()) |
|
236 { |
|
237 //when enforcement is ready... |
|
238 requested = EFalse; |
|
239 iOperationState = 0; |
|
240 iOperationCounter++; |
|
241 } |
|
242 else |
|
243 { |
|
244 //and the next rounds are dedicated for doing enforcement until enforcement is ready |
|
245 iActiveEnforcementBase->DoEnforcementL( iStatus); |
|
246 } |
|
247 } |
|
248 break; |
|
249 } |
|
250 |
|
251 //Continue scheduling... |
|
252 SetActive(); |
|
253 if ( !requested ) |
|
254 { |
|
255 TRequestStatus * status = &iStatus; |
|
256 User::RequestComplete( status, requestStatus); |
|
257 } |
|
258 } |
|
259 else |
|
260 { |
|
261 User::RequestComplete( iExternalRequestStatus, KErrNone); |
|
262 } |
|
263 } |
|
264 |
|
265 // ----------------------------------------------------------------------------- |
|
266 // CSettingEnforcementManager::RunError() |
|
267 // ----------------------------------------------------------------------------- |
|
268 // |
|
269 TInt CSettingEnforcementManager::RunError( TInt aError) |
|
270 { |
|
271 RDEBUG_2(" **** ERROR, CSettingEnforcementManager::RunError( %d )", aError ); |
|
272 //Complete external request with error value |
|
273 User::RequestComplete( iExternalRequestStatus, aError); |
|
274 |
|
275 return KErrNone; |
|
276 } |
|
277 |
|
278 // ----------------------------------------------------------------------------- |
|
279 // CSettingEnforcementManager::DoCancel() |
|
280 // ----------------------------------------------------------------------------- |
|
281 // |
|
282 void CSettingEnforcementManager::DoCancel() |
|
283 { |
|
284 RunError( KErrAbort); |
|
285 } |
|
286 |
|
287 |
|
288 // ----------------------------------------------------------------------------- |
|
289 // CSettingEnforcementManager::SetActiveEnforcementBaseL() |
|
290 // ----------------------------------------------------------------------------- |
|
291 // |
|
292 |
|
293 void CSettingEnforcementManager::SetActiveEnforcementBaseL( const TDesC8& aEnforcementId) |
|
294 { |
|
295 //delete old enforcement base |
|
296 delete iActiveEnforcementBase; |
|
297 iActiveEnforcementBase = 0; |
|
298 |
|
299 //and if element is enforcement element |
|
300 iActiveEnforcementBase = CEmailEnforcement::NewL( aEnforcementId); |
|
301 |
|
302 |
|
303 if ( !iActiveEnforcementBase) |
|
304 { |
|
305 iActiveEnforcementBase = CCommsDatEnforcement::NewL( aEnforcementId); |
|
306 } |
|
307 |
|
308 if ( !iActiveEnforcementBase) |
|
309 { |
|
310 iActiveEnforcementBase = CDataSyncMLEnforcement::NewL( aEnforcementId); |
|
311 } |
|
312 |
|
313 if ( !iActiveEnforcementBase) |
|
314 { |
|
315 iActiveEnforcementBase = CImEnforcement::NewL( aEnforcementId); |
|
316 } |
|
317 |
|
318 if ( iActiveEnforcementBase ) |
|
319 { |
|
320 iActiveEnforcementBase->AccessRightList( iValidEditorsForSetting); |
|
321 iActiveEnforcementBase->SetSessionCertificate( iCertInfo ); |
|
322 } |
|
323 } |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 // ----------------------------------------------------------------------------- |
|
329 // CSettingEnforcementManager::ResolveValidEditorsForSettingL() |
|
330 // ----------------------------------------------------------------------------- |
|
331 // |
|
332 void CSettingEnforcementManager::ResolveValidEditorsForSettingL( TUint32 iElementId) |
|
333 { |
|
334 using namespace PolicyLanguage::NativeLanguage::Functions; |
|
335 using namespace PolicyLanguage::Constants; |
|
336 |
|
337 //get and reserve element |
|
338 CElementBase * policyElement = CPolicyStorage::PolicyStorage()->GetEditableElementL( iElementId); |
|
339 |
|
340 if ( policyElement == NULL) |
|
341 { |
|
342 return; |
|
343 } |
|
344 |
|
345 if ( policyElement->ElementType() != EPolicy) |
|
346 { |
|
347 return; |
|
348 } |
|
349 |
|
350 TElementReserver policyReserver( policyElement); |
|
351 CPolicyStorage::PolicyStorage()->CheckElementL( policyElement); |
|
352 |
|
353 |
|
354 //Find Subjectmatch element, they determines who has right to modifie settings |
|
355 RElementArray rules; |
|
356 policyElement->FindAttributesL( ERule, rules); |
|
357 CleanupClosePushL( rules); |
|
358 |
|
359 for ( TInt j(0); j < rules.Count(); j++) |
|
360 { |
|
361 CRule* rule = (CRule*)rules[ j]; |
|
362 TElementReserver ruleReserver( rule); |
|
363 CPolicyStorage::PolicyStorage()->CheckElementL( rule); |
|
364 |
|
365 if ( rule->Effect() == EPermit) |
|
366 { |
|
367 //Find Subjectmatch element, they determines who has right to modifie settings |
|
368 RElementArray attributes; |
|
369 rule->FindAttributesL( ESubjectMatch, attributes); |
|
370 CleanupClosePushL( attributes); |
|
371 |
|
372 |
|
373 for ( TInt i(0); i < attributes.Count(); i++) |
|
374 { |
|
375 CElementBase * element = attributes[i]; |
|
376 |
|
377 if ( element->ElementType() == ESubjectMatch ) |
|
378 { |
|
379 TElementReserver elementReserver( attributes[i]); |
|
380 CPolicyStorage::PolicyStorage()->CheckElementL( element); |
|
381 |
|
382 CMatchObject* subjectMatch = (CMatchObject*)element; |
|
383 |
|
384 //Search TrustedSubjectMatch attributes |
|
385 if ( *subjectMatch->MatchId() == TrustedSubjectMatch ) |
|
386 { |
|
387 //and add valid editors (Trusted subjects) to valid editors list... |
|
388 if ( subjectMatch->AttributeDesignator()->GetAttributeid() == PolicyEngineXACML::KTrustedSubject ) |
|
389 { |
|
390 iValidEditorsForSetting.AppendL( subjectMatch->AttributeValue()->Data()->Value().AllocL()); |
|
391 } |
|
392 } |
|
393 |
|
394 elementReserver.Release(); |
|
395 } |
|
396 } |
|
397 |
|
398 CleanupStack::PopAndDestroy( &attributes); |
|
399 } |
|
400 |
|
401 ruleReserver.Release(); |
|
402 } |
|
403 |
|
404 policyReserver.Release(); |
|
405 CleanupStack::PopAndDestroy( &rules); |
|
406 |
|
407 } |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 // ----------------------------------------------------------------------------- |
|
413 // CSettingEnforcementManager::SessionCertificate() |
|
414 // ----------------------------------------------------------------------------- |
|
415 // |
|
416 TCertInfo& CSettingEnforcementManager::SessionCertificate() |
|
417 { |
|
418 return iCertInfo; |
|
419 } |
|
420 |
|
421 // ----------------------------------------------------------------------------- |
|
422 // CEnforcementBase::SetSessionCertificate() |
|
423 // ----------------------------------------------------------------------------- |
|
424 // |
|
425 void CEnforcementBase::SetSessionCertificate( TCertInfo& aCertInfo) |
|
426 { |
|
427 iCertInfo = &aCertInfo; |
|
428 } |
|
429 |
|
430 |
|
431 // ----------------------------------------------------------------------------- |
|
432 // CEnforcementBase::SetSessionCertificate() |
|
433 // ----------------------------------------------------------------------------- |
|
434 // |
|
435 TCertInfo& CEnforcementBase::SessionCertificate() |
|
436 { |
|
437 return *iCertInfo; |
|
438 } |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |