]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/UserIdentification/UsbCredentialProviderDxe/UsbCredentialProvider.c
Update UID drivers to align with latest UEFI spec 2.3.1.
[mirror_edk2.git] / SecurityPkg / UserIdentification / UsbCredentialProviderDxe / UsbCredentialProvider.c
index 726e61c3b1f1dd7722e560e53b58cf08cd0f6793..327a2b03884b88bbbc46297f5787d7585ab3b8a8 100644 (file)
@@ -18,7 +18,7 @@ CREDENTIAL_TABLE            *mUsbTable       = NULL;
 USB_PROVIDER_CALLBACK_INFO  *mCallbackInfo   = NULL;\r
 USB_CREDENTIAL_INFO         *mUsbInfoHandle  = NULL;\r
 \r
-EFI_USER_CREDENTIAL_PROTOCOL  gUsbCredentialProviderDriver = {\r
+EFI_USER_CREDENTIAL2_PROTOCOL  gUsbCredentialProviderDriver = {\r
   USB_CREDENTIAL_PROVIDER_GUID,\r
   EFI_USER_CREDENTIAL_CLASS_SECURE_CARD,\r
   CredentialEnroll,\r
@@ -30,7 +30,9 @@ EFI_USER_CREDENTIAL_PROTOCOL  gUsbCredentialProviderDriver = {
   CredentialDeselect,\r
   CredentialDefault,\r
   CredentialGetInfo,\r
-  CredentialGetNextInfo\r
+  CredentialGetNextInfo,\r
+  EFI_CREDENTIAL_CAPABILITIES_ENROLL,\r
+  CredentialDelete\r
 };\r
 \r
 \r
@@ -95,12 +97,12 @@ ExpandTableSize (
 \r
 \r
 /**\r
-  Add or delete info in table, and sync with NV variable.\r
+  Add, update or delete info in table, and sync with NV variable.\r
 \r
-  @param[in]  Index     The index of the password in table. The index begin from 1.\r
-                        If index is found in table, delete the info, else add the \r
-                        into to table. \r
-  @param[in]  Info      The new password info to add into table.\r
+  @param[in]  Index     The index of the password in table. If index is found in\r
+                        table, update the info, else add the into to table. \r
+  @param[in]  Info      The new credential info to add into table. If Info is NULL, \r
+                        delete the info by Index.\r
 \r
   @retval EFI_INVALID_PARAMETER  Info is NULL when save the info.\r
   @retval EFI_SUCCESS            Modify the table successfully.\r
@@ -114,18 +116,23 @@ ModifyTable (
   )\r
 {\r
   EFI_STATUS  Status;\r
+  USB_INFO    *NewUsbInfo;\r
   \r
+  NewUsbInfo = NULL;\r
   if (Index < mUsbTable->Count) {\r
-    //\r
-    // Delete the specified entry\r
-    //\r
-    mUsbTable->Count--;\r
-    if (Index != mUsbTable->Count) {\r
-      CopyMem (\r
-        &mUsbTable->UserInfo[Index],\r
-        &mUsbTable->UserInfo[mUsbTable->Count],\r
-        sizeof (USB_INFO)\r
-        );\r
+    if (Info == NULL) {\r
+      //\r
+      // Delete the specified entry.\r
+      //\r
+      mUsbTable->Count--;\r
+      if (Index != mUsbTable->Count) {\r
+        NewUsbInfo = &mUsbTable->UserInfo[mUsbTable->Count];\r
+      } \r
+    } else {\r
+      //\r
+      // Update the specified entry.\r
+      //\r
+      NewUsbInfo = Info;\r
     }\r
   } else {\r
     //\r
@@ -139,14 +146,14 @@ ModifyTable (
       ExpandTableSize ();\r
     }\r
 \r
-    CopyMem (\r
-      &mUsbTable->UserInfo[mUsbTable->Count], \r
-      Info, \r
-      sizeof (USB_INFO)\r
-      );\r
+    NewUsbInfo = Info;\r
     mUsbTable->Count++;\r
   }\r
 \r
+  if (NewUsbInfo != NULL) {\r
+    CopyMem (&mUsbTable->UserInfo[Index], NewUsbInfo, sizeof (USB_INFO));\r
+  }\r
+\r
   //\r
   // Save the credential table.\r
   //\r
@@ -636,13 +643,11 @@ InitFormBrowser (
 /**\r
   Enroll a user on a credential provider.\r
 \r
-  This function enrolls and deletes a user profile using this credential provider. \r
-  If a user profile is successfully enrolled, it calls the User Manager Protocol \r
-  function Notify() to notify the user manager driver that credential information \r
-  has changed. If an enrolled user does exist, delete the user on the credential \r
-  provider.\r
+  This function enrolls a user on this credential provider. If the user exists on \r
+  this credential provider, update the user information on this credential provider; \r
+  otherwise add the user information on credential provider.\r
   \r
-  @param[in] This                Points to this instance of EFI_USER_CREDENTIAL_PROTOCOL.\r
+  @param[in] This                Points to this instance of EFI_USER_CREDENTIAL2_PROTOCOL.\r
   @param[in] User                The user profile to enroll.\r
  \r
   @retval EFI_SUCCESS            User profile was successfully enrolled.\r
@@ -660,7 +665,7 @@ InitFormBrowser (
 EFI_STATUS\r
 EFIAPI\r
 CredentialEnroll (\r
-  IN CONST  EFI_USER_CREDENTIAL_PROTOCOL        *This,\r
+  IN CONST  EFI_USER_CREDENTIAL2_PROTOCOL       *This,\r
   IN        EFI_USER_PROFILE_HANDLE             User\r
   )\r
 {\r
@@ -669,10 +674,7 @@ CredentialEnroll (
   USB_INFO                  UsbInfo;\r
   EFI_USER_INFO             *UserInfo;\r
   EFI_INPUT_KEY             Key;\r
-  EFI_USER_MANAGER_PROTOCOL *UserManager;\r
   UINT8                     *UserId;\r
-  UINT8                     *NewUserId;\r
-  EFI_TPL                   OldTpl;\r
   CHAR16                    *QuestionStr;\r
   CHAR16                    *PromptStr;\r
 \r
@@ -680,15 +682,6 @@ CredentialEnroll (
     return EFI_INVALID_PARAMETER;\r
   }\r
  \r
-  Status = gBS->LocateProtocol (\r
-                  &gEfiUserManagerProtocolGuid,\r
-                  NULL,\r
-                  (VOID **) &UserManager\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
   //\r
   // Get User Identifier\r
   //\r
@@ -701,22 +694,10 @@ CredentialEnroll (
   if (EFI_ERROR (Status)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
-  //\r
-  // If User exists in mUsbTable, delete User.\r
-  // \r
-  for (Index = 0; Index < mUsbTable->Count; Index++) {\r
-    UserId    = (UINT8 *) &mUsbTable->UserInfo[Index].UserId;\r
-    NewUserId = (UINT8 *) (UserInfo + 1);\r
-    if (CompareMem (UserId, NewUserId, sizeof (EFI_USER_INFO_IDENTIFIER)) == 0) {\r
-      //\r
-      // Delete the exist Token.\r
-      //\r
-      FreePool (UserInfo);\r
-      return ModifyTable (Index, NULL);\r
-    }\r
-  }\r
 \r
+  CopyMem (UsbInfo.UserId, (UINT8 *) (UserInfo + 1), sizeof (EFI_USER_INFO_IDENTIFIER)); \r
+  FreePool (UserInfo);\r
+  \r
   //\r
   // Get Token and User ID to UsbInfo.\r
   //\r
@@ -724,8 +705,6 @@ CredentialEnroll (
   if (EFI_ERROR (Status)) {\r
     QuestionStr = GetStringById (STRING_TOKEN (STR_READ_USB_TOKEN_ERROR));\r
     PromptStr   = GetStringById (STRING_TOKEN (STR_INSERT_USB_TOKEN)); \r
-    OldTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
-    gBS->RestoreTPL (TPL_APPLICATION);    \r
     CreatePopUp (\r
       EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
       &Key,\r
@@ -734,32 +713,32 @@ CredentialEnroll (
       PromptStr,\r
       NULL\r
       );\r
-    gBS->RaiseTPL (OldTpl);\r
     FreePool (QuestionStr);\r
     FreePool (PromptStr);\r
-    FreePool (UserInfo);\r
     return Status;\r
   } \r
-  CopyMem (\r
-    UsbInfo.UserId,\r
-    (UINT8 *) (UserInfo + 1),\r
-    sizeof (EFI_USER_INFO_IDENTIFIER)\r
-    );\r
-  FreePool (UserInfo);\r
 \r
   //\r
-  // Save the new added entry.\r
+  // Check whether User is ever enrolled in the provider.\r
+  // \r
+  for (Index = 0; Index < mUsbTable->Count; Index++) {\r
+    UserId = (UINT8 *) &mUsbTable->UserInfo[Index].UserId;\r
+    if (CompareMem (UserId, (UINT8 *) &UsbInfo.UserId, sizeof (EFI_USER_INFO_IDENTIFIER)) == 0) {\r
+      //\r
+      // User already exists, update the password.\r
+      //      \r
+      break;\r
+    }\r
+  }\r
+  \r
+  //\r
+  // Enroll the User to the provider.\r
   //\r
-  Status = ModifyTable (mUsbTable->Count, &UsbInfo);\r
+  Status = ModifyTable (Index, &UsbInfo);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
-  //\r
-  // Notify the user manager driver that credential information has changed.\r
-  //\r
-  UserManager->Notify (UserManager, mCallbackInfo->DriverHandle);  \r
-\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -773,7 +752,7 @@ CredentialEnroll (
   the user credential provider does not require a form to identify the user, then this\r
   function should return EFI_NOT_FOUND.\r
 \r
-  @param[in]  This       Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.\r
+  @param[in]  This       Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
   @param[out] Hii        On return, holds the HII database handle.\r
   @param[out] FormSetId  On return, holds the identifier of the form set which contains\r
                          the form used during user identification.\r
@@ -788,7 +767,7 @@ CredentialEnroll (
 EFI_STATUS\r
 EFIAPI\r
 CredentialForm (\r
-  IN CONST  EFI_USER_CREDENTIAL_PROTOCOL        *This,\r
+  IN CONST  EFI_USER_CREDENTIAL2_PROTOCOL       *This,\r
   OUT       EFI_HII_HANDLE                      *Hii,\r
   OUT       EFI_GUID                            *FormSetId,\r
   OUT       EFI_FORM_ID                         *FormId\r
@@ -809,7 +788,7 @@ CredentialForm (
   of pixels specified by Width and Height. If no such bitmap exists, then EFI_NOT_FOUND\r
   is returned. \r
 \r
-  @param[in]     This    Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.\r
+  @param[in]     This    Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
   @param[in, out] Width  On entry, points to the desired bitmap width. If NULL then no \r
                          bitmap information will be returned. On exit, points to the \r
                          width of the bitmap returned.\r
@@ -827,7 +806,7 @@ CredentialForm (
 EFI_STATUS\r
 EFIAPI\r
 CredentialTile (\r
-  IN CONST  EFI_USER_CREDENTIAL_PROTOCOL        *This,\r
+  IN CONST  EFI_USER_CREDENTIAL2_PROTOCOL       *This,\r
   IN OUT    UINTN                               *Width,\r
   IN OUT    UINTN                               *Height,\r
   OUT       EFI_HII_HANDLE                      *Hii,\r
@@ -847,7 +826,7 @@ CredentialTile (
   This function returns a string which describes the credential provider. If no\r
   such string exists, then EFI_NOT_FOUND is returned. \r
 \r
-  @param[in]  This       Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.\r
+  @param[in]  This       Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
   @param[out] Hii        On return, holds the HII database handle.\r
   @param[out] String     On return, holds the HII string identifier.\r
  \r
@@ -859,7 +838,7 @@ CredentialTile (
 EFI_STATUS\r
 EFIAPI\r
 CredentialTitle (\r
-  IN CONST  EFI_USER_CREDENTIAL_PROTOCOL        *This,\r
+  IN CONST  EFI_USER_CREDENTIAL2_PROTOCOL       *This,\r
   OUT       EFI_HII_HANDLE                      *Hii,\r
   OUT       EFI_STRING_ID                       *String\r
   )\r
@@ -885,7 +864,7 @@ CredentialTitle (
   submitted on a form OR after a call to Default() has returned that this credential is\r
   ready to log on.\r
 \r
-  @param[in]  This           Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.\r
+  @param[in]  This           Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
   @param[in]  User           The user profile handle of the user profile currently being \r
                              considered by the user identity manager. If NULL, then no user\r
                              profile is currently under consideration.\r
@@ -902,7 +881,7 @@ CredentialTitle (
 EFI_STATUS\r
 EFIAPI\r
 CredentialUser (\r
-  IN CONST  EFI_USER_CREDENTIAL_PROTOCOL        *This,\r
+  IN CONST  EFI_USER_CREDENTIAL2_PROTOCOL       *This,\r
   IN        EFI_USER_PROFILE_HANDLE             User,\r
   OUT       EFI_USER_INFO_IDENTIFIER            *Identifier\r
   )\r
@@ -1023,7 +1002,7 @@ CredentialUser (
   AutoLogon returns FALSE, then the user interface will be constructed by the User\r
   Identity Manager. \r
 \r
-  @param[in]  This       Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.\r
+  @param[in]  This       Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
   @param[out] AutoLogon  On return, points to the credential provider's capabilities \r
                          after the credential provider has been selected by the user. \r
  \r
@@ -1034,7 +1013,7 @@ CredentialUser (
 EFI_STATUS\r
 EFIAPI\r
 CredentialSelect (\r
-  IN  CONST  EFI_USER_CREDENTIAL_PROTOCOL    *This,\r
+  IN  CONST  EFI_USER_CREDENTIAL2_PROTOCOL   *This,\r
   OUT        EFI_CREDENTIAL_LOGON_FLAGS      *AutoLogon\r
   )\r
 {\r
@@ -1053,7 +1032,7 @@ CredentialSelect (
 \r
   This function is called when a credential provider is deselected by the user.\r
 \r
-  @param[in] This        Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.\r
+  @param[in] This        Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
  \r
   @retval EFI_SUCCESS    Credential provider successfully deselected.\r
   \r
@@ -1061,7 +1040,7 @@ CredentialSelect (
 EFI_STATUS\r
 EFIAPI\r
 CredentialDeselect (\r
-  IN CONST  EFI_USER_CREDENTIAL_PROTOCOL        *This\r
+  IN CONST  EFI_USER_CREDENTIAL2_PROTOCOL       *This\r
   )\r
 {\r
   if (This == NULL) {\r
@@ -1076,7 +1055,7 @@ CredentialDeselect (
 \r
   This function reports the default login behavior regarding this credential provider.  \r
 \r
-  @param[in]  This       Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.\r
+  @param[in]  This       Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
   @param[out] AutoLogon  On return, holds whether the credential provider should be used\r
                          by default to automatically log on the user.  \r
  \r
@@ -1087,7 +1066,7 @@ CredentialDeselect (
 EFI_STATUS\r
 EFIAPI\r
 CredentialDefault (\r
-  IN CONST  EFI_USER_CREDENTIAL_PROTOCOL        *This,\r
+  IN CONST  EFI_USER_CREDENTIAL2_PROTOCOL       *This,\r
   OUT       EFI_CREDENTIAL_LOGON_FLAGS          *AutoLogon\r
   )\r
 {\r
@@ -1105,7 +1084,7 @@ CredentialDefault (
 \r
   This function returns user information. \r
 \r
-  @param[in]      This          Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.\r
+  @param[in]      This          Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
   @param[in]      UserInfo      Handle of the user information data record. \r
   @param[out]     Info          On entry, points to a buffer of at least *InfoSize bytes. On\r
                                 exit, holds the user information. If the buffer is too small\r
@@ -1125,7 +1104,7 @@ CredentialDefault (
 EFI_STATUS\r
 EFIAPI\r
 CredentialGetInfo (\r
-  IN CONST  EFI_USER_CREDENTIAL_PROTOCOL        *This,\r
+  IN CONST  EFI_USER_CREDENTIAL2_PROTOCOL       *This,\r
   IN        EFI_USER_INFO_HANDLE                UserInfo,\r
   OUT       EFI_USER_INFO                       *Info,\r
   IN OUT    UINTN                               *InfoSize\r
@@ -1173,7 +1152,7 @@ CredentialGetInfo (
   another user information record handle until there are no more, at which point UserInfo\r
   will point to NULL. \r
 \r
-  @param[in]      This     Points to this instance of the EFI_USER_CREDENTIAL_PROTOCOL.\r
+  @param[in]      This     Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
   @param[in, out] UserInfo On entry, points to the previous user information handle or NULL\r
                            to start enumeration. On exit, points to the next user information\r
                            handle or NULL if there is no more user information.\r
@@ -1186,7 +1165,7 @@ CredentialGetInfo (
 EFI_STATUS\r
 EFIAPI\r
 CredentialGetNextInfo (\r
-  IN CONST  EFI_USER_CREDENTIAL_PROTOCOL        *This,\r
+  IN CONST  EFI_USER_CREDENTIAL2_PROTOCOL       *This,\r
   IN OUT    EFI_USER_INFO_HANDLE                *UserInfo\r
   )\r
 {\r
@@ -1317,6 +1296,72 @@ CredentialGetNextInfo (
 }\r
 \r
 \r
+/**\r
+  Delete a user on this credential provider.\r
+\r
+  This function deletes a user on this credential provider. \r
+\r
+  @param[in]     This            Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
+  @param[in]     User            The user profile handle to delete.\r
+\r
+  @retval EFI_SUCCESS            User profile was successfully deleted.\r
+  @retval EFI_ACCESS_DENIED      Current user profile does not permit deletion on the user profile handle. \r
+                                 Either the user profile cannot delete on any user profile or cannot delete \r
+                                 on a user profile other than the current user profile. \r
+  @retval EFI_UNSUPPORTED        This credential provider does not support deletion in the pre-OS.\r
+  @retval EFI_DEVICE_ERROR       The new credential could not be deleted because of a device error.\r
+  @retval EFI_INVALID_PARAMETER  User does not refer to a valid user profile handle.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CredentialDelete (\r
+  IN CONST  EFI_USER_CREDENTIAL2_PROTOCOL       *This,\r
+  IN        EFI_USER_PROFILE_HANDLE             User\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_USER_INFO             *UserInfo;\r
+  UINT8                     *UserId;\r
+  UINT8                     *NewUserId;\r
+  UINTN                     Index;\r
+  \r
+  if ((This == NULL) || (User == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Get User Identifier.\r
+  //\r
+  UserInfo = NULL;\r
+  Status = FindUserInfoByType (\r
+             User,\r
+             EFI_USER_INFO_IDENTIFIER_RECORD,\r
+             &UserInfo\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Find the user by user identifier in mPwdTable.\r
+  // \r
+  for (Index = 0; Index < mUsbTable->Count; Index++) {\r
+    UserId    = (UINT8 *) &mUsbTable->UserInfo[Index].UserId;\r
+    NewUserId = (UINT8 *) (UserInfo + 1);\r
+    if (CompareMem (UserId, NewUserId, sizeof (EFI_USER_INFO_IDENTIFIER)) == 0) {\r
+      //\r
+      // Found the user, delete it.\r
+      //\r
+      ModifyTable (Index, NULL);\r
+      break;\r
+    }\r
+  }\r
+\r
+  FreePool (UserInfo);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
 /**\r
   Main entry for this driver.\r
 \r
@@ -1356,7 +1401,7 @@ UsbProviderInit (
   //\r
   Status = gBS->InstallProtocolInterface (\r
                   &mCallbackInfo->DriverHandle,\r
-                  &gEfiUserCredentialProtocolGuid,\r
+                  &gEfiUserCredential2ProtocolGuid,\r
                   EFI_NATIVE_INTERFACE,\r
                   &gUsbCredentialProviderDriver\r
                   );\r