From be5bc5cb16e676a091e8192368247f1b7fadf992 Mon Sep 17 00:00:00 2001 From: Klas Lindfors Date: Tue, 27 Mar 2012 13:48:46 +0200 Subject: [PATCH] add -x option for swapping configurations --- ykpers-args.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/ykpers-args.c b/ykpers-args.c index 85ad4ae..2d238a2 100644 --- a/ykpers-args.c +++ b/ykpers-args.c @@ -50,6 +50,8 @@ const char *usage = " In this configuration, TKTFLAG_APPEND_CR, CFGFLAG_STATIC_TICKET,\n" " CFGFLAG_STRONG_PW1, CFGFLAG_STRONG_PW2 and CFGFLAG_MAN_UPDATE\n" " are set by default.\n" +"-x swap the configuration in slot 1 and 2. This is for YubiKey 2.3\n" +" and newer only\n" "-sFILE save configuration to FILE instead of key.\n" " (if FILE is -, send to stdout)\n" "-iFILE read configuration from FILE.\n" @@ -125,7 +127,7 @@ const char *usage = "-v verbose\n" "-h help (this text)\n" ; -const char *optstring = "12a:c:hi:o:s:vy"; +const char *optstring = "12xa:c:hi:o:s:vy"; static int hex_modhex_decode(unsigned char *result, size_t *resultlen, const char *str, size_t strl, @@ -203,6 +205,7 @@ int args_to_config(int argc, char **argv, YKP_CONFIG *cfg, bool slot_chosen = false; bool mode_chosen = false; bool option_seen = false; + bool swap_seen = false; struct config_st *ycfg = (struct config_st *) ykp_core_config(cfg); @@ -256,11 +259,32 @@ int args_to_config(int argc, char **argv, YKP_CONFIG *cfg, *exit_code = 1; return 0; } + if (swap_seen) { + fprintf(stderr, "You can not combine slot swap (-x) with configuring a slot.\n"); + *exit_code = 1; + return 0; + } if (!ykp_configure_for(cfg, slot, st)) return 0; slot_chosen = true; break; } + case 'x': + if (slot_chosen) { + fprintf(stderr, "You can not use slot swap with a chosen slot (-1 / -2).\n"); + *exit_code = 1; + return 0; + } + if (option_seen) { + fprintf(stderr, "You must set slot swap before any options (-o).\n"); + *exit_code = 1; + return 0; + } + if (!ykp_configure_command(cfg, SLOT_SWAP, st)) { + return 0; + } + swap_seen = true; + break; case 'i': *infname = optarg; break; -- 2.39.5