2 Password Credential Provider driver implementation.
4 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "PwdCredentialProvider.h"
17 CREDENTIAL_TABLE
*mPwdTable
= NULL
;
18 PWD_PROVIDER_CALLBACK_INFO
*mCallbackInfo
= NULL
;
19 PASSWORD_CREDENTIAL_INFO
*mPwdInfoHandle
= NULL
;
21 HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath
= {
27 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
28 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
31 PWD_CREDENTIAL_PROVIDER_GUID
35 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
37 (UINT8
) (END_DEVICE_PATH_LENGTH
),
38 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
43 EFI_USER_CREDENTIAL_PROTOCOL gPwdCredentialProviderDriver
= {
44 PWD_CREDENTIAL_PROVIDER_GUID
,
45 EFI_USER_CREDENTIAL_CLASS_PASSWORD
,
60 Get string by string id from HII Interface.
63 @param[in] Id String ID to get the string from.
65 @retval CHAR16 * String from ID.
66 @retval NULL If error occurs.
75 // Get the current string for the current Language.
77 return HiiGetString (mCallbackInfo
->HiiHandle
, Id
, NULL
);
82 Expand password table size.
90 CREDENTIAL_TABLE
*NewTable
;
93 Count
= mPwdTable
->MaxCount
+ PASSWORD_TABLE_INC
;
95 // Create new credential table.
97 NewTable
= (CREDENTIAL_TABLE
*) AllocateZeroPool (
98 sizeof (CREDENTIAL_TABLE
) +
99 (Count
- 1) * sizeof (PASSWORD_INFO
)
101 ASSERT (NewTable
!= NULL
);
103 NewTable
->MaxCount
= Count
;
104 NewTable
->Count
= mPwdTable
->Count
;
105 NewTable
->ValidIndex
= mPwdTable
->ValidIndex
;
111 &mPwdTable
->UserInfo
,
112 mPwdTable
->Count
* sizeof (PASSWORD_INFO
)
114 FreePool (mPwdTable
);
115 mPwdTable
= NewTable
;
120 Add or delete info in table, and sync with NV variable.
122 @param[in] Index The index of the password in table. The index begin from 1.
123 If index is found in table, delete the info, else add the
125 @param[in] Info The new password info to add into table.
127 @retval EFI_INVALID_PARAMETER Info is NULL when save the info.
128 @retval EFI_SUCCESS Modify the table successfully.
129 @retval Others Failed to modify the table.
135 IN PASSWORD_INFO
* Info OPTIONAL
140 if (Index
< mPwdTable
->Count
) {
142 // Delete the specified entry.
145 if (Index
!= mPwdTable
->Count
) {
147 &mPwdTable
->UserInfo
[Index
],
148 &mPwdTable
->UserInfo
[mPwdTable
->Count
],
149 sizeof (PASSWORD_INFO
)
157 return EFI_INVALID_PARAMETER
;
160 if (mPwdTable
->Count
>= mPwdTable
->MaxCount
) {
165 &mPwdTable
->UserInfo
[mPwdTable
->Count
],
167 sizeof (PASSWORD_INFO
)
173 // Save the credential table.
175 Status
= gRT
->SetVariable (
177 &gPwdCredentialProviderGuid
,
178 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
179 mPwdTable
->Count
* sizeof (PASSWORD_INFO
),
187 Create a password table.
189 @retval EFI_SUCCESS Create a password table successfully.
190 @retval Others Failed to create a password.
194 InitCredentialTable (
203 // Get Password credential data from NV variable.
207 Status
= gRT
->GetVariable (
209 &gPwdCredentialProviderGuid
,
214 if (Status
== EFI_BUFFER_TOO_SMALL
) {
215 Var
= AllocateZeroPool (VarSize
);
217 return EFI_OUT_OF_RESOURCES
;
219 Status
= gRT
->GetVariable (
221 &gPwdCredentialProviderGuid
,
227 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_FOUND
)) {
232 // Create the password credential table.
234 mPwdTable
= AllocateZeroPool (
235 sizeof (CREDENTIAL_TABLE
) - sizeof (PASSWORD_INFO
) +
236 PASSWORD_TABLE_INC
* sizeof (PASSWORD_INFO
) +
239 if (mPwdTable
== NULL
) {
241 return EFI_OUT_OF_RESOURCES
;
244 mPwdTable
->Count
= VarSize
/ sizeof (PASSWORD_INFO
);
245 mPwdTable
->MaxCount
= mPwdTable
->Count
+ PASSWORD_TABLE_INC
;
246 mPwdTable
->ValidIndex
= 0;
248 CopyMem (mPwdTable
->UserInfo
, Var
, VarSize
);
256 Hash the password to get credential.
258 @param[in] Password Points to the input password.
259 @param[in] PasswordSize The size of password, in bytes.
260 @param[out] Credential Points to the hashed result.
262 @retval TRUE Hash the password successfully.
263 @retval FALSE Failed to hash the password.
269 IN UINTN PasswordSize
,
270 OUT UINT8
*Credential
277 HashSize
= Sha1GetContextSize ();
278 Hash
= AllocatePool (HashSize
);
279 ASSERT (Hash
!= NULL
);
281 Status
= Sha1Init (Hash
);
286 Status
= Sha1Update (Hash
, Password
, PasswordSize
);
291 Status
= Sha1Final (Hash
, Credential
);
300 Get password from user input.
302 @param[in] FirstPwd If True, prompt to input the first password.
303 If False, prompt to input password again.
304 @param[out] Credential Points to the input password.
310 OUT CHAR8
*Credential
314 CHAR16 PasswordMask
[CREDENTIAL_LEN
+ 1];
315 CHAR16 Password
[CREDENTIAL_LEN
];
322 PasswordMask
[PasswordLen
] = L
'_';
323 PasswordMask
[PasswordLen
+ 1] = L
'\0';
324 LineStr
= GetStringById (STRING_TOKEN (STR_DRAW_A_LINE
));
326 QuestionStr
= GetStringById (STRING_TOKEN (STR_INPUT_PASSWORD
));
328 QuestionStr
= GetStringById (STRING_TOKEN (STR_INPUT_PASSWORD_AGAIN
));
331 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
338 FreePool (QuestionStr
);
344 if (Key
.ScanCode
== SCAN_NULL
) {
345 if (Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
347 } else if (Key
.UnicodeChar
== CHAR_BACKSPACE
) {
348 if (PasswordLen
> 0) {
351 } else if ((Key
.UnicodeChar
== CHAR_NULL
) ||
352 (Key
.UnicodeChar
== CHAR_TAB
) ||
353 (Key
.UnicodeChar
== CHAR_LINEFEED
)) {
356 Password
[PasswordLen
] = Key
.UnicodeChar
;
357 PasswordMask
[PasswordLen
] = L
'*';
359 if (PasswordLen
== CREDENTIAL_LEN
) {
366 PasswordLen
= PasswordLen
* sizeof (CHAR16
);
367 GenerateCredential (Password
, PasswordLen
, (UINT8
*)Credential
);
371 Check whether the password can be found on this provider.
373 @param[in] Password The password to be found.
375 @retval EFI_SUCCESS Found password sucessfully.
376 @retval EFI_NOT_FOUND Fail to find the password.
388 // Check password credential.
390 mPwdTable
->ValidIndex
= 0;
391 for (Index
= 0; Index
< mPwdTable
->Count
; Index
++) {
392 Pwd
= mPwdTable
->UserInfo
[Index
].Password
;
393 if (CompareMem (Pwd
, Password
, CREDENTIAL_LEN
) == 0) {
394 mPwdTable
->ValidIndex
= Index
+ 1;
399 return EFI_NOT_FOUND
;
404 Find a user infomation record by the information record type.
406 This function searches all user information records of User from beginning
407 until either the information is found, or there are no more user infomation
408 records. A match occurs when a Info.InfoType field matches the user information
411 @param[in] User Points to the user profile record to search.
412 @param[in] InfoType The infomation type to be searched.
413 @param[out] Info Points to the user info found, the caller is responsible
416 @retval EFI_SUCCESS Find the user information successfully.
417 @retval Others Fail to find the user information.
422 IN EFI_USER_PROFILE_HANDLE User
,
424 OUT EFI_USER_INFO
**Info
428 EFI_USER_INFO
*UserInfo
;
430 EFI_USER_INFO_HANDLE UserInfoHandle
;
431 EFI_USER_MANAGER_PROTOCOL
*UserManager
;
434 // Find user information by information type.
437 return EFI_INVALID_PARAMETER
;
440 Status
= gBS
->LocateProtocol (
441 &gEfiUserManagerProtocolGuid
,
443 (VOID
**) &UserManager
445 if (EFI_ERROR (Status
)) {
446 return EFI_NOT_FOUND
;
450 // Get each user information.
453 UserInfoHandle
= NULL
;
457 Status
= UserManager
->GetNextInfo (UserManager
, User
, &UserInfoHandle
);
458 if (EFI_ERROR (Status
)) {
464 Status
= UserManager
->GetInfo (
471 if (Status
== EFI_BUFFER_TOO_SMALL
) {
472 if (UserInfo
!= NULL
) {
475 UserInfo
= AllocateZeroPool (UserInfoSize
);
476 if (UserInfo
== NULL
) {
477 return EFI_OUT_OF_RESOURCES
;
479 Status
= UserManager
->GetInfo (
487 if (EFI_ERROR (Status
)) {
491 ASSERT (UserInfo
!= NULL
);
492 if (UserInfo
->InfoType
== InfoType
) {
498 if (UserInfo
!= NULL
) {
506 This function processes the results of changes in configuration.
508 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
509 @param Action Specifies the type of action taken by the browser.
510 @param QuestionId A unique value which is sent to the original
511 exporting driver so that it can identify the type
513 @param Type The type of value for the question.
514 @param Value A pointer to the data being sent to the original
516 @param ActionRequest On return, points to the action requested by the
519 @retval EFI_SUCCESS The callback successfully handled the action.
520 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
521 variable and its data.
522 @retval EFI_DEVICE_ERROR The variable could not be saved.
523 @retval EFI_UNSUPPORTED The specified Action is not supported by the
529 CredentialDriverCallback (
530 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
531 IN EFI_BROWSER_ACTION Action
,
532 IN EFI_QUESTION_ID QuestionId
,
534 IN EFI_IFR_TYPE_VALUE
*Value
,
535 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
540 CHAR8 Password
[CREDENTIAL_LEN
];
543 if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
544 if (QuestionId
== KEY_GET_PASSWORD
) {
546 // Get and check password.
548 GetPassword (TRUE
, Password
);
549 Status
= CheckPassword (Password
);
550 if (EFI_ERROR (Status
)) {
551 PromptStr
= GetStringById (STRING_TOKEN (STR_PASSWORD_INCORRECT
));
553 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
560 FreePool (PromptStr
);
563 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
569 // All other action return unsupported.
571 return EFI_UNSUPPORTED
;
576 This function allows a caller to extract the current configuration for one
577 or more named elements from the target driver.
580 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
581 @param Request A null-terminated Unicode string in <ConfigRequest> format.
582 @param Progress On return, points to a character in the Request string.
583 Points to the string's null terminator if request was successful.
584 Points to the most recent '&' before the first failing name/value
585 pair (or the beginning of the string if the failure is in the
586 first name/value pair) if the request was not successful.
587 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
588 has all values filled in for the names in the Request string.
589 String to be allocated by the called function.
591 @retval EFI_SUCCESS The Results is filled with the requested values.
592 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
593 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
594 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
600 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
601 IN CONST EFI_STRING Request
,
602 OUT EFI_STRING
*Progress
,
603 OUT EFI_STRING
*Results
606 if (Progress
== NULL
|| Results
== NULL
) {
607 return EFI_INVALID_PARAMETER
;
610 return EFI_NOT_FOUND
;
614 This function processes the results of changes in configuration.
617 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
618 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
619 @param Progress A pointer to a string filled in with the offset of the most
620 recent '&' before the first failing name/value pair (or the
621 beginning of the string if the failure is in the first
622 name/value pair) or the terminating NULL if all was successful.
624 @retval EFI_SUCCESS The Results is processed successfully.
625 @retval EFI_INVALID_PARAMETER Configuration is NULL.
626 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
632 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
633 IN CONST EFI_STRING Configuration
,
634 OUT EFI_STRING
*Progress
637 if (Configuration
== NULL
|| Progress
== NULL
) {
638 return EFI_INVALID_PARAMETER
;
641 return EFI_NOT_FOUND
;
645 This function initialize the data mainly used in form browser.
647 @retval EFI_SUCCESS Initialize form data successfully.
648 @retval Others Fail to Initialize form data.
657 PWD_PROVIDER_CALLBACK_INFO
*CallbackInfo
;
660 // Initialize driver private data.
662 CallbackInfo
= AllocateZeroPool (sizeof (PWD_PROVIDER_CALLBACK_INFO
));
663 if (CallbackInfo
== NULL
) {
664 return EFI_OUT_OF_RESOURCES
;
667 CallbackInfo
->Signature
= PWD_PROVIDER_SIGNATURE
;
668 CallbackInfo
->ConfigAccess
.ExtractConfig
= FakeExtractConfig
;
669 CallbackInfo
->ConfigAccess
.RouteConfig
= FakeRouteConfig
;
670 CallbackInfo
->ConfigAccess
.Callback
= CredentialDriverCallback
;
671 CallbackInfo
->DriverHandle
= NULL
;
674 // Install Device Path Protocol and Config Access protocol to driver handle.
676 Status
= gBS
->InstallMultipleProtocolInterfaces (
677 &CallbackInfo
->DriverHandle
,
678 &gEfiDevicePathProtocolGuid
,
679 &mHiiVendorDevicePath
,
680 &gEfiHiiConfigAccessProtocolGuid
,
681 &CallbackInfo
->ConfigAccess
,
684 ASSERT_EFI_ERROR (Status
);
689 CallbackInfo
->HiiHandle
= HiiAddPackages (
690 &gPwdCredentialProviderGuid
,
691 CallbackInfo
->DriverHandle
,
692 PwdCredentialProviderStrings
,
693 PwdCredentialProviderVfrBin
,
696 if (CallbackInfo
->HiiHandle
== NULL
) {
697 return EFI_OUT_OF_RESOURCES
;
699 mCallbackInfo
= CallbackInfo
;
706 Enroll a user on a credential provider.
708 This function enrolls and deletes a user profile using this credential provider.
709 If a user profile is successfully enrolled, it calls the User Manager Protocol
710 function Notify() to notify the user manager driver that credential information
711 has changed. If an enrolled user does exist, delete the user on the credential
714 @param[in] This Points to this instance of EFI_USER_CREDENTIAL_PROTOCOL.
715 @param[in] User The user profile to enroll.
717 @retval EFI_SUCCESS User profile was successfully enrolled.
718 @retval EFI_ACCESS_DENIED Current user profile does not permit enrollment on the
719 user profile handle. Either the user profile cannot enroll
720 on any user profile or cannot enroll on a user profile
721 other than the current user profile.
722 @retval EFI_UNSUPPORTED This credential provider does not support enrollment in
724 @retval EFI_DEVICE_ERROR The new credential could not be created because of a device
726 @retval EFI_INVALID_PARAMETER User does not refer to a valid user profile handle.
732 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
,
733 IN EFI_USER_PROFILE_HANDLE User
738 PASSWORD_INFO PwdInfo
;
739 EFI_USER_INFO
*UserInfo
;
740 CHAR8 Password
[CREDENTIAL_LEN
];
742 EFI_USER_MANAGER_PROTOCOL
*UserManager
;
748 if ((This
== NULL
) || (User
== NULL
)) {
749 return EFI_INVALID_PARAMETER
;
752 Status
= gBS
->LocateProtocol (
753 &gEfiUserManagerProtocolGuid
,
755 (VOID
**) &UserManager
757 if (EFI_ERROR (Status
)) {
758 return EFI_UNSUPPORTED
;
762 // Get User Identifier.
765 Status
= FindUserInfoByType (
767 EFI_USER_INFO_IDENTIFIER_RECORD
,
770 if (EFI_ERROR (Status
)) {
771 return EFI_INVALID_PARAMETER
;
775 // If User exists in mPwdTable, delete User.
777 for (Index
= 0; Index
< mPwdTable
->Count
; Index
++) {
778 UserId
= (UINT8
*) &mPwdTable
->UserInfo
[Index
].UserId
;
779 NewUserId
= (UINT8
*) (UserInfo
+ 1);
780 if (CompareMem (UserId
, NewUserId
, sizeof (EFI_USER_INFO_IDENTIFIER
)) == 0) {
782 // Delete the existing password.
785 return ModifyTable (Index
, NULL
);
790 // The User doesn't exist in mPwdTable; Enroll the new User.
796 GetPassword (TRUE
, PwdInfo
.Password
);
799 // Input password again.
801 GetPassword (FALSE
, Password
);
804 // Compare the two password consistency.
806 if (CompareMem (PwdInfo
.Password
, Password
, CREDENTIAL_LEN
) == 0) {
810 QuestionStr
= GetStringById (STRING_TOKEN (STR_PASSWORD_MISMATCH
));
811 PromptStr
= GetStringById (STRING_TOKEN (STR_INPUT_PASSWORD_AGAIN
));
813 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
820 FreePool (QuestionStr
);
821 FreePool (PromptStr
);
826 (UINT8
*) (UserInfo
+ 1),
827 sizeof (EFI_USER_INFO_IDENTIFIER
)
832 // Save the new added entry.
834 Status
= ModifyTable (mPwdTable
->Count
, &PwdInfo
);
835 if (EFI_ERROR (Status
)) {
840 // Notify the user manager driver that credential information has changed.
842 UserManager
->Notify (UserManager
, mCallbackInfo
->DriverHandle
);
849 Returns the user interface information used during user identification.
851 This function returns information about the form used when interacting with the
852 user during user identification. The form is the first enabled form in the form-set
853 class EFI_HII_USER_CREDENTIAL_FORMSET_GUID installed on the HII handle HiiHandle. If
854 the user credential provider does not require a form to identify the user, then this
855 function should return EFI_NOT_FOUND.
857 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
858 @param[out] Hii On return, holds the HII database handle.
859 @param[out] FormSetId On return, holds the identifier of the form set which contains
860 the form used during user identification.
861 @param[out] FormId On return, holds the identifier of the form used during user
864 @retval EFI_SUCCESS Form returned successfully.
865 @retval EFI_NOT_FOUND Form not returned.
866 @retval EFI_INVALID_PARAMETER Hii is NULL or FormSetId is NULL or FormId is NULL.
872 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
,
873 OUT EFI_HII_HANDLE
*Hii
,
874 OUT EFI_GUID
*FormSetId
,
875 OUT EFI_FORM_ID
*FormId
878 if ((This
== NULL
) || (Hii
== NULL
) ||
879 (FormSetId
== NULL
) || (FormId
== NULL
)) {
880 return EFI_INVALID_PARAMETER
;
883 *Hii
= mCallbackInfo
->HiiHandle
;
884 *FormId
= FORMID_GET_PASSWORD_FORM
;
885 CopyGuid (FormSetId
, &gPwdCredentialProviderGuid
);
892 Returns bitmap used to describe the credential provider type.
894 This optional function returns a bitmap that is less than or equal to the number
895 of pixels specified by Width and Height. If no such bitmap exists, then EFI_NOT_FOUND
898 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
899 @param[in, out] Width On entry, points to the desired bitmap width. If NULL then no
900 bitmap information will be returned. On exit, points to the
901 width of the bitmap returned.
902 @param[in, out] Height On entry, points to the desired bitmap height. If NULL then no
903 bitmap information will be returned. On exit, points to the
904 height of the bitmap returned
905 @param[out] Hii On return, holds the HII database handle.
906 @param[out] Image On return, holds the HII image identifier.
908 @retval EFI_SUCCESS Image identifier returned successfully.
909 @retval EFI_NOT_FOUND Image identifier not returned.
910 @retval EFI_INVALID_PARAMETER Hii is NULL or Image is NULL.
916 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
,
918 IN OUT UINTN
*Height
,
919 OUT EFI_HII_HANDLE
*Hii
,
920 OUT EFI_IMAGE_ID
*Image
923 if ((This
== NULL
) || (Hii
== NULL
) || (Image
== NULL
)) {
924 return EFI_INVALID_PARAMETER
;
926 return EFI_NOT_FOUND
;
931 Returns string used to describe the credential provider type.
933 This function returns a string which describes the credential provider. If no
934 such string exists, then EFI_NOT_FOUND is returned.
936 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
937 @param[out] Hii On return, holds the HII database handle.
938 @param[out] String On return, holds the HII string identifier.
940 @retval EFI_SUCCESS String identifier returned successfully.
941 @retval EFI_NOT_FOUND String identifier not returned.
942 @retval EFI_INVALID_PARAMETER Hii is NULL or String is NULL.
948 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
,
949 OUT EFI_HII_HANDLE
*Hii
,
950 OUT EFI_STRING_ID
*String
953 if ((This
== NULL
) || (Hii
== NULL
) || (String
== NULL
)) {
954 return EFI_INVALID_PARAMETER
;
958 // Set Hii handle and String ID.
960 *Hii
= mCallbackInfo
->HiiHandle
;
961 *String
= STRING_TOKEN (STR_CREDENTIAL_TITLE
);
968 Return the user identifier associated with the currently authenticated user.
970 This function returns the user identifier of the user authenticated by this credential
971 provider. This function is called after the credential-related information has been
972 submitted on a form, OR after a call to Default() has returned that this credential is
975 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
976 @param[in] User The user profile handle of the user profile currently being
977 considered by the user identity manager. If NULL, then no user
978 profile is currently under consideration.
979 @param[out] Identifier On return, points to the user identifier.
981 @retval EFI_SUCCESS User identifier returned successfully.
982 @retval EFI_NOT_READY No user identifier can be returned.
983 @retval EFI_ACCESS_DENIED The user has been locked out of this user credential.
984 @retval EFI_INVALID_PARAMETER This is NULL, or Identifier is NULL.
985 @retval EFI_NOT_FOUND User is not NULL, and the specified user handle can't be
986 found in user profile database
992 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
,
993 IN EFI_USER_PROFILE_HANDLE User
,
994 OUT EFI_USER_INFO_IDENTIFIER
*Identifier
999 EFI_USER_INFO
*UserInfo
;
1005 if ((This
== NULL
) || (Identifier
== NULL
)) {
1006 return EFI_INVALID_PARAMETER
;
1009 if (mPwdTable
->ValidIndex
== 0) {
1011 // No password input, or the input password doesn't match
1012 // anyone in PwdTable.
1014 return EFI_NOT_READY
;
1019 // Return the user ID whose password matches the input password.
1023 &mPwdTable
->UserInfo
[mPwdTable
->ValidIndex
- 1].UserId
,
1024 sizeof (EFI_USER_INFO_IDENTIFIER
)
1030 // Get the User's ID.
1032 Status
= FindUserInfoByType (
1034 EFI_USER_INFO_IDENTIFIER_RECORD
,
1037 if (EFI_ERROR (Status
)) {
1038 return EFI_NOT_FOUND
;
1042 // Check whether the input password matches one in PwdTable.
1044 for (Index
= 0; Index
< mPwdTable
->Count
; Index
++) {
1045 UserId
= (UINT8
*) &mPwdTable
->UserInfo
[Index
].UserId
;
1046 NewUserId
= (UINT8
*) (UserInfo
+ 1);
1047 if (CompareMem (UserId
, NewUserId
, sizeof (EFI_USER_INFO_IDENTIFIER
)) == 0) {
1048 Pwd
= mPwdTable
->UserInfo
[Index
].Password
;
1049 NewPwd
= mPwdTable
->UserInfo
[mPwdTable
->ValidIndex
- 1].Password
;
1050 if (CompareMem (Pwd
, NewPwd
, CREDENTIAL_LEN
) == 0) {
1051 CopyMem (Identifier
, UserId
, sizeof (EFI_USER_INFO_IDENTIFIER
));
1052 FreePool (UserInfo
);
1058 FreePool (UserInfo
);
1059 return EFI_NOT_READY
;
1064 Indicate that user interface interaction has begun for the specified credential.
1066 This function is called when a credential provider is selected by the user. If
1067 AutoLogon returns FALSE, then the user interface will be constructed by the User
1070 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
1071 @param[out] AutoLogon On return, points to the credential provider's capabilities
1072 after the credential provider has been selected by the user.
1074 @retval EFI_SUCCESS Credential provider successfully selected.
1075 @retval EFI_INVALID_PARAMETER AutoLogon is NULL.
1081 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
,
1082 OUT EFI_CREDENTIAL_LOGON_FLAGS
*AutoLogon
1085 if ((This
== NULL
) || (AutoLogon
== NULL
)) {
1086 return EFI_INVALID_PARAMETER
;
1095 Indicate that user interface interaction has ended for the specified credential.
1097 This function is called when a credential provider is deselected by the user.
1099 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
1101 @retval EFI_SUCCESS Credential provider successfully deselected.
1106 CredentialDeselect (
1107 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
1111 return EFI_INVALID_PARAMETER
;
1118 Return the default logon behavior for this user credential.
1120 This function reports the default login behavior regarding this credential provider.
1122 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
1123 @param[out] AutoLogon On return, holds whether the credential provider should be used
1124 by default to automatically log on the user.
1126 @retval EFI_SUCCESS Default information successfully returned.
1127 @retval EFI_INVALID_PARAMETER AutoLogon is NULL.
1133 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
,
1134 OUT EFI_CREDENTIAL_LOGON_FLAGS
*AutoLogon
1137 if ((This
== NULL
) || (AutoLogon
== NULL
)) {
1138 return EFI_INVALID_PARAMETER
;
1147 Return information attached to the credential provider.
1149 This function returns user information.
1151 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
1152 @param[in] UserInfo Handle of the user information data record.
1153 @param[out] Info On entry, points to a buffer of at least *InfoSize bytes. On
1154 exit, holds the user information. If the buffer is too small
1155 to hold the information, then EFI_BUFFER_TOO_SMALL is returned
1156 and InfoSize is updated to contain the number of bytes actually
1158 @param[in, out] InfoSize On entry, points to the size of Info. On return, points to the
1159 size of the user information.
1161 @retval EFI_SUCCESS Information returned successfully.
1162 @retval EFI_BUFFER_TOO_SMALL The size specified by InfoSize is too small to hold all of the
1163 user information. The size required is returned in *InfoSize.
1164 @retval EFI_INVALID_PARAMETER Info is NULL or InfoSize is NULL.
1165 @retval EFI_NOT_FOUND The specified UserInfo does not refer to a valid user info handle.
1171 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
,
1172 IN EFI_USER_INFO_HANDLE UserInfo
,
1173 OUT EFI_USER_INFO
*Info
,
1174 IN OUT UINTN
*InfoSize
1177 EFI_USER_INFO
*CredentialInfo
;
1180 if ((This
== NULL
) || (InfoSize
== NULL
) || (Info
== NULL
)) {
1181 return EFI_INVALID_PARAMETER
;
1184 if ((UserInfo
== NULL
) || (mPwdInfoHandle
== NULL
)) {
1185 return EFI_NOT_FOUND
;
1189 // Find information handle in credential info table.
1191 for (Index
= 0; Index
< mPwdInfoHandle
->Count
; Index
++) {
1192 CredentialInfo
= mPwdInfoHandle
->Info
[Index
];
1193 if (UserInfo
== (EFI_USER_INFO_HANDLE
)CredentialInfo
) {
1195 // The handle is found, copy the user info.
1197 if (CredentialInfo
->InfoSize
> *InfoSize
) {
1198 *InfoSize
= CredentialInfo
->InfoSize
;
1199 return EFI_BUFFER_TOO_SMALL
;
1201 CopyMem (Info
, CredentialInfo
, CredentialInfo
->InfoSize
);
1206 return EFI_NOT_FOUND
;
1211 Enumerate all of the user informations on the credential provider.
1213 This function returns the next user information record. To retrieve the first user
1214 information record handle, point UserInfo at a NULL. Each subsequent call will retrieve
1215 another user information record handle until there are no more, at which point UserInfo
1218 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.
1219 @param[in, out] UserInfo On entry, points to the previous user information handle or NULL
1220 to start enumeration. On exit, points to the next user information
1221 handle or NULL if there is no more user information.
1223 @retval EFI_SUCCESS User information returned.
1224 @retval EFI_NOT_FOUND No more user information found.
1225 @retval EFI_INVALID_PARAMETER UserInfo is NULL.
1230 CredentialGetNextInfo (
1231 IN CONST EFI_USER_CREDENTIAL_PROTOCOL
*This
,
1232 IN OUT EFI_USER_INFO_HANDLE
*UserInfo
1235 EFI_USER_INFO
*Info
;
1236 CHAR16
*ProvNameStr
;
1241 if ((This
== NULL
) || (UserInfo
== NULL
)) {
1242 return EFI_INVALID_PARAMETER
;
1245 if (mPwdInfoHandle
== NULL
) {
1247 // Initilized user info table. There are 4 user info records in the table.
1249 InfoLen
= sizeof (PASSWORD_CREDENTIAL_INFO
) + (4 - 1) * sizeof (EFI_USER_INFO
*);
1250 mPwdInfoHandle
= AllocateZeroPool (InfoLen
);
1251 if (mPwdInfoHandle
== NULL
) {
1253 return EFI_NOT_FOUND
;
1257 // The first information, Credential Provider info.
1259 InfoLen
= sizeof (EFI_USER_INFO
) + sizeof (EFI_GUID
);
1260 Info
= AllocateZeroPool (InfoLen
);
1261 ASSERT (Info
!= NULL
);
1263 Info
->InfoType
= EFI_USER_INFO_CREDENTIAL_PROVIDER_RECORD
;
1264 Info
->InfoSize
= (UINT32
) InfoLen
;
1265 Info
->InfoAttribs
= EFI_USER_INFO_PROTECTED
;
1266 CopyGuid (&Info
->Credential
, &gPwdCredentialProviderGuid
);
1267 CopyGuid ((EFI_GUID
*)(Info
+ 1), &gPwdCredentialProviderGuid
);
1269 mPwdInfoHandle
->Info
[0] = Info
;
1270 mPwdInfoHandle
->Count
++;
1273 // The second information, Credential Provider name info.
1275 ProvNameStr
= GetStringById (STRING_TOKEN (STR_PROVIDER_NAME
));
1276 ProvStrLen
= StrSize (ProvNameStr
);
1277 InfoLen
= sizeof (EFI_USER_INFO
) + ProvStrLen
;
1278 Info
= AllocateZeroPool (InfoLen
);
1279 ASSERT (Info
!= NULL
);
1281 Info
->InfoType
= EFI_USER_INFO_CREDENTIAL_PROVIDER_NAME_RECORD
;
1282 Info
->InfoSize
= (UINT32
) InfoLen
;
1283 Info
->InfoAttribs
= EFI_USER_INFO_PROTECTED
;
1284 CopyGuid (&Info
->Credential
, &gPwdCredentialProviderGuid
);
1285 CopyMem ((UINT8
*)(Info
+ 1), ProvNameStr
, ProvStrLen
);
1286 FreePool (ProvNameStr
);
1288 mPwdInfoHandle
->Info
[1] = Info
;
1289 mPwdInfoHandle
->Count
++;
1292 // The third information, Credential Provider type info.
1294 InfoLen
= sizeof (EFI_USER_INFO
) + sizeof (EFI_GUID
);
1295 Info
= AllocateZeroPool (InfoLen
);
1296 ASSERT (Info
!= NULL
);
1298 Info
->InfoType
= EFI_USER_INFO_CREDENTIAL_TYPE_RECORD
;
1299 Info
->InfoSize
= (UINT32
) InfoLen
;
1300 Info
->InfoAttribs
= EFI_USER_INFO_PROTECTED
;
1301 CopyGuid (&Info
->Credential
, &gPwdCredentialProviderGuid
);
1302 CopyGuid ((EFI_GUID
*)(Info
+ 1), &gEfiUserCredentialClassPasswordGuid
);
1304 mPwdInfoHandle
->Info
[2] = Info
;
1305 mPwdInfoHandle
->Count
++;
1308 // The fourth information, Credential Provider type name info.
1310 ProvNameStr
= GetStringById (STRING_TOKEN (STR_PROVIDER_TYPE_NAME
));
1311 ProvStrLen
= StrSize (ProvNameStr
);
1312 InfoLen
= sizeof (EFI_USER_INFO
) + ProvStrLen
;
1313 Info
= AllocateZeroPool (InfoLen
);
1314 ASSERT (Info
!= NULL
);
1316 Info
->InfoType
= EFI_USER_INFO_CREDENTIAL_PROVIDER_NAME_RECORD
;
1317 Info
->InfoSize
= (UINT32
) InfoLen
;
1318 Info
->InfoAttribs
= EFI_USER_INFO_PROTECTED
;
1319 CopyGuid (&Info
->Credential
, &gPwdCredentialProviderGuid
);
1320 CopyMem ((UINT8
*)(Info
+ 1), ProvNameStr
, ProvStrLen
);
1321 FreePool (ProvNameStr
);
1323 mPwdInfoHandle
->Info
[3] = Info
;
1324 mPwdInfoHandle
->Count
++;
1327 if (*UserInfo
== NULL
) {
1329 // Return the first info handle.
1331 *UserInfo
= (EFI_USER_INFO_HANDLE
) mPwdInfoHandle
->Info
[0];
1336 // Find information handle in credential info table.
1338 for (Index
= 0; Index
< mPwdInfoHandle
->Count
; Index
++) {
1339 Info
= mPwdInfoHandle
->Info
[Index
];
1340 if (*UserInfo
== (EFI_USER_INFO_HANDLE
)Info
) {
1342 // The handle is found, get the next one.
1344 if (Index
== mPwdInfoHandle
->Count
- 1) {
1346 // Already last one.
1349 return EFI_NOT_FOUND
;
1353 *UserInfo
= (EFI_USER_INFO_HANDLE
)mPwdInfoHandle
->Info
[Index
];
1359 return EFI_NOT_FOUND
;
1364 Main entry for this driver.
1366 @param ImageHandle Image handle this driver.
1367 @param SystemTable Pointer to SystemTable.
1369 @retval EFI_SUCESS This function always complete successfully.
1374 PasswordProviderInit (
1375 IN EFI_HANDLE ImageHandle
,
1376 IN EFI_SYSTEM_TABLE
*SystemTable
1382 // Init credential table.
1384 Status
= InitCredentialTable ();
1385 if (EFI_ERROR (Status
)) {
1390 // Init Form Browser.
1392 Status
= InitFormBrowser ();
1393 if (EFI_ERROR (Status
)) {
1398 // Install protocol interfaces for the password credential provider.
1400 Status
= gBS
->InstallProtocolInterface (
1401 &mCallbackInfo
->DriverHandle
,
1402 &gEfiUserCredentialProtocolGuid
,
1403 EFI_NATIVE_INTERFACE
,
1404 &gPwdCredentialProviderDriver