From: Andreas Reichel <[email protected]>

If the above flag is set in the type field of a user variable,
bgenv_set_uservar_global is called, which iterates all environments
and stores the given variable globally.

If the flag is absent, only the environment specified by the context
handle gets affected.

The flag is set per default if not otherwise specified.

Signed-off-by: Andreas Reichel <[email protected]>
---
 env/env_api_fat.c | 27 +++++++++++++++++++++++++++
 include/env_api.h |  2 ++
 2 files changed, 29 insertions(+)

diff --git a/env/env_api_fat.c b/env/env_api_fat.c
index 7d5e714..565ab44 100644
--- a/env/env_api_fat.c
+++ b/env/env_api_fat.c
@@ -320,6 +320,29 @@ int bgenv_get(BGENV *env, char *key, uint64_t *type, void 
*data,
        return 0;
 }
 
+int bgenv_set_uservar_global(char *key, uint64_t type, void *data,
+                            uint32_t datalen)
+{
+       int ret = 0;
+       for (int i = 0; i < ENV_NUM_CONFIG_PARTS; i++) {
+               BGENV *env = bgenv_open_by_index(i);
+               if (!env) {
+                       ret = -EIO;
+                       continue;
+               }
+               int r = bgenv_set_uservar(env->data->userdata, key, type, data,
+                                 datalen);
+               if (r) {
+                       ret = r;
+               }
+               if (!bgenv_write(env)) {
+                       ret = -EIO;
+               }
+               (void)bgenv_close(env);
+       }
+       return ret;
+}
+
 int bgenv_set(BGENV *env, char *key, uint64_t type, void *data,
              uint32_t datalen)
 {
@@ -337,6 +360,10 @@ int bgenv_set(BGENV *env, char *key, uint64_t type, void 
*data,
                return -EPERM;
        }
        if (e == EBGENV_UNKNOWN) {
+               if (type & USERVAR_TYPE_GLOBAL) {
+                       return bgenv_set_uservar_global(key, type, data,
+                                                       datalen);
+               }
                return bgenv_set_uservar(env->data->userdata, key, type, data,
                                         datalen);
        }
diff --git a/include/env_api.h b/include/env_api.h
index 8ea2c11..3b1ba1f 100644
--- a/include/env_api.h
+++ b/include/env_api.h
@@ -83,5 +83,7 @@ extern int bgenv_get(BGENV *env, char *key, uint64_t *type, 
void *data,
                     uint32_t maxlen);
 extern int bgenv_set(BGENV *env, char *key, uint64_t type, void *data,
                     uint32_t datalen);
+extern int bgenv_set_uservar_global(char *key, uint64_t type,
+                                   void *data, uint32_t datalen);
 
 #endif // __ENV_API_H__
-- 
2.14.2

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/efibootguard-dev/20171103122121.27121-4-andreas.reichel.ext%40siemens.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to