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