commit 0414cb5bbd9e6f1e7400cc7fab862b8154ba9ac9
parent e1844aaee0b3f7f690656fd1b2fa7de358277bc8
Author: Jan Pobrislo <ccx@te2000.cz>
Date: Mon, 11 Nov 2024 00:23:17 +0000
Load env whitelist
Diffstat:
3 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/src/bytebuffer.c b/src/bytebuffer.c
@@ -3,6 +3,10 @@
#include "bytebuffer.h"
+int bbcmp(const bytebuffer a, const bytebuffer b) {
+ return a.len == b.len ? memcmp(a.data, b.data, b.len) : (a.len < b.len ? -1 : 1);
+}
+
int strbbcmp(const bytebuffer bb, const char *s) {
return strncmp(bb.data, s, bb.len);
}
diff --git a/src/bytebuffer.h b/src/bytebuffer.h
@@ -8,6 +8,7 @@ typedef struct bytebuffer_s {
size_t len;
} bytebuffer;
+int bbcmp(const bytebuffer a, const bytebuffer b);
int strbbcmp(const bytebuffer bb, const char *s);
void dbg_print_bb(const bytebuffer bb);
diff --git a/src/miniroon-verify.c b/src/miniroon-verify.c
@@ -28,8 +28,8 @@
#define MAX_ENV_ALLOW 256
typedef struct miniroon_env_entry_s {
- const bytebuffer name;
- const bytebuffer value;
+ bytebuffer name;
+ bytebuffer value;
enum miniroon_env_state {
ENV_NO_CHANGE = 0,
ENV_SET = 1,
@@ -51,7 +51,7 @@ typedef struct miniroon_data_s {
/* declarations */
void miniroon_env_map_init(miniroon_env_map *emap);
void miniroon_env_map_add(miniroon_env_map *emap, const bytebuffer name);
-int miniroon_env_map_find(miniroon_env_map *emap, const bytebuffer name);
+miniroon_env_entry * miniroon_env_map_find(miniroon_env_map *emap, const bytebuffer name);
void miniroon_data_init(miniroon_data *data);
void process_payload(const bytebuffer payload);
void validate_caveats(miniroon_data *data);
@@ -98,11 +98,21 @@ void read_secret(const bytebuffer secret){
void miniroon_env_map_init(miniroon_env_map *emap) {
memset(emap, 0, sizeof(miniroon_env_map));
}
+
void miniroon_env_map_add(miniroon_env_map *emap, const bytebuffer name) {
- assert(0); // TODO
+ assert(miniroon_env_map_find(emap, name) == NULL);
+ assert(emap->env_count < MAX_ENV_ALLOW); // TODO: proper check
+ emap->env[emap->env_count++].name = name;
+}
+
+miniroon_env_entry * miniroon_env_map_find(miniroon_env_map *emap, const bytebuffer name) {
+ for(size_t i=0; i < emap->env_count; i++) {
+ if(bbcmp(emap->env[i].name, name) == 0) {
+ return &emap->env[i];
+ }
+ }
+ return NULL;
}
-int miniroon_env_map_find(miniroon_env_map *emap, const bytebuffer name);
-// TODO
void validate_caveats(miniroon_data *md) {
miniroon_env_map emap;
@@ -123,12 +133,13 @@ void validate_caveats(miniroon_data *md) {
if(var[i] >= 'A' && var[i] <= 'z') { continue; }
if(var[i] == '=') {
if(var[i+1]) { break; }
- bytebuffer bb = {var, i - 1};
+ bytebuffer bb = {var, i};
miniroon_env_map_add(&emap, bb);
}
}
}
+
for(size_t i=0; i < md->caveat_count; i++) {
dbg_print_bb1("Validate caveat", md->caveats[i]);
}