From: Fredrik Thulin Date: Tue, 21 Dec 2010 22:08:17 +0000 (+0100) Subject: Check return value of ykp_set_(cfg|tkt)flag. X-Git-Tag: v1.4.0~26 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9809b046329c731e2eae2ac1cff34934736305be;p=yubikey-personalization.old Check return value of ykp_set_(cfg|tkt)flag. Wrong Yubikey version errors were concealed (and flags just dropped) : $ ./ykpersonalize -ooath-hotp8 -s- Firmware version 1.3.2 Touch level 7104 Program sequence 1 ... ticket_flags: APPEND_CR config_flags: $ With this patch : $ ./ykpersonalize -ooath-hotp8 -s- Firmware version 1.3.2 Touch level 7440 Program sequence 4 Yubikey personalization error: option not available for this Yubikey version $ --- diff --git a/ykpersonalize.c b/ykpersonalize.c index 6b60df7..c46774d 100644 --- a/ykpersonalize.c +++ b/ykpersonalize.c @@ -340,40 +340,50 @@ int main(int argc, char **argv) ykp_set_access_code(cfg, accbin, accbinlen); new_access_code = true; } -#define TKTFLAG(o, f) \ - else if (strcmp(optarg, o) == 0) \ - ykp_set_tktflag_##f(cfg, true); \ - else if (strcmp(optarg, "-" o) == 0) \ - ykp_set_tktflag_##f(cfg, false) - TKTFLAG("tab-first", TAB_FIRST); - TKTFLAG("append-tab1", APPEND_TAB1); - TKTFLAG("append-tab2", APPEND_TAB2); - TKTFLAG("append-delay1", APPEND_DELAY1); - TKTFLAG("append-delay2", APPEND_DELAY2); - TKTFLAG("append-cr", APPEND_CR); - TKTFLAG("protect-cfg2", PROTECT_CFG2); - TKTFLAG("oath-hotp", OATH_HOTP); +#define TKTFLAG(o, f) \ + else if (strcmp(optarg, o) == 0) { \ + if (!ykp_set_tktflag_##f(cfg, true)) \ + exit_code = 1; \ + goto err; \ + } else if (strcmp(optarg, "-" o) == 0) { \ + if (! ykp_set_tktflag_##f(cfg, false)) \ + exit_code = 1; \ + goto err; \ + } + TKTFLAG("tab-first", TAB_FIRST) + TKTFLAG("append-tab1", APPEND_TAB1) + TKTFLAG("append-tab2", APPEND_TAB2) + TKTFLAG("append-delay1", APPEND_DELAY1) + TKTFLAG("append-delay2", APPEND_DELAY2) + TKTFLAG("append-cr", APPEND_CR) + TKTFLAG("protect-cfg2", PROTECT_CFG2) + TKTFLAG("oath-hotp", OATH_HOTP) #undef TKTFLAG -#define CFGFLAG(o, f) \ - else if (strcmp(optarg, o) == 0) \ - ykp_set_cfgflag_##f(cfg, true); \ - else if (strcmp(optarg, "-" o) == 0) \ - ykp_set_cfgflag_##f(cfg, false) - CFGFLAG("send-ref", SEND_REF); - CFGFLAG("ticket-first", TICKET_FIRST); - CFGFLAG("pacing-10ms", PACING_10MS); - CFGFLAG("pacing-20ms", PACING_20MS); - CFGFLAG("allow-hidtrig", ALLOW_HIDTRIG); - CFGFLAG("static-ticket", STATIC_TICKET); - CFGFLAG("short-ticket", SHORT_TICKET); - CFGFLAG("strong-pw1", STRONG_PW1); - CFGFLAG("strong-pw2", STRONG_PW2); - CFGFLAG("man-update", MAN_UPDATE); - CFGFLAG("oath-hotp8", OATH_HOTP8); - CFGFLAG("oath-fixed-modhex1", OATH_FIXED_MODHEX1); - CFGFLAG("oath-fixed-modhex2", OATH_FIXED_MODHEX2); - CFGFLAG("oath-fixed-modhex", OATH_FIXED_MODHEX); +#define CFGFLAG(o, f) \ + else if (strcmp(optarg, o) == 0) { \ + if (! ykp_set_cfgflag_##f(cfg, true)) \ + exit_code = 1; \ + goto err; \ + } else if (strcmp(optarg, "-" o) == 0) { \ + if (! ykp_set_cfgflag_##f(cfg, false)) \ + exit_code = 1; \ + goto err; \ + } + CFGFLAG("send-ref", SEND_REF) + CFGFLAG("ticket-first", TICKET_FIRST) + CFGFLAG("pacing-10ms", PACING_10MS) + CFGFLAG("pacing-20ms", PACING_20MS) + CFGFLAG("allow-hidtrig", ALLOW_HIDTRIG) + CFGFLAG("static-ticket", STATIC_TICKET) + CFGFLAG("short-ticket", SHORT_TICKET) + CFGFLAG("strong-pw1", STRONG_PW1) + CFGFLAG("strong-pw2", STRONG_PW2) + CFGFLAG("man-update", MAN_UPDATE) + CFGFLAG("oath-hotp8", OATH_HOTP8) + CFGFLAG("oath-fixed-modhex1", OATH_FIXED_MODHEX1) + CFGFLAG("oath-fixed-modhex2", OATH_FIXED_MODHEX2) + CFGFLAG("oath-fixed-modhex", OATH_FIXED_MODHEX) #undef CFGFLAG else { fprintf(stderr, "Unknown option '%s'\n",