]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c
SecurityPkg: remove PE/COFF header workaround for ELILO on IPF
[mirror_edk2.git] / SecurityPkg / VariableAuthenticated / SecureBootConfigDxe / SecureBootConfigFileExplorer.c
index 2adb85ce90a5f60c6160e518adb11f3c89aafd64..aef85c47014361264250f0efeafec11cde83d10d 100644 (file)
@@ -80,153 +80,15 @@ CleanUpPage (
     );\r
 }\r
 \r
-/**\r
-  This function will open a file or directory referenced by DevicePath.\r
-\r
-  This function opens a file with the open mode according to the file path. The\r
-  Attributes is valid only for EFI_FILE_MODE_CREATE.\r
-\r
-  @param[in, out]  FilePath        On input, the device path to the file.\r
-                                   On output, the remaining device path.\r
-  @param[out]      FileHandle      Pointer to the file handle.\r
-  @param[in]       OpenMode        The mode to open the file with.\r
-  @param[in]       Attributes      The file's file attributes.\r
-\r
-  @retval EFI_SUCCESS              The information was set.\r
-  @retval EFI_INVALID_PARAMETER    One of the parameters has an invalid value.\r
-  @retval EFI_UNSUPPORTED          Could not open the file path.\r
-  @retval EFI_NOT_FOUND            The specified file could not be found on the\r
-                                   device or the file system could not be found on\r
-                                   the device.\r
-  @retval EFI_NO_MEDIA             The device has no medium.\r
-  @retval EFI_MEDIA_CHANGED        The device has a different medium in it or the\r
-                                   medium is no longer supported.\r
-  @retval EFI_DEVICE_ERROR         The device reported an error.\r
-  @retval EFI_VOLUME_CORRUPTED     The file system structures are corrupted.\r
-  @retval EFI_WRITE_PROTECTED      The file or medium is write protected.\r
-  @retval EFI_ACCESS_DENIED        The file was opened read only.\r
-  @retval EFI_OUT_OF_RESOURCES     Not enough resources were available to open the\r
-                                   file.\r
-  @retval EFI_VOLUME_FULL          The volume is full.\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-OpenFileByDevicePath(\r
-  IN OUT EFI_DEVICE_PATH_PROTOCOL     **FilePath,\r
-  OUT EFI_FILE_HANDLE                 *FileHandle,\r
-  IN UINT64                           OpenMode,\r
-  IN UINT64                           Attributes\r
-  )\r
-{\r
-  EFI_STATUS                      Status;\r
-  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *EfiSimpleFileSystemProtocol;\r
-  EFI_FILE_PROTOCOL               *Handle1;\r
-  EFI_FILE_PROTOCOL               *Handle2;\r
-  EFI_HANDLE                      DeviceHandle;\r
-\r
-  if ((FilePath == NULL || FileHandle == NULL)) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  Status = gBS->LocateDevicePath (\r
-                  &gEfiSimpleFileSystemProtocolGuid,\r
-                  FilePath,\r
-                  &DeviceHandle\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  Status = gBS->OpenProtocol(\r
-                  DeviceHandle,\r
-                  &gEfiSimpleFileSystemProtocolGuid,\r
-                  (VOID**)&EfiSimpleFileSystemProtocol,\r
-                  gImageHandle,\r
-                  NULL,\r
-                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  Status = EfiSimpleFileSystemProtocol->OpenVolume(EfiSimpleFileSystemProtocol, &Handle1);\r
-  if (EFI_ERROR (Status)) {\r
-    FileHandle = NULL;\r
-    return Status;\r
-  }\r
-\r
-  //\r
-  // go down directories one node at a time.\r
-  //\r
-  while (!IsDevicePathEnd (*FilePath)) {\r
-    //\r
-    // For file system access each node should be a file path component\r
-    //\r
-    if (DevicePathType    (*FilePath) != MEDIA_DEVICE_PATH ||\r
-        DevicePathSubType (*FilePath) != MEDIA_FILEPATH_DP\r
-       ) {\r
-      FileHandle = NULL;\r
-      return (EFI_INVALID_PARAMETER);\r
-    }\r
-    //\r
-    // Open this file path node\r
-    //\r
-    Handle2  = Handle1;\r
-    Handle1 = NULL;\r
-\r
-    //\r
-    // Try to test opening an existing file\r
-    //\r
-    Status = Handle2->Open (\r
-                          Handle2,\r
-                          &Handle1,\r
-                          ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName,\r
-                          OpenMode &~EFI_FILE_MODE_CREATE,\r
-                          0\r
-                         );\r
-\r
-    //\r
-    // see if the error was that it needs to be created\r
-    //\r
-    if ((EFI_ERROR (Status)) && (OpenMode != (OpenMode &~EFI_FILE_MODE_CREATE))) {\r
-      Status = Handle2->Open (\r
-                            Handle2,\r
-                            &Handle1,\r
-                            ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName,\r
-                            OpenMode,\r
-                            Attributes\r
-                           );\r
-    }\r
-    //\r
-    // Close the last node\r
-    //\r
-    Handle2->Close (Handle2);\r
-\r
-    if (EFI_ERROR(Status)) {\r
-      return (Status);\r
-    }\r
-\r
-    //\r
-    // Get the next node\r
-    //\r
-    *FilePath = NextDevicePathNode (*FilePath);\r
-  }\r
-\r
-  //\r
-  // This is a weak spot since if the undefined SHELL_FILE_HANDLE format changes this must change also!\r
-  //\r
-  *FileHandle = (VOID*)Handle1;\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
 /**\r
   Extract filename from device path. The returned buffer is allocated using AllocateCopyPool.\r
-  The caller is responsible for freeing the allocated buffer using FreePool().\r
+  The caller is responsible for freeing the allocated buffer using FreePool(). If return NULL\r
+  means not enough memory resource.\r
 \r
   @param DevicePath       Device path.\r
 \r
-  @return                 A new allocated string that represents the file name.\r
+  @retval NULL            Not enough memory resourece for AllocateCopyPool.\r
+  @retval Other           A new allocated string that represents the file name.\r
 \r
 **/\r
 CHAR16 *\r
@@ -245,6 +107,7 @@ ExtractFileNameFromDevicePath (
   String = DevicePathToStr(DevicePath);\r
   MatchString = String;\r
   LastMatch   = String;\r
+  FileName    = NULL;\r
 \r
   while(MatchString != NULL){\r
     LastMatch   = MatchString + 1;\r
@@ -253,7 +116,9 @@ ExtractFileNameFromDevicePath (
 \r
   Length = StrLen(LastMatch);\r
   FileName = AllocateCopyPool ((Length + 1) * sizeof(CHAR16), LastMatch);\r
-  *(FileName + Length) = 0;\r
+  if (FileName != NULL) {\r
+    *(FileName + Length) = 0;\r
+  }\r
 \r
   FreePool(String);\r
 \r
@@ -280,18 +145,25 @@ UpdatePage(
   CHAR16                *FileName;\r
   EFI_STRING_ID         StringToken;\r
 \r
-  if (FilePath != NULL){\r
+  FileName = NULL;\r
+\r
+  if (FilePath != NULL) {\r
     FileName = ExtractFileNameFromDevicePath(FilePath);\r
-    StringToken = HiiSetString (gSecureBootPrivateData->HiiHandle, 0, FileName, NULL);\r
-  } else {\r
-    FileName = HiiGetString (gSecureBootPrivateData->HiiHandle, STRING_TOKEN (STR_NULL), NULL);\r
-    ASSERT (FileName != NULL);\r
-    StringToken =  HiiSetString (gSecureBootPrivateData->HiiHandle, 0, FileName, NULL);\r
   }\r
+  if (FileName == NULL) {\r
+    //\r
+    // FileName = NULL has two case:\r
+    // 1. FilePath == NULL, not select file.\r
+    // 2. FilePath != NULL, but ExtractFileNameFromDevicePath return NULL not enough memory resource.\r
+    // In these two case, no need to update the form, and exit the caller function.\r
+    //\r
+    return TRUE;\r
+  }\r
+  StringToken =  HiiSetString (gSecureBootPrivateData->HiiHandle, 0, FileName, NULL);\r
 \r
   gSecureBootPrivateData->FileContext->FileName = FileName;\r
 \r
-  OpenFileByDevicePath(\r
+  EfiOpenFileByDevicePath (\r
     &FilePath,\r
     &gSecureBootPrivateData->FileContext->FHandle,\r
     EFI_FILE_MODE_READ,\r
@@ -331,6 +203,7 @@ UpdatePage(
   @retval FALSE  Not exit caller function.\r
 **/\r
 BOOLEAN\r
+EFIAPI\r
 UpdatePKFromFile (\r
   IN EFI_DEVICE_PATH_PROTOCOL    *FilePath\r
   )\r
@@ -348,6 +221,7 @@ UpdatePKFromFile (
   @retval FALSE  Not exit caller function.\r
 **/\r
 BOOLEAN\r
+EFIAPI\r
 UpdateKEKFromFile (\r
   IN EFI_DEVICE_PATH_PROTOCOL    *FilePath\r
   )\r
@@ -364,6 +238,7 @@ UpdateKEKFromFile (
   @retval FALSE  Not exit caller function.\r
 **/\r
 BOOLEAN\r
+EFIAPI\r
 UpdateDBFromFile (\r
   IN EFI_DEVICE_PATH_PROTOCOL    *FilePath\r
   )\r
@@ -380,6 +255,7 @@ UpdateDBFromFile (
   @retval FALSE  Not exit caller function.\r
 **/\r
 BOOLEAN\r
+EFIAPI\r
 UpdateDBXFromFile (\r
   IN EFI_DEVICE_PATH_PROTOCOL    *FilePath\r
   )\r
@@ -396,6 +272,7 @@ UpdateDBXFromFile (
   @retval FALSE  Not exit caller function.\r
 **/\r
 BOOLEAN\r
+EFIAPI\r
 UpdateDBTFromFile (\r
   IN EFI_DEVICE_PATH_PROTOCOL    *FilePath\r
   )\r