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 &gEfiUserCredentialProtocolGuid
,
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_CREDENTIAL_PROTOCOL
*) +
115 HandleCount
* sizeof (EFI_USER_CREDENTIAL_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 &gEfiUserCredentialProtocolGuid
,
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_CHANGING
:
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 // Enter delete user profile form.
343 case KEY_ENTER_NEXT_FORM
:
344 SelectUserToDelete ();
348 // Delete specified user profile.
350 case KEY_SELECT_USER
:
351 DeleteUser ((UINT8
) QuestionId
);
353 // Update select user form after delete a user.
355 SelectUserToDelete ();
364 // Modify user profile operation.
366 case KEY_MODIFY_USER
:
368 // Judge next 2 bits.
370 switch (QuestionId
& KEY_SECOND_FORM_MASK
) {
372 // Enter modify user profile form.
374 case KEY_ENTER_NEXT_FORM
:
375 SelectUserToModify ();
379 // Enter user profile information form.
381 case KEY_SELECT_USER
:
383 // Judge next 3 bits.
385 switch (QuestionId
& KEY_MODIFY_INFO_MASK
) {
387 // Display user information form.
389 case KEY_ENTER_NEXT_FORM
:
390 ModifyUserInfo ((UINT8
) QuestionId
);
396 case KEY_MODIFY_NAME
:
399 // Update username in parent form.
401 SelectUserToModify ();
405 // Modify identity policy.
411 switch (QuestionId
& KEY_MODIFY_IP_MASK
) {
413 // Display identity policy modify form.
415 case KEY_ENTER_NEXT_FORM
:
416 ModifyIdentityPolicy ();
420 // Change credential provider option.
422 case KEY_MODIFY_PROV
:
423 mProviderChoice
= Value
->u8
;
427 // Change logical connector.
429 case KEY_MODIFY_CONN
:
430 mConncetLogical
= Value
->u8
;
437 AddIdentityPolicyItem ();
441 // Return to user profile information form.
443 case KEY_IP_RETURN_UIF
:
444 SaveIdentityPolicy ();
445 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
454 // Modify access policy.
458 // Judge next 3 bits.
460 switch (QuestionId
& KEY_MODIFY_AP_MASK
) {
462 // Display access policy modify form.
464 case KEY_ENTER_NEXT_FORM
:
465 ModidyAccessPolicy ();
469 // Change access right choice.
471 case KEY_MODIFY_RIGHT
:
472 mAccessInfo
.AccessRight
= Value
->u8
;
476 // Change setup choice.
478 case KEY_MODIFY_SETUP
:
479 mAccessInfo
.AccessSetup
= Value
->u8
;
483 // Change boot order choice.
485 case KEY_MODIFY_BOOT
:
486 mAccessInfo
.AccessBootOrder
= Value
->u32
;
490 // Load device path form.
492 case KEY_MODIFY_LOAD
:
494 // Judge next 2 bits.
496 switch (QuestionId
& KEY_DISPLAY_DP_MASK
) {
498 // Permit load device path.
500 case KEY_PERMIT_MODIFY
:
501 DisplayLoadPermit ();
505 // Forbid load device path.
507 case KEY_FORBID_MODIFY
:
508 DisplayLoadForbid ();
517 // Connect device path form.
519 case KEY_MODIFY_CONNECT
:
521 // Judge next 2 bits.
523 switch (QuestionId
& KEY_DISPLAY_DP_MASK
) {
525 // Permit connect device path.
527 case KEY_PERMIT_MODIFY
:
528 DisplayConnectPermit ();
532 // Forbid connect device path.
534 case KEY_FORBID_MODIFY
:
535 DisplayConnectForbid ();
544 // Return to user profile information form.
546 case KEY_AP_RETURN_UIF
:
548 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
562 // Access policy device path modified.
564 case KEY_MODIFY_AP_DP
:
566 // Judge next 2 bits.
568 switch (QuestionId
& KEY_MODIFY_DP_MASK
) {
570 // Load permit device path modified.
572 case KEY_LOAD_PERMIT_MODIFY
:
573 QuestionStr
= GetStringById (STRING_TOKEN (STR_MOVE_TO_FORBID_LIST
));
574 PromptStr
= GetStringById (STRING_TOKEN (STR_PRESS_KEY_CONTINUE
));
576 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
583 FreePool (QuestionStr
);
584 FreePool (PromptStr
);
585 if (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
) {
589 AddToForbidLoad ((UINT16
)(QuestionId
& (KEY_MODIFY_DP_MASK
- 1)));
590 DisplayLoadPermit ();
594 // Load forbid device path modified.
596 case KEY_LOAD_FORBID_MODIFY
:
597 QuestionStr
= GetStringById (STRING_TOKEN (STR_MOVE_TO_PERMIT_LIST
));
598 PromptStr
= GetStringById (STRING_TOKEN (STR_PRESS_KEY_CONTINUE
));
600 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
607 FreePool (QuestionStr
);
608 FreePool (PromptStr
);
609 if (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
) {
613 DeleteFromForbidLoad ((UINT16
)(QuestionId
& (KEY_MODIFY_DP_MASK
- 1)));
614 DisplayLoadForbid ();
618 // Connect permit device path modified.
620 case KEY_CONNECT_PERMIT_MODIFY
:
624 // Connect forbid device path modified.
626 case KEY_CONNECT_FORBID_MODIFY
:
647 // All other action return unsupported.
649 Status
= EFI_UNSUPPORTED
;
659 This function allows a caller to extract the current configuration for one
660 or more named elements from the target driver.
663 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
664 @param Request A null-terminated Unicode string in <ConfigRequest> format.
665 @param Progress On return, points to a character in the Request string.
666 Points to the string's null terminator if request was successful.
667 Points to the most recent '&' before the first failing name/value
668 pair (or the beginning of the string if the failure is in the
669 first name/value pair) if the request was not successful.
670 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
671 has all values filled in for the names in the Request string.
672 String to be allocated by the called function.
674 @retval EFI_SUCCESS The Results is filled with the requested values.
675 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
676 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
677 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
683 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
684 IN CONST EFI_STRING Request
,
685 OUT EFI_STRING
*Progress
,
686 OUT EFI_STRING
*Results
689 if (Progress
== NULL
|| Results
== NULL
) {
690 return EFI_INVALID_PARAMETER
;
693 return EFI_NOT_FOUND
;
697 This function processes the results of changes in configuration.
700 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
701 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
702 @param Progress A pointer to a string filled in with the offset of the most
703 recent '&' before the first failing name/value pair (or the
704 beginning of the string if the failure is in the first
705 name/value pair) or the terminating NULL if all was successful.
707 @retval EFI_SUCCESS The Results is processed successfully.
708 @retval EFI_INVALID_PARAMETER Configuration is NULL.
709 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
715 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
716 IN CONST EFI_STRING Configuration
,
717 OUT EFI_STRING
*Progress
720 if (Configuration
== NULL
|| Progress
== NULL
) {
721 return EFI_INVALID_PARAMETER
;
724 return EFI_NOT_FOUND
;
729 Main entry for this driver.
731 @param ImageHandle Image handle this driver.
732 @param SystemTable Pointer to SystemTable.
734 @retval EFI_SUCESS This function always complete successfully.
739 UserProfileManagerInit (
740 IN EFI_HANDLE ImageHandle
,
741 IN EFI_SYSTEM_TABLE
*SystemTable
745 USER_PROFILE_MANAGER_CALLBACK_INFO
*CallbackInfo
;
747 Status
= gBS
->LocateProtocol (
748 &gEfiUserManagerProtocolGuid
,
750 (VOID
**) &mUserManager
752 if (EFI_ERROR (Status
)) {
757 // Initialize driver private data.
759 ZeroMem (&mUserInfo
, sizeof (mUserInfo
));
760 ZeroMem (&mAccessInfo
, sizeof (mAccessInfo
));
762 CallbackInfo
= AllocateZeroPool (sizeof (USER_PROFILE_MANAGER_CALLBACK_INFO
));
763 ASSERT (CallbackInfo
!= NULL
);
765 CallbackInfo
->Signature
= USER_PROFILE_MANAGER_SIGNATURE
;
766 CallbackInfo
->ConfigAccess
.ExtractConfig
= FakeExtractConfig
;
767 CallbackInfo
->ConfigAccess
.RouteConfig
= FakeRouteConfig
;
768 CallbackInfo
->ConfigAccess
.Callback
= UserProfileManagerCallback
;
769 CallbackInfo
->DriverHandle
= NULL
;
772 // Install Device Path Protocol and Config Access protocol to driver handle.
774 Status
= gBS
->InstallMultipleProtocolInterfaces (
775 &CallbackInfo
->DriverHandle
,
776 &gEfiDevicePathProtocolGuid
,
777 &mHiiVendorDevicePath
,
778 &gEfiHiiConfigAccessProtocolGuid
,
779 &CallbackInfo
->ConfigAccess
,
782 ASSERT_EFI_ERROR (Status
);
787 CallbackInfo
->HiiHandle
= HiiAddPackages (
788 &gUserProfileManagerGuid
,
789 CallbackInfo
->DriverHandle
,
790 UserProfileManagerStrings
,
791 UserProfileManagerVfrBin
,
794 ASSERT (CallbackInfo
->HiiHandle
!= NULL
);
795 mCallbackInfo
= CallbackInfo
;