|
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 300 |
|
23 #undef EAP_FILE_NUMBER_DATE |
|
24 #define EAP_FILE_NUMBER_DATE 1127594498 |
|
25 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES) |
|
26 |
|
27 #include <e32base.h> |
|
28 #include "EapMsChapV2DbUtils.h" |
|
29 #include "EapMsChapV2DbParameterNames.h" |
|
30 #include "EapMsChapV2DbDefaults.h" |
|
31 #include <EapMsChapV2UiConnection.h> |
|
32 #include <EapMsChapV2UiDataConnection.h> |
|
33 #include <EapMsChapV2UiMsChapV2Data.h> |
|
34 #include "eap_am_trace_symbian.h" |
|
35 |
|
36 const TUint KMaxSqlQueryLength = 256; |
|
37 |
|
38 |
|
39 CEapMsChapV2UiDataConnection::CEapMsChapV2UiDataConnection(CEapMsChapV2UiConnection * aUiConn) |
|
40 : iIsOpened(EFalse) |
|
41 , iUiConn(aUiConn) |
|
42 , iColSet(NULL) |
|
43 , iDataPtr(NULL) |
|
44 { |
|
45 } |
|
46 |
|
47 |
|
48 CEapMsChapV2UiDataConnection::~CEapMsChapV2UiDataConnection() |
|
49 { |
|
50 if (iUiConn) |
|
51 { |
|
52 Close(); |
|
53 iUiConn = NULL; |
|
54 } |
|
55 } |
|
56 |
|
57 |
|
58 TInt CEapMsChapV2UiDataConnection::Open() |
|
59 { |
|
60 if (iIsOpened) |
|
61 { |
|
62 return KErrAlreadyExists; |
|
63 } |
|
64 |
|
65 TInt err = iUiConn->GetDatabase(iDatabase); |
|
66 if (err != KErrNone) |
|
67 { |
|
68 return err; |
|
69 } |
|
70 |
|
71 iIsOpened = ETrue; |
|
72 return KErrNone; |
|
73 } |
|
74 |
|
75 |
|
76 TInt CEapMsChapV2UiDataConnection::GetData(CEapMsChapV2UiMsChapV2Data ** aDataPtr) |
|
77 { |
|
78 if (aDataPtr == NULL) |
|
79 { |
|
80 return KErrArgument; |
|
81 } |
|
82 if (iIsOpened == EFalse) |
|
83 { |
|
84 return KErrSessionClosed; |
|
85 } |
|
86 iDataPtr = new CEapMsChapV2UiMsChapV2Data(); |
|
87 if (!iDataPtr) |
|
88 { |
|
89 return KErrNoMemory; |
|
90 } |
|
91 |
|
92 TRAPD(err, FetchDataL()); |
|
93 if (err != KErrNone) |
|
94 { |
|
95 delete iDataPtr; |
|
96 iDataPtr = NULL; |
|
97 |
|
98 delete iColSet; |
|
99 iColSet = NULL; |
|
100 |
|
101 iView.Close(); |
|
102 |
|
103 return err; |
|
104 } |
|
105 |
|
106 *aDataPtr = iDataPtr; |
|
107 |
|
108 return KErrNone; |
|
109 } |
|
110 |
|
111 |
|
112 TInt CEapMsChapV2UiDataConnection::Update() |
|
113 { |
|
114 TRAPD(err, iView.UpdateL()); |
|
115 if (err != KErrNone) |
|
116 { |
|
117 return err; |
|
118 } |
|
119 |
|
120 // Validate the length of username and password. |
|
121 if(iDataPtr->GetUsername().Length() > KMaxUsernameLengthInDB |
|
122 || iDataPtr->GetPassword().Length() > KMaxPasswordLengthInDB) |
|
123 { |
|
124 // Username or password too long. Can not be stored in DB. |
|
125 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapMsChapV2UiDataConnection::Update: Too long username or password. Length: UN=%d, PW=%d\n"), |
|
126 iDataPtr->GetUsername().Length(), |
|
127 iDataPtr->GetPassword().Length())); |
|
128 |
|
129 return KErrArgument; |
|
130 } |
|
131 |
|
132 TRAP(err, iView.SetColL(iColSet->ColNo(cf_str_EAP_MSCHAPV2_username_literal), iDataPtr->GetUsername())); |
|
133 if (err != KErrNone) |
|
134 { |
|
135 return err; |
|
136 } |
|
137 |
|
138 TRAP(err, iView.SetColL(iColSet->ColNo(cf_str_EAP_MSCHAPV2_password_literal), iDataPtr->GetPassword())); |
|
139 if (err != KErrNone) |
|
140 { |
|
141 return err; |
|
142 } |
|
143 |
|
144 if (*(iDataPtr->GetPasswordPrompt())) |
|
145 { |
|
146 TRAP(err, iView.SetColL(iColSet->ColNo(cf_str_EAP_MSCHAPV2_password_prompt_literal), EMSCHAPV2PasswordPromptOn)); |
|
147 if (err != KErrNone) |
|
148 { |
|
149 return err; |
|
150 } |
|
151 } |
|
152 else |
|
153 { |
|
154 TRAP(err, iView.SetColL(iColSet->ColNo(cf_str_EAP_MSCHAPV2_password_prompt_literal), EMSCHAPV2PasswordPromptOff)); |
|
155 if (err != KErrNone) |
|
156 { |
|
157 return err; |
|
158 } |
|
159 } |
|
160 |
|
161 // Last full authentication time should be made zero when EAP configurations are modified. |
|
162 // This makes sure that the next authentication with this EAP would be full authentication |
|
163 // instead of reauthentication even if the session is still valid. |
|
164 |
|
165 TRAP(err, iView.SetColL(iColSet->ColNo(KMSCHAPv2LastFullAuthTime), default_FullAuthTime)); |
|
166 if (err != KErrNone) |
|
167 { |
|
168 return err; |
|
169 } |
|
170 |
|
171 EAP_TRACE_DEBUG_SYMBIAN((_L("Session Validity: EAP-Type=MSCHAPv2 (or plain), Resetting Full Auth Time since settings are modified\n"))); |
|
172 |
|
173 TRAP(err, iView.PutL()); |
|
174 |
|
175 return err; |
|
176 } |
|
177 |
|
178 |
|
179 TInt CEapMsChapV2UiDataConnection::Close() |
|
180 { |
|
181 if (iIsOpened == EFalse) |
|
182 { |
|
183 return KErrNone; |
|
184 } |
|
185 |
|
186 delete iDataPtr; |
|
187 iDataPtr = NULL; |
|
188 |
|
189 delete iColSet; |
|
190 iColSet = NULL; |
|
191 |
|
192 iView.Close(); |
|
193 |
|
194 iUiConn = NULL; |
|
195 |
|
196 return KErrNone; |
|
197 } |
|
198 |
|
199 |
|
200 void CEapMsChapV2UiDataConnection::FetchDataL() |
|
201 { |
|
202 HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength); |
|
203 TPtr sqlStatement = buf->Des(); |
|
204 |
|
205 // Form the query. Query everything. |
|
206 _LIT(KSQLQuery, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d"); |
|
207 sqlStatement.Format(KSQLQuery, |
|
208 &KMsChapV2TableName, |
|
209 &KServiceType, |
|
210 iUiConn->GetIndexType(), |
|
211 &KServiceIndex, |
|
212 iUiConn->GetIndex(), |
|
213 &KTunnelingType, |
|
214 iUiConn->GetTunnelingType()); |
|
215 // Evaluate view |
|
216 User::LeaveIfError(iView.Prepare(iDatabase, TDbQuery(sqlStatement))); |
|
217 User::LeaveIfError(iView.EvaluateAll()); |
|
218 |
|
219 // Get the first (and only) row |
|
220 iView.FirstL(); |
|
221 iView.GetL(); |
|
222 |
|
223 // Get column set so we get the correct column numbers |
|
224 delete iColSet; |
|
225 iColSet = NULL; |
|
226 iColSet = iView.ColSetL(); |
|
227 |
|
228 // Start fetching the values |
|
229 |
|
230 // Prompt password |
|
231 TUint intValue = iView.ColUint(iColSet->ColNo(cf_str_EAP_MSCHAPV2_password_prompt_literal)); |
|
232 if (intValue == 0) |
|
233 { |
|
234 *(iDataPtr->GetPasswordPrompt()) = EFalse; |
|
235 } |
|
236 else |
|
237 { |
|
238 *(iDataPtr->GetPasswordPrompt()) = ETrue; |
|
239 } |
|
240 |
|
241 // username |
|
242 iDataPtr->GetUsername().Copy(iView.ColDes16(iColSet->ColNo(cf_str_EAP_MSCHAPV2_username_literal))); |
|
243 |
|
244 // password |
|
245 iDataPtr->GetPassword().Copy(iView.ColDes16(iColSet->ColNo(cf_str_EAP_MSCHAPV2_password_literal))); |
|
246 |
|
247 CleanupStack::PopAndDestroy(buf); |
|
248 } |
|
249 |
|
250 // End of file |