From: Klas Lindfors Date: Thu, 25 Apr 2013 09:21:05 +0000 (+0200) Subject: implement dry-run for the cli X-Git-Tag: v1.14.0~18 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e0cea62384d8993498dcacc6f608c548161a3c1;p=yubikey-personalization implement dry-run for the cli --- diff --git a/tests/test_args_to_config.c b/tests/test_args_to_config.c index 62a5ba6..97169b4 100644 --- a/tests/test_args_to_config.c +++ b/tests/test_args_to_config.c @@ -104,6 +104,7 @@ int _test_config (YKP_CONFIG *cfg, YK_STATUS *st, int argc, char **argv) const char *infname = NULL; const char *outfname = NULL; bool verbose = false; + bool dry_run = false; bool aesviahash = false; bool use_access_code = false; unsigned char access_code[256]; @@ -140,7 +141,7 @@ int _test_config (YKP_CONFIG *cfg, YK_STATUS *st, int argc, char **argv) &infname, &outfname, &data_format, &autocommit, salt, - st, &verbose, + st, &verbose, &dry_run, access_code, &use_access_code, &aesviahash, &ndef_type, ndef, &usb_mode, &zap, scan_map, &exit_code); @@ -292,6 +293,7 @@ int _test_non_config_args(void) const char *infname = NULL; const char *outfname = NULL; bool verbose = false; + bool dry_run = false; bool aesviahash = false; bool use_access_code = false; unsigned char access_code[256]; @@ -334,7 +336,7 @@ int _test_non_config_args(void) &infname, &outfname, &data_format, &autocommit, salt, - st, &verbose, + st, &verbose, &dry_run, access_code, &use_access_code, &aesviahash, &ndef_type, ndef, &usb_mode, &zap, scan_map, &exit_code); diff --git a/ykpers-args.c b/ykpers-args.c index 7ed0a49..4c5d4e0 100644 --- a/ykpers-args.c +++ b/ykpers-args.c @@ -154,10 +154,12 @@ const char *usage = "\n" "-y always commit (do not prompt)\n" "\n" +"-d dry-run (don't write anything to key)\n" +"\n" "-v verbose\n" "-h help (this text)\n" ; -const char *optstring = "u12xza:c:n:t:hi:o:s:f:vym:S::"; +const char *optstring = "u12xza:c:n:t:hi:o:s:f:dvym:S::"; static int _set_fixed(char *opt, YKP_CONFIG *cfg); static int _format_decimal_as_hex(uint8_t *dst, size_t dst_len, uint8_t *src); @@ -230,7 +232,7 @@ int args_to_config(int argc, char **argv, YKP_CONFIG *cfg, YK_KEY *yk, const char **infname, const char **outfname, int *data_format, bool *autocommit, char *salt, - YK_STATUS *st, bool *verbose, + YK_STATUS *st, bool *verbose, bool *dry_run, unsigned char *access_code, bool *use_access_code, bool *aesviahash, char *ndef_type, char *ndef, unsigned char *usb_mode, bool *zap, @@ -666,6 +668,9 @@ int args_to_config(int argc, char **argv, YKP_CONFIG *cfg, YK_KEY *yk, return 0; } break; + case 'd': + *dry_run = true; + break; case 'v': *verbose = true; break; diff --git a/ykpers-args.h b/ykpers-args.h index a0aadee..61e8c70 100644 --- a/ykpers-args.h +++ b/ykpers-args.h @@ -37,7 +37,7 @@ int args_to_config(int argc, char **argv, YKP_CONFIG *cfg, YK_KEY *yk, const char **infname, const char **outfname, int *data_format, bool *autocommit, char *salt, - YK_STATUS *st, bool *verbose, + YK_STATUS *st, bool *verbose, bool *dry_run, unsigned char *access_code, bool *use_access_code, bool *aesviahash, char *ndef_type, char *ndef, unsigned char *usb_mode, bool *zap, unsigned char *scan_bin, int *exit_code); diff --git a/ykpersonalize.1 b/ykpersonalize.1 index 8b7fced..e643b08 100644 --- a/ykpersonalize.1 +++ b/ykpersonalize.1 @@ -37,7 +37,7 @@ ykpersonalize - personalize YubiKey OTP tokens .SH SYNOPSIS .B ykpersonalize [\fI-1\fR | \fI-2\fR] [\fI-sfile\fR] [\fI-ifile\fR] [\fI-fformat\fR] [\fI-axxx\fR] [\fI-cxxx\fR] -[\fI-ooption\fR] [\fI-y\fR] [\fI-v\fR] [\fI-h\fR] [\fI-n\fR] [\fI-t\fR] [\fI-u\fR] [\fI-x\fR] +[\fI-ooption\fR] [\fI-y\fR] [\fI-v\fR] [\fI-d\fR] [\fI-h\fR] [\fI-n\fR] [\fI-t\fR] [\fI-u\fR] [\fI-x\fR] [\fI-z\fR] [\fI-m\fR] [\fI-S\fR] .\".SH DESCRIPTION .\" Add any additional description here @@ -124,6 +124,9 @@ Set/clear ticket flag, see the section `Configuration flags\&' \fB-y\fR always commit without prompting .TP +\fB-d\fR +dry-run, run without writing a YubiKey +.TP \fB-v\fR Be more verbose .TP diff --git a/ykpersonalize.c b/ykpersonalize.c index 16f2733..e4c3fb2 100644 --- a/ykpersonalize.c +++ b/ykpersonalize.c @@ -56,6 +56,7 @@ int main(int argc, char **argv) YK_STATUS *st = ykds_alloc(); bool autocommit = false; char data[1024]; + bool dry_run = false; /* Options */ char *salt = NULL; @@ -121,7 +122,7 @@ int main(int argc, char **argv) &infname, &outfname, &data_format, &autocommit, salt, - st, &verbose, + st, &verbose, &dry_run, access_code, &use_access_code, &aesviahash, &ndef_type, ndef_string, &usb_mode, &zap, scan_codes, &exit_code)) { @@ -246,7 +247,10 @@ int main(int argc, char **argv) if (verbose) printf("Attempting to write configuration to the yubikey..."); - if(ykp_command(cfg) == SLOT_NDEF || ykp_command(cfg) == SLOT_NDEF2) { + if (dry_run) { + printf("Not writing anything to key due to dry_run requested.\n"); + } + else if(ykp_command(cfg) == SLOT_NDEF || ykp_command(cfg) == SLOT_NDEF2) { YK_NDEF *ndef = ykp_alloc_ndef(); int confnum = 1; if(ndef_type == 'U') { @@ -298,7 +302,7 @@ int main(int argc, char **argv) } } - if (verbose) + if (verbose && !dry_run) printf(" success\n"); } }