From 887c0edab93c52e2558047897847166b73dc8c3a Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Wed, 15 May 2024 16:01:34 -0400 Subject: mok variables: add a format callback This adds a member to the mok_state_variable struct to provide a callback function for formatting external data. It basically has snprintf()-like semantics for filling the buffer, but without the actual printf-like formatting bits. Signed-off-by: Peter Jones --- mok.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'mok.c') diff --git a/mok.c b/mok.c index 2778cd05..67a798a3 100644 --- a/mok.c +++ b/mok.c @@ -985,8 +985,22 @@ EFI_STATUS import_one_mok_state(struct mok_state_variable *v, } } + if (v->format) { + v->data_size = v->format(NULL, 0, v); + if (v->data_size > 0) { + v->data = AllocatePool(v->data_size); + if (!v->data) { + perror(L"Could not allocate %lu bytes for %s\n", + v->data_size, v->name); + return EFI_OUT_OF_RESOURCES; + } + } + v->format(v->data, v->data_size, v); + } + if (!v->data && !v->data_size && - (v->flags & MOK_VARIABLE_CONFIG_ONLY)) { + (v->flags & MOK_VARIABLE_CONFIG_ONLY) && + !v->format) { efi_status = get_variable_attr(v->name, &v->data, &v->data_size, *v->guid, &attrs); -- cgit v1.2.3