]> err.no Git - yubikey-personalization/commitdiff
add pointer to setter function to mapping tables
authorKlas Lindfors <klas@yubico.com>
Tue, 30 Apr 2013 11:38:55 +0000 (13:38 +0200)
committerKlas Lindfors <klas@yubico.com>
Tue, 30 Apr 2013 11:38:55 +0000 (13:38 +0200)
also use those for import

ykpers-json.c
ykpers_lcl.c
ykpers_lcl.h

index d47f8f3c8a97c0eb96f54fc5096a8e7f7aebd167..232f7d5f874f6b7a2a176d172124153ce5071e2a 100644 (file)
@@ -219,6 +219,7 @@ int _ykp_json_import_cfg(YKP_CONFIG *cfg, const char *json, size_t len) {
                        }
                }
 
+
                if(mode == MODE_OATH_HOTP) {
                        json_object *jdigits = json_object_object_get(options, "oathDigits");
                        json_object *jrandom = json_object_object_get(options, "randomSeed");
@@ -253,9 +254,6 @@ int _ykp_json_import_cfg(YKP_CONFIG *cfg, const char *json, size_t len) {
                        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;
@@ -265,7 +263,7 @@ int _ykp_json_import_cfg(YKP_CONFIG *cfg, const char *json, size_t len) {
                                if(joption && json_object_get_type(joption) == json_type_boolean) {
                                        int value = json_object_get_boolean(joption);
                                        if(value == 1) {
-                                               ycfg.tktFlags |= p->flag;
+                                               p->setter(cfg, true);
                                        }
                                }
                        }
@@ -280,7 +278,7 @@ int _ykp_json_import_cfg(YKP_CONFIG *cfg, const char *json, size_t len) {
                                if(joption && json_object_get_type(joption) == json_type_boolean) {
                                        int value = json_object_get_boolean(joption);
                                        if(value == 1) {
-                                               ycfg.cfgFlags |= p->flag;
+                                               p->setter(cfg, true);
                                        }
                                }
                        }
@@ -295,14 +293,12 @@ int _ykp_json_import_cfg(YKP_CONFIG *cfg, const char *json, size_t len) {
                                if(joption && json_object_get_type(joption) == json_type_boolean) {
                                        int value = json_object_get_boolean(joption);
                                        if(value == 1) {
-                                               ycfg.extFlags |= p->flag;
+                                               p->setter(cfg, true);
                                        }
                                }
                        }
                }
 
-               /* copy in the ykcore config again */
-               cfg->ykcore_config = ycfg;
                ret_code = 1;
 out:
                if(jobj) {
index 1512929cb44d83fb0fb8d9bb450af1df1d22d200..20d75f25ad5b2640bba71f24ea3092ba07c84e9b 100644 (file)
 #include "ykpers_lcl.h"
 
 struct map_st _ticket_flags_map[] = {
-       { TKTFLAG_TAB_FIRST,    "TAB_FIRST",    "tabFirst",     capability_has_ticket_mods,     MODE_OUTPUT },
-       { TKTFLAG_APPEND_TAB1,  "APPEND_TAB1",  "tabBetween",   capability_has_ticket_mods,     MODE_OUTPUT },
-       { TKTFLAG_APPEND_TAB2,  "APPEND_TAB2",  "tabLast",      capability_has_ticket_mods,     MODE_OUTPUT },
-       { TKTFLAG_APPEND_DELAY1,"APPEND_DELAY1","appendDelay1", capability_has_ticket_mods,     MODE_OUTPUT },
-       { TKTFLAG_APPEND_DELAY2,"APPEND_DELAY2","appendDelay2", capability_has_ticket_mods,     MODE_OUTPUT },
-       { TKTFLAG_APPEND_CR,    "APPEND_CR",    "appendCR",     capability_has_ticket_mods,     MODE_OUTPUT },
-       { TKTFLAG_PROTECT_CFG2, "PROTEXT_CFG2", "protectSecond",capability_has_slot_two,        MODE_ALL },
-       { TKTFLAG_OATH_HOTP,    "OATH_HOTP",    0,              capability_has_oath,            MODE_OATH_HOTP },
-       { TKTFLAG_CHAL_RESP,    "CHAL_RESP",    0,              capability_has_chal_resp,       MODE_CHAL_RESP },
-       { 0, 0, 0, 0, 0 }
+       { TKTFLAG_TAB_FIRST,    "TAB_FIRST",    "tabFirst",     capability_has_ticket_mods,     MODE_OUTPUT,    ykp_set_tktflag_TAB_FIRST },
+       { TKTFLAG_APPEND_TAB1,  "APPEND_TAB1",  "tabBetween",   capability_has_ticket_mods,     MODE_OUTPUT,    ykp_set_tktflag_APPEND_TAB1 },
+       { TKTFLAG_APPEND_TAB2,  "APPEND_TAB2",  "tabLast",      capability_has_ticket_mods,     MODE_OUTPUT,    ykp_set_tktflag_APPEND_TAB2 },
+       { TKTFLAG_APPEND_DELAY1,"APPEND_DELAY1","appendDelay1", capability_has_ticket_mods,     MODE_OUTPUT,    ykp_set_tktflag_APPEND_DELAY1 },
+       { TKTFLAG_APPEND_DELAY2,"APPEND_DELAY2","appendDelay2", capability_has_ticket_mods,     MODE_OUTPUT,    ykp_set_tktflag_APPEND_DELAY2 },
+       { TKTFLAG_APPEND_CR,    "APPEND_CR",    "appendCR",     capability_has_ticket_mods,     MODE_OUTPUT,    ykp_set_tktflag_APPEND_CR },
+       { TKTFLAG_PROTECT_CFG2, "PROTECT_CFG2", "protectSecond",capability_has_slot_two,        MODE_ALL,       ykp_set_tktflag_PROTECT_CFG2 },
+       { TKTFLAG_OATH_HOTP,    "OATH_HOTP",    0,              capability_has_oath,            MODE_OATH_HOTP, ykp_set_tktflag_OATH_HOTP },
+       { TKTFLAG_CHAL_RESP,    "CHAL_RESP",    0,              capability_has_chal_resp,       MODE_CHAL_RESP, ykp_set_tktflag_CHAL_RESP },
+       { 0, 0, 0, 0, 0, 0 }
 };
 
 struct map_st _config_flags_map[] = {
-       { CFGFLAG_CHAL_YUBICO,          "CHAL_YUBICO",          0,              capability_has_chal_resp,       MODE_CHAL_YUBICO },
-       { CFGFLAG_CHAL_HMAC,            "CHAL_HMAC",            0,              capability_has_chal_resp,       MODE_CHAL_HMAC },
-       { CFGFLAG_HMAC_LT64,            "HMAC_LT64",            "hmacLt64",     capability_has_chal_resp,       MODE_CHAL_HMAC },
-       { CFGFLAG_CHAL_BTN_TRIG,        "CHAL_BTN_TRIG",        "buttonReqd",   capability_has_chal_resp,       MODE_CHAL_RESP },
-       { CFGFLAG_OATH_HOTP8,           "OATH_HOTP8",           0,              capability_has_oath,            MODE_OATH_HOTP },
-       { CFGFLAG_OATH_FIXED_MODHEX1,   "OATH_FIXED_MODHEX1",   0,              capability_has_oath,            MODE_OATH_HOTP },
-       { CFGFLAG_OATH_FIXED_MODHEX2,   "OATH_FIXED_MODHEX2",   0,              capability_has_oath,            MODE_OATH_HOTP },
-       { CFGFLAG_OATH_FIXED_MODHEX,    "OATH_FIXED_MODHEX",    0,              capability_has_oath,            MODE_OATH_HOTP },
-       { CFGFLAG_SEND_REF,             "SEND_REF",             "sendRef",      capability_has_ticket_mods,     MODE_OUTPUT },
-       { CFGFLAG_TICKET_FIRST,         "TICKET_FIRST",         0,              capability_has_ticket_mods,     MODE_OUTPUT },
-       { CFGFLAG_PACING_10MS,          "PACKING_10MS",         "pacing10ms",   capability_has_ticket_mods,     MODE_OUTPUT },
-       { CFGFLAG_PACING_20MS,          "PACING_20MS",          "pacing20ms",   capability_has_ticket_mods,     MODE_OUTPUT },
-       { CFGFLAG_ALLOW_HIDTRIG,        "ALLOW_HIDTRIG",        0,              capability_has_hidtrig,         MODE_OUTPUT },
-       { CFGFLAG_SHORT_TICKET,         "SHORT_TICKET",         "shortTicket",  capability_has_static_extras,   MODE_STATIC_TICKET },
-       { CFGFLAG_STRONG_PW1,           "STRONG_PW1",           "strongPw1",    capability_has_static_extras,   MODE_STATIC_TICKET },
-       { CFGFLAG_STRONG_PW2,           "STRONG_PW2",           "strongPw2",    capability_has_static_extras,   MODE_STATIC_TICKET },
-       { CFGFLAG_MAN_UPDATE,           "MAN_UPDATE",           "manUpdate",    capability_has_static_extras,   MODE_STATIC_TICKET },
-       { 0, 0, 0, 0, 0 }
+       { CFGFLAG_CHAL_YUBICO,          "CHAL_YUBICO",          0,              capability_has_chal_resp,       MODE_CHAL_YUBICO,       ykp_set_cfgflag_CHAL_YUBICO },
+       { CFGFLAG_CHAL_HMAC,            "CHAL_HMAC",            0,              capability_has_chal_resp,       MODE_CHAL_HMAC,         ykp_set_cfgflag_CHAL_HMAC },
+       { CFGFLAG_HMAC_LT64,            "HMAC_LT64",            "hmacLt64",     capability_has_chal_resp,       MODE_CHAL_HMAC,         ykp_set_cfgflag_HMAC_LT64 },
+       { CFGFLAG_CHAL_BTN_TRIG,        "CHAL_BTN_TRIG",        "buttonReqd",   capability_has_chal_resp,       MODE_CHAL_RESP,         ykp_set_cfgflag_CHAL_BTN_TRIG },
+       { CFGFLAG_OATH_HOTP8,           "OATH_HOTP8",           0,              capability_has_oath,            MODE_OATH_HOTP,         ykp_set_cfgflag_OATH_HOTP8 },
+       { CFGFLAG_OATH_FIXED_MODHEX1,   "OATH_FIXED_MODHEX1",   0,              capability_has_oath,            MODE_OATH_HOTP,         ykp_set_cfgflag_OATH_FIXED_MODHEX1 },
+       { CFGFLAG_OATH_FIXED_MODHEX2,   "OATH_FIXED_MODHEX2",   0,              capability_has_oath,            MODE_OATH_HOTP,         ykp_set_cfgflag_OATH_FIXED_MODHEX2 },
+       { CFGFLAG_OATH_FIXED_MODHEX,    "OATH_FIXED_MODHEX",    0,              capability_has_oath,            MODE_OATH_HOTP,         ykp_set_cfgflag_OATH_FIXED_MODHEX },
+       { CFGFLAG_SEND_REF,             "SEND_REF",             "sendRef",      capability_has_ticket_mods,     MODE_OUTPUT,            ykp_set_cfgflag_SEND_REF },
+       { CFGFLAG_TICKET_FIRST,         "TICKET_FIRST",         0,              capability_has_ticket_mods,     MODE_OUTPUT,            ykp_set_cfgflag_TICKET_FIRST },
+       { CFGFLAG_PACING_10MS,          "PACKING_10MS",         "pacing10ms",   capability_has_ticket_mods,     MODE_OUTPUT,            ykp_set_cfgflag_PACING_10MS },
+       { CFGFLAG_PACING_20MS,          "PACING_20MS",          "pacing20ms",   capability_has_ticket_mods,     MODE_OUTPUT,            ykp_set_cfgflag_PACING_20MS },
+       { CFGFLAG_ALLOW_HIDTRIG,        "ALLOW_HIDTRIG",        0,              capability_has_hidtrig,         MODE_OUTPUT,            ykp_set_cfgflag_ALLOW_HIDTRIG },
+       { CFGFLAG_SHORT_TICKET,         "SHORT_TICKET",         "shortTicket",  capability_has_static_extras,   MODE_STATIC_TICKET,     ykp_set_cfgflag_SHORT_TICKET },
+       { CFGFLAG_STRONG_PW1,           "STRONG_PW1",           "strongPw1",    capability_has_static_extras,   MODE_STATIC_TICKET,     ykp_set_cfgflag_STRONG_PW1 },
+       { CFGFLAG_STRONG_PW2,           "STRONG_PW2",           "strongPw2",    capability_has_static_extras,   MODE_STATIC_TICKET,     ykp_set_cfgflag_STRONG_PW2 },
+       { CFGFLAG_MAN_UPDATE,           "MAN_UPDATE",           "manUpdate",    capability_has_static_extras,   MODE_STATIC_TICKET,     ykp_set_cfgflag_MAN_UPDATE },
+       { 0, 0, 0, 0, 0, 0 }
 };
 
 struct map_st _extended_flags_map[] = {
-       { EXTFLAG_SERIAL_BTN_VISIBLE,   "SERIAL_BTN_VISIBLE",   "serialBtnVisible",     capability_has_serial,          MODE_ALL },
-       { EXTFLAG_SERIAL_USB_VISIBLE,   "SERIAL_USB_VISIBLE",   "serialUsbVisible",     capability_has_serial,          MODE_ALL },
-       { EXTFLAG_SERIAL_API_VISIBLE,   "SERIAL_API_VISIBLE",   "serialApiVisible",     capability_has_serial_api,      MODE_ALL },
-       { EXTFLAG_USE_NUMERIC_KEYPAD,   "USE_NUMERIC_KEYPAD",   "useNumericKeypad",     capability_has_numeric,         MODE_ALL },
-       { EXTFLAG_FAST_TRIG,            "FAST_TRIG",            "fastTrig",             capability_has_fast,            MODE_ALL },
-       { EXTFLAG_ALLOW_UPDATE,         "ALLOW_UPDATE",         "allowUpdate",          capability_has_update,          MODE_ALL },
-       { EXTFLAG_DORMANT,              "DORMANT",              "dormant",              capability_has_dormant,         MODE_ALL },
-       { EXTFLAG_LED_INV,              "LED_INV",              "ledInverted",          capability_has_led_inv,         MODE_ALL },
-       { 0, 0, 0, 0, 0 }
+       { EXTFLAG_SERIAL_BTN_VISIBLE,   "SERIAL_BTN_VISIBLE",   "serialBtnVisible",     capability_has_serial,          MODE_ALL,       ykp_set_extflag_SERIAL_BTN_VISIBLE },
+       { EXTFLAG_SERIAL_USB_VISIBLE,   "SERIAL_USB_VISIBLE",   "serialUsbVisible",     capability_has_serial,          MODE_ALL,       ykp_set_extflag_SERIAL_USB_VISIBLE },
+       { EXTFLAG_SERIAL_API_VISIBLE,   "SERIAL_API_VISIBLE",   "serialApiVisible",     capability_has_serial_api,      MODE_ALL,       ykp_set_extflag_SERIAL_API_VISIBLE },
+       { EXTFLAG_USE_NUMERIC_KEYPAD,   "USE_NUMERIC_KEYPAD",   "useNumericKeypad",     capability_has_numeric,         MODE_ALL,       ykp_set_extflag_USE_NUMERIC_KEYPAD },
+       { EXTFLAG_FAST_TRIG,            "FAST_TRIG",            "fastTrig",             capability_has_fast,            MODE_ALL,       ykp_set_extflag_FAST_TRIG },
+       { EXTFLAG_ALLOW_UPDATE,         "ALLOW_UPDATE",         "allowUpdate",          capability_has_update,          MODE_ALL,       ykp_set_extflag_ALLOW_UPDATE },
+       { EXTFLAG_DORMANT,              "DORMANT",              "dormant",              capability_has_dormant,         MODE_ALL,       ykp_set_extflag_DORMANT },
+       { EXTFLAG_LED_INV,              "LED_INV",              "ledInverted",          capability_has_led_inv,         MODE_ALL,       ykp_set_extflag_LED_INV },
+       { 0, 0, 0, 0, 0, 0 }
 };
 
 
 struct map_st _modes_map[] = {
-       { MODE_OATH_HOTP,       0,      "oathHOTP",     0, 0 },
-       { MODE_CHAL_HMAC,       0,      "hmacCR",       0, 0 },
-       { MODE_STATIC_TICKET,   0,      "staticTicket", 0, 0 },
-       { MODE_CHAL_YUBICO,     0,      "yubicoCR",     0, 0 },
-       { MODE_OTP_YUBICO,      0,      "yubicoOTP",    0, 0 },
-       { 0, 0, 0, 0, 0 }
+       { MODE_OATH_HOTP,       0,      "oathHOTP",     0, 0, 0 },
+       { MODE_CHAL_HMAC,       0,      "hmacCR",       0, 0, 0 },
+       { MODE_STATIC_TICKET,   0,      "staticTicket", 0, 0, 0 },
+       { MODE_CHAL_YUBICO,     0,      "yubicoCR",     0, 0, 0 },
+       { MODE_OTP_YUBICO,      0,      "yubicoOTP",    0, 0, 0 },
+       { 0, 0, 0, 0, 0, 0 }
 };
index fd531c4ec8f04f50d94eb0cf99fb2b482cbd2d0e..228260b1b8669567071485f2b842632d7428de17 100644 (file)
@@ -70,6 +70,7 @@ struct map_st {
        const char *json_text;
        bool (*capability)(const YKP_CONFIG *cfg);
        unsigned char mode;
+       int (*setter)(YKP_CONFIG *cfg, bool state);
 };
 
 extern struct map_st _ticket_flags_map[];