]> code.delx.au - refind/blobdiff - mok/mok.c
Added ability to boot the previously-booted loader if
[refind] / mok / mok.c
index 3948b08af03d6482f70b6855c4a86ff5a5a56fe5..6b47522f90ae0dae5378a32773d30452798253ce 100644 (file)
--- a/mok/mok.c
+++ b/mok/mok.c
 #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;
    }