On 2018-09-03 16:09, [ext] Andreas J. Reichel wrote:
From: Andreas Reichel <[email protected]>
Get the boot device out of the loaded image's handle and add a
function to compare a device path with the boot device's one.
Signed-off-by: Andreas Reichel <[email protected]>
---
bootguard.c | 1 +
include/utils.h | 1 +
main.c | 8 ++++++++
utils.c | 18 ++++++++++++++++++
4 files changed, 28 insertions(+)
diff --git a/bootguard.c b/bootguard.c
index 0aa95b4..9eea350 100644
--- a/bootguard.c
+++ b/bootguard.c
@@ -18,3 +18,4 @@ EFI_HANDLE this_image;
VOLUME_DESC *volumes = NULL;
UINTN volume_count = 128;
+CHAR16 *boot_device_path;
diff --git a/include/utils.h b/include/utils.h
index 846e8be..3d1a318 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -42,5 +42,6 @@ EFI_STATUS close_volumes(VOLUME_DESC *volumes, UINTN count);
EFI_DEVICE_PATH *FileDevicePathFromConfig(EFI_HANDLE device,
CHAR16 *payloadpath);
CHAR16 *dirname(CHAR16 *input);
+BOOLEAN IsOnBootDevice(EFI_DEVICE_PATH *dp);
#endif // __H_UTILS__
diff --git a/main.c b/main.c
index 2f8e151..986bb57 100644
--- a/main.c
+++ b/main.c
@@ -24,6 +24,7 @@
extern const unsigned long init_array_start[];
extern const unsigned long init_array_end[];
+extern CHAR16 *boot_device_path;
static EFI_STATUS probe_watchdog(EFI_LOADED_IMAGE *loaded_image,
EFI_PCI_IO *pci_io, UINT16 pci_vendor_id,
@@ -105,6 +106,7 @@ EFI_STATUS efi_main(EFI_HANDLE image_handle,
EFI_SYSTEM_TABLE *system_table)
EFI_STATUS status;
BG_STATUS bg_status;
BG_LOADER_PARAMS bg_loader_params;
+ CHAR16 *tmp;
ZeroMem(&bg_loader_params, sizeof(bg_loader_params));
@@ -123,6 +125,11 @@ EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table)
status);
}
+ tmp = DevicePathToStr(DevicePathFromHandle(loaded_image->DeviceHandle));
For my understanding: What is actually cut off there, ie. who does that
path look like so that we only to cut off the last element, and there is
not filesystem directory element remaining in it?
+ boot_device_path = dirname(tmp);
+ mfree(tmp);
+ Print(L"Boot device: %s\n", boot_device_path);
+
status = get_volumes(&volumes, &volume_count);
if (EFI_ERROR(status)) {
error_exit(L"Could not get volumes installed on system.\n",
@@ -176,6 +183,7 @@ EFI_STATUS efi_main(EFI_HANDLE image_handle,
EFI_SYSTEM_TABLE *system_table)
}
mfree(payload_dev_path);
+ mfree(boot_device_path);
status =
uefi_call_wrapper(BS->OpenProtocol, 6, payload_handle,
diff --git a/utils.c b/utils.c
index 94226fb..ad779f4 100644
--- a/utils.c
+++ b/utils.c
@@ -16,6 +16,24 @@
#include <bootguard.h>
#include <utils.h>
+BOOLEAN IsOnBootDevice(EFI_DEVICE_PATH *dp)
+{
+ extern CHAR16 *boot_device_path;
+ CHAR16 *device_path, *tmp;
+ BOOLEAN result = FALSE;
+
+ tmp = DevicePathToStr(dp);
+ device_path = dirname(tmp);
+ mfree(tmp);
+
+ if (StrCmp(device_path, boot_device_path) == 0) {
+ result = TRUE;
+ }
+ mfree(device_path);
+
+ return result;
+}
+
uint32_t calc_crc32(void *data, int32_t size)
{
uint32_t crc;
Looks good, /me just needs to understand the path structure, and maybe
that should then also be documented in the code.
Jan
--
You received this message because you are subscribed to the Google Groups "EFI Boot
Guard" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/efibootguard-dev/1e5fad57-3fd5-51b3-eed4-bfd70777c10e%40siemens.com.
For more options, visit https://groups.google.com/d/optout.