[PATCH 2/6] bg_printenv: added INI part

3 views
Skip to first unread message

Tobias Schmidl

unread,
Aug 9, 2022, 9:53:19 AM8/9/22
to efibootg...@googlegroups.com, Tobias Schmidl
Added the possibility to print environment variables via the INI
interface.

Also, ran clang-format over the file.

Signed-off-by: Tobias Schmidl <tobias...@siemens.com>
---
Makefile.am | 1 +
tools/bg_printenv.c | 41 +++++++++++++++++++++++++----------------
2 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index b5384c9..0ab83e0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -135,6 +135,7 @@ endif

bg_setenv_LDADD = \
$(top_builddir)/libebgenv.a \
+ -l:libiniparser.a \
-lz

install-exec-hook:
diff --git a/tools/bg_printenv.c b/tools/bg_printenv.c
index 69d428b..c0eb181 100644
--- a/tools/bg_printenv.c
+++ b/tools/bg_printenv.c
@@ -17,6 +17,7 @@

#include "bg_envtools.h"
#include "bg_printenv.h"
+#include "env_user_config_file.h"

static char tool_doc[] =
"bg_printenv - Environment tool for the EFI Boot Guard";
@@ -91,42 +92,42 @@ static void dump_uservars(uint8_t *udata, bool raw)
fprintf(stdout, raw ? "=%s\n" : " = %s\n", value);
} else if (type >= USERVAR_TYPE_UINT8 &&
type <= USERVAR_TYPE_UINT64) {
- switch(type) {
+ switch (type) {
case USERVAR_TYPE_UINT8:
- val_unum = *((uint8_t *) value);
+ val_unum = *((uint8_t *)value);
break;
case USERVAR_TYPE_UINT16:
- val_unum = *((uint16_t *) value);
+ val_unum = *((uint16_t *)value);
break;
case USERVAR_TYPE_UINT32:
- val_unum = *((uint32_t *) value);
+ val_unum = *((uint32_t *)value);
break;
case USERVAR_TYPE_UINT64:
- val_unum = *((uint64_t *) value);
+ val_unum = *((uint64_t *)value);
break;
}
fprintf(stdout, raw ? "=%llu\n" : " = %llu\n",
(long long unsigned int)val_unum);
} else if (type >= USERVAR_TYPE_SINT8 &&
type <= USERVAR_TYPE_SINT64) {
- switch(type) {
+ switch (type) {
case USERVAR_TYPE_SINT8:
- val_snum = *((int8_t *) value);
+ val_snum = *((int8_t *)value);
break;
case USERVAR_TYPE_SINT16:
- val_snum = *((int16_t *) value);
+ val_snum = *((int16_t *)value);
break;
case USERVAR_TYPE_SINT32:
- val_snum = *((int32_t *) value);
+ val_snum = *((int32_t *)value);
break;
case USERVAR_TYPE_SINT64:
- val_snum = *((int64_t *) value);
+ val_snum = *((int64_t *)value);
break;
}
fprintf(stdout, raw ? "=%lld\n" : " = %lld\n",
(long long signed int)val_snum);
} else {
- switch(type) {
+ switch (type) {
case USERVAR_TYPE_CHAR:
fprintf(stdout, raw ? "=%c\n" : " = %c\n",
(char)*value);
@@ -220,8 +221,9 @@ void dump_envs(const struct fields *output_fields, bool raw)
}
BGENV *env = bgenv_open_by_index(i);
if (!env) {
- fprintf(stderr, "Error, could not read environment "
- "for index %d\n",
+ fprintf(stderr,
+ "Error, could not read environment "
+ "for index %d\n",
i);
return;
}
@@ -253,13 +255,20 @@ static void dump_env_by_index(uint32_t index, struct fields output_fields,
bgenv_close(env);
}

-static int printenv_from_file(char *envfilepath, const struct fields *output_fields,
- bool raw)
+static int printenv_from_file(char *envfilepath,
+ const struct fields *output_fields, bool raw)
{
int success = 0;
BG_ENVDATA data;

- success = get_env(envfilepath, &data);
+ const char *file_name = strrchr(envfilepath, '/');
+ file_name = (file_name != NULL) ? file_name + 1 : envfilepath;
+
+ if (strcasecmp(file_name, FAT_ENV_FILENAME) != 0)
+ success = (env_user_config_file_read(envfilepath, &data,
+ false) == 0);
+ else
+ success = get_env(envfilepath, &data);
if (success) {
dump_env(&data, output_fields, raw);
return 0;
--
2.36.1

Reply all
Reply to author
Forward
0 new messages