X-Git-Url: https://code.delx.au/refind/blobdiff_plain/7e22a0b1a85d3403ed76ece8339a07ef59174ed3..999e9b76afa9e57b16b54da313a46bdcf08dc412:/mok/mok.c diff --git a/mok/mok.c b/mok/mok.c index bedd031..6b47522 100644 --- a/mok/mok.c +++ b/mok/mok.c @@ -47,29 +47,9 @@ #include "global.h" #include "mok.h" #include "../include/refit_call_wrapper.h" +#include "../refind/lib.h" +#include "../refind/screen.h" -static EFI_STATUS get_variable (CHAR16 *name, EFI_GUID guid, UINT32 *attributes, UINTN *size, VOID **buffer) -{ - EFI_STATUS efi_status; - char allocate = !(*size); - - efi_status = uefi_call_wrapper(RT->GetVariable, 5, name, &guid, attributes, size, buffer); - - if (efi_status != EFI_BUFFER_TOO_SMALL || !allocate) { - return efi_status; - } - - *buffer = AllocatePool(*size); - - if (!*buffer) { - Print(L"Unable to allocate variable buffer\n"); - return EFI_OUT_OF_RESOURCES; - } - - efi_status = uefi_call_wrapper(RT->GetVariable, 5, name, &guid, attributes, size, *buffer); - - return efi_status; -} // get_variable() /* * Check whether we're in Secure Boot and user mode @@ -79,19 +59,16 @@ BOOLEAN secure_mode (VOID) EFI_STATUS status; EFI_GUID global_var = EFI_GLOBAL_VARIABLE; UINTN charsize = sizeof(char); - UINT8 sb, setupmode; - UINT32 attributes; - - status = get_variable(L"SecureBoot", global_var, &attributes, &charsize, (VOID *)&sb); + UINT8 *sb = NULL, *setupmode = NULL; + status = EfivarGetRaw(&global_var, L"SecureBoot", (CHAR8 **) &sb, &charsize); /* FIXME - more paranoia here? */ - if (status != EFI_SUCCESS || sb != 1) { + if (status != EFI_SUCCESS || charsize != sizeof(CHAR8) || *sb != 1) { return FALSE; } - status = get_variable(L"SetupMode", global_var, &attributes, &charsize, (VOID *)&setupmode); - - if (status == EFI_SUCCESS && setupmode == 1) { + status = EfivarGetRaw(&global_var, L"SetupMode", (CHAR8 **) &setupmode, &charsize); + if (status == EFI_SUCCESS && charsize == sizeof(CHAR8) && *setupmode == 1) { return FALSE; } @@ -115,7 +92,7 @@ BOOLEAN ShimValidate (VOID *data, UINT32 size) SHIM_LOCK *shim_lock; EFI_GUID ShimLockGuid = SHIM_LOCK_GUID; - if (refit_call3_wrapper(BS->LocateProtocol, &ShimLockGuid, NULL, (VOID**) &shim_lock) == EFI_SUCCESS) { + if ((data != NULL) && (refit_call3_wrapper(BS->LocateProtocol, &ShimLockGuid, NULL, (VOID**) &shim_lock) == EFI_SUCCESS)) { if (!shim_lock) return FALSE; @@ -124,4 +101,4 @@ BOOLEAN ShimValidate (VOID *data, UINT32 size) } return FALSE; -} // BOOLEAN ShimValidate() +} // BOOLEAN ShimValidate() \ No newline at end of file