|
1 /* |
|
2 * Copyright (c) 2001-2006 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 the License "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: EAP and WLAN authentication protocols. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // This is enumeration of EAPOL source code. |
|
20 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES) |
|
21 #undef EAP_FILE_NUMBER_ENUM |
|
22 #define EAP_FILE_NUMBER_ENUM 337 |
|
23 #undef EAP_FILE_NUMBER_DATE |
|
24 #define EAP_FILE_NUMBER_DATE 1127594498 |
|
25 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES) |
|
26 |
|
27 |
|
28 // INCLUDE FILES |
|
29 |
|
30 #include "EapGtcDbUtils.h" |
|
31 #include "EapGtcDbDefaults.h" |
|
32 #include "EapGtcDbParameterNames.h" |
|
33 #include "EapSecurIDDbParameterNames.h" |
|
34 |
|
35 #include "eap_am_trace_symbian.h" |
|
36 |
|
37 const TUint KMaxSqlQueryLength = 512; |
|
38 const TInt KMicroSecsInAMinute = 60000000; // 60000000 micro seconds is 1 minute. |
|
39 |
|
40 // ================= MEMBER FUNCTIONS ======================= |
|
41 |
|
42 void EapGtcDbUtils::OpenDatabaseL(RDbNamedDatabase& aDatabase, RDbs& aSession, const TIndexType aIndexType, |
|
43 const TInt aIndex, const eap_type_value_e aTunnelingType) |
|
44 { |
|
45 #ifdef USE_EAP_EXPANDED_TYPES |
|
46 |
|
47 TUint aTunnelingVendorType = aTunnelingType.get_vendor_type(); |
|
48 |
|
49 #else |
|
50 |
|
51 TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType); |
|
52 |
|
53 #endif //#ifdef USE_EAP_EXPANDED_TYPES |
|
54 |
|
55 EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL -Start- aIndexType=%d, aIndex=%d, aTunnelingVendorType=%d \n"), |
|
56 aIndexType,aIndex,aTunnelingVendorType) ); |
|
57 |
|
58 // 1. Open/create a database |
|
59 |
|
60 // Connect to the DBMS server. |
|
61 User::LeaveIfError(aSession.Connect()); |
|
62 CleanupClosePushL(aSession); |
|
63 // aSession and aDatabase are pushed to the cleanup stack even though they may be member |
|
64 // variables of the calling class and would be closed in the destructor anyway. This ensures |
|
65 // that if they are not member variables they will be closed. Closing the handle twice |
|
66 // does no harm. |
|
67 |
|
68 #ifdef SYMBIAN_SECURE_DBMS |
|
69 |
|
70 // Create the secure shared database with the specified secure policy. |
|
71 // Database will be created in the data caging path for DBMS (C:\private\100012a5). |
|
72 |
|
73 TInt err = aDatabase.Create(aSession, KGtcDatabaseName, KGtcSecureUIDFormat); |
|
74 |
|
75 EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL - Created Secure DB for eapgtc.dat. err=%d\n"), err)); |
|
76 |
|
77 |
|
78 if(err == KErrNone) |
|
79 { |
|
80 aDatabase.Close(); |
|
81 |
|
82 } else if (err != KErrAlreadyExists) |
|
83 { |
|
84 User::LeaveIfError(err); |
|
85 } |
|
86 |
|
87 User::LeaveIfError(aDatabase.Open(aSession, KGtcDatabaseName, KGtcSecureUIDFormat)); |
|
88 CleanupClosePushL(aDatabase); |
|
89 |
|
90 #else |
|
91 // For non-secured database. The database will be created in the old location (c:\system\data). |
|
92 |
|
93 RFs fsSession; |
|
94 User::LeaveIfError(fsSession.Connect()); |
|
95 CleanupClosePushL(fsSession); |
|
96 TInt err = aDatabase.Create(fsSession, KGtcDatabaseName); |
|
97 |
|
98 EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL - Created Non-Secure DB for eapgtc.dat. err=%d\n"), err)); |
|
99 |
|
100 |
|
101 if(err == KErrNone) |
|
102 { |
|
103 aDatabase.Close(); |
|
104 |
|
105 } else if (err != KErrAlreadyExists) |
|
106 { |
|
107 User::LeaveIfError(err); |
|
108 } |
|
109 CleanupStack::PopAndDestroy(); // close fsSession |
|
110 |
|
111 User::LeaveIfError(aDatabase.Open(aSession, KGtcDatabaseName)); |
|
112 CleanupClosePushL(aDatabase); |
|
113 |
|
114 #endif // #ifdef SYMBIAN_SECURE_DBMS |
|
115 |
|
116 // 2. Create the eap-securid table to database (ignore error if exists) |
|
117 |
|
118 // Table columns: |
|
119 //// NAME ///////////////////////////////////////////////// TYPE ////////////// Constant ///////// |
|
120 //| ServiceType | UNSIGNED INTEGER | KServiceType |// |
|
121 //| ServiceIndex | UNSIGNED INTEGER | KServiceIndex |// |
|
122 //| TunnelingType | UNSIGNED INTEGER | KTunnelingType |// |
|
123 //| EAP_GTC_identity | VARCHAR(255) | cf_str_EAP_GTC_identity_literal |// |
|
124 //| EAP_GTC_max_session_validity_time | BIGINT | cf_str_EAP_GTC_max_session_validity_time_literal |// |
|
125 //| EAP_GTC_last_full_authentication_time | BIGINT | KGTCLastFullAuthTime |// |
|
126 ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
127 |
|
128 HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength); |
|
129 TPtr sqlStatement = buf->Des(); |
|
130 |
|
131 _LIT(KSQLCreateTable1, "CREATE TABLE %S (%S UNSIGNED INTEGER, \ |
|
132 %S UNSIGNED INTEGER, \ |
|
133 %S UNSIGNED INTEGER, \ |
|
134 %S VARCHAR(255), \ |
|
135 %S BIGINT, \ |
|
136 %S BIGINT)"); |
|
137 |
|
138 sqlStatement.Format(KSQLCreateTable1, |
|
139 &KGtcTableName, |
|
140 &KServiceType, |
|
141 &KServiceIndex, |
|
142 &KTunnelingType, |
|
143 &cf_str_EAP_GTC_identity_literal, |
|
144 &cf_str_EAP_GTC_max_session_validity_time_literal, |
|
145 &KGTCLastFullAuthTime); |
|
146 |
|
147 err = aDatabase.Execute(sqlStatement); |
|
148 if (err != KErrNone && err != KErrAlreadyExists) |
|
149 { |
|
150 User::Leave(err); |
|
151 } |
|
152 |
|
153 // 4. Check if database table contains a row for this service type and id |
|
154 |
|
155 _LIT(KSQLQueryRow, "SELECT %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d"); |
|
156 sqlStatement.Format(KSQLQueryRow, &cf_str_EAP_GTC_identity_literal, &KGtcTableName, |
|
157 &KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType); |
|
158 |
|
159 RDbView view; |
|
160 User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited)); |
|
161 // View must be closed when no longer needed |
|
162 CleanupClosePushL(view); |
|
163 User::LeaveIfError(view.EvaluateAll()); |
|
164 |
|
165 // 5. If row is not found then add it |
|
166 |
|
167 TInt rows = view.CountL(); |
|
168 CleanupStack::PopAndDestroy(); // view |
|
169 if (rows == 0) |
|
170 { |
|
171 _LIT(KSQLInsert, "SELECT * FROM %S"); |
|
172 sqlStatement.Format(KSQLInsert, &KGtcTableName); |
|
173 |
|
174 view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited, RDbView::EInsertOnly); |
|
175 CleanupClosePushL(view); |
|
176 |
|
177 // Get column set so we get the correct column numbers |
|
178 CDbColSet* colSet = view.ColSetL(); |
|
179 CleanupStack::PushL(colSet); |
|
180 |
|
181 view.InsertL(); |
|
182 view.SetColL(colSet->ColNo(KServiceType), static_cast<TInt> (aIndexType)); |
|
183 view.SetColL(colSet->ColNo(KServiceIndex), aIndex); |
|
184 view.SetColL(colSet->ColNo(KTunnelingType), aTunnelingVendorType); |
|
185 view.SetColL(colSet->ColNo(cf_str_EAP_GTC_identity_literal), default_EAP_GTC_identity); |
|
186 |
|
187 view.SetColL(colSet->ColNo(cf_str_EAP_GTC_max_session_validity_time_literal), default_MaxSessionTime); |
|
188 |
|
189 view.SetColL(colSet->ColNo(KGTCLastFullAuthTime), default_FullAuthTime); |
|
190 |
|
191 view.PutL(); |
|
192 |
|
193 CleanupStack::PopAndDestroy( colSet ); // Delete colSet. |
|
194 |
|
195 CleanupStack::PopAndDestroy( &view ); // Close view. |
|
196 |
|
197 } |
|
198 |
|
199 CleanupStack::PopAndDestroy( buf ); // Delete buf |
|
200 CleanupStack::Pop( &aDatabase ); |
|
201 CleanupStack::Pop( &aSession ); |
|
202 |
|
203 aDatabase.Compact(); |
|
204 } |
|
205 |
|
206 |
|
207 void EapGtcDbUtils::SetIndexL( |
|
208 RDbNamedDatabase& aDatabase, |
|
209 const TIndexType aIndexType, |
|
210 const TInt aIndex, |
|
211 const eap_type_value_e aTunnelingType, |
|
212 const TIndexType aNewIndexType, |
|
213 const TInt aNewIndex, |
|
214 const eap_type_value_e aNewTunnelingType) |
|
215 { |
|
216 #ifdef USE_EAP_EXPANDED_TYPES |
|
217 |
|
218 TUint aTunnelingVendorType = aTunnelingType.get_vendor_type(); |
|
219 TUint aNewTunnelingVendorType = aNewTunnelingType.get_vendor_type(); |
|
220 |
|
221 #else |
|
222 |
|
223 TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType); |
|
224 TUint aNewTunnelingVendorType = static_cast<TUint>(aNewTunnelingType); |
|
225 |
|
226 #endif //#ifdef USE_EAP_EXPANDED_TYPES |
|
227 |
|
228 HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength); |
|
229 TPtr sqlStatement = buf->Des(); |
|
230 |
|
231 _LIT(KSQL, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d"); |
|
232 |
|
233 sqlStatement.Format(KSQL, &KGtcTableName, |
|
234 &KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType); |
|
235 |
|
236 RDbView view; |
|
237 |
|
238 User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited)); |
|
239 |
|
240 // View must be closed when no longer needed |
|
241 CleanupClosePushL(view); |
|
242 |
|
243 User::LeaveIfError(view.EvaluateAll()); |
|
244 |
|
245 TInt rows = view.CountL(); |
|
246 |
|
247 if (rows == 0) |
|
248 { |
|
249 User::Leave(KErrNotFound); |
|
250 } |
|
251 |
|
252 // Get the first (and only) row |
|
253 view.FirstL(); |
|
254 view.GetL(); |
|
255 |
|
256 // Get column set so we get the correct column numbers |
|
257 CDbColSet* colSet = view.ColSetL(); |
|
258 |
|
259 CleanupStack::PushL(colSet); |
|
260 |
|
261 |
|
262 view.UpdateL(); |
|
263 |
|
264 view.SetColL(colSet->ColNo(KServiceType), static_cast<TUint>(aNewIndexType)); |
|
265 |
|
266 view.SetColL(colSet->ColNo(KServiceIndex), aNewIndex); |
|
267 |
|
268 view.SetColL(colSet->ColNo(KTunnelingType), aNewTunnelingVendorType); |
|
269 |
|
270 view.PutL(); |
|
271 |
|
272 CleanupStack::PopAndDestroy(3); // view, colset, buf |
|
273 } |
|
274 |
|
275 void EapGtcDbUtils::SetConfigurationL( |
|
276 RDbNamedDatabase& aDatabase, |
|
277 const EAPSettings& aSettings, |
|
278 const TIndexType aIndexType, |
|
279 const TInt aIndex, |
|
280 const eap_type_value_e aTunnelingType) |
|
281 { |
|
282 #ifdef USE_EAP_EXPANDED_TYPES |
|
283 |
|
284 TUint aTunnelingVendorType = aTunnelingType.get_vendor_type(); |
|
285 |
|
286 #else |
|
287 |
|
288 TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType); |
|
289 |
|
290 #endif //#ifdef USE_EAP_EXPANDED_TYPES |
|
291 |
|
292 // Check if the settings are for the correct type |
|
293 if (aSettings.iEAPType != EAPSettings::EEapGtc) |
|
294 { |
|
295 User::Leave(KErrNotSupported); |
|
296 } |
|
297 |
|
298 |
|
299 HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength); |
|
300 TPtr sqlStatement = buf->Des(); |
|
301 |
|
302 RDbView view; |
|
303 |
|
304 _LIT(KSQLQuery, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d"); |
|
305 sqlStatement.Format(KSQLQuery, &KGtcTableName, |
|
306 &KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType); |
|
307 |
|
308 // Evaluate view |
|
309 User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement))); |
|
310 |
|
311 CleanupClosePushL(view); |
|
312 |
|
313 User::LeaveIfError(view.EvaluateAll()); |
|
314 |
|
315 view.FirstL(); |
|
316 |
|
317 view.UpdateL(); |
|
318 |
|
319 // Get column set so we get the correct column numbers |
|
320 CDbColSet* colSet = view.ColSetL(); |
|
321 CleanupStack::PushL(colSet); |
|
322 |
|
323 // Username |
|
324 if (aSettings.iUsernamePresent) |
|
325 { |
|
326 // Validate length. |
|
327 if(aSettings.iUsername.Length() > KMaxIdentityLengthInDB) |
|
328 { |
|
329 // Username too long. Can not be stored in DB. |
|
330 |
|
331 EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::SetConfigurationL: Too long Username. Length=%d \n"), |
|
332 aSettings.iUsername.Length())); |
|
333 |
|
334 User::Leave(KErrArgument); |
|
335 } |
|
336 |
|
337 // Length is ok. Set the value in DB. |
|
338 view.SetColL(colSet->ColNo(cf_str_EAP_GTC_identity_literal), aSettings.iUsername); |
|
339 } |
|
340 |
|
341 // Session validity time |
|
342 if (aSettings.iSessionValidityTimePresent) |
|
343 { |
|
344 // User or device management wants to store the session validity time. |
|
345 // Convert the time to micro seconds and save. |
|
346 |
|
347 TInt64 validityInMicro = (aSettings.iSessionValidityTime) * KMicroSecsInAMinute; |
|
348 |
|
349 view.SetColL(colSet->ColNo(cf_str_EAP_GTC_max_session_validity_time_literal), validityInMicro); |
|
350 } |
|
351 |
|
352 // Last full authentication time should be made zero when EAP configurations are modified. |
|
353 // This makes sure that the next authentication with this EAP would be full authentication |
|
354 // instead of reauthentication even if the session is still valid. |
|
355 |
|
356 view.SetColL(colSet->ColNo(KGTCLastFullAuthTime), default_FullAuthTime); |
|
357 |
|
358 EAP_TRACE_DEBUG_SYMBIAN((_L("Session Validity: EAP-Type=%d, Resetting Full Auth Time since settings are modified\n"), |
|
359 aSettings.iEAPType )); |
|
360 |
|
361 view.PutL(); |
|
362 CleanupStack::PopAndDestroy(3); // view, colset, buf |
|
363 |
|
364 } |
|
365 |
|
366 void EapGtcDbUtils::GetConfigurationL( |
|
367 RDbNamedDatabase& aDatabase, |
|
368 EAPSettings& aSettings, |
|
369 const TIndexType aIndexType, |
|
370 const TInt aIndex, |
|
371 const eap_type_value_e aTunnelingType) |
|
372 { |
|
373 #ifdef USE_EAP_EXPANDED_TYPES |
|
374 |
|
375 TUint aTunnelingVendorType = aTunnelingType.get_vendor_type(); |
|
376 |
|
377 #else |
|
378 |
|
379 TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType); |
|
380 |
|
381 #endif //#ifdef USE_EAP_EXPANDED_TYPES |
|
382 |
|
383 HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength); |
|
384 TPtr sqlStatement = buf->Des(); |
|
385 |
|
386 RDbView view; |
|
387 |
|
388 // Form the query |
|
389 _LIT(KSQLQuery, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d"); |
|
390 sqlStatement.Format(KSQLQuery, &KGtcTableName, |
|
391 &KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType); |
|
392 |
|
393 // Evaluate view |
|
394 User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement))); |
|
395 |
|
396 CleanupClosePushL(view); |
|
397 |
|
398 User::LeaveIfError(view.EvaluateAll()); |
|
399 |
|
400 // Get the first (and only) row |
|
401 view.FirstL(); |
|
402 view.GetL(); |
|
403 |
|
404 // Get column set so we get the correct column numbers |
|
405 CDbColSet* colSet = view.ColSetL(); |
|
406 CleanupStack::PushL(colSet); |
|
407 |
|
408 aSettings.iEAPType = EAPSettings::EEapGtc; |
|
409 |
|
410 // Username |
|
411 TPtrC username = view.ColDes(colSet->ColNo(cf_str_EAP_GTC_identity_literal)); |
|
412 aSettings.iUsername.Copy(username); |
|
413 aSettings.iUsernamePresent = ETrue; |
|
414 |
|
415 // Session validity time |
|
416 TInt64 maxSessionTimeMicro = view.ColInt64(colSet->ColNo(cf_str_EAP_GTC_max_session_validity_time_literal)); |
|
417 |
|
418 // Convert the time to minutes. |
|
419 TInt64 maxSessionTimeMin = maxSessionTimeMicro / KMicroSecsInAMinute; |
|
420 |
|
421 aSettings.iSessionValidityTime = static_cast<TUint>(maxSessionTimeMin); |
|
422 aSettings.iSessionValidityTimePresent = ETrue; |
|
423 |
|
424 CleanupStack::PopAndDestroy(3); // view, colset, buf |
|
425 } |
|
426 |
|
427 void EapGtcDbUtils::CopySettingsL( |
|
428 RDbNamedDatabase& aDatabase, |
|
429 const TIndexType aSrcIndexType, |
|
430 const TInt aSrcIndex, |
|
431 const eap_type_value_e aSrcTunnelingType, |
|
432 const TIndexType aDestIndexType, |
|
433 const TInt aDestIndex, |
|
434 const eap_type_value_e aDestTunnelingType) |
|
435 { |
|
436 #ifdef USE_EAP_EXPANDED_TYPES |
|
437 |
|
438 TUint aSrcTunnelingVendorType = aSrcTunnelingType.get_vendor_type(); |
|
439 TUint aDestTunnelingVendorType = aDestTunnelingType.get_vendor_type(); |
|
440 |
|
441 #else |
|
442 |
|
443 TUint aSrcTunnelingVendorType = static_cast<TUint>(aSrcTunnelingType); |
|
444 TUint aDestTunnelingVendorType = static_cast<TUint>(aDestTunnelingType); |
|
445 |
|
446 #endif //#ifdef USE_EAP_EXPANDED_TYPES |
|
447 |
|
448 HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength); |
|
449 TPtr sqlStatement = buf->Des(); |
|
450 |
|
451 _LIT(KSQL, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d"); |
|
452 |
|
453 sqlStatement.Format(KSQL, &KGtcTableName, |
|
454 &KServiceType, aSrcIndexType, &KServiceIndex, aSrcIndex, &KTunnelingType, aSrcTunnelingVendorType); |
|
455 |
|
456 RDbView view; |
|
457 |
|
458 User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited)); |
|
459 |
|
460 // View must be closed when no longer needed |
|
461 CleanupClosePushL(view); |
|
462 |
|
463 User::LeaveIfError(view.EvaluateAll()); |
|
464 |
|
465 TInt rows = view.CountL(); |
|
466 |
|
467 if (rows == 0) |
|
468 { |
|
469 User::Leave(KErrNotFound); |
|
470 } |
|
471 |
|
472 // Get the first (and only) row |
|
473 view.FirstL(); |
|
474 |
|
475 view.GetL(); |
|
476 |
|
477 view.InsertCopyL(); |
|
478 |
|
479 // Get column set so we get the correct column numbers |
|
480 CDbColSet* colSet = view.ColSetL(); |
|
481 |
|
482 CleanupStack::PushL(colSet); |
|
483 |
|
484 view.SetColL(colSet->ColNo(KServiceType), static_cast<TUint>(aDestIndexType)); |
|
485 |
|
486 view.SetColL(colSet->ColNo(KServiceIndex), aDestIndex); |
|
487 |
|
488 view.SetColL(colSet->ColNo(KTunnelingType), aDestTunnelingVendorType); |
|
489 |
|
490 view.PutL(); |
|
491 |
|
492 CleanupStack::PopAndDestroy(3); // view, colset, buf |
|
493 } |
|
494 |
|
495 void EapGtcDbUtils::DeleteConfigurationL( |
|
496 const TIndexType aIndexType, |
|
497 const TInt aIndex, |
|
498 const eap_type_value_e aTunnelingType) |
|
499 { |
|
500 #ifdef USE_EAP_EXPANDED_TYPES |
|
501 |
|
502 TUint aTunnelingVendorType = aTunnelingType.get_vendor_type(); |
|
503 |
|
504 #else |
|
505 |
|
506 TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType); |
|
507 |
|
508 #endif //#ifdef USE_EAP_EXPANDED_TYPES |
|
509 |
|
510 RDbs session; |
|
511 RDbNamedDatabase database; |
|
512 // Connect to the DBMS server. |
|
513 User::LeaveIfError(session.Connect()); |
|
514 CleanupClosePushL(session); |
|
515 |
|
516 #ifdef SYMBIAN_SECURE_DBMS |
|
517 |
|
518 // Create the secure shared database with the specified secure policy. |
|
519 // Database will be created in the data caging path for DBMS (C:\private\100012a5). |
|
520 |
|
521 TInt err = database.Create(session, KGtcDatabaseName, KGtcSecureUIDFormat); |
|
522 |
|
523 if(err == KErrNone) |
|
524 { |
|
525 // Database was created so it was empty. No need for further actions. |
|
526 database.Destroy(); |
|
527 CleanupStack::PopAndDestroy(); |
|
528 return; |
|
529 |
|
530 } |
|
531 else if (err != KErrAlreadyExists) |
|
532 { |
|
533 User::LeaveIfError(err); |
|
534 } |
|
535 |
|
536 // Database existed, open it. |
|
537 User::LeaveIfError(database.Open(session, KGtcDatabaseName, KGtcSecureUIDFormat)); |
|
538 CleanupClosePushL(database); |
|
539 |
|
540 #else |
|
541 // For non-secured database. The database will be created in the old location (c:\system\data). |
|
542 |
|
543 RFs fsSession; |
|
544 User::LeaveIfError(fsSession.Connect()); |
|
545 CleanupClosePushL(fsSession); |
|
546 TInt err = database.Create(fsSession, KGtcDatabaseName); |
|
547 |
|
548 if(err == KErrNone) |
|
549 { |
|
550 // Database was created so it was empty. No need for further actions. |
|
551 database.Destroy(); |
|
552 CleanupStack::PopAndDestroy(2); // fsSession, database session |
|
553 return; |
|
554 |
|
555 } |
|
556 else if (err != KErrAlreadyExists) |
|
557 { |
|
558 User::LeaveIfError(err); |
|
559 } |
|
560 |
|
561 CleanupStack::PopAndDestroy(); // close fsSession |
|
562 |
|
563 User::LeaveIfError(database.Open(session, KGtcDatabaseName)); |
|
564 CleanupClosePushL(database); |
|
565 |
|
566 #endif // #ifdef SYMBIAN_SECURE_DBMS |
|
567 |
|
568 HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength); |
|
569 TPtr sqlStatement = buf->Des(); |
|
570 |
|
571 // Main settings table |
|
572 _LIT(KSQL, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d"); |
|
573 sqlStatement.Format(KSQL, &KGtcTableName, |
|
574 &KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType); |
|
575 // Evaluate view |
|
576 RDbView view; |
|
577 User::LeaveIfError(view.Prepare(database,TDbQuery(sqlStatement), TDbWindow::EUnlimited)); |
|
578 CleanupClosePushL(view); |
|
579 User::LeaveIfError(view.EvaluateAll()); |
|
580 |
|
581 // Delete rows |
|
582 if (view.FirstL()) |
|
583 { |
|
584 do { |
|
585 view.DeleteL(); |
|
586 } while (view.NextL() != EFalse); |
|
587 } |
|
588 |
|
589 // Close database |
|
590 CleanupStack::PopAndDestroy(4); // view, buf, database, session |
|
591 } |
|
592 |
|
593 // End of File |