]>
Commit | Line | Data |
---|---|---|
0c18794e | 1 | /** @file\r |
2 | Password Credential Provider driver implementation.\r | |
3 | \r | |
68d151bb | 4 | Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r |
0c18794e | 5 | This program and the accompanying materials \r |
6 | are licensed and made available under the terms and conditions of the BSD License \r | |
7 | which accompanies this distribution. The full text of the license may be found at \r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "PwdCredentialProvider.h"\r | |
16 | \r | |
17 | CREDENTIAL_TABLE *mPwdTable = NULL;\r | |
18 | PWD_PROVIDER_CALLBACK_INFO *mCallbackInfo = NULL;\r | |
19 | PASSWORD_CREDENTIAL_INFO *mPwdInfoHandle = NULL;\r | |
20 | \r | |
0c18794e | 21 | HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath = {\r |
22 | {\r | |
23 | {\r | |
24 | HARDWARE_DEVICE_PATH,\r | |
25 | HW_VENDOR_DP,\r | |
26 | {\r | |
27 | (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r | |
28 | (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r | |
29 | }\r | |
30 | },\r | |
a0c56a82 | 31 | PWD_CREDENTIAL_PROVIDER_GUID\r |
0c18794e | 32 | },\r |
33 | {\r | |
34 | END_DEVICE_PATH_TYPE,\r | |
35 | END_ENTIRE_DEVICE_PATH_SUBTYPE,\r | |
36 | {\r | |
37 | (UINT8) (END_DEVICE_PATH_LENGTH),\r | |
38 | (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r | |
39 | }\r | |
40 | }\r | |
41 | };\r | |
42 | \r | |
6f0b8648 | 43 | EFI_USER_CREDENTIAL2_PROTOCOL gPwdCredentialProviderDriver = {\r |
0c18794e | 44 | PWD_CREDENTIAL_PROVIDER_GUID,\r |
45 | EFI_USER_CREDENTIAL_CLASS_PASSWORD,\r | |
46 | CredentialEnroll,\r | |
47 | CredentialForm,\r | |
48 | CredentialTile,\r | |
49 | CredentialTitle,\r | |
50 | CredentialUser,\r | |
51 | CredentialSelect,\r | |
52 | CredentialDeselect,\r | |
53 | CredentialDefault,\r | |
54 | CredentialGetInfo,\r | |
6f0b8648 | 55 | CredentialGetNextInfo,\r |
56 | EFI_CREDENTIAL_CAPABILITIES_ENROLL,\r | |
57 | CredentialDelete\r | |
0c18794e | 58 | };\r |
59 | \r | |
60 | \r | |
61 | /**\r | |
62 | Get string by string id from HII Interface.\r | |
63 | \r | |
64 | \r | |
65 | @param[in] Id String ID to get the string from.\r | |
66 | \r | |
67 | @retval CHAR16 * String from ID.\r | |
68 | @retval NULL If error occurs.\r | |
69 | \r | |
70 | **/\r | |
71 | CHAR16 *\r | |
72 | GetStringById (\r | |
73 | IN EFI_STRING_ID Id\r | |
74 | )\r | |
75 | {\r | |
76 | //\r | |
77 | // Get the current string for the current Language.\r | |
78 | //\r | |
79 | return HiiGetString (mCallbackInfo->HiiHandle, Id, NULL);\r | |
80 | }\r | |
81 | \r | |
82 | \r | |
83 | /**\r | |
84 | Expand password table size.\r | |
85 | \r | |
86 | **/\r | |
87 | VOID\r | |
88 | ExpandTableSize (\r | |
89 | VOID\r | |
90 | )\r | |
91 | {\r | |
92 | CREDENTIAL_TABLE *NewTable;\r | |
93 | UINTN Count;\r | |
94 | \r | |
95 | Count = mPwdTable->MaxCount + PASSWORD_TABLE_INC;\r | |
96 | //\r | |
97 | // Create new credential table.\r | |
98 | //\r | |
99 | NewTable = (CREDENTIAL_TABLE *) AllocateZeroPool (\r | |
100 | sizeof (CREDENTIAL_TABLE) + \r | |
101 | (Count - 1) * sizeof (PASSWORD_INFO)\r | |
102 | );\r | |
103 | ASSERT (NewTable != NULL); \r | |
104 | \r | |
105 | NewTable->MaxCount = Count;\r | |
106 | NewTable->Count = mPwdTable->Count;\r | |
107 | NewTable->ValidIndex = mPwdTable->ValidIndex;\r | |
108 | //\r | |
109 | // Copy old entries\r | |
110 | //\r | |
111 | CopyMem (\r | |
112 | &NewTable->UserInfo, \r | |
113 | &mPwdTable->UserInfo, \r | |
114 | mPwdTable->Count * sizeof (PASSWORD_INFO)\r | |
115 | );\r | |
116 | FreePool (mPwdTable);\r | |
117 | mPwdTable = NewTable;\r | |
118 | }\r | |
119 | \r | |
120 | \r | |
121 | /**\r | |
6f0b8648 | 122 | Add, update or delete info in table, and sync with NV variable.\r |
0c18794e | 123 | \r |
6f0b8648 | 124 | @param[in] Index The index of the password in table. If index is found in\r |
125 | table, update the info, else add the into to table. \r | |
126 | @param[in] Info The new password info to add into table.If Info is NULL, \r | |
127 | delete the info by Index.\r | |
0c18794e | 128 | \r |
129 | @retval EFI_INVALID_PARAMETER Info is NULL when save the info.\r | |
130 | @retval EFI_SUCCESS Modify the table successfully.\r | |
131 | @retval Others Failed to modify the table.\r | |
132 | \r | |
133 | **/\r | |
134 | EFI_STATUS\r | |
135 | ModifyTable (\r | |
136 | IN UINTN Index,\r | |
137 | IN PASSWORD_INFO * Info OPTIONAL\r | |
138 | )\r | |
139 | {\r | |
6f0b8648 | 140 | EFI_STATUS Status;\r |
141 | PASSWORD_INFO *NewPasswordInfo;\r | |
142 | \r | |
143 | NewPasswordInfo = NULL;\r | |
144 | \r | |
0c18794e | 145 | if (Index < mPwdTable->Count) {\r |
6f0b8648 | 146 | if (Info == NULL) {\r |
147 | //\r | |
148 | // Delete the specified entry.\r | |
149 | //\r | |
150 | mPwdTable->Count--;\r | |
151 | if (Index != mPwdTable->Count) {\r | |
152 | NewPasswordInfo = &mPwdTable->UserInfo[mPwdTable->Count];\r | |
153 | } \r | |
154 | } else {\r | |
155 | //\r | |
156 | // Update the specified entry.\r | |
157 | //\r | |
158 | NewPasswordInfo = Info;\r | |
0c18794e | 159 | }\r |
160 | } else {\r | |
161 | //\r | |
6f0b8648 | 162 | // Add a new password info.\r |
0c18794e | 163 | //\r |
164 | if (Info == NULL) {\r | |
165 | return EFI_INVALID_PARAMETER;\r | |
166 | }\r | |
167 | \r | |
168 | if (mPwdTable->Count >= mPwdTable->MaxCount) {\r | |
169 | ExpandTableSize ();\r | |
170 | }\r | |
171 | \r | |
6f0b8648 | 172 | NewPasswordInfo = Info;\r |
0c18794e | 173 | mPwdTable->Count++;\r |
174 | }\r | |
175 | \r | |
6f0b8648 | 176 | if (NewPasswordInfo != NULL) {\r |
177 | CopyMem (&mPwdTable->UserInfo[Index], NewPasswordInfo, sizeof (PASSWORD_INFO));\r | |
178 | }\r | |
179 | \r | |
0c18794e | 180 | //\r |
181 | // Save the credential table.\r | |
182 | //\r | |
183 | Status = gRT->SetVariable (\r | |
184 | L"PwdCredential",\r | |
a0c56a82 | 185 | &gPwdCredentialProviderGuid,\r |
0c18794e | 186 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r |
187 | mPwdTable->Count * sizeof (PASSWORD_INFO),\r | |
188 | &mPwdTable->UserInfo\r | |
189 | );\r | |
190 | return Status;\r | |
191 | }\r | |
192 | \r | |
193 | \r | |
194 | /**\r | |
195 | Create a password table.\r | |
196 | \r | |
197 | @retval EFI_SUCCESS Create a password table successfully.\r | |
198 | @retval Others Failed to create a password.\r | |
199 | \r | |
200 | **/\r | |
201 | EFI_STATUS\r | |
202 | InitCredentialTable (\r | |
203 | VOID\r | |
204 | )\r | |
205 | {\r | |
206 | EFI_STATUS Status;\r | |
207 | UINT8 *Var;\r | |
208 | UINTN VarSize;\r | |
209 | \r | |
210 | //\r | |
211 | // Get Password credential data from NV variable.\r | |
212 | //\r | |
213 | VarSize = 0;\r | |
214 | Var = NULL;\r | |
215 | Status = gRT->GetVariable (\r | |
216 | L"PwdCredential", \r | |
a0c56a82 | 217 | &gPwdCredentialProviderGuid, \r |
0c18794e | 218 | NULL, \r |
219 | &VarSize,\r | |
220 | Var\r | |
221 | );\r | |
222 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
223 | Var = AllocateZeroPool (VarSize);\r | |
224 | if (Var == NULL) {\r | |
225 | return EFI_OUT_OF_RESOURCES;\r | |
226 | }\r | |
227 | Status = gRT->GetVariable (\r | |
228 | L"PwdCredential", \r | |
a0c56a82 | 229 | &gPwdCredentialProviderGuid, \r |
0c18794e | 230 | NULL, \r |
231 | &VarSize,\r | |
232 | Var\r | |
233 | );\r | |
234 | }\r | |
235 | if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {\r | |
236 | return Status;\r | |
237 | }\r | |
238 | \r | |
239 | //\r | |
240 | // Create the password credential table.\r | |
241 | //\r | |
242 | mPwdTable = AllocateZeroPool (\r | |
243 | sizeof (CREDENTIAL_TABLE) - sizeof (PASSWORD_INFO) +\r | |
244 | PASSWORD_TABLE_INC * sizeof (PASSWORD_INFO) + \r | |
245 | VarSize\r | |
246 | );\r | |
247 | if (mPwdTable == NULL) {\r | |
248 | FreePool (Var);\r | |
249 | return EFI_OUT_OF_RESOURCES;\r | |
250 | }\r | |
251 | \r | |
252 | mPwdTable->Count = VarSize / sizeof (PASSWORD_INFO);\r | |
253 | mPwdTable->MaxCount = mPwdTable->Count + PASSWORD_TABLE_INC;\r | |
254 | mPwdTable->ValidIndex = 0;\r | |
255 | if (Var != NULL) {\r | |
256 | CopyMem (mPwdTable->UserInfo, Var, VarSize);\r | |
257 | FreePool (Var);\r | |
258 | }\r | |
259 | return EFI_SUCCESS;\r | |
260 | }\r | |
261 | \r | |
262 | \r | |
263 | /**\r | |
264 | Hash the password to get credential.\r | |
265 | \r | |
266 | @param[in] Password Points to the input password.\r | |
267 | @param[in] PasswordSize The size of password, in bytes.\r | |
268 | @param[out] Credential Points to the hashed result.\r | |
269 | \r | |
270 | @retval TRUE Hash the password successfully.\r | |
271 | @retval FALSE Failed to hash the password.\r | |
272 | \r | |
273 | **/\r | |
274 | BOOLEAN\r | |
275 | GenerateCredential (\r | |
276 | IN CHAR16 *Password,\r | |
277 | IN UINTN PasswordSize,\r | |
278 | OUT UINT8 *Credential\r | |
279 | )\r | |
280 | {\r | |
281 | BOOLEAN Status;\r | |
282 | UINTN HashSize;\r | |
283 | VOID *Hash;\r | |
284 | \r | |
285 | HashSize = Sha1GetContextSize ();\r | |
286 | Hash = AllocatePool (HashSize);\r | |
287 | ASSERT (Hash != NULL);\r | |
288 | \r | |
289 | Status = Sha1Init (Hash);\r | |
290 | if (!Status) {\r | |
291 | goto Done;\r | |
292 | }\r | |
293 | \r | |
294 | Status = Sha1Update (Hash, Password, PasswordSize);\r | |
295 | if (!Status) {\r | |
296 | goto Done;\r | |
297 | }\r | |
298 | \r | |
299 | Status = Sha1Final (Hash, Credential);\r | |
300 | \r | |
301 | Done:\r | |
302 | FreePool (Hash);\r | |
303 | return Status;\r | |
304 | }\r | |
305 | \r | |
306 | \r | |
307 | /**\r | |
308 | Get password from user input.\r | |
309 | \r | |
310 | @param[in] FirstPwd If True, prompt to input the first password.\r | |
311 | If False, prompt to input password again.\r | |
312 | @param[out] Credential Points to the input password.\r | |
313 | \r | |
314 | **/\r | |
315 | VOID\r | |
316 | GetPassword (\r | |
317 | IN BOOLEAN FirstPwd,\r | |
318 | OUT CHAR8 *Credential\r | |
319 | )\r | |
320 | {\r | |
321 | EFI_INPUT_KEY Key;\r | |
322 | CHAR16 PasswordMask[CREDENTIAL_LEN + 1];\r | |
323 | CHAR16 Password[CREDENTIAL_LEN];\r | |
324 | UINTN PasswordLen;\r | |
325 | CHAR16 *QuestionStr;\r | |
326 | CHAR16 *LineStr;\r | |
327 | \r | |
328 | PasswordLen = 0;\r | |
329 | while (TRUE) {\r | |
330 | PasswordMask[PasswordLen] = L'_';\r | |
331 | PasswordMask[PasswordLen + 1] = L'\0';\r | |
332 | LineStr = GetStringById (STRING_TOKEN (STR_DRAW_A_LINE));\r | |
333 | if (FirstPwd) {\r | |
334 | QuestionStr = GetStringById (STRING_TOKEN (STR_INPUT_PASSWORD));\r | |
335 | } else {\r | |
336 | QuestionStr = GetStringById (STRING_TOKEN (STR_INPUT_PASSWORD_AGAIN));\r | |
337 | }\r | |
338 | CreatePopUp (\r | |
339 | EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r | |
340 | &Key,\r | |
341 | QuestionStr,\r | |
342 | LineStr,\r | |
343 | PasswordMask,\r | |
344 | NULL\r | |
345 | );\r | |
346 | FreePool (QuestionStr);\r | |
347 | FreePool (LineStr);\r | |
348 | \r | |
349 | //\r | |
350 | // Check key stroke\r | |
351 | //\r | |
352 | if (Key.ScanCode == SCAN_NULL) {\r | |
353 | if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r | |
354 | break;\r | |
355 | } else if (Key.UnicodeChar == CHAR_BACKSPACE) {\r | |
356 | if (PasswordLen > 0) {\r | |
357 | PasswordLen--;\r | |
358 | }\r | |
359 | } else if ((Key.UnicodeChar == CHAR_NULL) || \r | |
360 | (Key.UnicodeChar == CHAR_TAB) || \r | |
361 | (Key.UnicodeChar == CHAR_LINEFEED)) {\r | |
362 | continue;\r | |
363 | } else {\r | |
364 | Password[PasswordLen] = Key.UnicodeChar;\r | |
365 | PasswordMask[PasswordLen] = L'*';\r | |
366 | PasswordLen++;\r | |
367 | if (PasswordLen == CREDENTIAL_LEN) {\r | |
368 | break;\r | |
369 | }\r | |
370 | }\r | |
371 | }\r | |
372 | }\r | |
373 | \r | |
374 | PasswordLen = PasswordLen * sizeof (CHAR16);\r | |
375 | GenerateCredential (Password, PasswordLen, (UINT8 *)Credential);\r | |
376 | }\r | |
377 | \r | |
378 | /**\r | |
379 | Check whether the password can be found on this provider.\r | |
380 | \r | |
381 | @param[in] Password The password to be found.\r | |
382 | \r | |
383 | @retval EFI_SUCCESS Found password sucessfully.\r | |
384 | @retval EFI_NOT_FOUND Fail to find the password.\r | |
385 | \r | |
386 | **/\r | |
387 | EFI_STATUS\r | |
388 | CheckPassword (\r | |
389 | IN CHAR8 *Password\r | |
390 | )\r | |
391 | {\r | |
392 | UINTN Index;\r | |
393 | CHAR8 *Pwd;\r | |
394 | \r | |
395 | //\r | |
396 | // Check password credential.\r | |
397 | //\r | |
398 | mPwdTable->ValidIndex = 0;\r | |
399 | for (Index = 0; Index < mPwdTable->Count; Index++) {\r | |
400 | Pwd = mPwdTable->UserInfo[Index].Password;\r | |
401 | if (CompareMem (Pwd, Password, CREDENTIAL_LEN) == 0) {\r | |
402 | mPwdTable->ValidIndex = Index + 1;\r | |
403 | return EFI_SUCCESS;\r | |
404 | }\r | |
405 | }\r | |
406 | \r | |
407 | return EFI_NOT_FOUND;\r | |
408 | }\r | |
409 | \r | |
410 | \r | |
411 | /**\r | |
412 | Find a user infomation record by the information record type.\r | |
413 | \r | |
414 | This function searches all user information records of User from beginning \r | |
415 | until either the information is found, or there are no more user infomation\r | |
416 | records. A match occurs when a Info.InfoType field matches the user information\r | |
417 | record type.\r | |
418 | \r | |
419 | @param[in] User Points to the user profile record to search. \r | |
420 | @param[in] InfoType The infomation type to be searched.\r | |
421 | @param[out] Info Points to the user info found, the caller is responsible\r | |
422 | to free.\r | |
423 | \r | |
424 | @retval EFI_SUCCESS Find the user information successfully.\r | |
425 | @retval Others Fail to find the user information.\r | |
426 | \r | |
427 | **/\r | |
428 | EFI_STATUS\r | |
429 | FindUserInfoByType (\r | |
430 | IN EFI_USER_PROFILE_HANDLE User,\r | |
431 | IN UINT8 InfoType,\r | |
432 | OUT EFI_USER_INFO **Info\r | |
433 | )\r | |
434 | {\r | |
435 | EFI_STATUS Status;\r | |
436 | EFI_USER_INFO *UserInfo;\r | |
437 | UINTN UserInfoSize;\r | |
438 | EFI_USER_INFO_HANDLE UserInfoHandle;\r | |
439 | EFI_USER_MANAGER_PROTOCOL *UserManager;\r | |
440 | \r | |
441 | //\r | |
442 | // Find user information by information type.\r | |
443 | //\r | |
444 | if (Info == NULL) {\r | |
445 | return EFI_INVALID_PARAMETER;\r | |
446 | }\r | |
447 | \r | |
448 | Status = gBS->LocateProtocol (\r | |
449 | &gEfiUserManagerProtocolGuid,\r | |
450 | NULL,\r | |
451 | (VOID **) &UserManager\r | |
452 | );\r | |
453 | if (EFI_ERROR (Status)) {\r | |
454 | return EFI_NOT_FOUND;\r | |
455 | }\r | |
456 | \r | |
457 | //\r | |
458 | // Get each user information.\r | |
459 | //\r | |
460 | \r | |
461 | UserInfoHandle = NULL;\r | |
462 | UserInfo = NULL;\r | |
463 | UserInfoSize = 0;\r | |
464 | while (TRUE) {\r | |
465 | Status = UserManager->GetNextInfo (UserManager, User, &UserInfoHandle);\r | |
466 | if (EFI_ERROR (Status)) {\r | |
467 | break;\r | |
468 | }\r | |
469 | //\r | |
470 | // Get information.\r | |
471 | //\r | |
472 | Status = UserManager->GetInfo (\r | |
473 | UserManager,\r | |
474 | User,\r | |
475 | UserInfoHandle,\r | |
476 | UserInfo,\r | |
477 | &UserInfoSize\r | |
478 | );\r | |
479 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
480 | if (UserInfo != NULL) {\r | |
481 | FreePool (UserInfo);\r | |
482 | }\r | |
483 | UserInfo = AllocateZeroPool (UserInfoSize);\r | |
484 | if (UserInfo == NULL) {\r | |
485 | return EFI_OUT_OF_RESOURCES;\r | |
486 | }\r | |
487 | Status = UserManager->GetInfo (\r | |
488 | UserManager,\r | |
489 | User,\r | |
490 | UserInfoHandle,\r | |
491 | UserInfo,\r | |
492 | &UserInfoSize\r | |
493 | );\r | |
494 | }\r | |
495 | if (EFI_ERROR (Status)) {\r | |
496 | break;\r | |
497 | }\r | |
498 | \r | |
499 | ASSERT (UserInfo != NULL);\r | |
500 | if (UserInfo->InfoType == InfoType) {\r | |
501 | *Info = UserInfo;\r | |
502 | return EFI_SUCCESS;\r | |
503 | } \r | |
504 | }\r | |
505 | \r | |
506 | if (UserInfo != NULL) {\r | |
507 | FreePool (UserInfo);\r | |
508 | }\r | |
509 | return Status;\r | |
510 | }\r | |
511 | \r | |
512 | \r | |
513 | /**\r | |
514 | This function processes the results of changes in configuration.\r | |
515 | \r | |
516 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
517 | @param Action Specifies the type of action taken by the browser.\r | |
518 | @param QuestionId A unique value which is sent to the original\r | |
519 | exporting driver so that it can identify the type\r | |
520 | of data to expect.\r | |
521 | @param Type The type of value for the question.\r | |
522 | @param Value A pointer to the data being sent to the original\r | |
523 | exporting driver.\r | |
524 | @param ActionRequest On return, points to the action requested by the\r | |
525 | callback function.\r | |
526 | \r | |
527 | @retval EFI_SUCCESS The callback successfully handled the action.\r | |
528 | @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r | |
529 | variable and its data.\r | |
530 | @retval EFI_DEVICE_ERROR The variable could not be saved.\r | |
531 | @retval EFI_UNSUPPORTED The specified Action is not supported by the\r | |
532 | callback.\r | |
533 | \r | |
534 | **/\r | |
535 | EFI_STATUS\r | |
536 | EFIAPI\r | |
537 | CredentialDriverCallback (\r | |
538 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
539 | IN EFI_BROWSER_ACTION Action,\r | |
540 | IN EFI_QUESTION_ID QuestionId,\r | |
541 | IN UINT8 Type,\r | |
542 | IN EFI_IFR_TYPE_VALUE *Value,\r | |
543 | OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r | |
544 | )\r | |
545 | {\r | |
546 | EFI_STATUS Status;\r | |
547 | EFI_INPUT_KEY Key;\r | |
548 | CHAR8 Password[CREDENTIAL_LEN];\r | |
549 | CHAR16 *PromptStr;\r | |
550 | \r | |
fab10465 | 551 | if (Action == EFI_BROWSER_ACTION_CHANGED) {\r |
0c18794e | 552 | if (QuestionId == KEY_GET_PASSWORD) {\r |
553 | //\r | |
554 | // Get and check password.\r | |
555 | //\r | |
556 | GetPassword (TRUE, Password);\r | |
557 | Status = CheckPassword (Password);\r | |
558 | if (EFI_ERROR (Status)) {\r | |
559 | PromptStr = GetStringById (STRING_TOKEN (STR_PASSWORD_INCORRECT));\r | |
560 | CreatePopUp (\r | |
561 | EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r | |
562 | &Key,\r | |
563 | L"",\r | |
564 | PromptStr,\r | |
565 | L"",\r | |
566 | NULL\r | |
567 | );\r | |
568 | FreePool (PromptStr);\r | |
569 | return Status;\r | |
570 | }\r | |
571 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r | |
572 | } \r | |
573 | return EFI_SUCCESS;\r | |
574 | }\r | |
575 | \r | |
576 | //\r | |
577 | // All other action return unsupported.\r | |
578 | //\r | |
579 | return EFI_UNSUPPORTED;\r | |
580 | }\r | |
581 | \r | |
582 | \r | |
583 | /**\r | |
584 | This function allows a caller to extract the current configuration for one\r | |
585 | or more named elements from the target driver.\r | |
586 | \r | |
587 | \r | |
588 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
589 | @param Request A null-terminated Unicode string in <ConfigRequest> format.\r | |
590 | @param Progress On return, points to a character in the Request string.\r | |
591 | Points to the string's null terminator if request was successful.\r | |
592 | Points to the most recent '&' before the first failing name/value\r | |
593 | pair (or the beginning of the string if the failure is in the\r | |
594 | first name/value pair) if the request was not successful.\r | |
595 | @param Results A null-terminated Unicode string in <ConfigAltResp> format which\r | |
596 | has all values filled in for the names in the Request string.\r | |
597 | String to be allocated by the called function.\r | |
598 | \r | |
599 | @retval EFI_SUCCESS The Results is filled with the requested values.\r | |
600 | @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r | |
601 | @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.\r | |
602 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r | |
603 | \r | |
604 | **/\r | |
605 | EFI_STATUS\r | |
606 | EFIAPI\r | |
607 | FakeExtractConfig (\r | |
608 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
609 | IN CONST EFI_STRING Request,\r | |
610 | OUT EFI_STRING *Progress,\r | |
611 | OUT EFI_STRING *Results\r | |
612 | )\r | |
613 | {\r | |
614 | if (Progress == NULL || Results == NULL) {\r | |
615 | return EFI_INVALID_PARAMETER;\r | |
616 | }\r | |
617 | *Progress = Request;\r | |
618 | return EFI_NOT_FOUND;\r | |
619 | }\r | |
620 | \r | |
621 | /**\r | |
622 | This function processes the results of changes in configuration.\r | |
623 | \r | |
624 | \r | |
625 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
626 | @param Configuration A null-terminated Unicode string in <ConfigResp> format.\r | |
627 | @param Progress A pointer to a string filled in with the offset of the most\r | |
628 | recent '&' before the first failing name/value pair (or the\r | |
629 | beginning of the string if the failure is in the first\r | |
630 | name/value pair) or the terminating NULL if all was successful.\r | |
631 | \r | |
632 | @retval EFI_SUCCESS The Results is processed successfully.\r | |
633 | @retval EFI_INVALID_PARAMETER Configuration is NULL.\r | |
634 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r | |
635 | \r | |
636 | **/\r | |
637 | EFI_STATUS\r | |
638 | EFIAPI\r | |
639 | FakeRouteConfig (\r | |
640 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
641 | IN CONST EFI_STRING Configuration,\r | |
642 | OUT EFI_STRING *Progress\r | |
643 | )\r | |
644 | {\r | |
645 | if (Configuration == NULL || Progress == NULL) {\r | |
646 | return EFI_INVALID_PARAMETER;\r | |
647 | }\r | |
648 | \r | |
649 | return EFI_NOT_FOUND;\r | |
650 | }\r | |
651 | \r | |
652 | /**\r | |
653 | This function initialize the data mainly used in form browser.\r | |
654 | \r | |
655 | @retval EFI_SUCCESS Initialize form data successfully.\r | |
656 | @retval Others Fail to Initialize form data.\r | |
657 | \r | |
658 | **/\r | |
659 | EFI_STATUS\r | |
660 | InitFormBrowser (\r | |
661 | VOID\r | |
662 | )\r | |
663 | {\r | |
664 | EFI_STATUS Status;\r | |
665 | PWD_PROVIDER_CALLBACK_INFO *CallbackInfo;\r | |
666 | \r | |
667 | //\r | |
668 | // Initialize driver private data.\r | |
669 | //\r | |
670 | CallbackInfo = AllocateZeroPool (sizeof (PWD_PROVIDER_CALLBACK_INFO));\r | |
671 | if (CallbackInfo == NULL) {\r | |
672 | return EFI_OUT_OF_RESOURCES;\r | |
673 | }\r | |
674 | \r | |
675 | CallbackInfo->Signature = PWD_PROVIDER_SIGNATURE;\r | |
676 | CallbackInfo->ConfigAccess.ExtractConfig = FakeExtractConfig;\r | |
677 | CallbackInfo->ConfigAccess.RouteConfig = FakeRouteConfig;\r | |
678 | CallbackInfo->ConfigAccess.Callback = CredentialDriverCallback;\r | |
679 | CallbackInfo->DriverHandle = NULL;\r | |
680 | \r | |
681 | //\r | |
682 | // Install Device Path Protocol and Config Access protocol to driver handle.\r | |
683 | //\r | |
684 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
685 | &CallbackInfo->DriverHandle,\r | |
686 | &gEfiDevicePathProtocolGuid,\r | |
687 | &mHiiVendorDevicePath,\r | |
688 | &gEfiHiiConfigAccessProtocolGuid,\r | |
689 | &CallbackInfo->ConfigAccess,\r | |
690 | NULL\r | |
691 | );\r | |
692 | ASSERT_EFI_ERROR (Status);\r | |
693 | \r | |
694 | //\r | |
695 | // Publish HII data.\r | |
696 | //\r | |
697 | CallbackInfo->HiiHandle = HiiAddPackages (\r | |
a0c56a82 | 698 | &gPwdCredentialProviderGuid,\r |
0c18794e | 699 | CallbackInfo->DriverHandle,\r |
700 | PwdCredentialProviderStrings,\r | |
701 | PwdCredentialProviderVfrBin,\r | |
702 | NULL\r | |
703 | );\r | |
704 | if (CallbackInfo->HiiHandle == NULL) {\r | |
705 | return EFI_OUT_OF_RESOURCES;\r | |
706 | }\r | |
707 | mCallbackInfo = CallbackInfo;\r | |
708 | \r | |
709 | return Status;\r | |
710 | }\r | |
711 | \r | |
712 | \r | |
713 | /**\r | |
714 | Enroll a user on a credential provider.\r | |
715 | \r | |
6f0b8648 | 716 | This function enrolls a user on this credential provider. If the user exists on \r |
717 | this credential provider, update the user information on this credential provider; \r | |
718 | otherwise add the user information on credential provider.\r | |
0c18794e | 719 | \r |
6f0b8648 | 720 | @param[in] This Points to this instance of EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 721 | @param[in] User The user profile to enroll.\r |
722 | \r | |
723 | @retval EFI_SUCCESS User profile was successfully enrolled.\r | |
724 | @retval EFI_ACCESS_DENIED Current user profile does not permit enrollment on the\r | |
725 | user profile handle. Either the user profile cannot enroll\r | |
726 | on any user profile or cannot enroll on a user profile \r | |
727 | other than the current user profile.\r | |
728 | @retval EFI_UNSUPPORTED This credential provider does not support enrollment in\r | |
729 | the pre-OS.\r | |
730 | @retval EFI_DEVICE_ERROR The new credential could not be created because of a device\r | |
731 | error.\r | |
732 | @retval EFI_INVALID_PARAMETER User does not refer to a valid user profile handle.\r | |
733 | \r | |
734 | **/\r | |
735 | EFI_STATUS\r | |
736 | EFIAPI\r | |
737 | CredentialEnroll (\r | |
6f0b8648 | 738 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 739 | IN EFI_USER_PROFILE_HANDLE User\r |
740 | )\r | |
741 | {\r | |
742 | EFI_STATUS Status;\r | |
743 | UINTN Index;\r | |
744 | PASSWORD_INFO PwdInfo;\r | |
745 | EFI_USER_INFO *UserInfo;\r | |
746 | CHAR8 Password[CREDENTIAL_LEN];\r | |
747 | EFI_INPUT_KEY Key;\r | |
0c18794e | 748 | UINT8 *UserId;\r |
0c18794e | 749 | CHAR16 *QuestionStr;\r |
750 | CHAR16 *PromptStr;\r | |
751 | \r | |
752 | if ((This == NULL) || (User == NULL)) {\r | |
753 | return EFI_INVALID_PARAMETER;\r | |
754 | }\r | |
755 | \r | |
0c18794e | 756 | //\r |
757 | // Get User Identifier.\r | |
758 | //\r | |
759 | UserInfo = NULL;\r | |
760 | Status = FindUserInfoByType (\r | |
761 | User,\r | |
762 | EFI_USER_INFO_IDENTIFIER_RECORD,\r | |
763 | &UserInfo\r | |
764 | );\r | |
765 | if (EFI_ERROR (Status)) {\r | |
766 | return EFI_INVALID_PARAMETER;\r | |
767 | }\r | |
768 | \r | |
6f0b8648 | 769 | CopyMem (PwdInfo.UserId, (UINT8 *) (UserInfo + 1), sizeof (EFI_USER_INFO_IDENTIFIER)); \r |
770 | FreePool (UserInfo);\r | |
0c18794e | 771 | \r |
772 | //\r | |
6f0b8648 | 773 | // Get password from user.\r |
0c18794e | 774 | // \r |
775 | while (TRUE) {\r | |
776 | //\r | |
777 | // Input password.\r | |
778 | //\r | |
779 | GetPassword (TRUE, PwdInfo.Password);\r | |
780 | \r | |
781 | //\r | |
782 | // Input password again.\r | |
783 | //\r | |
784 | GetPassword (FALSE, Password);\r | |
785 | \r | |
786 | //\r | |
787 | // Compare the two password consistency.\r | |
788 | //\r | |
789 | if (CompareMem (PwdInfo.Password, Password, CREDENTIAL_LEN) == 0) {\r | |
790 | break;\r | |
791 | } \r | |
792 | \r | |
793 | QuestionStr = GetStringById (STRING_TOKEN (STR_PASSWORD_MISMATCH));\r | |
794 | PromptStr = GetStringById (STRING_TOKEN (STR_INPUT_PASSWORD_AGAIN)); \r | |
795 | CreatePopUp (\r | |
796 | EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r | |
797 | &Key,\r | |
798 | QuestionStr,\r | |
799 | L"",\r | |
800 | PromptStr,\r | |
801 | NULL\r | |
802 | );\r | |
803 | FreePool (QuestionStr);\r | |
804 | FreePool (PromptStr);\r | |
805 | }\r | |
806 | \r | |
0c18794e | 807 | //\r |
6f0b8648 | 808 | // Check whether User is ever enrolled in the provider.\r |
809 | // \r | |
810 | for (Index = 0; Index < mPwdTable->Count; Index++) {\r | |
811 | UserId = (UINT8 *) &mPwdTable->UserInfo[Index].UserId;\r | |
812 | if (CompareMem (UserId, (UINT8 *) &PwdInfo.UserId, sizeof (EFI_USER_INFO_IDENTIFIER)) == 0) {\r | |
813 | //\r | |
814 | // User already exists, update the password.\r | |
815 | // \r | |
816 | break;\r | |
817 | }\r | |
818 | }\r | |
819 | \r | |
820 | //\r | |
821 | // Enroll the User to the provider.\r | |
0c18794e | 822 | //\r |
6f0b8648 | 823 | Status = ModifyTable (Index, &PwdInfo);\r |
0c18794e | 824 | if (EFI_ERROR (Status)) {\r |
825 | return Status;\r | |
826 | }\r | |
827 | \r | |
0c18794e | 828 | return EFI_SUCCESS;\r |
829 | }\r | |
830 | \r | |
831 | \r | |
832 | /**\r | |
833 | Returns the user interface information used during user identification.\r | |
834 | \r | |
835 | This function returns information about the form used when interacting with the\r | |
836 | user during user identification. The form is the first enabled form in the form-set\r | |
837 | class EFI_HII_USER_CREDENTIAL_FORMSET_GUID installed on the HII handle HiiHandle. If \r | |
838 | the user credential provider does not require a form to identify the user, then this\r | |
839 | function should return EFI_NOT_FOUND.\r | |
840 | \r | |
6f0b8648 | 841 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 842 | @param[out] Hii On return, holds the HII database handle.\r |
843 | @param[out] FormSetId On return, holds the identifier of the form set which contains\r | |
844 | the form used during user identification.\r | |
845 | @param[out] FormId On return, holds the identifier of the form used during user \r | |
846 | identification.\r | |
847 | \r | |
848 | @retval EFI_SUCCESS Form returned successfully.\r | |
849 | @retval EFI_NOT_FOUND Form not returned.\r | |
850 | @retval EFI_INVALID_PARAMETER Hii is NULL or FormSetId is NULL or FormId is NULL.\r | |
851 | \r | |
852 | **/\r | |
853 | EFI_STATUS\r | |
854 | EFIAPI\r | |
855 | CredentialForm (\r | |
6f0b8648 | 856 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 857 | OUT EFI_HII_HANDLE *Hii,\r |
858 | OUT EFI_GUID *FormSetId,\r | |
859 | OUT EFI_FORM_ID *FormId\r | |
860 | )\r | |
861 | {\r | |
862 | if ((This == NULL) || (Hii == NULL) || \r | |
863 | (FormSetId == NULL) || (FormId == NULL)) {\r | |
864 | return EFI_INVALID_PARAMETER;\r | |
865 | }\r | |
866 | \r | |
867 | *Hii = mCallbackInfo->HiiHandle;\r | |
868 | *FormId = FORMID_GET_PASSWORD_FORM;\r | |
a0c56a82 | 869 | CopyGuid (FormSetId, &gPwdCredentialProviderGuid);\r |
0c18794e | 870 | \r |
871 | return EFI_SUCCESS;\r | |
872 | }\r | |
873 | \r | |
874 | \r | |
875 | /**\r | |
876 | Returns bitmap used to describe the credential provider type.\r | |
877 | \r | |
878 | This optional function returns a bitmap that is less than or equal to the number\r | |
879 | of pixels specified by Width and Height. If no such bitmap exists, then EFI_NOT_FOUND\r | |
880 | is returned. \r | |
881 | \r | |
6f0b8648 | 882 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 883 | @param[in, out] Width On entry, points to the desired bitmap width. If NULL then no \r |
884 | bitmap information will be returned. On exit, points to the \r | |
885 | width of the bitmap returned.\r | |
886 | @param[in, out] Height On entry, points to the desired bitmap height. If NULL then no\r | |
887 | bitmap information will be returned. On exit, points to the \r | |
888 | height of the bitmap returned\r | |
889 | @param[out] Hii On return, holds the HII database handle. \r | |
890 | @param[out] Image On return, holds the HII image identifier. \r | |
891 | \r | |
892 | @retval EFI_SUCCESS Image identifier returned successfully.\r | |
893 | @retval EFI_NOT_FOUND Image identifier not returned.\r | |
894 | @retval EFI_INVALID_PARAMETER Hii is NULL or Image is NULL.\r | |
895 | \r | |
896 | **/\r | |
897 | EFI_STATUS\r | |
898 | EFIAPI\r | |
899 | CredentialTile (\r | |
6f0b8648 | 900 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 901 | IN OUT UINTN *Width,\r |
902 | IN OUT UINTN *Height,\r | |
903 | OUT EFI_HII_HANDLE *Hii,\r | |
904 | OUT EFI_IMAGE_ID *Image\r | |
905 | )\r | |
906 | { \r | |
907 | if ((This == NULL) || (Hii == NULL) || (Image == NULL)) {\r | |
908 | return EFI_INVALID_PARAMETER;\r | |
909 | }\r | |
910 | return EFI_NOT_FOUND;\r | |
911 | }\r | |
912 | \r | |
913 | \r | |
914 | /**\r | |
915 | Returns string used to describe the credential provider type.\r | |
916 | \r | |
917 | This function returns a string which describes the credential provider. If no\r | |
918 | such string exists, then EFI_NOT_FOUND is returned. \r | |
919 | \r | |
6f0b8648 | 920 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 921 | @param[out] Hii On return, holds the HII database handle.\r |
922 | @param[out] String On return, holds the HII string identifier.\r | |
923 | \r | |
924 | @retval EFI_SUCCESS String identifier returned successfully.\r | |
925 | @retval EFI_NOT_FOUND String identifier not returned.\r | |
926 | @retval EFI_INVALID_PARAMETER Hii is NULL or String is NULL.\r | |
927 | \r | |
928 | **/\r | |
929 | EFI_STATUS\r | |
930 | EFIAPI\r | |
931 | CredentialTitle (\r | |
6f0b8648 | 932 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 933 | OUT EFI_HII_HANDLE *Hii,\r |
934 | OUT EFI_STRING_ID *String\r | |
935 | )\r | |
936 | {\r | |
937 | if ((This == NULL) || (Hii == NULL) || (String == NULL)) {\r | |
938 | return EFI_INVALID_PARAMETER;\r | |
939 | }\r | |
940 | \r | |
941 | //\r | |
942 | // Set Hii handle and String ID.\r | |
943 | //\r | |
944 | *Hii = mCallbackInfo->HiiHandle;\r | |
945 | *String = STRING_TOKEN (STR_CREDENTIAL_TITLE);\r | |
946 | \r | |
947 | return EFI_SUCCESS;\r | |
948 | }\r | |
949 | \r | |
950 | \r | |
951 | /**\r | |
952 | Return the user identifier associated with the currently authenticated user.\r | |
953 | \r | |
954 | This function returns the user identifier of the user authenticated by this credential\r | |
955 | provider. This function is called after the credential-related information has been \r | |
956 | submitted on a form, OR after a call to Default() has returned that this credential is\r | |
957 | ready to log on.\r | |
958 | \r | |
6f0b8648 | 959 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 960 | @param[in] User The user profile handle of the user profile currently being \r |
961 | considered by the user identity manager. If NULL, then no user\r | |
962 | profile is currently under consideration.\r | |
963 | @param[out] Identifier On return, points to the user identifier. \r | |
964 | \r | |
965 | @retval EFI_SUCCESS User identifier returned successfully.\r | |
966 | @retval EFI_NOT_READY No user identifier can be returned.\r | |
967 | @retval EFI_ACCESS_DENIED The user has been locked out of this user credential.\r | |
968 | @retval EFI_INVALID_PARAMETER This is NULL, or Identifier is NULL.\r | |
969 | @retval EFI_NOT_FOUND User is not NULL, and the specified user handle can't be\r | |
970 | found in user profile database\r | |
971 | \r | |
972 | **/\r | |
973 | EFI_STATUS\r | |
974 | EFIAPI\r | |
975 | CredentialUser (\r | |
6f0b8648 | 976 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 977 | IN EFI_USER_PROFILE_HANDLE User,\r |
978 | OUT EFI_USER_INFO_IDENTIFIER *Identifier\r | |
979 | )\r | |
980 | {\r | |
981 | EFI_STATUS Status;\r | |
982 | UINTN Index;\r | |
983 | EFI_USER_INFO *UserInfo;\r | |
984 | UINT8 *UserId;\r | |
985 | UINT8 *NewUserId;\r | |
986 | CHAR8 *Pwd;\r | |
987 | CHAR8 *NewPwd;\r | |
988 | \r | |
989 | if ((This == NULL) || (Identifier == NULL)) {\r | |
990 | return EFI_INVALID_PARAMETER;\r | |
991 | }\r | |
992 | \r | |
993 | if (mPwdTable->ValidIndex == 0) {\r | |
994 | //\r | |
995 | // No password input, or the input password doesn't match\r | |
996 | // anyone in PwdTable.\r | |
997 | //\r | |
998 | return EFI_NOT_READY;\r | |
999 | }\r | |
1000 | \r | |
1001 | if (User == NULL) {\r | |
1002 | //\r | |
1003 | // Return the user ID whose password matches the input password.\r | |
1004 | // \r | |
1005 | CopyMem (\r | |
1006 | Identifier, \r | |
1007 | &mPwdTable->UserInfo[mPwdTable->ValidIndex - 1].UserId, \r | |
1008 | sizeof (EFI_USER_INFO_IDENTIFIER)\r | |
1009 | ); \r | |
1010 | return EFI_SUCCESS;\r | |
1011 | }\r | |
1012 | \r | |
1013 | //\r | |
1014 | // Get the User's ID.\r | |
1015 | //\r | |
1016 | Status = FindUserInfoByType (\r | |
1017 | User,\r | |
1018 | EFI_USER_INFO_IDENTIFIER_RECORD,\r | |
1019 | &UserInfo\r | |
1020 | );\r | |
1021 | if (EFI_ERROR (Status)) {\r | |
1022 | return EFI_NOT_FOUND;\r | |
1023 | }\r | |
1024 | \r | |
1025 | //\r | |
1026 | // Check whether the input password matches one in PwdTable.\r | |
1027 | //\r | |
1028 | for (Index = 0; Index < mPwdTable->Count; Index++) {\r | |
1029 | UserId = (UINT8 *) &mPwdTable->UserInfo[Index].UserId;\r | |
1030 | NewUserId = (UINT8 *) (UserInfo + 1);\r | |
1031 | if (CompareMem (UserId, NewUserId, sizeof (EFI_USER_INFO_IDENTIFIER)) == 0) {\r | |
1032 | Pwd = mPwdTable->UserInfo[Index].Password;\r | |
1033 | NewPwd = mPwdTable->UserInfo[mPwdTable->ValidIndex - 1].Password;\r | |
1034 | if (CompareMem (Pwd, NewPwd, CREDENTIAL_LEN) == 0) {\r | |
1035 | CopyMem (Identifier, UserId, sizeof (EFI_USER_INFO_IDENTIFIER));\r | |
1036 | FreePool (UserInfo);\r | |
1037 | return EFI_SUCCESS;\r | |
1038 | } \r | |
1039 | }\r | |
1040 | }\r | |
1041 | \r | |
0c18794e | 1042 | FreePool (UserInfo); \r |
ae4cb94f | 1043 | return EFI_NOT_READY;\r |
0c18794e | 1044 | }\r |
1045 | \r | |
1046 | \r | |
1047 | /**\r | |
1048 | Indicate that user interface interaction has begun for the specified credential.\r | |
1049 | \r | |
1050 | This function is called when a credential provider is selected by the user. If \r | |
1051 | AutoLogon returns FALSE, then the user interface will be constructed by the User\r | |
1052 | Identity Manager. \r | |
1053 | \r | |
6f0b8648 | 1054 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 1055 | @param[out] AutoLogon On return, points to the credential provider's capabilities \r |
1056 | after the credential provider has been selected by the user. \r | |
1057 | \r | |
1058 | @retval EFI_SUCCESS Credential provider successfully selected.\r | |
1059 | @retval EFI_INVALID_PARAMETER AutoLogon is NULL.\r | |
1060 | \r | |
1061 | **/\r | |
1062 | EFI_STATUS\r | |
1063 | EFIAPI\r | |
1064 | CredentialSelect (\r | |
6f0b8648 | 1065 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 1066 | OUT EFI_CREDENTIAL_LOGON_FLAGS *AutoLogon\r |
1067 | )\r | |
1068 | {\r | |
1069 | if ((This == NULL) || (AutoLogon == NULL)) {\r | |
1070 | return EFI_INVALID_PARAMETER;\r | |
1071 | }\r | |
1072 | *AutoLogon = 0;\r | |
1073 | \r | |
1074 | return EFI_SUCCESS;\r | |
1075 | }\r | |
1076 | \r | |
1077 | \r | |
1078 | /**\r | |
1079 | Indicate that user interface interaction has ended for the specified credential.\r | |
1080 | \r | |
1081 | This function is called when a credential provider is deselected by the user.\r | |
1082 | \r | |
6f0b8648 | 1083 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 1084 | \r |
1085 | @retval EFI_SUCCESS Credential provider successfully deselected.\r | |
1086 | \r | |
1087 | **/\r | |
1088 | EFI_STATUS\r | |
1089 | EFIAPI\r | |
1090 | CredentialDeselect (\r | |
6f0b8648 | 1091 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This\r |
0c18794e | 1092 | )\r |
1093 | {\r | |
1094 | if (This == NULL) {\r | |
1095 | return EFI_INVALID_PARAMETER;\r | |
1096 | }\r | |
1097 | return EFI_SUCCESS;\r | |
1098 | }\r | |
1099 | \r | |
1100 | \r | |
1101 | /**\r | |
1102 | Return the default logon behavior for this user credential.\r | |
1103 | \r | |
1104 | This function reports the default login behavior regarding this credential provider. \r | |
1105 | \r | |
6f0b8648 | 1106 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 1107 | @param[out] AutoLogon On return, holds whether the credential provider should be used\r |
1108 | by default to automatically log on the user. \r | |
1109 | \r | |
1110 | @retval EFI_SUCCESS Default information successfully returned.\r | |
1111 | @retval EFI_INVALID_PARAMETER AutoLogon is NULL.\r | |
1112 | \r | |
1113 | **/\r | |
1114 | EFI_STATUS\r | |
1115 | EFIAPI\r | |
1116 | CredentialDefault (\r | |
6f0b8648 | 1117 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 1118 | OUT EFI_CREDENTIAL_LOGON_FLAGS *AutoLogon\r |
1119 | )\r | |
1120 | {\r | |
1121 | if ((This == NULL) || (AutoLogon == NULL)) {\r | |
1122 | return EFI_INVALID_PARAMETER;\r | |
1123 | }\r | |
1124 | *AutoLogon = 0;\r | |
1125 | \r | |
1126 | return EFI_SUCCESS;\r | |
1127 | }\r | |
1128 | \r | |
1129 | \r | |
1130 | /**\r | |
1131 | Return information attached to the credential provider.\r | |
1132 | \r | |
1133 | This function returns user information. \r | |
1134 | \r | |
6f0b8648 | 1135 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 1136 | @param[in] UserInfo Handle of the user information data record. \r |
1137 | @param[out] Info On entry, points to a buffer of at least *InfoSize bytes. On\r | |
1138 | exit, holds the user information. If the buffer is too small\r | |
1139 | to hold the information, then EFI_BUFFER_TOO_SMALL is returned\r | |
1140 | and InfoSize is updated to contain the number of bytes actually\r | |
1141 | required.\r | |
1142 | @param[in, out] InfoSize On entry, points to the size of Info. On return, points to the \r | |
1143 | size of the user information. \r | |
1144 | \r | |
1145 | @retval EFI_SUCCESS Information returned successfully.\r | |
1146 | @retval EFI_BUFFER_TOO_SMALL The size specified by InfoSize is too small to hold all of the\r | |
1147 | user information. The size required is returned in *InfoSize.\r | |
1148 | @retval EFI_INVALID_PARAMETER Info is NULL or InfoSize is NULL.\r | |
1149 | @retval EFI_NOT_FOUND The specified UserInfo does not refer to a valid user info handle. \r | |
1150 | \r | |
1151 | **/\r | |
1152 | EFI_STATUS\r | |
1153 | EFIAPI\r | |
1154 | CredentialGetInfo (\r | |
6f0b8648 | 1155 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 1156 | IN EFI_USER_INFO_HANDLE UserInfo,\r |
1157 | OUT EFI_USER_INFO *Info,\r | |
1158 | IN OUT UINTN *InfoSize\r | |
1159 | )\r | |
1160 | {\r | |
1161 | EFI_USER_INFO *CredentialInfo;\r | |
1162 | UINTN Index;\r | |
1163 | \r | |
1164 | if ((This == NULL) || (InfoSize == NULL) || (Info == NULL)) {\r | |
1165 | return EFI_INVALID_PARAMETER;\r | |
1166 | }\r | |
1167 | \r | |
1168 | if ((UserInfo == NULL) || (mPwdInfoHandle == NULL)) {\r | |
1169 | return EFI_NOT_FOUND;\r | |
1170 | }\r | |
1171 | \r | |
1172 | //\r | |
1173 | // Find information handle in credential info table.\r | |
1174 | //\r | |
1175 | for (Index = 0; Index < mPwdInfoHandle->Count; Index++) {\r | |
1176 | CredentialInfo = mPwdInfoHandle->Info[Index];\r | |
1177 | if (UserInfo == (EFI_USER_INFO_HANDLE)CredentialInfo) {\r | |
1178 | //\r | |
1179 | // The handle is found, copy the user info.\r | |
1180 | //\r | |
1181 | if (CredentialInfo->InfoSize > *InfoSize) {\r | |
1182 | *InfoSize = CredentialInfo->InfoSize;\r | |
1183 | return EFI_BUFFER_TOO_SMALL;\r | |
1184 | }\r | |
1185 | CopyMem (Info, CredentialInfo, CredentialInfo->InfoSize); \r | |
1186 | return EFI_SUCCESS; \r | |
1187 | }\r | |
1188 | }\r | |
1189 | \r | |
1190 | return EFI_NOT_FOUND;\r | |
1191 | }\r | |
1192 | \r | |
1193 | \r | |
1194 | /**\r | |
1195 | Enumerate all of the user informations on the credential provider.\r | |
1196 | \r | |
1197 | This function returns the next user information record. To retrieve the first user\r | |
1198 | information record handle, point UserInfo at a NULL. Each subsequent call will retrieve\r | |
1199 | another user information record handle until there are no more, at which point UserInfo\r | |
1200 | will point to NULL. \r | |
1201 | \r | |
6f0b8648 | 1202 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r |
0c18794e | 1203 | @param[in, out] UserInfo On entry, points to the previous user information handle or NULL\r |
1204 | to start enumeration. On exit, points to the next user information\r | |
1205 | handle or NULL if there is no more user information.\r | |
1206 | \r | |
1207 | @retval EFI_SUCCESS User information returned.\r | |
1208 | @retval EFI_NOT_FOUND No more user information found.\r | |
1209 | @retval EFI_INVALID_PARAMETER UserInfo is NULL.\r | |
1210 | \r | |
1211 | **/\r | |
1212 | EFI_STATUS\r | |
1213 | EFIAPI\r | |
1214 | CredentialGetNextInfo (\r | |
6f0b8648 | 1215 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r |
0c18794e | 1216 | IN OUT EFI_USER_INFO_HANDLE *UserInfo\r |
1217 | )\r | |
1218 | {\r | |
1219 | EFI_USER_INFO *Info;\r | |
1220 | CHAR16 *ProvNameStr;\r | |
1221 | UINTN InfoLen;\r | |
1222 | UINTN Index;\r | |
1223 | UINTN ProvStrLen;\r | |
1224 | \r | |
1225 | if ((This == NULL) || (UserInfo == NULL)) {\r | |
1226 | return EFI_INVALID_PARAMETER;\r | |
1227 | }\r | |
1228 | \r | |
1229 | if (mPwdInfoHandle == NULL) {\r | |
1230 | //\r | |
1231 | // Initilized user info table. There are 4 user info records in the table.\r | |
1232 | //\r | |
1233 | InfoLen = sizeof (PASSWORD_CREDENTIAL_INFO) + (4 - 1) * sizeof (EFI_USER_INFO *);\r | |
1234 | mPwdInfoHandle = AllocateZeroPool (InfoLen);\r | |
1235 | if (mPwdInfoHandle == NULL) {\r | |
1236 | *UserInfo = NULL;\r | |
1237 | return EFI_NOT_FOUND;\r | |
1238 | }\r | |
1239 | \r | |
1240 | //\r | |
1241 | // The first information, Credential Provider info.\r | |
1242 | //\r | |
1243 | InfoLen = sizeof (EFI_USER_INFO) + sizeof (EFI_GUID);\r | |
1244 | Info = AllocateZeroPool (InfoLen);\r | |
1245 | ASSERT (Info != NULL);\r | |
1246 | \r | |
1247 | Info->InfoType = EFI_USER_INFO_CREDENTIAL_PROVIDER_RECORD;\r | |
1248 | Info->InfoSize = (UINT32) InfoLen;\r | |
1249 | Info->InfoAttribs = EFI_USER_INFO_PROTECTED;\r | |
a0c56a82 LG |
1250 | CopyGuid (&Info->Credential, &gPwdCredentialProviderGuid);\r |
1251 | CopyGuid ((EFI_GUID *)(Info + 1), &gPwdCredentialProviderGuid);\r | |
0c18794e | 1252 | \r |
1253 | mPwdInfoHandle->Info[0] = Info;\r | |
1254 | mPwdInfoHandle->Count++;\r | |
1255 | \r | |
1256 | //\r | |
1257 | // The second information, Credential Provider name info.\r | |
1258 | //\r | |
1259 | ProvNameStr = GetStringById (STRING_TOKEN (STR_PROVIDER_NAME));\r | |
1260 | ProvStrLen = StrSize (ProvNameStr);\r | |
1261 | InfoLen = sizeof (EFI_USER_INFO) + ProvStrLen;\r | |
1262 | Info = AllocateZeroPool (InfoLen);\r | |
1263 | ASSERT (Info != NULL);\r | |
1264 | \r | |
1265 | Info->InfoType = EFI_USER_INFO_CREDENTIAL_PROVIDER_NAME_RECORD;\r | |
1266 | Info->InfoSize = (UINT32) InfoLen;\r | |
1267 | Info->InfoAttribs = EFI_USER_INFO_PROTECTED;\r | |
a0c56a82 | 1268 | CopyGuid (&Info->Credential, &gPwdCredentialProviderGuid);\r |
0c18794e | 1269 | CopyMem ((UINT8*)(Info + 1), ProvNameStr, ProvStrLen);\r |
1270 | FreePool (ProvNameStr);\r | |
1271 | \r | |
1272 | mPwdInfoHandle->Info[1] = Info;\r | |
1273 | mPwdInfoHandle->Count++;\r | |
1274 | \r | |
1275 | //\r | |
1276 | // The third information, Credential Provider type info.\r | |
1277 | //\r | |
1278 | InfoLen = sizeof (EFI_USER_INFO) + sizeof (EFI_GUID);\r | |
1279 | Info = AllocateZeroPool (InfoLen);\r | |
1280 | ASSERT (Info != NULL);\r | |
1281 | \r | |
1282 | Info->InfoType = EFI_USER_INFO_CREDENTIAL_TYPE_RECORD;\r | |
1283 | Info->InfoSize = (UINT32) InfoLen;\r | |
1284 | Info->InfoAttribs = EFI_USER_INFO_PROTECTED;\r | |
a0c56a82 | 1285 | CopyGuid (&Info->Credential, &gPwdCredentialProviderGuid);\r |
0c18794e | 1286 | CopyGuid ((EFI_GUID *)(Info + 1), &gEfiUserCredentialClassPasswordGuid);\r |
1287 | \r | |
1288 | mPwdInfoHandle->Info[2] = Info;\r | |
1289 | mPwdInfoHandle->Count++;\r | |
1290 | \r | |
1291 | //\r | |
1292 | // The fourth information, Credential Provider type name info.\r | |
1293 | //\r | |
1294 | ProvNameStr = GetStringById (STRING_TOKEN (STR_PROVIDER_TYPE_NAME));\r | |
1295 | ProvStrLen = StrSize (ProvNameStr);\r | |
1296 | InfoLen = sizeof (EFI_USER_INFO) + ProvStrLen;\r | |
1297 | Info = AllocateZeroPool (InfoLen);\r | |
1298 | ASSERT (Info != NULL);\r | |
1299 | \r | |
1300 | Info->InfoType = EFI_USER_INFO_CREDENTIAL_PROVIDER_NAME_RECORD;\r | |
1301 | Info->InfoSize = (UINT32) InfoLen;\r | |
1302 | Info->InfoAttribs = EFI_USER_INFO_PROTECTED;\r | |
a0c56a82 | 1303 | CopyGuid (&Info->Credential, &gPwdCredentialProviderGuid);\r |
0c18794e | 1304 | CopyMem ((UINT8*)(Info + 1), ProvNameStr, ProvStrLen);\r |
1305 | FreePool (ProvNameStr);\r | |
1306 | \r | |
1307 | mPwdInfoHandle->Info[3] = Info;\r | |
1308 | mPwdInfoHandle->Count++;\r | |
1309 | }\r | |
1310 | \r | |
1311 | if (*UserInfo == NULL) {\r | |
1312 | //\r | |
1313 | // Return the first info handle.\r | |
1314 | //\r | |
1315 | *UserInfo = (EFI_USER_INFO_HANDLE) mPwdInfoHandle->Info[0];\r | |
1316 | return EFI_SUCCESS;\r | |
1317 | }\r | |
1318 | \r | |
1319 | //\r | |
1320 | // Find information handle in credential info table.\r | |
1321 | //\r | |
1322 | for (Index = 0; Index < mPwdInfoHandle->Count; Index++) {\r | |
1323 | Info = mPwdInfoHandle->Info[Index];\r | |
1324 | if (*UserInfo == (EFI_USER_INFO_HANDLE)Info) {\r | |
1325 | //\r | |
1326 | // The handle is found, get the next one.\r | |
1327 | //\r | |
1328 | if (Index == mPwdInfoHandle->Count - 1) {\r | |
1329 | //\r | |
1330 | // Already last one.\r | |
1331 | //\r | |
1332 | *UserInfo = NULL;\r | |
1333 | return EFI_NOT_FOUND;\r | |
1334 | }\r | |
1335 | \r | |
1336 | Index++;\r | |
1337 | *UserInfo = (EFI_USER_INFO_HANDLE)mPwdInfoHandle->Info[Index];\r | |
1338 | return EFI_SUCCESS; \r | |
1339 | }\r | |
1340 | }\r | |
1341 | \r | |
1342 | *UserInfo = NULL;\r | |
1343 | return EFI_NOT_FOUND;\r | |
1344 | }\r | |
1345 | \r | |
6f0b8648 | 1346 | /**\r |
1347 | Delete a user on this credential provider.\r | |
1348 | \r | |
1349 | This function deletes a user on this credential provider. \r | |
1350 | \r | |
1351 | @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r | |
1352 | @param[in] User The user profile handle to delete.\r | |
1353 | \r | |
1354 | @retval EFI_SUCCESS User profile was successfully deleted.\r | |
1355 | @retval EFI_ACCESS_DENIED Current user profile does not permit deletion on the user profile handle. \r | |
1356 | Either the user profile cannot delete on any user profile or cannot delete \r | |
1357 | on a user profile other than the current user profile. \r | |
1358 | @retval EFI_UNSUPPORTED This credential provider does not support deletion in the pre-OS.\r | |
1359 | @retval EFI_DEVICE_ERROR The new credential could not be deleted because of a device error.\r | |
1360 | @retval EFI_INVALID_PARAMETER User does not refer to a valid user profile handle.\r | |
1361 | **/\r | |
1362 | EFI_STATUS\r | |
1363 | EFIAPI\r | |
1364 | CredentialDelete (\r | |
1365 | IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r | |
1366 | IN EFI_USER_PROFILE_HANDLE User\r | |
1367 | )\r | |
1368 | {\r | |
1369 | EFI_STATUS Status;\r | |
1370 | EFI_USER_INFO *UserInfo;\r | |
1371 | UINT8 *UserId;\r | |
1372 | UINT8 *NewUserId;\r | |
1373 | UINTN Index;\r | |
1374 | \r | |
1375 | if ((This == NULL) || (User == NULL)) {\r | |
1376 | return EFI_INVALID_PARAMETER;\r | |
1377 | }\r | |
1378 | \r | |
1379 | //\r | |
1380 | // Get User Identifier.\r | |
1381 | //\r | |
1382 | UserInfo = NULL;\r | |
1383 | Status = FindUserInfoByType (\r | |
1384 | User,\r | |
1385 | EFI_USER_INFO_IDENTIFIER_RECORD,\r | |
1386 | &UserInfo\r | |
1387 | );\r | |
1388 | if (EFI_ERROR (Status)) {\r | |
1389 | return EFI_INVALID_PARAMETER;\r | |
1390 | }\r | |
1391 | \r | |
1392 | //\r | |
1393 | // Find the user by user identifier in mPwdTable.\r | |
1394 | // \r | |
1395 | for (Index = 0; Index < mPwdTable->Count; Index++) {\r | |
1396 | UserId = (UINT8 *) &mPwdTable->UserInfo[Index].UserId;\r | |
1397 | NewUserId = (UINT8 *) (UserInfo + 1);\r | |
1398 | if (CompareMem (UserId, NewUserId, sizeof (EFI_USER_INFO_IDENTIFIER)) == 0) {\r | |
1399 | //\r | |
1400 | // Found the user, delete it.\r | |
1401 | //\r | |
1402 | ModifyTable (Index, NULL);\r | |
1403 | break;\r | |
1404 | }\r | |
1405 | }\r | |
1406 | \r | |
1407 | FreePool (UserInfo);\r | |
1408 | return EFI_SUCCESS;\r | |
1409 | }\r | |
1410 | \r | |
0c18794e | 1411 | \r |
1412 | /**\r | |
1413 | Main entry for this driver.\r | |
1414 | \r | |
1415 | @param ImageHandle Image handle this driver.\r | |
1416 | @param SystemTable Pointer to SystemTable.\r | |
1417 | \r | |
1418 | @retval EFI_SUCESS This function always complete successfully.\r | |
1419 | \r | |
1420 | **/\r | |
1421 | EFI_STATUS\r | |
1422 | EFIAPI\r | |
1423 | PasswordProviderInit (\r | |
1424 | IN EFI_HANDLE ImageHandle,\r | |
1425 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
1426 | )\r | |
1427 | {\r | |
1428 | EFI_STATUS Status;\r | |
1429 | \r | |
68d151bb DG |
1430 | //\r |
1431 | // It is NOT robust enough to be included in production.\r | |
1432 | //\r | |
1433 | #error "This implementation is just a sample, please comment this line if you really want to use this driver."\r | |
1434 | \r | |
0c18794e | 1435 | //\r |
1436 | // Init credential table.\r | |
1437 | //\r | |
1438 | Status = InitCredentialTable ();\r | |
1439 | if (EFI_ERROR (Status)) {\r | |
1440 | return Status;\r | |
1441 | }\r | |
1442 | \r | |
1443 | //\r | |
1444 | // Init Form Browser.\r | |
1445 | //\r | |
1446 | Status = InitFormBrowser ();\r | |
1447 | if (EFI_ERROR (Status)) {\r | |
1448 | return Status;\r | |
1449 | }\r | |
1450 | \r | |
1451 | //\r | |
1452 | // Install protocol interfaces for the password credential provider.\r | |
1453 | //\r | |
1454 | Status = gBS->InstallProtocolInterface (\r | |
1455 | &mCallbackInfo->DriverHandle,\r | |
6f0b8648 | 1456 | &gEfiUserCredential2ProtocolGuid,\r |
0c18794e | 1457 | EFI_NATIVE_INTERFACE,\r |
1458 | &gPwdCredentialProviderDriver\r | |
1459 | );\r | |
1460 | return Status;\r | |
1461 | }\r |