2 The functions to delete a user profile.
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 "UserProfileManager.h"
18 Get the username from the specified user.
20 @param[in] User Handle of a user profile.
22 @retval EFI_STRING_ID The String Id of the user's username.
27 IN EFI_USER_PROFILE_HANDLE User
31 EFI_USER_INFO_HANDLE UserInfo
;
36 CHAR16 UserName
[USER_NAME_LENGTH
];
40 // Allocate user information memory.
42 MemSize
= sizeof (EFI_USER_INFO
) + 63;
43 Info
= AllocateZeroPool (MemSize
);
44 ASSERT (Info
!= NULL
);
47 // Get user name information.
53 // Get next user information.
55 Status
= mUserManager
->GetNextInfo (
60 if (EFI_ERROR (Status
)) {
64 Status
= mUserManager
->GetInfo (
71 if (Status
== EFI_BUFFER_TOO_SMALL
) {
74 Info
= AllocateZeroPool (MemSize
);
75 ASSERT (Info
!= NULL
);
77 Status
= mUserManager
->GetInfo (
86 // Check user information.
88 if (Status
== EFI_SUCCESS
) {
89 if (Info
->InfoType
== EFI_USER_INFO_NAME_RECORD
) {
90 NameLen
= Info
->InfoSize
- sizeof (EFI_USER_INFO
);
91 if (NameLen
> USER_NAME_LENGTH
* sizeof (CHAR16
)) {
92 NameLen
= USER_NAME_LENGTH
* sizeof (CHAR16
);
94 ASSERT (NameLen
>= sizeof (CHAR16
));
95 CopyMem (UserName
, (UINT8
*) (Info
+ 1), NameLen
);
96 UserName
[NameLen
/ sizeof (CHAR16
) - 1] = 0;
97 UserId
= HiiSetString (
98 mCallbackInfo
->HiiHandle
,
117 Add a username item in form.
119 @param[in] User Points to the user profile whose username is added.
120 @param[in] Index The index of the user in the user name list
121 @param[in] OpCodeHandle Points to container for dynamic created opcodes.
126 IN EFI_USER_PROFILE_HANDLE User
,
128 IN VOID
*OpCodeHandle
131 EFI_STRING_ID NameId
;
136 NameId
= GetUserName (User
);
142 // Create user name option.
144 switch (Index
& KEY_FIRST_FORM_MASK
) {
145 case KEY_MODIFY_USER
:
146 HiiCreateGotoOpCode (
147 OpCodeHandle
, // Container for dynamic created opcodes
148 FORMID_USER_INFO
, // Target Form ID
149 NameId
, // Prompt text
150 STRING_TOKEN (STR_NULL_STRING
), // Help text
151 EFI_IFR_FLAG_CALLBACK
, // Question flag
157 HiiCreateActionOpCode (
158 OpCodeHandle
, // Container for dynamic created opcodes
159 Index
, // Question ID
160 NameId
, // Prompt text
161 STRING_TOKEN (STR_NULL_STRING
), // Help text
162 EFI_IFR_FLAG_CALLBACK
, // Question flag
163 0 // Action String ID
174 Delete the user specified by UserIndex in user profile database.
176 @param[in] UserIndex The index of user in the user name list
186 EFI_USER_PROFILE_HANDLE User
;
188 EFI_USER_INFO_HANDLE UserInfo
;
193 // Find specified user profile and delete it.
196 Status
= mUserManager
->GetNext (mUserManager
, &User
);
197 if (EFI_ERROR (Status
)) {
201 while (UserIndex
> 1) {
202 Status
= mUserManager
->GetNext (mUserManager
, &User
);
203 if (EFI_ERROR (Status
)) {
209 if (UserIndex
== 1) {
211 // Get the identification policy.
213 Status
= FindInfoByType (User
, EFI_USER_INFO_IDENTITY_POLICY_RECORD
, &UserInfo
);
214 if (EFI_ERROR (Status
)) {
220 Status
= mUserManager
->GetInfo (mUserManager
, User
, UserInfo
, Info
, &InfoSize
);
221 if (Status
== EFI_BUFFER_TOO_SMALL
) {
222 Info
= AllocateZeroPool (InfoSize
);
226 Status
= mUserManager
->GetInfo (mUserManager
, User
, UserInfo
, Info
, &InfoSize
);
230 // Delete the user on the credential providers by its identification policy.
232 DeleteCredentialFromProviders ((UINT8
*)(Info
+ 1), Info
->InfoSize
- sizeof (EFI_USER_INFO
), User
);
235 Status
= mUserManager
->Delete (mUserManager
, User
);
236 if (EFI_ERROR (Status
)) {
240 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
242 L
"Delete User Succeed!",
244 L
"Please Press Any Key to Continue ...",
252 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
254 L
"Delete User Failed!",
256 L
"Please Press Any Key to Continue ...",
263 Display user select form, cab select a user to delete.
273 EFI_USER_PROFILE_HANDLE User
;
274 EFI_USER_PROFILE_HANDLE CurrentUser
;
275 VOID
*StartOpCodeHandle
;
276 VOID
*EndOpCodeHandle
;
277 EFI_IFR_GUID_LABEL
*StartLabel
;
278 EFI_IFR_GUID_LABEL
*EndLabel
;
281 // Initialize the container for dynamic opcodes.
283 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
284 ASSERT (StartOpCodeHandle
!= NULL
);
286 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
287 ASSERT (EndOpCodeHandle
!= NULL
);
290 // Create Hii Extend Label OpCode.
292 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (
296 sizeof (EFI_IFR_GUID_LABEL
)
298 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
299 StartLabel
->Number
= LABEL_USER_DEL_FUNC
;
301 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (
305 sizeof (EFI_IFR_GUID_LABEL
)
307 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
308 EndLabel
->Number
= LABEL_END
;
311 // Add each user can be deleted.
315 mUserManager
->Current (mUserManager
, &CurrentUser
);
317 Status
= mUserManager
->GetNext (mUserManager
, &User
);
318 if (EFI_ERROR (Status
)) {
322 if (User
!= CurrentUser
) {
325 (UINT16
)(KEY_DEL_USER
| KEY_SELECT_USER
| Index
),
333 mCallbackInfo
->HiiHandle
, // HII handle
334 &gUserProfileManagerGuid
, // Formset GUID
335 FORMID_DEL_USER
, // Form ID
336 StartOpCodeHandle
, // Label for where to insert opcodes
337 EndOpCodeHandle
// Replace data
340 HiiFreeOpCodeHandle (StartOpCodeHandle
);
341 HiiFreeOpCodeHandle (EndOpCodeHandle
);