]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Makes DxeDeferImageLoadLib not depend on
authorDong Guo <guo.dong@intel.com>
Wed, 27 Nov 2013 09:08:29 +0000 (09:08 +0000)
committergdong1 <gdong1@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 27 Nov 2013 09:08:29 +0000 (09:08 +0000)
Signed-off-by: Dong Guo <guo.dong@intel.com>
Reviewed-by: Ni, Ruiyu <ruiyu.ni@intel.com>
Reviewed-by: Ouyang, Qian <qian.ouyang@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14905 6f19259b-4bc3-4df7-8a09-765794883524

SecurityPkg/Library/DxeDeferImageLoadLib/DxeDeferImageLoadLib.c
SecurityPkg/Library/DxeDeferImageLoadLib/DxeDeferImageLoadLib.h
SecurityPkg/Library/DxeDeferImageLoadLib/DxeDeferImageLoadLib.inf

index fd18d2f7e7471d1c5cded7281eadaf8ddb28d7bd..3cbd0983650a64ae60d7b0e795eb21e212d3994c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implement defer image load services for user identification in UEFI2.2.\r
 \r
-Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2013, 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
@@ -263,57 +263,107 @@ GetAccessControl (
   return EFI_NOT_FOUND;\r
 }\r
 \r
-\r
 /**\r
-  Convert the '/' to '\' in the specified string.\r
+  Get file name from device path.\r
 \r
-  @param[in, out]  Str       Points to the string to convert.\r
+  The file name may contain one or more device path node. Save the file name in a \r
+  buffer if file name is found. The caller is responsible to free the buffer.  \r
+  \r
+  @param[in]  DevicePath     A pointer to a device path.\r
+  @param[out] FileName       The callee allocated buffer to save the file name if file name is found.\r
+  @param[out] FileNameOffset The offset of file name in device path if file name is found.\r
+  \r
+  @retval     UINTN          The file name length. 0 means file name is not found.\r
 \r
 **/\r
-VOID\r
-ConvertDPStr (\r
-  IN OUT EFI_STRING                     Str \r
+UINTN \r
+GetFileName (\r
+  IN  CONST EFI_DEVICE_PATH_PROTOCOL          *DevicePath,\r
+  OUT UINT8                                   **FileName,\r
+  OUT UINTN                                   *FileNameOffset\r
   )\r
 {\r
-  INTN                                  Count;\r
-  INTN                                  Index;\r
-  \r
-  Count = StrSize(Str) / 2 - 1;\r
+  UINTN                                       Length;\r
+  EFI_DEVICE_PATH_PROTOCOL                    *TmpDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL                    *RootDevicePath;\r
+  CHAR8                                       *NodeStr;\r
+  UINTN                                       NodeStrLength;\r
+  CHAR16                                      LastNodeChar;\r
+  CHAR16                                      FirstNodeChar;\r
 \r
-  if (Count < 4) {\r
-    return;\r
+  //\r
+  // Get the length of DevicePath before file name.\r
+  //\r
+  Length = 0;\r
+  RootDevicePath = (EFI_DEVICE_PATH_PROTOCOL *)DevicePath;\r
+  while (!IsDevicePathEnd (RootDevicePath)) {\r
+    if ((DevicePathType(RootDevicePath) == MEDIA_DEVICE_PATH) && (DevicePathSubType(RootDevicePath) == MEDIA_FILEPATH_DP)) {\r
+      break;\r
+    }\r
+    Length += DevicePathNodeLength (RootDevicePath);\r
+    RootDevicePath = NextDevicePathNode (RootDevicePath);\r
   }\r
-  \r
+\r
+  *FileNameOffset = Length;\r
+  if (Length == 0) {\r
+    return 0;\r
+  }\r
+\r
   //\r
-  // Convert device path string.\r
+  // Get the file name length.\r
   //\r
-  Index = Count - 1;\r
-  while (Index > 0) {\r
-    //\r
-    // Find the last '/'.\r
-    //\r
-    for (Index = Count - 1; Index > 0; Index--) {\r
-      if (Str[Index] == L'/')\r
-        break;\r
+  Length = 0;\r
+  TmpDevicePath = RootDevicePath;\r
+  while (!IsDevicePathEnd (TmpDevicePath)) {\r
+    if ((DevicePathType(TmpDevicePath) != MEDIA_DEVICE_PATH) || (DevicePathSubType(TmpDevicePath) != MEDIA_FILEPATH_DP)) {\r
+      break;\r
     }\r
+    Length += DevicePathNodeLength (TmpDevicePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
+    TmpDevicePath = NextDevicePathNode (TmpDevicePath);\r
+  }\r
+  if (Length == 0) {\r
+    return 0;\r
+  }\r
 \r
-    //\r
-    // Check next char.\r
-    //\r
-    if (Str[Index + 1] == L'\\')\r
-      return;\r
+  *FileName = AllocateZeroPool (Length);\r
+  ASSERT (*FileName != NULL);\r
+\r
+  //\r
+  // Copy the file name to the buffer.\r
+  //\r
+  Length = 0;\r
+  LastNodeChar = '\\';\r
+  TmpDevicePath = RootDevicePath;\r
+  while (!IsDevicePathEnd (TmpDevicePath)) {\r
+    if ((DevicePathType(TmpDevicePath) != MEDIA_DEVICE_PATH) || (DevicePathSubType(TmpDevicePath) != MEDIA_FILEPATH_DP)) {\r
+      break;\r
+    }\r
+\r
+    FirstNodeChar = (CHAR16) ReadUnaligned16 ((UINT16 *)((UINT8 *)TmpDevicePath + sizeof (EFI_DEVICE_PATH_PROTOCOL)));\r
+    NodeStr = (CHAR8 *)TmpDevicePath + sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
+    NodeStrLength = DevicePathNodeLength (TmpDevicePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL) - sizeof(CHAR16);\r
     \r
-    Str[Index] = L'\\';\r
+    if ((FirstNodeChar == '\\') && (LastNodeChar == '\\')) {\r
+      //\r
+      // Skip separator "\" when there are two separators.\r
+      //\r
+      NodeStr += sizeof (CHAR16);\r
+      NodeStrLength -= sizeof (CHAR16);      \r
+    } else if ((FirstNodeChar != '\\') && (LastNodeChar != '\\')) {\r
+      //\r
+      // Add separator "\" when there is no separator.\r
+      //\r
+      WriteUnaligned16 ((UINT16 *)(*FileName + Length), '\\');\r
+      Length += sizeof (CHAR16);\r
+    } \r
+    CopyMem (*FileName + Length, NodeStr, NodeStrLength);\r
+    Length += NodeStrLength;\r
     \r
-    //\r
-    // Check previous char.\r
-    //\r
-    if ((Index > 0) && (Str[Index - 1] == L'\\')) {\r
-      CopyMem (&Str[Index - 1], &Str[Index], (UINTN) ((Count - Index + 1) * sizeof (CHAR16)));\r
-      return;\r
-    }\r
-    Index--;\r
-  }\r
+    LastNodeChar  = (CHAR16) ReadUnaligned16 ((UINT16 *) (NodeStr + NodeStrLength - sizeof(CHAR16)));\r
+    TmpDevicePath = NextDevicePathNode (TmpDevicePath);\r
+  }    \r
+\r
+  return Length;\r
 }\r
 \r
 \r
@@ -342,54 +392,72 @@ CheckDevicePath (
   IN  CONST EFI_DEVICE_PATH_PROTOCOL          *DevicePath2\r
   )\r
 {\r
-  EFI_STATUS                            Status;\r
-  EFI_STRING                            DevicePathStr1;\r
-  EFI_STRING                            DevicePathStr2;\r
-  UINTN                                 StrLen1;\r
-  UINTN                                 StrLen2;\r
-  EFI_DEVICE_PATH_TO_TEXT_PROTOCOL      *DevicePathText;\r
-  BOOLEAN                               DevicePathEqual;\r
+  UINTN                                       DevicePathSize;\r
+  UINTN                                       FileNameSize1;\r
+  UINTN                                       FileNameSize2;\r
+  UINT8                                       *FileName1;\r
+  UINT8                                       *FileName2;\r
+  UINTN                                       FileNameOffset1;\r
+  UINTN                                       FileNameOffset2;\r
+  BOOLEAN                                     DevicePathEqual;\r
+\r
+  FileName1       = NULL;\r
+  FileName2       = NULL;\r
+  DevicePathEqual = TRUE;\r
 \r
   ASSERT (DevicePath1 != NULL);\r
   ASSERT (DevicePath2 != NULL);\r
+  if (IsDevicePathEnd (DevicePath1)) {\r
+    return FALSE;\r
+  }\r
   \r
-  DevicePathEqual = FALSE;\r
-  DevicePathText  = NULL;\r
-  Status = gBS->LocateProtocol ( \r
-                  &gEfiDevicePathToTextProtocolGuid,\r
-                  NULL,\r
-                  (VOID **) &DevicePathText\r
-                  );\r
-  ASSERT (Status == EFI_SUCCESS);\r
-  \r
-  //\r
-  // Get first device path string.\r
   //\r
-  DevicePathStr1 = DevicePathText->ConvertDevicePathToText (DevicePath1, TRUE, TRUE);\r
-  ConvertDPStr (DevicePathStr1);\r
+  // The file name may contain one or more device path node. \r
+  // To compare the file name, copy file name to a buffer and compare the buffer.\r
   //\r
-  // Get second device path string.\r
-  //\r
-  DevicePathStr2 = DevicePathText->ConvertDevicePathToText (DevicePath2, TRUE, TRUE);\r
-  ConvertDPStr (DevicePathStr2);\r
-  \r
+  FileNameSize1 = GetFileName (DevicePath1, &FileName1, &FileNameOffset1);\r
+  if (FileNameSize1 != 0) {\r
+    FileNameSize2 = GetFileName (DevicePath2, &FileName2, &FileNameOffset2);\r
+    if (FileNameOffset1 != FileNameOffset2) {\r
+      DevicePathEqual = FALSE;\r
+      goto Done;\r
+    }\r
+    if (CompareMem (DevicePath1, DevicePath2, FileNameOffset1) != 0) {      \r
+      DevicePathEqual = FALSE;\r
+      goto Done;\r
+    }\r
+    if (FileNameSize1 > FileNameSize2) {\r
+      DevicePathEqual = FALSE;\r
+      goto Done;\r
+    }\r
+    if (CompareMem (FileName1, FileName2, FileNameSize1) != 0) {      \r
+      DevicePathEqual = FALSE;\r
+      goto Done;\r
+    }\r
+    DevicePathEqual = TRUE;\r
+    goto Done;\r
+  }\r
+\r
+  DevicePathSize = GetDevicePathSize (DevicePath1);\r
+  if (DevicePathSize > GetDevicePathSize (DevicePath2)) {\r
+    return FALSE;\r
+  }\r
+\r
   //\r
-  // Compare device path string.\r
+  // Exclude the end of device path node.\r
   //\r
-  StrLen1 = StrSize (DevicePathStr1);\r
-  StrLen2 = StrSize (DevicePathStr2);\r
-  if (StrLen1 > StrLen2) {\r
+  DevicePathSize -= sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
+  if (CompareMem (DevicePath1, DevicePath2, DevicePathSize) != 0) {\r
     DevicePathEqual = FALSE;\r
-    goto Done;\r
-  }\r
+  } \r
   \r
-  if (CompareMem (DevicePathStr1, DevicePathStr2, StrLen1) == 0) {\r
-    DevicePathEqual = TRUE;\r
+Done: \r
+  if (FileName1 != NULL) {\r
+    FreePool (FileName1);\r
+  }\r
+  if (FileName2 != NULL) {\r
+    FreePool (FileName2);\r
   }\r
-\r
-Done:\r
-  FreePool (DevicePathStr1);\r
-  FreePool (DevicePathStr2);\r
   return DevicePathEqual;\r
 }\r
 \r
index 52eb81b7965403880ed8e55a9b75e7f57d2835fe..fd750be512af49c5c9d3a7e648dc7b419c3c8afa 100644 (file)
@@ -2,7 +2,7 @@
   The internal header file includes the common header files, defines\r
   internal structure and functions used by DeferImageLoadLib.\r
 \r
-Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2013, 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
@@ -34,7 +34,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Protocol/DeferredImageLoad.h>\r
 #include <Protocol/UserCredential.h>\r
 #include <Protocol/UserManager.h>\r
-#include <Protocol/DevicePathToText.h>\r
 \r
 #include <Guid/GlobalVariable.h>\r
 \r
index e16fe8dc04435fff5426313eb8c8aa540872e32e..dcd5c6128e5b21acce1780e297252931345744c3 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 #  The library instance provides security service of deferring image load.\r
 #\r
-# Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2009 - 2013, 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
@@ -53,7 +53,6 @@
   gEfiSimpleFileSystemProtocolGuid\r
   gEfiUserManagerProtocolGuid\r
   gEfiDeferredImageLoadProtocolGuid\r
-  gEfiDevicePathToTextProtocolGuid\r
   \r
 [Guids]\r
   gEfiGlobalVariableGuid\r