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_GUID mUserProfileManagerGuid
= USER_PROFILE_MANAGER_GUID
;
21 EFI_USER_MANAGER_PROTOCOL
*mUserManager
= NULL
;
22 CREDENTIAL_PROVIDER_INFO
*mProviderInfo
= NULL
;
23 UINT8 mProviderChoice
;
24 UINT8 mConncetLogical
;
25 USER_INFO_ACCESS mAccessInfo
;
27 USER_PROFILE_MANAGER_CALLBACK_INFO
*mCallbackInfo
;
28 HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath
= {
34 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
35 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
38 {0xad2e3474, 0x93e6, 0x488b, {0x93, 0x19, 0x64, 0x88, 0xfc, 0x68, 0x1f, 0x16}}
42 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
44 (UINT8
) (END_DEVICE_PATH_LENGTH
),
45 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
52 Get string by string id from HII Interface.
55 @param[in] Id String ID to get the string from.
57 @retval CHAR16 * String from ID.
58 @retval NULL If error occurs.
67 // Get the current string for the current Language.
69 return HiiGetString (mCallbackInfo
->HiiHandle
, Id
, NULL
);
74 This function gets all the credential providers in the system and saved them
77 @retval EFI_SUCESS Init credential provider database successfully.
78 @retval Others Fail to init credential provider database.
88 EFI_HANDLE
*HandleBuf
;
92 // Try to find all the user credential provider driver.
96 Status
= gBS
->LocateHandleBuffer (
98 &gEfiUserCredentialProtocolGuid
,
103 if (EFI_ERROR (Status
)) {
108 // Get provider infomation.
110 if (mProviderInfo
!= NULL
) {
111 FreePool (mProviderInfo
);
113 mProviderInfo
= AllocateZeroPool (
114 sizeof (CREDENTIAL_PROVIDER_INFO
) -
115 sizeof (EFI_USER_CREDENTIAL_PROTOCOL
*) +
116 HandleCount
* sizeof (EFI_USER_CREDENTIAL_PROTOCOL
*)
118 if (mProviderInfo
== NULL
) {
119 FreePool (HandleBuf
);
120 return EFI_OUT_OF_RESOURCES
;
123 mProviderInfo
->Count
= HandleCount
;
124 for (Index
= 0; Index
< HandleCount
; Index
++) {
125 Status
= gBS
->HandleProtocol (
127 &gEfiUserCredentialProtocolGuid
,
128 (VOID
**) &mProviderInfo
->Provider
[Index
]
130 if (EFI_ERROR (Status
)) {
131 FreePool (HandleBuf
);
132 FreePool (mProviderInfo
);
133 mProviderInfo
= NULL
;
138 FreePool (HandleBuf
);
144 This function processes changes in user profile configuration.
146 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
147 @param Action Specifies the type of action taken by the browser.
148 @param QuestionId A unique value which is sent to the original
149 exporting driver so that it can identify the type
151 @param Type The type of value for the question.
152 @param Value A pointer to the data being sent to the original
154 @param ActionRequest On return, points to the action requested by the
157 @retval EFI_SUCCESS The callback successfully handled the action.
158 @retval Others Fail to handle the action.
163 UserProfileManagerCallback (
164 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
165 IN EFI_BROWSER_ACTION Action
,
166 IN EFI_QUESTION_ID QuestionId
,
168 IN EFI_IFR_TYPE_VALUE
*Value
,
169 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
174 UINT32 CurrentAccessRight
;
177 VOID
*StartOpCodeHandle
;
178 VOID
*EndOpCodeHandle
;
179 EFI_IFR_GUID_LABEL
*StartLabel
;
180 EFI_IFR_GUID_LABEL
*EndLabel
;
181 EFI_USER_PROFILE_HANDLE CurrentUser
;
183 Status
= EFI_SUCCESS
;
186 case EFI_BROWSER_ACTION_FORM_OPEN
:
189 // Update user manage Form when user manage Form is opened.
190 // This will be done only in FORM_OPEN CallBack of question with QUESTIONID_USER_MANAGE from user manage Form.
192 if (QuestionId
!= QUESTIONID_USER_MANAGE
) {
200 mUserManager
->Current (mUserManager
, &CurrentUser
);
201 if (CurrentUser
== NULL
) {
202 DEBUG ((DEBUG_ERROR
, "Error: current user does not exist!\n"));
203 return EFI_NOT_READY
;
207 // Get current user's right information.
209 Status
= GetAccessRight (&CurrentAccessRight
);
210 if (EFI_ERROR (Status
)) {
211 CurrentAccessRight
= EFI_USER_INFO_ACCESS_ENROLL_SELF
;
215 // Init credential provider information.
217 Status
= InitProviderInfo ();
218 if (EFI_ERROR (Status
)) {
223 // Initialize the container for dynamic opcodes.
225 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
226 ASSERT (StartOpCodeHandle
!= NULL
);
228 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
229 ASSERT (EndOpCodeHandle
!= NULL
);
232 // Create Hii Extend Label OpCode.
234 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (
238 sizeof (EFI_IFR_GUID_LABEL
)
240 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
241 StartLabel
->Number
= LABEL_USER_MANAGE_FUNC
;
243 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (
247 sizeof (EFI_IFR_GUID_LABEL
)
249 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
250 EndLabel
->Number
= LABEL_END
;
253 // Add user profile option.
255 if ((CurrentAccessRight
== EFI_USER_INFO_ACCESS_MANAGE
) ||
256 (CurrentAccessRight
== EFI_USER_INFO_ACCESS_ENROLL_OTHERS
)
258 HiiCreateActionOpCode (
259 StartOpCodeHandle
, // Container for dynamic created opcodes
260 KEY_ADD_USER
, // Question ID
261 STRING_TOKEN (STR_ADD_USER_TITLE
), // Prompt text
262 STRING_TOKEN (STR_ADD_USER_HELP
), // Help text
263 EFI_IFR_FLAG_CALLBACK
, // Question flag
264 0 // Action String ID
269 // Add modify user profile option.
271 HiiCreateGotoOpCode (
272 StartOpCodeHandle
, // Container for dynamic created opcodes
273 FORMID_MODIFY_USER
, // Target Form ID
274 STRING_TOKEN (STR_MODIFY_USER_TITLE
), // Prompt text
275 STRING_TOKEN (STR_MODIFY_USER_HELP
), // Help text
276 EFI_IFR_FLAG_CALLBACK
, // Question flag
277 KEY_MODIFY_USER
// Question ID
281 // Add delete user profile option
283 if (CurrentAccessRight
== EFI_USER_INFO_ACCESS_MANAGE
) {
284 HiiCreateGotoOpCode (
285 StartOpCodeHandle
, // Container for dynamic created opcodes
286 FORMID_DEL_USER
, // Target Form ID
287 STRING_TOKEN (STR_DELETE_USER_TITLE
), // Prompt text
288 STRING_TOKEN (STR_DELETE_USER_HELP
), // Help text
289 EFI_IFR_FLAG_CALLBACK
, // Question flag
290 KEY_DEL_USER
// Question ID
295 mCallbackInfo
->HiiHandle
, // HII handle
296 &mUserProfileManagerGuid
, // Formset GUID
297 FORMID_USER_MANAGE
, // Form ID
298 StartOpCodeHandle
, // Label for where to insert opcodes
299 EndOpCodeHandle
// Replace data
302 HiiFreeOpCodeHandle (StartOpCodeHandle
);
303 HiiFreeOpCodeHandle (EndOpCodeHandle
);
309 case EFI_BROWSER_ACTION_FORM_CLOSE
:
310 Status
= EFI_SUCCESS
;
313 case EFI_BROWSER_ACTION_CHANGING
:
316 // Handle the request from form.
318 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
319 return EFI_INVALID_PARAMETER
;
323 // Judge first 2 bits.
325 switch (QuestionId
& KEY_FIRST_FORM_MASK
) {
327 // Add user profile operation.
334 // Delete user profile operation.
338 // Judge next 2 bits.
340 switch (QuestionId
& KEY_SECOND_FORM_MASK
) {
342 // Enter delete user profile form.
344 case KEY_ENTER_NEXT_FORM
:
345 SelectUserToDelete ();
349 // Delete specified user profile.
351 case KEY_SELECT_USER
:
352 DeleteUser ((UINT8
) QuestionId
);
354 // Update select user form after delete a user.
356 SelectUserToDelete ();
365 // Modify user profile operation.
367 case KEY_MODIFY_USER
:
369 // Judge next 2 bits.
371 switch (QuestionId
& KEY_SECOND_FORM_MASK
) {
373 // Enter modify user profile form.
375 case KEY_ENTER_NEXT_FORM
:
376 SelectUserToModify ();
380 // Enter user profile information form.
382 case KEY_SELECT_USER
:
384 // Judge next 3 bits.
386 switch (QuestionId
& KEY_MODIFY_INFO_MASK
) {
388 // Display user information form.
390 case KEY_ENTER_NEXT_FORM
:
391 ModifyUserInfo ((UINT8
) QuestionId
);
397 case KEY_MODIFY_NAME
:
400 // Update username in parent form.
402 SelectUserToModify ();
406 // Modify identity policy.
412 switch (QuestionId
& KEY_MODIFY_IP_MASK
) {
414 // Display identity policy modify form.
416 case KEY_ENTER_NEXT_FORM
:
417 ModifyIdentityPolicy ();
421 // Change credential provider option.
423 case KEY_MODIFY_PROV
:
424 mProviderChoice
= Value
->u8
;
428 // Change logical connector.
430 case KEY_MODIFY_CONN
:
431 mConncetLogical
= Value
->u8
;
438 AddIdentityPolicyItem ();
442 // Return to user profile information form.
444 case KEY_IP_RETURN_UIF
:
445 SaveIdentityPolicy ();
446 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
455 // Modify access policy.
459 // Judge next 3 bits.
461 switch (QuestionId
& KEY_MODIFY_AP_MASK
) {
463 // Display access policy modify form.
465 case KEY_ENTER_NEXT_FORM
:
466 ModidyAccessPolicy ();
470 // Change access right choice.
472 case KEY_MODIFY_RIGHT
:
473 mAccessInfo
.AccessRight
= Value
->u8
;
477 // Change setup choice.
479 case KEY_MODIFY_SETUP
:
480 mAccessInfo
.AccessSetup
= Value
->u8
;
484 // Change boot order choice.
486 case KEY_MODIFY_BOOT
:
487 mAccessInfo
.AccessBootOrder
= Value
->u32
;
491 // Load device path form.
493 case KEY_MODIFY_LOAD
:
495 // Judge next 2 bits.
497 switch (QuestionId
& KEY_DISPLAY_DP_MASK
) {
499 // Permit load device path.
501 case KEY_PERMIT_MODIFY
:
502 DisplayLoadPermit ();
506 // Forbid load device path.
508 case KEY_FORBID_MODIFY
:
509 DisplayLoadForbid ();
518 // Connect device path form.
520 case KEY_MODIFY_CONNECT
:
522 // Judge next 2 bits.
524 switch (QuestionId
& KEY_DISPLAY_DP_MASK
) {
526 // Permit connect device path.
528 case KEY_PERMIT_MODIFY
:
529 DisplayConnectPermit ();
533 // Forbid connect device path.
535 case KEY_FORBID_MODIFY
:
536 DisplayConnectForbid ();
545 // Return to user profile information form.
547 case KEY_AP_RETURN_UIF
:
549 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
563 // Access policy device path modified.
565 case KEY_MODIFY_AP_DP
:
567 // Judge next 2 bits.
569 switch (QuestionId
& KEY_MODIFY_DP_MASK
) {
571 // Load permit device path modified.
573 case KEY_LOAD_PERMIT_MODIFY
:
574 QuestionStr
= GetStringById (STRING_TOKEN (STR_MOVE_TO_FORBID_LIST
));
575 PromptStr
= GetStringById (STRING_TOKEN (STR_PRESS_KEY_CONTINUE
));
577 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
584 FreePool (QuestionStr
);
585 FreePool (PromptStr
);
586 if (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
) {
590 AddToForbidLoad ((UINT16
)(QuestionId
& (KEY_MODIFY_DP_MASK
- 1)));
591 DisplayLoadPermit ();
595 // Load forbid device path modified.
597 case KEY_LOAD_FORBID_MODIFY
:
598 QuestionStr
= GetStringById (STRING_TOKEN (STR_MOVE_TO_PERMIT_LIST
));
599 PromptStr
= GetStringById (STRING_TOKEN (STR_PRESS_KEY_CONTINUE
));
601 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
608 FreePool (QuestionStr
);
609 FreePool (PromptStr
);
610 if (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
) {
614 DeleteFromForbidLoad ((UINT16
)(QuestionId
& (KEY_MODIFY_DP_MASK
- 1)));
615 DisplayLoadForbid ();
619 // Connect permit device path modified.
621 case KEY_CONNECT_PERMIT_MODIFY
:
625 // Connect forbid device path modified.
627 case KEY_CONNECT_FORBID_MODIFY
:
648 // All other action return unsupported.
650 Status
= EFI_UNSUPPORTED
;
660 This function allows a caller to extract the current configuration for one
661 or more named elements from the target driver.
664 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
665 @param Request A null-terminated Unicode string in <ConfigRequest> format.
666 @param Progress On return, points to a character in the Request string.
667 Points to the string's null terminator if request was successful.
668 Points to the most recent '&' before the first failing name/value
669 pair (or the beginning of the string if the failure is in the
670 first name/value pair) if the request was not successful.
671 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
672 has all values filled in for the names in the Request string.
673 String to be allocated by the called function.
675 @retval EFI_SUCCESS The Results is filled with the requested values.
676 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
677 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
678 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
684 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
685 IN CONST EFI_STRING Request
,
686 OUT EFI_STRING
*Progress
,
687 OUT EFI_STRING
*Results
690 if (Progress
== NULL
|| Results
== NULL
) {
691 return EFI_INVALID_PARAMETER
;
694 return EFI_NOT_FOUND
;
698 This function processes the results of changes in configuration.
701 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
702 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
703 @param Progress A pointer to a string filled in with the offset of the most
704 recent '&' before the first failing name/value pair (or the
705 beginning of the string if the failure is in the first
706 name/value pair) or the terminating NULL if all was successful.
708 @retval EFI_SUCCESS The Results is processed successfully.
709 @retval EFI_INVALID_PARAMETER Configuration is NULL.
710 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
716 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
717 IN CONST EFI_STRING Configuration
,
718 OUT EFI_STRING
*Progress
721 if (Configuration
== NULL
|| Progress
== NULL
) {
722 return EFI_INVALID_PARAMETER
;
725 return EFI_NOT_FOUND
;
730 Main entry for this driver.
732 @param ImageHandle Image handle this driver.
733 @param SystemTable Pointer to SystemTable.
735 @retval EFI_SUCESS This function always complete successfully.
740 UserProfileManagerInit (
741 IN EFI_HANDLE ImageHandle
,
742 IN EFI_SYSTEM_TABLE
*SystemTable
746 USER_PROFILE_MANAGER_CALLBACK_INFO
*CallbackInfo
;
748 Status
= gBS
->LocateProtocol (
749 &gEfiUserManagerProtocolGuid
,
751 (VOID
**) &mUserManager
753 if (EFI_ERROR (Status
)) {
758 // Initialize driver private data.
760 ZeroMem (&mUserInfo
, sizeof (mUserInfo
));
761 ZeroMem (&mAccessInfo
, sizeof (mAccessInfo
));
763 CallbackInfo
= AllocateZeroPool (sizeof (USER_PROFILE_MANAGER_CALLBACK_INFO
));
764 ASSERT (CallbackInfo
!= NULL
);
766 CallbackInfo
->Signature
= USER_PROFILE_MANAGER_SIGNATURE
;
767 CallbackInfo
->ConfigAccess
.ExtractConfig
= FakeExtractConfig
;
768 CallbackInfo
->ConfigAccess
.RouteConfig
= FakeRouteConfig
;
769 CallbackInfo
->ConfigAccess
.Callback
= UserProfileManagerCallback
;
770 CallbackInfo
->DriverHandle
= NULL
;
773 // Install Device Path Protocol and Config Access protocol to driver handle.
775 Status
= gBS
->InstallMultipleProtocolInterfaces (
776 &CallbackInfo
->DriverHandle
,
777 &gEfiDevicePathProtocolGuid
,
778 &mHiiVendorDevicePath
,
779 &gEfiHiiConfigAccessProtocolGuid
,
780 &CallbackInfo
->ConfigAccess
,
783 ASSERT_EFI_ERROR (Status
);
788 CallbackInfo
->HiiHandle
= HiiAddPackages (
789 &mUserProfileManagerGuid
,
790 CallbackInfo
->DriverHandle
,
791 UserProfileManagerStrings
,
792 UserProfileManagerVfrBin
,
795 ASSERT (CallbackInfo
->HiiHandle
!= NULL
);
796 mCallbackInfo
= CallbackInfo
;