|
1 /* |
|
2 * Copyright (c) 2007-2009 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: Controls the vpn policy import procedure. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <apacmdln.h> |
|
20 #include <bautils.h> |
|
21 #include <sysutil.h> |
|
22 #include <securityerr.h> |
|
23 |
|
24 #include "policyinstaller.h" |
|
25 #include "vpnnotifierdefs.h" |
|
26 #include "vpnpolicyrecognizerconstants.h" |
|
27 #include "zipfiledecompressor.h" |
|
28 #include "policyinstaller_constants.h" |
|
29 |
|
30 // Device lock / PKCS#12 installation |
|
31 #include "vpnbundlehandler.h" |
|
32 #include "cmdfileparser.h" |
|
33 #include "pkcs12vpn.h" |
|
34 #include "cmdfilexmltags.h" |
|
35 #include "vpndevlockhandler.h" |
|
36 |
|
37 |
|
38 #include "log_r6.h" |
|
39 |
|
40 |
|
41 void RunServerL(); |
|
42 |
|
43 GLDEF_C TInt E32Main() |
|
44 { |
|
45 __UHEAP_MARK; |
|
46 |
|
47 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
48 if (!cleanupStack) |
|
49 { |
|
50 return KErrNoMemory; |
|
51 } |
|
52 |
|
53 TRAP_IGNORE(RunServerL()); |
|
54 |
|
55 delete cleanupStack; |
|
56 |
|
57 __UHEAP_MARKEND; |
|
58 return KErrNone; |
|
59 } |
|
60 |
|
61 void RunServerL() |
|
62 { |
|
63 LOG_("-> VPNPolins RunServerL()"); |
|
64 |
|
65 |
|
66 // Create and install the active scheduler |
|
67 LOG_(" Instantiate active scheduler()"); |
|
68 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
69 CleanupStack::PushL(scheduler); |
|
70 LOG_(" Installing active scheduler()"); |
|
71 CActiveScheduler::Install(scheduler); |
|
72 |
|
73 // Create the installer active object and issue the install request |
|
74 LOG_(" Instantiating CVpnPolicyInstaller"); |
|
75 CVpnPolicyInstaller* installer = CVpnPolicyInstaller::NewL(); |
|
76 CleanupStack::PushL(installer); |
|
77 |
|
78 LOG_(" Installing policy"); |
|
79 installer->InstallPolicy(); |
|
80 |
|
81 // Now we can start the active scheduler |
|
82 LOG_(" Starting active scheduler"); |
|
83 CActiveScheduler::Start(); |
|
84 |
|
85 |
|
86 LOG_(" Returning to RunServerL()"); |
|
87 |
|
88 // We're done, so remove objects from |
|
89 // cleanup stack and destroy them |
|
90 |
|
91 LOG_(" Pop installer"); |
|
92 CleanupStack::PopAndDestroy(installer); |
|
93 |
|
94 LOG_(" Pop scheduler"); |
|
95 CleanupStack::PopAndDestroy(scheduler); |
|
96 |
|
97 LOG_("<- VPNPolins RunServerL()"); |
|
98 } |
|
99 |
|
100 |
|
101 ///////////////////////////////////// |
|
102 // CVpnPolicyInstaller class implementation |
|
103 |
|
104 CVpnPolicyInstaller* CVpnPolicyInstaller::NewL() |
|
105 { |
|
106 CVpnPolicyInstaller* self = new (ELeave) CVpnPolicyInstaller(); |
|
107 CleanupStack::PushL(self); |
|
108 self->ConstructL(); |
|
109 CleanupStack::Pop(self); |
|
110 return self; |
|
111 } |
|
112 |
|
113 CVpnPolicyInstaller::CVpnPolicyInstaller() : CActive(EPriorityStandard) |
|
114 { |
|
115 } |
|
116 |
|
117 void CVpnPolicyInstaller::ConstructL() |
|
118 { |
|
119 LOG_("-> CVpnPolicyInstaller::ConstructL()"); |
|
120 CActiveScheduler::Add(this); |
|
121 User::LeaveIfError(iNotifier.Connect()); |
|
122 User::LeaveIfError(iFileServer.Connect()); |
|
123 |
|
124 |
|
125 TInt err = |
|
126 CApaCommandLine::GetCommandLineFromProcessEnvironment(iCommandLine); |
|
127 User::LeaveIfError(err); |
|
128 |
|
129 |
|
130 if (iCommandLine->DocumentName().Length() == 0) |
|
131 { |
|
132 User::Leave(KErrArgument); |
|
133 } |
|
134 #ifdef ATS_BUILD |
|
135 _LIT(KPassword, "password"); |
|
136 iP12Password = HBufC::NewL(KPassword().Length()); |
|
137 iP12Password->Des().Copy(KPassword); |
|
138 #endif |
|
139 LOG_("<- CVpnPolicyInstaller::ConstructL()"); |
|
140 } |
|
141 |
|
142 CVpnPolicyInstaller::~CVpnPolicyInstaller() |
|
143 { |
|
144 LOG_("-> CVpnPolicyInstaller::~CVpnPolicyInstaller()"); |
|
145 Cancel(); |
|
146 |
|
147 delete iDecompressor; |
|
148 delete iDriveAndPath; |
|
149 delete iCommandLine; |
|
150 delete iFormat; |
|
151 delete iFileName; |
|
152 delete iP12Password; |
|
153 delete iWaitNoteHandler; |
|
154 |
|
155 iFileServer.Close(); |
|
156 iNotifier.Close(); |
|
157 iVpnServ.Close(); |
|
158 |
|
159 LOG_("<- CVpnPolicyInstaller::~CVpnPolicyInstaller()"); |
|
160 } |
|
161 |
|
162 void CVpnPolicyInstaller::InstallPolicy() |
|
163 { |
|
164 LOG_("-> CVpnPolicyInstaller::InstallPolicy()"); |
|
165 TRAPD(err, InstallPolicyL()); |
|
166 if (err != KErrNone) |
|
167 { |
|
168 LOG_1(" Policy installation terminated with error code %d", err); |
|
169 |
|
170 // Show the error note before completing. |
|
171 ShowImportErrorNote(err); |
|
172 } |
|
173 LOG_("<- CVpnPolicyInstaller::InstallPolicy()"); |
|
174 } |
|
175 |
|
176 void CVpnPolicyInstaller::InstallPolicyL() |
|
177 { |
|
178 LOG_("-> CVpnPolicyInstaller::InstallPolicyL()"); |
|
179 |
|
180 __ASSERT_ALWAYS(iCommandLine, User::Invariant()); |
|
181 |
|
182 // Disk space criticality check before attempting |
|
183 // to install |
|
184 if (SysUtil::FFSSpaceBelowCriticalLevelL(0, 0)) |
|
185 { |
|
186 User::Leave(KErrDiskFull); |
|
187 } |
|
188 |
|
189 // Parse the filename that is to be operated on, |
|
190 // and deduce its type (ZIP, PIN etc) |
|
191 |
|
192 HBufC* document = iCommandLine->DocumentName().AllocLC(); |
|
193 TPtr documentPtr(document->Des()); |
|
194 TParsePtr parse(documentPtr); |
|
195 TPtrC extension = parse.Ext(); |
|
196 iFormat = extension.AllocL(); |
|
197 |
|
198 iFileName = HBufC8::NewL(parse.NameAndExt().Length()); |
|
199 TPtr8 des = iFileName->Des(); |
|
200 des.Copy(parse.NameAndExt()); |
|
201 |
|
202 |
|
203 if (extension.CompareF(KVpnZipPolicyFileExtension) == 0) |
|
204 { |
|
205 LOG_(" Policy is in a VPN zip file"); |
|
206 ContinueInstallPolicyL(); |
|
207 } |
|
208 else if (extension.CompareF(KVpnPinPolicyFileExtension) == 0) |
|
209 { |
|
210 LOG_(" Policy is unpacked pol/pin file"); |
|
211 iDriveAndPath = parse.DriveAndPath().AllocL(); |
|
212 ContinueInstallPolicyL(); |
|
213 } |
|
214 else |
|
215 { |
|
216 LOG_(" Policy is in an unknown format, leaving"); |
|
217 LOG_("<- CVpnPolicyInstaller::InstallPolicyL() (leave)"); |
|
218 User::Leave(KErrArgument); |
|
219 } |
|
220 |
|
221 CleanupStack::PopAndDestroy(document); |
|
222 LOG_("<- CVpnPolicyInstaller::InstallPolicyL()"); |
|
223 } |
|
224 |
|
225 void CVpnPolicyInstaller::ContinueInstallPolicyL() |
|
226 { |
|
227 LOG_("-> CVpnPolicyInstaller::ContinueInstallPolicyL()"); |
|
228 |
|
229 if (iFormat->CompareF(KVpnZipPolicyFileExtension) == 0) |
|
230 { |
|
231 DeflateZippedPolicyL(); |
|
232 } |
|
233 else if (iFormat->CompareF(KVpnPinPolicyFileExtension) == 0) |
|
234 { |
|
235 InstallPinPolicyL(*iDriveAndPath); |
|
236 } |
|
237 else |
|
238 { |
|
239 LOG_("<- CVpnPolicyInstaller::ContinueInstallPolicyL() (leave)"); |
|
240 User::Leave(KErrArgument); |
|
241 } |
|
242 LOG_("<- CVpnPolicyInstaller::ContinueInstallPolicyL()"); |
|
243 } |
|
244 |
|
245 void CVpnPolicyInstaller::InstallPinPolicyL(const TDesC& aFileDirectory) |
|
246 { |
|
247 LOG_("-> CVpnPolicyInstaller::InstallPinPolicy()"); |
|
248 |
|
249 User::LeaveIfError(iVpnServ.Connect()); |
|
250 |
|
251 iVpnServ.ImportPolicy(aFileDirectory, iStatus); |
|
252 iOngoingTask = ETaskImportPinPolicies; |
|
253 SetActive(); |
|
254 LOG_("<- CVpnPolicyInstaller::InstallPinPolicy()"); |
|
255 } |
|
256 |
|
257 |
|
258 void CVpnPolicyInstaller::DeflateZippedPolicyL() |
|
259 { |
|
260 LOG_("-> CVpnPolicyInstaller::DeflateZippedPolicyL()"); |
|
261 |
|
262 LOG_(" Showing wait note"); |
|
263 ShowWaitNoteL(TVpnDialog::EGenericProgress); |
|
264 |
|
265 __ASSERT_ALWAYS(!iDecompressor, User::Invariant()); |
|
266 |
|
267 iOngoingTask = ETaskImportZippedPolicies; |
|
268 |
|
269 iDriveAndPath = KTempDirectory().AllocL(); |
|
270 iOngoingTask = ETaskImportZippedPolicies; |
|
271 |
|
272 //Makes sure the temp dir is empty |
|
273 if (BaflUtils::FolderExists(iFileServer, KTempDirectory)) |
|
274 { |
|
275 EmtpyTempDirL(); |
|
276 } |
|
277 |
|
278 iDecompressor = CZipFileDecompressor::NewL(); |
|
279 |
|
280 RFile file; |
|
281 iCommandLine->GetFileByHandleL(file); |
|
282 |
|
283 if (file.SubSessionHandle()) |
|
284 { |
|
285 iDecompressor->DecompressZipFile(file, KTempDirectory, iStatus); |
|
286 } |
|
287 else |
|
288 { |
|
289 iDecompressor->DecompressZipFile(iCommandLine->DocumentName(), KTempDirectory, iStatus); |
|
290 } |
|
291 SetActive(); |
|
292 |
|
293 LOG_("<- CVpnPolicyInstaller::DeflateZippedPolicyL()"); |
|
294 } |
|
295 |
|
296 void CVpnPolicyInstaller::EmtpyTempDirL() |
|
297 { |
|
298 LOG_("-> CVpnPolicyInstaller::EmtpyTempDirL()"); |
|
299 CDir* dir = NULL; |
|
300 User::LeaveIfError(iFileServer.GetDir(KTempDirectory, KEntryAttNormal, ESortByName, dir)); |
|
301 CleanupStack::PushL(dir); |
|
302 |
|
303 |
|
304 TFileName* fileName = new (ELeave) TFileName; |
|
305 CleanupStack::PushL(fileName); |
|
306 |
|
307 for (TInt i = 0; i < dir->Count(); ++i) |
|
308 { |
|
309 const TEntry& entry = (*dir)[i]; |
|
310 *fileName = KTempDirectory; |
|
311 fileName->Append(entry.iName); |
|
312 User::LeaveIfError(iFileServer.Delete(*fileName)); |
|
313 } |
|
314 |
|
315 CleanupStack::PopAndDestroy(fileName); |
|
316 CleanupStack::PopAndDestroy(dir); |
|
317 LOG_("<- CVpnPolicyInstaller::EmtpyTempDirL()"); |
|
318 } |
|
319 |
|
320 |
|
321 void CVpnPolicyInstaller::DoCancel() |
|
322 { |
|
323 LOG_("-> CVpnPolicyInstaller::DoCancel()"); |
|
324 |
|
325 CancelWaitNote(); |
|
326 |
|
327 switch(iOngoingTask) |
|
328 { |
|
329 case ETaskImportZippedPolicies: |
|
330 LOG_(" case ETaskImportZippedPolicies"); |
|
331 if (iDecompressor) |
|
332 { |
|
333 iDecompressor->Cancel(); |
|
334 delete iDecompressor; |
|
335 iDecompressor = NULL; |
|
336 } |
|
337 break; |
|
338 |
|
339 case ETaskImportPinPolicies: |
|
340 LOG_(" case ETaskImportPinPolicies"); |
|
341 |
|
342 iVpnServ.CancelImport(); |
|
343 |
|
344 delete iDriveAndPath; |
|
345 iDriveAndPath = NULL; |
|
346 break; |
|
347 |
|
348 case ETaskShowImportErrorNote: |
|
349 LOG_(" case ETaskShowImportErrorNote"); |
|
350 LOG_1(" (IMPERR) Terminating dialog, iStatus: %d", iStatus.Int()); |
|
351 iNotifier.CancelNotifier(KUidVpnDialogNotifier); |
|
352 break; |
|
353 |
|
354 default: |
|
355 LOG_(" case default"); |
|
356 User::Invariant(); |
|
357 break; |
|
358 } |
|
359 |
|
360 TRAP_IGNORE(EmtpyTempDirL()); |
|
361 LOG_("<- CVpnPolicyInstaller::DoCancel()"); |
|
362 } |
|
363 |
|
364 TInt CVpnPolicyInstaller::RunError(TInt aError) |
|
365 { |
|
366 LOG_1("-> CVpnPolicyInstaller::RunError() code: %d", aError); |
|
367 |
|
368 CancelWaitNote(); |
|
369 |
|
370 switch(iOngoingTask) |
|
371 { |
|
372 case ETaskImportZippedPolicies: |
|
373 LOG_(" case ETaskImportZippedPolicies"); |
|
374 if (iDecompressor) |
|
375 { |
|
376 LOG_(" Found decompressor, terminating"); |
|
377 iDecompressor->Cancel(); |
|
378 delete iDecompressor; |
|
379 iDecompressor = NULL; |
|
380 } |
|
381 |
|
382 |
|
383 LOG_(" case handled"); |
|
384 break; |
|
385 |
|
386 case ETaskImportPinPolicies: |
|
387 LOG_(" case ETaskImportPinPolicies"); |
|
388 |
|
389 iVpnServ.CancelImport(); |
|
390 |
|
391 delete iDriveAndPath; |
|
392 iDriveAndPath = NULL; |
|
393 break; |
|
394 |
|
395 case ETaskShowImportErrorNote: |
|
396 LOG_(" case ETaskShowImportErrorNote"); |
|
397 LOG_1(" (IMPERR) Terminating dialog, iStatus: %d", iStatus.Int()); |
|
398 iNotifier.CancelNotifier(KUidVpnDialogNotifier); |
|
399 break; |
|
400 |
|
401 default: |
|
402 LOG_(" case default"); |
|
403 User::Invariant(); |
|
404 break; |
|
405 } |
|
406 |
|
407 TRAP_IGNORE(EmtpyTempDirL()); |
|
408 |
|
409 // Show error note unless the operation was cancelled |
|
410 // (in which case we will just exit silently) |
|
411 if (aError != KErrCancel && aError != KErrBadPassphrase) |
|
412 { |
|
413 ShowImportErrorNote(aError); |
|
414 } |
|
415 |
|
416 CActiveScheduler::Stop(); |
|
417 |
|
418 LOG_("<- CVpnPolicyInstaller::RunError()"); |
|
419 return KErrNone; |
|
420 } |
|
421 |
|
422 void CVpnPolicyInstaller::RunL() |
|
423 { |
|
424 |
|
425 LOG_("-> CVpnPolicyInstaller::RunL()"); |
|
426 TInt status = iStatus.Int(); |
|
427 TBool finished(EFalse); |
|
428 |
|
429 switch(iOngoingTask) |
|
430 { |
|
431 case ETaskImportZippedPolicies: |
|
432 LOG_(" Case ETaskImportZippedPolicies"); |
|
433 delete iDecompressor; |
|
434 iDecompressor = NULL; |
|
435 |
|
436 if (status == KErrNone) |
|
437 { |
|
438 LOG_(" Status: KErrNone, continuing installation"); |
|
439 |
|
440 ProcessBundleContentsL(); |
|
441 |
|
442 // Wait note has been cancelled in ProcessBundleContentsL |
|
443 ShowWaitNoteL(); |
|
444 |
|
445 InstallPinPolicyL(*iDriveAndPath); |
|
446 } |
|
447 else |
|
448 { |
|
449 LOG_1(" Status: %d, aborting installation", status); |
|
450 // Installation FAILED |
|
451 // Policy import failed, so show an error note |
|
452 // (asynchronous call, RunL called again on completion) |
|
453 iOngoingTask = ETaskShowImportErrorNote; |
|
454 ShowImportErrorNote(); |
|
455 finished = ETrue; |
|
456 } |
|
457 break; |
|
458 |
|
459 case ETaskImportPinPolicies: |
|
460 LOG_(" Case ETaskImportPinPolicies"); |
|
461 |
|
462 // We're finished, so clean up and terminate |
|
463 TRAP_IGNORE(EmtpyTempDirL()); |
|
464 |
|
465 if (status == KErrNone) |
|
466 { |
|
467 // Finally, only apply devlock settings |
|
468 // if we've come this far without errors |
|
469 TRAP(status, ApplyDevLockSettingsL()); |
|
470 } |
|
471 |
|
472 CancelWaitNote(); |
|
473 |
|
474 delete iDriveAndPath; |
|
475 iDriveAndPath = NULL; |
|
476 |
|
477 LOG_1(" Status: %d", status); |
|
478 if (status == KErrNone) |
|
479 { |
|
480 // Everything went OK. Show completion note and finish. |
|
481 |
|
482 LOG_(" Completing"); |
|
483 iOngoingTask = ETaskNone; |
|
484 |
|
485 TVpnDialogInfo dialogInfo(TNoteDialog::EInfo, |
|
486 TVpnNoteDialog::EVpnPolicyInstalled); |
|
487 iDialogInfoDes() = dialogInfo; |
|
488 |
|
489 LOG_(" Starting 'finished' dialog"); |
|
490 |
|
491 iNotifier.StartNotifierAndGetResponse(iStatus, |
|
492 KUidVpnDialogNotifier, |
|
493 iDialogInfoDes, |
|
494 iDialogResponseDes); |
|
495 User::WaitForRequest(iStatus); |
|
496 |
|
497 |
|
498 LOG_(" Request complete, terminating"); |
|
499 |
|
500 // We're done, so cancel the completion note, and terminate |
|
501 iNotifier.CancelNotifier(KUidVpnDialogNotifier); |
|
502 finished = ETrue; |
|
503 } |
|
504 else if (status != KErrCancel) |
|
505 { |
|
506 // Policy import failed, so show an error note |
|
507 // and terminate |
|
508 LOG_(" Installation failed, showing import error note"); |
|
509 iOngoingTask = ETaskShowImportErrorNote; |
|
510 ShowImportErrorNote(); |
|
511 finished = ETrue; |
|
512 } |
|
513 else |
|
514 { |
|
515 LOG_(" Installation was cancelled, silent exit"); |
|
516 finished = ETrue; |
|
517 } |
|
518 break; |
|
519 |
|
520 case ETaskShowImportErrorNote: |
|
521 LOG_(" Case ETaskShowImportErrorNote"); |
|
522 |
|
523 // Cancel |
|
524 LOG_1(" (imperr) Terminating dialog, status: %d", status); |
|
525 iNotifier.CancelNotifier(KUidVpnDialogNotifier); |
|
526 iOngoingTask = ETaskNone; |
|
527 |
|
528 // We're done, so terminate |
|
529 finished = ETrue; |
|
530 break; |
|
531 |
|
532 default: |
|
533 LOG_(" Case default"); |
|
534 User::Invariant(); |
|
535 } |
|
536 |
|
537 if (finished) |
|
538 { |
|
539 LOG_(" Shutting down active scheduler, all tasks finished"); |
|
540 CActiveScheduler::Stop(); |
|
541 } |
|
542 |
|
543 LOG_("<- CVpnPolicyInstaller::RunL()"); |
|
544 } |
|
545 |
|
546 void CVpnPolicyInstaller::ShowImportErrorNote(const TInt aReason) |
|
547 { |
|
548 LOG_("-> CVpnPolicyInstaller::ShowImportErrorNote()"); |
|
549 |
|
550 |
|
551 TInt reasonCode(TVpnNoteDialog::EPolicyInstallationFailed); |
|
552 |
|
553 // Check if we can display a more specific error note |
|
554 if (aReason == KErrAccessDenied) |
|
555 { |
|
556 reasonCode = TVpnNoteDialog::EVpnCannotForceDeviceLock; |
|
557 } |
|
558 |
|
559 TVpnDialogInfo dialogInfo(TNoteDialog::EInfo, reasonCode); |
|
560 iDialogInfoDes() = dialogInfo; |
|
561 |
|
562 TRequestStatus status; |
|
563 |
|
564 iNotifier.StartNotifierAndGetResponse(status, KUidVpnDialogNotifier, |
|
565 iDialogInfoDes, iDialogResponseDes); |
|
566 |
|
567 // Wait until error note completes |
|
568 User::WaitForRequest(status); |
|
569 iNotifier.CancelNotifier(KUidVpnDialogNotifier); |
|
570 |
|
571 LOG_("<- CVpnPolicyInstaller::ShowImportErrorNote()"); |
|
572 } |
|
573 |
|
574 TBool CVpnPolicyInstaller::ShowDevLockConfirmNote() |
|
575 { |
|
576 LOG_("-> CVpnPolicyInstaller::ShowDevLockConfirmNote()"); |
|
577 TBool ret(EFalse); |
|
578 TRequestStatus status; |
|
579 |
|
580 TVpnDialogInfo dialogInfo(TVpnDialog::EDeviceLockConfirmation, 0, *iFileName); |
|
581 |
|
582 dialogInfo.SetExtraInput(*iFileName); |
|
583 |
|
584 iDialogInfoDes() = dialogInfo; |
|
585 |
|
586 iNotifier.StartNotifierAndGetResponse(status, KUidVpnDialogNotifier, |
|
587 iDialogInfoDes, iDialogResponseDes); |
|
588 |
|
589 // Wait until error note completes |
|
590 User::WaitForRequest(status); |
|
591 |
|
592 if (status != KErrCancel) |
|
593 { |
|
594 ret = ETrue; |
|
595 } |
|
596 |
|
597 LOG_1("<- CVpnPolicyInstaller::ShowDevLockConfirmNote() ret: %d", ret); |
|
598 return ret; |
|
599 } |
|
600 |
|
601 TBool CVpnPolicyInstaller::ShowConfirmNote() |
|
602 { |
|
603 LOG_("-> CVpnPolicyInstaller::ShowConfirmNoteL()"); |
|
604 |
|
605 TBool ret(EFalse); |
|
606 TRequestStatus status; |
|
607 |
|
608 TVpnDialogInfo dialogInfo(TVpnDialog::EPolicyInstallConfirmation, 0, *iFileName); |
|
609 |
|
610 dialogInfo.SetExtraInput(*iFileName); |
|
611 |
|
612 iDialogInfoDes() = dialogInfo; |
|
613 |
|
614 iNotifier.StartNotifierAndGetResponse(status, KUidVpnDialogNotifier, |
|
615 iDialogInfoDes, iDialogResponseDes); |
|
616 |
|
617 // Wait until error note completes |
|
618 User::WaitForRequest(status); |
|
619 |
|
620 if (status != KErrCancel) |
|
621 { |
|
622 ret = ETrue; |
|
623 } |
|
624 |
|
625 LOG_1("<- CVpnPolicyInstaller::ShowConfirmNoteL(), ret: %d", ret); |
|
626 return ret; |
|
627 } |
|
628 |
|
629 void CVpnPolicyInstaller::ShowWaitNoteL(TInt aNoteId) |
|
630 { |
|
631 |
|
632 LOG_("-> CVpnPolicyInstaller::ShowWaitNoteL()"); |
|
633 |
|
634 iWaitNoteHandler = CImportWaitNoteHandler::NewL(this); |
|
635 |
|
636 iWaitNoteHandler->StartWaitNote(aNoteId); |
|
637 |
|
638 LOG_("<- CVpnPolicyInstaller::ShowWaitNoteL()"); |
|
639 } |
|
640 |
|
641 void CVpnPolicyInstaller::CancelWaitNote() |
|
642 { |
|
643 LOG_("-> CVpnPolicyInstaller::CancelWaitNote()"); |
|
644 if (iWaitNoteHandler) |
|
645 { |
|
646 iWaitNoteHandler->Cancel(); |
|
647 delete iWaitNoteHandler; |
|
648 iWaitNoteHandler = NULL; |
|
649 } |
|
650 LOG_("<- CVpnPolicyInstaller::CancelWaitNote()"); |
|
651 } |
|
652 |
|
653 void CVpnPolicyInstaller::UserCancelledWait() |
|
654 { |
|
655 LOG_("-> CVpnPolicyInstaller::UserCancelledWait()"); |
|
656 |
|
657 DoCancel(); |
|
658 |
|
659 LOG_("<- CVpnPolicyInstaller::UserCancelledWait()"); |
|
660 } |
|
661 |
|
662 |
|
663 |
|
664 |
|
665 ///////////////////////////////////////////////////////////// |
|
666 // Device lock / pkcs#12 installation specific part |
|
667 // of implementation |
|
668 |
|
669 void CVpnPolicyInstaller::ApplyDevLockSettingsL() |
|
670 { |
|
671 // See whether change to devlock settings was requested |
|
672 if (iDevLockPolicy > 0) |
|
673 { |
|
674 // If device supports VPN devlock operations, set the settings |
|
675 // Otherwise it's an error -- unless device lock was |
|
676 // defined "optional" in the VPN command file |
|
677 if (iDevSupportsDevLock) |
|
678 { |
|
679 CVpnDevLockHandler* dlh = CVpnDevLockHandler::NewLC(); |
|
680 |
|
681 dlh->SetTerminalControlPolicyL(iDevLockPolicy); |
|
682 CleanupStack::PopAndDestroy(dlh); |
|
683 } |
|
684 else if (iDevLockRequired) |
|
685 { |
|
686 User::Leave(KErrAccessDenied); |
|
687 } |
|
688 } |
|
689 } |
|
690 void CVpnPolicyInstaller::ProcessBundleContentsL() |
|
691 { |
|
692 LOG_("-> CVpnPolicyInstaller::ProcessBundleContentsL()"); |
|
693 |
|
694 |
|
695 CVpnBundleHandler* bundler = CVpnBundleHandler::NewLC(KTempDirectory); |
|
696 |
|
697 bundler->AnalyzeBundleContentsL(); |
|
698 |
|
699 if (bundler->CommandFileExists()) |
|
700 { |
|
701 LOG_(" Bundle command file exists"); |
|
702 HBufC8* cmdXml = bundler->ExtractCommandFileDataL(); |
|
703 CleanupStack::PushL(cmdXml); |
|
704 |
|
705 ExtractCommandParametersL(*cmdXml); |
|
706 |
|
707 CleanupStack::PopAndDestroy(cmdXml); |
|
708 } |
|
709 |
|
710 |
|
711 TBool okToContinue = ConfirmDeviceLockUseL(); |
|
712 |
|
713 if (okToContinue) |
|
714 { |
|
715 // Extract PKCS#12-contained security objects and save them to disk |
|
716 if (bundler->PKCS12FileExists()) |
|
717 { |
|
718 LOG_(" Bundle P12 file exists"); |
|
719 HBufC8* pkcs12 = bundler->ExtractPKCS12DataL(); |
|
720 CleanupStack::PushL(pkcs12); |
|
721 |
|
722 if (iP12Password) |
|
723 { |
|
724 ExtractPKCS12ObjectsL(*pkcs12, *iP12Password); |
|
725 } |
|
726 else |
|
727 { |
|
728 ExtractPKCS12ObjectsL(*pkcs12, KNullDesC); |
|
729 } |
|
730 |
|
731 CleanupStack::PopAndDestroy(pkcs12); |
|
732 } |
|
733 } |
|
734 else |
|
735 { |
|
736 LOG_(" User cancelled device lock install, halting import"); |
|
737 User::Leave(KErrCancel); |
|
738 } |
|
739 |
|
740 CleanupStack::PopAndDestroy(bundler); |
|
741 |
|
742 LOG_("<- CVpnPolicyInstaller::ProcessBundleContentsL()"); |
|
743 } |
|
744 |
|
745 void CVpnPolicyInstaller::ExtractPKCS12ObjectsL(const TDesC8& aData, const TDesC& aPwd) |
|
746 { |
|
747 LOG_("-> CVpnPolicyInstaller::ExtractPKCS12ObjectsL()"); |
|
748 CPKCS12Handler* p12handler = CPKCS12Handler::NewLC(); |
|
749 p12handler->SaveSecurityObjectsToDiskL(aData, aPwd, KTempDirectory); |
|
750 CleanupStack::PopAndDestroy(p12handler); |
|
751 LOG_("<- CVpnPolicyInstaller::ExtractPKCS12ObjectsL()"); |
|
752 } |
|
753 |
|
754 void CVpnPolicyInstaller::ExtractCommandParametersL(const TDesC8& aData) |
|
755 { |
|
756 LOG_("-> CVpnPolicyInstaller::ExtractCommandParametersL()"); |
|
757 |
|
758 CCmdFileParser* parser = new (ELeave) CCmdFileParser(); |
|
759 CleanupStack::PushL(parser); |
|
760 |
|
761 parser->ParseL(aData); |
|
762 |
|
763 #ifdef ATS_BUILD |
|
764 delete iP12Password; iP12Password = NULL; |
|
765 #endif |
|
766 |
|
767 iP12Password = parser->GetParsedValueStrL(KCmdPKCS12PasswordUri); |
|
768 parser->GetParsedValueIntL(KCmdDevlockPolicyUri, iDevLockPolicy); |
|
769 parser->GetParsedValueBoolL(KCmdDevlockRequiredUri, iDevLockRequired); |
|
770 |
|
771 if (iP12Password) |
|
772 { |
|
773 LOG_1(" PASSWORD: '%S'", iP12Password); |
|
774 } |
|
775 |
|
776 LOG_1(" Requested devlock policy: %d", iDevLockPolicy); |
|
777 LOG_1(" Devlock mandatory: %d", iDevLockRequired); |
|
778 LOG_(" Popping from stack"); |
|
779 |
|
780 CleanupStack::PopAndDestroy(parser); |
|
781 |
|
782 LOG_("<- CVpnPolicyInstaller::ExtractCommandParametersL()"); |
|
783 } |
|
784 |
|
785 TInt CVpnPolicyInstaller::IsDeviceLockAvailable() |
|
786 { |
|
787 LOG_("-> CVpnPolicyInstaller::IsDeviceLockAvailableL()"); |
|
788 TInt status(KErrNone); |
|
789 |
|
790 CVpnDevLockHandler* dlh = CVpnDevLockHandler::NewLC(); |
|
791 |
|
792 TRAP(status, dlh->TerminalControlSupportsVpnL()); |
|
793 if (status == KErrNone) |
|
794 { |
|
795 iDevSupportsDevLock = ETrue; |
|
796 } |
|
797 else |
|
798 { |
|
799 iDevSupportsDevLock = EFalse; |
|
800 } |
|
801 |
|
802 CleanupStack::PopAndDestroy(dlh); |
|
803 |
|
804 LOG_1("<- CVpnPolicyInstaller::IsDeviceLockAvailableL() ret: %d", status); |
|
805 return status; |
|
806 } |
|
807 |
|
808 TBool CVpnPolicyInstaller::ConfirmDeviceLockUseL() |
|
809 { |
|
810 TBool ret(EFalse); |
|
811 |
|
812 // If device lock was requested, check whether we can use it |
|
813 if (iDevLockPolicy > 0) |
|
814 { |
|
815 TInt dlError = IsDeviceLockAvailable(); |
|
816 LOG_1(" Device lock status: %d", dlError); |
|
817 |
|
818 if (dlError != KErrNone) |
|
819 { |
|
820 // We might still be able to continue, |
|
821 // depending on whether device lock configuration |
|
822 // is mandatory (or just optional). |
|
823 // Mandatory status is defined in the vpn cmd file. |
|
824 if (dlError != KErrAccessDenied) |
|
825 { |
|
826 User::Leave(dlError); |
|
827 } |
|
828 |
|
829 if (iDevLockRequired) |
|
830 { |
|
831 LOG_1("<- CVpnPolicyInstaller::ProcessBundleContentsL() LEAVE: %d", |
|
832 dlError); |
|
833 User::Leave(dlError); |
|
834 } |
|
835 else |
|
836 { |
|
837 CancelWaitNote(); |
|
838 LOG_(" Couldn't set device lock, but it's not mandatory. Proceeding"); |
|
839 ret = ShowConfirmNote(); |
|
840 } |
|
841 } |
|
842 else |
|
843 { |
|
844 CancelWaitNote(); |
|
845 LOG_(" Showing device lock confirmation note"); |
|
846 ret = ShowDevLockConfirmNote(); |
|
847 } |
|
848 } |
|
849 else |
|
850 { |
|
851 CancelWaitNote(); |
|
852 LOG_(" No changes required to device lock"); |
|
853 #ifdef ATS_BUILD |
|
854 ret = ETrue; |
|
855 #else |
|
856 ret = ShowConfirmNote(); |
|
857 #endif |
|
858 } |
|
859 return ret; |
|
860 } |
|
861 |
|
862 |
|
863 |
|
864 //////////////////////////////////////////////////////////////// |
|
865 // WaitNoteHandler class implementation |
|
866 |
|
867 CImportWaitNoteHandler::CImportWaitNoteHandler(CVpnPolicyInstaller* aCallBack) : |
|
868 CActive(EPriorityStandard), iCallBack(aCallBack) |
|
869 { |
|
870 LOG_("-> CImportWaitNoteHandler::CImportWaitNoteHandler()"); |
|
871 CActiveScheduler::Add(this); |
|
872 LOG_("-> CImportWaitNoteHandler::CImportWaitNoteHandler()"); |
|
873 } |
|
874 |
|
875 CImportWaitNoteHandler::~CImportWaitNoteHandler() |
|
876 { |
|
877 LOG_("-> CImportWaitNoteHandler::~CImportWaitNoteHandler()"); |
|
878 Cancel(); |
|
879 LOG_("<- CImportWaitNoteHandler::~CImportWaitNoteHandler()"); |
|
880 } |
|
881 |
|
882 void CImportWaitNoteHandler::DoCancel() |
|
883 { |
|
884 LOG_("-> CImportWaitNoteHandler::DoCancel()"); |
|
885 |
|
886 iNotifier.CancelNotifier(KUidVpnDialogNotifier); |
|
887 iNotifier.Close(); |
|
888 |
|
889 LOG_("<- CImportWaitNoteHandler::DoCancel()"); |
|
890 } |
|
891 |
|
892 void CImportWaitNoteHandler::ConstructL() |
|
893 { |
|
894 User::LeaveIfError(iNotifier.Connect()); |
|
895 } |
|
896 |
|
897 // Codescanner complains about non-leaving L function. |
|
898 // Sadly, there's little we can do... |
|
899 void CImportWaitNoteHandler::RunL() |
|
900 { |
|
901 LOG_("-> CImportWaitNoteHandler::RunL()"); |
|
902 TInt status = iStatus.Int(); |
|
903 LOG_1(" Status: %d", status); |
|
904 if (status == KErrCancel) |
|
905 { |
|
906 LOG_(" CANCEL"); |
|
907 iCallBack->UserCancelledWait(); |
|
908 } |
|
909 |
|
910 LOG_("<- CImportWaitNoteHandler::RunL()"); |
|
911 } |
|
912 |
|
913 TInt CImportWaitNoteHandler::RunError(TInt aError) |
|
914 { |
|
915 LOG_1("-> CImportWaitNoteHandler::RunError() %d", aError); |
|
916 Cancel(); |
|
917 LOG_("<- CImportWaitNoteHandler::RunError()"); |
|
918 |
|
919 // Remove compiler warning in urel case |
|
920 aError = aError; |
|
921 |
|
922 return KErrNone; |
|
923 } |
|
924 |
|
925 void CImportWaitNoteHandler::StartWaitNote(TInt aNoteId) |
|
926 { |
|
927 LOG_("-> CImportWaitNoteHandler::StartWaitNote()"); |
|
928 |
|
929 TVpnDialogInfo dialogInfo(aNoteId, 0); |
|
930 iDialogInfoDes() = dialogInfo; |
|
931 |
|
932 iNotifier.StartNotifierAndGetResponse(iStatus, KUidVpnDialogNotifier, |
|
933 iDialogInfoDes, iDialogResponseDes); |
|
934 |
|
935 SetActive(); |
|
936 LOG_("<- CImportWaitNoteHandler::StartWaitNote()"); |
|
937 } |
|
938 |
|
939 CImportWaitNoteHandler* CImportWaitNoteHandler::NewL(CVpnPolicyInstaller* aCallBack) |
|
940 { |
|
941 CImportWaitNoteHandler* self = new (ELeave) CImportWaitNoteHandler(aCallBack); |
|
942 CleanupStack::PushL(self); |
|
943 self->ConstructL(); |
|
944 CleanupStack::Pop(self); |
|
945 return self; |
|
946 } |
|
947 |
|
948 |
|
949 |