efi_loader: function to get GUID for variable name
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Thu, 9 Sep 2021 06:22:58 +0000 (08:22 +0200)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Mon, 25 Oct 2021 19:13:06 +0000 (21:13 +0200)
In multiple places we need the default GUID matching a variable name.
The patch provides a library function. For secure boot related variables
like 'PK', 'KEK', 'db' a lookup table is used. For all other variable
names EFI_GLOBAL_VARIABLE is returned.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
include/efi_variable.h
lib/efi_loader/efi_var_common.c

index 8f666b2..03a3ecb 100644 (file)
@@ -257,6 +257,14 @@ enum efi_auth_var_type efi_auth_var_get_type(const u16 *name,
                                             const efi_guid_t *guid);
 
 /**
+ * efi_auth_var_get_guid() - get the predefined GUID for a variable name
+ *
+ * @name:      name of UEFI variable
+ * Return:     guid of UEFI variable
+ */
+const efi_guid_t *efi_auth_var_get_guid(const u16 *name);
+
+/**
  * efi_get_next_variable_name_mem() - Runtime common code across efi variable
  *                                    implementations for GetNextVariable()
  *                                    from the cached memory copy
index e179932..3cbb7c9 100644 (file)
@@ -385,6 +385,15 @@ enum efi_auth_var_type efi_auth_var_get_type(const u16 *name,
        return EFI_AUTH_VAR_NONE;
 }
 
+const efi_guid_t *efi_auth_var_get_guid(const u16 *name)
+{
+       for (size_t i = 0; i < ARRAY_SIZE(name_type); ++i) {
+               if (!u16_strcmp(name, name_type[i].name))
+                       return name_type[i].guid;
+       }
+       return &efi_global_variable_guid;
+}
+
 /**
  * efi_get_var() - read value of an EFI variable
  *