caveats.c (2115B)
1 #include <assert.h> 2 3 #include "verify_common.h" 4 5 #include "caveats.h" 6 #include "caveats_impl.h" 7 #include "netstring.h" 8 #include "miniroon_caveat_name_perfhash.h" 9 typedef enum miniroon_caveat_name_perfhash_key miniroon_caveat_type; 10 11 void miniroon_caveats_state_init(miniroon_caveats_state *state) { 12 miniroon_env_map_init(&state->emap); 13 }; 14 15 void miniroon_caveats_state_exec(miniroon_caveats_state *state, char const *const *argv) { 16 miniroon_env_map_exec(&state->emap, argv); 17 }; 18 19 20 miniroon_caveat_type caveat_get_type(netstring_chunk *c, const bytebuffer caveat) { 21 netstring_chunk_init(c, caveat); 22 if(!netstring_chunk_next(c)) { 23 strerr_dief1x(111, "Mising caveat name"); 24 } 25 dbg_print_bb1("Caveat ID", c->inner); 26 return miniroon_caveat_name_perfhash_hash(c->inner.data, c->inner.len); 27 } 28 29 void miniroon_caveat_prepare(const bytebuffer caveat, miniroon_caveats_state *state) { 30 netstring_chunk c; 31 switch(caveat_get_type(&c, caveat)) { 32 case MINIROON_CAVEAT_UNDEFINED: 33 strerr_dief1x(111, "Unrecognized caveat type"); 34 break; 35 case MINIROON_CAVEAT_ENV_IS: 36 miniroon_caveat_prepare_env_is(&c, state); 37 break; 38 case MINIROON_CAVEAT_ENV_ABSENT: 39 miniroon_caveat_prepare_env_absent(&c, state); 40 break; 41 case MINIROON_CAVEAT_ENV_FNMATCH: 42 miniroon_caveat_prepare_env_fnmatch(&c, state); 43 break; 44 default: 45 strerr_dief1x(111, "Unimplemented caveat type"); 46 break; 47 } 48 } 49 50 void miniroon_caveat_validate(const bytebuffer caveat, miniroon_caveats_state *state) { 51 netstring_chunk c; 52 switch(caveat_get_type(&c, caveat)) { 53 case MINIROON_CAVEAT_UNDEFINED: 54 strerr_dief1x(111, "Unrecognized caveat type"); 55 break; 56 case MINIROON_CAVEAT_ENV_IS: 57 miniroon_caveat_validate_env_is(&c, state); 58 break; 59 case MINIROON_CAVEAT_ENV_ABSENT: 60 miniroon_caveat_validate_env_absent(&c, state); 61 break; 62 case MINIROON_CAVEAT_ENV_FNMATCH: 63 miniroon_caveat_validate_env_fnmatch(&c, state); 64 break; 65 default: 66 strerr_dief1x(111, "Unimplemented caveat type"); 67 break; 68 } 69 } 70 71 /* vim: sts=2 sw=2 et 72 */