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