SecurityPkg: Calculate the length of the String.
[mirror_edk2.git] / SecurityPkg / UserIdentification / UserProfileManagerDxe / UserProfileModify.c
CommitLineData
0c18794e 1/** @file\r
2 The functions to modify a user profile.\r
3 \r
a0c56a82 4Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
0c18794e 5This program and the accompanying materials \r
6are licensed and made available under the terms and conditions of the BSD License \r
7which accompanies this distribution. The full text of the license may be found at \r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "UserProfileManager.h"\r
16\r
17EFI_USER_PROFILE_HANDLE mModifyUser = NULL;\r
18\r
19/**\r
20 Display user select form, cab select a user to modify.\r
21\r
22**/\r
23VOID\r
24SelectUserToModify (\r
25 VOID\r
26 )\r
27{\r
28 EFI_STATUS Status;\r
29 UINT8 Index;\r
30 EFI_USER_PROFILE_HANDLE User;\r
31 EFI_USER_PROFILE_HANDLE CurrentUser;\r
32 UINT32 CurrentAccessRight;\r
33 VOID *StartOpCodeHandle;\r
34 VOID *EndOpCodeHandle;\r
35 EFI_IFR_GUID_LABEL *StartLabel;\r
36 EFI_IFR_GUID_LABEL *EndLabel;\r
37\r
38 //\r
39 // Initialize the container for dynamic opcodes.\r
40 //\r
41 StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
42 ASSERT (StartOpCodeHandle != NULL);\r
43\r
44 EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
45 ASSERT (EndOpCodeHandle != NULL);\r
46\r
47 //\r
48 // Create Hii Extend Label OpCode.\r
49 //\r
50 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (\r
51 StartOpCodeHandle,\r
52 &gEfiIfrTianoGuid,\r
53 NULL,\r
54 sizeof (EFI_IFR_GUID_LABEL)\r
55 );\r
56 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
57 StartLabel->Number = LABEL_USER_MOD_FUNC;\r
58\r
59 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (\r
60 EndOpCodeHandle,\r
61 &gEfiIfrTianoGuid,\r
62 NULL,\r
63 sizeof (EFI_IFR_GUID_LABEL)\r
64 );\r
65 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
66 EndLabel->Number = LABEL_END;\r
67\r
68 //\r
69 // Add each user can be modified.\r
70 //\r
71 User = NULL;\r
72 Index = 1;\r
73 mUserManager->Current (mUserManager, &CurrentUser);\r
74 while (TRUE) {\r
75 Status = mUserManager->GetNext (mUserManager, &User);\r
76 if (EFI_ERROR (Status)) {\r
77 break;\r
78 }\r
79\r
80 Status = GetAccessRight (&CurrentAccessRight);\r
81 if (EFI_ERROR (Status)) {\r
82 CurrentAccessRight = EFI_USER_INFO_ACCESS_ENROLL_SELF;\r
83 }\r
84\r
85 if ((CurrentAccessRight == EFI_USER_INFO_ACCESS_MANAGE) || (User == CurrentUser)) {\r
86 AddUserToForm (User, (UINT16)(KEY_MODIFY_USER | KEY_SELECT_USER | Index), StartOpCodeHandle);\r
87 }\r
88 Index++;\r
89 }\r
90\r
91 HiiUpdateForm (\r
92 mCallbackInfo->HiiHandle, // HII handle\r
a0c56a82 93 &gUserProfileManagerGuid, // Formset GUID\r
0c18794e 94 FORMID_MODIFY_USER, // Form ID\r
95 StartOpCodeHandle, // Label for where to insert opcodes\r
96 EndOpCodeHandle // Replace data\r
97 );\r
98\r
99 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
100 HiiFreeOpCodeHandle (EndOpCodeHandle);\r
101}\r
102\r
103\r
104/**\r
105 Get all the user info from mModifyUser in the user manager, and save on the\r
106 global variable.\r
107\r
108**/\r
109VOID\r
110GetAllUserInfo (\r
111 VOID\r
112 )\r
113{\r
114 EFI_STATUS Status;\r
115 EFI_USER_INFO_HANDLE UserInfo;\r
116 EFI_USER_INFO *Info;\r
117 UINTN InfoSize;\r
118 UINTN MemSize;\r
119 UINTN DataLen;\r
120\r
121 //\r
122 // Init variable to default value.\r
123 //\r
124 mProviderChoice = 0;\r
125 mConncetLogical = 0;\r
126\r
127 mUserInfo.CreateDateExist = FALSE;\r
128 mUserInfo.UsageDateExist = FALSE;\r
129 mUserInfo.UsageCount = 0;\r
130 \r
131 mUserInfo.AccessPolicyLen = 0;\r
132 mUserInfo.AccessPolicyModified = FALSE;\r
133 if (mUserInfo.AccessPolicy != NULL) {\r
134 FreePool (mUserInfo.AccessPolicy);\r
135 mUserInfo.AccessPolicy = NULL;\r
136 }\r
137 mUserInfo.IdentityPolicyLen = 0;\r
138 mUserInfo.IdentityPolicyModified = FALSE;\r
139 if (mUserInfo.IdentityPolicy != NULL) {\r
140 FreePool (mUserInfo.IdentityPolicy);\r
141 mUserInfo.IdentityPolicy = NULL;\r
142 }\r
143 \r
144 //\r
145 // Allocate user information memory.\r
146 //\r
147 MemSize = sizeof (EFI_USER_INFO) + 63;\r
148 Info = AllocateZeroPool (MemSize);\r
149 if (Info == NULL) {\r
150 return ;\r
151 }\r
152 \r
153 //\r
154 // Get each user information.\r
155 //\r
156 UserInfo = NULL;\r
157 while (TRUE) {\r
158 Status = mUserManager->GetNextInfo (mUserManager, mModifyUser, &UserInfo);\r
159 if (EFI_ERROR (Status)) {\r
160 break;\r
161 }\r
162 //\r
163 // Get information.\r
164 //\r
165 InfoSize = MemSize;\r
166 Status = mUserManager->GetInfo (\r
167 mUserManager, \r
168 mModifyUser, \r
169 UserInfo, \r
170 Info, \r
171 &InfoSize\r
172 );\r
173 if (Status == EFI_BUFFER_TOO_SMALL) {\r
174 MemSize = InfoSize;\r
175 FreePool (Info);\r
176 Info = AllocateZeroPool (MemSize);\r
177 if (Info == NULL) {\r
178 return ;\r
179 }\r
180\r
181 Status = mUserManager->GetInfo (\r
182 mUserManager,\r
183 mModifyUser,\r
184 UserInfo,\r
185 Info,\r
186 &InfoSize\r
187 );\r
188 }\r
189\r
190 if (Status == EFI_SUCCESS) {\r
191 //\r
192 // Deal with each information according to informaiton type.\r
193 //\r
194 DataLen = Info->InfoSize - sizeof (EFI_USER_INFO);\r
195 switch (Info->InfoType) {\r
196 case EFI_USER_INFO_NAME_RECORD:\r
197 CopyMem (&mUserInfo.UserName, (UINT8 *) (Info + 1), DataLen);\r
198 break;\r
199\r
200 case EFI_USER_INFO_CREATE_DATE_RECORD:\r
201 CopyMem (&mUserInfo.CreateDate, (UINT8 *) (Info + 1), DataLen);\r
202 mUserInfo.CreateDateExist = TRUE;\r
203 break;\r
204\r
205 case EFI_USER_INFO_USAGE_DATE_RECORD:\r
206 CopyMem (&mUserInfo.UsageDate, (UINT8 *) (Info + 1), DataLen);\r
207 mUserInfo.UsageDateExist = TRUE;\r
208 break;\r
209\r
210 case EFI_USER_INFO_USAGE_COUNT_RECORD:\r
211 CopyMem (&mUserInfo.UsageCount, (UINT8 *) (Info + 1), DataLen);\r
212 break;\r
213\r
214 case EFI_USER_INFO_ACCESS_POLICY_RECORD:\r
215 mUserInfo.AccessPolicy = AllocateZeroPool (DataLen);\r
216 if (mUserInfo.AccessPolicy == NULL) {\r
217 break;\r
218 }\r
219\r
220 CopyMem (mUserInfo.AccessPolicy, (UINT8 *) (Info + 1), DataLen);\r
221 mUserInfo.AccessPolicyLen = DataLen;\r
222 break;\r
223\r
224 case EFI_USER_INFO_IDENTITY_POLICY_RECORD:\r
225 mUserInfo.IdentityPolicy = AllocateZeroPool (DataLen);\r
226 if (mUserInfo.IdentityPolicy == NULL) {\r
227 break;\r
228 }\r
229\r
230 CopyMem (mUserInfo.IdentityPolicy, (UINT8 *) (Info + 1), DataLen);\r
231 mUserInfo.IdentityPolicyLen = DataLen;\r
232 break;\r
233\r
234 default:\r
235 break;\r
236 }\r
237 }\r
238 }\r
239 FreePool (Info);\r
240}\r
241\r
242\r
243/**\r
244 Convert the Date to a string, and update the Hii database DateID string with it.\r
245\r
246 @param[in] Date Points to the date to be converted.\r
247 @param[in] DateId String ID in the HII database to be replaced.\r
248\r
249**/\r
250VOID\r
251ResolveDate (\r
252 IN EFI_TIME *Date,\r
253 IN EFI_STRING_ID DateId\r
254 )\r
255{\r
256 CHAR16 *Str;\r
257 UINTN DateBufLen;\r
258\r
259 //\r
260 // Convert date to string.\r
261 //\r
262 DateBufLen = 64;\r
263 Str = AllocateZeroPool (DateBufLen);\r
264 if (Str == NULL) {\r
265 return ;\r
266 }\r
267\r
268 UnicodeSPrint (\r
269 Str,\r
270 DateBufLen,\r
271 L"%4d-%2d-%2d ",\r
272 Date->Year,\r
273 Date->Month,\r
274 Date->Day\r
275 );\r
276\r
277 //\r
278 // Convert time to string.\r
279 //\r
280 DateBufLen -= StrLen (Str);\r
281 UnicodeSPrint (\r
282 Str + StrLen (Str),\r
283 DateBufLen,\r
284 L"%2d:%2d:%2d", \r
285 Date->Hour,\r
286 Date->Minute,\r
287 Date->Second\r
288 );\r
289 \r
290 HiiSetString (mCallbackInfo->HiiHandle, DateId, Str, NULL);\r
291 FreePool (Str);\r
292}\r
293\r
294\r
295/**\r
296 Convert the CountVal to a string, and update the Hii database CountId string\r
297 with it.\r
298\r
299 @param[in] CountVal The hex value to convert.\r
300 @param[in] CountId String ID in the HII database to be replaced.\r
301\r
302**/\r
303VOID\r
304ResolveCount (\r
305 IN UINT32 CountVal,\r
306 IN EFI_STRING_ID CountId\r
307 )\r
308{\r
309 CHAR16 Count[10];\r
310\r
311 UnicodeSPrint (Count, 20, L"%d", CountVal); \r
312 HiiSetString (mCallbackInfo->HiiHandle, CountId, Count, NULL);\r
313}\r
314\r
315\r
316/**\r
317 Concatenates one Null-terminated Unicode string to another Null-terminated\r
318 Unicode string.\r
319\r
320 @param[in, out] Source1 On entry, point to a Null-terminated Unicode string.\r
321 On exit, point to a new concatenated Unicode string \r
322 @param[in] Source2 Pointer to a Null-terminated Unicode string.\r
323\r
324**/\r
325VOID\r
326AddStr (\r
327 IN OUT CHAR16 **Source1,\r
328 IN CONST CHAR16 *Source2\r
329 )\r
330{\r
331 CHAR16 *TmpStr;\r
332 UINTN StrLength;\r
333\r
334 ASSERT (Source1 != NULL);\r
335 ASSERT (Source2 != NULL);\r
336\r
337 if (*Source1 == NULL) {\r
338 StrLength = StrSize (Source2);\r
339 } else {\r
340 StrLength = StrSize (*Source1);\r
cc976d20 341 StrLength += StrSize (Source2) - 2;\r
0c18794e 342 }\r
343\r
344 TmpStr = AllocateZeroPool (StrLength);\r
345 ASSERT (TmpStr != NULL);\r
346\r
347 if (*Source1 == NULL) {\r
348 StrCpy (TmpStr, Source2);;\r
349 } else {\r
350 StrCpy (TmpStr, *Source1);\r
351 FreePool (*Source1);\r
352 StrCat (TmpStr, Source2);\r
353 }\r
354\r
355 *Source1 = TmpStr;\r
356}\r
357\r
358\r
359/**\r
360 Convert the identity policy to a unicode string and update the Hii database\r
361 IpStringId string with it.\r
362\r
363 @param[in] Ip Points to identity policy.\r
364 @param[in] IpLen The identity policy length.\r
365 @param[in] IpStringId String ID in the HII database to be replaced.\r
366\r
367**/\r
368VOID\r
369ResolveIdentityPolicy (\r
370 IN UINT8 *Ip,\r
371 IN UINTN IpLen,\r
372 IN EFI_STRING_ID IpStringId\r
373 )\r
374{\r
375 CHAR16 *TmpStr;\r
376 UINTN ChkLen;\r
377 EFI_USER_INFO_IDENTITY_POLICY *Identity;\r
378 UINT16 Index;\r
379 CHAR16 *ProvStr;\r
380 EFI_STRING_ID ProvId;\r
381 EFI_HII_HANDLE HiiHandle;\r
6f0b8648 382 EFI_USER_CREDENTIAL2_PROTOCOL *UserCredential;\r
0c18794e 383 \r
384 TmpStr = NULL;\r
385 \r
386 //\r
387 // Resolve each policy.\r
388 //\r
389 ChkLen = 0;\r
390 while (ChkLen < IpLen) {\r
391 Identity = (EFI_USER_INFO_IDENTITY_POLICY *) (Ip + ChkLen);\r
392 switch (Identity->Type) {\r
393 case EFI_USER_INFO_IDENTITY_FALSE:\r
394 AddStr (&TmpStr, L"False");\r
395 break;\r
396\r
397 case EFI_USER_INFO_IDENTITY_TRUE:\r
398 AddStr (&TmpStr, L"None");\r
399 break;\r
400\r
401 case EFI_USER_INFO_IDENTITY_NOT:\r
402 AddStr (&TmpStr, L"! ");\r
403 break;\r
404\r
405 case EFI_USER_INFO_IDENTITY_AND:\r
406 AddStr (&TmpStr, L" && ");\r
407 break;\r
408\r
409 case EFI_USER_INFO_IDENTITY_OR:\r
410 AddStr (&TmpStr, L" || ");\r
411 break;\r
412\r
413 case EFI_USER_INFO_IDENTITY_CREDENTIAL_TYPE:\r
414 for (Index = 0; Index < mProviderInfo->Count; Index++) {\r
415 UserCredential = mProviderInfo->Provider[Index];\r
416 if (CompareGuid ((EFI_GUID *) (Identity + 1), &UserCredential->Type)) { \r
417 UserCredential->Title (\r
418 UserCredential, \r
419 &HiiHandle, \r
420 &ProvId\r
421 );\r
422 ProvStr = HiiGetString (HiiHandle, ProvId, NULL);\r
423 if (ProvStr != NULL) {\r
424 AddStr (&TmpStr, ProvStr);\r
425 FreePool (ProvStr);\r
426 }\r
427 break;\r
428 }\r
429 }\r
430 break;\r
431\r
432 case EFI_USER_INFO_IDENTITY_CREDENTIAL_PROVIDER:\r
433 for (Index = 0; Index < mProviderInfo->Count; Index++) {\r
434 UserCredential = mProviderInfo->Provider[Index];\r
435 if (CompareGuid ((EFI_GUID *) (Identity + 1), &UserCredential->Identifier)) { \r
436 UserCredential->Title (\r
437 UserCredential,\r
438 &HiiHandle,\r
439 &ProvId\r
440 );\r
441 ProvStr = HiiGetString (HiiHandle, ProvId, NULL);\r
442 if (ProvStr != NULL) {\r
443 AddStr (&TmpStr, ProvStr);\r
444 FreePool (ProvStr);\r
445 }\r
446 break;\r
447 }\r
448 }\r
449 break;\r
450 }\r
451\r
452 ChkLen += Identity->Length;\r
453 }\r
454\r
455 if (TmpStr != NULL) {\r
456 HiiSetString (mCallbackInfo->HiiHandle, IpStringId, TmpStr, NULL);\r
457 FreePool (TmpStr);\r
458 }\r
459}\r
460\r
461\r
462/**\r
463 Display modify user information form.\r
464\r
465 This form displays, username, create Date, usage date, usage count, identity policy,\r
466 and access policy.\r
467\r
468 @param[in] UserIndex The index of the user in display list to modify.\r
469 \r
470**/\r
471VOID\r
472ModifyUserInfo (\r
473 IN UINT8 UserIndex\r
474 )\r
475{\r
476 EFI_STATUS Status;\r
477 EFI_USER_PROFILE_HANDLE CurrentUser;\r
478 UINT32 CurrentAccessRight;\r
479 VOID *StartOpCodeHandle;\r
480 VOID *EndOpCodeHandle;\r
481 EFI_IFR_GUID_LABEL *StartLabel;\r
482 EFI_IFR_GUID_LABEL *EndLabel;\r
483\r
484 //\r
485 // Initialize the container for dynamic opcodes.\r
486 //\r
487 StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
488 ASSERT (StartOpCodeHandle != NULL);\r
489\r
490 EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
491 ASSERT (EndOpCodeHandle != NULL);\r
492\r
493 //\r
494 // Create Hii Extend Label OpCode.\r
495 //\r
496 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (\r
497 StartOpCodeHandle,\r
498 &gEfiIfrTianoGuid,\r
499 NULL,\r
500 sizeof (EFI_IFR_GUID_LABEL)\r
501 );\r
502 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
503 StartLabel->Number = LABEL_USER_INFO_FUNC;\r
504\r
505 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (\r
506 EndOpCodeHandle,\r
507 &gEfiIfrTianoGuid,\r
508 NULL,\r
509 sizeof (EFI_IFR_GUID_LABEL)\r
510 );\r
511 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
512 EndLabel->Number = LABEL_END;\r
513\r
514 //\r
515 // Find the user profile to be modified.\r
516 //\r
517 mModifyUser = NULL;\r
518 Status = mUserManager->GetNext (mUserManager, &mModifyUser);\r
519 if (EFI_ERROR (Status)) {\r
520 return ;\r
521 }\r
522\r
523 while (UserIndex > 1) {\r
524 Status = mUserManager->GetNext (mUserManager, &mModifyUser);\r
525 if (EFI_ERROR (Status)) {\r
526 return ;\r
527 }\r
528 UserIndex--;\r
529 }\r
530 \r
531 //\r
532 // Get user profile information.\r
533 //\r
534 GetAllUserInfo ();\r
535\r
536 //\r
537 // Update user name.\r
538 HiiSetString (\r
539 mCallbackInfo->HiiHandle,\r
540 STRING_TOKEN (STR_USER_NAME_VAL),\r
541 mUserInfo.UserName,\r
542 NULL\r
543 );\r
544 \r
545 //\r
546 // Update create date.\r
547 //\r
548 if (mUserInfo.CreateDateExist) {\r
549 ResolveDate (&mUserInfo.CreateDate, STRING_TOKEN (STR_CREATE_DATE_VAL));\r
550 } else {\r
551 HiiSetString (\r
552 mCallbackInfo->HiiHandle,\r
553 STRING_TOKEN (STR_CREATE_DATE_VAL),\r
554 L"",\r
555 NULL\r
556 );\r
557 }\r
558 \r
559 //\r
560 // Add usage date.\r
561 //\r
562 if (mUserInfo.UsageDateExist) {\r
563 ResolveDate (&mUserInfo.UsageDate, STRING_TOKEN (STR_USAGE_DATE_VAL));\r
564 } else {\r
565 HiiSetString (\r
566 mCallbackInfo->HiiHandle,\r
567 STRING_TOKEN (STR_USAGE_DATE_VAL),\r
568 L"",\r
569 NULL\r
570 );\r
571 }\r
572 \r
573 //\r
574 // Add usage count.\r
575 //\r
576 ResolveCount ((UINT32) mUserInfo.UsageCount, STRING_TOKEN (STR_USAGE_COUNT_VAL));\r
577 \r
578 //\r
579 // Add identity policy.\r
580 //\r
581 mUserManager->Current (mUserManager, &CurrentUser);\r
582 if (mModifyUser == CurrentUser) {\r
583 ResolveIdentityPolicy (\r
584 mUserInfo.IdentityPolicy,\r
585 mUserInfo.IdentityPolicyLen,\r
586 STRING_TOKEN (STR_IDENTIFY_POLICY_VAL)\r
587 );\r
588 HiiCreateGotoOpCode (\r
589 StartOpCodeHandle, // Container for opcodes\r
590 FORMID_MODIFY_IP, // Target Form ID\r
591 STRING_TOKEN (STR_IDENTIFY_POLICY), // Prompt text\r
592 STRING_TOKEN (STR_IDENTIFY_POLICY_VAL), // Help text\r
593 EFI_IFR_FLAG_CALLBACK, // Question flag\r
594 KEY_MODIFY_USER | KEY_SELECT_USER | KEY_MODIFY_IP // Question ID\r
595 );\r
596 }\r
597 \r
598 //\r
599 // Add access policy.\r
600 //\r
601 Status = GetAccessRight (&CurrentAccessRight);\r
602 if (EFI_ERROR (Status)) {\r
603 CurrentAccessRight = EFI_USER_INFO_ACCESS_ENROLL_SELF;\r
604 }\r
605\r
606 if (CurrentAccessRight == EFI_USER_INFO_ACCESS_MANAGE) {\r
607 HiiCreateGotoOpCode (\r
608 StartOpCodeHandle, // Container for opcodes\r
609 FORMID_MODIFY_AP, // Target Form ID\r
610 STRING_TOKEN (STR_ACCESS_POLICY), // Prompt text\r
611 STRING_TOKEN (STR_NULL_STRING), // Help text\r
612 EFI_IFR_FLAG_CALLBACK, // Question flag\r
613 KEY_MODIFY_USER | KEY_SELECT_USER | KEY_MODIFY_AP // Question ID\r
614 );\r
615 }\r
616\r
617 HiiUpdateForm (\r
618 mCallbackInfo->HiiHandle, // HII handle\r
a0c56a82 619 &gUserProfileManagerGuid, // Formset GUID\r
0c18794e 620 FORMID_USER_INFO, // Form ID\r
621 StartOpCodeHandle, // Label\r
622 EndOpCodeHandle // Replace data\r
623 );\r
624\r
625 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
626 HiiFreeOpCodeHandle (EndOpCodeHandle);\r
627}\r
628\r
629\r
630/**\r
631 Get all the access policy info from current user info, and save in the global\r
632 variable.\r
633\r
634**/\r
635VOID\r
636ResolveAccessPolicy (\r
637 VOID\r
638 )\r
639{\r
640 UINTN OffSet;\r
641 EFI_USER_INFO_ACCESS_CONTROL Control;\r
642 UINTN ValLen;\r
643 UINT8 *AccessData;\r
644\r
645 //\r
646 // Set default value \r
647 //\r
648 mAccessInfo.AccessRight = EFI_USER_INFO_ACCESS_ENROLL_SELF;\r
649 mAccessInfo.AccessSetup = ACCESS_SETUP_RESTRICTED;\r
650 mAccessInfo.AccessBootOrder = EFI_USER_INFO_ACCESS_BOOT_ORDER_INSERT;\r
651\r
652 mAccessInfo.LoadPermitLen = 0;\r
653 mAccessInfo.LoadForbidLen = 0;\r
654 mAccessInfo.ConnectPermitLen = 0;\r
655 mAccessInfo.ConnectForbidLen = 0;\r
656 \r
657 //\r
658 // Get each user access policy.\r
659 //\r
660 OffSet = 0;\r
661 while (OffSet < mUserInfo.AccessPolicyLen) {\r
662 CopyMem (&Control, mUserInfo.AccessPolicy + OffSet, sizeof (Control)); \r
663 ValLen = Control.Size - sizeof (Control);\r
664 switch (Control.Type) {\r
665 case EFI_USER_INFO_ACCESS_ENROLL_SELF:\r
666 mAccessInfo.AccessRight = EFI_USER_INFO_ACCESS_ENROLL_SELF;\r
667 break;\r
668\r
669 case EFI_USER_INFO_ACCESS_ENROLL_OTHERS:\r
670 mAccessInfo.AccessRight = EFI_USER_INFO_ACCESS_ENROLL_OTHERS;\r
671 break;\r
672\r
673 case EFI_USER_INFO_ACCESS_MANAGE:\r
674 mAccessInfo.AccessRight = EFI_USER_INFO_ACCESS_MANAGE;\r
675 break;\r
676\r
677 case EFI_USER_INFO_ACCESS_SETUP:\r
678 AccessData = mUserInfo.AccessPolicy + OffSet + sizeof (Control);\r
679 if (CompareGuid ((EFI_GUID *) AccessData, &gEfiUserInfoAccessSetupNormalGuid)) {\r
680 mAccessInfo.AccessSetup = ACCESS_SETUP_NORMAL;\r
681 } else if (CompareGuid ((EFI_GUID *) AccessData, &gEfiUserInfoAccessSetupRestrictedGuid)) {\r
682 mAccessInfo.AccessSetup = ACCESS_SETUP_RESTRICTED;\r
683 } else if (CompareGuid ((EFI_GUID *) AccessData, &gEfiUserInfoAccessSetupAdminGuid)) {\r
684 mAccessInfo.AccessSetup = ACCESS_SETUP_ADMIN;\r
685 }\r
686 break;\r
687\r
688 case EFI_USER_INFO_ACCESS_BOOT_ORDER:\r
689 AccessData = mUserInfo.AccessPolicy + OffSet + sizeof (Control);\r
690 CopyMem (&mAccessInfo.AccessBootOrder, AccessData, sizeof (UINT32));\r
691 break;\r
692\r
693 case EFI_USER_INFO_ACCESS_FORBID_LOAD:\r
694 if (mAccessInfo.LoadForbid != NULL) {\r
695 FreePool (mAccessInfo.LoadForbid);\r
696 }\r
697\r
698 mAccessInfo.LoadForbid = AllocateZeroPool (ValLen);\r
699 if (mAccessInfo.LoadForbid != NULL) {\r
700 AccessData = mUserInfo.AccessPolicy + OffSet + sizeof (Control);\r
701 CopyMem (mAccessInfo.LoadForbid, AccessData, ValLen);\r
702 mAccessInfo.LoadForbidLen = ValLen;\r
703 }\r
704 break;\r
705\r
706 case EFI_USER_INFO_ACCESS_PERMIT_LOAD:\r
707 if (mAccessInfo.LoadPermit != NULL) {\r
708 FreePool (mAccessInfo.LoadPermit);\r
709 }\r
710\r
711 mAccessInfo.LoadPermit = AllocateZeroPool (ValLen);\r
712 if (mAccessInfo.LoadPermit != NULL) {\r
713 AccessData = mUserInfo.AccessPolicy + OffSet + sizeof (Control);\r
714 CopyMem (mAccessInfo.LoadPermit, AccessData, ValLen);\r
715 mAccessInfo.LoadPermitLen = ValLen;\r
716 }\r
717 break;\r
718\r
719 case EFI_USER_INFO_ACCESS_FORBID_CONNECT:\r
720 if (mAccessInfo.ConnectForbid != NULL) {\r
721 FreePool (mAccessInfo.ConnectForbid);\r
722 }\r
723\r
724 mAccessInfo.ConnectForbid = AllocateZeroPool (ValLen);\r
725 if (mAccessInfo.ConnectForbid != NULL) {\r
726 AccessData = mUserInfo.AccessPolicy + OffSet + sizeof (Control);\r
727 CopyMem (mAccessInfo.ConnectForbid, AccessData, ValLen);\r
728 mAccessInfo.ConnectForbidLen = ValLen;\r
729 }\r
730 break;\r
731\r
732 case EFI_USER_INFO_ACCESS_PERMIT_CONNECT:\r
733 if (mAccessInfo.ConnectPermit != NULL) {\r
734 FreePool (mAccessInfo.ConnectPermit);\r
735 }\r
736\r
737 mAccessInfo.ConnectPermit = AllocateZeroPool (ValLen);\r
738 if (mAccessInfo.ConnectPermit != NULL) {\r
739 AccessData = mUserInfo.AccessPolicy + OffSet + sizeof (Control);\r
740 CopyMem (mAccessInfo.ConnectPermit, AccessData, ValLen);\r
741 mAccessInfo.ConnectPermitLen = ValLen;\r
742 }\r
743 break;\r
744 }\r
745\r
746 OffSet += Control.Size;\r
747 }\r
748}\r
749\r
750\r
751/**\r
0c5b25f0 752 Find the specified info in User profile by the InfoType.\r
0c18794e 753\r
0c5b25f0 754 @param[in] User Handle of the user whose information will be searched.\r
0c18794e 755 @param[in] InfoType The user information type to find.\r
756 @param[out] UserInfo Points to user information handle found.\r
757 \r
758 @retval EFI_SUCCESS Find the user information successfully.\r
759 @retval Others Fail to find the user information.\r
760\r
761**/\r
762EFI_STATUS\r
763FindInfoByType (\r
0c5b25f0 764 IN EFI_USER_PROFILE_HANDLE User,\r
0c18794e 765 IN UINT8 InfoType,\r
766 OUT EFI_USER_INFO_HANDLE *UserInfo\r
767 )\r
768{\r
769 EFI_STATUS Status;\r
770 EFI_USER_INFO *Info;\r
771 UINTN InfoSize;\r
772 UINTN MemSize;\r
773\r
774 if (UserInfo == NULL) {\r
775 return EFI_INVALID_PARAMETER;\r
776 }\r
777\r
778 *UserInfo = NULL;\r
779 //\r
780 // Allocate user information memory.\r
781 //\r
782 MemSize = sizeof (EFI_USER_INFO) + 63;\r
783 Info = AllocateZeroPool (MemSize);\r
784 if (Info == NULL) {\r
785 return EFI_OUT_OF_RESOURCES;\r
786 }\r
787 \r
788 //\r
789 // Get each user information.\r
790 //\r
791 while (TRUE) {\r
0c5b25f0 792 Status = mUserManager->GetNextInfo (mUserManager, User, UserInfo);\r
0c18794e 793 if (EFI_ERROR (Status)) {\r
794 break;\r
795 }\r
796 //\r
797 // Get information.\r
798 //\r
799 InfoSize = MemSize;\r
800 Status = mUserManager->GetInfo (\r
801 mUserManager,\r
0c5b25f0 802 User,\r
0c18794e 803 *UserInfo,\r
804 Info,\r
805 &InfoSize\r
806 );\r
807 if (Status == EFI_BUFFER_TOO_SMALL) {\r
808 MemSize = InfoSize;\r
809 FreePool (Info);\r
810 Info = AllocateZeroPool (MemSize);\r
811 if (Info == NULL) {\r
812 return EFI_OUT_OF_RESOURCES;\r
813 }\r
814 Status = mUserManager->GetInfo (\r
815 mUserManager,\r
0c5b25f0 816 User,\r
0c18794e 817 *UserInfo,\r
818 Info,\r
819 &InfoSize\r
820 );\r
821 }\r
822 if (Status == EFI_SUCCESS) {\r
823 if (Info->InfoType == InfoType) {\r
824 break;\r
825 }\r
826 }\r
827 }\r
828\r
829 FreePool (Info);\r
830 return Status;\r
831}\r
832\r
833\r
834/**\r
835 Display modify user access policy form.\r
836\r
837 In this form, access right, access setup and access boot order are dynamically\r
838 added. Load devicepath and connect devicepath are displayed too.\r
839 \r
840**/\r
841VOID\r
842ModidyAccessPolicy (\r
843 VOID\r
844 )\r
845{\r
846 VOID *StartOpCodeHandle;\r
847 VOID *EndOpCodeHandle;\r
848 VOID *OptionsOpCodeHandle;\r
849 EFI_IFR_GUID_LABEL *StartLabel;\r
850 EFI_IFR_GUID_LABEL *EndLabel;\r
851 VOID *DefaultOpCodeHandle;\r
852 \r
853 //\r
854 // Initialize the container for dynamic opcodes.\r
855 //\r
856 StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
857 ASSERT (StartOpCodeHandle != NULL);\r
858\r
859 EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
860 ASSERT (EndOpCodeHandle != NULL);\r
861\r
862 //\r
863 // Create Hii Extend Label OpCode.\r
864 //\r
865 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (\r
866 StartOpCodeHandle,\r
867 &gEfiIfrTianoGuid,\r
868 NULL,\r
869 sizeof (EFI_IFR_GUID_LABEL)\r
870 );\r
871 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
872 StartLabel->Number = LABEL_AP_MOD_FUNC;\r
873\r
874 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (\r
875 EndOpCodeHandle,\r
876 &gEfiIfrTianoGuid,\r
877 NULL,\r
878 sizeof (EFI_IFR_GUID_LABEL)\r
879 );\r
880 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
881 EndLabel->Number = LABEL_END;\r
882\r
883\r
884 //\r
885 // Resolve access policy information.\r
886 //\r
887 ResolveAccessPolicy ();\r
888\r
889 //\r
890 // Add access right one-of-code.\r
891 //\r
892 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
893 ASSERT (OptionsOpCodeHandle != NULL);\r
894 DefaultOpCodeHandle = HiiAllocateOpCodeHandle ();\r
895 ASSERT (DefaultOpCodeHandle != NULL);\r
896 \r
897 HiiCreateOneOfOptionOpCode (\r
898 OptionsOpCodeHandle,\r
899 STRING_TOKEN (STR_NORMAL),\r
900 0,\r
901 EFI_IFR_NUMERIC_SIZE_1,\r
902 EFI_USER_INFO_ACCESS_ENROLL_SELF\r
903 );\r
904\r
905 HiiCreateOneOfOptionOpCode (\r
906 OptionsOpCodeHandle,\r
907 STRING_TOKEN (STR_ENROLL),\r
908 0,\r
909 EFI_IFR_NUMERIC_SIZE_1,\r
910 EFI_USER_INFO_ACCESS_ENROLL_OTHERS\r
911 );\r
912\r
913 HiiCreateOneOfOptionOpCode (\r
914 OptionsOpCodeHandle,\r
915 STRING_TOKEN (STR_MANAGE),\r
916 0,\r
917 EFI_IFR_NUMERIC_SIZE_1,\r
918 EFI_USER_INFO_ACCESS_MANAGE\r
919 );\r
920\r
921 HiiCreateDefaultOpCode (\r
922 DefaultOpCodeHandle, \r
923 EFI_HII_DEFAULT_CLASS_STANDARD, \r
924 EFI_IFR_NUMERIC_SIZE_1, \r
925 mAccessInfo.AccessRight\r
926 );\r
927 \r
928 HiiCreateOneOfOpCode (\r
929 StartOpCodeHandle, // Container for dynamic created opcodes\r
930 KEY_MODIFY_USER | KEY_SELECT_USER | KEY_MODIFY_AP | KEY_MODIFY_RIGHT, // Question ID\r
931 0, // VarStore ID\r
932 0, // Offset in Buffer Storage\r
933 STRING_TOKEN (STR_ACCESS_RIGHT), // Question prompt text\r
934 STRING_TOKEN (STR_ACCESS_RIGHT_HELP), // Question help text\r
935 EFI_IFR_FLAG_CALLBACK, // Question flag\r
936 EFI_IFR_NUMERIC_SIZE_1, // Data type of Question Value\r
937 OptionsOpCodeHandle, // Option Opcode list\r
938 DefaultOpCodeHandle // Default Opcode\r
939 );\r
940 HiiFreeOpCodeHandle (DefaultOpCodeHandle);\r
941 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
942\r
943\r
944 //\r
945 // Add setup type one-of-code.\r
946 //\r
947 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
948 ASSERT (OptionsOpCodeHandle != NULL);\r
949 DefaultOpCodeHandle = HiiAllocateOpCodeHandle ();\r
950 ASSERT (DefaultOpCodeHandle != NULL);\r
951 \r
952 HiiCreateOneOfOptionOpCode (\r
953 OptionsOpCodeHandle,\r
954 STRING_TOKEN (STR_RESTRICTED),\r
955 0,\r
956 EFI_IFR_NUMERIC_SIZE_1,\r
957 ACCESS_SETUP_RESTRICTED\r
958 );\r
959 \r
960 HiiCreateOneOfOptionOpCode (\r
961 OptionsOpCodeHandle,\r
962 STRING_TOKEN (STR_NORMAL),\r
963 0,\r
964 EFI_IFR_NUMERIC_SIZE_1,\r
965 ACCESS_SETUP_NORMAL\r
966 );\r
967\r
968 HiiCreateOneOfOptionOpCode (\r
969 OptionsOpCodeHandle,\r
970 STRING_TOKEN (STR_ADMIN),\r
971 0,\r
972 EFI_IFR_NUMERIC_SIZE_1,\r
973 ACCESS_SETUP_ADMIN\r
974 );\r
975\r
976 HiiCreateDefaultOpCode (\r
977 DefaultOpCodeHandle, \r
978 EFI_HII_DEFAULT_CLASS_STANDARD, \r
979 EFI_IFR_NUMERIC_SIZE_1, \r
980 mAccessInfo.AccessSetup\r
981 ); \r
982\r
983 HiiCreateOneOfOpCode (\r
984 StartOpCodeHandle, // Container for dynamic created opcodes\r
985 KEY_MODIFY_USER | KEY_SELECT_USER | KEY_MODIFY_AP | KEY_MODIFY_SETUP, // Question ID\r
986 0, // VarStore ID\r
987 0, // Offset in Buffer Storage\r
988 STRING_TOKEN (STR_ACCESS_SETUP), // Question prompt text\r
989 STRING_TOKEN (STR_ACCESS_SETUP_HELP), // Question help text\r
990 EFI_IFR_FLAG_CALLBACK, // Question flag\r
991 EFI_IFR_NUMERIC_SIZE_1, // Data type of Question Value\r
992 OptionsOpCodeHandle, // Option Opcode list\r
993 DefaultOpCodeHandle // Default Opcode\r
994 );\r
995 HiiFreeOpCodeHandle (DefaultOpCodeHandle);\r
996 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
997 \r
998 //\r
999 // Add boot order one-of-code.\r
1000 //\r
1001 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1002 ASSERT (OptionsOpCodeHandle != NULL);\r
1003 DefaultOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1004 ASSERT (DefaultOpCodeHandle != NULL);\r
1005 \r
1006 HiiCreateOneOfOptionOpCode (\r
1007 OptionsOpCodeHandle,\r
1008 STRING_TOKEN (STR_INSERT),\r
1009 0,\r
1010 EFI_IFR_NUMERIC_SIZE_4,\r
1011 EFI_USER_INFO_ACCESS_BOOT_ORDER_INSERT\r
1012 );\r
1013\r
1014 HiiCreateOneOfOptionOpCode (\r
1015 OptionsOpCodeHandle,\r
1016 STRING_TOKEN (STR_APPEND),\r
1017 0,\r
1018 EFI_IFR_NUMERIC_SIZE_4,\r
1019 EFI_USER_INFO_ACCESS_BOOT_ORDER_APPEND\r
1020 );\r
1021\r
1022 HiiCreateOneOfOptionOpCode (\r
1023 OptionsOpCodeHandle,\r
1024 STRING_TOKEN (STR_REPLACE),\r
1025 0,\r
1026 EFI_IFR_NUMERIC_SIZE_4,\r
1027 EFI_USER_INFO_ACCESS_BOOT_ORDER_REPLACE\r
1028 );\r
1029 \r
1030 HiiCreateOneOfOptionOpCode (\r
1031 OptionsOpCodeHandle,\r
1032 STRING_TOKEN (STR_NODEFAULT),\r
1033 0,\r
1034 EFI_IFR_NUMERIC_SIZE_4,\r
1035 EFI_USER_INFO_ACCESS_BOOT_ORDER_NODEFAULT\r
1036 );\r
1037\r
1038 HiiCreateDefaultOpCode (\r
1039 DefaultOpCodeHandle, \r
1040 EFI_HII_DEFAULT_CLASS_STANDARD, \r
1041 EFI_IFR_NUMERIC_SIZE_4, \r
1042 mAccessInfo.AccessBootOrder\r
1043 );\r
1044 \r
1045 HiiCreateOneOfOpCode (\r
1046 StartOpCodeHandle, // Container for dynamic created opcodes\r
1047 KEY_MODIFY_USER | KEY_SELECT_USER | KEY_MODIFY_AP | KEY_MODIFY_BOOT, // Question ID\r
1048 0, // VarStore ID\r
1049 0, // Offset in Buffer Storage\r
1050 STRING_TOKEN (STR_BOOR_ORDER), // Question prompt text\r
1051 STRING_TOKEN (STR_BOOT_ORDER_HELP), // Question help text\r
1052 EFI_IFR_FLAG_CALLBACK, // Question flag\r
1053 EFI_IFR_NUMERIC_SIZE_1, // Data type of Question Value\r
1054 OptionsOpCodeHandle, // Option Opcode list\r
1055 DefaultOpCodeHandle // Default Opcode\r
1056 );\r
1057 HiiFreeOpCodeHandle (DefaultOpCodeHandle); \r
1058 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
1059\r
1060 //\r
1061 // Update Form.\r
1062 //\r
1063 HiiUpdateForm (\r
1064 mCallbackInfo->HiiHandle, // HII handle\r
a0c56a82 1065 &gUserProfileManagerGuid, // Formset GUID\r
0c18794e 1066 FORMID_MODIFY_AP, // Form ID\r
1067 StartOpCodeHandle, // Label for where to insert opcodes\r
1068 EndOpCodeHandle // Replace data\r
1069 );\r
1070\r
1071 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
1072 HiiFreeOpCodeHandle (EndOpCodeHandle);\r
1073}\r
1074\r
1075\r
1076/**\r
1077 Expand access policy memory size.\r
1078\r
1079 @param[in] ValidLen The valid access policy length.\r
1080 @param[in] ExpandLen The length that is needed to expand.\r
1081 \r
1082**/\r
1083VOID\r
1084ExpandMemory (\r
1085 IN UINTN ValidLen,\r
1086 IN UINTN ExpandLen\r
1087 )\r
1088{\r
1089 UINT8 *Mem;\r
1090 UINTN Len;\r
1091\r
1092 //\r
1093 // Expand memory.\r
1094 //\r
1095 Len = mUserInfo.AccessPolicyLen + (ExpandLen / 64 + 1) * 64;\r
1096 Mem = AllocateZeroPool (Len);\r
1097 ASSERT (Mem != NULL);\r
1098\r
1099 if (mUserInfo.AccessPolicy != NULL) {\r
1100 CopyMem (Mem, mUserInfo.AccessPolicy, ValidLen);\r
1101 FreePool (mUserInfo.AccessPolicy);\r
1102 }\r
1103\r
1104 mUserInfo.AccessPolicy = Mem;\r
1105 mUserInfo.AccessPolicyLen = Len;\r
1106}\r
1107\r
1108\r
0c18794e 1109/**\r
1110 Get the username from user input, and update username string in the Hii \r
1111 database with it.\r
1112\r
1113**/\r
1114VOID\r
1115ModifyUserName (\r
1116 VOID\r
1117 )\r
1118{\r
1119 EFI_STATUS Status;\r
1120 CHAR16 UserName[USER_NAME_LENGTH];\r
1121 UINTN Len;\r
1122 EFI_INPUT_KEY Key;\r
1123 EFI_USER_INFO_HANDLE UserInfo;\r
1124 EFI_USER_INFO *Info;\r
1125 EFI_USER_PROFILE_HANDLE TempUser;\r
1126\r
1127 //\r
1128 // Get the new user name.\r
1129 //\r
1130 Len = sizeof (UserName);\r
1131 Status = GetUserNameInput (&Len, UserName);\r
1132 if (EFI_ERROR (Status)) {\r
1133 if (Status != EFI_ABORTED) {\r
1134 CreatePopUp (\r
1135 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1136 &Key,\r
1137 L"Failed To Get User Name.",\r
1138 L"",\r
1139 L"Please Press Any Key to Continue ...",\r
1140 NULL\r
1141 );\r
1142 }\r
1143 return ;\r
1144 }\r
1145 \r
1146 //\r
1147 // Check whether the username had been used or not.\r
1148 //\r
1149 Info = AllocateZeroPool (sizeof (EFI_USER_INFO) + Len);\r
1150 if (Info == NULL) {\r
1151 return ;\r
1152 }\r
1153\r
1154 Info->InfoType = EFI_USER_INFO_NAME_RECORD;\r
1155 Info->InfoAttribs = EFI_USER_INFO_STORAGE_PLATFORM_NV |\r
1156 EFI_USER_INFO_PUBLIC |\r
1157 EFI_USER_INFO_EXCLUSIVE;\r
1158 Info->InfoSize = (UINT32) (sizeof (EFI_USER_INFO) + Len);\r
1159 CopyMem ((UINT8 *) (Info + 1), UserName, Len);\r
1160\r
1161 TempUser = NULL;\r
1162 Status = mUserManager->Find (\r
1163 mUserManager,\r
1164 &TempUser,\r
1165 NULL,\r
1166 Info,\r
1167 Info->InfoSize\r
1168 );\r
1169 if (!EFI_ERROR (Status)) {\r
1170 CreatePopUp (\r
1171 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1172 &Key,\r
1173 L"The User Name Had Been Used.",\r
1174 L"",\r
1175 L"Please Use Other User Name",\r
1176 NULL\r
1177 );\r
1178 FreePool (Info);\r
1179 return ;\r
1180 }\r
1181 \r
1182 //\r
1183 // Update username display in the form.\r
1184 //\r
1185 CopyMem (mUserInfo.UserName, UserName, Len);\r
1186 HiiSetString (\r
1187 mCallbackInfo->HiiHandle, \r
1188 STRING_TOKEN (STR_USER_NAME_VAL), \r
1189 mUserInfo.UserName, \r
1190 NULL\r
1191 );\r
1192\r
1193 //\r
1194 // Save the user name.\r
1195 //\r
0c5b25f0 1196 Status = FindInfoByType (mModifyUser, EFI_USER_INFO_NAME_RECORD, &UserInfo);\r
0c18794e 1197 if (!EFI_ERROR (Status)) {\r
1198 mUserManager->SetInfo (\r
1199 mUserManager,\r
1200 mModifyUser,\r
1201 &UserInfo,\r
1202 Info,\r
1203 Info->InfoSize\r
1204 );\r
1205 }\r
1206 FreePool (Info);\r
1207}\r
1208\r
1209\r
1210/**\r
1211 Display the form of the modifying user identity policy.\r
1212\r
1213**/\r
1214VOID\r
1215ModifyIdentityPolicy (\r
1216 VOID\r
1217 )\r
1218{\r
1219 UINTN Index;\r
1220 CHAR16 *ProvStr;\r
1221 EFI_STRING_ID ProvID;\r
1222 EFI_HII_HANDLE HiiHandle;\r
1223 VOID *OptionsOpCodeHandle;\r
1224 VOID *StartOpCodeHandle;\r
1225 VOID *EndOpCodeHandle;\r
1226 EFI_IFR_GUID_LABEL *StartLabel;\r
1227 EFI_IFR_GUID_LABEL *EndLabel;\r
1228\r
1229 //\r
1230 // Initialize the container for dynamic opcodes.\r
1231 //\r
1232 StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1233 ASSERT (StartOpCodeHandle != NULL);\r
1234\r
1235 EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1236 ASSERT (EndOpCodeHandle != NULL);\r
1237\r
1238 //\r
1239 // Create Hii Extend Label OpCode.\r
1240 //\r
1241 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (\r
1242 StartOpCodeHandle,\r
1243 &gEfiIfrTianoGuid,\r
1244 NULL,\r
1245 sizeof (EFI_IFR_GUID_LABEL)\r
1246 );\r
1247 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
1248 StartLabel->Number = LABEL_IP_MOD_FUNC;\r
1249\r
1250 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (\r
1251 EndOpCodeHandle,\r
1252 &gEfiIfrTianoGuid,\r
1253 NULL,\r
1254 sizeof (EFI_IFR_GUID_LABEL)\r
1255 );\r
1256 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
1257 EndLabel->Number = LABEL_END;\r
1258\r
1259 //\r
1260 // Add credential providers\r
1261 //.\r
1262 if (mProviderInfo->Count > 0) {\r
1263 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1264 ASSERT (OptionsOpCodeHandle != NULL);\r
1265\r
1266 //\r
1267 // Add credential provider Option OpCode.\r
1268 //\r
1269 for (Index = 0; Index < mProviderInfo->Count; Index++) {\r
1270 mProviderInfo->Provider[Index]->Title (\r
1271 mProviderInfo->Provider[Index],\r
1272 &HiiHandle,\r
1273 &ProvID\r
1274 );\r
1275 ProvStr = HiiGetString (HiiHandle, ProvID, NULL);\r
1276 ProvID = HiiSetString (mCallbackInfo->HiiHandle, 0, ProvStr, NULL);\r
1277 FreePool (ProvStr);\r
1278 if (ProvID == 0) {\r
1279 return ;\r
1280 }\r
1281\r
1282 HiiCreateOneOfOptionOpCode (\r
1283 OptionsOpCodeHandle,\r
1284 ProvID,\r
1285 0,\r
1286 EFI_IFR_NUMERIC_SIZE_1,\r
1287 (UINT8) Index\r
1288 );\r
1289 }\r
1290\r
1291 HiiCreateOneOfOpCode (\r
1292 StartOpCodeHandle, // Container for dynamic created opcodes\r
1293 KEY_MODIFY_USER | KEY_SELECT_USER | KEY_MODIFY_IP | KEY_MODIFY_PROV, // Question ID\r
1294 0, // VarStore ID\r
1295 0, // Offset in Buffer Storage\r
1296 STRING_TOKEN (STR_PROVIDER), // Question prompt text\r
1297 STRING_TOKEN (STR_PROVIDER_HELP), // Question help text\r
1298 EFI_IFR_FLAG_CALLBACK, // Question flag\r
1299 EFI_IFR_NUMERIC_SIZE_1, // Data type of Question Value\r
1300 OptionsOpCodeHandle, // Option Opcode list\r
1301 NULL // Default Opcode is NULl\r
1302 );\r
1303\r
1304 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
1305 }\r
1306 \r
1307 //\r
1308 // Add logical connector Option OpCode.\r
1309 //\r
1310 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1311 ASSERT (OptionsOpCodeHandle != NULL);\r
1312\r
1313 HiiCreateOneOfOptionOpCode (\r
1314 OptionsOpCodeHandle,\r
1315 STRING_TOKEN (STR_AND_CON),\r
1316 0,\r
1317 EFI_IFR_NUMERIC_SIZE_1,\r
1318 0\r
1319 );\r
1320\r
1321 HiiCreateOneOfOptionOpCode (\r
1322 OptionsOpCodeHandle,\r
1323 STRING_TOKEN (STR_OR_CON),\r
1324 0,\r
1325 EFI_IFR_NUMERIC_SIZE_1,\r
1326 1\r
1327 );\r
1328\r
1329 HiiCreateOneOfOpCode (\r
1330 StartOpCodeHandle, // Container for dynamic created opcodes\r
1331 KEY_MODIFY_USER | KEY_SELECT_USER | KEY_MODIFY_IP | KEY_MODIFY_CONN, // Question ID\r
1332 0, // VarStore ID\r
1333 0, // Offset in Buffer Storage\r
1334 STRING_TOKEN (STR_CONNECTOR), // Question prompt text\r
1335 STRING_TOKEN (STR_CONNECTOR_HELP), // Question help text\r
1336 EFI_IFR_FLAG_CALLBACK, // Question flag\r
1337 EFI_IFR_NUMERIC_SIZE_1, // Data type of Question Value\r
1338 OptionsOpCodeHandle, // Option Opcode list\r
1339 NULL // Default Opcode is NULl\r
1340 );\r
1341\r
1342 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
1343\r
1344 //\r
1345 // Update identity policy in the form.\r
1346 //\r
1347 ResolveIdentityPolicy (\r
1348 mUserInfo.IdentityPolicy, \r
1349 mUserInfo.IdentityPolicyLen, \r
1350 STRING_TOKEN (STR_IDENTIFY_POLICY_VALUE)\r
1351 );\r
1352\r
1353 if (mUserInfo.NewIdentityPolicy != NULL) {\r
1354 FreePool (mUserInfo.NewIdentityPolicy);\r
1355 mUserInfo.NewIdentityPolicy = NULL;\r
1356 mUserInfo.NewIdentityPolicyLen = 0;\r
1357 mUserInfo.NewIdentityPolicyModified = FALSE;\r
1358 }\r
1359 mProviderChoice = 0;\r
1360 mConncetLogical = 0;\r
1361\r
1362 HiiUpdateForm (\r
1363 mCallbackInfo->HiiHandle, // HII handle\r
a0c56a82 1364 &gUserProfileManagerGuid, // Formset GUID\r
0c18794e 1365 FORMID_MODIFY_IP, // Form ID\r
1366 StartOpCodeHandle, // Label for where to insert opcodes\r
1367 EndOpCodeHandle // Replace data\r
1368 );\r
1369\r
1370 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
1371 HiiFreeOpCodeHandle (EndOpCodeHandle);\r
1372}\r
1373\r
1374\r
1375/**\r
0c5b25f0 1376 Get current user's access right.\r
1377\r
1378 @param[out] AccessRight Points to the buffer used for user's access right.\r
1379\r
1380 @retval EFI_SUCCESS Get current user access right successfully.\r
1381 @retval others Fail to get current user access right.\r
0c18794e 1382\r
1383**/\r
0c5b25f0 1384EFI_STATUS\r
1385GetAccessRight (\r
1386 OUT UINT32 *AccessRight\r
0c18794e 1387 )\r
1388{\r
1389 EFI_STATUS Status;\r
0c18794e 1390 EFI_USER_INFO_HANDLE UserInfo;\r
1391 EFI_USER_INFO *Info;\r
0c18794e 1392 UINTN InfoSize;\r
0c5b25f0 1393 UINTN MemSize;\r
1394 EFI_USER_INFO_ACCESS_CONTROL Access;\r
1395 EFI_USER_PROFILE_HANDLE CurrentUser;\r
1396 UINTN TotalLen;\r
1397 UINTN CheckLen;\r
0c18794e 1398\r
0c5b25f0 1399 //\r
1400 // Allocate user information memory.\r
1401 //\r
1402 MemSize = sizeof (EFI_USER_INFO) + 63;\r
1403 Info = AllocateZeroPool (MemSize);\r
1404 if (Info == NULL) {\r
1405 return EFI_OUT_OF_RESOURCES;\r
0c18794e 1406 }\r
0c5b25f0 1407 \r
0c18794e 1408 //\r
0c5b25f0 1409 // Get user access information.\r
0c18794e 1410 //\r
0c5b25f0 1411 UserInfo = NULL;\r
1412 mUserManager->Current (mUserManager, &CurrentUser);\r
1413 while (TRUE) {\r
1414 InfoSize = MemSize;\r
0c18794e 1415 //\r
0c5b25f0 1416 // Get next user information.\r
0c18794e 1417 //\r
0c5b25f0 1418 Status = mUserManager->GetNextInfo (mUserManager, CurrentUser, &UserInfo);\r
1419 if (EFI_ERROR (Status)) {\r
0c18794e 1420 break;\r
0c18794e 1421 }\r
0c18794e 1422\r
0c18794e 1423 Status = mUserManager->GetInfo (\r
1424 mUserManager,\r
0c5b25f0 1425 CurrentUser,\r
0c18794e 1426 UserInfo,\r
1427 Info,\r
1428 &InfoSize\r
1429 );\r
1430 if (Status == EFI_BUFFER_TOO_SMALL) {\r
0c5b25f0 1431 MemSize = InfoSize;\r
1432 FreePool (Info);\r
1433 Info = AllocateZeroPool (MemSize);\r
1434 if (Info == NULL) {\r
1435 return EFI_OUT_OF_RESOURCES;\r
1436 }\r
0c18794e 1437 Status = mUserManager->GetInfo (\r
1438 mUserManager,\r
0c5b25f0 1439 CurrentUser,\r
0c18794e 1440 UserInfo,\r
1441 Info,\r
1442 &InfoSize\r
1443 );\r
1444 }\r
0c5b25f0 1445 if (EFI_ERROR (Status)) {\r
1446 break;\r
0c18794e 1447 }\r
0c5b25f0 1448 \r
0c18794e 1449 //\r
0c5b25f0 1450 // Check user information.\r
0c18794e 1451 //\r
0c5b25f0 1452 if (Info->InfoType == EFI_USER_INFO_ACCESS_POLICY_RECORD) {\r
1453 TotalLen = Info->InfoSize - sizeof (EFI_USER_INFO);\r
1454 CheckLen = 0;\r
1455 //\r
1456 // Get specified access information.\r
1457 //\r
1458 while (CheckLen < TotalLen) {\r
1459 CopyMem (&Access, (UINT8 *) (Info + 1) + CheckLen, sizeof (Access));\r
1460 if ((Access.Type == EFI_USER_INFO_ACCESS_ENROLL_SELF) ||\r
1461 (Access.Type == EFI_USER_INFO_ACCESS_ENROLL_OTHERS) ||\r
1462 (Access.Type == EFI_USER_INFO_ACCESS_MANAGE)\r
1463 ) {\r
1464 *AccessRight = Access.Type;\r
1465 FreePool (Info);\r
1466 return EFI_SUCCESS;\r
1467 }\r
1468 CheckLen += Access.Size;\r
0c18794e 1469 }\r
0c18794e 1470 }\r
0c18794e 1471 }\r
0c5b25f0 1472 FreePool (Info);\r
1473 return EFI_NOT_FOUND;\r
0c18794e 1474}\r
1475\r