From: Klas Lindfors Date: Tue, 16 Apr 2013 13:09:45 +0000 (+0200) Subject: more import work (complete?) X-Git-Tag: v1.13.0~24^2~7 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ab437a1e24acf653ae22f91908c5019e1cf6fb5;p=yubikey-personalization more import work (complete?) --- diff --git a/ykpers-json.c b/ykpers-json.c index f3bfb63..43a50af 100644 --- a/ykpers-json.c +++ b/ykpers-json.c @@ -173,6 +173,11 @@ int ykp_json_import_cfg(const char *json, size_t len, YKP_CONFIG *cfg) { const char *raw_mode; int mode = MODE_OTP_YUBICO; struct map_st *p; + YK_CONFIG ycfg; + + ycfg.tktFlags = 0; + ycfg.extFlags = 0; + ycfg.cfgFlags = 0; if(!jobj || !yprod_json || !jmode || !options) { ykp_errno = YKP_EINVAL; @@ -222,6 +227,57 @@ int ykp_json_import_cfg(const char *json, size_t len, YKP_CONFIG *cfg) { ykp_set_cfgflag_STATIC_TICKET(cfg, true); } + /* copy the ykcore config to make setting it quick */ + ycfg = cfg->ykcore_config; + + for(p = _ticket_flags_map; p->flag; p++) { + if(!p->json_text) { + continue; + } + if(p->mode && (mode & p->mode) == mode) { + json_object *joption = json_object_object_get(options, p->json_text); + if(joption && json_object_get_type(joption) == json_type_boolean) { + int value = json_object_get_boolean(joption); + if(value == 1) { + ycfg.tktFlags |= p->flag; + } + } + } + } + + for(p = _config_flags_map; p->flag; p++) { + if(!p->json_text) { + continue; + } + if(p->mode && (mode & p->mode) == mode) { + json_object *joption = json_object_object_get(options, p->json_text); + if(joption && json_object_get_type(joption) == json_type_boolean) { + int value = json_object_get_boolean(joption); + if(value == 1) { + ycfg.cfgFlags |= p->flag; + } + } + } + } + + for(p = _extended_flags_map; p->flag; p++) { + if(!p->json_text) { + continue; + } + if(p->mode && (mode & p->mode) == mode) { + json_object *joption = json_object_object_get(options, p->json_text); + if(joption && json_object_get_type(joption) == json_type_boolean) { + int value = json_object_get_boolean(joption); + if(value == 1) { + ycfg.extFlags |= p->flag; + } + } + } + } + + /* copy in the ykcore config again */ + cfg->ykcore_config = ycfg; + json_object_put(jobj); return 1; }