[U-Boot] [RFC PATCH 3/7] env: Introduce "export" operation and (access flag) restriction
Bernhard Nortmann
bernhard.nortmann at web.de
Mon Jul 11 20:14:50 CEST 2016
This patch introduces a new "export" environment operation
(env_op_export) and the corresponding access flag
ENV_FLAGS_VARACCESS_PREVENT_EXPORT; so that env_flags_validate()
may now check requests to export specific variables.
In turn, hexport_r() makes uses of this ability to suppress the
export of variables that are flagged accordingly.
Note that env_flags_validate() and hexport_r() will respect H_FORCE
and H_PROGRAMMATIC flags, allowing to bypass the export filtering.
H_PROGRAMMATIC gets used within env_print() to make sure all
variables are listed. This is necessary because env_print() is
essentially an "export to text" operation.
Signed-off-by: Bernhard Nortmann <bernhard.nortmann at web.de>
---
cmd/nvedit.c | 3 ++-
common/env_flags.c | 8 +++++++-
include/env_flags.h | 3 ++-
include/search.h | 1 +
lib/hashtable.c | 4 ++++
5 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index b67563b..88dbcb9 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -101,7 +101,8 @@ static int env_print(char *name, int flag)
}
/* print whole list */
- len = hexport_r(&env_htab, '\n', flag, &res, 0, 0, NULL);
+ len = hexport_r(&env_htab, '\n',
+ flag | H_PROGRAMMATIC, &res, 0, 0, NULL);
if (len > 0) {
puts(res);
diff --git a/common/env_flags.c b/common/env_flags.c
index 1087f4e..f39d952 100644
--- a/common/env_flags.c
+++ b/common/env_flags.c
@@ -510,7 +510,7 @@ int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op,
newval = newval ? : "";
/* validate the value to match the variable type */
- if (op != env_op_delete) {
+ if (op != env_op_delete && op != env_op_export) {
enum env_flags_vartype type = (enum env_flags_vartype)
(ENV_FLAGS_VARTYPE_BIN_MASK & item->flags);
@@ -560,6 +560,12 @@ int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op,
return 1;
}
break;
+ case env_op_export:
+ if (item->flags & ENV_FLAGS_VARACCESS_PREVENT_EXPORT) {
+ printf("## Don't export \"%s\"\n", name);
+ return 1;
+ }
+ break;
}
return 0;
diff --git a/include/env_flags.h b/include/env_flags.h
index 0dcec06..7e2362a 100644
--- a/include/env_flags.h
+++ b/include/env_flags.h
@@ -173,6 +173,7 @@ int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op,
#define ENV_FLAGS_VARACCESS_PREVENT_CREATE 0x00000010
#define ENV_FLAGS_VARACCESS_PREVENT_OVERWR 0x00000020
#define ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR 0x00000040
-#define ENV_FLAGS_VARACCESS_BIN_MASK 0x00000078
+#define ENV_FLAGS_VARACCESS_PREVENT_EXPORT 0x00000080
+#define ENV_FLAGS_VARACCESS_BIN_MASK 0x000000F8
#endif /* __ENV_FLAGS_H__ */
diff --git a/include/search.h b/include/search.h
index 343dbc3..bb95265 100644
--- a/include/search.h
+++ b/include/search.h
@@ -23,6 +23,7 @@ enum env_op {
env_op_create,
env_op_delete,
env_op_overwrite,
+ env_op_export,
};
/* Action which shall be performed in the call the hsearch. */
diff --git a/lib/hashtable.c b/lib/hashtable.c
index 02b4105..708319d 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -621,6 +621,10 @@ ssize_t hexport_r(struct hsearch_data *htab, const char sep, int flag,
if ((flag & H_HIDE_DOT) && ep->key[0] == '.')
continue;
+ if (env_flags_validate(ep, NULL, env_op_export,
+ flag & H_FORCE) != 0)
+ continue;
+
list[n++] = ep;
totlen += strlen(ep->key) + 2;
--
2.7.3
More information about the U-Boot
mailing list