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
;
190 // Find specified user profile and delete it.
193 Status
= mUserManager
->GetNext (mUserManager
, &User
);
194 if (EFI_ERROR (Status
)) {
198 while (UserIndex
> 1) {
199 Status
= mUserManager
->GetNext (mUserManager
, &User
);
200 if (EFI_ERROR (Status
)) {
206 if (UserIndex
== 1) {
207 Status
= mUserManager
->Delete (mUserManager
, User
);
208 if (EFI_ERROR (Status
)) {
212 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
214 L
"Delete User Succeed!",
216 L
"Please Press Any Key to Continue ...",
224 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
226 L
"Delete User Failed!",
228 L
"Please Press Any Key to Continue ...",
235 Display user select form, cab select a user to delete.
245 EFI_USER_PROFILE_HANDLE User
;
246 EFI_USER_PROFILE_HANDLE CurrentUser
;
247 VOID
*StartOpCodeHandle
;
248 VOID
*EndOpCodeHandle
;
249 EFI_IFR_GUID_LABEL
*StartLabel
;
250 EFI_IFR_GUID_LABEL
*EndLabel
;
253 // Initialize the container for dynamic opcodes.
255 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
256 ASSERT (StartOpCodeHandle
!= NULL
);
258 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
259 ASSERT (EndOpCodeHandle
!= NULL
);
262 // Create Hii Extend Label OpCode.
264 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (
268 sizeof (EFI_IFR_GUID_LABEL
)
270 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
271 StartLabel
->Number
= LABEL_USER_DEL_FUNC
;
273 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (
277 sizeof (EFI_IFR_GUID_LABEL
)
279 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
280 EndLabel
->Number
= LABEL_END
;
283 // Add each user can be deleted.
287 mUserManager
->Current (mUserManager
, &CurrentUser
);
289 Status
= mUserManager
->GetNext (mUserManager
, &User
);
290 if (EFI_ERROR (Status
)) {
294 if (User
!= CurrentUser
) {
297 (UINT16
)(KEY_DEL_USER
| KEY_SELECT_USER
| Index
),
305 mCallbackInfo
->HiiHandle
, // HII handle
306 &gUserProfileManagerGuid
, // Formset GUID
307 FORMID_DEL_USER
, // Form ID
308 StartOpCodeHandle
, // Label for where to insert opcodes
309 EndOpCodeHandle
// Replace data
312 HiiFreeOpCodeHandle (StartOpCodeHandle
);
313 HiiFreeOpCodeHandle (EndOpCodeHandle
);