Added the possibility to print environment variables via the INI
interface.

Also, ran clang-format over the file.

Signed-off-by: Tobias Schmidl <[email protected]>
---
 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

-- 
You received this message because you are subscribed to the Google Groups "EFI 
Boot Guard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/efibootguard-dev/20220809135300.1470407-3-tobiasschmidl%40siemens.com.

Reply via email to