]>
Commit | Line | Data |
---|---|---|
0c18794e | 1 | /** @file\r |
2 | Password Credential Provider driver implementation.\r | |
b3548d32 LG |
3 | \r |
4 | Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
b59ac35e | 5 | (C) Copyright 2018 Hewlett Packard Enterprise Development LP<BR>\r |
b3548d32 LG |
6 | This program and the accompanying materials\r |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
0c18794e | 9 | http://opensource.org/licenses/bsd-license.php\r |
10 | \r | |
b3548d32 | 11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
0c18794e | 12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "PwdCredentialProvider.h"\r | |
17 | \r | |
18 | CREDENTIAL_TABLE *mPwdTable = NULL;\r | |
19 | PWD_PROVIDER_CALLBACK_INFO *mCallbackInfo = NULL;\r | |
20 | PASSWORD_CREDENTIAL_INFO *mPwdInfoHandle = NULL;\r | |
21 | \r | |
0c18794e | 22 | HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath = {\r |
23 | {\r | |
24 | {\r | |
25 | HARDWARE_DEVICE_PATH,\r | |
26 | HW_VENDOR_DP,\r | |
27 | {\r | |
28 | (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r | |
29 | (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r | |
30 | }\r | |
31 | },\r | |
a0c56a82 | 32 | PWD_CREDENTIAL_PROVIDER_GUID\r |
0c18794e | 33 | },\r |
34 | {\r | |
35 | END_DEVICE_PATH_TYPE,\r | |
36 | END_ENTIRE_DEVICE_PATH_SUBTYPE,\r | |
37 | {\r | |
38 | (UINT8) (END_DEVICE_PATH_LENGTH),\r | |
39 | (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r | |
40 | }\r | |
41 | }\r | |
42 | };\r | |
43 | \r | |
6f0b8648 | 44 | EFI_USER_CREDENTIAL2_PROTOCOL gPwdCredentialProviderDriver = {\r |
0c18794e | 45 | PWD_CREDENTIAL_PROVIDER_GUID,\r |
46 | EFI_USER_CREDENTIAL_CLASS_PASSWORD,\r | |
47 | CredentialEnroll,\r | |
48 | CredentialForm,\r | |
49 | CredentialTile,\r | |
50 | CredentialTitle,\r | |
51 | CredentialUser,\r | |
52 | CredentialSelect,\r | |
53 | CredentialDeselect,\r | |
54 | CredentialDefault,\r | |
55 | CredentialGetInfo,\r | |
6f0b8648 | 56 | CredentialGetNextInfo,\r |
57 | EFI_CREDENTIAL_CAPABILITIES_ENROLL,\r | |
58 | CredentialDelete\r | |
0c18794e | 59 | };\r |
60 | \r | |
61 | \r | |
62 | /**\r | |
63 | Get string by string id from HII Interface.\r | |
64 | \r | |
65 | \r | |
66 | @param[in] Id String ID to get the string from.\r | |
67 | \r | |
68 | @retval CHAR16 * String from ID.\r | |
69 | @retval NULL If error occurs.\r | |
70 | \r | |
71 | **/\r | |
72 | CHAR16 *\r | |
73 | GetStringById (\r | |
74 | IN EFI_STRING_ID Id\r | |
75 | )\r | |
76 | {\r | |
77 | //\r | |
78 | // Get the current string for the current Language.\r | |
79 | //\r | |
80 | return HiiGetString (mCallbackInfo->HiiHandle, Id, NULL);\r | |
81 | }\r | |
82 | \r | |
83 | \r | |
84 | /**\r | |
85 | Expand password table size.\r | |
86 | \r | |
87 | **/\r | |
88 | VOID\r | |
89 | ExpandTableSize (\r | |
90 | VOID\r | |
91 | )\r | |
92 | {\r | |
93 | CREDENTIAL_TABLE *NewTable;\r | |
94 | UINTN Count;\r | |
95 | \r | |
96 | Count = mPwdTable->MaxCount + PASSWORD_TABLE_INC;\r | |
97 | //\r | |
98 | // Create new credential table.\r | |
99 | //\r | |
100 | NewTable = (CREDENTIAL_TABLE *) AllocateZeroPool (\r | |
b3548d32 | 101 | sizeof (CREDENTIAL_TABLE) +\r |
0c18794e | 102 | (Count - 1) * sizeof (PASSWORD_INFO)\r |
103 | );\r | |
b3548d32 | 104 | ASSERT (NewTable != NULL);\r |
0c18794e | 105 | \r |
106 | NewTable->MaxCount = Count;\r | |
107 | NewTable->Count = mPwdTable->Count;\r | |
108 | NewTable->ValidIndex = mPwdTable->ValidIndex;\r | |
109 | //\r | |
110 | // Copy old entries\r | |
111 | //\r | |
112 | CopyMem (\r | |
b3548d32 LG |
113 | &NewTable->UserInfo,\r |
114 | &mPwdTable->UserInfo,\r | |
0c18794e | 115 | mPwdTable->Count * sizeof (PASSWORD_INFO)\r |
116 | );\r | |
117 | FreePool (mPwdTable);\r | |
118 | mPwdTable = NewTable;\r | |
119 | }\r | |
120 | \r | |
121 | \r | |
122 | /**\r | |
6f0b8648 | 123 | Add, update or delete info in table, and sync with NV variable.\r |
0c18794e | 124 | \r |
6f0b8648 | 125 | @param[in] Index The index of the password in table. If index is found in\r |
b3548d32 LG |
126 | table, update the info, else add the into to table.\r |
127 | @param[in] Info The new password info to add into table.If Info is NULL,\r | |
6f0b8648 | 128 | delete the info by Index.\r |
0c18794e | 129 | \r |
130 | @retval EFI_INVALID_PARAMETER Info is NULL when save the info.\r | |
131 | @retval EFI_SUCCESS Modify the table successfully.\r | |
132 | @retval Others Failed to modify the table.\r | |
133 | \r | |
134 | **/\r | |
135 | EFI_STATUS\r | |
136 | ModifyTable (\r | |
137 | IN UINTN Index,\r | |
138 | IN PASSWORD_INFO * Info OPTIONAL\r | |
139 | )\r | |
140 | {\r | |
6f0b8648 | 141 | EFI_STATUS Status;\r |
142 | PASSWORD_INFO *NewPasswordInfo;\r | |
143 | \r | |
144 | NewPasswordInfo = NULL;\r | |
145 | \r | |
0c18794e | 146 | if (Index < mPwdTable->Count) {\r |
6f0b8648 | 147 | if (Info == NULL) {\r |
148 | //\r | |
149 | // Delete the specified entry.\r | |
150 | //\r | |
151 | mPwdTable->Count--;\r | |
152 | if (Index != mPwdTable->Count) {\r | |
153 | NewPasswordInfo = &mPwdTable->UserInfo[mPwdTable->Count];\r | |
b3548d32 | 154 | }\r |
6f0b8648 | 155 | } else {\r |
156 | //\r | |
157 | // Update the specified entry.\r | |
158 | //\r | |
159 | NewPasswordInfo = Info;\r | |
0c18794e | 160 | }\r |
161 | } else {\r | |
162 | //\r | |
6f0b8648 | 163 | // Add a new password info.\r |
0c18794e | 164 | //\r |
165 | if (Info == NULL) {\r | |
166 | return EFI_INVALID_PARAMETER;\r | |
167 | }\r | |
168 | \r | |
169 | if (mPwdTable->Count >= mPwdTable->MaxCount) {\r | |
170 | ExpandTableSize ();\r | |
171 | }\r | |
172 | \r | |
6f0b8648 | 173 | NewPasswordInfo = Info;\r |
0c18794e | 174 | mPwdTable->Count++;\r |
175 | }\r | |
176 | \r | |
6f0b8648 | 177 | if (NewPasswordInfo != NULL) {\r |
178 | CopyMem (&mPwdTable->UserInfo[Index], NewPasswordInfo, sizeof (PASSWORD_INFO));\r | |
179 | }\r | |
180 | \r | |
0c18794e | 181 | //\r |
182 | // Save the credential table.\r | |
183 | //\r | |
184 | Status = gRT->SetVariable (\r | |
185 | L"PwdCredential",\r | |
a0c56a82 | 186 | &gPwdCredentialProviderGuid,\r |
0c18794e | 187 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r |
188 | mPwdTable->Count * sizeof (PASSWORD_INFO),\r | |
189 | &mPwdTable->UserInfo\r | |
190 | );\r | |
191 | return Status;\r | |
192 | }\r | |
193 | \r | |
194 | \r | |
195 | /**\r | |
196 | Create a password table.\r | |
197 | \r | |
198 | @retval EFI_SUCCESS Create a password table successfully.\r | |
199 | @retval Others Failed to create a password.\r | |
200 | \r | |
201 | **/\r | |
202 | EFI_STATUS\r | |
203 | InitCredentialTable (\r | |
204 | VOID\r | |
205 | )\r | |
206 | {\r | |
207 | EFI_STATUS Status;\r | |
208 | UINT8 *Var;\r | |
209 | UINTN VarSize;\r | |
210 | \r | |
211 | //\r | |
212 | // Get Password credential data from NV variable.\r | |
213 | //\r | |
214 | VarSize = 0;\r | |
215 | Var = NULL;\r | |
216 | Status = gRT->GetVariable (\r | |
b3548d32 LG |
217 | L"PwdCredential",\r |
218 | &gPwdCredentialProviderGuid,\r | |
219 | NULL,\r | |
0c18794e | 220 | &VarSize,\r |
221 | Var\r | |
222 | );\r | |
223 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
224 | Var = AllocateZeroPool (VarSize);\r | |
225 | if (Var == NULL) {\r | |
226 | return EFI_OUT_OF_RESOURCES;\r | |
227 | }\r | |
228 | Status = gRT->GetVariable (\r | |
b3548d32 LG |
229 | L"PwdCredential",\r |
230 | &gPwdCredentialProviderGuid,\r | |
231 | NULL,\r | |
0c18794e | 232 | &VarSize,\r |
233 | Var\r | |
234 | );\r | |
235 | }\r | |
236 | if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {\r | |
237 | return Status;\r | |
238 | }\r | |
b3548d32 | 239 | \r |
0c18794e | 240 | //\r |
241 | // Create the password credential table.\r | |
242 | //\r | |
243 | mPwdTable = AllocateZeroPool (\r | |
244 | sizeof (CREDENTIAL_TABLE) - sizeof (PASSWORD_INFO) +\r | |
b3548d32 | 245 | PASSWORD_TABLE_INC * sizeof (PASSWORD_INFO) +\r |
0c18794e | 246 | VarSize\r |
247 | );\r | |
248 | if (mPwdTable == NULL) {\r | |
249 | FreePool (Var);\r | |
250 | return EFI_OUT_OF_RESOURCES;\r | |
251 | }\r | |
252 | \r | |
253 | mPwdTable->Count = VarSize / sizeof (PASSWORD_INFO);\r | |
254 | mPwdTable->MaxCount = mPwdTable->Count + PASSWORD_TABLE_INC;\r | |
255 | mPwdTable->ValidIndex = 0;\r | |
256 | if (Var != NULL) {\r | |
257 | CopyMem (mPwdTable->UserInfo, Var, VarSize);\r | |
258 | FreePool (Var);\r | |
259 | }\r | |
260 | return EFI_SUCCESS;\r | |
261 | }\r | |
262 | \r | |
263 | \r | |
264 | /**\r | |
265 | Hash the password to get credential.\r | |
266 | \r | |
267 | @param[in] Password Points to the input password.\r | |
268 | @param[in] PasswordSize The size of password, in bytes.\r | |
269 | @param[out] Credential Points to the hashed result.\r | |
270 | \r | |
271 | @retval TRUE Hash the password successfully.\r | |
272 | @retval FALSE Failed to hash the password.\r | |
b3548d32 | 273 | \r |
0c18794e | 274 | **/\r |
275 | BOOLEAN\r | |
276 | GenerateCredential (\r | |
277 | IN CHAR16 *Password,\r | |
278 | IN UINTN PasswordSize,\r | |
279 | OUT UINT8 *Credential\r | |
280 | )\r | |
281 | {\r | |
282 | BOOLEAN Status;\r | |
283 | UINTN HashSize;\r | |
284 | VOID *Hash;\r | |
b3548d32 | 285 | \r |
0c18794e | 286 | HashSize = Sha1GetContextSize ();\r |
287 | Hash = AllocatePool (HashSize);\r | |
288 | ASSERT (Hash != NULL);\r | |
b3548d32 | 289 | \r |
0c18794e | 290 | Status = Sha1Init (Hash);\r |
291 | if (!Status) {\r | |
292 | goto Done;\r | |
293 | }\r | |
b3548d32 | 294 | \r |
0c18794e | 295 | Status = Sha1Update (Hash, Password, PasswordSize);\r |
296 | if (!Status) {\r | |
297 | goto Done;\r | |
298 | }\r | |
b3548d32 | 299 | \r |
0c18794e | 300 | Status = Sha1Final (Hash, Credential);\r |
b3548d32 | 301 | \r |
0c18794e | 302 | Done:\r |
303 | FreePool (Hash);\r | |
304 | return Status;\r | |
305 | }\r | |
306 | \r | |
307 | \r | |
308 | /**\r | |
309 | Get password from user input.\r | |
310 | \r | |
311 | @param[in] FirstPwd If True, prompt to input the first password.\r | |
312 | If False, prompt to input password again.\r | |
313 | @param[out] Credential Points to the input password.\r | |
314 | \r | |
315 | **/\r | |
316 | VOID\r | |
317 | GetPassword (\r | |
318 | IN BOOLEAN FirstPwd,\r | |
319 | OUT CHAR8 *Credential\r | |
320 | )\r | |
321 | {\r | |
322 | EFI_INPUT_KEY Key;\r | |
323 | CHAR16 PasswordMask[CREDENTIAL_LEN + 1];\r | |
324 | CHAR16 Password[CREDENTIAL_LEN];\r | |
325 | UINTN PasswordLen;\r | |
326 | CHAR16 *QuestionStr;\r | |
327 | CHAR16 *LineStr;\r | |
b3548d32 | 328 | \r |
0c18794e | 329 | PasswordLen = 0;\r |
330 | while (TRUE) {\r | |
331 | PasswordMask[PasswordLen] = L'_';\r | |
332 | PasswordMask[PasswordLen + 1] = L'\0';\r | |
333 | LineStr = GetStringById (STRING_TOKEN (STR_DRAW_A_LINE));\r | |
334 | if (FirstPwd) {\r | |
335 | QuestionStr = GetStringById (STRING_TOKEN (STR_INPUT_PASSWORD));\r | |
336 | } else {\r | |
337 | QuestionStr = GetStringById (STRING_TOKEN (STR_INPUT_PASSWORD_AGAIN));\r | |
338 | }\r | |
339 | CreatePopUp (\r | |
340 | EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r | |
341 | &Key,\r | |
342 | QuestionStr,\r | |
343 | LineStr,\r | |
344 | PasswordMask,\r | |
345 | NULL\r | |
346 | );\r | |
347 | FreePool (QuestionStr);\r | |
348 | FreePool (LineStr);\r | |
b3548d32 | 349 | \r |
0c18794e | 350 | //\r |
351 | // Check key stroke\r | |
352 | //\r | |
353 | if (Key.ScanCode == SCAN_NULL) {\r | |
354 | if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r | |
355 | break;\r | |
356 | } else if (Key.UnicodeChar == CHAR_BACKSPACE) {\r | |
357 | if (PasswordLen > 0) {\r | |
358 | PasswordLen--;\r | |
359 | }\r | |
b3548d32 LG |
360 | } else if ((Key.UnicodeChar == CHAR_NULL) ||\r |
361 | (Key.UnicodeChar == CHAR_TAB) ||\r | |
0c18794e | 362 | (Key.UnicodeChar == CHAR_LINEFEED)) {\r |
363 | continue;\r | |
364 | } else {\r | |
365 | Password[PasswordLen] = Key.UnicodeChar;\r | |
366 | PasswordMask[PasswordLen] = L'*';\r | |
367 | PasswordLen++;\r | |
368 | if (PasswordLen == CREDENTIAL_LEN) {\r | |
369 | break;\r | |
370 | }\r | |
371 | }\r | |
372 | }\r | |
373 | }\r | |
b3548d32 | 374 | \r |
0c18794e | 375 | PasswordLen = PasswordLen * sizeof (CHAR16);\r |
376 | GenerateCredential (Password, PasswordLen, (UINT8 *)Credential);\r | |
377 | }\r | |
378 | \r | |
379 | /**\r | |
380 | Check whether the password can be found on this provider.\r | |
381 | \r | |
382 | @param[in] Password The password to be found.\r | |
383 | \r | |
384 | @retval EFI_SUCCESS Found password sucessfully.\r | |
385 | @retval EFI_NOT_FOUND Fail to find the password.\r | |
386 | \r | |
387 | **/\r | |
388 | EFI_STATUS\r | |
389 | CheckPassword (\r | |
390 | IN CHAR8 *Password\r | |
391 | )\r | |
392 | {\r | |
393 | UINTN Index;\r | |
394 | CHAR8 *Pwd;\r | |
b3548d32 | 395 | \r |
0c18794e | 396 | //\r |
397 | // Check password credential.\r | |
398 | //\r | |
399 | mPwdTable->ValidIndex = 0;\r | |
400 | for (Index = 0; Index < mPwdTable->Count; Index++) {\r | |
401 | Pwd = mPwdTable->UserInfo[Index].Password;\r | |
402 | if (CompareMem (Pwd, Password, CREDENTIAL_LEN) == 0) {\r | |
403 | mPwdTable->ValidIndex = Index + 1;\r | |
404 | return EFI_SUCCESS;\r | |
405 | }\r | |
406 | }\r | |
407 | \r | |
408 | return EFI_NOT_FOUND;\r | |
409 | }\r | |
410 | \r | |
411 | \r | |
412 | /**\r | |
413 | Find a user infomation record by the information record type.\r | |
414 | \r | |
b3548d32 | 415 | This function searches all user information records of User from beginning\r |
0c18794e | 416 | until either the information is found, or there are no more user infomation\r |
417 | records. A match occurs when a Info.InfoType field matches the user information\r | |
418 | record type.\r | |
419 | \r | |
b3548d32 | 420 | @param[in] User Points to the user profile record to search.\r |
0c18794e | 421 | @param[in] InfoType The infomation type to be searched.\r |
422 | @param[out] Info Points to the user info found, the caller is responsible\r | |
423 | to free.\r | |
b3548d32 | 424 | \r |
0c18794e | 425 | @retval EFI_SUCCESS Find the user information successfully.\r |
426 | @retval Others Fail to find the user information.\r | |
427 | \r | |
428 | **/\r | |
429 | EFI_STATUS\r | |
430 | FindUserInfoByType (\r | |
431 | IN EFI_USER_PROFILE_HANDLE User,\r | |
432 | IN UINT8 InfoType,\r | |
433 | OUT EFI_USER_INFO **Info\r | |
434 | )\r | |
435 | {\r | |
436 | EFI_STATUS Status;\r | |
437 | EFI_USER_INFO *UserInfo;\r | |
438 | UINTN UserInfoSize;\r | |
439 | EFI_USER_INFO_HANDLE UserInfoHandle;\r | |
440 | EFI_USER_MANAGER_PROTOCOL *UserManager;\r | |
b3548d32 | 441 | \r |
0c18794e | 442 | //\r |
443 | // Find user information by information type.\r | |
444 | //\r | |
445 | if (Info == NULL) {\r | |
446 | return EFI_INVALID_PARAMETER;\r | |
447 | }\r | |
448 | \r | |
449 | Status = gBS->LocateProtocol (\r | |
450 | &gEfiUserManagerProtocolGuid,\r | |
451 | NULL,\r | |
452 | (VOID **) &UserManager\r | |
453 | );\r | |
454 | if (EFI_ERROR (Status)) {\r | |
455 | return EFI_NOT_FOUND;\r | |
456 | }\r | |
457 | \r | |
458 | //\r | |
459 | // Get each user information.\r | |
460 | //\r | |
461 | \r | |
462 | UserInfoHandle = NULL;\r | |
463 | UserInfo = NULL;\r | |
464 | UserInfoSize = 0;\r | |
465 | while (TRUE) {\r | |
466 | Status = UserManager->GetNextInfo (UserManager, User, &UserInfoHandle);\r | |
467 | if (EFI_ERROR (Status)) {\r | |
468 | break;\r | |
469 | }\r | |
470 | //\r | |
471 | // Get information.\r | |
472 | //\r | |
473 | Status = UserManager->GetInfo (\r | |
474 | UserManager,\r | |
475 | User,\r | |
476 | UserInfoHandle,\r | |
477 | UserInfo,\r | |
478 | &UserInfoSize\r | |
479 | );\r | |
480 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
481 | if (UserInfo != NULL) {\r | |
482 | FreePool (UserInfo);\r | |
483 | }\r | |
484 | UserInfo = AllocateZeroPool (UserInfoSize);\r | |
485 | if (UserInfo == NULL) {\r | |
486 | return EFI_OUT_OF_RESOURCES;\r | |
487 | }\r | |
488 | Status = UserManager->GetInfo (\r | |
489 | UserManager,\r | |
490 | User,\r | |
491 | UserInfoHandle,\r | |
492 | UserInfo,\r | |
493 | &UserInfoSize\r | |
494 | );\r | |
495 | }\r | |
496 | if (EFI_ERROR (Status)) {\r | |
497 | break;\r | |
498 | }\r | |
499 | \r | |
500 | ASSERT (UserInfo != NULL);\r | |
501 | if (UserInfo->InfoType == InfoType) {\r | |
502 | *Info = UserInfo;\r | |
503 | return EFI_SUCCESS;\r | |
b3548d32 | 504 | }\r |
0c18794e | 505 | }\r |
506 | \r | |
507 | if (UserInfo != NULL) {\r | |
508 | FreePool (UserInfo);\r | |
509 | }\r | |
510 | return Status;\r | |
511 | }\r | |
512 | \r | |
513 | \r | |
514 | /**\r | |
515 | This function processes the results of changes in configuration.\r | |
516 | \r | |
517 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
518 | @param Action Specifies the type of action taken by the browser.\r | |
519 | @param QuestionId A unique value which is sent to the original\r | |
520 | exporting driver so that it can identify the type\r | |
521 | of data to expect.\r | |
522 | @param Type The type of value for the question.\r | |
523 | @param Value A pointer to the data being sent to the original\r | |
524 | exporting driver.\r | |
525 | @param ActionRequest On return, points to the action requested by the\r | |
526 | callback function.\r | |
527 | \r | |
528 | @retval EFI_SUCCESS The callback successfully handled the action.\r | |
529 | @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r | |
530 | variable and its data.\r | |
531 | @retval EFI_DEVICE_ERROR The variable could not be saved.\r | |
532 | @retval EFI_UNSUPPORTED The specified Action is not supported by the\r | |
533 | callback.\r | |
534 | \r | |
535 | **/\r | |
536 | EFI_STATUS\r | |
537 | EFIAPI\r | |
538 | CredentialDriverCallback (\r | |
539 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
540 | IN EFI_BROWSER_ACTION Action,\r | |
541 | IN EFI_QUESTION_ID QuestionId,\r | |
542 | IN UINT8 Type,\r | |
543 | IN EFI_IFR_TYPE_VALUE *Value,\r | |
544 | OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r | |
545 | )\r | |
546 | {\r | |
547 | EFI_STATUS Status;\r | |
548 | EFI_INPUT_KEY Key;\r | |
549 | CHAR8 Password[CREDENTIAL_LEN];\r | |
550 | CHAR16 *PromptStr;\r | |
551 | \r | |
fab10465 | 552 | if (Action == EFI_BROWSER_ACTION_CHANGED) {\r |
0c18794e | 553 | if (QuestionId == KEY_GET_PASSWORD) {\r |
554 | //\r | |
555 | // Get and check password.\r | |
556 | //\r | |
557 | GetPassword (TRUE, Password);\r | |
558 | Status = CheckPassword (Password);\r | |
559 | if (EFI_ERROR (Status)) {\r | |
560 | PromptStr = GetStringById (STRING_TOKEN (STR_PASSWORD_INCORRECT));\r | |
561 | CreatePopUp (\r | |
562 | EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r | |
563 | &Key,\r | |
564 | L"",\r | |
565 | PromptStr,\r | |
566 | L"",\r | |
567 | NULL\r | |
568 | );\r | |
569 | FreePool (PromptStr);\r | |
570 | return Status;\r | |
571 | }\r | |
572 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r | |
b3548d32 | 573 | }\r |
0c18794e | 574 | return EFI_SUCCESS;\r |
575 | }\r | |
576 | \r | |
577 | //\r | |
578 | // All other action return unsupported.\r | |
579 | //\r | |
580 | return EFI_UNSUPPORTED;\r | |
581 | }\r | |
582 | \r | |
583 | \r | |
584 | /**\r | |
585 | This function allows a caller to extract the current configuration for one\r | |
586 | or more named elements from the target driver.\r | |
587 | \r | |
588 | \r | |
589 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
590 | @param Request A null-terminated Unicode string in <ConfigRequest> format.\r | |
591 | @param Progress On return, points to a character in the Request string.\r | |
592 | Points to the string's null terminator if request was successful.\r | |
593 | Points to the most recent '&' before the first failing name/value\r | |
594 | pair (or the beginning of the string if the failure is in the\r | |
595 | first name/value pair) if the request was not successful.\r | |
596 | @param Results A null-terminated Unicode string in <ConfigAltResp> format which\r | |
597 | has all values filled in for the names in the Request string.\r | |
598 | String to be allocated by the called function.\r | |
599 | \r | |
600 | @retval EFI_SUCCESS The Results is filled with the requested values.\r | |
601 | @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r | |
602 | @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.\r | |
603 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r | |
604 | \r | |
605 | **/\r | |
606 | EFI_STATUS\r | |
607 | EFIAPI\r | |
608 | FakeExtractConfig (\r | |
609 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
610 | IN CONST EFI_STRING Request,\r | |
611 | OUT EFI_STRING *Progress,\r | |
612 | OUT EFI_STRING *Results\r | |
613 | )\r | |
614 | {\r | |
615 | if (Progress == NULL || Results == NULL) {\r | |
616 | return EFI_INVALID_PARAMETER;\r | |
617 | }\r | |
618 | *Progress = Request;\r | |
619 | return EFI_NOT_FOUND;\r | |
620 | }\r | |
621 | \r | |
622 | /**\r | |
623 | This function processes the results of changes in configuration.\r | |
624 | \r | |
625 | \r | |
626 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
627 | @param Configuration A null-terminated Unicode string in <ConfigResp> format.\r | |
628 | @param Progress A pointer to a string filled in with the offset of the most\r | |
629 | recent '&' before the first failing name/value pair (or the\r | |
630 | beginning of the string if the failure is in the first\r | |
631 | name/value pair) or the terminating NULL if all was successful.\r | |
632 | \r | |
633 | @retval EFI_SUCCESS The Results is processed successfully.\r | |
634 | @retval EFI_INVALID_PARAMETER Configuration is NULL.\r | |
635 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r | |
636 | \r | |
637 | **/\r | |
638 | EFI_STATUS\r | |
639 | EFIAPI\r | |
640 | FakeRouteConfig (\r | |
641 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
642 | IN CONST EFI_STRING Configuration,\r | |
643 | OUT EFI_STRING *Progress\r | |
644 | )\r | |
645 | {\r | |
646 | if (Configuration == NULL || Progress == NULL) {\r | |
647 | return EFI_INVALID_PARAMETER;\r | |
648 | }\r | |
649 | \r | |
b59ac35e TP |
650 | *Progress = Configuration;\r |
651 | \r | |
0c18794e | 652 | return EFI_NOT_FOUND;\r |
653 | }\r | |
654 | \r | |
655 | /**\r | |
656 | This function initialize the data mainly used in form browser.\r | |
657 | \r | |
658 | @retval EFI_SUCCESS Initialize form data successfully.\r | |
659 | @retval Others Fail to Initialize form data.\r | |
660 | \r | |
661 | **/\r | |
662 | EFI_STATUS\r | |
663 | InitFormBrowser (\r | |
664 | VOID\r | |
665 | )\r | |
666 | {\r | |
667 | EFI_STATUS Status;\r | |
668 | PWD_PROVIDER_CALLBACK_INFO *CallbackInfo;\r | |
669 | \r | |
670 | //\r | |
671 | // Initialize driver private data.\r | |
672 | //\r | |
673 | CallbackInfo = AllocateZeroPool (sizeof (PWD_PROVIDER_CALLBACK_INFO));\r | |
674 | if (CallbackInfo == NULL) {\r | |
675 | return EFI_OUT_OF_RESOURCES;\r | |
676 | }\r | |
677 | \r | |
678 | CallbackInfo->Signature = PWD_PROVIDER_SIGNATURE;\r | |
679 | CallbackInfo->ConfigAccess.ExtractConfig = FakeExtractConfig;\r | |
680 | CallbackInfo->ConfigAccess.RouteConfig = FakeRouteConfig;\r | |
681 | CallbackInfo->ConfigAccess.Callback = CredentialDriverCallback;\r | |
682 | CallbackInfo->DriverHandle = NULL;\r | |
683 | \r | |
684 | //\r | |
685 | // Install Device Path Protocol and Config Access protocol to driver handle.\r | |
686 | //\r | |
687 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
688 | &CallbackInfo->DriverHandle,\r | |
689 | &gEfiDevicePathProtocolGuid,\r | |
690 | &mHiiVendorDevicePath,\r | |
691 | &gEfiHiiConfigAccessProtocolGuid,\r | |
692 | &CallbackInfo->ConfigAccess,\r | |
693 | NULL\r | |
694 | );\r | |
695 | ASSERT_EFI_ERROR (Status);\r | |
696 | \r | |
697 | //\r | |
698 | // Publish HII data.\r | |
699 | //\r | |
700 | CallbackInfo->HiiHandle = HiiAddPackages (\r | |
a0c56a82 | 701 | &gPwdCredentialProviderGuid,\r |
0c18794e | 702 | CallbackInfo->DriverHandle,\r |
703 | PwdCredentialProviderStrings,\r | |
704 | PwdCredentialProviderVfrBin,\r | |
705 | NULL\r | |
706 | );\r | |
707 | if (CallbackInfo->HiiHandle == NULL) {\r | |
708 | return EFI_OUT_OF_RESOURCES;\r | |
709 | }\r | |
710 | mCallbackInfo = CallbackInfo;\r | |
711 | \r | |
712 | return Status;\r | |
713 | }\r | |
714 | \r | |
715 | \r | |
716 | /**\r | |
717 | Enroll a user on a credential provider.\r | |
718 | \r | |
b3548d32 LG |
719 | This function enrolls a user on this credential provider. If the user exists on\r |
720 | this credential provider, update the user information on this credential provider;\r | |
6f0b8648 | 721 | otherwise add the user information on credential provider.\r |
b3548d32 | 722 | \r |
6f0b8648 | 723 | @param[in] This Points to this instance of EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 724 | @param[in] User The user profile to enroll.\r |
b3548d32 | 725 | \r |
0c18794e | 726 | @retval EFI_SUCCESS User profile was successfully enrolled.\r |
727 | @retval EFI_ACCESS_DENIED Current user profile does not permit enrollment on the\r | |
728 | user profile handle. Either the user profile cannot enroll\r | |
b3548d32 | 729 | on any user profile or cannot enroll on a user profile\r |
0c18794e | 730 | other than the current user profile.\r |
731 | @retval EFI_UNSUPPORTED This credential provider does not support enrollment in\r | |
732 | the pre-OS.\r | |
733 | @retval EFI_DEVICE_ERROR The new credential could not be created because of a device\r | |
734 | error.\r | |
735 | @retval EFI_INVALID_PARAMETER User does not refer to a valid user profile handle.\r | |
b3548d32 | 736 | \r |
0c18794e | 737 | **/\r |
738 | EFI_STATUS\r | |
739 | EFIAPI\r | |
740 | CredentialEnroll (\r | |
6f0b8648 | 741 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 742 | IN EFI_USER_PROFILE_HANDLE User\r |
743 | )\r | |
744 | {\r | |
745 | EFI_STATUS Status;\r | |
746 | UINTN Index;\r | |
747 | PASSWORD_INFO PwdInfo;\r | |
748 | EFI_USER_INFO *UserInfo;\r | |
749 | CHAR8 Password[CREDENTIAL_LEN];\r | |
750 | EFI_INPUT_KEY Key;\r | |
0c18794e | 751 | UINT8 *UserId;\r |
0c18794e | 752 | CHAR16 *QuestionStr;\r |
753 | CHAR16 *PromptStr;\r | |
754 | \r | |
755 | if ((This == NULL) || (User == NULL)) {\r | |
756 | return EFI_INVALID_PARAMETER;\r | |
757 | }\r | |
758 | \r | |
0c18794e | 759 | //\r |
760 | // Get User Identifier.\r | |
761 | //\r | |
762 | UserInfo = NULL;\r | |
763 | Status = FindUserInfoByType (\r | |
764 | User,\r | |
765 | EFI_USER_INFO_IDENTIFIER_RECORD,\r | |
766 | &UserInfo\r | |
767 | );\r | |
768 | if (EFI_ERROR (Status)) {\r | |
769 | return EFI_INVALID_PARAMETER;\r | |
770 | }\r | |
771 | \r | |
b3548d32 | 772 | CopyMem (PwdInfo.UserId, (UINT8 *) (UserInfo + 1), sizeof (EFI_USER_INFO_IDENTIFIER));\r |
6f0b8648 | 773 | FreePool (UserInfo);\r |
0c18794e | 774 | \r |
775 | //\r | |
6f0b8648 | 776 | // Get password from user.\r |
b3548d32 | 777 | //\r |
0c18794e | 778 | while (TRUE) {\r |
779 | //\r | |
780 | // Input password.\r | |
781 | //\r | |
782 | GetPassword (TRUE, PwdInfo.Password);\r | |
783 | \r | |
784 | //\r | |
785 | // Input password again.\r | |
786 | //\r | |
787 | GetPassword (FALSE, Password);\r | |
788 | \r | |
789 | //\r | |
790 | // Compare the two password consistency.\r | |
791 | //\r | |
792 | if (CompareMem (PwdInfo.Password, Password, CREDENTIAL_LEN) == 0) {\r | |
793 | break;\r | |
b3548d32 | 794 | }\r |
0c18794e | 795 | \r |
796 | QuestionStr = GetStringById (STRING_TOKEN (STR_PASSWORD_MISMATCH));\r | |
b3548d32 | 797 | PromptStr = GetStringById (STRING_TOKEN (STR_INPUT_PASSWORD_AGAIN));\r |
0c18794e | 798 | CreatePopUp (\r |
799 | EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r | |
800 | &Key,\r | |
801 | QuestionStr,\r | |
802 | L"",\r | |
803 | PromptStr,\r | |
804 | NULL\r | |
805 | );\r | |
806 | FreePool (QuestionStr);\r | |
807 | FreePool (PromptStr);\r | |
808 | }\r | |
809 | \r | |
0c18794e | 810 | //\r |
6f0b8648 | 811 | // Check whether User is ever enrolled in the provider.\r |
b3548d32 | 812 | //\r |
6f0b8648 | 813 | for (Index = 0; Index < mPwdTable->Count; Index++) {\r |
814 | UserId = (UINT8 *) &mPwdTable->UserInfo[Index].UserId;\r | |
815 | if (CompareMem (UserId, (UINT8 *) &PwdInfo.UserId, sizeof (EFI_USER_INFO_IDENTIFIER)) == 0) {\r | |
816 | //\r | |
817 | // User already exists, update the password.\r | |
b3548d32 | 818 | //\r |
6f0b8648 | 819 | break;\r |
820 | }\r | |
821 | }\r | |
b3548d32 | 822 | \r |
6f0b8648 | 823 | //\r |
824 | // Enroll the User to the provider.\r | |
0c18794e | 825 | //\r |
6f0b8648 | 826 | Status = ModifyTable (Index, &PwdInfo);\r |
0c18794e | 827 | if (EFI_ERROR (Status)) {\r |
828 | return Status;\r | |
829 | }\r | |
830 | \r | |
0c18794e | 831 | return EFI_SUCCESS;\r |
832 | }\r | |
833 | \r | |
834 | \r | |
835 | /**\r | |
836 | Returns the user interface information used during user identification.\r | |
837 | \r | |
838 | This function returns information about the form used when interacting with the\r | |
839 | user during user identification. The form is the first enabled form in the form-set\r | |
b3548d32 | 840 | class EFI_HII_USER_CREDENTIAL_FORMSET_GUID installed on the HII handle HiiHandle. If\r |
0c18794e | 841 | the user credential provider does not require a form to identify the user, then this\r |
842 | function should return EFI_NOT_FOUND.\r | |
843 | \r | |
6f0b8648 | 844 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 845 | @param[out] Hii On return, holds the HII database handle.\r |
846 | @param[out] FormSetId On return, holds the identifier of the form set which contains\r | |
847 | the form used during user identification.\r | |
b3548d32 | 848 | @param[out] FormId On return, holds the identifier of the form used during user\r |
0c18794e | 849 | identification.\r |
b3548d32 | 850 | \r |
0c18794e | 851 | @retval EFI_SUCCESS Form returned successfully.\r |
852 | @retval EFI_NOT_FOUND Form not returned.\r | |
853 | @retval EFI_INVALID_PARAMETER Hii is NULL or FormSetId is NULL or FormId is NULL.\r | |
b3548d32 | 854 | \r |
0c18794e | 855 | **/\r |
856 | EFI_STATUS\r | |
857 | EFIAPI\r | |
858 | CredentialForm (\r | |
6f0b8648 | 859 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 860 | OUT EFI_HII_HANDLE *Hii,\r |
861 | OUT EFI_GUID *FormSetId,\r | |
862 | OUT EFI_FORM_ID *FormId\r | |
863 | )\r | |
864 | {\r | |
b3548d32 | 865 | if ((This == NULL) || (Hii == NULL) ||\r |
0c18794e | 866 | (FormSetId == NULL) || (FormId == NULL)) {\r |
867 | return EFI_INVALID_PARAMETER;\r | |
868 | }\r | |
869 | \r | |
870 | *Hii = mCallbackInfo->HiiHandle;\r | |
871 | *FormId = FORMID_GET_PASSWORD_FORM;\r | |
a0c56a82 | 872 | CopyGuid (FormSetId, &gPwdCredentialProviderGuid);\r |
b3548d32 | 873 | \r |
0c18794e | 874 | return EFI_SUCCESS;\r |
875 | }\r | |
876 | \r | |
877 | \r | |
878 | /**\r | |
879 | Returns bitmap used to describe the credential provider type.\r | |
880 | \r | |
881 | This optional function returns a bitmap that is less than or equal to the number\r | |
882 | of pixels specified by Width and Height. If no such bitmap exists, then EFI_NOT_FOUND\r | |
b3548d32 | 883 | is returned.\r |
0c18794e | 884 | \r |
6f0b8648 | 885 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
b3548d32 LG |
886 | @param[in, out] Width On entry, points to the desired bitmap width. If NULL then no\r |
887 | bitmap information will be returned. On exit, points to the\r | |
0c18794e | 888 | width of the bitmap returned.\r |
889 | @param[in, out] Height On entry, points to the desired bitmap height. If NULL then no\r | |
b3548d32 | 890 | bitmap information will be returned. On exit, points to the\r |
0c18794e | 891 | height of the bitmap returned\r |
b3548d32 LG |
892 | @param[out] Hii On return, holds the HII database handle.\r |
893 | @param[out] Image On return, holds the HII image identifier.\r | |
894 | \r | |
0c18794e | 895 | @retval EFI_SUCCESS Image identifier returned successfully.\r |
896 | @retval EFI_NOT_FOUND Image identifier not returned.\r | |
897 | @retval EFI_INVALID_PARAMETER Hii is NULL or Image is NULL.\r | |
b3548d32 | 898 | \r |
0c18794e | 899 | **/\r |
900 | EFI_STATUS\r | |
901 | EFIAPI\r | |
902 | CredentialTile (\r | |
6f0b8648 | 903 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 904 | IN OUT UINTN *Width,\r |
905 | IN OUT UINTN *Height,\r | |
906 | OUT EFI_HII_HANDLE *Hii,\r | |
907 | OUT EFI_IMAGE_ID *Image\r | |
908 | )\r | |
b3548d32 | 909 | {\r |
0c18794e | 910 | if ((This == NULL) || (Hii == NULL) || (Image == NULL)) {\r |
911 | return EFI_INVALID_PARAMETER;\r | |
912 | }\r | |
913 | return EFI_NOT_FOUND;\r | |
914 | }\r | |
915 | \r | |
916 | \r | |
917 | /**\r | |
918 | Returns string used to describe the credential provider type.\r | |
919 | \r | |
920 | This function returns a string which describes the credential provider. If no\r | |
b3548d32 | 921 | such string exists, then EFI_NOT_FOUND is returned.\r |
0c18794e | 922 | \r |
6f0b8648 | 923 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 924 | @param[out] Hii On return, holds the HII database handle.\r |
925 | @param[out] String On return, holds the HII string identifier.\r | |
b3548d32 | 926 | \r |
0c18794e | 927 | @retval EFI_SUCCESS String identifier returned successfully.\r |
928 | @retval EFI_NOT_FOUND String identifier not returned.\r | |
929 | @retval EFI_INVALID_PARAMETER Hii is NULL or String is NULL.\r | |
b3548d32 | 930 | \r |
0c18794e | 931 | **/\r |
932 | EFI_STATUS\r | |
933 | EFIAPI\r | |
934 | CredentialTitle (\r | |
6f0b8648 | 935 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 936 | OUT EFI_HII_HANDLE *Hii,\r |
937 | OUT EFI_STRING_ID *String\r | |
938 | )\r | |
939 | {\r | |
940 | if ((This == NULL) || (Hii == NULL) || (String == NULL)) {\r | |
941 | return EFI_INVALID_PARAMETER;\r | |
942 | }\r | |
b3548d32 | 943 | \r |
0c18794e | 944 | //\r |
945 | // Set Hii handle and String ID.\r | |
946 | //\r | |
947 | *Hii = mCallbackInfo->HiiHandle;\r | |
948 | *String = STRING_TOKEN (STR_CREDENTIAL_TITLE);\r | |
949 | \r | |
950 | return EFI_SUCCESS;\r | |
951 | }\r | |
952 | \r | |
953 | \r | |
954 | /**\r | |
955 | Return the user identifier associated with the currently authenticated user.\r | |
956 | \r | |
957 | This function returns the user identifier of the user authenticated by this credential\r | |
b3548d32 | 958 | provider. This function is called after the credential-related information has been\r |
0c18794e | 959 | submitted on a form, OR after a call to Default() has returned that this credential is\r |
960 | ready to log on.\r | |
961 | \r | |
6f0b8648 | 962 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
b3548d32 | 963 | @param[in] User The user profile handle of the user profile currently being\r |
0c18794e | 964 | considered by the user identity manager. If NULL, then no user\r |
965 | profile is currently under consideration.\r | |
b3548d32 LG |
966 | @param[out] Identifier On return, points to the user identifier.\r |
967 | \r | |
0c18794e | 968 | @retval EFI_SUCCESS User identifier returned successfully.\r |
969 | @retval EFI_NOT_READY No user identifier can be returned.\r | |
970 | @retval EFI_ACCESS_DENIED The user has been locked out of this user credential.\r | |
971 | @retval EFI_INVALID_PARAMETER This is NULL, or Identifier is NULL.\r | |
972 | @retval EFI_NOT_FOUND User is not NULL, and the specified user handle can't be\r | |
973 | found in user profile database\r | |
b3548d32 | 974 | \r |
0c18794e | 975 | **/\r |
976 | EFI_STATUS\r | |
977 | EFIAPI\r | |
978 | CredentialUser (\r | |
6f0b8648 | 979 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 980 | IN EFI_USER_PROFILE_HANDLE User,\r |
981 | OUT EFI_USER_INFO_IDENTIFIER *Identifier\r | |
982 | )\r | |
983 | {\r | |
984 | EFI_STATUS Status;\r | |
985 | UINTN Index;\r | |
986 | EFI_USER_INFO *UserInfo;\r | |
987 | UINT8 *UserId;\r | |
988 | UINT8 *NewUserId;\r | |
989 | CHAR8 *Pwd;\r | |
990 | CHAR8 *NewPwd;\r | |
991 | \r | |
992 | if ((This == NULL) || (Identifier == NULL)) {\r | |
993 | return EFI_INVALID_PARAMETER;\r | |
994 | }\r | |
995 | \r | |
996 | if (mPwdTable->ValidIndex == 0) {\r | |
997 | //\r | |
998 | // No password input, or the input password doesn't match\r | |
999 | // anyone in PwdTable.\r | |
1000 | //\r | |
1001 | return EFI_NOT_READY;\r | |
1002 | }\r | |
b3548d32 | 1003 | \r |
0c18794e | 1004 | if (User == NULL) {\r |
1005 | //\r | |
1006 | // Return the user ID whose password matches the input password.\r | |
b3548d32 | 1007 | //\r |
0c18794e | 1008 | CopyMem (\r |
b3548d32 LG |
1009 | Identifier,\r |
1010 | &mPwdTable->UserInfo[mPwdTable->ValidIndex - 1].UserId,\r | |
0c18794e | 1011 | sizeof (EFI_USER_INFO_IDENTIFIER)\r |
b3548d32 | 1012 | );\r |
0c18794e | 1013 | return EFI_SUCCESS;\r |
1014 | }\r | |
b3548d32 | 1015 | \r |
0c18794e | 1016 | //\r |
1017 | // Get the User's ID.\r | |
1018 | //\r | |
1019 | Status = FindUserInfoByType (\r | |
1020 | User,\r | |
1021 | EFI_USER_INFO_IDENTIFIER_RECORD,\r | |
1022 | &UserInfo\r | |
1023 | );\r | |
1024 | if (EFI_ERROR (Status)) {\r | |
1025 | return EFI_NOT_FOUND;\r | |
1026 | }\r | |
b3548d32 | 1027 | \r |
0c18794e | 1028 | //\r |
1029 | // Check whether the input password matches one in PwdTable.\r | |
1030 | //\r | |
1031 | for (Index = 0; Index < mPwdTable->Count; Index++) {\r | |
1032 | UserId = (UINT8 *) &mPwdTable->UserInfo[Index].UserId;\r | |
1033 | NewUserId = (UINT8 *) (UserInfo + 1);\r | |
1034 | if (CompareMem (UserId, NewUserId, sizeof (EFI_USER_INFO_IDENTIFIER)) == 0) {\r | |
1035 | Pwd = mPwdTable->UserInfo[Index].Password;\r | |
1036 | NewPwd = mPwdTable->UserInfo[mPwdTable->ValidIndex - 1].Password;\r | |
1037 | if (CompareMem (Pwd, NewPwd, CREDENTIAL_LEN) == 0) {\r | |
1038 | CopyMem (Identifier, UserId, sizeof (EFI_USER_INFO_IDENTIFIER));\r | |
1039 | FreePool (UserInfo);\r | |
1040 | return EFI_SUCCESS;\r | |
b3548d32 | 1041 | }\r |
0c18794e | 1042 | }\r |
1043 | }\r | |
1044 | \r | |
b3548d32 | 1045 | FreePool (UserInfo);\r |
ae4cb94f | 1046 | return EFI_NOT_READY;\r |
0c18794e | 1047 | }\r |
1048 | \r | |
1049 | \r | |
1050 | /**\r | |
1051 | Indicate that user interface interaction has begun for the specified credential.\r | |
1052 | \r | |
b3548d32 | 1053 | This function is called when a credential provider is selected by the user. If\r |
0c18794e | 1054 | AutoLogon returns FALSE, then the user interface will be constructed by the User\r |
b3548d32 | 1055 | Identity Manager.\r |
0c18794e | 1056 | \r |
6f0b8648 | 1057 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
b3548d32 LG |
1058 | @param[out] AutoLogon On return, points to the credential provider's capabilities\r |
1059 | after the credential provider has been selected by the user.\r | |
1060 | \r | |
0c18794e | 1061 | @retval EFI_SUCCESS Credential provider successfully selected.\r |
1062 | @retval EFI_INVALID_PARAMETER AutoLogon is NULL.\r | |
b3548d32 | 1063 | \r |
0c18794e | 1064 | **/\r |
1065 | EFI_STATUS\r | |
1066 | EFIAPI\r | |
1067 | CredentialSelect (\r | |
6f0b8648 | 1068 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 1069 | OUT EFI_CREDENTIAL_LOGON_FLAGS *AutoLogon\r |
1070 | )\r | |
1071 | {\r | |
1072 | if ((This == NULL) || (AutoLogon == NULL)) {\r | |
1073 | return EFI_INVALID_PARAMETER;\r | |
1074 | }\r | |
1075 | *AutoLogon = 0;\r | |
1076 | \r | |
1077 | return EFI_SUCCESS;\r | |
1078 | }\r | |
1079 | \r | |
1080 | \r | |
1081 | /**\r | |
1082 | Indicate that user interface interaction has ended for the specified credential.\r | |
1083 | \r | |
1084 | This function is called when a credential provider is deselected by the user.\r | |
1085 | \r | |
6f0b8648 | 1086 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
b3548d32 | 1087 | \r |
0c18794e | 1088 | @retval EFI_SUCCESS Credential provider successfully deselected.\r |
b3548d32 | 1089 | \r |
0c18794e | 1090 | **/\r |
1091 | EFI_STATUS\r | |
1092 | EFIAPI\r | |
1093 | CredentialDeselect (\r | |
6f0b8648 | 1094 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This\r |
0c18794e | 1095 | )\r |
1096 | {\r | |
1097 | if (This == NULL) {\r | |
1098 | return EFI_INVALID_PARAMETER;\r | |
1099 | }\r | |
1100 | return EFI_SUCCESS;\r | |
1101 | }\r | |
1102 | \r | |
1103 | \r | |
1104 | /**\r | |
1105 | Return the default logon behavior for this user credential.\r | |
1106 | \r | |
b3548d32 | 1107 | This function reports the default login behavior regarding this credential provider.\r |
0c18794e | 1108 | \r |
6f0b8648 | 1109 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 1110 | @param[out] AutoLogon On return, holds whether the credential provider should be used\r |
b3548d32 LG |
1111 | by default to automatically log on the user.\r |
1112 | \r | |
0c18794e | 1113 | @retval EFI_SUCCESS Default information successfully returned.\r |
1114 | @retval EFI_INVALID_PARAMETER AutoLogon is NULL.\r | |
b3548d32 | 1115 | \r |
0c18794e | 1116 | **/\r |
1117 | EFI_STATUS\r | |
1118 | EFIAPI\r | |
1119 | CredentialDefault (\r | |
6f0b8648 | 1120 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 1121 | OUT EFI_CREDENTIAL_LOGON_FLAGS *AutoLogon\r |
1122 | )\r | |
1123 | {\r | |
1124 | if ((This == NULL) || (AutoLogon == NULL)) {\r | |
1125 | return EFI_INVALID_PARAMETER;\r | |
1126 | }\r | |
1127 | *AutoLogon = 0;\r | |
b3548d32 | 1128 | \r |
0c18794e | 1129 | return EFI_SUCCESS;\r |
1130 | }\r | |
1131 | \r | |
1132 | \r | |
1133 | /**\r | |
1134 | Return information attached to the credential provider.\r | |
1135 | \r | |
b3548d32 | 1136 | This function returns user information.\r |
0c18794e | 1137 | \r |
6f0b8648 | 1138 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
b3548d32 | 1139 | @param[in] UserInfo Handle of the user information data record.\r |
0c18794e | 1140 | @param[out] Info On entry, points to a buffer of at least *InfoSize bytes. On\r |
1141 | exit, holds the user information. If the buffer is too small\r | |
1142 | to hold the information, then EFI_BUFFER_TOO_SMALL is returned\r | |
1143 | and InfoSize is updated to contain the number of bytes actually\r | |
1144 | required.\r | |
b3548d32 LG |
1145 | @param[in, out] InfoSize On entry, points to the size of Info. On return, points to the\r |
1146 | size of the user information.\r | |
1147 | \r | |
0c18794e | 1148 | @retval EFI_SUCCESS Information returned successfully.\r |
1149 | @retval EFI_BUFFER_TOO_SMALL The size specified by InfoSize is too small to hold all of the\r | |
1150 | user information. The size required is returned in *InfoSize.\r | |
1151 | @retval EFI_INVALID_PARAMETER Info is NULL or InfoSize is NULL.\r | |
b3548d32 LG |
1152 | @retval EFI_NOT_FOUND The specified UserInfo does not refer to a valid user info handle.\r |
1153 | \r | |
0c18794e | 1154 | **/\r |
1155 | EFI_STATUS\r | |
1156 | EFIAPI\r | |
1157 | CredentialGetInfo (\r | |
6f0b8648 | 1158 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 1159 | IN EFI_USER_INFO_HANDLE UserInfo,\r |
1160 | OUT EFI_USER_INFO *Info,\r | |
1161 | IN OUT UINTN *InfoSize\r | |
1162 | )\r | |
1163 | {\r | |
1164 | EFI_USER_INFO *CredentialInfo;\r | |
1165 | UINTN Index;\r | |
b3548d32 | 1166 | \r |
0c18794e | 1167 | if ((This == NULL) || (InfoSize == NULL) || (Info == NULL)) {\r |
1168 | return EFI_INVALID_PARAMETER;\r | |
1169 | }\r | |
1170 | \r | |
1171 | if ((UserInfo == NULL) || (mPwdInfoHandle == NULL)) {\r | |
1172 | return EFI_NOT_FOUND;\r | |
1173 | }\r | |
b3548d32 | 1174 | \r |
0c18794e | 1175 | //\r |
1176 | // Find information handle in credential info table.\r | |
1177 | //\r | |
1178 | for (Index = 0; Index < mPwdInfoHandle->Count; Index++) {\r | |
1179 | CredentialInfo = mPwdInfoHandle->Info[Index];\r | |
1180 | if (UserInfo == (EFI_USER_INFO_HANDLE)CredentialInfo) {\r | |
1181 | //\r | |
1182 | // The handle is found, copy the user info.\r | |
1183 | //\r | |
1184 | if (CredentialInfo->InfoSize > *InfoSize) {\r | |
1185 | *InfoSize = CredentialInfo->InfoSize;\r | |
1186 | return EFI_BUFFER_TOO_SMALL;\r | |
1187 | }\r | |
b3548d32 LG |
1188 | CopyMem (Info, CredentialInfo, CredentialInfo->InfoSize);\r |
1189 | return EFI_SUCCESS;\r | |
0c18794e | 1190 | }\r |
1191 | }\r | |
b3548d32 | 1192 | \r |
0c18794e | 1193 | return EFI_NOT_FOUND;\r |
1194 | }\r | |
1195 | \r | |
1196 | \r | |
1197 | /**\r | |
1198 | Enumerate all of the user informations on the credential provider.\r | |
1199 | \r | |
1200 | This function returns the next user information record. To retrieve the first user\r | |
1201 | information record handle, point UserInfo at a NULL. Each subsequent call will retrieve\r | |
1202 | another user information record handle until there are no more, at which point UserInfo\r | |
b3548d32 | 1203 | will point to NULL.\r |
0c18794e | 1204 | \r |
6f0b8648 | 1205 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 1206 | @param[in, out] UserInfo On entry, points to the previous user information handle or NULL\r |
1207 | to start enumeration. On exit, points to the next user information\r | |
1208 | handle or NULL if there is no more user information.\r | |
b3548d32 | 1209 | \r |
0c18794e | 1210 | @retval EFI_SUCCESS User information returned.\r |
1211 | @retval EFI_NOT_FOUND No more user information found.\r | |
1212 | @retval EFI_INVALID_PARAMETER UserInfo is NULL.\r | |
b3548d32 | 1213 | \r |
0c18794e | 1214 | **/\r |
1215 | EFI_STATUS\r | |
1216 | EFIAPI\r | |
1217 | CredentialGetNextInfo (\r | |
6f0b8648 | 1218 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 1219 | IN OUT EFI_USER_INFO_HANDLE *UserInfo\r |
1220 | )\r | |
1221 | {\r | |
1222 | EFI_USER_INFO *Info;\r | |
1223 | CHAR16 *ProvNameStr;\r | |
1224 | UINTN InfoLen;\r | |
1225 | UINTN Index;\r | |
1226 | UINTN ProvStrLen;\r | |
b3548d32 | 1227 | \r |
0c18794e | 1228 | if ((This == NULL) || (UserInfo == NULL)) {\r |
1229 | return EFI_INVALID_PARAMETER;\r | |
1230 | }\r | |
1231 | \r | |
1232 | if (mPwdInfoHandle == NULL) {\r | |
1233 | //\r | |
1234 | // Initilized user info table. There are 4 user info records in the table.\r | |
1235 | //\r | |
1236 | InfoLen = sizeof (PASSWORD_CREDENTIAL_INFO) + (4 - 1) * sizeof (EFI_USER_INFO *);\r | |
1237 | mPwdInfoHandle = AllocateZeroPool (InfoLen);\r | |
1238 | if (mPwdInfoHandle == NULL) {\r | |
1239 | *UserInfo = NULL;\r | |
1240 | return EFI_NOT_FOUND;\r | |
1241 | }\r | |
1242 | \r | |
1243 | //\r | |
1244 | // The first information, Credential Provider info.\r | |
1245 | //\r | |
1246 | InfoLen = sizeof (EFI_USER_INFO) + sizeof (EFI_GUID);\r | |
1247 | Info = AllocateZeroPool (InfoLen);\r | |
1248 | ASSERT (Info != NULL);\r | |
b3548d32 | 1249 | \r |
0c18794e | 1250 | Info->InfoType = EFI_USER_INFO_CREDENTIAL_PROVIDER_RECORD;\r |
1251 | Info->InfoSize = (UINT32) InfoLen;\r | |
1252 | Info->InfoAttribs = EFI_USER_INFO_PROTECTED;\r | |
a0c56a82 LG |
1253 | CopyGuid (&Info->Credential, &gPwdCredentialProviderGuid);\r |
1254 | CopyGuid ((EFI_GUID *)(Info + 1), &gPwdCredentialProviderGuid);\r | |
b3548d32 | 1255 | \r |
0c18794e | 1256 | mPwdInfoHandle->Info[0] = Info;\r |
1257 | mPwdInfoHandle->Count++;\r | |
1258 | \r | |
1259 | //\r | |
1260 | // The second information, Credential Provider name info.\r | |
1261 | //\r | |
1262 | ProvNameStr = GetStringById (STRING_TOKEN (STR_PROVIDER_NAME));\r | |
1263 | ProvStrLen = StrSize (ProvNameStr);\r | |
1264 | InfoLen = sizeof (EFI_USER_INFO) + ProvStrLen;\r | |
1265 | Info = AllocateZeroPool (InfoLen);\r | |
1266 | ASSERT (Info != NULL);\r | |
b3548d32 | 1267 | \r |
0c18794e | 1268 | Info->InfoType = EFI_USER_INFO_CREDENTIAL_PROVIDER_NAME_RECORD;\r |
1269 | Info->InfoSize = (UINT32) InfoLen;\r | |
1270 | Info->InfoAttribs = EFI_USER_INFO_PROTECTED;\r | |
a0c56a82 | 1271 | CopyGuid (&Info->Credential, &gPwdCredentialProviderGuid);\r |
0c18794e | 1272 | CopyMem ((UINT8*)(Info + 1), ProvNameStr, ProvStrLen);\r |
1273 | FreePool (ProvNameStr);\r | |
1274 | \r | |
1275 | mPwdInfoHandle->Info[1] = Info;\r | |
1276 | mPwdInfoHandle->Count++;\r | |
1277 | \r | |
1278 | //\r | |
1279 | // The third information, Credential Provider type info.\r | |
1280 | //\r | |
1281 | InfoLen = sizeof (EFI_USER_INFO) + sizeof (EFI_GUID);\r | |
1282 | Info = AllocateZeroPool (InfoLen);\r | |
1283 | ASSERT (Info != NULL);\r | |
b3548d32 | 1284 | \r |
0c18794e | 1285 | Info->InfoType = EFI_USER_INFO_CREDENTIAL_TYPE_RECORD;\r |
1286 | Info->InfoSize = (UINT32) InfoLen;\r | |
1287 | Info->InfoAttribs = EFI_USER_INFO_PROTECTED;\r | |
a0c56a82 | 1288 | CopyGuid (&Info->Credential, &gPwdCredentialProviderGuid);\r |
0c18794e | 1289 | CopyGuid ((EFI_GUID *)(Info + 1), &gEfiUserCredentialClassPasswordGuid);\r |
b3548d32 | 1290 | \r |
0c18794e | 1291 | mPwdInfoHandle->Info[2] = Info;\r |
1292 | mPwdInfoHandle->Count++;\r | |
b3548d32 | 1293 | \r |
0c18794e | 1294 | //\r |
1295 | // The fourth information, Credential Provider type name info.\r | |
1296 | //\r | |
1297 | ProvNameStr = GetStringById (STRING_TOKEN (STR_PROVIDER_TYPE_NAME));\r | |
1298 | ProvStrLen = StrSize (ProvNameStr);\r | |
1299 | InfoLen = sizeof (EFI_USER_INFO) + ProvStrLen;\r | |
1300 | Info = AllocateZeroPool (InfoLen);\r | |
1301 | ASSERT (Info != NULL);\r | |
b3548d32 | 1302 | \r |
0c18794e | 1303 | Info->InfoType = EFI_USER_INFO_CREDENTIAL_PROVIDER_NAME_RECORD;\r |
1304 | Info->InfoSize = (UINT32) InfoLen;\r | |
1305 | Info->InfoAttribs = EFI_USER_INFO_PROTECTED;\r | |
a0c56a82 | 1306 | CopyGuid (&Info->Credential, &gPwdCredentialProviderGuid);\r |
0c18794e | 1307 | CopyMem ((UINT8*)(Info + 1), ProvNameStr, ProvStrLen);\r |
1308 | FreePool (ProvNameStr);\r | |
b3548d32 | 1309 | \r |
0c18794e | 1310 | mPwdInfoHandle->Info[3] = Info;\r |
1311 | mPwdInfoHandle->Count++;\r | |
1312 | }\r | |
b3548d32 | 1313 | \r |
0c18794e | 1314 | if (*UserInfo == NULL) {\r |
1315 | //\r | |
1316 | // Return the first info handle.\r | |
1317 | //\r | |
1318 | *UserInfo = (EFI_USER_INFO_HANDLE) mPwdInfoHandle->Info[0];\r | |
1319 | return EFI_SUCCESS;\r | |
1320 | }\r | |
b3548d32 | 1321 | \r |
0c18794e | 1322 | //\r |
1323 | // Find information handle in credential info table.\r | |
1324 | //\r | |
1325 | for (Index = 0; Index < mPwdInfoHandle->Count; Index++) {\r | |
1326 | Info = mPwdInfoHandle->Info[Index];\r | |
1327 | if (*UserInfo == (EFI_USER_INFO_HANDLE)Info) {\r | |
1328 | //\r | |
1329 | // The handle is found, get the next one.\r | |
1330 | //\r | |
1331 | if (Index == mPwdInfoHandle->Count - 1) {\r | |
1332 | //\r | |
1333 | // Already last one.\r | |
1334 | //\r | |
1335 | *UserInfo = NULL;\r | |
1336 | return EFI_NOT_FOUND;\r | |
1337 | }\r | |
b3548d32 | 1338 | \r |
0c18794e | 1339 | Index++;\r |
1340 | *UserInfo = (EFI_USER_INFO_HANDLE)mPwdInfoHandle->Info[Index];\r | |
b3548d32 | 1341 | return EFI_SUCCESS;\r |
0c18794e | 1342 | }\r |
1343 | }\r | |
1344 | \r | |
1345 | *UserInfo = NULL;\r | |
1346 | return EFI_NOT_FOUND;\r | |
1347 | }\r | |
1348 | \r | |
6f0b8648 | 1349 | /**\r |
1350 | Delete a user on this credential provider.\r | |
1351 | \r | |
b3548d32 | 1352 | This function deletes a user on this credential provider.\r |
6f0b8648 | 1353 | \r |
1354 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r | |
1355 | @param[in] User The user profile handle to delete.\r | |
1356 | \r | |
1357 | @retval EFI_SUCCESS User profile was successfully deleted.\r | |
b3548d32 LG |
1358 | @retval EFI_ACCESS_DENIED Current user profile does not permit deletion on the user profile handle.\r |
1359 | Either the user profile cannot delete on any user profile or cannot delete\r | |
1360 | on a user profile other than the current user profile.\r | |
6f0b8648 | 1361 | @retval EFI_UNSUPPORTED This credential provider does not support deletion in the pre-OS.\r |
1362 | @retval EFI_DEVICE_ERROR The new credential could not be deleted because of a device error.\r | |
1363 | @retval EFI_INVALID_PARAMETER User does not refer to a valid user profile handle.\r | |
1364 | **/\r | |
1365 | EFI_STATUS\r | |
1366 | EFIAPI\r | |
1367 | CredentialDelete (\r | |
1368 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r | |
1369 | IN EFI_USER_PROFILE_HANDLE User\r | |
1370 | )\r | |
1371 | {\r | |
1372 | EFI_STATUS Status;\r | |
1373 | EFI_USER_INFO *UserInfo;\r | |
1374 | UINT8 *UserId;\r | |
1375 | UINT8 *NewUserId;\r | |
1376 | UINTN Index;\r | |
b3548d32 | 1377 | \r |
6f0b8648 | 1378 | if ((This == NULL) || (User == NULL)) {\r |
1379 | return EFI_INVALID_PARAMETER;\r | |
1380 | }\r | |
1381 | \r | |
1382 | //\r | |
1383 | // Get User Identifier.\r | |
1384 | //\r | |
1385 | UserInfo = NULL;\r | |
1386 | Status = FindUserInfoByType (\r | |
1387 | User,\r | |
1388 | EFI_USER_INFO_IDENTIFIER_RECORD,\r | |
1389 | &UserInfo\r | |
1390 | );\r | |
1391 | if (EFI_ERROR (Status)) {\r | |
1392 | return EFI_INVALID_PARAMETER;\r | |
1393 | }\r | |
1394 | \r | |
1395 | //\r | |
1396 | // Find the user by user identifier in mPwdTable.\r | |
b3548d32 | 1397 | //\r |
6f0b8648 | 1398 | for (Index = 0; Index < mPwdTable->Count; Index++) {\r |
1399 | UserId = (UINT8 *) &mPwdTable->UserInfo[Index].UserId;\r | |
1400 | NewUserId = (UINT8 *) (UserInfo + 1);\r | |
1401 | if (CompareMem (UserId, NewUserId, sizeof (EFI_USER_INFO_IDENTIFIER)) == 0) {\r | |
1402 | //\r | |
1403 | // Found the user, delete it.\r | |
1404 | //\r | |
1405 | ModifyTable (Index, NULL);\r | |
1406 | break;\r | |
1407 | }\r | |
1408 | }\r | |
1409 | \r | |
1410 | FreePool (UserInfo);\r | |
1411 | return EFI_SUCCESS;\r | |
1412 | }\r | |
1413 | \r | |
0c18794e | 1414 | \r |
1415 | /**\r | |
1416 | Main entry for this driver.\r | |
1417 | \r | |
1418 | @param ImageHandle Image handle this driver.\r | |
1419 | @param SystemTable Pointer to SystemTable.\r | |
1420 | \r | |
1421 | @retval EFI_SUCESS This function always complete successfully.\r | |
1422 | \r | |
1423 | **/\r | |
1424 | EFI_STATUS\r | |
1425 | EFIAPI\r | |
1426 | PasswordProviderInit (\r | |
1427 | IN EFI_HANDLE ImageHandle,\r | |
1428 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
1429 | )\r | |
1430 | {\r | |
1431 | EFI_STATUS Status;\r | |
1432 | \r | |
68d151bb DG |
1433 | //\r |
1434 | // It is NOT robust enough to be included in production.\r | |
1435 | //\r | |
1436 | #error "This implementation is just a sample, please comment this line if you really want to use this driver."\r | |
1437 | \r | |
0c18794e | 1438 | //\r |
1439 | // Init credential table.\r | |
1440 | //\r | |
1441 | Status = InitCredentialTable ();\r | |
1442 | if (EFI_ERROR (Status)) {\r | |
1443 | return Status;\r | |
1444 | }\r | |
b3548d32 | 1445 | \r |
0c18794e | 1446 | //\r |
1447 | // Init Form Browser.\r | |
1448 | //\r | |
1449 | Status = InitFormBrowser ();\r | |
1450 | if (EFI_ERROR (Status)) {\r | |
1451 | return Status;\r | |
1452 | }\r | |
b3548d32 | 1453 | \r |
0c18794e | 1454 | //\r |
1455 | // Install protocol interfaces for the password credential provider.\r | |
1456 | //\r | |
1457 | Status = gBS->InstallProtocolInterface (\r | |
1458 | &mCallbackInfo->DriverHandle,\r | |
6f0b8648 | 1459 | &gEfiUserCredential2ProtocolGuid,\r |
0c18794e | 1460 | EFI_NATIVE_INTERFACE,\r |
1461 | &gPwdCredentialProviderDriver\r | |
1462 | );\r | |
1463 | return Status;\r | |
1464 | }\r |