2 This driver is a configuration tool for adding, deleting or modifying user
3 profiles, including gathering the necessary information to ascertain their
4 identity in the future, updating user access policy and identification
7 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include "UserProfileManager.h"
20 EFI_USER_MANAGER_PROTOCOL
*mUserManager
= NULL
;
21 CREDENTIAL_PROVIDER_INFO
*mProviderInfo
= NULL
;
22 UINT8 mProviderChoice
;
23 UINT8 mConncetLogical
;
24 USER_INFO_ACCESS mAccessInfo
;
26 USER_PROFILE_MANAGER_CALLBACK_INFO
*mCallbackInfo
;
27 HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath
= {
33 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
34 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
37 USER_PROFILE_MANAGER_GUID
41 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
43 (UINT8
) (END_DEVICE_PATH_LENGTH
),
44 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
51 Get string by string id from HII Interface.
54 @param[in] Id String ID to get the string from.
56 @retval CHAR16 * String from ID.
57 @retval NULL If error occurs.
66 // Get the current string for the current Language.
68 return HiiGetString (mCallbackInfo
->HiiHandle
, Id
, NULL
);
73 This function gets all the credential providers in the system and saved them
76 @retval EFI_SUCESS Init credential provider database successfully.
77 @retval Others Fail to init credential provider database.
87 EFI_HANDLE
*HandleBuf
;
91 // Try to find all the user credential provider driver.
95 Status
= gBS
->LocateHandleBuffer (
97 &gEfiUserCredential2ProtocolGuid
,
102 if (EFI_ERROR (Status
)) {
107 // Get provider infomation.
109 if (mProviderInfo
!= NULL
) {
110 FreePool (mProviderInfo
);
112 mProviderInfo
= AllocateZeroPool (
113 sizeof (CREDENTIAL_PROVIDER_INFO
) -
114 sizeof (EFI_USER_CREDENTIAL2_PROTOCOL
*) +
115 HandleCount
* sizeof (EFI_USER_CREDENTIAL2_PROTOCOL
*)
117 if (mProviderInfo
== NULL
) {
118 FreePool (HandleBuf
);
119 return EFI_OUT_OF_RESOURCES
;
122 mProviderInfo
->Count
= HandleCount
;
123 for (Index
= 0; Index
< HandleCount
; Index
++) {
124 Status
= gBS
->HandleProtocol (
126 &gEfiUserCredential2ProtocolGuid
,
127 (VOID
**) &mProviderInfo
->Provider
[Index
]
129 if (EFI_ERROR (Status
)) {
130 FreePool (HandleBuf
);
131 FreePool (mProviderInfo
);
132 mProviderInfo
= NULL
;
137 FreePool (HandleBuf
);
143 This function processes changes in user profile configuration.
145 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
146 @param Action Specifies the type of action taken by the browser.
147 @param QuestionId A unique value which is sent to the original
148 exporting driver so that it can identify the type
150 @param Type The type of value for the question.
151 @param Value A pointer to the data being sent to the original
153 @param ActionRequest On return, points to the action requested by the
156 @retval EFI_SUCCESS The callback successfully handled the action.
157 @retval Others Fail to handle the action.
162 UserProfileManagerCallback (
163 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
164 IN EFI_BROWSER_ACTION Action
,
165 IN EFI_QUESTION_ID QuestionId
,
167 IN EFI_IFR_TYPE_VALUE
*Value
,
168 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
173 UINT32 CurrentAccessRight
;
176 VOID
*StartOpCodeHandle
;
177 VOID
*EndOpCodeHandle
;
178 EFI_IFR_GUID_LABEL
*StartLabel
;
179 EFI_IFR_GUID_LABEL
*EndLabel
;
180 EFI_USER_PROFILE_HANDLE CurrentUser
;
182 Status
= EFI_SUCCESS
;
185 case EFI_BROWSER_ACTION_FORM_OPEN
:
188 // Update user manage Form when user manage Form is opened.
189 // This will be done only in FORM_OPEN CallBack of question with QUESTIONID_USER_MANAGE from user manage Form.
191 if (QuestionId
!= QUESTIONID_USER_MANAGE
) {
199 mUserManager
->Current (mUserManager
, &CurrentUser
);
200 if (CurrentUser
== NULL
) {
201 DEBUG ((DEBUG_ERROR
, "Error: current user does not exist!\n"));
202 return EFI_NOT_READY
;
206 // Get current user's right information.
208 Status
= GetAccessRight (&CurrentAccessRight
);
209 if (EFI_ERROR (Status
)) {
210 CurrentAccessRight
= EFI_USER_INFO_ACCESS_ENROLL_SELF
;
214 // Init credential provider information.
216 Status
= InitProviderInfo ();
217 if (EFI_ERROR (Status
)) {
222 // Initialize the container for dynamic opcodes.
224 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
225 ASSERT (StartOpCodeHandle
!= NULL
);
227 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
228 ASSERT (EndOpCodeHandle
!= NULL
);
231 // Create Hii Extend Label OpCode.
233 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (
237 sizeof (EFI_IFR_GUID_LABEL
)
239 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
240 StartLabel
->Number
= LABEL_USER_MANAGE_FUNC
;
242 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (
246 sizeof (EFI_IFR_GUID_LABEL
)
248 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
249 EndLabel
->Number
= LABEL_END
;
252 // Add user profile option.
254 if ((CurrentAccessRight
== EFI_USER_INFO_ACCESS_MANAGE
) ||
255 (CurrentAccessRight
== EFI_USER_INFO_ACCESS_ENROLL_OTHERS
)
257 HiiCreateActionOpCode (
258 StartOpCodeHandle
, // Container for dynamic created opcodes
259 KEY_ADD_USER
, // Question ID
260 STRING_TOKEN (STR_ADD_USER_TITLE
), // Prompt text
261 STRING_TOKEN (STR_ADD_USER_HELP
), // Help text
262 EFI_IFR_FLAG_CALLBACK
, // Question flag
263 0 // Action String ID
268 // Add modify user profile option.
270 HiiCreateGotoOpCode (
271 StartOpCodeHandle
, // Container for dynamic created opcodes
272 FORMID_MODIFY_USER
, // Target Form ID
273 STRING_TOKEN (STR_MODIFY_USER_TITLE
), // Prompt text
274 STRING_TOKEN (STR_MODIFY_USER_HELP
), // Help text
275 EFI_IFR_FLAG_CALLBACK
, // Question flag
276 KEY_MODIFY_USER
// Question ID
280 // Add delete user profile option
282 if (CurrentAccessRight
== EFI_USER_INFO_ACCESS_MANAGE
) {
283 HiiCreateGotoOpCode (
284 StartOpCodeHandle
, // Container for dynamic created opcodes
285 FORMID_DEL_USER
, // Target Form ID
286 STRING_TOKEN (STR_DELETE_USER_TITLE
), // Prompt text
287 STRING_TOKEN (STR_DELETE_USER_HELP
), // Help text
288 EFI_IFR_FLAG_CALLBACK
, // Question flag
289 KEY_DEL_USER
// Question ID
294 mCallbackInfo
->HiiHandle
, // HII handle
295 &gUserProfileManagerGuid
, // Formset GUID
296 FORMID_USER_MANAGE
, // Form ID
297 StartOpCodeHandle
, // Label for where to insert opcodes
298 EndOpCodeHandle
// Replace data
301 HiiFreeOpCodeHandle (StartOpCodeHandle
);
302 HiiFreeOpCodeHandle (EndOpCodeHandle
);
308 case EFI_BROWSER_ACTION_FORM_CLOSE
:
309 Status
= EFI_SUCCESS
;
312 case EFI_BROWSER_ACTION_CHANGED
:
315 // Handle the request from form.
317 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
318 return EFI_INVALID_PARAMETER
;
322 // Judge first 2 bits.
324 switch (QuestionId
& KEY_FIRST_FORM_MASK
) {
326 // Add user profile operation.
333 // Delete user profile operation.
337 // Judge next 2 bits.
339 switch (QuestionId
& KEY_SECOND_FORM_MASK
) {
341 // Delete specified user profile.
343 case KEY_SELECT_USER
:
344 DeleteUser ((UINT8
) QuestionId
);
346 // Update select user form after delete a user.
348 SelectUserToDelete ();
357 // Modify user profile operation.
359 case KEY_MODIFY_USER
:
361 // Judge next 2 bits.
363 switch (QuestionId
& KEY_SECOND_FORM_MASK
) {
365 // Enter user profile information form.
367 case KEY_SELECT_USER
:
369 // Judge next 3 bits.
371 switch (QuestionId
& KEY_MODIFY_INFO_MASK
) {
375 case KEY_MODIFY_NAME
:
378 // Update username in parent form.
380 SelectUserToModify ();
384 // Modify identity policy.
390 switch (QuestionId
& KEY_MODIFY_IP_MASK
) {
392 // Change credential provider option.
394 case KEY_MODIFY_PROV
:
395 mProviderChoice
= Value
->u8
;
399 // Change logical connector.
401 case KEY_MODIFY_CONN
:
402 mConncetLogical
= Value
->u8
;
409 AddIdentityPolicyItem ();
413 // Return to user profile information form.
415 case KEY_IP_RETURN_UIF
:
416 SaveIdentityPolicy ();
417 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT
;
426 // Modify access policy.
430 // Judge next 3 bits.
432 switch (QuestionId
& KEY_MODIFY_AP_MASK
) {
434 // Change access right choice.
436 case KEY_MODIFY_RIGHT
:
437 mAccessInfo
.AccessRight
= Value
->u8
;
441 // Change setup choice.
443 case KEY_MODIFY_SETUP
:
444 mAccessInfo
.AccessSetup
= Value
->u8
;
448 // Change boot order choice.
450 case KEY_MODIFY_BOOT
:
451 mAccessInfo
.AccessBootOrder
= Value
->u32
;
455 // Return to user profile information form.
457 case KEY_AP_RETURN_UIF
:
459 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT
;
473 // Access policy device path modified.
475 case KEY_MODIFY_AP_DP
:
477 // Judge next 2 bits.
479 switch (QuestionId
& KEY_MODIFY_DP_MASK
) {
481 // Load permit device path modified.
483 case KEY_LOAD_PERMIT_MODIFY
:
484 QuestionStr
= GetStringById (STRING_TOKEN (STR_MOVE_TO_FORBID_LIST
));
485 PromptStr
= GetStringById (STRING_TOKEN (STR_PRESS_KEY_CONTINUE
));
487 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
494 FreePool (QuestionStr
);
495 FreePool (PromptStr
);
496 if (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
) {
500 AddToForbidLoad ((UINT16
)(QuestionId
& (KEY_MODIFY_DP_MASK
- 1)));
501 DisplayLoadPermit ();
505 // Load forbid device path modified.
507 case KEY_LOAD_FORBID_MODIFY
:
508 QuestionStr
= GetStringById (STRING_TOKEN (STR_MOVE_TO_PERMIT_LIST
));
509 PromptStr
= GetStringById (STRING_TOKEN (STR_PRESS_KEY_CONTINUE
));
511 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
518 FreePool (QuestionStr
);
519 FreePool (PromptStr
);
520 if (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
) {
524 DeleteFromForbidLoad ((UINT16
)(QuestionId
& (KEY_MODIFY_DP_MASK
- 1)));
525 DisplayLoadForbid ();
529 // Connect permit device path modified.
531 case KEY_CONNECT_PERMIT_MODIFY
:
535 // Connect forbid device path modified.
537 case KEY_CONNECT_FORBID_MODIFY
:
557 case EFI_BROWSER_ACTION_CHANGING
:
560 // Handle the request from form.
563 return EFI_INVALID_PARAMETER
;
567 // Judge first 2 bits.
569 switch (QuestionId
& KEY_FIRST_FORM_MASK
) {
571 // Delete user profile operation.
575 // Judge next 2 bits.
577 switch (QuestionId
& KEY_SECOND_FORM_MASK
) {
579 // Enter delete user profile form.
581 case KEY_ENTER_NEXT_FORM
:
582 SelectUserToDelete ();
591 // Modify user profile operation.
593 case KEY_MODIFY_USER
:
595 // Judge next 2 bits.
597 switch (QuestionId
& KEY_SECOND_FORM_MASK
) {
599 // Enter modify user profile form.
601 case KEY_ENTER_NEXT_FORM
:
602 SelectUserToModify ();
606 // Enter user profile information form.
608 case KEY_SELECT_USER
:
610 // Judge next 3 bits.
612 switch (QuestionId
& KEY_MODIFY_INFO_MASK
) {
614 // Display user information form.
616 case KEY_ENTER_NEXT_FORM
:
617 ModifyUserInfo ((UINT8
) QuestionId
);
621 // Modify identity policy.
627 switch (QuestionId
& KEY_MODIFY_IP_MASK
) {
629 // Display identity policy modify form.
631 case KEY_ENTER_NEXT_FORM
:
632 ModifyIdentityPolicy ();
641 // Modify access policy.
645 // Judge next 3 bits.
647 switch (QuestionId
& KEY_MODIFY_AP_MASK
) {
649 // Display access policy modify form.
651 case KEY_ENTER_NEXT_FORM
:
652 ModidyAccessPolicy ();
655 // Load device path form.
657 case KEY_MODIFY_LOAD
:
659 // Judge next 2 bits.
661 switch (QuestionId
& KEY_DISPLAY_DP_MASK
) {
663 // Permit load device path.
665 case KEY_PERMIT_MODIFY
:
666 DisplayLoadPermit ();
670 // Forbid load device path.
672 case KEY_FORBID_MODIFY
:
673 DisplayLoadForbid ();
682 // Connect device path form.
684 case KEY_MODIFY_CONNECT
:
686 // Judge next 2 bits.
688 switch (QuestionId
& KEY_DISPLAY_DP_MASK
) {
690 // Permit connect device path.
692 case KEY_PERMIT_MODIFY
:
693 DisplayConnectPermit ();
697 // Forbid connect device path.
699 case KEY_FORBID_MODIFY
:
700 DisplayConnectForbid ();
731 // All other action return unsupported.
733 Status
= EFI_UNSUPPORTED
;
743 This function allows a caller to extract the current configuration for one
744 or more named elements from the target driver.
747 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
748 @param Request A null-terminated Unicode string in <ConfigRequest> format.
749 @param Progress On return, points to a character in the Request string.
750 Points to the string's null terminator if request was successful.
751 Points to the most recent '&' before the first failing name/value
752 pair (or the beginning of the string if the failure is in the
753 first name/value pair) if the request was not successful.
754 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
755 has all values filled in for the names in the Request string.
756 String to be allocated by the called function.
758 @retval EFI_SUCCESS The Results is filled with the requested values.
759 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
760 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
761 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
767 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
768 IN CONST EFI_STRING Request
,
769 OUT EFI_STRING
*Progress
,
770 OUT EFI_STRING
*Results
773 if (Progress
== NULL
|| Results
== NULL
) {
774 return EFI_INVALID_PARAMETER
;
777 return EFI_NOT_FOUND
;
781 This function processes the results of changes in configuration.
784 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
785 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
786 @param Progress A pointer to a string filled in with the offset of the most
787 recent '&' before the first failing name/value pair (or the
788 beginning of the string if the failure is in the first
789 name/value pair) or the terminating NULL if all was successful.
791 @retval EFI_SUCCESS The Results is processed successfully.
792 @retval EFI_INVALID_PARAMETER Configuration is NULL.
793 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
799 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
800 IN CONST EFI_STRING Configuration
,
801 OUT EFI_STRING
*Progress
804 if (Configuration
== NULL
|| Progress
== NULL
) {
805 return EFI_INVALID_PARAMETER
;
808 return EFI_NOT_FOUND
;
813 Main entry for this driver.
815 @param ImageHandle Image handle this driver.
816 @param SystemTable Pointer to SystemTable.
818 @retval EFI_SUCESS This function always complete successfully.
823 UserProfileManagerInit (
824 IN EFI_HANDLE ImageHandle
,
825 IN EFI_SYSTEM_TABLE
*SystemTable
829 USER_PROFILE_MANAGER_CALLBACK_INFO
*CallbackInfo
;
831 Status
= gBS
->LocateProtocol (
832 &gEfiUserManagerProtocolGuid
,
834 (VOID
**) &mUserManager
836 if (EFI_ERROR (Status
)) {
841 // Initialize driver private data.
843 ZeroMem (&mUserInfo
, sizeof (mUserInfo
));
844 ZeroMem (&mAccessInfo
, sizeof (mAccessInfo
));
846 CallbackInfo
= AllocateZeroPool (sizeof (USER_PROFILE_MANAGER_CALLBACK_INFO
));
847 ASSERT (CallbackInfo
!= NULL
);
849 CallbackInfo
->Signature
= USER_PROFILE_MANAGER_SIGNATURE
;
850 CallbackInfo
->ConfigAccess
.ExtractConfig
= FakeExtractConfig
;
851 CallbackInfo
->ConfigAccess
.RouteConfig
= FakeRouteConfig
;
852 CallbackInfo
->ConfigAccess
.Callback
= UserProfileManagerCallback
;
853 CallbackInfo
->DriverHandle
= NULL
;
856 // Install Device Path Protocol and Config Access protocol to driver handle.
858 Status
= gBS
->InstallMultipleProtocolInterfaces (
859 &CallbackInfo
->DriverHandle
,
860 &gEfiDevicePathProtocolGuid
,
861 &mHiiVendorDevicePath
,
862 &gEfiHiiConfigAccessProtocolGuid
,
863 &CallbackInfo
->ConfigAccess
,
866 ASSERT_EFI_ERROR (Status
);
871 CallbackInfo
->HiiHandle
= HiiAddPackages (
872 &gUserProfileManagerGuid
,
873 CallbackInfo
->DriverHandle
,
874 UserProfileManagerStrings
,
875 UserProfileManagerVfrBin
,
878 ASSERT (CallbackInfo
->HiiHandle
!= NULL
);
879 mCallbackInfo
= CallbackInfo
;