]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/UserIdentification/UserIdentifyManagerDxe/UserIdentifyManager.c
Force UID modules build error to warn user that currently it is just a sample.
[mirror_edk2.git] / SecurityPkg / UserIdentification / UserIdentifyManagerDxe / UserIdentifyManager.c
index e105579115a89cf1864dfc5fb7962f4677049a79..a7467b366290e4bcc8a962292646a4c5c7d94cf2 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   This driver manages user information and produces user manager protocol.\r
   \r
-Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials \r
 are licensed and made available under the terms and conditions of the BSD License \r
 which accompanies this distribution.  The full text of the license may be found at \r
@@ -14,11 +14,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "UserIdentifyManager.h"\r
 \r
-//\r
-// Guid used in user profile saving and in form browser.\r
-//\r
-EFI_GUID                    mUserManagerGuid  = USER_IDENTIFY_MANAGER_GUID;\r
-\r
 //\r
 // Default user name.\r
 //\r
@@ -54,10 +49,7 @@ HII_VENDOR_DEVICE_PATH      mHiiVendorDevicePath = {
         (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
       }\r
     },\r
-    //\r
-    // {ACA7C06F-743C-454f-9C6D-692138482498}\r
-    //\r
-    { 0xaca7c06f, 0x743c, 0x454f, { 0x9c, 0x6d, 0x69, 0x21, 0x38, 0x48, 0x24, 0x98 } }\r
+    USER_IDENTIFY_MANAGER_GUID\r
   },\r
   {\r
     END_DEVICE_PATH_TYPE,\r
@@ -408,43 +400,6 @@ FindUserProfileByInfo (
   return EFI_NOT_FOUND;\r
 }\r
 \r
-/**\r
-  Find the credential provider in the specified identity policy.\r
-\r
-  @param[in]  FindIdentity        Point to the user identity policy.\r
-  @param[in]  IdentifyInfo        Point to the user information to be searched.\r
-\r
-  @retval TRUE     The credential provider was found in the identity policy.\r
-  @retval FALSE    The credential provider was not found.\r
-**/\r
-BOOLEAN\r
-FindProvider (\r
-  IN       EFI_USER_INFO_IDENTITY_POLICY        *FindIdentity,\r
-  IN CONST EFI_USER_INFO                        *IdentifyInfo\r
-  )\r
-{\r
-  UINTN                         TotalLen;\r
-  EFI_USER_INFO_IDENTITY_POLICY *Identity;\r
-\r
-  //\r
-  // Found the credential provider.\r
-  //\r
-  TotalLen = 0;\r
-  while (TotalLen < IdentifyInfo->InfoSize - sizeof (EFI_USER_INFO)) {\r
-    Identity = (EFI_USER_INFO_IDENTITY_POLICY *) ((UINT8 *) (IdentifyInfo + 1) + TotalLen);\r
-    if ((Identity->Type == FindIdentity->Type) &&\r
-        (Identity->Length == FindIdentity->Length) &&\r
-        CompareGuid ((EFI_GUID *) (Identity + 1), (EFI_GUID *) (FindIdentity + 1))\r
-        ) {\r
-      return TRUE;\r
-    }\r
-\r
-    TotalLen += Identity->Length;\r
-  }\r
-\r
-  return FALSE;\r
-}\r
-\r
 \r
 /**\r
   Check whether the access policy is valid.\r
@@ -1017,110 +972,6 @@ ExpandUserProfile (
 }\r
 \r
 \r
-/**\r
-  Add or delete the user's credential record in the provider.\r
-\r
-  @param[in]  ProviderGuid        Point to credential provider guid or class guid.\r
-  @param[in]  ByType              If TRUE, Provider is credential class guid.\r
-                                  If FALSE, Provider is provider guid.\r
-  @param[in]  User                Points to user profile.\r
-\r
-  @retval EFI_SUCCESS      Add or delete record successfully.\r
-  @retval Others           Fail to add or delete record.\r
-\r
-**/\r
-EFI_STATUS\r
-ModifyProviderCredential (\r
-  IN  EFI_GUID                                  *Provider,\r
-  IN  BOOLEAN                                   ByType,\r
-  IN  USER_PROFILE_ENTRY                        *User\r
-  )\r
-{\r
-  UINTN                         Index;\r
-  EFI_USER_CREDENTIAL_PROTOCOL  *UserCredential;\r
-  \r
-  if (Provider == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  \r
-  //\r
-  // Find the specified credential provider.\r
-  //\r
-  for (Index = 0; Index < mProviderDb->Count; Index++) {\r
-    //\r
-    // Check credential provider ID.\r
-    //\r
-    UserCredential = mProviderDb->Provider[Index];\r
-    if (CompareGuid (&UserCredential->Identifier, Provider)) {\r
-      return UserCredential->Enroll (UserCredential, User);\r
-    }\r
-  }\r
-\r
-  return EFI_NOT_FOUND;\r
-}\r
-\r
-\r
-/**\r
-  Modify user's credential record in the providers.\r
-\r
-  Found the providers information in PolicyInfo, and then add or delete the user's credential\r
-  record in the providers.\r
-\r
-  @param  User                    Points to user profile.\r
-  @param  PolicyInfo              Point to identification policy to be modified.\r
-  @param  InfoLen                 The length of PolicyInfo.\r
-\r
-  @retval EFI_SUCCESS      Modify PolicyInfo successfully.\r
-  @retval Others           Fail to modify PolicyInfo.\r
-\r
-**/\r
-EFI_STATUS\r
-ModifyCredentialInfo (\r
-  IN  USER_PROFILE_ENTRY                        *User,\r
-  IN  UINT8                                     *PolicyInfo,\r
-  IN  UINTN                                     InfoLen\r
-  )\r
-{\r
-  EFI_STATUS                    Status;\r
-  UINTN                         TotalLen;\r
-  EFI_USER_INFO_IDENTITY_POLICY *Identity;\r
-\r
-  //\r
-  // Modify user's credential.\r
-  //\r
-  TotalLen = 0;\r
-  while (TotalLen < InfoLen) {\r
-    //\r
-    // Check identification policy according to type.\r
-    //\r
-    Identity = (EFI_USER_INFO_IDENTITY_POLICY *) (PolicyInfo + TotalLen);\r
-    switch (Identity->Type) {\r
-    case EFI_USER_INFO_IDENTITY_CREDENTIAL_TYPE:\r
-      Status = ModifyProviderCredential ((EFI_GUID *) (Identity + 1), TRUE, User);\r
-      if (EFI_ERROR (Status)) {\r
-        return Status;\r
-      }\r
-      break;\r
-\r
-    case EFI_USER_INFO_IDENTITY_CREDENTIAL_PROVIDER:\r
-      Status = ModifyProviderCredential ((EFI_GUID *) (Identity + 1), FALSE, User);\r
-      if (EFI_ERROR (Status)) {\r
-        return Status;\r
-      }\r
-      break;\r
-\r
-    default:\r
-      break;\r
-    }\r
-\r
-    TotalLen += Identity->Length;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
 /**\r
   Save the user profile to non-volatile memory, or delete it from non-volatile memory.\r
 \r
@@ -1152,7 +1003,7 @@ SaveNvUserProfile (
   //\r
   Status = gRT->SetVariable (\r
                   User->UserVarName,\r
-                  &mUserManagerGuid,\r
+                  &gUserIdentifyManagerGuid,\r
                   EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
                   Delete ? 0 : User->UserProfileSize,\r
                   User->ProfileInfo\r
@@ -1160,327 +1011,6 @@ SaveNvUserProfile (
   return Status;\r
 }\r
 \r
-\r
-/**\r
-  Replace the old identity info with NewInfo in NV Flash.\r
-\r
-  This function only replace the identity record in the user profile. Don't update\r
-  the the information on the credential provider.\r
-  \r
-  @param[in]   User               Point to the user profile.\r
-  @param[in]   NewInfo            Point to the new identity policy info.\r
-  @param[out]  UserInfo           Point to the new added identity info.\r
-\r
-  @retval EFI_SUCCESS      Replace user identity successfully.\r
-  @retval Others           Fail to Replace user identity.\r
-\r
-**/\r
-EFI_STATUS\r
-SaveUserIpInfo (\r
-  IN       USER_PROFILE_ENTRY                   * User,\r
-  IN CONST EFI_USER_INFO                        * NewInfo,\r
-  OUT   EFI_USER_INFO                           **UserInfo OPTIONAL\r
-  )\r
-{\r
-  EFI_STATUS    Status;\r
-  EFI_USER_INFO *OldIpInfo;\r
-  UINTN         Offset;\r
-  UINTN         NextOffset;\r
-\r
-  if ((NewInfo == NULL) || (User == NULL)) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-  \r
-  //\r
-  // Get user old identify policy information.\r
-  //\r
-  OldIpInfo = NULL;\r
-  Status    = FindUserInfoByType (User, &OldIpInfo, EFI_USER_INFO_IDENTITY_POLICY_RECORD);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-  \r
-  //\r
-  // Get the old identity policy offset.\r
-  //\r
-  Status = FindUserInfo (User, &OldIpInfo, FALSE, &Offset);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-  \r
-  //\r
-  // Delete the old identity policy information.\r
-  //\r
-  NextOffset = ALIGN_VARIABLE (OldIpInfo->InfoSize) + Offset;\r
-  User->UserProfileSize -= ALIGN_VARIABLE (OldIpInfo->InfoSize);\r
-  if (Offset < User->UserProfileSize) {\r
-    CopyMem (User->ProfileInfo + Offset, User->ProfileInfo + NextOffset, User->UserProfileSize - Offset);\r
-  }\r
-  \r
-  //\r
-  // Add new user information.\r
-  //\r
-  if (User->MaxProfileSize - User->UserProfileSize < ALIGN_VARIABLE (NewInfo->InfoSize)) {\r
-    if (!ExpandUserProfile (User, ALIGN_VARIABLE (NewInfo->InfoSize))) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-  }\r
-\r
-  CopyMem (User->ProfileInfo + User->UserProfileSize, (VOID *) NewInfo, NewInfo->InfoSize);\r
-  if (UserInfo != NULL) {\r
-    *UserInfo = (EFI_USER_INFO *) (User->ProfileInfo + User->UserProfileSize);\r
-  }\r
-\r
-  User->UserProfileSize += ALIGN_VARIABLE (NewInfo->InfoSize);\r
-\r
-  //\r
-  // Save user profile information.\r
-  //\r
-  Status = SaveNvUserProfile (User, FALSE);\r
-  return Status;\r
-}\r
-\r
-\r
-/**\r
-  Remove the provider in FindIdentity from the user identification information record.\r
-  \r
-  @param[in, out] NewInfo       On entry, points to the user information to remove provider. \r
-                                On return, points to the user information the provider is removed.\r
-  @param[in]      FindIdentity  Point to the user identity policy.\r
-\r
-  @retval TRUE                  The provider is removed successfully.\r
-  @retval FALSE                 Fail to remove the provider.\r
-\r
-**/\r
-BOOLEAN\r
-RemoveProvider (\r
-  IN OUT EFI_USER_INFO                         **NewInfo,\r
-  IN     EFI_USER_INFO_IDENTITY_POLICY         *FindIdentity\r
-  )\r
-{\r
-  UINTN                         TotalLen;\r
-  EFI_USER_INFO_IDENTITY_POLICY *Identity;\r
-  EFI_USER_INFO                 *IdentifyInfo;\r
-  UINT8                         *Buffer;\r
-\r
-  IdentifyInfo = *NewInfo;\r
-  TotalLen = IdentifyInfo->InfoSize - sizeof (EFI_USER_INFO);\r
-  if (TotalLen == FindIdentity->Length) {\r
-    //\r
-    // Only one credential provider in the identification policy.\r
-    // Set the new policy to be TRUE after removed the provider.\r
-    //\r
-    Identity = (EFI_USER_INFO_IDENTITY_POLICY *) (IdentifyInfo + 1);\r
-    Identity->Type         = EFI_USER_INFO_IDENTITY_TRUE;\r
-    Identity->Length       = sizeof (EFI_USER_INFO_IDENTITY_POLICY);  \r
-    IdentifyInfo->InfoSize = sizeof (EFI_USER_INFO) + Identity->Length;\r
-    return TRUE;\r
-  }\r
-\r
-  //\r
-  // Found the credential provider.\r
-  //\r
-  TotalLen = 0;\r
-  while (TotalLen < IdentifyInfo->InfoSize - sizeof (EFI_USER_INFO)) {\r
-    Identity = (EFI_USER_INFO_IDENTITY_POLICY *) ((UINT8 *) (IdentifyInfo + 1) + TotalLen);\r
-    if ((Identity->Type == FindIdentity->Type) &&\r
-        (Identity->Length == FindIdentity->Length) &&\r
-        CompareGuid ((EFI_GUID *) (Identity + 1), (EFI_GUID *) (FindIdentity + 1))\r
-        ) {\r
-      //\r
-      // Found the credential provider to delete\r
-      //\r
-      if (Identity == (EFI_USER_INFO_IDENTITY_POLICY *)(IdentifyInfo + 1)) {\r
-        //\r
-        // It is the first item in the identification policy, delete it and the connector after it.\r
-        //\r
-        Buffer = (UINT8 *) Identity + Identity->Length + sizeof(EFI_USER_INFO_IDENTITY_POLICY);\r
-        IdentifyInfo->InfoSize -= Identity->Length + sizeof(EFI_USER_INFO_IDENTITY_POLICY);\r
-        TotalLen = IdentifyInfo->InfoSize - sizeof (EFI_USER_INFO);\r
-        CopyMem (Identity, Buffer, TotalLen);\r
-       } else {\r
-        //\r
-        // It is not the first item in the identification policy, delete it and the connector before it.\r
-        //\r
-        Buffer    = (UINT8 *) Identity + Identity->Length;\r
-        TotalLen  = IdentifyInfo->InfoSize - sizeof (EFI_USER_INFO);\r
-        TotalLen -= (Buffer - (UINT8 *)(IdentifyInfo + 1));\r
-        IdentifyInfo->InfoSize -= Identity->Length + sizeof(EFI_USER_INFO_IDENTITY_POLICY);\r
-        CopyMem ((UINT8 *) (Identity - 1), Buffer, TotalLen);\r
-      }      \r
-      return TRUE;\r
-    }\r
-\r
-    TotalLen += Identity->Length;\r
-  }  \r
-  return FALSE;\r
-}\r
-\r
-\r
-/**\r
-  This function replaces the old identity policy with a new identity policy.\r
-\r
-  This function changes user identity policy information.\r
-  If enroll new credential failed, recover the old identity policy.\r
-\r
-  For new policy:\r
-  a. For each credential, if it is newly added, try to enroll it.\r
-     If enroll failed, try to delete the newly added ones.\r
-  \r
-  b. For each credential, if it exists in the old policy, delete old one, \r
-     and enroll new one. If failed to enroll the new one, removed it from new \r
-     identification policy.\r
-\r
-  For old policy:  \r
-  a. For each credential, if it does not exist in new one, delete it.\r
-\r
-  @param[in]  User         Point to the user profile.\r
-  @param[in]  Info         Points to the user identity information.\r
-  @param[in]  InfoSize     The size of Info (Not used in this function).\r
-  @param[out] IpInfo       The new identification info after modify.\r
-\r
-  @retval EFI_SUCCESS      Modify user identity policy successfully.\r
-  @retval Others           Fail to modify user identity policy.\r
-\r
-**/\r
-EFI_STATUS\r
-ModifyUserIpInfo (\r
-  IN        USER_PROFILE_ENTRY                  *User,\r
-  IN CONST  EFI_USER_INFO                       *Info,\r
-  IN        UINTN                               InfoSize,\r
-     OUT    EFI_USER_INFO                       **IpInfo\r
-  )\r
-{\r
-  EFI_STATUS                    Status;\r
-  EFI_USER_INFO                 *OldIpInfo;\r
-  UINTN                         TotalLen;\r
-  EFI_USER_INFO_IDENTITY_POLICY *Identity;\r
-  UINT32                        CredentialCount;\r
-  EFI_USER_INFO                 *NewIpInfo;\r
-\r
-  //\r
-  // Get user old identify policy information.\r
-  //\r
-  OldIpInfo = NULL;\r
-  Status    = FindUserInfoByType (User, &OldIpInfo, EFI_USER_INFO_IDENTITY_POLICY_RECORD);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-  ASSERT (OldIpInfo != NULL);\r
-  \r
-  //\r
-  // Enroll new added credential provider.\r
-  //\r
-  CredentialCount = 0;\r
-  TotalLen        = 0;\r
-  while (TotalLen < Info->InfoSize - sizeof (EFI_USER_INFO)) {\r
-    Identity = (EFI_USER_INFO_IDENTITY_POLICY *) ((UINT8 *) (Info + 1) + TotalLen);\r
-    if (Identity->Type == EFI_USER_INFO_IDENTITY_CREDENTIAL_PROVIDER) {\r
-      if (!FindProvider (Identity, OldIpInfo)) {\r
-        //\r
-        // The credential is NOT found in the old identity policy; add it.\r
-        //\r
-        Status = ModifyCredentialInfo (User, (UINT8 *) Identity, Identity->Length);\r
-        if (EFI_ERROR (Status)) {\r
-          break;\r
-        }\r
-        CredentialCount++;\r
-      }\r
-    }\r
-\r
-    TotalLen += Identity->Length;\r
-  }\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    //\r
-    // Enroll new credential failed. Delete the newly enrolled credential, and return.\r
-    //\r
-    TotalLen = 0;\r
-    while (TotalLen < Info->InfoSize - sizeof (EFI_USER_INFO)) {\r
-      Identity = (EFI_USER_INFO_IDENTITY_POLICY *) ((UINT8 *) (Info + 1) + TotalLen);\r
-      if (Identity->Type == EFI_USER_INFO_IDENTITY_CREDENTIAL_PROVIDER) {\r
-        if (!FindProvider (Identity, OldIpInfo)) {\r
-          //\r
-          // The credential is NOT found in the old identity policy. Delete it.\r
-          //\r
-          if (CredentialCount == 0) {\r
-            break;\r
-          }\r
-\r
-          ModifyCredentialInfo (User, (UINT8 *) Identity, Identity->Length);\r
-          CredentialCount--;\r
-        }\r
-      }\r
-      TotalLen += Identity->Length;\r
-    }\r
-\r
-    return EFI_DEVICE_ERROR;\r
-  }\r
-  \r
-  //\r
-  // Backup new identification policy\r
-  //\r
-  NewIpInfo = AllocateCopyPool (Info->InfoSize, Info);    \r
-  ASSERT (NewIpInfo != NULL);\r
-\r
-  //\r
-  // Enroll the credential that existed in the old identity policy.\r
-  //\r
-  TotalLen = 0;\r
-  while (TotalLen < Info->InfoSize - sizeof (EFI_USER_INFO)) {\r
-    Identity = (EFI_USER_INFO_IDENTITY_POLICY *) ((UINT8 *) (Info + 1) + TotalLen);\r
-    if (Identity->Type == EFI_USER_INFO_IDENTITY_CREDENTIAL_PROVIDER) {\r
-      if (FindProvider (Identity, OldIpInfo)) {\r
-        //\r
-        // The credential is found in the old identity policy, so delete the old credential first.\r
-        //\r
-        Status = ModifyCredentialInfo (User, (UINT8 *) Identity, Identity->Length);\r
-        if (EFI_ERROR (Status)) {\r
-          //\r
-          // Failed to delete old credential.\r
-          //\r
-          FreePool (NewIpInfo);\r
-          return EFI_DEVICE_ERROR;\r
-        }\r
-\r
-        //\r
-        // Add the new credential.\r
-        //\r
-        Status = ModifyCredentialInfo (User, (UINT8 *) Identity, Identity->Length);\r
-        if (EFI_ERROR (Status)) {\r
-          //\r
-          // Failed to enroll the user by new identification policy.\r
-          // So removed the credential provider from the identification policy          \r
-          //\r
-          RemoveProvider (&NewIpInfo, Identity);\r
-        }        \r
-      }\r
-    }\r
-    TotalLen += Identity->Length;\r
-  }\r
-  \r
-  //\r
-  // Delete old credential that didn't exist in the new identity policy.\r
-  //\r
-  TotalLen = 0;\r
-  while (TotalLen < OldIpInfo->InfoSize - sizeof (EFI_USER_INFO)) {\r
-    Identity = (EFI_USER_INFO_IDENTITY_POLICY *) ((UINT8 *) (OldIpInfo + 1) + TotalLen);\r
-    if (Identity->Type == EFI_USER_INFO_IDENTITY_CREDENTIAL_PROVIDER) {\r
-      if (!FindProvider (Identity, Info)) {\r
-        //\r
-        // The credential is NOT found in the new identity policy. Delete the old credential.\r
-        //\r
-        ModifyCredentialInfo (User, (UINT8 *) Identity, Identity->Length);\r
-      }\r
-    }\r
-    TotalLen += Identity->Length;\r
-  }\r
-\r
-  *IpInfo = NewIpInfo;\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
 /**\r
   Add one new user info into the user's profile.\r
 \r
@@ -1527,20 +1057,6 @@ AddUserInfo (
     }\r
   }\r
   \r
-  //\r
-  // Add credential.\r
-  //\r
-  if (((EFI_USER_INFO *) Info)->InfoType == EFI_USER_INFO_IDENTITY_POLICY_RECORD) {\r
-    Status = ModifyCredentialInfo (\r
-              User,\r
-              (UINT8 *) ((EFI_USER_INFO *) Info + 1),\r
-              InfoSize - sizeof (EFI_USER_INFO)\r
-              );\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
-  }\r
-  \r
   //\r
   // Add new user information.\r
   //\r
@@ -1679,11 +1195,6 @@ DelUserInfo (
 \r
   if (Info->InfoType == EFI_USER_INFO_IDENTIFIER_RECORD) {\r
     return EFI_ACCESS_DENIED;\r
-  } else if (Info->InfoType == EFI_USER_INFO_IDENTITY_POLICY_RECORD) {\r
-    Status = ModifyCredentialInfo (User, (UINT8 *) (Info + 1), Info->InfoSize - sizeof (EFI_USER_INFO));\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
   }\r
   \r
   //\r
@@ -1729,7 +1240,6 @@ ModifyUserInfo (
   EFI_STATUS    Status;\r
   UINTN         PayloadLen;\r
   EFI_USER_INFO *OldInfo;\r
-  EFI_USER_INFO *IpInfo;\r
 \r
   if ((UserInfo == NULL) || (Info == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -1831,25 +1341,6 @@ ModifyUserInfo (
     } while (TRUE);    \r
   }\r
 \r
-  if (Info->InfoType == EFI_USER_INFO_IDENTITY_POLICY_RECORD) {\r
-    //\r
-    // For user identification policy, need to update the info in credential provider.\r
-    //\r
-    IpInfo = NULL;\r
-    Status = ModifyUserIpInfo (User, Info, InfoSize, &IpInfo);\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
-\r
-    ASSERT (IpInfo != NULL);\r
-    Status = SaveUserIpInfo (User, IpInfo, UserInfo);\r
-    if (IpInfo->InfoSize != Info->InfoSize) {\r
-      Status = EFI_DEVICE_ERROR;\r
-    }\r
-    FreePool (IpInfo);    \r
-    return Status;\r
-  }\r
-\r
   Status = DelUserInfo (User, *UserInfo, FALSE);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
@@ -1875,7 +1366,6 @@ DelUserProfile (
 {\r
   EFI_STATUS          Status;\r
   UINTN               Index;\r
-  EFI_USER_INFO       *UserInfo;\r
 \r
   //\r
   // Check whether it is in the user profile database.\r
@@ -1892,18 +1382,6 @@ DelUserProfile (
     return EFI_ACCESS_DENIED;\r
   }\r
   \r
-  //\r
-  // Delete user credential information.\r
-  //\r
-  UserInfo  = NULL;\r
-  Status    = FindUserInfoByType (User, &UserInfo, EFI_USER_INFO_IDENTITY_POLICY_RECORD);\r
-  if (Status == EFI_SUCCESS) {\r
-    Status = DelUserInfo (User, UserInfo, FALSE);\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
-  }\r
-  \r
   //\r
   // Delete user profile from the non-volatile memory.\r
   //\r
@@ -2319,7 +1797,7 @@ GetIdentifyType (
   Identify the User by the specfied provider.\r
 \r
   @param[in]  User                Handle of a user profile.\r
-  @param[in]  Provider            Points to the identifir of credential provider.\r
+  @param[in]  Provider            Points to the identifier of credential provider.\r
 \r
   @retval EFI_INVALID_PARAMETER   Provider is NULL.\r
   @retval EFI_NOT_FOUND           Fail to identify the specified user.\r
@@ -2339,8 +1817,7 @@ IdentifyByProviderId (
   EFI_HII_HANDLE                HiiHandle;\r
   EFI_GUID                      FormSetId;\r
   EFI_FORM_ID                   FormId;\r
-  EFI_USER_CREDENTIAL_PROTOCOL  *UserCredential;\r
-  EFI_USER_INFO                 *IdInfo;\r
+  EFI_USER_CREDENTIAL2_PROTOCOL *UserCredential;\r
 \r
   if (Provider == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -2398,24 +1875,7 @@ IdentifyByProviderId (
       if (EFI_ERROR (Status)) {\r
         return Status;\r
       }\r
-\r
-      if (User == NULL) {\r
-        return EFI_SUCCESS;\r
-      }\r
       \r
-      //\r
-      // Get user ID information.\r
-      //\r
-      IdInfo  = NULL;\r
-      Status  = FindUserInfoByType (User, &IdInfo, EFI_USER_INFO_IDENTIFIER_RECORD);\r
-      ASSERT (IdInfo != NULL);\r
-\r
-      if (CompareMem ((UINT8 *) (IdInfo + 1), UserId, sizeof (EFI_USER_INFO_IDENTIFIER)) != 0) {\r
-        //\r
-        // One user name is selected, but the other's credential is given. Here no user passed.\r
-        //\r
-        break;\r
-      }\r
       return EFI_SUCCESS;\r
     }\r
   }\r
@@ -2549,7 +2009,7 @@ AddProviderSelection (
   EFI_STRING_ID                 ProvID;\r
   CHAR16                        *ProvStr;\r
   UINTN                         Index;\r
-  EFI_USER_CREDENTIAL_PROTOCOL  *UserCredential;\r
+  EFI_USER_CREDENTIAL2_PROTOCOL *UserCredential;\r
 \r
   for (Index = 0; Index < mProviderDb->Count; Index++) {\r
     UserCredential = mProviderDb->Provider[Index];\r
@@ -2830,7 +2290,7 @@ IdentifyOrTypeUser (
 \r
   HiiUpdateForm (\r
     mCallbackInfo->HiiHandle, // HII handle\r
-    &mUserManagerGuid,        // Formset GUID\r
+    &gUserIdentifyManagerGuid,// Formset GUID\r
     FORMID_PROVIDER_FORM,     // Form ID\r
     StartOpCodeHandle,        // Label for where to insert opcodes\r
     EndOpCodeHandle           // Replace data\r
@@ -2934,7 +2394,7 @@ UserIdentifyManagerCallback (
   \r
       HiiUpdateForm (\r
         mCallbackInfo->HiiHandle, // HII handle\r
-        &mUserManagerGuid,        // Formset GUID\r
+        &gUserIdentifyManagerGuid,// Formset GUID\r
         FORMID_USER_FORM,         // Form ID\r
         StartOpCodeHandle,        // Label for where to insert opcodes\r
         EndOpCodeHandle           // Replace data\r
@@ -2951,8 +2411,7 @@ UserIdentifyManagerCallback (
     Status = EFI_SUCCESS;\r
     break;\r
 \r
-  case EFI_BROWSER_ACTION_CHANGING:\r
-  {\r
+  case EFI_BROWSER_ACTION_CHANGED:\r
     if (QuestionId >= LABEL_PROVIDER_NAME) {\r
       //\r
       // QuestionId comes from the second Form (Select a Credential Provider if identity  \r
@@ -2965,10 +2424,16 @@ UserIdentifyManagerCallback (
       }\r
       return EFI_SUCCESS;\r
     }\r
-\r
+    break;\r
+    \r
+  case EFI_BROWSER_ACTION_CHANGING:\r
     //\r
     // QuestionId comes from the first Form (Select a user to identify).\r
     //\r
+    if (QuestionId >= LABEL_PROVIDER_NAME) {\r
+      return EFI_SUCCESS;\r
+    }\r
+\r
     User   = (USER_PROFILE_ENTRY *) mUserProfileDb->UserProfile[QuestionId & 0xFFF];\r
     Status = GetIdentifyType (User, &PolicyType);\r
     if (EFI_ERROR (Status)) {\r
@@ -2996,9 +2461,10 @@ UserIdentifyManagerCallback (
 \r
       mCurrentUser    = (EFI_USER_PROFILE_HANDLE) User;\r
       mIdentified     = TRUE;\r
-      *ActionRequest  = EFI_BROWSER_ACTION_REQUEST_EXIT;\r
+      if (Type == EFI_IFR_TYPE_REF) {\r
+        Value->ref.FormId = FORMID_INVALID_FORM;\r
+      }\r
     }\r
-  }\r
   break;\r
 \r
   default:\r
@@ -3076,7 +2542,7 @@ InitUserProfileDb (
     // Get variable value.\r
     //\r
     VarSize = CurVarSize;\r
-    Status  = gRT->GetVariable (VarName, &mUserManagerGuid, &VarAttr, &VarSize, VarData);\r
+    Status  = gRT->GetVariable (VarName, &gUserIdentifyManagerGuid, &VarAttr, &VarSize, VarData);\r
     if (Status == EFI_BUFFER_TOO_SMALL) {\r
       FreePool (VarData);\r
       VarData = AllocatePool (VarSize);\r
@@ -3086,7 +2552,7 @@ InitUserProfileDb (
       }\r
 \r
       CurVarSize  = VarSize;\r
-      Status      = gRT->GetVariable (VarName, &mUserManagerGuid, &VarAttr, &VarSize, VarData);\r
+      Status      = gRT->GetVariable (VarName, &gUserIdentifyManagerGuid, &VarAttr, &VarSize, VarData);\r
     }\r
 \r
     if (EFI_ERROR (Status)) {\r
@@ -3100,7 +2566,7 @@ InitUserProfileDb (
     // Check variable attributes.\r
     //\r
     if (VarAttr != (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS)) {\r
-      Status = gRT->SetVariable (VarName, &mUserManagerGuid, VarAttr, 0, NULL);\r
+      Status = gRT->SetVariable (VarName, &gUserIdentifyManagerGuid, VarAttr, 0, NULL);\r
       continue;\r
     }\r
     \r
@@ -3113,7 +2579,7 @@ InitUserProfileDb (
         //\r
         // Delete invalid user profile\r
         //\r
-        gRT->SetVariable (VarName, &mUserManagerGuid, VarAttr, 0, NULL);\r
+        gRT->SetVariable (VarName, &gUserIdentifyManagerGuid, VarAttr, 0, NULL);\r
       } else if (Status == EFI_OUT_OF_RESOURCES) {\r
         break;\r
       }\r
@@ -3122,7 +2588,7 @@ InitUserProfileDb (
       // Delete and save the profile again if some invalid profiles are deleted.\r
       //\r
       if (mUserProfileDb->UserProfileNum < Index) {\r
-        gRT->SetVariable (VarName, &mUserManagerGuid, VarAttr, 0, NULL);\r
+        gRT->SetVariable (VarName, &gUserIdentifyManagerGuid, VarAttr, 0, NULL);\r
         SaveNvUserProfile (mUserProfileDb->UserProfile[mUserProfileDb->UserProfileNum - 1], FALSE);\r
       }\r
     }\r
@@ -3178,7 +2644,7 @@ InitProviderInfo (
   HandleBuf   = NULL;\r
   Status = gBS->LocateHandleBuffer (\r
                   ByProtocol,\r
-                  &gEfiUserCredentialProtocolGuid,\r
+                  &gEfiUserCredential2ProtocolGuid,\r
                   NULL,\r
                   &HandleCount,\r
                   &HandleBuf\r
@@ -3192,8 +2658,8 @@ InitProviderInfo (
   //\r
   mProviderDb = AllocateZeroPool (\r
                   sizeof (CREDENTIAL_PROVIDER_INFO) - \r
-                  sizeof (EFI_USER_CREDENTIAL_PROTOCOL *) + \r
-                  HandleCount * sizeof (EFI_USER_CREDENTIAL_PROTOCOL *)\r
+                  sizeof (EFI_USER_CREDENTIAL2_PROTOCOL *) + \r
+                  HandleCount * sizeof (EFI_USER_CREDENTIAL2_PROTOCOL *)\r
                   );\r
   if (mProviderDb == NULL) {\r
     FreePool (HandleBuf);\r
@@ -3204,7 +2670,7 @@ InitProviderInfo (
   for (Index = 0; Index < HandleCount; Index++) {\r
     Status = gBS->HandleProtocol (\r
                     HandleBuf[Index],\r
-                    &gEfiUserCredentialProtocolGuid,\r
+                    &gEfiUserCredential2ProtocolGuid,\r
                     (VOID **) &mProviderDb->Provider[Index]\r
                     );\r
     if (EFI_ERROR (Status)) {\r
@@ -3367,7 +2833,7 @@ InitFormBrowser (
   // Publish HII data.\r
   //\r
   CallbackInfo->HiiHandle = HiiAddPackages (\r
-                              &mUserManagerGuid,\r
+                              &gUserIdentifyManagerGuid,\r
                               CallbackInfo->DriverHandle,\r
                               UserIdentifyManagerStrings,\r
                               UserIdentifyManagerVfrBin,\r
@@ -3539,7 +3005,7 @@ IdentifyUser (
   EFI_CREDENTIAL_LOGON_FLAGS    AutoLogon;\r
   EFI_USER_INFO                 *IdentifyInfo;\r
   EFI_USER_INFO_IDENTITY_POLICY *Identity;\r
-  EFI_USER_CREDENTIAL_PROTOCOL  *UserCredential;\r
+  EFI_USER_CREDENTIAL2_PROTOCOL *UserCredential;\r
   USER_PROFILE_ENTRY            *UserEntry;\r
 \r
   //\r
@@ -3608,7 +3074,7 @@ IdentifyUser (
                                  mCallbackInfo->FormBrowser2,\r
                                  &mCallbackInfo->HiiHandle,\r
                                  1,\r
-                                 &mUserManagerGuid,\r
+                                 &gUserIdentifyManagerGuid,\r
                                  0,\r
                                  NULL,\r
                                  NULL\r
@@ -4044,6 +3510,8 @@ UserProfileGetInfo (
   This function changes user information.  If NULL is pointed to by UserInfo, then a new user \r
   information record is created and its handle is returned in UserInfo. Otherwise, the existing  \r
   one is replaced.\r
+  If EFI_USER_INFO_IDENITTY_POLICY_RECORD is changed, it is the caller's responsibility to keep \r
+  it to be synced with the information on credential providers.\r
   If EFI_USER_INFO_EXCLUSIVE is specified in Info and a user information record of the same \r
   type already exists in the user profile, then EFI_ACCESS_DENIED will be returned and UserInfo\r
   will point to the handle of the existing record.\r
@@ -4132,15 +3600,18 @@ UserProfileSetInfo (
   Called by credential provider to notify of information change.\r
 \r
   This function allows the credential provider to notify the User Identity Manager when user status  \r
-  has changed while deselected.\r
+  has changed.\r
   If the User Identity Manager doesn't support asynchronous changes in credentials, then this function \r
   should return EFI_UNSUPPORTED. \r
-  If the User Identity Manager supports this, it will call User() to get the user identifier and then \r
-  GetNextInfo() and GetInfo() in the User Credential Protocol to get all of the information from the \r
-  credential and add it.\r
+  If current user does not exist, and the credential provider can identify a user, then make the user \r
+  to be current user and signal the EFI_EVENT_GROUP_USER_PROFILE_CHANGED event.\r
+  If current user already exists, and the credential provider can identify another user, then switch \r
+  current user to the newly identified user, and signal the EFI_EVENT_GROUP_USER_PROFILE_CHANGED event.\r
+  If current user was identified by this credential provider and now the credential provider cannot identify \r
+  current user, then logout current user and signal the EFI_EVENT_GROUP_USER_PROFILE_CHANGED event.\r
 \r
   @param[in] This          Points to this instance of the EFI_USER_MANAGER_PROTOCOL.\r
-  @param[in] Changed       Handle on which is installed an instance of the EFI_USER_CREDENTIAL_PROTOCOL \r
+  @param[in] Changed       Handle on which is installed an instance of the EFI_USER_CREDENTIAL2_PROTOCOL \r
                            where the user has changed.\r
 \r
   @retval EFI_SUCCESS      The User Identity Manager has handled the notification.\r
@@ -4154,102 +3625,8 @@ UserProfileNotify (
   IN CONST  EFI_USER_MANAGER_PROTOCOL           *This,\r
   IN        EFI_HANDLE                          Changed\r
   )\r
-{\r
-  EFI_STATUS                    Status;\r
-  EFI_USER_CREDENTIAL_PROTOCOL  *Provider;\r
-  EFI_USER_INFO_IDENTIFIER      UserId;\r
-  EFI_USER_INFO_HANDLE          UserInfo;\r
-  EFI_USER_INFO_HANDLE          UserInfo2;\r
-  UINTN                         InfoSize;\r
-  EFI_USER_INFO                 *Info;\r
-  USER_PROFILE_ENTRY            *User;\r
-\r
-  if (This == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-  \r
-  Status = gBS->HandleProtocol (\r
-                  Changed,\r
-                  &gEfiUserCredentialProtocolGuid,\r
-                  (VOID **) &Provider\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  Status = Provider->User (Provider, NULL, &UserId);\r
-  if (EFI_ERROR (Status)) {\r
-    return EFI_NOT_READY;\r
-  }\r
-\r
-  //\r
-  // Find user with the UserId.\r
-  //\r
-  User = NULL;\r
-  while (TRUE) {\r
-    //\r
-    // Find next user profile.\r
-    // \r
-    Status = FindUserProfile (&User, TRUE, NULL);\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
-  \r
-    //\r
-    // Find the user information.\r
-    //\r
-    Info = NULL;\r
-    FindUserInfoByType (User, &Info, EFI_USER_INFO_IDENTIFIER_RECORD);\r
-    if (CompareMem ((UINT8 *) (Info + 1), UserId, sizeof (UserId)) == 0) {\r
-      //\r
-      // Found the infomation record. \r
-      //\r
-      break;\r
-    }\r
-  }\r
-\r
-  UserInfo = NULL;\r
-  do {\r
-    //\r
-    // Get user info handle.\r
-    //\r
-    Status = Provider->GetNextInfo(Provider, &UserInfo);\r
-    if (EFI_ERROR (Status)) {\r
-      return EFI_SUCCESS;\r
-    }\r
-\r
-    //\r
-    // Get the user information from the user info handle.\r
-    // \r
-    InfoSize = 0;\r
-    Status = Provider->GetInfo(Provider, UserInfo, NULL, &InfoSize);\r
-    if (EFI_ERROR (Status)) {\r
-      if (Status == EFI_BUFFER_TOO_SMALL) {\r
-        Info = AllocateZeroPool (InfoSize);\r
-        if (Info == NULL) {\r
-          return EFI_OUT_OF_RESOURCES;\r
-        }\r
-        Status = Provider->GetInfo(Provider, UserInfo, Info, &InfoSize);\r
-        if (EFI_ERROR (Status)) {\r
-          FreePool (Info);\r
-          break;\r
-        }\r
-      }\r
-      break;\r
-    }\r
-\r
-    //\r
-    // Save the user information.\r
-    // \r
-    UserInfo2 = NULL;\r
-    Status = UserProfileSetInfo (&gUserIdentifyManager, (EFI_USER_PROFILE_HANDLE)User, &UserInfo2, Info, InfoSize);\r
-    FreePool (Info);\r
-    if (EFI_ERROR (Status)) {\r
-      break;\r
-    }\r
-  } while (TRUE);\r
-  \r
-  return Status;\r
+{    \r
+  return EFI_UNSUPPORTED;\r
 }\r
 \r
 \r
@@ -4358,6 +3735,11 @@ UserIdentifyManagerInit (
 \r
   EFI_STATUS  Status;\r
 \r
+  //\r
+  // It is NOT robust enough to be included in production.\r
+  //\r
+  #error "This implementation is just a sample, please comment this line if you really want to use this driver."\r
+\r
   //\r
   // Initiate form browser.\r
   //\r