]> err.no Git - yubikey-personalization/commitdiff
more import work (complete?)
authorKlas Lindfors <klas@yubico.com>
Tue, 16 Apr 2013 13:09:45 +0000 (15:09 +0200)
committerKlas Lindfors <klas@yubico.com>
Tue, 16 Apr 2013 14:00:41 +0000 (16:00 +0200)
ykpers-json.c

index f3bfb63196ca430f49c5f41b2c3b1dd83207af85..43a50afd726878e3aa7b04e147d997d84187e2c0 100644 (file)
@@ -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;
        }