From efa464c6f71d16f278e0128776da7fcb54595c02 Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Tue, 27 Feb 2024 14:09:34 +0100 Subject: [PATCH 01/10] pkcs11-register: Chrome supports native crypto modules like Firefox --- src/tools/pkcs11-register.ggo.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/pkcs11-register.ggo.in b/src/tools/pkcs11-register.ggo.in index 7d463536cb..39f44c48a7 100644 --- a/src/tools/pkcs11-register.ggo.in +++ b/src/tools/pkcs11-register.ggo.in @@ -8,7 +8,7 @@ option "module" m option "skip-chrome" - "Don't install module to Chrome" - flag off + flag @PKCS11_REGISTER_SKIP_FIREFOX@ option "skip-firefox" - "Don't install module to Firefox" From 6abfbd816c1842326a04d9ce06f1a0263e2f326d Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Tue, 27 Feb 2024 14:29:30 +0100 Subject: [PATCH 02/10] include .dirstamp in gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c701372e60..26bede4f18 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ tags test-driver .deps .libs +.dirstamp .#*# .*.bak .*.orig From 1664609266420b54cec15f4dd88400c969dc0c7b Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Wed, 28 Feb 2024 10:57:37 +0100 Subject: [PATCH 03/10] pkcs11-register: don't adapt Firefox/Chrome by default The source code files for command line interface of pkcs11-register are switched to macOS/Windows defaults in case of adapting the configuration of the browsers. Setting up gengetopt as requirement in Linux is much easier. Also regenerates command line files for all other tools. --- src/tools/egk-tool-cmdline.c | 2 +- src/tools/goid-tool-cmdline.c | 286 ++++++++++++++-------------- src/tools/npa-tool-cmdline.c | 2 +- src/tools/opensc-asn1-cmdline.c | 2 +- src/tools/opensc-notify-cmdline.c | 2 +- src/tools/pkcs11-register-cmdline.c | 10 +- src/tools/pkcs11-register-cmdline.h | 4 +- 7 files changed, 154 insertions(+), 154 deletions(-) diff --git a/src/tools/egk-tool-cmdline.c b/src/tools/egk-tool-cmdline.c index 636c07690a..305b5691d2 100644 --- a/src/tools/egk-tool-cmdline.c +++ b/src/tools/egk-tool-cmdline.c @@ -1,7 +1,7 @@ /* File autogenerated by gengetopt version 2.23 generated with the following command: - /usr/bin/gengetopt --file-name=egk-tool-cmdline --output-dir=. + /opt/homebrew/bin/gengetopt --file-name=egk-tool-cmdline --output-dir=. The developers of gengetopt consider the fixed text that goes in all gengetopt output files to be in the public domain: diff --git a/src/tools/goid-tool-cmdline.c b/src/tools/goid-tool-cmdline.c index 1836678a7f..fe89bb7252 100644 --- a/src/tools/goid-tool-cmdline.c +++ b/src/tools/goid-tool-cmdline.c @@ -1,7 +1,7 @@ /* File autogenerated by gengetopt version 2.23 generated with the following command: - /usr/bin/gengetopt --file-name=goid-tool-cmdline --output-dir=. + /opt/homebrew/bin/gengetopt --file-name=goid-tool-cmdline --output-dir=. The developers of gengetopt consider the fixed text that goes in all gengetopt output files to be in the public domain: @@ -61,9 +61,9 @@ const char *gengetopt_args_info_help[] = { " --create-dg=ID Create the specified data group; use several\n times to create multiple files", " --new-size=SIZE File size of newly created DGs (default=`256')", " --new-read-ac=STRING Access condition for reading newly created DGs\n (possible values=\"always\", \"never\",\n \"ta\", \"sm\" default=`sm')", - " --new-read-ac-chatbit=INDEX\n Required access bits in certificate's CHAT for\n reading newly created DGs", + " --new-read-ac-chatbit=INDEX\n Required access bit in certificate's CHAT for\n reading newly created DGs", " --new-write-ac=STRING Access condition for writing newly created DGs\n (possible values=\"always\", \"never\",\n \"ta\", \"sm\" default=`sm')", - " --new-write-ac-chatbit=INDEX\n Required access bits in certificate's CHAT for\n reading newly created DGs", + " --new-write-ac-chatbit=INDEX\n Required access bit in certificate's CHAT for\n reading newly created DGs", 0 }; @@ -160,7 +160,7 @@ void clear_args (struct gengetopt_args_info *args_info) args_info->new_write_ac_orig = NULL; args_info->new_write_ac_chatbit_arg = NULL; args_info->new_write_ac_chatbit_orig = NULL; - + } static @@ -217,7 +217,7 @@ void init_args_info(struct gengetopt_args_info *args_info) args_info->new_write_ac_chatbit_help = gengetopt_args_info_help[29] ; args_info->new_write_ac_chatbit_min = 0; args_info->new_write_ac_chatbit_max = 0; - + } void @@ -273,7 +273,7 @@ void cmdline_parser_params_init(struct cmdline_parser_params *params) { if (params) - { + { params->override = 0; params->initialize = 1; params->check_required = 1; @@ -285,9 +285,9 @@ cmdline_parser_params_init(struct cmdline_parser_params *params) struct cmdline_parser_params * cmdline_parser_params_create(void) { - struct cmdline_parser_params *params = + struct cmdline_parser_params *params = (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); - cmdline_parser_params_init(params); + cmdline_parser_params_init(params); return params; } @@ -317,7 +317,7 @@ struct generic_list }; /** - * @brief add a node at the head of the list + * @brief add a node at the head of the list */ static void add_node(struct generic_list **list) { struct generic_list *new_node = (struct generic_list *) malloc (sizeof (struct generic_list)); @@ -397,8 +397,8 @@ cmdline_parser_release (struct gengetopt_args_info *args_info) free_string_field (&(args_info->new_write_ac_orig)); free_multiple_field (args_info->new_write_ac_chatbit_given, (void *)(args_info->new_write_ac_chatbit_arg), &(args_info->new_write_ac_chatbit_orig)); args_info->new_write_ac_chatbit_arg = 0; - - + + clear_given (args_info); } @@ -428,7 +428,7 @@ check_possible_values(const char *val, const char *values[]) ++found; last = i; if (strlen(values[i]) == len) - return i; /* exact match no need to check more */ + return i; /* exact macth no need to check more */ } } @@ -445,7 +445,7 @@ write_into_file(FILE *outfile, const char *opt, const char *arg, const char *val int found = -1; if (arg) { if (values) { - found = check_possible_values(arg, values); + found = check_possible_values(arg, values); } if (found >= 0) fprintf(outfile, "%s=\"%s\" # %s\n", opt, arg, values[found]); @@ -460,7 +460,7 @@ static void write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, const char *values[]) { int i; - + for (i = 0; i < len; ++i) write_into_file(outfile, opt, (arg ? arg[i] : 0), values); } @@ -519,7 +519,7 @@ cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) if (args_info->new_write_ac_given) write_into_file(outfile, "new-write-ac", args_info->new_write_ac_orig, cmdline_parser_new_write_ac_values); write_multiple_into_file(outfile, args_info->new_write_ac_chatbit_given, "new-write-ac-chatbit", args_info->new_write_ac_chatbit_orig, 0); - + i = EXIT_SUCCESS; return i; @@ -605,8 +605,8 @@ get_multiple_arg_token(const char *arg) j = 0; while (arg[i] && (j < len-1)) { - if (arg[i] == '\\' && - arg[ i + 1 ] && + if (arg[i] == '\\' && + arg[ i + 1 ] && arg[ i + 1 ] == ',') ++i; @@ -698,7 +698,7 @@ check_multiple_option_occurrences(const char *prog_name, unsigned int option_giv } } } - + return error_occurred; } int @@ -719,7 +719,7 @@ cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info cmdline_parser_free (args_info); exit (EXIT_FAILURE); } - + return result; } @@ -728,7 +728,7 @@ cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, i { int result; struct cmdline_parser_params params; - + params.override = override; params.initialize = initialize; params.check_required = check_required; @@ -742,7 +742,7 @@ cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, i cmdline_parser_free (args_info); exit (EXIT_FAILURE); } - + return result; } @@ -759,7 +759,7 @@ cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog cmdline_parser_free (args_info); exit (EXIT_FAILURE); } - + return result; } @@ -772,38 +772,38 @@ cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *pro /* checks for required options */ if (check_multiple_option_occurrences(prog_name, args_info->verbose_given, args_info->verbose_min, args_info->verbose_max, "'--verbose' ('-v')")) error_occurred = 1; - + if (args_info->soc_mode_counter && check_multiple_option_occurrences(prog_name, args_info->new_bio_given, args_info->new_bio_min, args_info->new_bio_max, "'--new-bio'")) error_occurred = 1; - + if (args_info->pxs_mode_counter && check_multiple_option_occurrences(prog_name, args_info->certificate_given, args_info->certificate_min, args_info->certificate_max, "'--certificate' ('-c')")) error_occurred = 1; - + if (args_info->pxs_mode_counter && check_multiple_option_occurrences(prog_name, args_info->read_dg_given, args_info->read_dg_min, args_info->read_dg_max, "'--read-dg'")) error_occurred = 1; - + if (args_info->pxs_mode_counter && check_multiple_option_occurrences(prog_name, args_info->out_file_given, args_info->out_file_min, args_info->out_file_max, "'--out-file'")) error_occurred = 1; - + if (args_info->pxs_mode_counter && check_multiple_option_occurrences(prog_name, args_info->write_dg_given, args_info->write_dg_min, args_info->write_dg_max, "'--write-dg'")) error_occurred = 1; - + if (args_info->pxs_mode_counter && check_multiple_option_occurrences(prog_name, args_info->in_file_given, args_info->in_file_min, args_info->in_file_max, "'--in-file'")) error_occurred = 1; - + if (args_info->pxs_mode_counter && check_multiple_option_occurrences(prog_name, args_info->delete_dg_given, args_info->delete_dg_min, args_info->delete_dg_max, "'--delete-dg'")) error_occurred = 1; - + if (args_info->pxs_mode_counter && check_multiple_option_occurrences(prog_name, args_info->create_dg_given, args_info->create_dg_min, args_info->create_dg_max, "'--create-dg'")) error_occurred = 1; - + if (args_info->pxs_mode_counter && check_multiple_option_occurrences(prog_name, args_info->new_read_ac_chatbit_given, args_info->new_read_ac_chatbit_min, args_info->new_read_ac_chatbit_max, "'--new-read-ac-chatbit'")) error_occurred = 1; - + if (args_info->pxs_mode_counter && check_multiple_option_occurrences(prog_name, args_info->new_write_ac_chatbit_given, args_info->new_write_ac_chatbit_min, args_info->new_write_ac_chatbit_max, "'--new-write-ac-chatbit'")) error_occurred = 1; - - + + /* checks for dependences among options */ if (args_info->certificate_given && ! args_info->key_given) { @@ -867,7 +867,7 @@ static char *package_name = 0; */ static int update_arg(void *field, char **orig_field, - unsigned int *field_given, unsigned int *prev_given, + unsigned int *field_given, unsigned int *prev_given, char *value, const char *possible_values[], const char *default_value, cmdline_parser_arg_type arg_type, @@ -888,11 +888,11 @@ int update_arg(void *field, char **orig_field, if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) { if (short_opt != '-') - fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", + fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", package_name, long_opt, short_opt, (additional_error ? additional_error : "")); else - fprintf (stderr, "%s: `--%s' option given more than once%s\n", + fprintf (stderr, "%s: `--%s' option given more than once%s\n", package_name, long_opt, (additional_error ? additional_error : "")); return 1; /* failure */ @@ -901,16 +901,16 @@ int update_arg(void *field, char **orig_field, if (possible_values && (found = check_possible_values((value ? value : default_value), possible_values)) < 0) { if (short_opt != '-') - fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s' (`-%c')%s\n", + fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s' (`-%c')%s\n", package_name, (found == -2) ? "ambiguous" : "invalid", value, long_opt, short_opt, (additional_error ? additional_error : "")); else - fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s'%s\n", + fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s'%s\n", package_name, (found == -2) ? "ambiguous" : "invalid", value, long_opt, (additional_error ? additional_error : "")); return 1; /* failure */ } - + if (field_given && *field_given && ! override) return 0; if (prev_given) @@ -995,7 +995,7 @@ int update_multiple_arg_temp(struct generic_list **list, { add_node (list); if (update_arg((void *)&((*list)->arg), &((*list)->orig), 0, - prev_given, multi_token, possible_values, default_value, + prev_given, multi_token, possible_values, default_value, arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) { if (multi_token) free(multi_token); return 1; /* failure */ @@ -1057,11 +1057,11 @@ void update_multiple_arg(void *field, char ***orig_field, default: break; }; - + for (i = (prev_given - 1); i >= 0; --i) { tmp = list; - + switch(arg_type) { case ARG_INT: (*((int **)field))[i + field_given] = tmp->arg.int_arg; break; @@ -1069,7 +1069,7 @@ void update_multiple_arg(void *field, char ***orig_field, (*((char ***)field))[i + field_given] = tmp->arg.string_arg; break; default: break; - } + } (*orig_field) [i + field_given] = list->orig; list = list->next; free (tmp); @@ -1080,7 +1080,7 @@ void update_multiple_arg(void *field, char ***orig_field, case ARG_INT: if (! *((int **)field)) { *((int **)field) = (int *)malloc (sizeof (int)); - (*((int **)field))[0] = default_value->int_arg; + (*((int **)field))[0] = default_value->int_arg; } break; case ARG_STRING: @@ -1104,7 +1104,7 @@ static int check_modes( int given2[], const char *options2[]) { int i = 0, j = 0, errors = 0; - + while (given1[i] >= 0) { if (given1[i]) { while (given2[j] >= 0) { @@ -1118,7 +1118,7 @@ static int check_modes( } ++i; } - + return errors; } @@ -1140,14 +1140,14 @@ cmdline_parser_internal ( struct generic_list * new_write_ac_chatbit_list = NULL; int error_occurred = 0; struct gengetopt_args_info local_args_info; - + int override; int initialize; int check_required; int check_ambiguity; - + package_name = argv[0]; - + /* TODO: Why is this here? It is not used anywhere. */ override = params->override; FIX_UNUSED(override); @@ -1221,325 +1221,325 @@ cmdline_parser_internal ( exit (EXIT_SUCCESS); case 'r': /* Number of the reader to use. By default, the first reader with a present card is used. If the argument is an ATR, the reader with a matching card will be chosen.. */ - - - if (update_arg( (void *)&(args_info->reader_arg), + + + if (update_arg( (void *)&(args_info->reader_arg), &(args_info->reader_orig), &(args_info->reader_given), &(local_args_info.reader_given), optarg, 0, 0, ARG_STRING, check_ambiguity, override, 0, 0, "reader", 'r', additional_error)) goto failure; - + break; case 'v': /* Use (several times) to be more verbose. */ - + local_args_info.verbose_given++; - + break; case 'p': /* Verify PIN. */ - - - if (update_arg( 0 , + + + if (update_arg( 0 , 0 , &(args_info->verify_pin_given), &(local_args_info.verify_pin_given), optarg, 0, 0, ARG_NO, check_ambiguity, override, 0, 0, "verify-pin", 'p', additional_error)) goto failure; - + break; case 'b': /* Verify finger print. */ - - - if (update_arg( 0 , + + + if (update_arg( 0 , 0 , &(args_info->verify_bio_given), &(local_args_info.verify_bio_given), optarg, 0, 0, ARG_NO, check_ambiguity, override, 0, 0, "verify-bio", 'b', additional_error)) goto failure; - + break; case 'c': /* Use (several times) to pass CV certificates. */ args_info->pxs_mode_counter += 1; - - if (update_multiple_arg_temp(&certificate_list, + + if (update_multiple_arg_temp(&certificate_list, &(local_args_info.certificate_given), optarg, 0, 0, ARG_STRING, "certificate", 'c', additional_error)) goto failure; - + break; case 'k': /* Private key for the CV certificate. */ args_info->pxs_mode_counter += 1; - - - if (update_arg( (void *)&(args_info->key_arg), + + + if (update_arg( (void *)&(args_info->key_arg), &(args_info->key_orig), &(args_info->key_given), &(local_args_info.key_given), optarg, 0, 0, ARG_STRING, check_ambiguity, override, 0, 0, "key", 'k', additional_error)) goto failure; - + break; case 0: /* Long option with no short option */ /* Verify PIN or finger print (user's choice). */ if (strcmp (long_options[option_index].name, "verify-pin-or-bio") == 0) { - - - if (update_arg( 0 , + + + if (update_arg( 0 , 0 , &(args_info->verify_pin_or_bio_given), &(local_args_info.verify_pin_or_bio_given), optarg, 0, 0, ARG_NO, check_ambiguity, override, 0, 0, "verify-pin-or-bio", '-', additional_error)) goto failure; - + } /* Change PIN. */ else if (strcmp (long_options[option_index].name, "new-pin") == 0) { args_info->soc_mode_counter += 1; - - - if (update_arg( 0 , + + + if (update_arg( 0 , 0 , &(args_info->new_pin_given), &(local_args_info.new_pin_given), optarg, 0, 0, ARG_NO, check_ambiguity, override, 0, 0, "new-pin", '-', additional_error)) goto failure; - + } /* Use (several times) to change one or more biometric templates. */ else if (strcmp (long_options[option_index].name, "new-bio") == 0) { args_info->soc_mode_counter += 1; - + local_args_info.new_bio_given++; - + } /* Dump Information about the SoCManager's configuration. */ else if (strcmp (long_options[option_index].name, "info") == 0) { args_info->soc_mode_counter += 1; - - - if (update_arg( 0 , + + + if (update_arg( 0 , 0 , &(args_info->info_given), &(local_args_info.info_given), optarg, 0, 0, ARG_NO, check_ambiguity, override, 0, 0, "info", '-', additional_error)) goto failure; - + } /* Print the card ID. */ else if (strcmp (long_options[option_index].name, "print-cardid") == 0) { args_info->pxs_mode_counter += 1; - - - if (update_arg( 0 , + + + if (update_arg( 0 , 0 , &(args_info->print_cardid_given), &(local_args_info.print_cardid_given), optarg, 0, 0, ARG_NO, check_ambiguity, override, 0, 0, "print-cardid", '-', additional_error)) goto failure; - + } /* Write the specified card ID. */ else if (strcmp (long_options[option_index].name, "write-cardid") == 0) { args_info->pxs_mode_counter += 1; - - - if (update_arg( (void *)&(args_info->write_cardid_arg), + + + if (update_arg( (void *)&(args_info->write_cardid_arg), &(args_info->write_cardid_orig), &(args_info->write_cardid_given), &(local_args_info.write_cardid_given), optarg, 0, 0, ARG_STRING, check_ambiguity, override, 0, 0, "write-cardid", '-', additional_error)) goto failure; - + } /* Print the PAccess ID. */ else if (strcmp (long_options[option_index].name, "print-paccessid") == 0) { args_info->pxs_mode_counter += 1; - - - if (update_arg( 0 , + + + if (update_arg( 0 , 0 , &(args_info->print_paccessid_given), &(local_args_info.print_paccessid_given), optarg, 0, 0, ARG_NO, check_ambiguity, override, 0, 0, "print-paccessid", '-', additional_error)) goto failure; - + } /* Write the specified PAccess ID. */ else if (strcmp (long_options[option_index].name, "write-paccessid") == 0) { args_info->pxs_mode_counter += 1; - - - if (update_arg( (void *)&(args_info->write_paccessid_arg), + + + if (update_arg( (void *)&(args_info->write_paccessid_arg), &(args_info->write_paccessid_orig), &(args_info->write_paccessid_given), &(local_args_info.write_paccessid_given), optarg, 0, 0, ARG_STRING, check_ambiguity, override, 0, 0, "write-paccessid", '-', additional_error)) goto failure; - + } /* Read the specified data group; use several times to read out multiple files. */ else if (strcmp (long_options[option_index].name, "read-dg") == 0) { args_info->pxs_mode_counter += 1; - - if (update_multiple_arg_temp(&read_dg_list, + + if (update_multiple_arg_temp(&read_dg_list, &(local_args_info.read_dg_given), optarg, 0, 0, ARG_INT, "read-dg", '-', additional_error)) goto failure; - + } /* Write output to a file instead of printing it; use once for each use of `--read-dg'. */ else if (strcmp (long_options[option_index].name, "out-file") == 0) { args_info->pxs_mode_counter += 1; - - if (update_multiple_arg_temp(&out_file_list, + + if (update_multiple_arg_temp(&out_file_list, &(local_args_info.out_file_given), optarg, 0, 0, ARG_STRING, "out-file", '-', additional_error)) goto failure; - + } /* Write the specified data group; use several times to write multiple files. */ else if (strcmp (long_options[option_index].name, "write-dg") == 0) { args_info->pxs_mode_counter += 1; - - if (update_multiple_arg_temp(&write_dg_list, + + if (update_multiple_arg_temp(&write_dg_list, &(local_args_info.write_dg_given), optarg, 0, 0, ARG_INT, "write-dg", '-', additional_error)) goto failure; - + } /* Read input from a file; use once for each use of `--write-dg'. */ else if (strcmp (long_options[option_index].name, "in-file") == 0) { args_info->pxs_mode_counter += 1; - - if (update_multiple_arg_temp(&in_file_list, + + if (update_multiple_arg_temp(&in_file_list, &(local_args_info.in_file_given), optarg, 0, 0, ARG_STRING, "in-file", '-', additional_error)) goto failure; - + } /* Delete the specified data group; use several times to delete multiple files. */ else if (strcmp (long_options[option_index].name, "delete-dg") == 0) { args_info->pxs_mode_counter += 1; - - if (update_multiple_arg_temp(&delete_dg_list, + + if (update_multiple_arg_temp(&delete_dg_list, &(local_args_info.delete_dg_given), optarg, 0, 0, ARG_INT, "delete-dg", '-', additional_error)) goto failure; - + } /* Create the specified data group; use several times to create multiple files. */ else if (strcmp (long_options[option_index].name, "create-dg") == 0) { args_info->pxs_mode_counter += 1; - - if (update_multiple_arg_temp(&create_dg_list, + + if (update_multiple_arg_temp(&create_dg_list, &(local_args_info.create_dg_given), optarg, 0, 0, ARG_INT, "create-dg", '-', additional_error)) goto failure; - + } /* File size of newly created DGs. */ else if (strcmp (long_options[option_index].name, "new-size") == 0) { args_info->pxs_mode_counter += 1; - - - if (update_arg( (void *)&(args_info->new_size_arg), + + + if (update_arg( (void *)&(args_info->new_size_arg), &(args_info->new_size_orig), &(args_info->new_size_given), &(local_args_info.new_size_given), optarg, 0, "256", ARG_INT, check_ambiguity, override, 0, 0, "new-size", '-', additional_error)) goto failure; - + } /* Access condition for reading newly created DGs. */ else if (strcmp (long_options[option_index].name, "new-read-ac") == 0) { args_info->pxs_mode_counter += 1; - - - if (update_arg( (void *)&(args_info->new_read_ac_arg), + + + if (update_arg( (void *)&(args_info->new_read_ac_arg), &(args_info->new_read_ac_orig), &(args_info->new_read_ac_given), &(local_args_info.new_read_ac_given), optarg, cmdline_parser_new_read_ac_values, "sm", ARG_STRING, check_ambiguity, override, 0, 0, "new-read-ac", '-', additional_error)) goto failure; - + } - /* Required access bits in certificate's CHAT for reading newly created DGs. */ + /* Required access bit in certificate's CHAT for reading newly created DGs. */ else if (strcmp (long_options[option_index].name, "new-read-ac-chatbit") == 0) { args_info->pxs_mode_counter += 1; - - if (update_multiple_arg_temp(&new_read_ac_chatbit_list, + + if (update_multiple_arg_temp(&new_read_ac_chatbit_list, &(local_args_info.new_read_ac_chatbit_given), optarg, 0, 0, ARG_INT, "new-read-ac-chatbit", '-', additional_error)) goto failure; - + } /* Access condition for writing newly created DGs. */ else if (strcmp (long_options[option_index].name, "new-write-ac") == 0) { args_info->pxs_mode_counter += 1; - - - if (update_arg( (void *)&(args_info->new_write_ac_arg), + + + if (update_arg( (void *)&(args_info->new_write_ac_arg), &(args_info->new_write_ac_orig), &(args_info->new_write_ac_given), &(local_args_info.new_write_ac_given), optarg, cmdline_parser_new_write_ac_values, "sm", ARG_STRING, check_ambiguity, override, 0, 0, "new-write-ac", '-', additional_error)) goto failure; - + } - /* Required access bits in certificate's CHAT for reading newly created DGs. */ + /* Required access bit in certificate's CHAT for reading newly created DGs. */ else if (strcmp (long_options[option_index].name, "new-write-ac-chatbit") == 0) { args_info->pxs_mode_counter += 1; - - if (update_multiple_arg_temp(&new_write_ac_chatbit_list, + + if (update_multiple_arg_temp(&new_write_ac_chatbit_list, &(local_args_info.new_write_ac_chatbit_given), optarg, 0, 0, ARG_INT, "new-write-ac-chatbit", '-', additional_error)) goto failure; - + } - + break; case '?': /* Invalid option. */ /* `getopt_long' already printed an error message. */ @@ -1611,7 +1611,7 @@ cmdline_parser_internal ( local_args_info.new_read_ac_chatbit_given = 0; args_info->new_write_ac_chatbit_given += local_args_info.new_write_ac_chatbit_given; local_args_info.new_write_ac_chatbit_given = 0; - + if (args_info->pxs_mode_counter && args_info->soc_mode_counter) { int pxs_given[] = {args_info->certificate_given, args_info->key_given, args_info->print_cardid_given, args_info->write_cardid_given, args_info->print_paccessid_given, args_info->write_paccessid_given, args_info->read_dg_given, args_info->out_file_given, args_info->write_dg_given, args_info->in_file_given, args_info->delete_dg_given, args_info->create_dg_given, args_info->new_size_given, args_info->new_read_ac_given, args_info->new_read_ac_chatbit_given, args_info->new_write_ac_given, args_info->new_write_ac_chatbit_given, -1}; const char *pxs_desc[] = {"--certificate", "--key", "--print-cardid", "--write-cardid", "--print-paccessid", "--write-paccessid", "--read-dg", "--out-file", "--write-dg", "--in-file", "--delete-dg", "--create-dg", "--new-size", "--new-read-ac", "--new-read-ac-chatbit", "--new-write-ac", "--new-write-ac-chatbit", 0}; @@ -1619,7 +1619,7 @@ cmdline_parser_internal ( const char *soc_desc[] = {"--new-pin", "--new-bio", "--info", 0}; error_occurred += check_modes(pxs_given, pxs_desc, soc_given, soc_desc); } - + if (check_required) { error_occurred += cmdline_parser_required2 (args_info, argv[0], additional_error); @@ -1642,7 +1642,7 @@ cmdline_parser_internal ( free_list (create_dg_list, 0 ); free_list (new_read_ac_chatbit_list, 0 ); free_list (new_write_ac_chatbit_list, 0 ); - + cmdline_parser_release (&local_args_info); return (EXIT_FAILURE); } diff --git a/src/tools/npa-tool-cmdline.c b/src/tools/npa-tool-cmdline.c index c617dca7e2..47e14153ea 100644 --- a/src/tools/npa-tool-cmdline.c +++ b/src/tools/npa-tool-cmdline.c @@ -1,7 +1,7 @@ /* File autogenerated by gengetopt version 2.23 generated with the following command: - /usr/bin/gengetopt --file-name=npa-tool-cmdline --output-dir=. + /opt/homebrew/bin/gengetopt --file-name=npa-tool-cmdline --output-dir=. The developers of gengetopt consider the fixed text that goes in all gengetopt output files to be in the public domain: diff --git a/src/tools/opensc-asn1-cmdline.c b/src/tools/opensc-asn1-cmdline.c index 13e5412acf..a571762b27 100644 --- a/src/tools/opensc-asn1-cmdline.c +++ b/src/tools/opensc-asn1-cmdline.c @@ -1,7 +1,7 @@ /* File autogenerated by gengetopt version 2.23 generated with the following command: - /usr/bin/gengetopt --file-name=opensc-asn1-cmdline --output-dir=. --unamed-opts + /opt/homebrew/bin/gengetopt --file-name=opensc-asn1-cmdline --output-dir=. --unamed-opts The developers of gengetopt consider the fixed text that goes in all gengetopt output files to be in the public domain: diff --git a/src/tools/opensc-notify-cmdline.c b/src/tools/opensc-notify-cmdline.c index 9bae830a9e..7f148927c0 100644 --- a/src/tools/opensc-notify-cmdline.c +++ b/src/tools/opensc-notify-cmdline.c @@ -1,7 +1,7 @@ /* File autogenerated by gengetopt version 2.23 generated with the following command: - /usr/bin/gengetopt --file-name=opensc-notify-cmdline --output-dir=. + /opt/homebrew/bin/gengetopt --file-name=opensc-notify-cmdline --output-dir=. The developers of gengetopt consider the fixed text that goes in all gengetopt output files to be in the public domain: diff --git a/src/tools/pkcs11-register-cmdline.c b/src/tools/pkcs11-register-cmdline.c index 4cdc789009..467fd927ab 100644 --- a/src/tools/pkcs11-register-cmdline.c +++ b/src/tools/pkcs11-register-cmdline.c @@ -1,7 +1,7 @@ /* File autogenerated by gengetopt version 2.23 generated with the following command: - /usr/bin/gengetopt --file-name=pkcs11-register-cmdline --output-dir=. + /opt/homebrew/bin/gengetopt --file-name=pkcs11-register-cmdline --output-dir=. The developers of gengetopt consider the fixed text that goes in all gengetopt output files to be in the public domain: @@ -37,8 +37,8 @@ const char *gengetopt_args_info_help[] = { " -h, --help Print help and exit", " -V, --version Print version and exit", " -m, --module=FILENAME Specify the module to load (default=`OpenSC's\n PKCS#11 module')", - " --skip-chrome Don't install module to Chrome (default=off)", - " --skip-firefox Don't install module to Firefox (default=off)", + " --skip-chrome Don't install module to Chrome (default=on)", + " --skip-firefox Don't install module to Firefox (default=on)", " --skip-thunderbird Don't install module to Thunderbird (default=off)", " --skip-seamonkey Don't install module to SeaMonkey (default=off)", "\nReport bugs to https://github.com/OpenSC/OpenSC/issues\n\nWritten by Frank Morgner ", @@ -81,8 +81,8 @@ void clear_args (struct gengetopt_args_info *args_info) FIX_UNUSED (args_info); args_info->module_arg = gengetopt_strdup ("OpenSC's PKCS#11 module"); args_info->module_orig = NULL; - args_info->skip_chrome_flag = 0; - args_info->skip_firefox_flag = 0; + args_info->skip_chrome_flag = 1; + args_info->skip_firefox_flag = 1; args_info->skip_thunderbird_flag = 0; args_info->skip_seamonkey_flag = 0; diff --git a/src/tools/pkcs11-register-cmdline.h b/src/tools/pkcs11-register-cmdline.h index 67188023db..8262da3e42 100644 --- a/src/tools/pkcs11-register-cmdline.h +++ b/src/tools/pkcs11-register-cmdline.h @@ -42,9 +42,9 @@ struct gengetopt_args_info char * module_arg; /**< @brief Specify the module to load (default='OpenSC's PKCS#11 module'). */ char * module_orig; /**< @brief Specify the module to load original value given at command line. */ const char *module_help; /**< @brief Specify the module to load help description. */ - int skip_chrome_flag; /**< @brief Don't install module to Chrome (default=off). */ + int skip_chrome_flag; /**< @brief Don't install module to Chrome (default=on). */ const char *skip_chrome_help; /**< @brief Don't install module to Chrome help description. */ - int skip_firefox_flag; /**< @brief Don't install module to Firefox (default=off). */ + int skip_firefox_flag; /**< @brief Don't install module to Firefox (default=on). */ const char *skip_firefox_help; /**< @brief Don't install module to Firefox help description. */ int skip_thunderbird_flag; /**< @brief Don't install module to Thunderbird (default=off). */ const char *skip_thunderbird_help; /**< @brief Don't install module to Thunderbird help description. */ From a635b445b5ae139984ead897bb9999235907ec56 Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Wed, 28 Feb 2024 11:13:54 +0100 Subject: [PATCH 04/10] fixed shorten-64-to-32 warning for gengetopt generated files --- configure.ac | 2 ++ src/tools/Makefile.am | 25 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 1639965ff2..6a65b58062 100644 --- a/configure.ac +++ b/configure.ac @@ -148,6 +148,8 @@ AX_CODE_COVERAGE() AX_CHECK_COMPILE_FLAG([-Wunknown-warning-option], [have_unknown_warning_option="yes"], [have_unknown_warning_option="no"]) AM_CONDITIONAL([HAVE_UNKNOWN_WARNING_OPTION], [test "${have_unknown_warning_option}" = "yes"]) +AX_CHECK_COMPILE_FLAG([-Wshorten-64-to-32], [have_shorten_warning_option="yes"], [have_shorten_warning_option="no"]) +AM_CONDITIONAL([HAVE_SHORTEN_WARNING_OPTION], [test "${have_shorten_warning_option}" = "yes"]) AX_VALGRIND_CHECK() diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am index aab4a81163..b700ebfd08 100644 --- a/src/tools/Makefile.am +++ b/src/tools/Makefile.am @@ -107,12 +107,19 @@ npa_tool_CFLAGS = $(OPTIONAL_OPENSSL_CFLAGS) $(OPENPACE_CFLAGS) if HAVE_UNKNOWN_WARNING_OPTION npa_tool_CFLAGS += -Wno-unknown-warning-option endif +if HAVE_SHORTEN_WARNING_OPTION +npa_tool_CFLAGS += -Wno-shorten-64-to-32 +endif opensc_notify_SOURCES = opensc-notify.c opensc-notify-cmdline.c opensc_notify_CFLAGS = $(PTHREAD_CFLAGS) +opensc_notify_CFLAGS = if HAVE_UNKNOWN_WARNING_OPTION opensc_notify_CFLAGS += -Wno-unknown-warning-option endif +if HAVE_SHORTEN_WARNING_OPTION +opensc_notify_CFLAGS += -Wno-shorten-64-to-32 +endif egk_tool_SOURCES = egk-tool.c util.c egk-tool-cmdline.c egk_tool_LDADD = $(OPTIONAL_ZLIB_LIBS) @@ -120,6 +127,9 @@ egk_tool_CFLAGS = $(OPTIONAL_ZLIB_CFLAGS) if HAVE_UNKNOWN_WARNING_OPTION egk_tool_CFLAGS += -Wno-unknown-warning-option endif +if HAVE_SHORTEN_WARNING_OPTION +egk_tool_CFLAGS += -Wno-shorten-64-to-32 +endif goid_tool_SOURCES = goid-tool.c util.c fread_to_eof.c goid-tool-cmdline.c goid_tool_LDADD = $(OPENPACE_LIBS) @@ -127,18 +137,29 @@ goid_tool_CFLAGS = $(OPENPACE_CFLAGS) if HAVE_UNKNOWN_WARNING_OPTION goid_tool_CFLAGS += -Wno-unknown-warning-option endif +if HAVE_SHORTEN_WARNING_OPTION +goid_tool_CFLAGS += -Wno-shorten-64-to-32 +endif dtrust_tool_SOURCES = dtrust-tool.c util.c opensc_asn1_SOURCES = opensc-asn1.c fread_to_eof.c opensc-asn1-cmdline.c +opensc_asn1_CFLAGS = if HAVE_UNKNOWN_WARNING_OPTION -opensc_asn1_CFLAGS = -Wno-unknown-warning-option +opensc_asn1_CFLAGS += -Wno-unknown-warning-option +endif +if HAVE_SHORTEN_WARNING_OPTION +opensc_asn1_CFLAGS += -Wno-shorten-64-to-32 endif pkcs11_register_SOURCES = pkcs11-register.c fread_to_eof.c pkcs11-register-cmdline.c pkcs11_register_LDADD = $(top_builddir)/src/common/libpkcs11.la +pkcs11_register_CFLAGS = if HAVE_UNKNOWN_WARNING_OPTION -pkcs11_register_CFLAGS = -Wno-unknown-warning-option +pkcs11_register_CFLAGS += -Wno-unknown-warning-option +endif +if HAVE_SHORTEN_WARNING_OPTION +pkcs11_register_CFLAGS += -Wno-shorten-64-to-32 endif .PHONY: cmdline From 65d890d8254f512013ddceb76a7a39ebe789eaa1 Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Thu, 7 Mar 2024 00:36:45 +0100 Subject: [PATCH 05/10] goid-tool: workaround for compiler warning of generated code --- src/tools/goid-tool-cmdline.c | 52 +++++++++++++++++------------------ src/tools/goid-tool-cmdline.h | 14 +++++----- src/tools/goid-tool.c | 2 +- src/tools/goid-tool.ggo.in | 14 +++++----- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/tools/goid-tool-cmdline.c b/src/tools/goid-tool-cmdline.c index fe89bb7252..459e10e2f6 100644 --- a/src/tools/goid-tool-cmdline.c +++ b/src/tools/goid-tool-cmdline.c @@ -69,7 +69,7 @@ const char *gengetopt_args_info_help[] = { typedef enum {ARG_NO , ARG_STRING - , ARG_INT + , ARG_SHORT } cmdline_parser_arg_type; static @@ -303,7 +303,7 @@ free_string_field (char **s) /** @brief generic value variable */ union generic_value { - int int_arg; + short short_arg; char *string_arg; const char *default_string_arg; }; @@ -921,8 +921,8 @@ int update_arg(void *field, char **orig_field, val = possible_values[found]; switch(arg_type) { - case ARG_INT: - if (val) *((int *)field) = (int)strtol (val, &stop_char, 0); + case ARG_SHORT: + if (val) *((short *)field) = (short)strtol (val, &stop_char, 0); break; case ARG_STRING: if (val) { @@ -938,7 +938,7 @@ int update_arg(void *field, char **orig_field, /* check numeric conversion */ switch(arg_type) { - case ARG_INT: + case ARG_SHORT: if (val && !(stop_char && *stop_char == '\0')) { fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); return 1; /* failure */ @@ -1050,8 +1050,8 @@ void update_multiple_arg(void *field, char ***orig_field, *orig_field = (char **) realloc (*orig_field, (field_given + prev_given) * sizeof (char *)); switch(arg_type) { - case ARG_INT: - *((int **)field) = (int *)realloc (*((int **)field), (field_given + prev_given) * sizeof (int)); break; + case ARG_SHORT: + *((short **)field) = (short *)realloc (*((short **)field), (field_given + prev_given) * sizeof (short)); break; case ARG_STRING: *((char ***)field) = (char **)realloc (*((char ***)field), (field_given + prev_given) * sizeof (char *)); break; default: @@ -1063,8 +1063,8 @@ void update_multiple_arg(void *field, char ***orig_field, tmp = list; switch(arg_type) { - case ARG_INT: - (*((int **)field))[i + field_given] = tmp->arg.int_arg; break; + case ARG_SHORT: + (*((short **)field))[i + field_given] = tmp->arg.short_arg; break; case ARG_STRING: (*((char ***)field))[i + field_given] = tmp->arg.string_arg; break; default: @@ -1077,10 +1077,10 @@ void update_multiple_arg(void *field, char ***orig_field, } else { /* set the default value */ if (default_value && ! field_given) { switch(arg_type) { - case ARG_INT: - if (! *((int **)field)) { - *((int **)field) = (int *)malloc (sizeof (int)); - (*((int **)field))[0] = default_value->int_arg; + case ARG_SHORT: + if (! *((short **)field)) { + *((short **)field) = (short *)malloc (sizeof (short)); + (*((short **)field))[0] = default_value->short_arg; } break; case ARG_STRING: @@ -1404,7 +1404,7 @@ cmdline_parser_internal ( args_info->pxs_mode_counter += 1; if (update_multiple_arg_temp(&read_dg_list, - &(local_args_info.read_dg_given), optarg, 0, 0, ARG_INT, + &(local_args_info.read_dg_given), optarg, 0, 0, ARG_SHORT, "read-dg", '-', additional_error)) goto failure; @@ -1428,7 +1428,7 @@ cmdline_parser_internal ( args_info->pxs_mode_counter += 1; if (update_multiple_arg_temp(&write_dg_list, - &(local_args_info.write_dg_given), optarg, 0, 0, ARG_INT, + &(local_args_info.write_dg_given), optarg, 0, 0, ARG_SHORT, "write-dg", '-', additional_error)) goto failure; @@ -1452,7 +1452,7 @@ cmdline_parser_internal ( args_info->pxs_mode_counter += 1; if (update_multiple_arg_temp(&delete_dg_list, - &(local_args_info.delete_dg_given), optarg, 0, 0, ARG_INT, + &(local_args_info.delete_dg_given), optarg, 0, 0, ARG_SHORT, "delete-dg", '-', additional_error)) goto failure; @@ -1464,7 +1464,7 @@ cmdline_parser_internal ( args_info->pxs_mode_counter += 1; if (update_multiple_arg_temp(&create_dg_list, - &(local_args_info.create_dg_given), optarg, 0, 0, ARG_INT, + &(local_args_info.create_dg_given), optarg, 0, 0, ARG_SHORT, "create-dg", '-', additional_error)) goto failure; @@ -1478,7 +1478,7 @@ cmdline_parser_internal ( if (update_arg( (void *)&(args_info->new_size_arg), &(args_info->new_size_orig), &(args_info->new_size_given), - &(local_args_info.new_size_given), optarg, 0, "256", ARG_INT, + &(local_args_info.new_size_given), optarg, 0, "256", ARG_SHORT, check_ambiguity, override, 0, 0, "new-size", '-', additional_error)) @@ -1506,7 +1506,7 @@ cmdline_parser_internal ( args_info->pxs_mode_counter += 1; if (update_multiple_arg_temp(&new_read_ac_chatbit_list, - &(local_args_info.new_read_ac_chatbit_given), optarg, 0, 0, ARG_INT, + &(local_args_info.new_read_ac_chatbit_given), optarg, 0, 0, ARG_SHORT, "new-read-ac-chatbit", '-', additional_error)) goto failure; @@ -1533,7 +1533,7 @@ cmdline_parser_internal ( args_info->pxs_mode_counter += 1; if (update_multiple_arg_temp(&new_write_ac_chatbit_list, - &(local_args_info.new_write_ac_chatbit_given), optarg, 0, 0, ARG_INT, + &(local_args_info.new_write_ac_chatbit_given), optarg, 0, 0, ARG_SHORT, "new-write-ac-chatbit", '-', additional_error)) goto failure; @@ -1559,7 +1559,7 @@ cmdline_parser_internal ( update_multiple_arg((void *)&(args_info->read_dg_arg), &(args_info->read_dg_orig), args_info->read_dg_given, local_args_info.read_dg_given, 0, - ARG_INT, read_dg_list); + ARG_SHORT, read_dg_list); update_multiple_arg((void *)&(args_info->out_file_arg), &(args_info->out_file_orig), args_info->out_file_given, local_args_info.out_file_given, 0, @@ -1567,7 +1567,7 @@ cmdline_parser_internal ( update_multiple_arg((void *)&(args_info->write_dg_arg), &(args_info->write_dg_orig), args_info->write_dg_given, local_args_info.write_dg_given, 0, - ARG_INT, write_dg_list); + ARG_SHORT, write_dg_list); update_multiple_arg((void *)&(args_info->in_file_arg), &(args_info->in_file_orig), args_info->in_file_given, local_args_info.in_file_given, 0, @@ -1575,19 +1575,19 @@ cmdline_parser_internal ( update_multiple_arg((void *)&(args_info->delete_dg_arg), &(args_info->delete_dg_orig), args_info->delete_dg_given, local_args_info.delete_dg_given, 0, - ARG_INT, delete_dg_list); + ARG_SHORT, delete_dg_list); update_multiple_arg((void *)&(args_info->create_dg_arg), &(args_info->create_dg_orig), args_info->create_dg_given, local_args_info.create_dg_given, 0, - ARG_INT, create_dg_list); + ARG_SHORT, create_dg_list); update_multiple_arg((void *)&(args_info->new_read_ac_chatbit_arg), &(args_info->new_read_ac_chatbit_orig), args_info->new_read_ac_chatbit_given, local_args_info.new_read_ac_chatbit_given, 0, - ARG_INT, new_read_ac_chatbit_list); + ARG_SHORT, new_read_ac_chatbit_list); update_multiple_arg((void *)&(args_info->new_write_ac_chatbit_arg), &(args_info->new_write_ac_chatbit_orig), args_info->new_write_ac_chatbit_given, local_args_info.new_write_ac_chatbit_given, 0, - ARG_INT, new_write_ac_chatbit_list); + ARG_SHORT, new_write_ac_chatbit_list); args_info->verbose_given += local_args_info.verbose_given; local_args_info.verbose_given = 0; diff --git a/src/tools/goid-tool-cmdline.h b/src/tools/goid-tool-cmdline.h index 3aec314753..50002c6a7f 100644 --- a/src/tools/goid-tool-cmdline.h +++ b/src/tools/goid-tool-cmdline.h @@ -69,7 +69,7 @@ struct gengetopt_args_info char * write_paccessid_arg; /**< @brief Write the specified PAccess ID. */ char * write_paccessid_orig; /**< @brief Write the specified PAccess ID original value given at command line. */ const char *write_paccessid_help; /**< @brief Write the specified PAccess ID help description. */ - int* read_dg_arg; /**< @brief Read the specified data group; use several times to read out multiple files. */ + short* read_dg_arg; /**< @brief Read the specified data group; use several times to read out multiple files. */ char ** read_dg_orig; /**< @brief Read the specified data group; use several times to read out multiple files original value given at command line. */ unsigned int read_dg_min; /**< @brief Read the specified data group; use several times to read out multiple files's minimum occurreces */ unsigned int read_dg_max; /**< @brief Read the specified data group; use several times to read out multiple files's maximum occurreces */ @@ -79,7 +79,7 @@ struct gengetopt_args_info unsigned int out_file_min; /**< @brief Write output to a file instead of printing it; use once for each use of `--read-dg''s minimum occurreces */ unsigned int out_file_max; /**< @brief Write output to a file instead of printing it; use once for each use of `--read-dg''s maximum occurreces */ const char *out_file_help; /**< @brief Write output to a file instead of printing it; use once for each use of `--read-dg' help description. */ - int* write_dg_arg; /**< @brief Write the specified data group; use several times to write multiple files. */ + short* write_dg_arg; /**< @brief Write the specified data group; use several times to write multiple files. */ char ** write_dg_orig; /**< @brief Write the specified data group; use several times to write multiple files original value given at command line. */ unsigned int write_dg_min; /**< @brief Write the specified data group; use several times to write multiple files's minimum occurreces */ unsigned int write_dg_max; /**< @brief Write the specified data group; use several times to write multiple files's maximum occurreces */ @@ -89,23 +89,23 @@ struct gengetopt_args_info unsigned int in_file_min; /**< @brief Read input from a file; use once for each use of `--write-dg''s minimum occurreces */ unsigned int in_file_max; /**< @brief Read input from a file; use once for each use of `--write-dg''s maximum occurreces */ const char *in_file_help; /**< @brief Read input from a file; use once for each use of `--write-dg' help description. */ - int* delete_dg_arg; /**< @brief Delete the specified data group; use several times to delete multiple files. */ + short* delete_dg_arg; /**< @brief Delete the specified data group; use several times to delete multiple files. */ char ** delete_dg_orig; /**< @brief Delete the specified data group; use several times to delete multiple files original value given at command line. */ unsigned int delete_dg_min; /**< @brief Delete the specified data group; use several times to delete multiple files's minimum occurreces */ unsigned int delete_dg_max; /**< @brief Delete the specified data group; use several times to delete multiple files's maximum occurreces */ const char *delete_dg_help; /**< @brief Delete the specified data group; use several times to delete multiple files help description. */ - int* create_dg_arg; /**< @brief Create the specified data group; use several times to create multiple files. */ + short* create_dg_arg; /**< @brief Create the specified data group; use several times to create multiple files. */ char ** create_dg_orig; /**< @brief Create the specified data group; use several times to create multiple files original value given at command line. */ unsigned int create_dg_min; /**< @brief Create the specified data group; use several times to create multiple files's minimum occurreces */ unsigned int create_dg_max; /**< @brief Create the specified data group; use several times to create multiple files's maximum occurreces */ const char *create_dg_help; /**< @brief Create the specified data group; use several times to create multiple files help description. */ - int new_size_arg; /**< @brief File size of newly created DGs (default='256'). */ + short new_size_arg; /**< @brief File size of newly created DGs (default='256'). */ char * new_size_orig; /**< @brief File size of newly created DGs original value given at command line. */ const char *new_size_help; /**< @brief File size of newly created DGs help description. */ char * new_read_ac_arg; /**< @brief Access condition for reading newly created DGs (default='sm'). */ char * new_read_ac_orig; /**< @brief Access condition for reading newly created DGs original value given at command line. */ const char *new_read_ac_help; /**< @brief Access condition for reading newly created DGs help description. */ - int* new_read_ac_chatbit_arg; /**< @brief Required access bit in certificate's CHAT for reading newly created DGs. */ + short* new_read_ac_chatbit_arg; /**< @brief Required access bit in certificate's CHAT for reading newly created DGs. */ char ** new_read_ac_chatbit_orig; /**< @brief Required access bit in certificate's CHAT for reading newly created DGs original value given at command line. */ unsigned int new_read_ac_chatbit_min; /**< @brief Required access bit in certificate's CHAT for reading newly created DGs's minimum occurreces */ unsigned int new_read_ac_chatbit_max; /**< @brief Required access bit in certificate's CHAT for reading newly created DGs's maximum occurreces */ @@ -113,7 +113,7 @@ struct gengetopt_args_info char * new_write_ac_arg; /**< @brief Access condition for writing newly created DGs (default='sm'). */ char * new_write_ac_orig; /**< @brief Access condition for writing newly created DGs original value given at command line. */ const char *new_write_ac_help; /**< @brief Access condition for writing newly created DGs help description. */ - int* new_write_ac_chatbit_arg; /**< @brief Required access bit in certificate's CHAT for reading newly created DGs. */ + short* new_write_ac_chatbit_arg; /**< @brief Required access bit in certificate's CHAT for reading newly created DGs. */ char ** new_write_ac_chatbit_orig; /**< @brief Required access bit in certificate's CHAT for reading newly created DGs original value given at command line. */ unsigned int new_write_ac_chatbit_min; /**< @brief Required access bit in certificate's CHAT for reading newly created DGs's minimum occurreces */ unsigned int new_write_ac_chatbit_max; /**< @brief Required access bit in certificate's CHAT for reading newly created DGs's maximum occurreces */ diff --git a/src/tools/goid-tool.c b/src/tools/goid-tool.c index c4a11475d9..619bf742af 100644 --- a/src/tools/goid-tool.c +++ b/src/tools/goid-tool.c @@ -453,7 +453,7 @@ paccess_delete_file(struct sc_card *card, int fid) } int -paccess_get_security_attributes(struct sc_context *ctx, const char *ac, int* chatbits, size_t chatbits_len, u8 sec_attr[2]) +paccess_get_security_attributes(struct sc_context *ctx, const char *ac, short* chatbits, size_t chatbits_len, u8 sec_attr[2]) { int ok = 0; memset(sec_attr, 0, 2); diff --git a/src/tools/goid-tool.ggo.in b/src/tools/goid-tool.ggo.in index fcf3a05b15..7d8b126cce 100644 --- a/src/tools/goid-tool.ggo.in +++ b/src/tools/goid-tool.ggo.in @@ -49,37 +49,37 @@ modeoption "write-paccessid" - string mode="pxs" optional typestr="PACCESSID" modeoption "read-dg" - "Read the specified data group; use several times to read out multiple files" - int mode="pxs" optional multiple typestr="ID" + short mode="pxs" optional multiple typestr="ID" modeoption "out-file" - "Write output to a file instead of printing it; use once for each use of `--read-dg'" string mode="pxs" optional multiple typestr="FILENAME" modeoption "write-dg" - "Write the specified data group; use several times to write multiple files" - int mode="pxs" optional multiple typestr="ID" + short mode="pxs" optional multiple typestr="ID" modeoption "in-file" - "Read input from a file; use once for each use of `--write-dg'" string mode="pxs" optional multiple typestr="FILENAME" modeoption "delete-dg" - "Delete the specified data group; use several times to delete multiple files" - int mode="pxs" optional multiple typestr="ID" + short mode="pxs" optional multiple typestr="ID" modeoption "create-dg" - "Create the specified data group; use several times to create multiple files" - int mode="pxs" optional multiple typestr="ID" + short mode="pxs" optional multiple typestr="ID" modeoption "new-size" - "File size of newly created DGs" - int mode="pxs" optional dependon="create-dg" typestr="SIZE" default="256" + short mode="pxs" optional dependon="create-dg" typestr="SIZE" default="256" modeoption "new-read-ac" - "Access condition for reading newly created DGs" values="always","never","ta","sm" default="sm" mode="pxs" optional dependon="create-dg" modeoption "new-read-ac-chatbit" - "Required access bit in certificate's CHAT for reading newly created DGs" - int mode="pxs" optional dependon="create-dg" multiple typestr="INDEX" + short mode="pxs" optional dependon="create-dg" multiple typestr="INDEX" modeoption "new-write-ac" - "Access condition for writing newly created DGs" values="always","never","ta","sm" default="sm" mode="pxs" optional dependon="create-dg" modeoption "new-write-ac-chatbit" - "Required access bit in certificate's CHAT for reading newly created DGs" - int mode="pxs" optional dependon="create-dg" multiple typestr="INDEX" + short mode="pxs" optional dependon="create-dg" multiple typestr="INDEX" text " Report bugs to @PACKAGE_BUGREPORT@ From 348c5a3d39203b2c56c908208ff7d7d82fd78d42 Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Tue, 27 Feb 2024 14:10:53 +0100 Subject: [PATCH 06/10] remove generated cmdline sources from distribution dependant tools will only be created if gengetopt is available during build. On Windows, this requires generating the files via `make cmdline -C src/tools` in cygwin with gengetopt installed fixes missing distribution of pkcs11-register.ggo.in fixes CVCDIR and X509DIR defaults on Windows --- .appveyor.yml | 11 +- .gitignore | 2 + configure.ac | 2 + packaging/opensc.spec | 1 + src/tools/Makefile.am | 70 +- src/tools/Makefile.mak | 2 +- src/tools/egk-tool-cmdline.c | 710 ---------- src/tools/egk-tool-cmdline.h | 193 --- src/tools/goid-tool-cmdline.c | 1649 ----------------------- src/tools/goid-tool-cmdline.h | 282 ---- src/tools/npa-tool-cmdline.c | 1904 --------------------------- src/tools/npa-tool-cmdline.h | 351 ----- src/tools/opensc-asn1-cmdline.c | 423 ------ src/tools/opensc-asn1-cmdline.h | 175 --- src/tools/opensc-notify-cmdline.c | 655 --------- src/tools/opensc-notify-cmdline.h | 196 --- src/tools/pkcs11-register-cmdline.c | 601 --------- src/tools/pkcs11-register-cmdline.h | 189 --- 18 files changed, 61 insertions(+), 7355 deletions(-) delete mode 100644 src/tools/egk-tool-cmdline.c delete mode 100644 src/tools/egk-tool-cmdline.h delete mode 100644 src/tools/goid-tool-cmdline.c delete mode 100644 src/tools/goid-tool-cmdline.h delete mode 100644 src/tools/npa-tool-cmdline.c delete mode 100644 src/tools/npa-tool-cmdline.h delete mode 100644 src/tools/opensc-asn1-cmdline.c delete mode 100644 src/tools/opensc-asn1-cmdline.h delete mode 100644 src/tools/opensc-notify-cmdline.c delete mode 100644 src/tools/opensc-notify-cmdline.h delete mode 100644 src/tools/pkcs11-register-cmdline.c delete mode 100644 src/tools/pkcs11-register-cmdline.h diff --git a/.appveyor.yml b/.appveyor.yml index 4599100ad2..3919761df0 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -62,6 +62,14 @@ install: If (!(Test-Path cpdksetup.exe )) { appveyor DownloadFile "https://download.microsoft.com/download/1/7/6/176909B0-50F2-4DF3-B29B-830A17EA7E38/CPDK_RELEASE_UPDATE/cpdksetup.exe" } + - wget https://ftp.gnu.org/gnu/gengetopt/gengetopt-2.23.tar.xz + - tar xJf gengetopt-2.23.tar.xz + - cd gengetopt-2.23 + - bash -c "exec 0 "$${f%.in}"; done - @for f in *.ggo; do $(GENGETOPT) --file-name="$${f%.ggo}-cmdline" --output-dir=$(builddir) < "$$f"; done - $(AM_V_GEN)$(GENGETOPT) --file-name=opensc-asn1-cmdline --output-dir=$(builddir) --unamed-opts < opensc-asn1.ggo + @for f in *.ggo.in; do $(do_subst) < "$$f" | $(GENGETOPT) --file-name="$${f%.ggo.in}-cmdline" --output-dir=$(builddir); done + $(AM_V_GEN)$(do_subst) < "opensc-asn1.ggo.in" | $(GENGETOPT) --file-name=opensc-asn1-cmdline --output-dir=$(builddir) --unamed-opts if WIN32 LIBS += -lshlwapi @@ -207,4 +227,4 @@ noinst_DATA = org.opensc-project.mac.pkcs11-register.plist org.opensc-project.ma $(AM_V_GEN)$(do_subst) < $< > $@ clean-local: - rm -f $(abs_builddir)/npa-tool.ggo $(abs_builddir)/opensc-notify.ggo $(abs_builddir)/opensc-asn1.ggo $(abs_builddir)/goid-tool.ggo $(abs_builddir)/egk-tool.ggo org.opensc.notify.desktop pkcs11-register.desktop org.opensc-project.mac.opensc-notify.plist org.opensc-project.mac.pkcs11-register.plist + rm -f $(abs_builddir)/npa-tool.ggo $(abs_builddir)/opensc-notify.ggo $(abs_builddir)/opensc-asn1.ggo $(abs_builddir)/goid-tool.ggo $(abs_builddir)/egk-tool.ggo $(abs_builddir)/*cmdline* org.opensc.notify.desktop pkcs11-register.desktop org.opensc-project.mac.opensc-notify.plist org.opensc-project.mac.pkcs11-register.plist diff --git a/src/tools/Makefile.mak b/src/tools/Makefile.mak index b2682727d2..abef3f6490 100644 --- a/src/tools/Makefile.mak +++ b/src/tools/Makefile.mak @@ -6,7 +6,7 @@ default: all TARGETS = opensc-tool.exe opensc-explorer.exe pkcs15-tool.exe pkcs15-crypt.exe \ pkcs11-tool.exe cardos-tool.exe eidenv.exe openpgp-tool.exe iasecc-tool.exe \ - opensc-notify.exe egk-tool.exe goid-tool.exe dtrust-tool paccess-tool.exe \ + opensc-notify.exe egk-tool.exe goid-tool.exe dtrust-tool \ opensc-asn1.exe pkcs11-register.exe $(PROGRAMS_OPENSSL) $(PROGRAMS_OPENPACE) OBJECTS = util.obj versioninfo-tools.res diff --git a/src/tools/egk-tool-cmdline.c b/src/tools/egk-tool-cmdline.c deleted file mode 100644 index 305b5691d2..0000000000 --- a/src/tools/egk-tool-cmdline.c +++ /dev/null @@ -1,710 +0,0 @@ -/* - File autogenerated by gengetopt version 2.23 - generated with the following command: - /opt/homebrew/bin/gengetopt --file-name=egk-tool-cmdline --output-dir=. - - The developers of gengetopt consider the fixed text that goes in all - gengetopt output files to be in the public domain: - we make no copyright claims on it. -*/ - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#ifndef FIX_UNUSED -#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ -#endif - -#include - -#include "egk-tool-cmdline.h" - -const char *gengetopt_args_info_purpose = ""; - -const char *gengetopt_args_info_usage = "Usage: egk-tool [OPTION]..."; - -const char *gengetopt_args_info_versiontext = ""; - -const char *gengetopt_args_info_description = ""; - -const char *gengetopt_args_info_help[] = { - " -h, --help Print help and exit", - " -V, --version Print version and exit", - " -r, --reader=STRING Number of the reader to use. By default, the first\n reader with a present card is used. If the argument is\n an ATR, the reader with a matching card will be\n chosen.", - " -v, --verbose Use (several times) to be more verbose", - "\n'Gesundheitsanwendung', Health Care Application (HCA):", - " --pd Show 'Persönliche Versichertendaten' (XML)\n (default=off)", - " --vd Show 'Allgemeine Versichertendaten' (XML) (default=off)", - " --gvd Show 'Geschützte Versichertendaten' (XML)\n (default=off)", - " --vsd-status Show 'Versichertenstammdaten-Status' (default=off)", - "\nReport bugs to https://github.com/OpenSC/OpenSC/issues\n\nWritten by Frank Morgner ", - 0 -}; - -typedef enum {ARG_NO - , ARG_FLAG - , ARG_STRING -} cmdline_parser_arg_type; - -static -void clear_given (struct gengetopt_args_info *args_info); -static -void clear_args (struct gengetopt_args_info *args_info); - -static int -cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params, const char *additional_error); - -static int -cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error); - -static char * -gengetopt_strdup (const char *s); - -static -void clear_given (struct gengetopt_args_info *args_info) -{ - args_info->help_given = 0 ; - args_info->version_given = 0 ; - args_info->reader_given = 0 ; - args_info->verbose_given = 0 ; - args_info->pd_given = 0 ; - args_info->vd_given = 0 ; - args_info->gvd_given = 0 ; - args_info->vsd_status_given = 0 ; -} - -static -void clear_args (struct gengetopt_args_info *args_info) -{ - FIX_UNUSED (args_info); - args_info->reader_arg = NULL; - args_info->reader_orig = NULL; - args_info->pd_flag = 0; - args_info->vd_flag = 0; - args_info->gvd_flag = 0; - args_info->vsd_status_flag = 0; - -} - -static -void init_args_info(struct gengetopt_args_info *args_info) -{ - - - args_info->help_help = gengetopt_args_info_help[0] ; - args_info->version_help = gengetopt_args_info_help[1] ; - args_info->reader_help = gengetopt_args_info_help[2] ; - args_info->verbose_help = gengetopt_args_info_help[3] ; - args_info->verbose_min = 0; - args_info->verbose_max = 0; - args_info->pd_help = gengetopt_args_info_help[5] ; - args_info->vd_help = gengetopt_args_info_help[6] ; - args_info->gvd_help = gengetopt_args_info_help[7] ; - args_info->vsd_status_help = gengetopt_args_info_help[8] ; - -} - -void -cmdline_parser_print_version (void) -{ - printf ("%s %s\n", - (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE), - CMDLINE_PARSER_VERSION); - - if (strlen(gengetopt_args_info_versiontext) > 0) - printf("\n%s\n", gengetopt_args_info_versiontext); -} - -static void print_help_common(void) -{ - size_t len_purpose = strlen(gengetopt_args_info_purpose); - size_t len_usage = strlen(gengetopt_args_info_usage); - - if (len_usage > 0) { - printf("%s\n", gengetopt_args_info_usage); - } - if (len_purpose > 0) { - printf("%s\n", gengetopt_args_info_purpose); - } - - if (len_usage || len_purpose) { - printf("\n"); - } - - if (strlen(gengetopt_args_info_description) > 0) { - printf("%s\n\n", gengetopt_args_info_description); - } -} - -void -cmdline_parser_print_help (void) -{ - int i = 0; - print_help_common(); - while (gengetopt_args_info_help[i]) - printf("%s\n", gengetopt_args_info_help[i++]); -} - -void -cmdline_parser_init (struct gengetopt_args_info *args_info) -{ - clear_given (args_info); - clear_args (args_info); - init_args_info (args_info); -} - -void -cmdline_parser_params_init(struct cmdline_parser_params *params) -{ - if (params) - { - params->override = 0; - params->initialize = 1; - params->check_required = 1; - params->check_ambiguity = 0; - params->print_errors = 1; - } -} - -struct cmdline_parser_params * -cmdline_parser_params_create(void) -{ - struct cmdline_parser_params *params = - (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); - cmdline_parser_params_init(params); - return params; -} - -static void -free_string_field (char **s) -{ - if (*s) - { - free (*s); - *s = 0; - } -} - - -static void -cmdline_parser_release (struct gengetopt_args_info *args_info) -{ - - free_string_field (&(args_info->reader_arg)); - free_string_field (&(args_info->reader_orig)); - - - - clear_given (args_info); -} - - -static void -write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) -{ - FIX_UNUSED (values); - if (arg) { - fprintf(outfile, "%s=\"%s\"\n", opt, arg); - } else { - fprintf(outfile, "%s\n", opt); - } -} - -static void -write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, const char *values[]) -{ - int i; - - for (i = 0; i < len; ++i) - write_into_file(outfile, opt, (arg ? arg[i] : 0), values); -} - -int -cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) -{ - int i = 0; - - if (!outfile) - { - fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE); - return EXIT_FAILURE; - } - - if (args_info->help_given) - write_into_file(outfile, "help", 0, 0 ); - if (args_info->version_given) - write_into_file(outfile, "version", 0, 0 ); - if (args_info->reader_given) - write_into_file(outfile, "reader", args_info->reader_orig, 0); - write_multiple_into_file(outfile, args_info->verbose_given, "verbose", 0, 0); - if (args_info->pd_given) - write_into_file(outfile, "pd", 0, 0 ); - if (args_info->vd_given) - write_into_file(outfile, "vd", 0, 0 ); - if (args_info->gvd_given) - write_into_file(outfile, "gvd", 0, 0 ); - if (args_info->vsd_status_given) - write_into_file(outfile, "vsd-status", 0, 0 ); - - - i = EXIT_SUCCESS; - return i; -} - -int -cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) -{ - FILE *outfile; - int i = 0; - - outfile = fopen(filename, "w"); - - if (!outfile) - { - fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); - return EXIT_FAILURE; - } - - i = cmdline_parser_dump(outfile, args_info); - fclose (outfile); - - return i; -} - -void -cmdline_parser_free (struct gengetopt_args_info *args_info) -{ - cmdline_parser_release (args_info); -} - -/** @brief replacement of strdup, which is not standard */ -char * -gengetopt_strdup (const char *s) -{ - char *result = 0; - if (!s) - return result; - - result = (char*)malloc(strlen(s) + 1); - if (result == (char*)0) - return (char*)0; - strcpy(result, s); - return result; -} - -static int -check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc); - -int -check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc) -{ - int error_occurred = 0; - - if (option_given && (min > 0 || max > 0)) - { - if (min > 0 && max > 0) - { - if (min == max) - { - /* specific occurrences */ - if (option_given != (unsigned int) min) - { - fprintf (stderr, "%s: %s option occurrences must be %d\n", - prog_name, option_desc, min); - error_occurred = 1; - } - } - else if (option_given < (unsigned int) min - || option_given > (unsigned int) max) - { - /* range occurrences */ - fprintf (stderr, "%s: %s option occurrences must be between %d and %d\n", - prog_name, option_desc, min, max); - error_occurred = 1; - } - } - else if (min > 0) - { - /* at least check */ - if (option_given < min) - { - fprintf (stderr, "%s: %s option occurrences must be at least %d\n", - prog_name, option_desc, min); - error_occurred = 1; - } - } - else if (max > 0) - { - /* at most check */ - if (option_given > max) - { - fprintf (stderr, "%s: %s option occurrences must be at most %d\n", - prog_name, option_desc, max); - error_occurred = 1; - } - } - } - - return error_occurred; -} -int -cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info) -{ - return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); -} - -int -cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params) -{ - int result; - result = cmdline_parser_internal (argc, argv, args_info, params, 0); - - if (result == EXIT_FAILURE) - { - cmdline_parser_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) -{ - int result; - struct cmdline_parser_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0); - - if (result == EXIT_FAILURE) - { - cmdline_parser_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) -{ - int result = EXIT_SUCCESS; - - if (cmdline_parser_required2(args_info, prog_name, 0) > 0) - result = EXIT_FAILURE; - - if (result == EXIT_FAILURE) - { - cmdline_parser_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error) -{ - int error_occurred = 0; - FIX_UNUSED (additional_error); - - /* checks for required options */ - if (check_multiple_option_occurrences(prog_name, args_info->verbose_given, args_info->verbose_min, args_info->verbose_max, "'--verbose' ('-v')")) - error_occurred = 1; - - - /* checks for dependences among options */ - - return error_occurred; -} - - -static char *package_name = 0; - -/** - * @brief updates an option - * @param field the generic pointer to the field to update - * @param orig_field the pointer to the orig field - * @param field_given the pointer to the number of occurrence of this option - * @param prev_given the pointer to the number of occurrence already seen - * @param value the argument for this option (if null no arg was specified) - * @param possible_values the possible values for this option (if specified) - * @param default_value the default value (in case the option only accepts fixed values) - * @param arg_type the type of this option - * @param check_ambiguity @see cmdline_parser_params.check_ambiguity - * @param override @see cmdline_parser_params.override - * @param no_free whether to free a possible previous value - * @param multiple_option whether this is a multiple option - * @param long_opt the corresponding long option - * @param short_opt the corresponding short option (or '-' if none) - * @param additional_error possible further error specification - */ -static -int update_arg(void *field, char **orig_field, - unsigned int *field_given, unsigned int *prev_given, - char *value, const char *possible_values[], - const char *default_value, - cmdline_parser_arg_type arg_type, - int check_ambiguity, int override, - int no_free, int multiple_option, - const char *long_opt, char short_opt, - const char *additional_error) -{ - char *stop_char = 0; - const char *val = value; - int found; - char **string_field; - FIX_UNUSED (field); - - stop_char = 0; - found = 0; - - if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) - { - if (short_opt != '-') - fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", - package_name, long_opt, short_opt, - (additional_error ? additional_error : "")); - else - fprintf (stderr, "%s: `--%s' option given more than once%s\n", - package_name, long_opt, - (additional_error ? additional_error : "")); - return 1; /* failure */ - } - - FIX_UNUSED (default_value); - - if (field_given && *field_given && ! override) - return 0; - if (prev_given) - (*prev_given)++; - if (field_given) - (*field_given)++; - if (possible_values) - val = possible_values[found]; - - switch(arg_type) { - case ARG_FLAG: - *((int *)field) = !*((int *)field); - break; - case ARG_STRING: - if (val) { - string_field = (char **)field; - if (!no_free && *string_field) - free (*string_field); /* free previous string */ - *string_field = gengetopt_strdup (val); - } - break; - default: - break; - }; - - FIX_UNUSED(stop_char); - - /* store the original value */ - switch(arg_type) { - case ARG_NO: - case ARG_FLAG: - break; - default: - if (value && orig_field) { - if (no_free) { - *orig_field = value; - } else { - if (*orig_field) - free (*orig_field); /* free previous string */ - *orig_field = gengetopt_strdup (value); - } - } - }; - - return 0; /* OK */ -} - - -int -cmdline_parser_internal ( - int argc, char **argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params, const char *additional_error) -{ - int c; /* Character of the parsed option. */ - - int error_occurred = 0; - struct gengetopt_args_info local_args_info; - - int override; - int initialize; - int check_required; - int check_ambiguity; - - package_name = argv[0]; - - /* TODO: Why is this here? It is not used anywhere. */ - override = params->override; - FIX_UNUSED(override); - - initialize = params->initialize; - check_required = params->check_required; - - /* TODO: Why is this here? It is not used anywhere. */ - check_ambiguity = params->check_ambiguity; - FIX_UNUSED(check_ambiguity); - - if (initialize) - cmdline_parser_init (args_info); - - cmdline_parser_init (&local_args_info); - - optarg = 0; - optind = 0; - opterr = params->print_errors; - optopt = '?'; - - while (1) - { - int option_index = 0; - - static struct option long_options[] = { - { "help", 0, NULL, 'h' }, - { "version", 0, NULL, 'V' }, - { "reader", 1, NULL, 'r' }, - { "verbose", 0, NULL, 'v' }, - { "pd", 0, NULL, 0 }, - { "vd", 0, NULL, 0 }, - { "gvd", 0, NULL, 0 }, - { "vsd-status", 0, NULL, 0 }, - { 0, 0, 0, 0 } - }; - - c = getopt_long (argc, argv, "hVr:v", long_options, &option_index); - - if (c == -1) break; /* Exit from `while (1)' loop. */ - - switch (c) - { - case 'h': /* Print help and exit. */ - cmdline_parser_print_help (); - cmdline_parser_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'V': /* Print version and exit. */ - cmdline_parser_print_version (); - cmdline_parser_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'r': /* Number of the reader to use. By default, the first reader with a present card is used. If the argument is an ATR, the reader with a matching card will be chosen.. */ - - - if (update_arg( (void *)&(args_info->reader_arg), - &(args_info->reader_orig), &(args_info->reader_given), - &(local_args_info.reader_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "reader", 'r', - additional_error)) - goto failure; - - break; - case 'v': /* Use (several times) to be more verbose. */ - - local_args_info.verbose_given++; - - break; - - case 0: /* Long option with no short option */ - /* Show 'Persönliche Versichertendaten' (XML). */ - if (strcmp (long_options[option_index].name, "pd") == 0) - { - - - if (update_arg((void *)&(args_info->pd_flag), 0, &(args_info->pd_given), - &(local_args_info.pd_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "pd", '-', - additional_error)) - goto failure; - - } - /* Show 'Allgemeine Versichertendaten' (XML). */ - else if (strcmp (long_options[option_index].name, "vd") == 0) - { - - - if (update_arg((void *)&(args_info->vd_flag), 0, &(args_info->vd_given), - &(local_args_info.vd_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "vd", '-', - additional_error)) - goto failure; - - } - /* Show 'Geschützte Versichertendaten' (XML). */ - else if (strcmp (long_options[option_index].name, "gvd") == 0) - { - - - if (update_arg((void *)&(args_info->gvd_flag), 0, &(args_info->gvd_given), - &(local_args_info.gvd_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "gvd", '-', - additional_error)) - goto failure; - - } - /* Show 'Versichertenstammdaten-Status'. */ - else if (strcmp (long_options[option_index].name, "vsd-status") == 0) - { - - - if (update_arg((void *)&(args_info->vsd_status_flag), 0, &(args_info->vsd_status_given), - &(local_args_info.vsd_status_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "vsd-status", '-', - additional_error)) - goto failure; - - } - - break; - case '?': /* Invalid option. */ - /* `getopt_long' already printed an error message. */ - goto failure; - - default: /* bug: option not considered. */ - fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); - abort (); - } /* switch */ - } /* while */ - - - - args_info->verbose_given += local_args_info.verbose_given; - local_args_info.verbose_given = 0; - - if (check_required) - { - error_occurred += cmdline_parser_required2 (args_info, argv[0], additional_error); - } - - cmdline_parser_release (&local_args_info); - - if ( error_occurred ) - return (EXIT_FAILURE); - - return 0; - -failure: - - cmdline_parser_release (&local_args_info); - return (EXIT_FAILURE); -} -/* vim: set ft=c noet ts=8 sts=8 sw=8 tw=80 nojs spell : */ diff --git a/src/tools/egk-tool-cmdline.h b/src/tools/egk-tool-cmdline.h deleted file mode 100644 index ffbc9c8979..0000000000 --- a/src/tools/egk-tool-cmdline.h +++ /dev/null @@ -1,193 +0,0 @@ -/** @file egk-tool-cmdline.h - * @brief The header file for the command line option parser - * generated by GNU Gengetopt version 2.23 - * http://www.gnu.org/software/gengetopt. - * DO NOT modify this file, since it can be overwritten - * @author GNU Gengetopt */ - -#ifndef EGK_TOOL_CMDLINE_H -#define EGK_TOOL_CMDLINE_H - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for FILE */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifndef CMDLINE_PARSER_PACKAGE -/** @brief the program name (used for printing errors) */ -#define CMDLINE_PARSER_PACKAGE "egk-tool" -#endif - -#ifndef CMDLINE_PARSER_PACKAGE_NAME -/** @brief the complete program name (used for help and version) */ -#define CMDLINE_PARSER_PACKAGE_NAME "egk-tool" -#endif - -#ifndef CMDLINE_PARSER_VERSION -/** @brief the program version */ -#define CMDLINE_PARSER_VERSION VERSION -#endif - -/** @brief Where the command line options are stored */ -struct gengetopt_args_info -{ - const char *help_help; /**< @brief Print help and exit help description. */ - const char *version_help; /**< @brief Print version and exit help description. */ - char * reader_arg; /**< @brief Number of the reader to use. By default, the first reader with a present card is used. If the argument is an ATR, the reader with a matching card will be chosen.. */ - char * reader_orig; /**< @brief Number of the reader to use. By default, the first reader with a present card is used. If the argument is an ATR, the reader with a matching card will be chosen. original value given at command line. */ - const char *reader_help; /**< @brief Number of the reader to use. By default, the first reader with a present card is used. If the argument is an ATR, the reader with a matching card will be chosen. help description. */ - unsigned int verbose_min; /**< @brief Use (several times) to be more verbose's minimum occurreces */ - unsigned int verbose_max; /**< @brief Use (several times) to be more verbose's maximum occurreces */ - const char *verbose_help; /**< @brief Use (several times) to be more verbose help description. */ - int pd_flag; /**< @brief Show 'Persönliche Versichertendaten' (XML) (default=off). */ - const char *pd_help; /**< @brief Show 'Persönliche Versichertendaten' (XML) help description. */ - int vd_flag; /**< @brief Show 'Allgemeine Versichertendaten' (XML) (default=off). */ - const char *vd_help; /**< @brief Show 'Allgemeine Versichertendaten' (XML) help description. */ - int gvd_flag; /**< @brief Show 'Geschützte Versichertendaten' (XML) (default=off). */ - const char *gvd_help; /**< @brief Show 'Geschützte Versichertendaten' (XML) help description. */ - int vsd_status_flag; /**< @brief Show 'Versichertenstammdaten-Status' (default=off). */ - const char *vsd_status_help; /**< @brief Show 'Versichertenstammdaten-Status' help description. */ - - unsigned int help_given ; /**< @brief Whether help was given. */ - unsigned int version_given ; /**< @brief Whether version was given. */ - unsigned int reader_given ; /**< @brief Whether reader was given. */ - unsigned int verbose_given ; /**< @brief Whether verbose was given. */ - unsigned int pd_given ; /**< @brief Whether pd was given. */ - unsigned int vd_given ; /**< @brief Whether vd was given. */ - unsigned int gvd_given ; /**< @brief Whether gvd was given. */ - unsigned int vsd_status_given ; /**< @brief Whether vsd-status was given. */ - -} ; - -/** @brief The additional parameters to pass to parser functions */ -struct cmdline_parser_params -{ - int override; /**< @brief whether to override possibly already present options (default 0) */ - int initialize; /**< @brief whether to initialize the option structure gengetopt_args_info (default 1) */ - int check_required; /**< @brief whether to check that all required options were provided (default 1) */ - int check_ambiguity; /**< @brief whether to check for options already specified in the option structure gengetopt_args_info (default 0) */ - int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ -} ; - -/** @brief the purpose string of the program */ -extern const char *gengetopt_args_info_purpose; -/** @brief the usage string of the program */ -extern const char *gengetopt_args_info_usage; -/** @brief the description string of the program */ -extern const char *gengetopt_args_info_description; -/** @brief all the lines making the help output */ -extern const char *gengetopt_args_info_help[]; - -/** - * The command line parser - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser (int argc, char **argv, - struct gengetopt_args_info *args_info); - -/** - * The command line parser (version with additional parameters - deprecated) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_ext() instead - */ -int cmdline_parser2 (int argc, char **argv, - struct gengetopt_args_info *args_info, - int override, int initialize, int check_required); - -/** - * The command line parser (version with additional parameters) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_ext (int argc, char **argv, - struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params); - -/** - * Save the contents of the option struct into an already open FILE stream. - * @param outfile the stream where to dump options - * @param args_info the option struct to dump - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_dump(FILE *outfile, - struct gengetopt_args_info *args_info); - -/** - * Save the contents of the option struct into a (text) file. - * This file can be read by the config file parser (if generated by gengetopt) - * @param filename the file where to save - * @param args_info the option struct to save - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_file_save(const char *filename, - struct gengetopt_args_info *args_info); - -/** - * Print the help - */ -void cmdline_parser_print_help(void); -/** - * Print the version - */ -void cmdline_parser_print_version(void); - -/** - * Initializes all the fields a cmdline_parser_params structure - * to their default values - * @param params the structure to initialize - */ -void cmdline_parser_params_init(struct cmdline_parser_params *params); - -/** - * Allocates dynamically a cmdline_parser_params structure and initializes - * all its fields to their default values - * @return the created and initialized cmdline_parser_params structure - */ -struct cmdline_parser_params *cmdline_parser_params_create(void); - -/** - * Initializes the passed gengetopt_args_info structure's fields - * (also set default values for options that have a default) - * @param args_info the structure to initialize - */ -void cmdline_parser_init (struct gengetopt_args_info *args_info); -/** - * Deallocates the string fields of the gengetopt_args_info structure - * (but does not deallocate the structure itself) - * @param args_info the structure to deallocate - */ -void cmdline_parser_free (struct gengetopt_args_info *args_info); - -/** - * Checks that all the required options were specified - * @param args_info the structure to check - * @param prog_name the name of the program that will be used to print - * possible errors - * @return - */ -int cmdline_parser_required (struct gengetopt_args_info *args_info, - const char *prog_name); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* EGK_TOOL_CMDLINE_H */ diff --git a/src/tools/goid-tool-cmdline.c b/src/tools/goid-tool-cmdline.c deleted file mode 100644 index 459e10e2f6..0000000000 --- a/src/tools/goid-tool-cmdline.c +++ /dev/null @@ -1,1649 +0,0 @@ -/* - File autogenerated by gengetopt version 2.23 - generated with the following command: - /opt/homebrew/bin/gengetopt --file-name=goid-tool-cmdline --output-dir=. - - The developers of gengetopt consider the fixed text that goes in all - gengetopt output files to be in the public domain: - we make no copyright claims on it. -*/ - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#ifndef FIX_UNUSED -#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ -#endif - -#include - -#include "goid-tool-cmdline.h" - -const char *gengetopt_args_info_purpose = ""; - -const char *gengetopt_args_info_usage = "Usage: goid-tool [OPTION]..."; - -const char *gengetopt_args_info_versiontext = ""; - -const char *gengetopt_args_info_description = ""; - -const char *gengetopt_args_info_help[] = { - " -h, --help Print help and exit", - " -V, --version Print version and exit", - " -r, --reader=STRING Number of the reader to use. By default, the\n first reader with a present card is used. If\n the argument is an ATR, the reader with a\n matching card will be chosen.", - " -v, --verbose Use (several times) to be more verbose", - " -p, --verify-pin Verify PIN", - " -b, --verify-bio Verify finger print", - " --verify-pin-or-bio Verify PIN or finger print (user's choice)", - "\nReport bugs to https://github.com/OpenSC/OpenSC/issues\n\nWritten by Frank Morgner ", - "\n Mode: soc\n Options for SoCManager Applet", - " --new-pin Change PIN", - " --new-bio Use (several times) to change one or more\n biometric templates", - " --info Dump Information about the SoCManager's\n configuration", - "\n Mode: pxs\n Options for PAccess Applet", - " -c, --certificate=FILENAME Use (several times) to pass CV certificates", - " -k, --key=FILENAME Private key for the CV certificate", - " --print-cardid Print the card ID", - " --write-cardid=CARDID Write the specified card ID", - " --print-paccessid Print the PAccess ID", - " --write-paccessid=PACCESSID\n Write the specified PAccess ID", - " --read-dg=ID Read the specified data group; use several\n times to read out multiple files", - " --out-file=FILENAME Write output to a file instead of printing it;\n use once for each use of `--read-dg'", - " --write-dg=ID Write the specified data group; use several\n times to write multiple files", - " --in-file=FILENAME Read input from a file; use once for each use\n of `--write-dg'", - " --delete-dg=ID Delete the specified data group; use several\n times to delete multiple files", - " --create-dg=ID Create the specified data group; use several\n times to create multiple files", - " --new-size=SIZE File size of newly created DGs (default=`256')", - " --new-read-ac=STRING Access condition for reading newly created DGs\n (possible values=\"always\", \"never\",\n \"ta\", \"sm\" default=`sm')", - " --new-read-ac-chatbit=INDEX\n Required access bit in certificate's CHAT for\n reading newly created DGs", - " --new-write-ac=STRING Access condition for writing newly created DGs\n (possible values=\"always\", \"never\",\n \"ta\", \"sm\" default=`sm')", - " --new-write-ac-chatbit=INDEX\n Required access bit in certificate's CHAT for\n reading newly created DGs", - 0 -}; - -typedef enum {ARG_NO - , ARG_STRING - , ARG_SHORT -} cmdline_parser_arg_type; - -static -void clear_given (struct gengetopt_args_info *args_info); -static -void clear_args (struct gengetopt_args_info *args_info); - -static int -cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params, const char *additional_error); - -static int -cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error); - -const char *cmdline_parser_new_read_ac_values[] = {"always", "never", "ta", "sm", 0}; /*< Possible values for new-read-ac. */ -const char *cmdline_parser_new_write_ac_values[] = {"always", "never", "ta", "sm", 0}; /*< Possible values for new-write-ac. */ - -static char * -gengetopt_strdup (const char *s); - -static -void clear_given (struct gengetopt_args_info *args_info) -{ - args_info->help_given = 0 ; - args_info->version_given = 0 ; - args_info->reader_given = 0 ; - args_info->verbose_given = 0 ; - args_info->verify_pin_given = 0 ; - args_info->verify_bio_given = 0 ; - args_info->verify_pin_or_bio_given = 0 ; - args_info->new_pin_given = 0 ; - args_info->new_bio_given = 0 ; - args_info->info_given = 0 ; - args_info->certificate_given = 0 ; - args_info->key_given = 0 ; - args_info->print_cardid_given = 0 ; - args_info->write_cardid_given = 0 ; - args_info->print_paccessid_given = 0 ; - args_info->write_paccessid_given = 0 ; - args_info->read_dg_given = 0 ; - args_info->out_file_given = 0 ; - args_info->write_dg_given = 0 ; - args_info->in_file_given = 0 ; - args_info->delete_dg_given = 0 ; - args_info->create_dg_given = 0 ; - args_info->new_size_given = 0 ; - args_info->new_read_ac_given = 0 ; - args_info->new_read_ac_chatbit_given = 0 ; - args_info->new_write_ac_given = 0 ; - args_info->new_write_ac_chatbit_given = 0 ; - args_info->pxs_mode_counter = 0 ; - args_info->soc_mode_counter = 0 ; -} - -static -void clear_args (struct gengetopt_args_info *args_info) -{ - FIX_UNUSED (args_info); - args_info->reader_arg = NULL; - args_info->reader_orig = NULL; - args_info->certificate_arg = NULL; - args_info->certificate_orig = NULL; - args_info->key_arg = NULL; - args_info->key_orig = NULL; - args_info->write_cardid_arg = NULL; - args_info->write_cardid_orig = NULL; - args_info->write_paccessid_arg = NULL; - args_info->write_paccessid_orig = NULL; - args_info->read_dg_arg = NULL; - args_info->read_dg_orig = NULL; - args_info->out_file_arg = NULL; - args_info->out_file_orig = NULL; - args_info->write_dg_arg = NULL; - args_info->write_dg_orig = NULL; - args_info->in_file_arg = NULL; - args_info->in_file_orig = NULL; - args_info->delete_dg_arg = NULL; - args_info->delete_dg_orig = NULL; - args_info->create_dg_arg = NULL; - args_info->create_dg_orig = NULL; - args_info->new_size_arg = 256; - args_info->new_size_orig = NULL; - args_info->new_read_ac_arg = gengetopt_strdup ("sm"); - args_info->new_read_ac_orig = NULL; - args_info->new_read_ac_chatbit_arg = NULL; - args_info->new_read_ac_chatbit_orig = NULL; - args_info->new_write_ac_arg = gengetopt_strdup ("sm"); - args_info->new_write_ac_orig = NULL; - args_info->new_write_ac_chatbit_arg = NULL; - args_info->new_write_ac_chatbit_orig = NULL; - -} - -static -void init_args_info(struct gengetopt_args_info *args_info) -{ - - - args_info->help_help = gengetopt_args_info_help[0] ; - args_info->version_help = gengetopt_args_info_help[1] ; - args_info->reader_help = gengetopt_args_info_help[2] ; - args_info->verbose_help = gengetopt_args_info_help[3] ; - args_info->verbose_min = 0; - args_info->verbose_max = 0; - args_info->verify_pin_help = gengetopt_args_info_help[4] ; - args_info->verify_bio_help = gengetopt_args_info_help[5] ; - args_info->verify_pin_or_bio_help = gengetopt_args_info_help[6] ; - args_info->new_pin_help = gengetopt_args_info_help[9] ; - args_info->new_bio_help = gengetopt_args_info_help[10] ; - args_info->new_bio_min = 0; - args_info->new_bio_max = 0; - args_info->info_help = gengetopt_args_info_help[11] ; - args_info->certificate_help = gengetopt_args_info_help[13] ; - args_info->certificate_min = 0; - args_info->certificate_max = 0; - args_info->key_help = gengetopt_args_info_help[14] ; - args_info->print_cardid_help = gengetopt_args_info_help[15] ; - args_info->write_cardid_help = gengetopt_args_info_help[16] ; - args_info->print_paccessid_help = gengetopt_args_info_help[17] ; - args_info->write_paccessid_help = gengetopt_args_info_help[18] ; - args_info->read_dg_help = gengetopt_args_info_help[19] ; - args_info->read_dg_min = 0; - args_info->read_dg_max = 0; - args_info->out_file_help = gengetopt_args_info_help[20] ; - args_info->out_file_min = 0; - args_info->out_file_max = 0; - args_info->write_dg_help = gengetopt_args_info_help[21] ; - args_info->write_dg_min = 0; - args_info->write_dg_max = 0; - args_info->in_file_help = gengetopt_args_info_help[22] ; - args_info->in_file_min = 0; - args_info->in_file_max = 0; - args_info->delete_dg_help = gengetopt_args_info_help[23] ; - args_info->delete_dg_min = 0; - args_info->delete_dg_max = 0; - args_info->create_dg_help = gengetopt_args_info_help[24] ; - args_info->create_dg_min = 0; - args_info->create_dg_max = 0; - args_info->new_size_help = gengetopt_args_info_help[25] ; - args_info->new_read_ac_help = gengetopt_args_info_help[26] ; - args_info->new_read_ac_chatbit_help = gengetopt_args_info_help[27] ; - args_info->new_read_ac_chatbit_min = 0; - args_info->new_read_ac_chatbit_max = 0; - args_info->new_write_ac_help = gengetopt_args_info_help[28] ; - args_info->new_write_ac_chatbit_help = gengetopt_args_info_help[29] ; - args_info->new_write_ac_chatbit_min = 0; - args_info->new_write_ac_chatbit_max = 0; - -} - -void -cmdline_parser_print_version (void) -{ - printf ("%s %s\n", - (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE), - CMDLINE_PARSER_VERSION); - - if (strlen(gengetopt_args_info_versiontext) > 0) - printf("\n%s\n", gengetopt_args_info_versiontext); -} - -static void print_help_common(void) -{ - size_t len_purpose = strlen(gengetopt_args_info_purpose); - size_t len_usage = strlen(gengetopt_args_info_usage); - - if (len_usage > 0) { - printf("%s\n", gengetopt_args_info_usage); - } - if (len_purpose > 0) { - printf("%s\n", gengetopt_args_info_purpose); - } - - if (len_usage || len_purpose) { - printf("\n"); - } - - if (strlen(gengetopt_args_info_description) > 0) { - printf("%s\n\n", gengetopt_args_info_description); - } -} - -void -cmdline_parser_print_help (void) -{ - int i = 0; - print_help_common(); - while (gengetopt_args_info_help[i]) - printf("%s\n", gengetopt_args_info_help[i++]); -} - -void -cmdline_parser_init (struct gengetopt_args_info *args_info) -{ - clear_given (args_info); - clear_args (args_info); - init_args_info (args_info); -} - -void -cmdline_parser_params_init(struct cmdline_parser_params *params) -{ - if (params) - { - params->override = 0; - params->initialize = 1; - params->check_required = 1; - params->check_ambiguity = 0; - params->print_errors = 1; - } -} - -struct cmdline_parser_params * -cmdline_parser_params_create(void) -{ - struct cmdline_parser_params *params = - (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); - cmdline_parser_params_init(params); - return params; -} - -static void -free_string_field (char **s) -{ - if (*s) - { - free (*s); - *s = 0; - } -} - -/** @brief generic value variable */ -union generic_value { - short short_arg; - char *string_arg; - const char *default_string_arg; -}; - -/** @brief holds temporary values for multiple options */ -struct generic_list -{ - union generic_value arg; - char *orig; - struct generic_list *next; -}; - -/** - * @brief add a node at the head of the list - */ -static void add_node(struct generic_list **list) { - struct generic_list *new_node = (struct generic_list *) malloc (sizeof (struct generic_list)); - new_node->next = *list; - *list = new_node; - new_node->arg.string_arg = 0; - new_node->orig = 0; -} - -/** - * The passed arg parameter is NOT set to 0 from this function - */ -static void -free_multiple_field(unsigned int len, void *arg, char ***orig) -{ - unsigned int i; - if (arg) { - for (i = 0; i < len; ++i) - { - free_string_field(&((*orig)[i])); - } - - free (arg); - free (*orig); - *orig = 0; - } -} - -static void -free_multiple_string_field(unsigned int len, char ***arg, char ***orig) -{ - unsigned int i; - if (*arg) { - for (i = 0; i < len; ++i) - { - free_string_field(&((*arg)[i])); - free_string_field(&((*orig)[i])); - } - free_string_field(&((*arg)[0])); /* free default string */ - - free (*arg); - *arg = 0; - free (*orig); - *orig = 0; - } -} - -static void -cmdline_parser_release (struct gengetopt_args_info *args_info) -{ - - free_string_field (&(args_info->reader_arg)); - free_string_field (&(args_info->reader_orig)); - free_multiple_string_field (args_info->certificate_given, &(args_info->certificate_arg), &(args_info->certificate_orig)); - free_string_field (&(args_info->key_arg)); - free_string_field (&(args_info->key_orig)); - free_string_field (&(args_info->write_cardid_arg)); - free_string_field (&(args_info->write_cardid_orig)); - free_string_field (&(args_info->write_paccessid_arg)); - free_string_field (&(args_info->write_paccessid_orig)); - free_multiple_field (args_info->read_dg_given, (void *)(args_info->read_dg_arg), &(args_info->read_dg_orig)); - args_info->read_dg_arg = 0; - free_multiple_string_field (args_info->out_file_given, &(args_info->out_file_arg), &(args_info->out_file_orig)); - free_multiple_field (args_info->write_dg_given, (void *)(args_info->write_dg_arg), &(args_info->write_dg_orig)); - args_info->write_dg_arg = 0; - free_multiple_string_field (args_info->in_file_given, &(args_info->in_file_arg), &(args_info->in_file_orig)); - free_multiple_field (args_info->delete_dg_given, (void *)(args_info->delete_dg_arg), &(args_info->delete_dg_orig)); - args_info->delete_dg_arg = 0; - free_multiple_field (args_info->create_dg_given, (void *)(args_info->create_dg_arg), &(args_info->create_dg_orig)); - args_info->create_dg_arg = 0; - free_string_field (&(args_info->new_size_orig)); - free_string_field (&(args_info->new_read_ac_arg)); - free_string_field (&(args_info->new_read_ac_orig)); - free_multiple_field (args_info->new_read_ac_chatbit_given, (void *)(args_info->new_read_ac_chatbit_arg), &(args_info->new_read_ac_chatbit_orig)); - args_info->new_read_ac_chatbit_arg = 0; - free_string_field (&(args_info->new_write_ac_arg)); - free_string_field (&(args_info->new_write_ac_orig)); - free_multiple_field (args_info->new_write_ac_chatbit_given, (void *)(args_info->new_write_ac_chatbit_arg), &(args_info->new_write_ac_chatbit_orig)); - args_info->new_write_ac_chatbit_arg = 0; - - - - clear_given (args_info); -} - -/** - * @param val the value to check - * @param values the possible values - * @return the index of the matched value: - * -1 if no value matched, - * -2 if more than one value has matched - */ -static int -check_possible_values(const char *val, const char *values[]) -{ - int i, found, last; - size_t len; - - if (!val) /* otherwise strlen() crashes below */ - return -1; /* -1 means no argument for the option */ - - found = last = 0; - - for (i = 0, len = strlen(val); values[i]; ++i) - { - if (strncmp(val, values[i], len) == 0) - { - ++found; - last = i; - if (strlen(values[i]) == len) - return i; /* exact macth no need to check more */ - } - } - - if (found == 1) /* one match: OK */ - return last; - - return (found ? -2 : -1); /* return many values or none matched */ -} - - -static void -write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) -{ - int found = -1; - if (arg) { - if (values) { - found = check_possible_values(arg, values); - } - if (found >= 0) - fprintf(outfile, "%s=\"%s\" # %s\n", opt, arg, values[found]); - else - fprintf(outfile, "%s=\"%s\"\n", opt, arg); - } else { - fprintf(outfile, "%s\n", opt); - } -} - -static void -write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, const char *values[]) -{ - int i; - - for (i = 0; i < len; ++i) - write_into_file(outfile, opt, (arg ? arg[i] : 0), values); -} - -int -cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) -{ - int i = 0; - - if (!outfile) - { - fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE); - return EXIT_FAILURE; - } - - if (args_info->help_given) - write_into_file(outfile, "help", 0, 0 ); - if (args_info->version_given) - write_into_file(outfile, "version", 0, 0 ); - if (args_info->reader_given) - write_into_file(outfile, "reader", args_info->reader_orig, 0); - write_multiple_into_file(outfile, args_info->verbose_given, "verbose", 0, 0); - if (args_info->verify_pin_given) - write_into_file(outfile, "verify-pin", 0, 0 ); - if (args_info->verify_bio_given) - write_into_file(outfile, "verify-bio", 0, 0 ); - if (args_info->verify_pin_or_bio_given) - write_into_file(outfile, "verify-pin-or-bio", 0, 0 ); - if (args_info->new_pin_given) - write_into_file(outfile, "new-pin", 0, 0 ); - write_multiple_into_file(outfile, args_info->new_bio_given, "new-bio", 0, 0); - if (args_info->info_given) - write_into_file(outfile, "info", 0, 0 ); - write_multiple_into_file(outfile, args_info->certificate_given, "certificate", args_info->certificate_orig, 0); - if (args_info->key_given) - write_into_file(outfile, "key", args_info->key_orig, 0); - if (args_info->print_cardid_given) - write_into_file(outfile, "print-cardid", 0, 0 ); - if (args_info->write_cardid_given) - write_into_file(outfile, "write-cardid", args_info->write_cardid_orig, 0); - if (args_info->print_paccessid_given) - write_into_file(outfile, "print-paccessid", 0, 0 ); - if (args_info->write_paccessid_given) - write_into_file(outfile, "write-paccessid", args_info->write_paccessid_orig, 0); - write_multiple_into_file(outfile, args_info->read_dg_given, "read-dg", args_info->read_dg_orig, 0); - write_multiple_into_file(outfile, args_info->out_file_given, "out-file", args_info->out_file_orig, 0); - write_multiple_into_file(outfile, args_info->write_dg_given, "write-dg", args_info->write_dg_orig, 0); - write_multiple_into_file(outfile, args_info->in_file_given, "in-file", args_info->in_file_orig, 0); - write_multiple_into_file(outfile, args_info->delete_dg_given, "delete-dg", args_info->delete_dg_orig, 0); - write_multiple_into_file(outfile, args_info->create_dg_given, "create-dg", args_info->create_dg_orig, 0); - if (args_info->new_size_given) - write_into_file(outfile, "new-size", args_info->new_size_orig, 0); - if (args_info->new_read_ac_given) - write_into_file(outfile, "new-read-ac", args_info->new_read_ac_orig, cmdline_parser_new_read_ac_values); - write_multiple_into_file(outfile, args_info->new_read_ac_chatbit_given, "new-read-ac-chatbit", args_info->new_read_ac_chatbit_orig, 0); - if (args_info->new_write_ac_given) - write_into_file(outfile, "new-write-ac", args_info->new_write_ac_orig, cmdline_parser_new_write_ac_values); - write_multiple_into_file(outfile, args_info->new_write_ac_chatbit_given, "new-write-ac-chatbit", args_info->new_write_ac_chatbit_orig, 0); - - - i = EXIT_SUCCESS; - return i; -} - -int -cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) -{ - FILE *outfile; - int i = 0; - - outfile = fopen(filename, "w"); - - if (!outfile) - { - fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); - return EXIT_FAILURE; - } - - i = cmdline_parser_dump(outfile, args_info); - fclose (outfile); - - return i; -} - -void -cmdline_parser_free (struct gengetopt_args_info *args_info) -{ - cmdline_parser_release (args_info); -} - -/** @brief replacement of strdup, which is not standard */ -char * -gengetopt_strdup (const char *s) -{ - char *result = 0; - if (!s) - return result; - - result = (char*)malloc(strlen(s) + 1); - if (result == (char*)0) - return (char*)0; - strcpy(result, s); - return result; -} - -static char * -get_multiple_arg_token(const char *arg) -{ - const char *tok; - char *ret; - size_t len, num_of_escape, i, j; - - if (!arg) - return 0; - - tok = strchr (arg, ','); - num_of_escape = 0; - - /* make sure it is not escaped */ - while (tok) - { - if (*(tok-1) == '\\') - { - /* find the next one */ - tok = strchr (tok+1, ','); - ++num_of_escape; - } - else - break; - } - - if (tok) - len = (size_t)(tok - arg + 1); - else - len = strlen (arg) + 1; - - len -= num_of_escape; - - ret = (char *) malloc (len); - - i = 0; - j = 0; - while (arg[i] && (j < len-1)) - { - if (arg[i] == '\\' && - arg[ i + 1 ] && - arg[ i + 1 ] == ',') - ++i; - - ret[j++] = arg[i++]; - } - - ret[len-1] = '\0'; - - return ret; -} - -static const char * -get_multiple_arg_token_next(const char *arg) -{ - const char *tok; - - if (!arg) - return 0; - - tok = strchr (arg, ','); - - /* make sure it is not escaped */ - while (tok) - { - if (*(tok-1) == '\\') - { - /* find the next one */ - tok = strchr (tok+1, ','); - } - else - break; - } - - if (! tok || strlen(tok) == 1) - return 0; - - return tok+1; -} - -static int -check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc); - -int -check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc) -{ - int error_occurred = 0; - - if (option_given && (min > 0 || max > 0)) - { - if (min > 0 && max > 0) - { - if (min == max) - { - /* specific occurrences */ - if (option_given != (unsigned int) min) - { - fprintf (stderr, "%s: %s option occurrences must be %d\n", - prog_name, option_desc, min); - error_occurred = 1; - } - } - else if (option_given < (unsigned int) min - || option_given > (unsigned int) max) - { - /* range occurrences */ - fprintf (stderr, "%s: %s option occurrences must be between %d and %d\n", - prog_name, option_desc, min, max); - error_occurred = 1; - } - } - else if (min > 0) - { - /* at least check */ - if (option_given < min) - { - fprintf (stderr, "%s: %s option occurrences must be at least %d\n", - prog_name, option_desc, min); - error_occurred = 1; - } - } - else if (max > 0) - { - /* at most check */ - if (option_given > max) - { - fprintf (stderr, "%s: %s option occurrences must be at most %d\n", - prog_name, option_desc, max); - error_occurred = 1; - } - } - } - - return error_occurred; -} -int -cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info) -{ - return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); -} - -int -cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params) -{ - int result; - result = cmdline_parser_internal (argc, argv, args_info, params, 0); - - if (result == EXIT_FAILURE) - { - cmdline_parser_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) -{ - int result; - struct cmdline_parser_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0); - - if (result == EXIT_FAILURE) - { - cmdline_parser_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) -{ - int result = EXIT_SUCCESS; - - if (cmdline_parser_required2(args_info, prog_name, 0) > 0) - result = EXIT_FAILURE; - - if (result == EXIT_FAILURE) - { - cmdline_parser_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error) -{ - int error_occurred = 0; - FIX_UNUSED (additional_error); - - /* checks for required options */ - if (check_multiple_option_occurrences(prog_name, args_info->verbose_given, args_info->verbose_min, args_info->verbose_max, "'--verbose' ('-v')")) - error_occurred = 1; - - if (args_info->soc_mode_counter && check_multiple_option_occurrences(prog_name, args_info->new_bio_given, args_info->new_bio_min, args_info->new_bio_max, "'--new-bio'")) - error_occurred = 1; - - if (args_info->pxs_mode_counter && check_multiple_option_occurrences(prog_name, args_info->certificate_given, args_info->certificate_min, args_info->certificate_max, "'--certificate' ('-c')")) - error_occurred = 1; - - if (args_info->pxs_mode_counter && check_multiple_option_occurrences(prog_name, args_info->read_dg_given, args_info->read_dg_min, args_info->read_dg_max, "'--read-dg'")) - error_occurred = 1; - - if (args_info->pxs_mode_counter && check_multiple_option_occurrences(prog_name, args_info->out_file_given, args_info->out_file_min, args_info->out_file_max, "'--out-file'")) - error_occurred = 1; - - if (args_info->pxs_mode_counter && check_multiple_option_occurrences(prog_name, args_info->write_dg_given, args_info->write_dg_min, args_info->write_dg_max, "'--write-dg'")) - error_occurred = 1; - - if (args_info->pxs_mode_counter && check_multiple_option_occurrences(prog_name, args_info->in_file_given, args_info->in_file_min, args_info->in_file_max, "'--in-file'")) - error_occurred = 1; - - if (args_info->pxs_mode_counter && check_multiple_option_occurrences(prog_name, args_info->delete_dg_given, args_info->delete_dg_min, args_info->delete_dg_max, "'--delete-dg'")) - error_occurred = 1; - - if (args_info->pxs_mode_counter && check_multiple_option_occurrences(prog_name, args_info->create_dg_given, args_info->create_dg_min, args_info->create_dg_max, "'--create-dg'")) - error_occurred = 1; - - if (args_info->pxs_mode_counter && check_multiple_option_occurrences(prog_name, args_info->new_read_ac_chatbit_given, args_info->new_read_ac_chatbit_min, args_info->new_read_ac_chatbit_max, "'--new-read-ac-chatbit'")) - error_occurred = 1; - - if (args_info->pxs_mode_counter && check_multiple_option_occurrences(prog_name, args_info->new_write_ac_chatbit_given, args_info->new_write_ac_chatbit_min, args_info->new_write_ac_chatbit_max, "'--new-write-ac-chatbit'")) - error_occurred = 1; - - - /* checks for dependences among options */ - if (args_info->certificate_given && ! args_info->key_given) - { - fprintf (stderr, "%s: '--certificate' ('-c') option depends on option 'key'%s\n", prog_name, (additional_error ? additional_error : "")); - error_occurred = 1; - } - if (args_info->key_given && ! args_info->certificate_given) - { - fprintf (stderr, "%s: '--key' ('-k') option depends on option 'certificate'%s\n", prog_name, (additional_error ? additional_error : "")); - error_occurred = 1; - } - if (args_info->new_size_given && ! args_info->create_dg_given) - { - fprintf (stderr, "%s: '--new-size' option depends on option 'create-dg'%s\n", prog_name, (additional_error ? additional_error : "")); - error_occurred = 1; - } - if (args_info->new_read_ac_given && ! args_info->create_dg_given) - { - fprintf (stderr, "%s: '--new-read-ac' option depends on option 'create-dg'%s\n", prog_name, (additional_error ? additional_error : "")); - error_occurred = 1; - } - if (args_info->new_read_ac_chatbit_given && ! args_info->create_dg_given) - { - fprintf (stderr, "%s: '--new-read-ac-chatbit' option depends on option 'create-dg'%s\n", prog_name, (additional_error ? additional_error : "")); - error_occurred = 1; - } - if (args_info->new_write_ac_given && ! args_info->create_dg_given) - { - fprintf (stderr, "%s: '--new-write-ac' option depends on option 'create-dg'%s\n", prog_name, (additional_error ? additional_error : "")); - error_occurred = 1; - } - if (args_info->new_write_ac_chatbit_given && ! args_info->create_dg_given) - { - fprintf (stderr, "%s: '--new-write-ac-chatbit' option depends on option 'create-dg'%s\n", prog_name, (additional_error ? additional_error : "")); - error_occurred = 1; - } - - return error_occurred; -} - - -static char *package_name = 0; - -/** - * @brief updates an option - * @param field the generic pointer to the field to update - * @param orig_field the pointer to the orig field - * @param field_given the pointer to the number of occurrence of this option - * @param prev_given the pointer to the number of occurrence already seen - * @param value the argument for this option (if null no arg was specified) - * @param possible_values the possible values for this option (if specified) - * @param default_value the default value (in case the option only accepts fixed values) - * @param arg_type the type of this option - * @param check_ambiguity @see cmdline_parser_params.check_ambiguity - * @param override @see cmdline_parser_params.override - * @param no_free whether to free a possible previous value - * @param multiple_option whether this is a multiple option - * @param long_opt the corresponding long option - * @param short_opt the corresponding short option (or '-' if none) - * @param additional_error possible further error specification - */ -static -int update_arg(void *field, char **orig_field, - unsigned int *field_given, unsigned int *prev_given, - char *value, const char *possible_values[], - const char *default_value, - cmdline_parser_arg_type arg_type, - int check_ambiguity, int override, - int no_free, int multiple_option, - const char *long_opt, char short_opt, - const char *additional_error) -{ - char *stop_char = 0; - const char *val = value; - int found; - char **string_field; - FIX_UNUSED (field); - - stop_char = 0; - found = 0; - - if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) - { - if (short_opt != '-') - fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", - package_name, long_opt, short_opt, - (additional_error ? additional_error : "")); - else - fprintf (stderr, "%s: `--%s' option given more than once%s\n", - package_name, long_opt, - (additional_error ? additional_error : "")); - return 1; /* failure */ - } - - if (possible_values && (found = check_possible_values((value ? value : default_value), possible_values)) < 0) - { - if (short_opt != '-') - fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s' (`-%c')%s\n", - package_name, (found == -2) ? "ambiguous" : "invalid", value, long_opt, short_opt, - (additional_error ? additional_error : "")); - else - fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s'%s\n", - package_name, (found == -2) ? "ambiguous" : "invalid", value, long_opt, - (additional_error ? additional_error : "")); - return 1; /* failure */ - } - - if (field_given && *field_given && ! override) - return 0; - if (prev_given) - (*prev_given)++; - if (field_given) - (*field_given)++; - if (possible_values) - val = possible_values[found]; - - switch(arg_type) { - case ARG_SHORT: - if (val) *((short *)field) = (short)strtol (val, &stop_char, 0); - break; - case ARG_STRING: - if (val) { - string_field = (char **)field; - if (!no_free && *string_field) - free (*string_field); /* free previous string */ - *string_field = gengetopt_strdup (val); - } - break; - default: - break; - }; - - /* check numeric conversion */ - switch(arg_type) { - case ARG_SHORT: - if (val && !(stop_char && *stop_char == '\0')) { - fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); - return 1; /* failure */ - } - break; - default: - ; - }; - - /* store the original value */ - switch(arg_type) { - case ARG_NO: - break; - default: - if (value && orig_field) { - if (no_free) { - *orig_field = value; - } else { - if (*orig_field) - free (*orig_field); /* free previous string */ - *orig_field = gengetopt_strdup (value); - } - } - }; - - return 0; /* OK */ -} - -/** - * @brief store information about a multiple option in a temporary list - * @param list where to (temporarily) store multiple options - */ -static -int update_multiple_arg_temp(struct generic_list **list, - unsigned int *prev_given, const char *val, - const char *possible_values[], const char *default_value, - cmdline_parser_arg_type arg_type, - const char *long_opt, char short_opt, - const char *additional_error) -{ - /* store single arguments */ - char *multi_token; - const char *multi_next; - - if (arg_type == ARG_NO) { - (*prev_given)++; - return 0; /* OK */ - } - - multi_token = get_multiple_arg_token(val); - multi_next = get_multiple_arg_token_next (val); - - while (1) - { - add_node (list); - if (update_arg((void *)&((*list)->arg), &((*list)->orig), 0, - prev_given, multi_token, possible_values, default_value, - arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) { - if (multi_token) free(multi_token); - return 1; /* failure */ - } - - if (multi_next) - { - multi_token = get_multiple_arg_token(multi_next); - multi_next = get_multiple_arg_token_next (multi_next); - } - else - break; - } - - return 0; /* OK */ -} - -/** - * @brief free the passed list (including possible string argument) - */ -static -void free_list(struct generic_list *list, short string_arg) -{ - if (list) { - struct generic_list *tmp; - while (list) - { - tmp = list; - if (string_arg && list->arg.string_arg) - free (list->arg.string_arg); - if (list->orig) - free (list->orig); - list = list->next; - free (tmp); - } - } -} - -/** - * @brief updates a multiple option starting from the passed list - */ -static -void update_multiple_arg(void *field, char ***orig_field, - unsigned int field_given, unsigned int prev_given, union generic_value *default_value, - cmdline_parser_arg_type arg_type, - struct generic_list *list) -{ - int i; - struct generic_list *tmp; - - if (prev_given && list) { - *orig_field = (char **) realloc (*orig_field, (field_given + prev_given) * sizeof (char *)); - - switch(arg_type) { - case ARG_SHORT: - *((short **)field) = (short *)realloc (*((short **)field), (field_given + prev_given) * sizeof (short)); break; - case ARG_STRING: - *((char ***)field) = (char **)realloc (*((char ***)field), (field_given + prev_given) * sizeof (char *)); break; - default: - break; - }; - - for (i = (prev_given - 1); i >= 0; --i) - { - tmp = list; - - switch(arg_type) { - case ARG_SHORT: - (*((short **)field))[i + field_given] = tmp->arg.short_arg; break; - case ARG_STRING: - (*((char ***)field))[i + field_given] = tmp->arg.string_arg; break; - default: - break; - } - (*orig_field) [i + field_given] = list->orig; - list = list->next; - free (tmp); - } - } else { /* set the default value */ - if (default_value && ! field_given) { - switch(arg_type) { - case ARG_SHORT: - if (! *((short **)field)) { - *((short **)field) = (short *)malloc (sizeof (short)); - (*((short **)field))[0] = default_value->short_arg; - } - break; - case ARG_STRING: - if (! *((char ***)field)) { - *((char ***)field) = (char **)malloc (sizeof (char *)); - (*((char ***)field))[0] = gengetopt_strdup(default_value->string_arg); - } - break; - default: break; - } - if (!(*orig_field)) { - *orig_field = (char **) malloc (sizeof (char *)); - (*orig_field)[0] = 0; - } - } - } -} - -static int check_modes( - int given1[], const char *options1[], - int given2[], const char *options2[]) -{ - int i = 0, j = 0, errors = 0; - - while (given1[i] >= 0) { - if (given1[i]) { - while (given2[j] >= 0) { - if (given2[j]) { - ++errors; - fprintf(stderr, "%s: option %s conflicts with option %s\n", - package_name, options1[i], options2[j]); - } - ++j; - } - } - ++i; - } - - return errors; -} - -int -cmdline_parser_internal ( - int argc, char **argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params, const char *additional_error) -{ - int c; /* Character of the parsed option. */ - - struct generic_list * certificate_list = NULL; - struct generic_list * read_dg_list = NULL; - struct generic_list * out_file_list = NULL; - struct generic_list * write_dg_list = NULL; - struct generic_list * in_file_list = NULL; - struct generic_list * delete_dg_list = NULL; - struct generic_list * create_dg_list = NULL; - struct generic_list * new_read_ac_chatbit_list = NULL; - struct generic_list * new_write_ac_chatbit_list = NULL; - int error_occurred = 0; - struct gengetopt_args_info local_args_info; - - int override; - int initialize; - int check_required; - int check_ambiguity; - - package_name = argv[0]; - - /* TODO: Why is this here? It is not used anywhere. */ - override = params->override; - FIX_UNUSED(override); - - initialize = params->initialize; - check_required = params->check_required; - - /* TODO: Why is this here? It is not used anywhere. */ - check_ambiguity = params->check_ambiguity; - FIX_UNUSED(check_ambiguity); - - if (initialize) - cmdline_parser_init (args_info); - - cmdline_parser_init (&local_args_info); - - optarg = 0; - optind = 0; - opterr = params->print_errors; - optopt = '?'; - - while (1) - { - int option_index = 0; - - static struct option long_options[] = { - { "help", 0, NULL, 'h' }, - { "version", 0, NULL, 'V' }, - { "reader", 1, NULL, 'r' }, - { "verbose", 0, NULL, 'v' }, - { "verify-pin", 0, NULL, 'p' }, - { "verify-bio", 0, NULL, 'b' }, - { "verify-pin-or-bio", 0, NULL, 0 }, - { "new-pin", 0, NULL, 0 }, - { "new-bio", 0, NULL, 0 }, - { "info", 0, NULL, 0 }, - { "certificate", 1, NULL, 'c' }, - { "key", 1, NULL, 'k' }, - { "print-cardid", 0, NULL, 0 }, - { "write-cardid", 1, NULL, 0 }, - { "print-paccessid", 0, NULL, 0 }, - { "write-paccessid", 1, NULL, 0 }, - { "read-dg", 1, NULL, 0 }, - { "out-file", 1, NULL, 0 }, - { "write-dg", 1, NULL, 0 }, - { "in-file", 1, NULL, 0 }, - { "delete-dg", 1, NULL, 0 }, - { "create-dg", 1, NULL, 0 }, - { "new-size", 1, NULL, 0 }, - { "new-read-ac", 1, NULL, 0 }, - { "new-read-ac-chatbit", 1, NULL, 0 }, - { "new-write-ac", 1, NULL, 0 }, - { "new-write-ac-chatbit", 1, NULL, 0 }, - { 0, 0, 0, 0 } - }; - - c = getopt_long (argc, argv, "hVr:vpbc:k:", long_options, &option_index); - - if (c == -1) break; /* Exit from `while (1)' loop. */ - - switch (c) - { - case 'h': /* Print help and exit. */ - cmdline_parser_print_help (); - cmdline_parser_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'V': /* Print version and exit. */ - cmdline_parser_print_version (); - cmdline_parser_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'r': /* Number of the reader to use. By default, the first reader with a present card is used. If the argument is an ATR, the reader with a matching card will be chosen.. */ - - - if (update_arg( (void *)&(args_info->reader_arg), - &(args_info->reader_orig), &(args_info->reader_given), - &(local_args_info.reader_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "reader", 'r', - additional_error)) - goto failure; - - break; - case 'v': /* Use (several times) to be more verbose. */ - - local_args_info.verbose_given++; - - break; - case 'p': /* Verify PIN. */ - - - if (update_arg( 0 , - 0 , &(args_info->verify_pin_given), - &(local_args_info.verify_pin_given), optarg, 0, 0, ARG_NO, - check_ambiguity, override, 0, 0, - "verify-pin", 'p', - additional_error)) - goto failure; - - break; - case 'b': /* Verify finger print. */ - - - if (update_arg( 0 , - 0 , &(args_info->verify_bio_given), - &(local_args_info.verify_bio_given), optarg, 0, 0, ARG_NO, - check_ambiguity, override, 0, 0, - "verify-bio", 'b', - additional_error)) - goto failure; - - break; - case 'c': /* Use (several times) to pass CV certificates. */ - args_info->pxs_mode_counter += 1; - - if (update_multiple_arg_temp(&certificate_list, - &(local_args_info.certificate_given), optarg, 0, 0, ARG_STRING, - "certificate", 'c', - additional_error)) - goto failure; - - break; - case 'k': /* Private key for the CV certificate. */ - args_info->pxs_mode_counter += 1; - - - if (update_arg( (void *)&(args_info->key_arg), - &(args_info->key_orig), &(args_info->key_given), - &(local_args_info.key_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "key", 'k', - additional_error)) - goto failure; - - break; - - case 0: /* Long option with no short option */ - /* Verify PIN or finger print (user's choice). */ - if (strcmp (long_options[option_index].name, "verify-pin-or-bio") == 0) - { - - - if (update_arg( 0 , - 0 , &(args_info->verify_pin_or_bio_given), - &(local_args_info.verify_pin_or_bio_given), optarg, 0, 0, ARG_NO, - check_ambiguity, override, 0, 0, - "verify-pin-or-bio", '-', - additional_error)) - goto failure; - - } - /* Change PIN. */ - else if (strcmp (long_options[option_index].name, "new-pin") == 0) - { - args_info->soc_mode_counter += 1; - - - if (update_arg( 0 , - 0 , &(args_info->new_pin_given), - &(local_args_info.new_pin_given), optarg, 0, 0, ARG_NO, - check_ambiguity, override, 0, 0, - "new-pin", '-', - additional_error)) - goto failure; - - } - /* Use (several times) to change one or more biometric templates. */ - else if (strcmp (long_options[option_index].name, "new-bio") == 0) - { - args_info->soc_mode_counter += 1; - - local_args_info.new_bio_given++; - - } - /* Dump Information about the SoCManager's configuration. */ - else if (strcmp (long_options[option_index].name, "info") == 0) - { - args_info->soc_mode_counter += 1; - - - if (update_arg( 0 , - 0 , &(args_info->info_given), - &(local_args_info.info_given), optarg, 0, 0, ARG_NO, - check_ambiguity, override, 0, 0, - "info", '-', - additional_error)) - goto failure; - - } - /* Print the card ID. */ - else if (strcmp (long_options[option_index].name, "print-cardid") == 0) - { - args_info->pxs_mode_counter += 1; - - - if (update_arg( 0 , - 0 , &(args_info->print_cardid_given), - &(local_args_info.print_cardid_given), optarg, 0, 0, ARG_NO, - check_ambiguity, override, 0, 0, - "print-cardid", '-', - additional_error)) - goto failure; - - } - /* Write the specified card ID. */ - else if (strcmp (long_options[option_index].name, "write-cardid") == 0) - { - args_info->pxs_mode_counter += 1; - - - if (update_arg( (void *)&(args_info->write_cardid_arg), - &(args_info->write_cardid_orig), &(args_info->write_cardid_given), - &(local_args_info.write_cardid_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "write-cardid", '-', - additional_error)) - goto failure; - - } - /* Print the PAccess ID. */ - else if (strcmp (long_options[option_index].name, "print-paccessid") == 0) - { - args_info->pxs_mode_counter += 1; - - - if (update_arg( 0 , - 0 , &(args_info->print_paccessid_given), - &(local_args_info.print_paccessid_given), optarg, 0, 0, ARG_NO, - check_ambiguity, override, 0, 0, - "print-paccessid", '-', - additional_error)) - goto failure; - - } - /* Write the specified PAccess ID. */ - else if (strcmp (long_options[option_index].name, "write-paccessid") == 0) - { - args_info->pxs_mode_counter += 1; - - - if (update_arg( (void *)&(args_info->write_paccessid_arg), - &(args_info->write_paccessid_orig), &(args_info->write_paccessid_given), - &(local_args_info.write_paccessid_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "write-paccessid", '-', - additional_error)) - goto failure; - - } - /* Read the specified data group; use several times to read out multiple files. */ - else if (strcmp (long_options[option_index].name, "read-dg") == 0) - { - args_info->pxs_mode_counter += 1; - - if (update_multiple_arg_temp(&read_dg_list, - &(local_args_info.read_dg_given), optarg, 0, 0, ARG_SHORT, - "read-dg", '-', - additional_error)) - goto failure; - - } - /* Write output to a file instead of printing it; use once for each use of `--read-dg'. */ - else if (strcmp (long_options[option_index].name, "out-file") == 0) - { - args_info->pxs_mode_counter += 1; - - if (update_multiple_arg_temp(&out_file_list, - &(local_args_info.out_file_given), optarg, 0, 0, ARG_STRING, - "out-file", '-', - additional_error)) - goto failure; - - } - /* Write the specified data group; use several times to write multiple files. */ - else if (strcmp (long_options[option_index].name, "write-dg") == 0) - { - args_info->pxs_mode_counter += 1; - - if (update_multiple_arg_temp(&write_dg_list, - &(local_args_info.write_dg_given), optarg, 0, 0, ARG_SHORT, - "write-dg", '-', - additional_error)) - goto failure; - - } - /* Read input from a file; use once for each use of `--write-dg'. */ - else if (strcmp (long_options[option_index].name, "in-file") == 0) - { - args_info->pxs_mode_counter += 1; - - if (update_multiple_arg_temp(&in_file_list, - &(local_args_info.in_file_given), optarg, 0, 0, ARG_STRING, - "in-file", '-', - additional_error)) - goto failure; - - } - /* Delete the specified data group; use several times to delete multiple files. */ - else if (strcmp (long_options[option_index].name, "delete-dg") == 0) - { - args_info->pxs_mode_counter += 1; - - if (update_multiple_arg_temp(&delete_dg_list, - &(local_args_info.delete_dg_given), optarg, 0, 0, ARG_SHORT, - "delete-dg", '-', - additional_error)) - goto failure; - - } - /* Create the specified data group; use several times to create multiple files. */ - else if (strcmp (long_options[option_index].name, "create-dg") == 0) - { - args_info->pxs_mode_counter += 1; - - if (update_multiple_arg_temp(&create_dg_list, - &(local_args_info.create_dg_given), optarg, 0, 0, ARG_SHORT, - "create-dg", '-', - additional_error)) - goto failure; - - } - /* File size of newly created DGs. */ - else if (strcmp (long_options[option_index].name, "new-size") == 0) - { - args_info->pxs_mode_counter += 1; - - - if (update_arg( (void *)&(args_info->new_size_arg), - &(args_info->new_size_orig), &(args_info->new_size_given), - &(local_args_info.new_size_given), optarg, 0, "256", ARG_SHORT, - check_ambiguity, override, 0, 0, - "new-size", '-', - additional_error)) - goto failure; - - } - /* Access condition for reading newly created DGs. */ - else if (strcmp (long_options[option_index].name, "new-read-ac") == 0) - { - args_info->pxs_mode_counter += 1; - - - if (update_arg( (void *)&(args_info->new_read_ac_arg), - &(args_info->new_read_ac_orig), &(args_info->new_read_ac_given), - &(local_args_info.new_read_ac_given), optarg, cmdline_parser_new_read_ac_values, "sm", ARG_STRING, - check_ambiguity, override, 0, 0, - "new-read-ac", '-', - additional_error)) - goto failure; - - } - /* Required access bit in certificate's CHAT for reading newly created DGs. */ - else if (strcmp (long_options[option_index].name, "new-read-ac-chatbit") == 0) - { - args_info->pxs_mode_counter += 1; - - if (update_multiple_arg_temp(&new_read_ac_chatbit_list, - &(local_args_info.new_read_ac_chatbit_given), optarg, 0, 0, ARG_SHORT, - "new-read-ac-chatbit", '-', - additional_error)) - goto failure; - - } - /* Access condition for writing newly created DGs. */ - else if (strcmp (long_options[option_index].name, "new-write-ac") == 0) - { - args_info->pxs_mode_counter += 1; - - - if (update_arg( (void *)&(args_info->new_write_ac_arg), - &(args_info->new_write_ac_orig), &(args_info->new_write_ac_given), - &(local_args_info.new_write_ac_given), optarg, cmdline_parser_new_write_ac_values, "sm", ARG_STRING, - check_ambiguity, override, 0, 0, - "new-write-ac", '-', - additional_error)) - goto failure; - - } - /* Required access bit in certificate's CHAT for reading newly created DGs. */ - else if (strcmp (long_options[option_index].name, "new-write-ac-chatbit") == 0) - { - args_info->pxs_mode_counter += 1; - - if (update_multiple_arg_temp(&new_write_ac_chatbit_list, - &(local_args_info.new_write_ac_chatbit_given), optarg, 0, 0, ARG_SHORT, - "new-write-ac-chatbit", '-', - additional_error)) - goto failure; - - } - - break; - case '?': /* Invalid option. */ - /* `getopt_long' already printed an error message. */ - goto failure; - - default: /* bug: option not considered. */ - fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); - abort (); - } /* switch */ - } /* while */ - - - update_multiple_arg((void *)&(args_info->certificate_arg), - &(args_info->certificate_orig), args_info->certificate_given, - local_args_info.certificate_given, 0, - ARG_STRING, certificate_list); - update_multiple_arg((void *)&(args_info->read_dg_arg), - &(args_info->read_dg_orig), args_info->read_dg_given, - local_args_info.read_dg_given, 0, - ARG_SHORT, read_dg_list); - update_multiple_arg((void *)&(args_info->out_file_arg), - &(args_info->out_file_orig), args_info->out_file_given, - local_args_info.out_file_given, 0, - ARG_STRING, out_file_list); - update_multiple_arg((void *)&(args_info->write_dg_arg), - &(args_info->write_dg_orig), args_info->write_dg_given, - local_args_info.write_dg_given, 0, - ARG_SHORT, write_dg_list); - update_multiple_arg((void *)&(args_info->in_file_arg), - &(args_info->in_file_orig), args_info->in_file_given, - local_args_info.in_file_given, 0, - ARG_STRING, in_file_list); - update_multiple_arg((void *)&(args_info->delete_dg_arg), - &(args_info->delete_dg_orig), args_info->delete_dg_given, - local_args_info.delete_dg_given, 0, - ARG_SHORT, delete_dg_list); - update_multiple_arg((void *)&(args_info->create_dg_arg), - &(args_info->create_dg_orig), args_info->create_dg_given, - local_args_info.create_dg_given, 0, - ARG_SHORT, create_dg_list); - update_multiple_arg((void *)&(args_info->new_read_ac_chatbit_arg), - &(args_info->new_read_ac_chatbit_orig), args_info->new_read_ac_chatbit_given, - local_args_info.new_read_ac_chatbit_given, 0, - ARG_SHORT, new_read_ac_chatbit_list); - update_multiple_arg((void *)&(args_info->new_write_ac_chatbit_arg), - &(args_info->new_write_ac_chatbit_orig), args_info->new_write_ac_chatbit_given, - local_args_info.new_write_ac_chatbit_given, 0, - ARG_SHORT, new_write_ac_chatbit_list); - - args_info->verbose_given += local_args_info.verbose_given; - local_args_info.verbose_given = 0; - args_info->new_bio_given += local_args_info.new_bio_given; - local_args_info.new_bio_given = 0; - args_info->certificate_given += local_args_info.certificate_given; - local_args_info.certificate_given = 0; - args_info->read_dg_given += local_args_info.read_dg_given; - local_args_info.read_dg_given = 0; - args_info->out_file_given += local_args_info.out_file_given; - local_args_info.out_file_given = 0; - args_info->write_dg_given += local_args_info.write_dg_given; - local_args_info.write_dg_given = 0; - args_info->in_file_given += local_args_info.in_file_given; - local_args_info.in_file_given = 0; - args_info->delete_dg_given += local_args_info.delete_dg_given; - local_args_info.delete_dg_given = 0; - args_info->create_dg_given += local_args_info.create_dg_given; - local_args_info.create_dg_given = 0; - args_info->new_read_ac_chatbit_given += local_args_info.new_read_ac_chatbit_given; - local_args_info.new_read_ac_chatbit_given = 0; - args_info->new_write_ac_chatbit_given += local_args_info.new_write_ac_chatbit_given; - local_args_info.new_write_ac_chatbit_given = 0; - - if (args_info->pxs_mode_counter && args_info->soc_mode_counter) { - int pxs_given[] = {args_info->certificate_given, args_info->key_given, args_info->print_cardid_given, args_info->write_cardid_given, args_info->print_paccessid_given, args_info->write_paccessid_given, args_info->read_dg_given, args_info->out_file_given, args_info->write_dg_given, args_info->in_file_given, args_info->delete_dg_given, args_info->create_dg_given, args_info->new_size_given, args_info->new_read_ac_given, args_info->new_read_ac_chatbit_given, args_info->new_write_ac_given, args_info->new_write_ac_chatbit_given, -1}; - const char *pxs_desc[] = {"--certificate", "--key", "--print-cardid", "--write-cardid", "--print-paccessid", "--write-paccessid", "--read-dg", "--out-file", "--write-dg", "--in-file", "--delete-dg", "--create-dg", "--new-size", "--new-read-ac", "--new-read-ac-chatbit", "--new-write-ac", "--new-write-ac-chatbit", 0}; - int soc_given[] = {args_info->new_pin_given, args_info->new_bio_given, args_info->info_given, -1}; - const char *soc_desc[] = {"--new-pin", "--new-bio", "--info", 0}; - error_occurred += check_modes(pxs_given, pxs_desc, soc_given, soc_desc); - } - - if (check_required) - { - error_occurred += cmdline_parser_required2 (args_info, argv[0], additional_error); - } - - cmdline_parser_release (&local_args_info); - - if ( error_occurred ) - return (EXIT_FAILURE); - - return 0; - -failure: - free_list (certificate_list, 1 ); - free_list (read_dg_list, 0 ); - free_list (out_file_list, 1 ); - free_list (write_dg_list, 0 ); - free_list (in_file_list, 1 ); - free_list (delete_dg_list, 0 ); - free_list (create_dg_list, 0 ); - free_list (new_read_ac_chatbit_list, 0 ); - free_list (new_write_ac_chatbit_list, 0 ); - - cmdline_parser_release (&local_args_info); - return (EXIT_FAILURE); -} -/* vim: set ft=c noet ts=8 sts=8 sw=8 tw=80 nojs spell : */ diff --git a/src/tools/goid-tool-cmdline.h b/src/tools/goid-tool-cmdline.h deleted file mode 100644 index 50002c6a7f..0000000000 --- a/src/tools/goid-tool-cmdline.h +++ /dev/null @@ -1,282 +0,0 @@ -/** @file goid-tool-cmdline.h - * @brief The header file for the command line option parser - * generated by GNU Gengetopt version 2.23 - * http://www.gnu.org/software/gengetopt. - * DO NOT modify this file, since it can be overwritten - * @author GNU Gengetopt */ - -#ifndef GOID_TOOL_CMDLINE_H -#define GOID_TOOL_CMDLINE_H - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for FILE */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifndef CMDLINE_PARSER_PACKAGE -/** @brief the program name (used for printing errors) */ -#define CMDLINE_PARSER_PACKAGE "goid-tool" -#endif - -#ifndef CMDLINE_PARSER_PACKAGE_NAME -/** @brief the complete program name (used for help and version) */ -#define CMDLINE_PARSER_PACKAGE_NAME "goid-tool" -#endif - -#ifndef CMDLINE_PARSER_VERSION -/** @brief the program version */ -#define CMDLINE_PARSER_VERSION VERSION -#endif - -/** @brief Where the command line options are stored */ -struct gengetopt_args_info -{ - const char *help_help; /**< @brief Print help and exit help description. */ - const char *version_help; /**< @brief Print version and exit help description. */ - char * reader_arg; /**< @brief Number of the reader to use. By default, the first reader with a present card is used. If the argument is an ATR, the reader with a matching card will be chosen.. */ - char * reader_orig; /**< @brief Number of the reader to use. By default, the first reader with a present card is used. If the argument is an ATR, the reader with a matching card will be chosen. original value given at command line. */ - const char *reader_help; /**< @brief Number of the reader to use. By default, the first reader with a present card is used. If the argument is an ATR, the reader with a matching card will be chosen. help description. */ - unsigned int verbose_min; /**< @brief Use (several times) to be more verbose's minimum occurreces */ - unsigned int verbose_max; /**< @brief Use (several times) to be more verbose's maximum occurreces */ - const char *verbose_help; /**< @brief Use (several times) to be more verbose help description. */ - const char *verify_pin_help; /**< @brief Verify PIN help description. */ - const char *verify_bio_help; /**< @brief Verify finger print help description. */ - const char *verify_pin_or_bio_help; /**< @brief Verify PIN or finger print (user's choice) help description. */ - const char *new_pin_help; /**< @brief Change PIN help description. */ - unsigned int new_bio_min; /**< @brief Use (several times) to change one or more biometric templates's minimum occurreces */ - unsigned int new_bio_max; /**< @brief Use (several times) to change one or more biometric templates's maximum occurreces */ - const char *new_bio_help; /**< @brief Use (several times) to change one or more biometric templates help description. */ - const char *info_help; /**< @brief Dump Information about the SoCManager's configuration help description. */ - char ** certificate_arg; /**< @brief Use (several times) to pass CV certificates. */ - char ** certificate_orig; /**< @brief Use (several times) to pass CV certificates original value given at command line. */ - unsigned int certificate_min; /**< @brief Use (several times) to pass CV certificates's minimum occurreces */ - unsigned int certificate_max; /**< @brief Use (several times) to pass CV certificates's maximum occurreces */ - const char *certificate_help; /**< @brief Use (several times) to pass CV certificates help description. */ - char * key_arg; /**< @brief Private key for the CV certificate. */ - char * key_orig; /**< @brief Private key for the CV certificate original value given at command line. */ - const char *key_help; /**< @brief Private key for the CV certificate help description. */ - const char *print_cardid_help; /**< @brief Print the card ID help description. */ - char * write_cardid_arg; /**< @brief Write the specified card ID. */ - char * write_cardid_orig; /**< @brief Write the specified card ID original value given at command line. */ - const char *write_cardid_help; /**< @brief Write the specified card ID help description. */ - const char *print_paccessid_help; /**< @brief Print the PAccess ID help description. */ - char * write_paccessid_arg; /**< @brief Write the specified PAccess ID. */ - char * write_paccessid_orig; /**< @brief Write the specified PAccess ID original value given at command line. */ - const char *write_paccessid_help; /**< @brief Write the specified PAccess ID help description. */ - short* read_dg_arg; /**< @brief Read the specified data group; use several times to read out multiple files. */ - char ** read_dg_orig; /**< @brief Read the specified data group; use several times to read out multiple files original value given at command line. */ - unsigned int read_dg_min; /**< @brief Read the specified data group; use several times to read out multiple files's minimum occurreces */ - unsigned int read_dg_max; /**< @brief Read the specified data group; use several times to read out multiple files's maximum occurreces */ - const char *read_dg_help; /**< @brief Read the specified data group; use several times to read out multiple files help description. */ - char ** out_file_arg; /**< @brief Write output to a file instead of printing it; use once for each use of `--read-dg'. */ - char ** out_file_orig; /**< @brief Write output to a file instead of printing it; use once for each use of `--read-dg' original value given at command line. */ - unsigned int out_file_min; /**< @brief Write output to a file instead of printing it; use once for each use of `--read-dg''s minimum occurreces */ - unsigned int out_file_max; /**< @brief Write output to a file instead of printing it; use once for each use of `--read-dg''s maximum occurreces */ - const char *out_file_help; /**< @brief Write output to a file instead of printing it; use once for each use of `--read-dg' help description. */ - short* write_dg_arg; /**< @brief Write the specified data group; use several times to write multiple files. */ - char ** write_dg_orig; /**< @brief Write the specified data group; use several times to write multiple files original value given at command line. */ - unsigned int write_dg_min; /**< @brief Write the specified data group; use several times to write multiple files's minimum occurreces */ - unsigned int write_dg_max; /**< @brief Write the specified data group; use several times to write multiple files's maximum occurreces */ - const char *write_dg_help; /**< @brief Write the specified data group; use several times to write multiple files help description. */ - char ** in_file_arg; /**< @brief Read input from a file; use once for each use of `--write-dg'. */ - char ** in_file_orig; /**< @brief Read input from a file; use once for each use of `--write-dg' original value given at command line. */ - unsigned int in_file_min; /**< @brief Read input from a file; use once for each use of `--write-dg''s minimum occurreces */ - unsigned int in_file_max; /**< @brief Read input from a file; use once for each use of `--write-dg''s maximum occurreces */ - const char *in_file_help; /**< @brief Read input from a file; use once for each use of `--write-dg' help description. */ - short* delete_dg_arg; /**< @brief Delete the specified data group; use several times to delete multiple files. */ - char ** delete_dg_orig; /**< @brief Delete the specified data group; use several times to delete multiple files original value given at command line. */ - unsigned int delete_dg_min; /**< @brief Delete the specified data group; use several times to delete multiple files's minimum occurreces */ - unsigned int delete_dg_max; /**< @brief Delete the specified data group; use several times to delete multiple files's maximum occurreces */ - const char *delete_dg_help; /**< @brief Delete the specified data group; use several times to delete multiple files help description. */ - short* create_dg_arg; /**< @brief Create the specified data group; use several times to create multiple files. */ - char ** create_dg_orig; /**< @brief Create the specified data group; use several times to create multiple files original value given at command line. */ - unsigned int create_dg_min; /**< @brief Create the specified data group; use several times to create multiple files's minimum occurreces */ - unsigned int create_dg_max; /**< @brief Create the specified data group; use several times to create multiple files's maximum occurreces */ - const char *create_dg_help; /**< @brief Create the specified data group; use several times to create multiple files help description. */ - short new_size_arg; /**< @brief File size of newly created DGs (default='256'). */ - char * new_size_orig; /**< @brief File size of newly created DGs original value given at command line. */ - const char *new_size_help; /**< @brief File size of newly created DGs help description. */ - char * new_read_ac_arg; /**< @brief Access condition for reading newly created DGs (default='sm'). */ - char * new_read_ac_orig; /**< @brief Access condition for reading newly created DGs original value given at command line. */ - const char *new_read_ac_help; /**< @brief Access condition for reading newly created DGs help description. */ - short* new_read_ac_chatbit_arg; /**< @brief Required access bit in certificate's CHAT for reading newly created DGs. */ - char ** new_read_ac_chatbit_orig; /**< @brief Required access bit in certificate's CHAT for reading newly created DGs original value given at command line. */ - unsigned int new_read_ac_chatbit_min; /**< @brief Required access bit in certificate's CHAT for reading newly created DGs's minimum occurreces */ - unsigned int new_read_ac_chatbit_max; /**< @brief Required access bit in certificate's CHAT for reading newly created DGs's maximum occurreces */ - const char *new_read_ac_chatbit_help; /**< @brief Required access bit in certificate's CHAT for reading newly created DGs help description. */ - char * new_write_ac_arg; /**< @brief Access condition for writing newly created DGs (default='sm'). */ - char * new_write_ac_orig; /**< @brief Access condition for writing newly created DGs original value given at command line. */ - const char *new_write_ac_help; /**< @brief Access condition for writing newly created DGs help description. */ - short* new_write_ac_chatbit_arg; /**< @brief Required access bit in certificate's CHAT for reading newly created DGs. */ - char ** new_write_ac_chatbit_orig; /**< @brief Required access bit in certificate's CHAT for reading newly created DGs original value given at command line. */ - unsigned int new_write_ac_chatbit_min; /**< @brief Required access bit in certificate's CHAT for reading newly created DGs's minimum occurreces */ - unsigned int new_write_ac_chatbit_max; /**< @brief Required access bit in certificate's CHAT for reading newly created DGs's maximum occurreces */ - const char *new_write_ac_chatbit_help; /**< @brief Required access bit in certificate's CHAT for reading newly created DGs help description. */ - - unsigned int help_given ; /**< @brief Whether help was given. */ - unsigned int version_given ; /**< @brief Whether version was given. */ - unsigned int reader_given ; /**< @brief Whether reader was given. */ - unsigned int verbose_given ; /**< @brief Whether verbose was given. */ - unsigned int verify_pin_given ; /**< @brief Whether verify-pin was given. */ - unsigned int verify_bio_given ; /**< @brief Whether verify-bio was given. */ - unsigned int verify_pin_or_bio_given ; /**< @brief Whether verify-pin-or-bio was given. */ - unsigned int new_pin_given ; /**< @brief Whether new-pin was given. */ - unsigned int new_bio_given ; /**< @brief Whether new-bio was given. */ - unsigned int info_given ; /**< @brief Whether info was given. */ - unsigned int certificate_given ; /**< @brief Whether certificate was given. */ - unsigned int key_given ; /**< @brief Whether key was given. */ - unsigned int print_cardid_given ; /**< @brief Whether print-cardid was given. */ - unsigned int write_cardid_given ; /**< @brief Whether write-cardid was given. */ - unsigned int print_paccessid_given ; /**< @brief Whether print-paccessid was given. */ - unsigned int write_paccessid_given ; /**< @brief Whether write-paccessid was given. */ - unsigned int read_dg_given ; /**< @brief Whether read-dg was given. */ - unsigned int out_file_given ; /**< @brief Whether out-file was given. */ - unsigned int write_dg_given ; /**< @brief Whether write-dg was given. */ - unsigned int in_file_given ; /**< @brief Whether in-file was given. */ - unsigned int delete_dg_given ; /**< @brief Whether delete-dg was given. */ - unsigned int create_dg_given ; /**< @brief Whether create-dg was given. */ - unsigned int new_size_given ; /**< @brief Whether new-size was given. */ - unsigned int new_read_ac_given ; /**< @brief Whether new-read-ac was given. */ - unsigned int new_read_ac_chatbit_given ; /**< @brief Whether new-read-ac-chatbit was given. */ - unsigned int new_write_ac_given ; /**< @brief Whether new-write-ac was given. */ - unsigned int new_write_ac_chatbit_given ; /**< @brief Whether new-write-ac-chatbit was given. */ - - int pxs_mode_counter; /**< @brief Counter for mode pxs */ - int soc_mode_counter; /**< @brief Counter for mode soc */ -} ; - -/** @brief The additional parameters to pass to parser functions */ -struct cmdline_parser_params -{ - int override; /**< @brief whether to override possibly already present options (default 0) */ - int initialize; /**< @brief whether to initialize the option structure gengetopt_args_info (default 1) */ - int check_required; /**< @brief whether to check that all required options were provided (default 1) */ - int check_ambiguity; /**< @brief whether to check for options already specified in the option structure gengetopt_args_info (default 0) */ - int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ -} ; - -/** @brief the purpose string of the program */ -extern const char *gengetopt_args_info_purpose; -/** @brief the usage string of the program */ -extern const char *gengetopt_args_info_usage; -/** @brief the description string of the program */ -extern const char *gengetopt_args_info_description; -/** @brief all the lines making the help output */ -extern const char *gengetopt_args_info_help[]; - -/** - * The command line parser - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser (int argc, char **argv, - struct gengetopt_args_info *args_info); - -/** - * The command line parser (version with additional parameters - deprecated) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_ext() instead - */ -int cmdline_parser2 (int argc, char **argv, - struct gengetopt_args_info *args_info, - int override, int initialize, int check_required); - -/** - * The command line parser (version with additional parameters) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_ext (int argc, char **argv, - struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params); - -/** - * Save the contents of the option struct into an already open FILE stream. - * @param outfile the stream where to dump options - * @param args_info the option struct to dump - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_dump(FILE *outfile, - struct gengetopt_args_info *args_info); - -/** - * Save the contents of the option struct into a (text) file. - * This file can be read by the config file parser (if generated by gengetopt) - * @param filename the file where to save - * @param args_info the option struct to save - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_file_save(const char *filename, - struct gengetopt_args_info *args_info); - -/** - * Print the help - */ -void cmdline_parser_print_help(void); -/** - * Print the version - */ -void cmdline_parser_print_version(void); - -/** - * Initializes all the fields a cmdline_parser_params structure - * to their default values - * @param params the structure to initialize - */ -void cmdline_parser_params_init(struct cmdline_parser_params *params); - -/** - * Allocates dynamically a cmdline_parser_params structure and initializes - * all its fields to their default values - * @return the created and initialized cmdline_parser_params structure - */ -struct cmdline_parser_params *cmdline_parser_params_create(void); - -/** - * Initializes the passed gengetopt_args_info structure's fields - * (also set default values for options that have a default) - * @param args_info the structure to initialize - */ -void cmdline_parser_init (struct gengetopt_args_info *args_info); -/** - * Deallocates the string fields of the gengetopt_args_info structure - * (but does not deallocate the structure itself) - * @param args_info the structure to deallocate - */ -void cmdline_parser_free (struct gengetopt_args_info *args_info); - -/** - * Checks that all the required options were specified - * @param args_info the structure to check - * @param prog_name the name of the program that will be used to print - * possible errors - * @return - */ -int cmdline_parser_required (struct gengetopt_args_info *args_info, - const char *prog_name); - -extern const char *cmdline_parser_new_read_ac_values[]; /**< @brief Possible values for new-read-ac. */ -extern const char *cmdline_parser_new_write_ac_values[]; /**< @brief Possible values for new-write-ac. */ - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* GOID_TOOL_CMDLINE_H */ diff --git a/src/tools/npa-tool-cmdline.c b/src/tools/npa-tool-cmdline.c deleted file mode 100644 index 47e14153ea..0000000000 --- a/src/tools/npa-tool-cmdline.c +++ /dev/null @@ -1,1904 +0,0 @@ -/* - File autogenerated by gengetopt version 2.23 - generated with the following command: - /opt/homebrew/bin/gengetopt --file-name=npa-tool-cmdline --output-dir=. - - The developers of gengetopt consider the fixed text that goes in all - gengetopt output files to be in the public domain: - we make no copyright claims on it. -*/ - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#ifndef FIX_UNUSED -#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ -#endif - -#include - -#include "npa-tool-cmdline.h" - -const char *gengetopt_args_info_purpose = ""; - -const char *gengetopt_args_info_usage = "Usage: npa-tool [OPTION]..."; - -const char *gengetopt_args_info_versiontext = ""; - -const char *gengetopt_args_info_description = ""; - -const char *gengetopt_args_info_help[] = { - " -h, --help Print help and exit", - " -V, --version Print version and exit", - " -r, --reader=STRING Number of the reader to use. By default, the\n first reader with a present card is used. If\n the argument is an ATR, the reader with a\n matching card will be chosen.", - " -v, --verbose Use (several times) to be more verbose", - "\nPassword Authenticated Connection Establishment (PACE):", - " -p, --pin[=STRING] Run PACE with (transport) eID-PIN", - " -u, --puk[=STRING] Run PACE with PUK", - " -c, --can[=STRING] Run PACE with CAN", - " -m, --mrz[=STRING] Run PACE with MRZ (insert MRZ without newlines)", - " --env Whether to use environment variables PIN, PUK,\n CAN, MRZ and NEWPIN. You may want to clean\n your environment before enabling this.\n (default=off)", - "\nPIN management:", - " -N, --new-pin[=STRING] Install a new PIN", - " -R, --resume Resume eID-PIN (uses CAN to activate last\n retry) (default=off)", - " -U, --unblock Unblock PIN (uses PUK to activate three more\n retries) (default=off)", - "\nTerminal Authentication (TA) and Chip Authentication (CA):", - " -C, --cv-certificate=FILENAME Card Verifiable Certificate to create a\n certificate chain. Can be used multiple times\n (order is important).", - " --cert-desc=HEX_STRING Certificate description to show for Terminal\n Authentication", - " --chat=HEX_STRING Card holder authorization template to use\n (default is terminal's CHAT). Use\n 7F4C0E060904007F000703010203530103 to trigger\n EAC on the CAT-C (Komfortleser).", - " -A, --auxiliary-data=HEX_STRING\n Terminal's auxiliary data (default is\n determined by verification of validity, age\n and community ID).", - " -P, --private-key=FILENAME Terminal's private key", - " --cvc-dir=DIRECTORY Where to look for the CVCA's certificate\n (default=`')", - " --x509-dir=DIRECTORY Where to look for the CSCA's certificate\n (default=`')", - " --disable-ta-checks Disable checking the validity period of CV\n certificates (default=off)", - " --disable-ca-checks Disable passive authentication (default=off)", - "\nRead and write data groups:", - " --read-dg1 Read DG 1 (Document Type) (default=off)", - " --read-dg2 Read DG 2 (Issuing State) (default=off)", - " --read-dg3 Read DG 3 (Date of Expiry) (default=off)", - " --read-dg4 Read DG 4 (Given Names) (default=off)", - " --read-dg5 Read DG 5 (Family Names) (default=off)", - " --read-dg6 Read DG 6 (Religious/Artistic Name)\n (default=off)", - " --read-dg7 Read DG 7 (Academic Title) (default=off)", - " --read-dg8 Read DG 8 (Date of Birth) (default=off)", - " --read-dg9 Read DG 9 (Place of Birth) (default=off)", - " --read-dg10 Read DG 10 (Nationality) (default=off)", - " --read-dg11 Read DG 11 (Sex) (default=off)", - " --read-dg12 Read DG 12 (Optional Data) (default=off)", - " --read-dg13 Read DG 13 (Birth Name) (default=off)", - " --read-dg14 Read DG 14 (default=off)", - " --read-dg15 Read DG 15 (default=off)", - " --read-dg16 Read DG 16 (default=off)", - " --read-dg17 Read DG 17 (Normal Place of Residence)\n (default=off)", - " --read-dg18 Read DG 18 (Community ID) (default=off)", - " --read-dg19 Read DG 19 (Residence Permit I) (default=off)", - " --read-dg20 Read DG 20 (Residence Permit II)\n (default=off)", - " --read-dg21 Read DG 21 (Optional Data) (default=off)", - " --write-dg17=HEX_STRING Write DG 17 (Normal Place of Residence)", - " --write-dg18=HEX_STRING Write DG 18 (Community ID)", - " --write-dg19=HEX_STRING Write DG 19 (Residence Permit I)", - " --write-dg20=HEX_STRING Write DG 20 (Residence Permit II)", - " --write-dg21=HEX_STRING Write DG 21 (Optional Data)", - "\nVerification of validity, age and community ID:", - " --verify-validity=YYYYMMDD\n Verify chip's validity with a reference date", - " --older-than=YYYYMMDD Verify age with a reference date", - " --verify-community=HEX_STRING\n Verify community ID with a reference ID", - "\nSpecial options, not always useful:", - " -b, --break Brute force PIN, CAN or PUK. Use together with\n -p, -a or -u (default=off)", - " -t, --translate=FILENAME File with APDUs of HEX_STRINGs to send through\n the secure channel (default=`stdin')", - " --tr-03110v201 Force compliance to BSI TR-03110 version 2.01\n (default=off)", - "\nReport bugs to https://github.com/OpenSC/OpenSC/issues\n\nWritten by Frank Morgner ", - 0 -}; - -typedef enum {ARG_NO - , ARG_FLAG - , ARG_STRING -} cmdline_parser_arg_type; - -static -void clear_given (struct gengetopt_args_info *args_info); -static -void clear_args (struct gengetopt_args_info *args_info); - -static int -cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params, const char *additional_error); - -static int -cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error); - -static char * -gengetopt_strdup (const char *s); - -static -void clear_given (struct gengetopt_args_info *args_info) -{ - args_info->help_given = 0 ; - args_info->version_given = 0 ; - args_info->reader_given = 0 ; - args_info->verbose_given = 0 ; - args_info->pin_given = 0 ; - args_info->puk_given = 0 ; - args_info->can_given = 0 ; - args_info->mrz_given = 0 ; - args_info->env_given = 0 ; - args_info->new_pin_given = 0 ; - args_info->resume_given = 0 ; - args_info->unblock_given = 0 ; - args_info->cv_certificate_given = 0 ; - args_info->cert_desc_given = 0 ; - args_info->chat_given = 0 ; - args_info->auxiliary_data_given = 0 ; - args_info->private_key_given = 0 ; - args_info->cvc_dir_given = 0 ; - args_info->x509_dir_given = 0 ; - args_info->disable_ta_checks_given = 0 ; - args_info->disable_ca_checks_given = 0 ; - args_info->read_dg1_given = 0 ; - args_info->read_dg2_given = 0 ; - args_info->read_dg3_given = 0 ; - args_info->read_dg4_given = 0 ; - args_info->read_dg5_given = 0 ; - args_info->read_dg6_given = 0 ; - args_info->read_dg7_given = 0 ; - args_info->read_dg8_given = 0 ; - args_info->read_dg9_given = 0 ; - args_info->read_dg10_given = 0 ; - args_info->read_dg11_given = 0 ; - args_info->read_dg12_given = 0 ; - args_info->read_dg13_given = 0 ; - args_info->read_dg14_given = 0 ; - args_info->read_dg15_given = 0 ; - args_info->read_dg16_given = 0 ; - args_info->read_dg17_given = 0 ; - args_info->read_dg18_given = 0 ; - args_info->read_dg19_given = 0 ; - args_info->read_dg20_given = 0 ; - args_info->read_dg21_given = 0 ; - args_info->write_dg17_given = 0 ; - args_info->write_dg18_given = 0 ; - args_info->write_dg19_given = 0 ; - args_info->write_dg20_given = 0 ; - args_info->write_dg21_given = 0 ; - args_info->verify_validity_given = 0 ; - args_info->older_than_given = 0 ; - args_info->verify_community_given = 0 ; - args_info->break_given = 0 ; - args_info->translate_given = 0 ; - args_info->tr_03110v201_given = 0 ; -} - -static -void clear_args (struct gengetopt_args_info *args_info) -{ - FIX_UNUSED (args_info); - args_info->reader_arg = NULL; - args_info->reader_orig = NULL; - args_info->pin_arg = NULL; - args_info->pin_orig = NULL; - args_info->puk_arg = NULL; - args_info->puk_orig = NULL; - args_info->can_arg = NULL; - args_info->can_orig = NULL; - args_info->mrz_arg = NULL; - args_info->mrz_orig = NULL; - args_info->env_flag = 0; - args_info->new_pin_arg = NULL; - args_info->new_pin_orig = NULL; - args_info->resume_flag = 0; - args_info->unblock_flag = 0; - args_info->cv_certificate_arg = NULL; - args_info->cv_certificate_orig = NULL; - args_info->cert_desc_arg = NULL; - args_info->cert_desc_orig = NULL; - args_info->chat_arg = NULL; - args_info->chat_orig = NULL; - args_info->auxiliary_data_arg = NULL; - args_info->auxiliary_data_orig = NULL; - args_info->private_key_arg = NULL; - args_info->private_key_orig = NULL; - args_info->cvc_dir_arg = gengetopt_strdup (""); - args_info->cvc_dir_orig = NULL; - args_info->x509_dir_arg = gengetopt_strdup (""); - args_info->x509_dir_orig = NULL; - args_info->disable_ta_checks_flag = 0; - args_info->disable_ca_checks_flag = 0; - args_info->read_dg1_flag = 0; - args_info->read_dg2_flag = 0; - args_info->read_dg3_flag = 0; - args_info->read_dg4_flag = 0; - args_info->read_dg5_flag = 0; - args_info->read_dg6_flag = 0; - args_info->read_dg7_flag = 0; - args_info->read_dg8_flag = 0; - args_info->read_dg9_flag = 0; - args_info->read_dg10_flag = 0; - args_info->read_dg11_flag = 0; - args_info->read_dg12_flag = 0; - args_info->read_dg13_flag = 0; - args_info->read_dg14_flag = 0; - args_info->read_dg15_flag = 0; - args_info->read_dg16_flag = 0; - args_info->read_dg17_flag = 0; - args_info->read_dg18_flag = 0; - args_info->read_dg19_flag = 0; - args_info->read_dg20_flag = 0; - args_info->read_dg21_flag = 0; - args_info->write_dg17_arg = NULL; - args_info->write_dg17_orig = NULL; - args_info->write_dg18_arg = NULL; - args_info->write_dg18_orig = NULL; - args_info->write_dg19_arg = NULL; - args_info->write_dg19_orig = NULL; - args_info->write_dg20_arg = NULL; - args_info->write_dg20_orig = NULL; - args_info->write_dg21_arg = NULL; - args_info->write_dg21_orig = NULL; - args_info->verify_validity_arg = NULL; - args_info->verify_validity_orig = NULL; - args_info->older_than_arg = NULL; - args_info->older_than_orig = NULL; - args_info->verify_community_arg = NULL; - args_info->verify_community_orig = NULL; - args_info->break_flag = 0; - args_info->translate_arg = gengetopt_strdup ("stdin"); - args_info->translate_orig = NULL; - args_info->tr_03110v201_flag = 0; - -} - -static -void init_args_info(struct gengetopt_args_info *args_info) -{ - - - args_info->help_help = gengetopt_args_info_help[0] ; - args_info->version_help = gengetopt_args_info_help[1] ; - args_info->reader_help = gengetopt_args_info_help[2] ; - args_info->verbose_help = gengetopt_args_info_help[3] ; - args_info->verbose_min = 0; - args_info->verbose_max = 0; - args_info->pin_help = gengetopt_args_info_help[5] ; - args_info->puk_help = gengetopt_args_info_help[6] ; - args_info->can_help = gengetopt_args_info_help[7] ; - args_info->mrz_help = gengetopt_args_info_help[8] ; - args_info->env_help = gengetopt_args_info_help[9] ; - args_info->new_pin_help = gengetopt_args_info_help[11] ; - args_info->resume_help = gengetopt_args_info_help[12] ; - args_info->unblock_help = gengetopt_args_info_help[13] ; - args_info->cv_certificate_help = gengetopt_args_info_help[15] ; - args_info->cv_certificate_min = 0; - args_info->cv_certificate_max = 0; - args_info->cert_desc_help = gengetopt_args_info_help[16] ; - args_info->chat_help = gengetopt_args_info_help[17] ; - args_info->auxiliary_data_help = gengetopt_args_info_help[18] ; - args_info->private_key_help = gengetopt_args_info_help[19] ; - args_info->cvc_dir_help = gengetopt_args_info_help[20] ; - args_info->x509_dir_help = gengetopt_args_info_help[21] ; - args_info->disable_ta_checks_help = gengetopt_args_info_help[22] ; - args_info->disable_ca_checks_help = gengetopt_args_info_help[23] ; - args_info->read_dg1_help = gengetopt_args_info_help[25] ; - args_info->read_dg2_help = gengetopt_args_info_help[26] ; - args_info->read_dg3_help = gengetopt_args_info_help[27] ; - args_info->read_dg4_help = gengetopt_args_info_help[28] ; - args_info->read_dg5_help = gengetopt_args_info_help[29] ; - args_info->read_dg6_help = gengetopt_args_info_help[30] ; - args_info->read_dg7_help = gengetopt_args_info_help[31] ; - args_info->read_dg8_help = gengetopt_args_info_help[32] ; - args_info->read_dg9_help = gengetopt_args_info_help[33] ; - args_info->read_dg10_help = gengetopt_args_info_help[34] ; - args_info->read_dg11_help = gengetopt_args_info_help[35] ; - args_info->read_dg12_help = gengetopt_args_info_help[36] ; - args_info->read_dg13_help = gengetopt_args_info_help[37] ; - args_info->read_dg14_help = gengetopt_args_info_help[38] ; - args_info->read_dg15_help = gengetopt_args_info_help[39] ; - args_info->read_dg16_help = gengetopt_args_info_help[40] ; - args_info->read_dg17_help = gengetopt_args_info_help[41] ; - args_info->read_dg18_help = gengetopt_args_info_help[42] ; - args_info->read_dg19_help = gengetopt_args_info_help[43] ; - args_info->read_dg20_help = gengetopt_args_info_help[44] ; - args_info->read_dg21_help = gengetopt_args_info_help[45] ; - args_info->write_dg17_help = gengetopt_args_info_help[46] ; - args_info->write_dg18_help = gengetopt_args_info_help[47] ; - args_info->write_dg19_help = gengetopt_args_info_help[48] ; - args_info->write_dg20_help = gengetopt_args_info_help[49] ; - args_info->write_dg21_help = gengetopt_args_info_help[50] ; - args_info->verify_validity_help = gengetopt_args_info_help[52] ; - args_info->older_than_help = gengetopt_args_info_help[53] ; - args_info->verify_community_help = gengetopt_args_info_help[54] ; - args_info->break_help = gengetopt_args_info_help[56] ; - args_info->translate_help = gengetopt_args_info_help[57] ; - args_info->tr_03110v201_help = gengetopt_args_info_help[58] ; - -} - -void -cmdline_parser_print_version (void) -{ - printf ("%s %s\n", - (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE), - CMDLINE_PARSER_VERSION); - - if (strlen(gengetopt_args_info_versiontext) > 0) - printf("\n%s\n", gengetopt_args_info_versiontext); -} - -static void print_help_common(void) -{ - size_t len_purpose = strlen(gengetopt_args_info_purpose); - size_t len_usage = strlen(gengetopt_args_info_usage); - - if (len_usage > 0) { - printf("%s\n", gengetopt_args_info_usage); - } - if (len_purpose > 0) { - printf("%s\n", gengetopt_args_info_purpose); - } - - if (len_usage || len_purpose) { - printf("\n"); - } - - if (strlen(gengetopt_args_info_description) > 0) { - printf("%s\n\n", gengetopt_args_info_description); - } -} - -void -cmdline_parser_print_help (void) -{ - int i = 0; - print_help_common(); - while (gengetopt_args_info_help[i]) - printf("%s\n", gengetopt_args_info_help[i++]); -} - -void -cmdline_parser_init (struct gengetopt_args_info *args_info) -{ - clear_given (args_info); - clear_args (args_info); - init_args_info (args_info); -} - -void -cmdline_parser_params_init(struct cmdline_parser_params *params) -{ - if (params) - { - params->override = 0; - params->initialize = 1; - params->check_required = 1; - params->check_ambiguity = 0; - params->print_errors = 1; - } -} - -struct cmdline_parser_params * -cmdline_parser_params_create(void) -{ - struct cmdline_parser_params *params = - (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); - cmdline_parser_params_init(params); - return params; -} - -static void -free_string_field (char **s) -{ - if (*s) - { - free (*s); - *s = 0; - } -} - -/** @brief generic value variable */ -union generic_value { - char *string_arg; - const char *default_string_arg; -}; - -/** @brief holds temporary values for multiple options */ -struct generic_list -{ - union generic_value arg; - char *orig; - struct generic_list *next; -}; - -/** - * @brief add a node at the head of the list - */ -static void add_node(struct generic_list **list) { - struct generic_list *new_node = (struct generic_list *) malloc (sizeof (struct generic_list)); - new_node->next = *list; - *list = new_node; - new_node->arg.string_arg = 0; - new_node->orig = 0; -} - - -static void -free_multiple_string_field(unsigned int len, char ***arg, char ***orig) -{ - unsigned int i; - if (*arg) { - for (i = 0; i < len; ++i) - { - free_string_field(&((*arg)[i])); - free_string_field(&((*orig)[i])); - } - free_string_field(&((*arg)[0])); /* free default string */ - - free (*arg); - *arg = 0; - free (*orig); - *orig = 0; - } -} - -static void -cmdline_parser_release (struct gengetopt_args_info *args_info) -{ - - free_string_field (&(args_info->reader_arg)); - free_string_field (&(args_info->reader_orig)); - free_string_field (&(args_info->pin_arg)); - free_string_field (&(args_info->pin_orig)); - free_string_field (&(args_info->puk_arg)); - free_string_field (&(args_info->puk_orig)); - free_string_field (&(args_info->can_arg)); - free_string_field (&(args_info->can_orig)); - free_string_field (&(args_info->mrz_arg)); - free_string_field (&(args_info->mrz_orig)); - free_string_field (&(args_info->new_pin_arg)); - free_string_field (&(args_info->new_pin_orig)); - free_multiple_string_field (args_info->cv_certificate_given, &(args_info->cv_certificate_arg), &(args_info->cv_certificate_orig)); - free_string_field (&(args_info->cert_desc_arg)); - free_string_field (&(args_info->cert_desc_orig)); - free_string_field (&(args_info->chat_arg)); - free_string_field (&(args_info->chat_orig)); - free_string_field (&(args_info->auxiliary_data_arg)); - free_string_field (&(args_info->auxiliary_data_orig)); - free_string_field (&(args_info->private_key_arg)); - free_string_field (&(args_info->private_key_orig)); - free_string_field (&(args_info->cvc_dir_arg)); - free_string_field (&(args_info->cvc_dir_orig)); - free_string_field (&(args_info->x509_dir_arg)); - free_string_field (&(args_info->x509_dir_orig)); - free_string_field (&(args_info->write_dg17_arg)); - free_string_field (&(args_info->write_dg17_orig)); - free_string_field (&(args_info->write_dg18_arg)); - free_string_field (&(args_info->write_dg18_orig)); - free_string_field (&(args_info->write_dg19_arg)); - free_string_field (&(args_info->write_dg19_orig)); - free_string_field (&(args_info->write_dg20_arg)); - free_string_field (&(args_info->write_dg20_orig)); - free_string_field (&(args_info->write_dg21_arg)); - free_string_field (&(args_info->write_dg21_orig)); - free_string_field (&(args_info->verify_validity_arg)); - free_string_field (&(args_info->verify_validity_orig)); - free_string_field (&(args_info->older_than_arg)); - free_string_field (&(args_info->older_than_orig)); - free_string_field (&(args_info->verify_community_arg)); - free_string_field (&(args_info->verify_community_orig)); - free_string_field (&(args_info->translate_arg)); - free_string_field (&(args_info->translate_orig)); - - - - clear_given (args_info); -} - - -static void -write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) -{ - FIX_UNUSED (values); - if (arg) { - fprintf(outfile, "%s=\"%s\"\n", opt, arg); - } else { - fprintf(outfile, "%s\n", opt); - } -} - -static void -write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, const char *values[]) -{ - int i; - - for (i = 0; i < len; ++i) - write_into_file(outfile, opt, (arg ? arg[i] : 0), values); -} - -int -cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) -{ - int i = 0; - - if (!outfile) - { - fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE); - return EXIT_FAILURE; - } - - if (args_info->help_given) - write_into_file(outfile, "help", 0, 0 ); - if (args_info->version_given) - write_into_file(outfile, "version", 0, 0 ); - if (args_info->reader_given) - write_into_file(outfile, "reader", args_info->reader_orig, 0); - write_multiple_into_file(outfile, args_info->verbose_given, "verbose", 0, 0); - if (args_info->pin_given) - write_into_file(outfile, "pin", args_info->pin_orig, 0); - if (args_info->puk_given) - write_into_file(outfile, "puk", args_info->puk_orig, 0); - if (args_info->can_given) - write_into_file(outfile, "can", args_info->can_orig, 0); - if (args_info->mrz_given) - write_into_file(outfile, "mrz", args_info->mrz_orig, 0); - if (args_info->env_given) - write_into_file(outfile, "env", 0, 0 ); - if (args_info->new_pin_given) - write_into_file(outfile, "new-pin", args_info->new_pin_orig, 0); - if (args_info->resume_given) - write_into_file(outfile, "resume", 0, 0 ); - if (args_info->unblock_given) - write_into_file(outfile, "unblock", 0, 0 ); - write_multiple_into_file(outfile, args_info->cv_certificate_given, "cv-certificate", args_info->cv_certificate_orig, 0); - if (args_info->cert_desc_given) - write_into_file(outfile, "cert-desc", args_info->cert_desc_orig, 0); - if (args_info->chat_given) - write_into_file(outfile, "chat", args_info->chat_orig, 0); - if (args_info->auxiliary_data_given) - write_into_file(outfile, "auxiliary-data", args_info->auxiliary_data_orig, 0); - if (args_info->private_key_given) - write_into_file(outfile, "private-key", args_info->private_key_orig, 0); - if (args_info->cvc_dir_given) - write_into_file(outfile, "cvc-dir", args_info->cvc_dir_orig, 0); - if (args_info->x509_dir_given) - write_into_file(outfile, "x509-dir", args_info->x509_dir_orig, 0); - if (args_info->disable_ta_checks_given) - write_into_file(outfile, "disable-ta-checks", 0, 0 ); - if (args_info->disable_ca_checks_given) - write_into_file(outfile, "disable-ca-checks", 0, 0 ); - if (args_info->read_dg1_given) - write_into_file(outfile, "read-dg1", 0, 0 ); - if (args_info->read_dg2_given) - write_into_file(outfile, "read-dg2", 0, 0 ); - if (args_info->read_dg3_given) - write_into_file(outfile, "read-dg3", 0, 0 ); - if (args_info->read_dg4_given) - write_into_file(outfile, "read-dg4", 0, 0 ); - if (args_info->read_dg5_given) - write_into_file(outfile, "read-dg5", 0, 0 ); - if (args_info->read_dg6_given) - write_into_file(outfile, "read-dg6", 0, 0 ); - if (args_info->read_dg7_given) - write_into_file(outfile, "read-dg7", 0, 0 ); - if (args_info->read_dg8_given) - write_into_file(outfile, "read-dg8", 0, 0 ); - if (args_info->read_dg9_given) - write_into_file(outfile, "read-dg9", 0, 0 ); - if (args_info->read_dg10_given) - write_into_file(outfile, "read-dg10", 0, 0 ); - if (args_info->read_dg11_given) - write_into_file(outfile, "read-dg11", 0, 0 ); - if (args_info->read_dg12_given) - write_into_file(outfile, "read-dg12", 0, 0 ); - if (args_info->read_dg13_given) - write_into_file(outfile, "read-dg13", 0, 0 ); - if (args_info->read_dg14_given) - write_into_file(outfile, "read-dg14", 0, 0 ); - if (args_info->read_dg15_given) - write_into_file(outfile, "read-dg15", 0, 0 ); - if (args_info->read_dg16_given) - write_into_file(outfile, "read-dg16", 0, 0 ); - if (args_info->read_dg17_given) - write_into_file(outfile, "read-dg17", 0, 0 ); - if (args_info->read_dg18_given) - write_into_file(outfile, "read-dg18", 0, 0 ); - if (args_info->read_dg19_given) - write_into_file(outfile, "read-dg19", 0, 0 ); - if (args_info->read_dg20_given) - write_into_file(outfile, "read-dg20", 0, 0 ); - if (args_info->read_dg21_given) - write_into_file(outfile, "read-dg21", 0, 0 ); - if (args_info->write_dg17_given) - write_into_file(outfile, "write-dg17", args_info->write_dg17_orig, 0); - if (args_info->write_dg18_given) - write_into_file(outfile, "write-dg18", args_info->write_dg18_orig, 0); - if (args_info->write_dg19_given) - write_into_file(outfile, "write-dg19", args_info->write_dg19_orig, 0); - if (args_info->write_dg20_given) - write_into_file(outfile, "write-dg20", args_info->write_dg20_orig, 0); - if (args_info->write_dg21_given) - write_into_file(outfile, "write-dg21", args_info->write_dg21_orig, 0); - if (args_info->verify_validity_given) - write_into_file(outfile, "verify-validity", args_info->verify_validity_orig, 0); - if (args_info->older_than_given) - write_into_file(outfile, "older-than", args_info->older_than_orig, 0); - if (args_info->verify_community_given) - write_into_file(outfile, "verify-community", args_info->verify_community_orig, 0); - if (args_info->break_given) - write_into_file(outfile, "break", 0, 0 ); - if (args_info->translate_given) - write_into_file(outfile, "translate", args_info->translate_orig, 0); - if (args_info->tr_03110v201_given) - write_into_file(outfile, "tr-03110v201", 0, 0 ); - - - i = EXIT_SUCCESS; - return i; -} - -int -cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) -{ - FILE *outfile; - int i = 0; - - outfile = fopen(filename, "w"); - - if (!outfile) - { - fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); - return EXIT_FAILURE; - } - - i = cmdline_parser_dump(outfile, args_info); - fclose (outfile); - - return i; -} - -void -cmdline_parser_free (struct gengetopt_args_info *args_info) -{ - cmdline_parser_release (args_info); -} - -/** @brief replacement of strdup, which is not standard */ -char * -gengetopt_strdup (const char *s) -{ - char *result = 0; - if (!s) - return result; - - result = (char*)malloc(strlen(s) + 1); - if (result == (char*)0) - return (char*)0; - strcpy(result, s); - return result; -} - -static char * -get_multiple_arg_token(const char *arg) -{ - const char *tok; - char *ret; - size_t len, num_of_escape, i, j; - - if (!arg) - return 0; - - tok = strchr (arg, ','); - num_of_escape = 0; - - /* make sure it is not escaped */ - while (tok) - { - if (*(tok-1) == '\\') - { - /* find the next one */ - tok = strchr (tok+1, ','); - ++num_of_escape; - } - else - break; - } - - if (tok) - len = (size_t)(tok - arg + 1); - else - len = strlen (arg) + 1; - - len -= num_of_escape; - - ret = (char *) malloc (len); - - i = 0; - j = 0; - while (arg[i] && (j < len-1)) - { - if (arg[i] == '\\' && - arg[ i + 1 ] && - arg[ i + 1 ] == ',') - ++i; - - ret[j++] = arg[i++]; - } - - ret[len-1] = '\0'; - - return ret; -} - -static const char * -get_multiple_arg_token_next(const char *arg) -{ - const char *tok; - - if (!arg) - return 0; - - tok = strchr (arg, ','); - - /* make sure it is not escaped */ - while (tok) - { - if (*(tok-1) == '\\') - { - /* find the next one */ - tok = strchr (tok+1, ','); - } - else - break; - } - - if (! tok || strlen(tok) == 1) - return 0; - - return tok+1; -} - -static int -check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc); - -int -check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc) -{ - int error_occurred = 0; - - if (option_given && (min > 0 || max > 0)) - { - if (min > 0 && max > 0) - { - if (min == max) - { - /* specific occurrences */ - if (option_given != (unsigned int) min) - { - fprintf (stderr, "%s: %s option occurrences must be %d\n", - prog_name, option_desc, min); - error_occurred = 1; - } - } - else if (option_given < (unsigned int) min - || option_given > (unsigned int) max) - { - /* range occurrences */ - fprintf (stderr, "%s: %s option occurrences must be between %d and %d\n", - prog_name, option_desc, min, max); - error_occurred = 1; - } - } - else if (min > 0) - { - /* at least check */ - if (option_given < min) - { - fprintf (stderr, "%s: %s option occurrences must be at least %d\n", - prog_name, option_desc, min); - error_occurred = 1; - } - } - else if (max > 0) - { - /* at most check */ - if (option_given > max) - { - fprintf (stderr, "%s: %s option occurrences must be at most %d\n", - prog_name, option_desc, max); - error_occurred = 1; - } - } - } - - return error_occurred; -} -int -cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info) -{ - return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); -} - -int -cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params) -{ - int result; - result = cmdline_parser_internal (argc, argv, args_info, params, 0); - - if (result == EXIT_FAILURE) - { - cmdline_parser_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) -{ - int result; - struct cmdline_parser_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0); - - if (result == EXIT_FAILURE) - { - cmdline_parser_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) -{ - int result = EXIT_SUCCESS; - - if (cmdline_parser_required2(args_info, prog_name, 0) > 0) - result = EXIT_FAILURE; - - if (result == EXIT_FAILURE) - { - cmdline_parser_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error) -{ - int error_occurred = 0; - FIX_UNUSED (additional_error); - - /* checks for required options */ - if (check_multiple_option_occurrences(prog_name, args_info->verbose_given, args_info->verbose_min, args_info->verbose_max, "'--verbose' ('-v')")) - error_occurred = 1; - - if (check_multiple_option_occurrences(prog_name, args_info->cv_certificate_given, args_info->cv_certificate_min, args_info->cv_certificate_max, "'--cv-certificate' ('-C')")) - error_occurred = 1; - - - /* checks for dependences among options */ - - return error_occurred; -} - - -static char *package_name = 0; - -/** - * @brief updates an option - * @param field the generic pointer to the field to update - * @param orig_field the pointer to the orig field - * @param field_given the pointer to the number of occurrence of this option - * @param prev_given the pointer to the number of occurrence already seen - * @param value the argument for this option (if null no arg was specified) - * @param possible_values the possible values for this option (if specified) - * @param default_value the default value (in case the option only accepts fixed values) - * @param arg_type the type of this option - * @param check_ambiguity @see cmdline_parser_params.check_ambiguity - * @param override @see cmdline_parser_params.override - * @param no_free whether to free a possible previous value - * @param multiple_option whether this is a multiple option - * @param long_opt the corresponding long option - * @param short_opt the corresponding short option (or '-' if none) - * @param additional_error possible further error specification - */ -static -int update_arg(void *field, char **orig_field, - unsigned int *field_given, unsigned int *prev_given, - char *value, const char *possible_values[], - const char *default_value, - cmdline_parser_arg_type arg_type, - int check_ambiguity, int override, - int no_free, int multiple_option, - const char *long_opt, char short_opt, - const char *additional_error) -{ - char *stop_char = 0; - const char *val = value; - int found; - char **string_field; - FIX_UNUSED (field); - - stop_char = 0; - found = 0; - - if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) - { - if (short_opt != '-') - fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", - package_name, long_opt, short_opt, - (additional_error ? additional_error : "")); - else - fprintf (stderr, "%s: `--%s' option given more than once%s\n", - package_name, long_opt, - (additional_error ? additional_error : "")); - return 1; /* failure */ - } - - FIX_UNUSED (default_value); - - if (field_given && *field_given && ! override) - return 0; - if (prev_given) - (*prev_given)++; - if (field_given) - (*field_given)++; - if (possible_values) - val = possible_values[found]; - - switch(arg_type) { - case ARG_FLAG: - *((int *)field) = !*((int *)field); - break; - case ARG_STRING: - if (val) { - string_field = (char **)field; - if (!no_free && *string_field) - free (*string_field); /* free previous string */ - *string_field = gengetopt_strdup (val); - } - break; - default: - break; - }; - - FIX_UNUSED(stop_char); - - /* store the original value */ - switch(arg_type) { - case ARG_NO: - case ARG_FLAG: - break; - default: - if (value && orig_field) { - if (no_free) { - *orig_field = value; - } else { - if (*orig_field) - free (*orig_field); /* free previous string */ - *orig_field = gengetopt_strdup (value); - } - } - }; - - return 0; /* OK */ -} - -/** - * @brief store information about a multiple option in a temporary list - * @param list where to (temporarily) store multiple options - */ -static -int update_multiple_arg_temp(struct generic_list **list, - unsigned int *prev_given, const char *val, - const char *possible_values[], const char *default_value, - cmdline_parser_arg_type arg_type, - const char *long_opt, char short_opt, - const char *additional_error) -{ - /* store single arguments */ - char *multi_token; - const char *multi_next; - - if (arg_type == ARG_NO) { - (*prev_given)++; - return 0; /* OK */ - } - - multi_token = get_multiple_arg_token(val); - multi_next = get_multiple_arg_token_next (val); - - while (1) - { - add_node (list); - if (update_arg((void *)&((*list)->arg), &((*list)->orig), 0, - prev_given, multi_token, possible_values, default_value, - arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) { - if (multi_token) free(multi_token); - return 1; /* failure */ - } - - if (multi_next) - { - multi_token = get_multiple_arg_token(multi_next); - multi_next = get_multiple_arg_token_next (multi_next); - } - else - break; - } - - return 0; /* OK */ -} - -/** - * @brief free the passed list (including possible string argument) - */ -static -void free_list(struct generic_list *list, short string_arg) -{ - if (list) { - struct generic_list *tmp; - while (list) - { - tmp = list; - if (string_arg && list->arg.string_arg) - free (list->arg.string_arg); - if (list->orig) - free (list->orig); - list = list->next; - free (tmp); - } - } -} - -/** - * @brief updates a multiple option starting from the passed list - */ -static -void update_multiple_arg(void *field, char ***orig_field, - unsigned int field_given, unsigned int prev_given, union generic_value *default_value, - cmdline_parser_arg_type arg_type, - struct generic_list *list) -{ - int i; - struct generic_list *tmp; - - if (prev_given && list) { - *orig_field = (char **) realloc (*orig_field, (field_given + prev_given) * sizeof (char *)); - - switch(arg_type) { - case ARG_STRING: - *((char ***)field) = (char **)realloc (*((char ***)field), (field_given + prev_given) * sizeof (char *)); break; - default: - break; - }; - - for (i = (prev_given - 1); i >= 0; --i) - { - tmp = list; - - switch(arg_type) { - case ARG_STRING: - (*((char ***)field))[i + field_given] = tmp->arg.string_arg; break; - default: - break; - } - (*orig_field) [i + field_given] = list->orig; - list = list->next; - free (tmp); - } - } else { /* set the default value */ - if (default_value && ! field_given) { - switch(arg_type) { - case ARG_STRING: - if (! *((char ***)field)) { - *((char ***)field) = (char **)malloc (sizeof (char *)); - (*((char ***)field))[0] = gengetopt_strdup(default_value->string_arg); - } - break; - default: break; - } - if (!(*orig_field)) { - *orig_field = (char **) malloc (sizeof (char *)); - (*orig_field)[0] = 0; - } - } - } -} - -int -cmdline_parser_internal ( - int argc, char **argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params, const char *additional_error) -{ - int c; /* Character of the parsed option. */ - - struct generic_list * cv_certificate_list = NULL; - int error_occurred = 0; - struct gengetopt_args_info local_args_info; - - int override; - int initialize; - int check_required; - int check_ambiguity; - - package_name = argv[0]; - - /* TODO: Why is this here? It is not used anywhere. */ - override = params->override; - FIX_UNUSED(override); - - initialize = params->initialize; - check_required = params->check_required; - - /* TODO: Why is this here? It is not used anywhere. */ - check_ambiguity = params->check_ambiguity; - FIX_UNUSED(check_ambiguity); - - if (initialize) - cmdline_parser_init (args_info); - - cmdline_parser_init (&local_args_info); - - optarg = 0; - optind = 0; - opterr = params->print_errors; - optopt = '?'; - - while (1) - { - int option_index = 0; - - static struct option long_options[] = { - { "help", 0, NULL, 'h' }, - { "version", 0, NULL, 'V' }, - { "reader", 1, NULL, 'r' }, - { "verbose", 0, NULL, 'v' }, - { "pin", 2, NULL, 'p' }, - { "puk", 2, NULL, 'u' }, - { "can", 2, NULL, 'c' }, - { "mrz", 2, NULL, 'm' }, - { "env", 0, NULL, 0 }, - { "new-pin", 2, NULL, 'N' }, - { "resume", 0, NULL, 'R' }, - { "unblock", 0, NULL, 'U' }, - { "cv-certificate", 1, NULL, 'C' }, - { "cert-desc", 1, NULL, 0 }, - { "chat", 1, NULL, 0 }, - { "auxiliary-data", 1, NULL, 'A' }, - { "private-key", 1, NULL, 'P' }, - { "cvc-dir", 1, NULL, 0 }, - { "x509-dir", 1, NULL, 0 }, - { "disable-ta-checks", 0, NULL, 0 }, - { "disable-ca-checks", 0, NULL, 0 }, - { "read-dg1", 0, NULL, 0 }, - { "read-dg2", 0, NULL, 0 }, - { "read-dg3", 0, NULL, 0 }, - { "read-dg4", 0, NULL, 0 }, - { "read-dg5", 0, NULL, 0 }, - { "read-dg6", 0, NULL, 0 }, - { "read-dg7", 0, NULL, 0 }, - { "read-dg8", 0, NULL, 0 }, - { "read-dg9", 0, NULL, 0 }, - { "read-dg10", 0, NULL, 0 }, - { "read-dg11", 0, NULL, 0 }, - { "read-dg12", 0, NULL, 0 }, - { "read-dg13", 0, NULL, 0 }, - { "read-dg14", 0, NULL, 0 }, - { "read-dg15", 0, NULL, 0 }, - { "read-dg16", 0, NULL, 0 }, - { "read-dg17", 0, NULL, 0 }, - { "read-dg18", 0, NULL, 0 }, - { "read-dg19", 0, NULL, 0 }, - { "read-dg20", 0, NULL, 0 }, - { "read-dg21", 0, NULL, 0 }, - { "write-dg17", 1, NULL, 0 }, - { "write-dg18", 1, NULL, 0 }, - { "write-dg19", 1, NULL, 0 }, - { "write-dg20", 1, NULL, 0 }, - { "write-dg21", 1, NULL, 0 }, - { "verify-validity", 1, NULL, 0 }, - { "older-than", 1, NULL, 0 }, - { "verify-community", 1, NULL, 0 }, - { "break", 0, NULL, 'b' }, - { "translate", 1, NULL, 't' }, - { "tr-03110v201", 0, NULL, 0 }, - { 0, 0, 0, 0 } - }; - - c = getopt_long (argc, argv, "hVr:vp::u::c::m::N::RUC:A:P:bt:", long_options, &option_index); - - if (c == -1) break; /* Exit from `while (1)' loop. */ - - switch (c) - { - case 'h': /* Print help and exit. */ - cmdline_parser_print_help (); - cmdline_parser_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'V': /* Print version and exit. */ - cmdline_parser_print_version (); - cmdline_parser_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'r': /* Number of the reader to use. By default, the first reader with a present card is used. If the argument is an ATR, the reader with a matching card will be chosen.. */ - - - if (update_arg( (void *)&(args_info->reader_arg), - &(args_info->reader_orig), &(args_info->reader_given), - &(local_args_info.reader_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "reader", 'r', - additional_error)) - goto failure; - - break; - case 'v': /* Use (several times) to be more verbose. */ - - local_args_info.verbose_given++; - - break; - case 'p': /* Run PACE with (transport) eID-PIN. */ - - - if (update_arg( (void *)&(args_info->pin_arg), - &(args_info->pin_orig), &(args_info->pin_given), - &(local_args_info.pin_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "pin", 'p', - additional_error)) - goto failure; - - break; - case 'u': /* Run PACE with PUK. */ - - - if (update_arg( (void *)&(args_info->puk_arg), - &(args_info->puk_orig), &(args_info->puk_given), - &(local_args_info.puk_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "puk", 'u', - additional_error)) - goto failure; - - break; - case 'c': /* Run PACE with CAN. */ - - - if (update_arg( (void *)&(args_info->can_arg), - &(args_info->can_orig), &(args_info->can_given), - &(local_args_info.can_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "can", 'c', - additional_error)) - goto failure; - - break; - case 'm': /* Run PACE with MRZ (insert MRZ without newlines). */ - - - if (update_arg( (void *)&(args_info->mrz_arg), - &(args_info->mrz_orig), &(args_info->mrz_given), - &(local_args_info.mrz_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "mrz", 'm', - additional_error)) - goto failure; - - break; - case 'N': /* Install a new PIN. */ - - - if (update_arg( (void *)&(args_info->new_pin_arg), - &(args_info->new_pin_orig), &(args_info->new_pin_given), - &(local_args_info.new_pin_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "new-pin", 'N', - additional_error)) - goto failure; - - break; - case 'R': /* Resume eID-PIN (uses CAN to activate last retry). */ - - - if (update_arg((void *)&(args_info->resume_flag), 0, &(args_info->resume_given), - &(local_args_info.resume_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "resume", 'R', - additional_error)) - goto failure; - - break; - case 'U': /* Unblock PIN (uses PUK to activate three more retries). */ - - - if (update_arg((void *)&(args_info->unblock_flag), 0, &(args_info->unblock_given), - &(local_args_info.unblock_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "unblock", 'U', - additional_error)) - goto failure; - - break; - case 'C': /* Card Verifiable Certificate to create a certificate chain. Can be used multiple times (order is important).. */ - - if (update_multiple_arg_temp(&cv_certificate_list, - &(local_args_info.cv_certificate_given), optarg, 0, 0, ARG_STRING, - "cv-certificate", 'C', - additional_error)) - goto failure; - - break; - case 'A': /* Terminal's auxiliary data (default is determined by verification of validity, age and community ID).. */ - - - if (update_arg( (void *)&(args_info->auxiliary_data_arg), - &(args_info->auxiliary_data_orig), &(args_info->auxiliary_data_given), - &(local_args_info.auxiliary_data_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "auxiliary-data", 'A', - additional_error)) - goto failure; - - break; - case 'P': /* Terminal's private key. */ - - - if (update_arg( (void *)&(args_info->private_key_arg), - &(args_info->private_key_orig), &(args_info->private_key_given), - &(local_args_info.private_key_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "private-key", 'P', - additional_error)) - goto failure; - - break; - case 'b': /* Brute force PIN, CAN or PUK. Use together with -p, -a or -u. */ - - - if (update_arg((void *)&(args_info->break_flag), 0, &(args_info->break_given), - &(local_args_info.break_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "break", 'b', - additional_error)) - goto failure; - - break; - case 't': /* File with APDUs of HEX_STRINGs to send through the secure channel. */ - - - if (update_arg( (void *)&(args_info->translate_arg), - &(args_info->translate_orig), &(args_info->translate_given), - &(local_args_info.translate_given), optarg, 0, "stdin", ARG_STRING, - check_ambiguity, override, 0, 0, - "translate", 't', - additional_error)) - goto failure; - - break; - - case 0: /* Long option with no short option */ - /* Whether to use environment variables PIN, PUK, CAN, MRZ and NEWPIN. You may want to clean your environment before enabling this.. */ - if (strcmp (long_options[option_index].name, "env") == 0) - { - - - if (update_arg((void *)&(args_info->env_flag), 0, &(args_info->env_given), - &(local_args_info.env_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "env", '-', - additional_error)) - goto failure; - - } - /* Certificate description to show for Terminal Authentication. */ - else if (strcmp (long_options[option_index].name, "cert-desc") == 0) - { - - - if (update_arg( (void *)&(args_info->cert_desc_arg), - &(args_info->cert_desc_orig), &(args_info->cert_desc_given), - &(local_args_info.cert_desc_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "cert-desc", '-', - additional_error)) - goto failure; - - } - /* Card holder authorization template to use (default is terminal's CHAT). Use 7F4C0E060904007F000703010203530103 to trigger EAC on the CAT-C (Komfortleser).. */ - else if (strcmp (long_options[option_index].name, "chat") == 0) - { - - - if (update_arg( (void *)&(args_info->chat_arg), - &(args_info->chat_orig), &(args_info->chat_given), - &(local_args_info.chat_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "chat", '-', - additional_error)) - goto failure; - - } - /* Where to look for the CVCA's certificate. */ - else if (strcmp (long_options[option_index].name, "cvc-dir") == 0) - { - - - if (update_arg( (void *)&(args_info->cvc_dir_arg), - &(args_info->cvc_dir_orig), &(args_info->cvc_dir_given), - &(local_args_info.cvc_dir_given), optarg, 0, "", ARG_STRING, - check_ambiguity, override, 0, 0, - "cvc-dir", '-', - additional_error)) - goto failure; - - } - /* Where to look for the CSCA's certificate. */ - else if (strcmp (long_options[option_index].name, "x509-dir") == 0) - { - - - if (update_arg( (void *)&(args_info->x509_dir_arg), - &(args_info->x509_dir_orig), &(args_info->x509_dir_given), - &(local_args_info.x509_dir_given), optarg, 0, "", ARG_STRING, - check_ambiguity, override, 0, 0, - "x509-dir", '-', - additional_error)) - goto failure; - - } - /* Disable checking the validity period of CV certificates. */ - else if (strcmp (long_options[option_index].name, "disable-ta-checks") == 0) - { - - - if (update_arg((void *)&(args_info->disable_ta_checks_flag), 0, &(args_info->disable_ta_checks_given), - &(local_args_info.disable_ta_checks_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "disable-ta-checks", '-', - additional_error)) - goto failure; - - } - /* Disable passive authentication. */ - else if (strcmp (long_options[option_index].name, "disable-ca-checks") == 0) - { - - - if (update_arg((void *)&(args_info->disable_ca_checks_flag), 0, &(args_info->disable_ca_checks_given), - &(local_args_info.disable_ca_checks_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "disable-ca-checks", '-', - additional_error)) - goto failure; - - } - /* Read DG 1 (Document Type). */ - else if (strcmp (long_options[option_index].name, "read-dg1") == 0) - { - - - if (update_arg((void *)&(args_info->read_dg1_flag), 0, &(args_info->read_dg1_given), - &(local_args_info.read_dg1_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "read-dg1", '-', - additional_error)) - goto failure; - - } - /* Read DG 2 (Issuing State). */ - else if (strcmp (long_options[option_index].name, "read-dg2") == 0) - { - - - if (update_arg((void *)&(args_info->read_dg2_flag), 0, &(args_info->read_dg2_given), - &(local_args_info.read_dg2_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "read-dg2", '-', - additional_error)) - goto failure; - - } - /* Read DG 3 (Date of Expiry). */ - else if (strcmp (long_options[option_index].name, "read-dg3") == 0) - { - - - if (update_arg((void *)&(args_info->read_dg3_flag), 0, &(args_info->read_dg3_given), - &(local_args_info.read_dg3_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "read-dg3", '-', - additional_error)) - goto failure; - - } - /* Read DG 4 (Given Names). */ - else if (strcmp (long_options[option_index].name, "read-dg4") == 0) - { - - - if (update_arg((void *)&(args_info->read_dg4_flag), 0, &(args_info->read_dg4_given), - &(local_args_info.read_dg4_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "read-dg4", '-', - additional_error)) - goto failure; - - } - /* Read DG 5 (Family Names). */ - else if (strcmp (long_options[option_index].name, "read-dg5") == 0) - { - - - if (update_arg((void *)&(args_info->read_dg5_flag), 0, &(args_info->read_dg5_given), - &(local_args_info.read_dg5_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "read-dg5", '-', - additional_error)) - goto failure; - - } - /* Read DG 6 (Religious/Artistic Name). */ - else if (strcmp (long_options[option_index].name, "read-dg6") == 0) - { - - - if (update_arg((void *)&(args_info->read_dg6_flag), 0, &(args_info->read_dg6_given), - &(local_args_info.read_dg6_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "read-dg6", '-', - additional_error)) - goto failure; - - } - /* Read DG 7 (Academic Title). */ - else if (strcmp (long_options[option_index].name, "read-dg7") == 0) - { - - - if (update_arg((void *)&(args_info->read_dg7_flag), 0, &(args_info->read_dg7_given), - &(local_args_info.read_dg7_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "read-dg7", '-', - additional_error)) - goto failure; - - } - /* Read DG 8 (Date of Birth). */ - else if (strcmp (long_options[option_index].name, "read-dg8") == 0) - { - - - if (update_arg((void *)&(args_info->read_dg8_flag), 0, &(args_info->read_dg8_given), - &(local_args_info.read_dg8_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "read-dg8", '-', - additional_error)) - goto failure; - - } - /* Read DG 9 (Place of Birth). */ - else if (strcmp (long_options[option_index].name, "read-dg9") == 0) - { - - - if (update_arg((void *)&(args_info->read_dg9_flag), 0, &(args_info->read_dg9_given), - &(local_args_info.read_dg9_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "read-dg9", '-', - additional_error)) - goto failure; - - } - /* Read DG 10 (Nationality). */ - else if (strcmp (long_options[option_index].name, "read-dg10") == 0) - { - - - if (update_arg((void *)&(args_info->read_dg10_flag), 0, &(args_info->read_dg10_given), - &(local_args_info.read_dg10_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "read-dg10", '-', - additional_error)) - goto failure; - - } - /* Read DG 11 (Sex). */ - else if (strcmp (long_options[option_index].name, "read-dg11") == 0) - { - - - if (update_arg((void *)&(args_info->read_dg11_flag), 0, &(args_info->read_dg11_given), - &(local_args_info.read_dg11_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "read-dg11", '-', - additional_error)) - goto failure; - - } - /* Read DG 12 (Optional Data). */ - else if (strcmp (long_options[option_index].name, "read-dg12") == 0) - { - - - if (update_arg((void *)&(args_info->read_dg12_flag), 0, &(args_info->read_dg12_given), - &(local_args_info.read_dg12_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "read-dg12", '-', - additional_error)) - goto failure; - - } - /* Read DG 13 (Birth Name). */ - else if (strcmp (long_options[option_index].name, "read-dg13") == 0) - { - - - if (update_arg((void *)&(args_info->read_dg13_flag), 0, &(args_info->read_dg13_given), - &(local_args_info.read_dg13_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "read-dg13", '-', - additional_error)) - goto failure; - - } - /* Read DG 14. */ - else if (strcmp (long_options[option_index].name, "read-dg14") == 0) - { - - - if (update_arg((void *)&(args_info->read_dg14_flag), 0, &(args_info->read_dg14_given), - &(local_args_info.read_dg14_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "read-dg14", '-', - additional_error)) - goto failure; - - } - /* Read DG 15. */ - else if (strcmp (long_options[option_index].name, "read-dg15") == 0) - { - - - if (update_arg((void *)&(args_info->read_dg15_flag), 0, &(args_info->read_dg15_given), - &(local_args_info.read_dg15_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "read-dg15", '-', - additional_error)) - goto failure; - - } - /* Read DG 16. */ - else if (strcmp (long_options[option_index].name, "read-dg16") == 0) - { - - - if (update_arg((void *)&(args_info->read_dg16_flag), 0, &(args_info->read_dg16_given), - &(local_args_info.read_dg16_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "read-dg16", '-', - additional_error)) - goto failure; - - } - /* Read DG 17 (Normal Place of Residence). */ - else if (strcmp (long_options[option_index].name, "read-dg17") == 0) - { - - - if (update_arg((void *)&(args_info->read_dg17_flag), 0, &(args_info->read_dg17_given), - &(local_args_info.read_dg17_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "read-dg17", '-', - additional_error)) - goto failure; - - } - /* Read DG 18 (Community ID). */ - else if (strcmp (long_options[option_index].name, "read-dg18") == 0) - { - - - if (update_arg((void *)&(args_info->read_dg18_flag), 0, &(args_info->read_dg18_given), - &(local_args_info.read_dg18_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "read-dg18", '-', - additional_error)) - goto failure; - - } - /* Read DG 19 (Residence Permit I). */ - else if (strcmp (long_options[option_index].name, "read-dg19") == 0) - { - - - if (update_arg((void *)&(args_info->read_dg19_flag), 0, &(args_info->read_dg19_given), - &(local_args_info.read_dg19_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "read-dg19", '-', - additional_error)) - goto failure; - - } - /* Read DG 20 (Residence Permit II). */ - else if (strcmp (long_options[option_index].name, "read-dg20") == 0) - { - - - if (update_arg((void *)&(args_info->read_dg20_flag), 0, &(args_info->read_dg20_given), - &(local_args_info.read_dg20_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "read-dg20", '-', - additional_error)) - goto failure; - - } - /* Read DG 21 (Optional Data). */ - else if (strcmp (long_options[option_index].name, "read-dg21") == 0) - { - - - if (update_arg((void *)&(args_info->read_dg21_flag), 0, &(args_info->read_dg21_given), - &(local_args_info.read_dg21_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "read-dg21", '-', - additional_error)) - goto failure; - - } - /* Write DG 17 (Normal Place of Residence). */ - else if (strcmp (long_options[option_index].name, "write-dg17") == 0) - { - - - if (update_arg( (void *)&(args_info->write_dg17_arg), - &(args_info->write_dg17_orig), &(args_info->write_dg17_given), - &(local_args_info.write_dg17_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "write-dg17", '-', - additional_error)) - goto failure; - - } - /* Write DG 18 (Community ID). */ - else if (strcmp (long_options[option_index].name, "write-dg18") == 0) - { - - - if (update_arg( (void *)&(args_info->write_dg18_arg), - &(args_info->write_dg18_orig), &(args_info->write_dg18_given), - &(local_args_info.write_dg18_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "write-dg18", '-', - additional_error)) - goto failure; - - } - /* Write DG 19 (Residence Permit I). */ - else if (strcmp (long_options[option_index].name, "write-dg19") == 0) - { - - - if (update_arg( (void *)&(args_info->write_dg19_arg), - &(args_info->write_dg19_orig), &(args_info->write_dg19_given), - &(local_args_info.write_dg19_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "write-dg19", '-', - additional_error)) - goto failure; - - } - /* Write DG 20 (Residence Permit II). */ - else if (strcmp (long_options[option_index].name, "write-dg20") == 0) - { - - - if (update_arg( (void *)&(args_info->write_dg20_arg), - &(args_info->write_dg20_orig), &(args_info->write_dg20_given), - &(local_args_info.write_dg20_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "write-dg20", '-', - additional_error)) - goto failure; - - } - /* Write DG 21 (Optional Data). */ - else if (strcmp (long_options[option_index].name, "write-dg21") == 0) - { - - - if (update_arg( (void *)&(args_info->write_dg21_arg), - &(args_info->write_dg21_orig), &(args_info->write_dg21_given), - &(local_args_info.write_dg21_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "write-dg21", '-', - additional_error)) - goto failure; - - } - /* Verify chip's validity with a reference date. */ - else if (strcmp (long_options[option_index].name, "verify-validity") == 0) - { - - - if (update_arg( (void *)&(args_info->verify_validity_arg), - &(args_info->verify_validity_orig), &(args_info->verify_validity_given), - &(local_args_info.verify_validity_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "verify-validity", '-', - additional_error)) - goto failure; - - } - /* Verify age with a reference date. */ - else if (strcmp (long_options[option_index].name, "older-than") == 0) - { - - - if (update_arg( (void *)&(args_info->older_than_arg), - &(args_info->older_than_orig), &(args_info->older_than_given), - &(local_args_info.older_than_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "older-than", '-', - additional_error)) - goto failure; - - } - /* Verify community ID with a reference ID. */ - else if (strcmp (long_options[option_index].name, "verify-community") == 0) - { - - - if (update_arg( (void *)&(args_info->verify_community_arg), - &(args_info->verify_community_orig), &(args_info->verify_community_given), - &(local_args_info.verify_community_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "verify-community", '-', - additional_error)) - goto failure; - - } - /* Force compliance to BSI TR-03110 version 2.01. */ - else if (strcmp (long_options[option_index].name, "tr-03110v201") == 0) - { - - - if (update_arg((void *)&(args_info->tr_03110v201_flag), 0, &(args_info->tr_03110v201_given), - &(local_args_info.tr_03110v201_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "tr-03110v201", '-', - additional_error)) - goto failure; - - } - - break; - case '?': /* Invalid option. */ - /* `getopt_long' already printed an error message. */ - goto failure; - - default: /* bug: option not considered. */ - fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); - abort (); - } /* switch */ - } /* while */ - - - update_multiple_arg((void *)&(args_info->cv_certificate_arg), - &(args_info->cv_certificate_orig), args_info->cv_certificate_given, - local_args_info.cv_certificate_given, 0, - ARG_STRING, cv_certificate_list); - - args_info->verbose_given += local_args_info.verbose_given; - local_args_info.verbose_given = 0; - args_info->cv_certificate_given += local_args_info.cv_certificate_given; - local_args_info.cv_certificate_given = 0; - - if (check_required) - { - error_occurred += cmdline_parser_required2 (args_info, argv[0], additional_error); - } - - cmdline_parser_release (&local_args_info); - - if ( error_occurred ) - return (EXIT_FAILURE); - - return 0; - -failure: - free_list (cv_certificate_list, 1 ); - - cmdline_parser_release (&local_args_info); - return (EXIT_FAILURE); -} -/* vim: set ft=c noet ts=8 sts=8 sw=8 tw=80 nojs spell : */ diff --git a/src/tools/npa-tool-cmdline.h b/src/tools/npa-tool-cmdline.h deleted file mode 100644 index e38e1e69a8..0000000000 --- a/src/tools/npa-tool-cmdline.h +++ /dev/null @@ -1,351 +0,0 @@ -/** @file npa-tool-cmdline.h - * @brief The header file for the command line option parser - * generated by GNU Gengetopt version 2.23 - * http://www.gnu.org/software/gengetopt. - * DO NOT modify this file, since it can be overwritten - * @author GNU Gengetopt */ - -#ifndef NPA_TOOL_CMDLINE_H -#define NPA_TOOL_CMDLINE_H - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for FILE */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifndef CMDLINE_PARSER_PACKAGE -/** @brief the program name (used for printing errors) */ -#define CMDLINE_PARSER_PACKAGE "npa-tool" -#endif - -#ifndef CMDLINE_PARSER_PACKAGE_NAME -/** @brief the complete program name (used for help and version) */ -#define CMDLINE_PARSER_PACKAGE_NAME "npa-tool" -#endif - -#ifndef CMDLINE_PARSER_VERSION -/** @brief the program version */ -#define CMDLINE_PARSER_VERSION VERSION -#endif - -/** @brief Where the command line options are stored */ -struct gengetopt_args_info -{ - const char *help_help; /**< @brief Print help and exit help description. */ - const char *version_help; /**< @brief Print version and exit help description. */ - char * reader_arg; /**< @brief Number of the reader to use. By default, the first reader with a present card is used. If the argument is an ATR, the reader with a matching card will be chosen.. */ - char * reader_orig; /**< @brief Number of the reader to use. By default, the first reader with a present card is used. If the argument is an ATR, the reader with a matching card will be chosen. original value given at command line. */ - const char *reader_help; /**< @brief Number of the reader to use. By default, the first reader with a present card is used. If the argument is an ATR, the reader with a matching card will be chosen. help description. */ - unsigned int verbose_min; /**< @brief Use (several times) to be more verbose's minimum occurreces */ - unsigned int verbose_max; /**< @brief Use (several times) to be more verbose's maximum occurreces */ - const char *verbose_help; /**< @brief Use (several times) to be more verbose help description. */ - char * pin_arg; /**< @brief Run PACE with (transport) eID-PIN. */ - char * pin_orig; /**< @brief Run PACE with (transport) eID-PIN original value given at command line. */ - const char *pin_help; /**< @brief Run PACE with (transport) eID-PIN help description. */ - char * puk_arg; /**< @brief Run PACE with PUK. */ - char * puk_orig; /**< @brief Run PACE with PUK original value given at command line. */ - const char *puk_help; /**< @brief Run PACE with PUK help description. */ - char * can_arg; /**< @brief Run PACE with CAN. */ - char * can_orig; /**< @brief Run PACE with CAN original value given at command line. */ - const char *can_help; /**< @brief Run PACE with CAN help description. */ - char * mrz_arg; /**< @brief Run PACE with MRZ (insert MRZ without newlines). */ - char * mrz_orig; /**< @brief Run PACE with MRZ (insert MRZ without newlines) original value given at command line. */ - const char *mrz_help; /**< @brief Run PACE with MRZ (insert MRZ without newlines) help description. */ - int env_flag; /**< @brief Whether to use environment variables PIN, PUK, CAN, MRZ and NEWPIN. You may want to clean your environment before enabling this. (default=off). */ - const char *env_help; /**< @brief Whether to use environment variables PIN, PUK, CAN, MRZ and NEWPIN. You may want to clean your environment before enabling this. help description. */ - char * new_pin_arg; /**< @brief Install a new PIN. */ - char * new_pin_orig; /**< @brief Install a new PIN original value given at command line. */ - const char *new_pin_help; /**< @brief Install a new PIN help description. */ - int resume_flag; /**< @brief Resume eID-PIN (uses CAN to activate last retry) (default=off). */ - const char *resume_help; /**< @brief Resume eID-PIN (uses CAN to activate last retry) help description. */ - int unblock_flag; /**< @brief Unblock PIN (uses PUK to activate three more retries) (default=off). */ - const char *unblock_help; /**< @brief Unblock PIN (uses PUK to activate three more retries) help description. */ - char ** cv_certificate_arg; /**< @brief Card Verifiable Certificate to create a certificate chain. Can be used multiple times (order is important).. */ - char ** cv_certificate_orig; /**< @brief Card Verifiable Certificate to create a certificate chain. Can be used multiple times (order is important). original value given at command line. */ - unsigned int cv_certificate_min; /**< @brief Card Verifiable Certificate to create a certificate chain. Can be used multiple times (order is important).'s minimum occurreces */ - unsigned int cv_certificate_max; /**< @brief Card Verifiable Certificate to create a certificate chain. Can be used multiple times (order is important).'s maximum occurreces */ - const char *cv_certificate_help; /**< @brief Card Verifiable Certificate to create a certificate chain. Can be used multiple times (order is important). help description. */ - char * cert_desc_arg; /**< @brief Certificate description to show for Terminal Authentication. */ - char * cert_desc_orig; /**< @brief Certificate description to show for Terminal Authentication original value given at command line. */ - const char *cert_desc_help; /**< @brief Certificate description to show for Terminal Authentication help description. */ - char * chat_arg; /**< @brief Card holder authorization template to use (default is terminal's CHAT). Use 7F4C0E060904007F000703010203530103 to trigger EAC on the CAT-C (Komfortleser).. */ - char * chat_orig; /**< @brief Card holder authorization template to use (default is terminal's CHAT). Use 7F4C0E060904007F000703010203530103 to trigger EAC on the CAT-C (Komfortleser). original value given at command line. */ - const char *chat_help; /**< @brief Card holder authorization template to use (default is terminal's CHAT). Use 7F4C0E060904007F000703010203530103 to trigger EAC on the CAT-C (Komfortleser). help description. */ - char * auxiliary_data_arg; /**< @brief Terminal's auxiliary data (default is determined by verification of validity, age and community ID).. */ - char * auxiliary_data_orig; /**< @brief Terminal's auxiliary data (default is determined by verification of validity, age and community ID). original value given at command line. */ - const char *auxiliary_data_help; /**< @brief Terminal's auxiliary data (default is determined by verification of validity, age and community ID). help description. */ - char * private_key_arg; /**< @brief Terminal's private key. */ - char * private_key_orig; /**< @brief Terminal's private key original value given at command line. */ - const char *private_key_help; /**< @brief Terminal's private key help description. */ - char * cvc_dir_arg; /**< @brief Where to look for the CVCA's certificate (default=''). */ - char * cvc_dir_orig; /**< @brief Where to look for the CVCA's certificate original value given at command line. */ - const char *cvc_dir_help; /**< @brief Where to look for the CVCA's certificate help description. */ - char * x509_dir_arg; /**< @brief Where to look for the CSCA's certificate (default=''). */ - char * x509_dir_orig; /**< @brief Where to look for the CSCA's certificate original value given at command line. */ - const char *x509_dir_help; /**< @brief Where to look for the CSCA's certificate help description. */ - int disable_ta_checks_flag; /**< @brief Disable checking the validity period of CV certificates (default=off). */ - const char *disable_ta_checks_help; /**< @brief Disable checking the validity period of CV certificates help description. */ - int disable_ca_checks_flag; /**< @brief Disable passive authentication (default=off). */ - const char *disable_ca_checks_help; /**< @brief Disable passive authentication help description. */ - int read_dg1_flag; /**< @brief Read DG 1 (Document Type) (default=off). */ - const char *read_dg1_help; /**< @brief Read DG 1 (Document Type) help description. */ - int read_dg2_flag; /**< @brief Read DG 2 (Issuing State) (default=off). */ - const char *read_dg2_help; /**< @brief Read DG 2 (Issuing State) help description. */ - int read_dg3_flag; /**< @brief Read DG 3 (Date of Expiry) (default=off). */ - const char *read_dg3_help; /**< @brief Read DG 3 (Date of Expiry) help description. */ - int read_dg4_flag; /**< @brief Read DG 4 (Given Names) (default=off). */ - const char *read_dg4_help; /**< @brief Read DG 4 (Given Names) help description. */ - int read_dg5_flag; /**< @brief Read DG 5 (Family Names) (default=off). */ - const char *read_dg5_help; /**< @brief Read DG 5 (Family Names) help description. */ - int read_dg6_flag; /**< @brief Read DG 6 (Religious/Artistic Name) (default=off). */ - const char *read_dg6_help; /**< @brief Read DG 6 (Religious/Artistic Name) help description. */ - int read_dg7_flag; /**< @brief Read DG 7 (Academic Title) (default=off). */ - const char *read_dg7_help; /**< @brief Read DG 7 (Academic Title) help description. */ - int read_dg8_flag; /**< @brief Read DG 8 (Date of Birth) (default=off). */ - const char *read_dg8_help; /**< @brief Read DG 8 (Date of Birth) help description. */ - int read_dg9_flag; /**< @brief Read DG 9 (Place of Birth) (default=off). */ - const char *read_dg9_help; /**< @brief Read DG 9 (Place of Birth) help description. */ - int read_dg10_flag; /**< @brief Read DG 10 (Nationality) (default=off). */ - const char *read_dg10_help; /**< @brief Read DG 10 (Nationality) help description. */ - int read_dg11_flag; /**< @brief Read DG 11 (Sex) (default=off). */ - const char *read_dg11_help; /**< @brief Read DG 11 (Sex) help description. */ - int read_dg12_flag; /**< @brief Read DG 12 (Optional Data) (default=off). */ - const char *read_dg12_help; /**< @brief Read DG 12 (Optional Data) help description. */ - int read_dg13_flag; /**< @brief Read DG 13 (Birth Name) (default=off). */ - const char *read_dg13_help; /**< @brief Read DG 13 (Birth Name) help description. */ - int read_dg14_flag; /**< @brief Read DG 14 (default=off). */ - const char *read_dg14_help; /**< @brief Read DG 14 help description. */ - int read_dg15_flag; /**< @brief Read DG 15 (default=off). */ - const char *read_dg15_help; /**< @brief Read DG 15 help description. */ - int read_dg16_flag; /**< @brief Read DG 16 (default=off). */ - const char *read_dg16_help; /**< @brief Read DG 16 help description. */ - int read_dg17_flag; /**< @brief Read DG 17 (Normal Place of Residence) (default=off). */ - const char *read_dg17_help; /**< @brief Read DG 17 (Normal Place of Residence) help description. */ - int read_dg18_flag; /**< @brief Read DG 18 (Community ID) (default=off). */ - const char *read_dg18_help; /**< @brief Read DG 18 (Community ID) help description. */ - int read_dg19_flag; /**< @brief Read DG 19 (Residence Permit I) (default=off). */ - const char *read_dg19_help; /**< @brief Read DG 19 (Residence Permit I) help description. */ - int read_dg20_flag; /**< @brief Read DG 20 (Residence Permit II) (default=off). */ - const char *read_dg20_help; /**< @brief Read DG 20 (Residence Permit II) help description. */ - int read_dg21_flag; /**< @brief Read DG 21 (Optional Data) (default=off). */ - const char *read_dg21_help; /**< @brief Read DG 21 (Optional Data) help description. */ - char * write_dg17_arg; /**< @brief Write DG 17 (Normal Place of Residence). */ - char * write_dg17_orig; /**< @brief Write DG 17 (Normal Place of Residence) original value given at command line. */ - const char *write_dg17_help; /**< @brief Write DG 17 (Normal Place of Residence) help description. */ - char * write_dg18_arg; /**< @brief Write DG 18 (Community ID). */ - char * write_dg18_orig; /**< @brief Write DG 18 (Community ID) original value given at command line. */ - const char *write_dg18_help; /**< @brief Write DG 18 (Community ID) help description. */ - char * write_dg19_arg; /**< @brief Write DG 19 (Residence Permit I). */ - char * write_dg19_orig; /**< @brief Write DG 19 (Residence Permit I) original value given at command line. */ - const char *write_dg19_help; /**< @brief Write DG 19 (Residence Permit I) help description. */ - char * write_dg20_arg; /**< @brief Write DG 20 (Residence Permit II). */ - char * write_dg20_orig; /**< @brief Write DG 20 (Residence Permit II) original value given at command line. */ - const char *write_dg20_help; /**< @brief Write DG 20 (Residence Permit II) help description. */ - char * write_dg21_arg; /**< @brief Write DG 21 (Optional Data). */ - char * write_dg21_orig; /**< @brief Write DG 21 (Optional Data) original value given at command line. */ - const char *write_dg21_help; /**< @brief Write DG 21 (Optional Data) help description. */ - char * verify_validity_arg; /**< @brief Verify chip's validity with a reference date. */ - char * verify_validity_orig; /**< @brief Verify chip's validity with a reference date original value given at command line. */ - const char *verify_validity_help; /**< @brief Verify chip's validity with a reference date help description. */ - char * older_than_arg; /**< @brief Verify age with a reference date. */ - char * older_than_orig; /**< @brief Verify age with a reference date original value given at command line. */ - const char *older_than_help; /**< @brief Verify age with a reference date help description. */ - char * verify_community_arg; /**< @brief Verify community ID with a reference ID. */ - char * verify_community_orig; /**< @brief Verify community ID with a reference ID original value given at command line. */ - const char *verify_community_help; /**< @brief Verify community ID with a reference ID help description. */ - int break_flag; /**< @brief Brute force PIN, CAN or PUK. Use together with -p, -a or -u (default=off). */ - const char *break_help; /**< @brief Brute force PIN, CAN or PUK. Use together with -p, -a or -u help description. */ - char * translate_arg; /**< @brief File with APDUs of HEX_STRINGs to send through the secure channel (default='stdin'). */ - char * translate_orig; /**< @brief File with APDUs of HEX_STRINGs to send through the secure channel original value given at command line. */ - const char *translate_help; /**< @brief File with APDUs of HEX_STRINGs to send through the secure channel help description. */ - int tr_03110v201_flag; /**< @brief Force compliance to BSI TR-03110 version 2.01 (default=off). */ - const char *tr_03110v201_help; /**< @brief Force compliance to BSI TR-03110 version 2.01 help description. */ - - unsigned int help_given ; /**< @brief Whether help was given. */ - unsigned int version_given ; /**< @brief Whether version was given. */ - unsigned int reader_given ; /**< @brief Whether reader was given. */ - unsigned int verbose_given ; /**< @brief Whether verbose was given. */ - unsigned int pin_given ; /**< @brief Whether pin was given. */ - unsigned int puk_given ; /**< @brief Whether puk was given. */ - unsigned int can_given ; /**< @brief Whether can was given. */ - unsigned int mrz_given ; /**< @brief Whether mrz was given. */ - unsigned int env_given ; /**< @brief Whether env was given. */ - unsigned int new_pin_given ; /**< @brief Whether new-pin was given. */ - unsigned int resume_given ; /**< @brief Whether resume was given. */ - unsigned int unblock_given ; /**< @brief Whether unblock was given. */ - unsigned int cv_certificate_given ; /**< @brief Whether cv-certificate was given. */ - unsigned int cert_desc_given ; /**< @brief Whether cert-desc was given. */ - unsigned int chat_given ; /**< @brief Whether chat was given. */ - unsigned int auxiliary_data_given ; /**< @brief Whether auxiliary-data was given. */ - unsigned int private_key_given ; /**< @brief Whether private-key was given. */ - unsigned int cvc_dir_given ; /**< @brief Whether cvc-dir was given. */ - unsigned int x509_dir_given ; /**< @brief Whether x509-dir was given. */ - unsigned int disable_ta_checks_given ; /**< @brief Whether disable-ta-checks was given. */ - unsigned int disable_ca_checks_given ; /**< @brief Whether disable-ca-checks was given. */ - unsigned int read_dg1_given ; /**< @brief Whether read-dg1 was given. */ - unsigned int read_dg2_given ; /**< @brief Whether read-dg2 was given. */ - unsigned int read_dg3_given ; /**< @brief Whether read-dg3 was given. */ - unsigned int read_dg4_given ; /**< @brief Whether read-dg4 was given. */ - unsigned int read_dg5_given ; /**< @brief Whether read-dg5 was given. */ - unsigned int read_dg6_given ; /**< @brief Whether read-dg6 was given. */ - unsigned int read_dg7_given ; /**< @brief Whether read-dg7 was given. */ - unsigned int read_dg8_given ; /**< @brief Whether read-dg8 was given. */ - unsigned int read_dg9_given ; /**< @brief Whether read-dg9 was given. */ - unsigned int read_dg10_given ; /**< @brief Whether read-dg10 was given. */ - unsigned int read_dg11_given ; /**< @brief Whether read-dg11 was given. */ - unsigned int read_dg12_given ; /**< @brief Whether read-dg12 was given. */ - unsigned int read_dg13_given ; /**< @brief Whether read-dg13 was given. */ - unsigned int read_dg14_given ; /**< @brief Whether read-dg14 was given. */ - unsigned int read_dg15_given ; /**< @brief Whether read-dg15 was given. */ - unsigned int read_dg16_given ; /**< @brief Whether read-dg16 was given. */ - unsigned int read_dg17_given ; /**< @brief Whether read-dg17 was given. */ - unsigned int read_dg18_given ; /**< @brief Whether read-dg18 was given. */ - unsigned int read_dg19_given ; /**< @brief Whether read-dg19 was given. */ - unsigned int read_dg20_given ; /**< @brief Whether read-dg20 was given. */ - unsigned int read_dg21_given ; /**< @brief Whether read-dg21 was given. */ - unsigned int write_dg17_given ; /**< @brief Whether write-dg17 was given. */ - unsigned int write_dg18_given ; /**< @brief Whether write-dg18 was given. */ - unsigned int write_dg19_given ; /**< @brief Whether write-dg19 was given. */ - unsigned int write_dg20_given ; /**< @brief Whether write-dg20 was given. */ - unsigned int write_dg21_given ; /**< @brief Whether write-dg21 was given. */ - unsigned int verify_validity_given ; /**< @brief Whether verify-validity was given. */ - unsigned int older_than_given ; /**< @brief Whether older-than was given. */ - unsigned int verify_community_given ; /**< @brief Whether verify-community was given. */ - unsigned int break_given ; /**< @brief Whether break was given. */ - unsigned int translate_given ; /**< @brief Whether translate was given. */ - unsigned int tr_03110v201_given ; /**< @brief Whether tr-03110v201 was given. */ - -} ; - -/** @brief The additional parameters to pass to parser functions */ -struct cmdline_parser_params -{ - int override; /**< @brief whether to override possibly already present options (default 0) */ - int initialize; /**< @brief whether to initialize the option structure gengetopt_args_info (default 1) */ - int check_required; /**< @brief whether to check that all required options were provided (default 1) */ - int check_ambiguity; /**< @brief whether to check for options already specified in the option structure gengetopt_args_info (default 0) */ - int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ -} ; - -/** @brief the purpose string of the program */ -extern const char *gengetopt_args_info_purpose; -/** @brief the usage string of the program */ -extern const char *gengetopt_args_info_usage; -/** @brief the description string of the program */ -extern const char *gengetopt_args_info_description; -/** @brief all the lines making the help output */ -extern const char *gengetopt_args_info_help[]; - -/** - * The command line parser - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser (int argc, char **argv, - struct gengetopt_args_info *args_info); - -/** - * The command line parser (version with additional parameters - deprecated) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_ext() instead - */ -int cmdline_parser2 (int argc, char **argv, - struct gengetopt_args_info *args_info, - int override, int initialize, int check_required); - -/** - * The command line parser (version with additional parameters) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_ext (int argc, char **argv, - struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params); - -/** - * Save the contents of the option struct into an already open FILE stream. - * @param outfile the stream where to dump options - * @param args_info the option struct to dump - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_dump(FILE *outfile, - struct gengetopt_args_info *args_info); - -/** - * Save the contents of the option struct into a (text) file. - * This file can be read by the config file parser (if generated by gengetopt) - * @param filename the file where to save - * @param args_info the option struct to save - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_file_save(const char *filename, - struct gengetopt_args_info *args_info); - -/** - * Print the help - */ -void cmdline_parser_print_help(void); -/** - * Print the version - */ -void cmdline_parser_print_version(void); - -/** - * Initializes all the fields a cmdline_parser_params structure - * to their default values - * @param params the structure to initialize - */ -void cmdline_parser_params_init(struct cmdline_parser_params *params); - -/** - * Allocates dynamically a cmdline_parser_params structure and initializes - * all its fields to their default values - * @return the created and initialized cmdline_parser_params structure - */ -struct cmdline_parser_params *cmdline_parser_params_create(void); - -/** - * Initializes the passed gengetopt_args_info structure's fields - * (also set default values for options that have a default) - * @param args_info the structure to initialize - */ -void cmdline_parser_init (struct gengetopt_args_info *args_info); -/** - * Deallocates the string fields of the gengetopt_args_info structure - * (but does not deallocate the structure itself) - * @param args_info the structure to deallocate - */ -void cmdline_parser_free (struct gengetopt_args_info *args_info); - -/** - * Checks that all the required options were specified - * @param args_info the structure to check - * @param prog_name the name of the program that will be used to print - * possible errors - * @return - */ -int cmdline_parser_required (struct gengetopt_args_info *args_info, - const char *prog_name); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* NPA_TOOL_CMDLINE_H */ diff --git a/src/tools/opensc-asn1-cmdline.c b/src/tools/opensc-asn1-cmdline.c deleted file mode 100644 index a571762b27..0000000000 --- a/src/tools/opensc-asn1-cmdline.c +++ /dev/null @@ -1,423 +0,0 @@ -/* - File autogenerated by gengetopt version 2.23 - generated with the following command: - /opt/homebrew/bin/gengetopt --file-name=opensc-asn1-cmdline --output-dir=. --unamed-opts - - The developers of gengetopt consider the fixed text that goes in all - gengetopt output files to be in the public domain: - we make no copyright claims on it. -*/ - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#ifndef FIX_UNUSED -#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ -#endif - -#include - -#include "opensc-asn1-cmdline.h" - -const char *gengetopt_args_info_purpose = ""; - -const char *gengetopt_args_info_usage = "Usage: opensc-asn1 [OPTION]... [FILE]..."; - -const char *gengetopt_args_info_versiontext = ""; - -const char *gengetopt_args_info_description = "Parse ASN.1 data."; - -const char *gengetopt_args_info_help[] = { - " -h, --help Print help and exit", - " -V, --version Print version and exit", - "\nReport bugs to https://github.com/OpenSC/OpenSC/issues\n\nWritten by Frank Morgner ", - 0 -}; - -typedef enum {ARG_NO -} cmdline_parser_arg_type; - -static -void clear_given (struct gengetopt_args_info *args_info); -static -void clear_args (struct gengetopt_args_info *args_info); - -static int -cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params, const char *additional_error); - - -static char * -gengetopt_strdup (const char *s); - -static -void clear_given (struct gengetopt_args_info *args_info) -{ - args_info->help_given = 0 ; - args_info->version_given = 0 ; -} - -static -void clear_args (struct gengetopt_args_info *args_info) -{ - FIX_UNUSED (args_info); - -} - -static -void init_args_info(struct gengetopt_args_info *args_info) -{ - - - args_info->help_help = gengetopt_args_info_help[0] ; - args_info->version_help = gengetopt_args_info_help[1] ; - -} - -void -cmdline_parser_print_version (void) -{ - printf ("%s %s\n", - (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE), - CMDLINE_PARSER_VERSION); - - if (strlen(gengetopt_args_info_versiontext) > 0) - printf("\n%s\n", gengetopt_args_info_versiontext); -} - -static void print_help_common(void) -{ - size_t len_purpose = strlen(gengetopt_args_info_purpose); - size_t len_usage = strlen(gengetopt_args_info_usage); - - if (len_usage > 0) { - printf("%s\n", gengetopt_args_info_usage); - } - if (len_purpose > 0) { - printf("%s\n", gengetopt_args_info_purpose); - } - - if (len_usage || len_purpose) { - printf("\n"); - } - - if (strlen(gengetopt_args_info_description) > 0) { - printf("%s\n\n", gengetopt_args_info_description); - } -} - -void -cmdline_parser_print_help (void) -{ - int i = 0; - print_help_common(); - while (gengetopt_args_info_help[i]) - printf("%s\n", gengetopt_args_info_help[i++]); -} - -void -cmdline_parser_init (struct gengetopt_args_info *args_info) -{ - clear_given (args_info); - clear_args (args_info); - init_args_info (args_info); - - args_info->inputs = 0; - args_info->inputs_num = 0; -} - -void -cmdline_parser_params_init(struct cmdline_parser_params *params) -{ - if (params) - { - params->override = 0; - params->initialize = 1; - params->check_required = 1; - params->check_ambiguity = 0; - params->print_errors = 1; - } -} - -struct cmdline_parser_params * -cmdline_parser_params_create(void) -{ - struct cmdline_parser_params *params = - (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); - cmdline_parser_params_init(params); - return params; -} - - - -static void -cmdline_parser_release (struct gengetopt_args_info *args_info) -{ - unsigned int i; - - - for (i = 0; i < args_info->inputs_num; ++i) - free (args_info->inputs [i]); - - if (args_info->inputs_num) - free (args_info->inputs); - - clear_given (args_info); -} - - -static void -write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) -{ - FIX_UNUSED (values); - if (arg) { - fprintf(outfile, "%s=\"%s\"\n", opt, arg); - } else { - fprintf(outfile, "%s\n", opt); - } -} - - -int -cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) -{ - int i = 0; - - if (!outfile) - { - fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE); - return EXIT_FAILURE; - } - - if (args_info->help_given) - write_into_file(outfile, "help", 0, 0 ); - if (args_info->version_given) - write_into_file(outfile, "version", 0, 0 ); - - - i = EXIT_SUCCESS; - return i; -} - -int -cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) -{ - FILE *outfile; - int i = 0; - - outfile = fopen(filename, "w"); - - if (!outfile) - { - fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); - return EXIT_FAILURE; - } - - i = cmdline_parser_dump(outfile, args_info); - fclose (outfile); - - return i; -} - -void -cmdline_parser_free (struct gengetopt_args_info *args_info) -{ - cmdline_parser_release (args_info); -} - -/** @brief replacement of strdup, which is not standard */ -char * -gengetopt_strdup (const char *s) -{ - char *result = 0; - if (!s) - return result; - - result = (char*)malloc(strlen(s) + 1); - if (result == (char*)0) - return (char*)0; - strcpy(result, s); - return result; -} - -int -cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info) -{ - return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); -} - -int -cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params) -{ - int result; - result = cmdline_parser_internal (argc, argv, args_info, params, 0); - - if (result == EXIT_FAILURE) - { - cmdline_parser_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) -{ - int result; - struct cmdline_parser_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0); - - if (result == EXIT_FAILURE) - { - cmdline_parser_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) -{ - FIX_UNUSED (args_info); - FIX_UNUSED (prog_name); - return EXIT_SUCCESS; -} - - -static char *package_name = 0; - - - -int -cmdline_parser_internal ( - int argc, char **argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params, const char *additional_error) -{ - int c; /* Character of the parsed option. */ - - int error_occurred = 0; - struct gengetopt_args_info local_args_info; - - int override; - int initialize; - int check_required; - int check_ambiguity; - - package_name = argv[0]; - - /* TODO: Why is this here? It is not used anywhere. */ - override = params->override; - FIX_UNUSED(override); - - initialize = params->initialize; - check_required = params->check_required; - - /* TODO: Why is this here? It is not used anywhere. */ - check_ambiguity = params->check_ambiguity; - FIX_UNUSED(check_ambiguity); - - if (initialize) - cmdline_parser_init (args_info); - - cmdline_parser_init (&local_args_info); - - optarg = 0; - optind = 0; - opterr = params->print_errors; - optopt = '?'; - - while (1) - { - int option_index = 0; - - static struct option long_options[] = { - { "help", 0, NULL, 'h' }, - { "version", 0, NULL, 'V' }, - { 0, 0, 0, 0 } - }; - - c = getopt_long (argc, argv, "hV", long_options, &option_index); - - if (c == -1) break; /* Exit from `while (1)' loop. */ - - switch (c) - { - case 'h': /* Print help and exit. */ - cmdline_parser_print_help (); - cmdline_parser_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'V': /* Print version and exit. */ - cmdline_parser_print_version (); - cmdline_parser_free (&local_args_info); - exit (EXIT_SUCCESS); - - - case 0: /* Long option with no short option */ - case '?': /* Invalid option. */ - /* `getopt_long' already printed an error message. */ - goto failure; - - default: /* bug: option not considered. */ - fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); - abort (); - } /* switch */ - } /* while */ - - - - FIX_UNUSED(check_required); - - cmdline_parser_release (&local_args_info); - - if ( error_occurred ) - return (EXIT_FAILURE); - - if (optind < argc) - { - int i = 0 ; - int found_prog_name = 0; - /* whether program name, i.e., argv[0], is in the remaining args - (this may happen with some implementations of getopt, - but surely not with the one included by gengetopt) */ - - i = optind; - while (i < argc) - if (argv[i++] == argv[0]) { - found_prog_name = 1; - break; - } - i = 0; - - args_info->inputs_num = argc - optind - found_prog_name; - args_info->inputs = - (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; - while (optind < argc) - if (argv[optind++] != argv[0]) - args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ; - } - - return 0; - -failure: - - cmdline_parser_release (&local_args_info); - return (EXIT_FAILURE); -} -/* vim: set ft=c noet ts=8 sts=8 sw=8 tw=80 nojs spell : */ diff --git a/src/tools/opensc-asn1-cmdline.h b/src/tools/opensc-asn1-cmdline.h deleted file mode 100644 index 93073da96b..0000000000 --- a/src/tools/opensc-asn1-cmdline.h +++ /dev/null @@ -1,175 +0,0 @@ -/** @file opensc-asn1-cmdline.h - * @brief The header file for the command line option parser - * generated by GNU Gengetopt version 2.23 - * http://www.gnu.org/software/gengetopt. - * DO NOT modify this file, since it can be overwritten - * @author GNU Gengetopt */ - -#ifndef OPENSC_ASN1_CMDLINE_H -#define OPENSC_ASN1_CMDLINE_H - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for FILE */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifndef CMDLINE_PARSER_PACKAGE -/** @brief the program name (used for printing errors) */ -#define CMDLINE_PARSER_PACKAGE "opensc-asn1" -#endif - -#ifndef CMDLINE_PARSER_PACKAGE_NAME -/** @brief the complete program name (used for help and version) */ -#define CMDLINE_PARSER_PACKAGE_NAME "opensc-asn1" -#endif - -#ifndef CMDLINE_PARSER_VERSION -/** @brief the program version */ -#define CMDLINE_PARSER_VERSION VERSION -#endif - -/** @brief Where the command line options are stored */ -struct gengetopt_args_info -{ - const char *help_help; /**< @brief Print help and exit help description. */ - const char *version_help; /**< @brief Print version and exit help description. */ - - unsigned int help_given ; /**< @brief Whether help was given. */ - unsigned int version_given ; /**< @brief Whether version was given. */ - - char **inputs ; /**< @brief unnamed options (options without names) */ - unsigned inputs_num ; /**< @brief unnamed options number */ -} ; - -/** @brief The additional parameters to pass to parser functions */ -struct cmdline_parser_params -{ - int override; /**< @brief whether to override possibly already present options (default 0) */ - int initialize; /**< @brief whether to initialize the option structure gengetopt_args_info (default 1) */ - int check_required; /**< @brief whether to check that all required options were provided (default 1) */ - int check_ambiguity; /**< @brief whether to check for options already specified in the option structure gengetopt_args_info (default 0) */ - int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ -} ; - -/** @brief the purpose string of the program */ -extern const char *gengetopt_args_info_purpose; -/** @brief the usage string of the program */ -extern const char *gengetopt_args_info_usage; -/** @brief the description string of the program */ -extern const char *gengetopt_args_info_description; -/** @brief all the lines making the help output */ -extern const char *gengetopt_args_info_help[]; - -/** - * The command line parser - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser (int argc, char **argv, - struct gengetopt_args_info *args_info); - -/** - * The command line parser (version with additional parameters - deprecated) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_ext() instead - */ -int cmdline_parser2 (int argc, char **argv, - struct gengetopt_args_info *args_info, - int override, int initialize, int check_required); - -/** - * The command line parser (version with additional parameters) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_ext (int argc, char **argv, - struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params); - -/** - * Save the contents of the option struct into an already open FILE stream. - * @param outfile the stream where to dump options - * @param args_info the option struct to dump - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_dump(FILE *outfile, - struct gengetopt_args_info *args_info); - -/** - * Save the contents of the option struct into a (text) file. - * This file can be read by the config file parser (if generated by gengetopt) - * @param filename the file where to save - * @param args_info the option struct to save - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_file_save(const char *filename, - struct gengetopt_args_info *args_info); - -/** - * Print the help - */ -void cmdline_parser_print_help(void); -/** - * Print the version - */ -void cmdline_parser_print_version(void); - -/** - * Initializes all the fields a cmdline_parser_params structure - * to their default values - * @param params the structure to initialize - */ -void cmdline_parser_params_init(struct cmdline_parser_params *params); - -/** - * Allocates dynamically a cmdline_parser_params structure and initializes - * all its fields to their default values - * @return the created and initialized cmdline_parser_params structure - */ -struct cmdline_parser_params *cmdline_parser_params_create(void); - -/** - * Initializes the passed gengetopt_args_info structure's fields - * (also set default values for options that have a default) - * @param args_info the structure to initialize - */ -void cmdline_parser_init (struct gengetopt_args_info *args_info); -/** - * Deallocates the string fields of the gengetopt_args_info structure - * (but does not deallocate the structure itself) - * @param args_info the structure to deallocate - */ -void cmdline_parser_free (struct gengetopt_args_info *args_info); - -/** - * Checks that all the required options were specified - * @param args_info the structure to check - * @param prog_name the name of the program that will be used to print - * possible errors - * @return - */ -int cmdline_parser_required (struct gengetopt_args_info *args_info, - const char *prog_name); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* OPENSC_ASN1_CMDLINE_H */ diff --git a/src/tools/opensc-notify-cmdline.c b/src/tools/opensc-notify-cmdline.c deleted file mode 100644 index 7f148927c0..0000000000 --- a/src/tools/opensc-notify-cmdline.c +++ /dev/null @@ -1,655 +0,0 @@ -/* - File autogenerated by gengetopt version 2.23 - generated with the following command: - /opt/homebrew/bin/gengetopt --file-name=opensc-notify-cmdline --output-dir=. - - The developers of gengetopt consider the fixed text that goes in all - gengetopt output files to be in the public domain: - we make no copyright claims on it. -*/ - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#ifndef FIX_UNUSED -#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ -#endif - -#include - -#include "opensc-notify-cmdline.h" - -const char *gengetopt_args_info_purpose = ""; - -const char *gengetopt_args_info_usage = "Usage: opensc-notify [OPTION]..."; - -const char *gengetopt_args_info_versiontext = ""; - -const char *gengetopt_args_info_description = "If no arguments are given, monitor smart card events and send the appropriate\nnotification."; - -const char *gengetopt_args_info_help[] = { - " -h, --help Print help and exit", - " -V, --version Print version and exit", - "\n Mode: customized\n Send customized notifications.", - " -t, --title[=STRING] Title of the notification", - " -m, --message[=STRING] Main text of the notification", - "\n Mode: standard\n Manually send standard notifications.", - " -I, --notify-card-inserted See notify_card_inserted in opensc.conf\n (default=off)", - " -R, --notify-card-removed See notify_card_removed in opensc.conf\n (default=off)", - " -G, --notify-pin-good See notify_pin_good in opensc.conf (default=off)", - " -B, --notify-pin-bad See notify_pin_bad in opensc.conf (default=off)", - "\nReport bugs to https://github.com/OpenSC/OpenSC/issues\n\nWritten by Frank Morgner ", - 0 -}; - -typedef enum {ARG_NO - , ARG_FLAG - , ARG_STRING -} cmdline_parser_arg_type; - -static -void clear_given (struct gengetopt_args_info *args_info); -static -void clear_args (struct gengetopt_args_info *args_info); - -static int -cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params, const char *additional_error); - - -static char * -gengetopt_strdup (const char *s); - -static -void clear_given (struct gengetopt_args_info *args_info) -{ - args_info->help_given = 0 ; - args_info->version_given = 0 ; - args_info->title_given = 0 ; - args_info->message_given = 0 ; - args_info->notify_card_inserted_given = 0 ; - args_info->notify_card_removed_given = 0 ; - args_info->notify_pin_good_given = 0 ; - args_info->notify_pin_bad_given = 0 ; - args_info->customized_mode_counter = 0 ; - args_info->daemon_mode_counter = 0 ; - args_info->standard_mode_counter = 0 ; -} - -static -void clear_args (struct gengetopt_args_info *args_info) -{ - FIX_UNUSED (args_info); - args_info->title_arg = NULL; - args_info->title_orig = NULL; - args_info->message_arg = NULL; - args_info->message_orig = NULL; - args_info->notify_card_inserted_flag = 0; - args_info->notify_card_removed_flag = 0; - args_info->notify_pin_good_flag = 0; - args_info->notify_pin_bad_flag = 0; - -} - -static -void init_args_info(struct gengetopt_args_info *args_info) -{ - - - args_info->help_help = gengetopt_args_info_help[0] ; - args_info->version_help = gengetopt_args_info_help[1] ; - args_info->title_help = gengetopt_args_info_help[3] ; - args_info->message_help = gengetopt_args_info_help[4] ; - args_info->notify_card_inserted_help = gengetopt_args_info_help[6] ; - args_info->notify_card_removed_help = gengetopt_args_info_help[7] ; - args_info->notify_pin_good_help = gengetopt_args_info_help[8] ; - args_info->notify_pin_bad_help = gengetopt_args_info_help[9] ; - -} - -void -cmdline_parser_print_version (void) -{ - printf ("%s %s\n", - (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE), - CMDLINE_PARSER_VERSION); - - if (strlen(gengetopt_args_info_versiontext) > 0) - printf("\n%s\n", gengetopt_args_info_versiontext); -} - -static void print_help_common(void) -{ - size_t len_purpose = strlen(gengetopt_args_info_purpose); - size_t len_usage = strlen(gengetopt_args_info_usage); - - if (len_usage > 0) { - printf("%s\n", gengetopt_args_info_usage); - } - if (len_purpose > 0) { - printf("%s\n", gengetopt_args_info_purpose); - } - - if (len_usage || len_purpose) { - printf("\n"); - } - - if (strlen(gengetopt_args_info_description) > 0) { - printf("%s\n\n", gengetopt_args_info_description); - } -} - -void -cmdline_parser_print_help (void) -{ - int i = 0; - print_help_common(); - while (gengetopt_args_info_help[i]) - printf("%s\n", gengetopt_args_info_help[i++]); -} - -void -cmdline_parser_init (struct gengetopt_args_info *args_info) -{ - clear_given (args_info); - clear_args (args_info); - init_args_info (args_info); -} - -void -cmdline_parser_params_init(struct cmdline_parser_params *params) -{ - if (params) - { - params->override = 0; - params->initialize = 1; - params->check_required = 1; - params->check_ambiguity = 0; - params->print_errors = 1; - } -} - -struct cmdline_parser_params * -cmdline_parser_params_create(void) -{ - struct cmdline_parser_params *params = - (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); - cmdline_parser_params_init(params); - return params; -} - -static void -free_string_field (char **s) -{ - if (*s) - { - free (*s); - *s = 0; - } -} - - -static void -cmdline_parser_release (struct gengetopt_args_info *args_info) -{ - - free_string_field (&(args_info->title_arg)); - free_string_field (&(args_info->title_orig)); - free_string_field (&(args_info->message_arg)); - free_string_field (&(args_info->message_orig)); - - - - clear_given (args_info); -} - - -static void -write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) -{ - FIX_UNUSED (values); - if (arg) { - fprintf(outfile, "%s=\"%s\"\n", opt, arg); - } else { - fprintf(outfile, "%s\n", opt); - } -} - - -int -cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) -{ - int i = 0; - - if (!outfile) - { - fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE); - return EXIT_FAILURE; - } - - if (args_info->help_given) - write_into_file(outfile, "help", 0, 0 ); - if (args_info->version_given) - write_into_file(outfile, "version", 0, 0 ); - if (args_info->title_given) - write_into_file(outfile, "title", args_info->title_orig, 0); - if (args_info->message_given) - write_into_file(outfile, "message", args_info->message_orig, 0); - if (args_info->notify_card_inserted_given) - write_into_file(outfile, "notify-card-inserted", 0, 0 ); - if (args_info->notify_card_removed_given) - write_into_file(outfile, "notify-card-removed", 0, 0 ); - if (args_info->notify_pin_good_given) - write_into_file(outfile, "notify-pin-good", 0, 0 ); - if (args_info->notify_pin_bad_given) - write_into_file(outfile, "notify-pin-bad", 0, 0 ); - - - i = EXIT_SUCCESS; - return i; -} - -int -cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) -{ - FILE *outfile; - int i = 0; - - outfile = fopen(filename, "w"); - - if (!outfile) - { - fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); - return EXIT_FAILURE; - } - - i = cmdline_parser_dump(outfile, args_info); - fclose (outfile); - - return i; -} - -void -cmdline_parser_free (struct gengetopt_args_info *args_info) -{ - cmdline_parser_release (args_info); -} - -/** @brief replacement of strdup, which is not standard */ -char * -gengetopt_strdup (const char *s) -{ - char *result = 0; - if (!s) - return result; - - result = (char*)malloc(strlen(s) + 1); - if (result == (char*)0) - return (char*)0; - strcpy(result, s); - return result; -} - -int -cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info) -{ - return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); -} - -int -cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params) -{ - int result; - result = cmdline_parser_internal (argc, argv, args_info, params, 0); - - if (result == EXIT_FAILURE) - { - cmdline_parser_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) -{ - int result; - struct cmdline_parser_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0); - - if (result == EXIT_FAILURE) - { - cmdline_parser_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) -{ - FIX_UNUSED (args_info); - FIX_UNUSED (prog_name); - return EXIT_SUCCESS; -} - - -static char *package_name = 0; - -/** - * @brief updates an option - * @param field the generic pointer to the field to update - * @param orig_field the pointer to the orig field - * @param field_given the pointer to the number of occurrence of this option - * @param prev_given the pointer to the number of occurrence already seen - * @param value the argument for this option (if null no arg was specified) - * @param possible_values the possible values for this option (if specified) - * @param default_value the default value (in case the option only accepts fixed values) - * @param arg_type the type of this option - * @param check_ambiguity @see cmdline_parser_params.check_ambiguity - * @param override @see cmdline_parser_params.override - * @param no_free whether to free a possible previous value - * @param multiple_option whether this is a multiple option - * @param long_opt the corresponding long option - * @param short_opt the corresponding short option (or '-' if none) - * @param additional_error possible further error specification - */ -static -int update_arg(void *field, char **orig_field, - unsigned int *field_given, unsigned int *prev_given, - char *value, const char *possible_values[], - const char *default_value, - cmdline_parser_arg_type arg_type, - int check_ambiguity, int override, - int no_free, int multiple_option, - const char *long_opt, char short_opt, - const char *additional_error) -{ - char *stop_char = 0; - const char *val = value; - int found; - char **string_field; - FIX_UNUSED (field); - - stop_char = 0; - found = 0; - - if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) - { - if (short_opt != '-') - fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", - package_name, long_opt, short_opt, - (additional_error ? additional_error : "")); - else - fprintf (stderr, "%s: `--%s' option given more than once%s\n", - package_name, long_opt, - (additional_error ? additional_error : "")); - return 1; /* failure */ - } - - FIX_UNUSED (default_value); - - if (field_given && *field_given && ! override) - return 0; - if (prev_given) - (*prev_given)++; - if (field_given) - (*field_given)++; - if (possible_values) - val = possible_values[found]; - - switch(arg_type) { - case ARG_FLAG: - *((int *)field) = !*((int *)field); - break; - case ARG_STRING: - if (val) { - string_field = (char **)field; - if (!no_free && *string_field) - free (*string_field); /* free previous string */ - *string_field = gengetopt_strdup (val); - } - break; - default: - break; - }; - - FIX_UNUSED(stop_char); - - /* store the original value */ - switch(arg_type) { - case ARG_NO: - case ARG_FLAG: - break; - default: - if (value && orig_field) { - if (no_free) { - *orig_field = value; - } else { - if (*orig_field) - free (*orig_field); /* free previous string */ - *orig_field = gengetopt_strdup (value); - } - } - }; - - return 0; /* OK */ -} - - -static int check_modes( - int given1[], const char *options1[], - int given2[], const char *options2[]) -{ - int i = 0, j = 0, errors = 0; - - while (given1[i] >= 0) { - if (given1[i]) { - while (given2[j] >= 0) { - if (given2[j]) { - ++errors; - fprintf(stderr, "%s: option %s conflicts with option %s\n", - package_name, options1[i], options2[j]); - } - ++j; - } - } - ++i; - } - - return errors; -} - -int -cmdline_parser_internal ( - int argc, char **argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params, const char *additional_error) -{ - int c; /* Character of the parsed option. */ - - int error_occurred = 0; - struct gengetopt_args_info local_args_info; - - int override; - int initialize; - int check_required; - int check_ambiguity; - - package_name = argv[0]; - - /* TODO: Why is this here? It is not used anywhere. */ - override = params->override; - FIX_UNUSED(override); - - initialize = params->initialize; - check_required = params->check_required; - - /* TODO: Why is this here? It is not used anywhere. */ - check_ambiguity = params->check_ambiguity; - FIX_UNUSED(check_ambiguity); - - if (initialize) - cmdline_parser_init (args_info); - - cmdline_parser_init (&local_args_info); - - optarg = 0; - optind = 0; - opterr = params->print_errors; - optopt = '?'; - - while (1) - { - int option_index = 0; - - static struct option long_options[] = { - { "help", 0, NULL, 'h' }, - { "version", 0, NULL, 'V' }, - { "title", 2, NULL, 't' }, - { "message", 2, NULL, 'm' }, - { "notify-card-inserted", 0, NULL, 'I' }, - { "notify-card-removed", 0, NULL, 'R' }, - { "notify-pin-good", 0, NULL, 'G' }, - { "notify-pin-bad", 0, NULL, 'B' }, - { 0, 0, 0, 0 } - }; - - c = getopt_long (argc, argv, "hVt::m::IRGB", long_options, &option_index); - - if (c == -1) break; /* Exit from `while (1)' loop. */ - - switch (c) - { - case 'h': /* Print help and exit. */ - cmdline_parser_print_help (); - cmdline_parser_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'V': /* Print version and exit. */ - cmdline_parser_print_version (); - cmdline_parser_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 't': /* Title of the notification. */ - args_info->customized_mode_counter += 1; - - - if (update_arg( (void *)&(args_info->title_arg), - &(args_info->title_orig), &(args_info->title_given), - &(local_args_info.title_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "title", 't', - additional_error)) - goto failure; - - break; - case 'm': /* Main text of the notification. */ - args_info->customized_mode_counter += 1; - - - if (update_arg( (void *)&(args_info->message_arg), - &(args_info->message_orig), &(args_info->message_given), - &(local_args_info.message_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "message", 'm', - additional_error)) - goto failure; - - break; - case 'I': /* See notify_card_inserted in opensc.conf. */ - args_info->standard_mode_counter += 1; - - - if (update_arg((void *)&(args_info->notify_card_inserted_flag), 0, &(args_info->notify_card_inserted_given), - &(local_args_info.notify_card_inserted_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "notify-card-inserted", 'I', - additional_error)) - goto failure; - - break; - case 'R': /* See notify_card_removed in opensc.conf. */ - args_info->standard_mode_counter += 1; - - - if (update_arg((void *)&(args_info->notify_card_removed_flag), 0, &(args_info->notify_card_removed_given), - &(local_args_info.notify_card_removed_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "notify-card-removed", 'R', - additional_error)) - goto failure; - - break; - case 'G': /* See notify_pin_good in opensc.conf. */ - args_info->standard_mode_counter += 1; - - - if (update_arg((void *)&(args_info->notify_pin_good_flag), 0, &(args_info->notify_pin_good_given), - &(local_args_info.notify_pin_good_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "notify-pin-good", 'G', - additional_error)) - goto failure; - - break; - case 'B': /* See notify_pin_bad in opensc.conf. */ - args_info->standard_mode_counter += 1; - - - if (update_arg((void *)&(args_info->notify_pin_bad_flag), 0, &(args_info->notify_pin_bad_given), - &(local_args_info.notify_pin_bad_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "notify-pin-bad", 'B', - additional_error)) - goto failure; - - break; - - case 0: /* Long option with no short option */ - case '?': /* Invalid option. */ - /* `getopt_long' already printed an error message. */ - goto failure; - - default: /* bug: option not considered. */ - fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); - abort (); - } /* switch */ - } /* while */ - - - - if (args_info->customized_mode_counter && args_info->standard_mode_counter) { - int customized_given[] = {args_info->title_given, args_info->message_given, -1}; - const char *customized_desc[] = {"--title", "--message", 0}; - int standard_given[] = {args_info->notify_card_inserted_given, args_info->notify_card_removed_given, args_info->notify_pin_good_given, args_info->notify_pin_bad_given, -1}; - const char *standard_desc[] = {"--notify-card-inserted", "--notify-card-removed", "--notify-pin-good", "--notify-pin-bad", 0}; - error_occurred += check_modes(customized_given, customized_desc, standard_given, standard_desc); - } - - FIX_UNUSED(check_required); - - cmdline_parser_release (&local_args_info); - - if ( error_occurred ) - return (EXIT_FAILURE); - - return 0; - -failure: - - cmdline_parser_release (&local_args_info); - return (EXIT_FAILURE); -} -/* vim: set ft=c noet ts=8 sts=8 sw=8 tw=80 nojs spell : */ diff --git a/src/tools/opensc-notify-cmdline.h b/src/tools/opensc-notify-cmdline.h deleted file mode 100644 index e36be178d9..0000000000 --- a/src/tools/opensc-notify-cmdline.h +++ /dev/null @@ -1,196 +0,0 @@ -/** @file opensc-notify-cmdline.h - * @brief The header file for the command line option parser - * generated by GNU Gengetopt version 2.23 - * http://www.gnu.org/software/gengetopt. - * DO NOT modify this file, since it can be overwritten - * @author GNU Gengetopt */ - -#ifndef OPENSC_NOTIFY_CMDLINE_H -#define OPENSC_NOTIFY_CMDLINE_H - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for FILE */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifndef CMDLINE_PARSER_PACKAGE -/** @brief the program name (used for printing errors) */ -#define CMDLINE_PARSER_PACKAGE "opensc-notify" -#endif - -#ifndef CMDLINE_PARSER_PACKAGE_NAME -/** @brief the complete program name (used for help and version) */ -#define CMDLINE_PARSER_PACKAGE_NAME "opensc-notify" -#endif - -#ifndef CMDLINE_PARSER_VERSION -/** @brief the program version */ -#define CMDLINE_PARSER_VERSION VERSION -#endif - -/** @brief Where the command line options are stored */ -struct gengetopt_args_info -{ - const char *help_help; /**< @brief Print help and exit help description. */ - const char *version_help; /**< @brief Print version and exit help description. */ - char * title_arg; /**< @brief Title of the notification. */ - char * title_orig; /**< @brief Title of the notification original value given at command line. */ - const char *title_help; /**< @brief Title of the notification help description. */ - char * message_arg; /**< @brief Main text of the notification. */ - char * message_orig; /**< @brief Main text of the notification original value given at command line. */ - const char *message_help; /**< @brief Main text of the notification help description. */ - int notify_card_inserted_flag; /**< @brief See notify_card_inserted in opensc.conf (default=off). */ - const char *notify_card_inserted_help; /**< @brief See notify_card_inserted in opensc.conf help description. */ - int notify_card_removed_flag; /**< @brief See notify_card_removed in opensc.conf (default=off). */ - const char *notify_card_removed_help; /**< @brief See notify_card_removed in opensc.conf help description. */ - int notify_pin_good_flag; /**< @brief See notify_pin_good in opensc.conf (default=off). */ - const char *notify_pin_good_help; /**< @brief See notify_pin_good in opensc.conf help description. */ - int notify_pin_bad_flag; /**< @brief See notify_pin_bad in opensc.conf (default=off). */ - const char *notify_pin_bad_help; /**< @brief See notify_pin_bad in opensc.conf help description. */ - - unsigned int help_given ; /**< @brief Whether help was given. */ - unsigned int version_given ; /**< @brief Whether version was given. */ - unsigned int title_given ; /**< @brief Whether title was given. */ - unsigned int message_given ; /**< @brief Whether message was given. */ - unsigned int notify_card_inserted_given ; /**< @brief Whether notify-card-inserted was given. */ - unsigned int notify_card_removed_given ; /**< @brief Whether notify-card-removed was given. */ - unsigned int notify_pin_good_given ; /**< @brief Whether notify-pin-good was given. */ - unsigned int notify_pin_bad_given ; /**< @brief Whether notify-pin-bad was given. */ - - int customized_mode_counter; /**< @brief Counter for mode customized */ - int daemon_mode_counter; /**< @brief Counter for mode daemon */ - int standard_mode_counter; /**< @brief Counter for mode standard */ -} ; - -/** @brief The additional parameters to pass to parser functions */ -struct cmdline_parser_params -{ - int override; /**< @brief whether to override possibly already present options (default 0) */ - int initialize; /**< @brief whether to initialize the option structure gengetopt_args_info (default 1) */ - int check_required; /**< @brief whether to check that all required options were provided (default 1) */ - int check_ambiguity; /**< @brief whether to check for options already specified in the option structure gengetopt_args_info (default 0) */ - int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ -} ; - -/** @brief the purpose string of the program */ -extern const char *gengetopt_args_info_purpose; -/** @brief the usage string of the program */ -extern const char *gengetopt_args_info_usage; -/** @brief the description string of the program */ -extern const char *gengetopt_args_info_description; -/** @brief all the lines making the help output */ -extern const char *gengetopt_args_info_help[]; - -/** - * The command line parser - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser (int argc, char **argv, - struct gengetopt_args_info *args_info); - -/** - * The command line parser (version with additional parameters - deprecated) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_ext() instead - */ -int cmdline_parser2 (int argc, char **argv, - struct gengetopt_args_info *args_info, - int override, int initialize, int check_required); - -/** - * The command line parser (version with additional parameters) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_ext (int argc, char **argv, - struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params); - -/** - * Save the contents of the option struct into an already open FILE stream. - * @param outfile the stream where to dump options - * @param args_info the option struct to dump - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_dump(FILE *outfile, - struct gengetopt_args_info *args_info); - -/** - * Save the contents of the option struct into a (text) file. - * This file can be read by the config file parser (if generated by gengetopt) - * @param filename the file where to save - * @param args_info the option struct to save - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_file_save(const char *filename, - struct gengetopt_args_info *args_info); - -/** - * Print the help - */ -void cmdline_parser_print_help(void); -/** - * Print the version - */ -void cmdline_parser_print_version(void); - -/** - * Initializes all the fields a cmdline_parser_params structure - * to their default values - * @param params the structure to initialize - */ -void cmdline_parser_params_init(struct cmdline_parser_params *params); - -/** - * Allocates dynamically a cmdline_parser_params structure and initializes - * all its fields to their default values - * @return the created and initialized cmdline_parser_params structure - */ -struct cmdline_parser_params *cmdline_parser_params_create(void); - -/** - * Initializes the passed gengetopt_args_info structure's fields - * (also set default values for options that have a default) - * @param args_info the structure to initialize - */ -void cmdline_parser_init (struct gengetopt_args_info *args_info); -/** - * Deallocates the string fields of the gengetopt_args_info structure - * (but does not deallocate the structure itself) - * @param args_info the structure to deallocate - */ -void cmdline_parser_free (struct gengetopt_args_info *args_info); - -/** - * Checks that all the required options were specified - * @param args_info the structure to check - * @param prog_name the name of the program that will be used to print - * possible errors - * @return - */ -int cmdline_parser_required (struct gengetopt_args_info *args_info, - const char *prog_name); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* OPENSC_NOTIFY_CMDLINE_H */ diff --git a/src/tools/pkcs11-register-cmdline.c b/src/tools/pkcs11-register-cmdline.c deleted file mode 100644 index 467fd927ab..0000000000 --- a/src/tools/pkcs11-register-cmdline.c +++ /dev/null @@ -1,601 +0,0 @@ -/* - File autogenerated by gengetopt version 2.23 - generated with the following command: - /opt/homebrew/bin/gengetopt --file-name=pkcs11-register-cmdline --output-dir=. - - The developers of gengetopt consider the fixed text that goes in all - gengetopt output files to be in the public domain: - we make no copyright claims on it. -*/ - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#ifndef FIX_UNUSED -#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ -#endif - -#include - -#include "pkcs11-register-cmdline.h" - -const char *gengetopt_args_info_purpose = ""; - -const char *gengetopt_args_info_usage = "Usage: pkcs11-register [OPTION]..."; - -const char *gengetopt_args_info_versiontext = ""; - -const char *gengetopt_args_info_description = "Install a PKCS#11 module to known applications."; - -const char *gengetopt_args_info_help[] = { - " -h, --help Print help and exit", - " -V, --version Print version and exit", - " -m, --module=FILENAME Specify the module to load (default=`OpenSC's\n PKCS#11 module')", - " --skip-chrome Don't install module to Chrome (default=on)", - " --skip-firefox Don't install module to Firefox (default=on)", - " --skip-thunderbird Don't install module to Thunderbird (default=off)", - " --skip-seamonkey Don't install module to SeaMonkey (default=off)", - "\nReport bugs to https://github.com/OpenSC/OpenSC/issues\n\nWritten by Frank Morgner ", - 0 -}; - -typedef enum {ARG_NO - , ARG_FLAG - , ARG_STRING -} cmdline_parser_arg_type; - -static -void clear_given (struct gengetopt_args_info *args_info); -static -void clear_args (struct gengetopt_args_info *args_info); - -static int -cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params, const char *additional_error); - - -static char * -gengetopt_strdup (const char *s); - -static -void clear_given (struct gengetopt_args_info *args_info) -{ - args_info->help_given = 0 ; - args_info->version_given = 0 ; - args_info->module_given = 0 ; - args_info->skip_chrome_given = 0 ; - args_info->skip_firefox_given = 0 ; - args_info->skip_thunderbird_given = 0 ; - args_info->skip_seamonkey_given = 0 ; -} - -static -void clear_args (struct gengetopt_args_info *args_info) -{ - FIX_UNUSED (args_info); - args_info->module_arg = gengetopt_strdup ("OpenSC's PKCS#11 module"); - args_info->module_orig = NULL; - args_info->skip_chrome_flag = 1; - args_info->skip_firefox_flag = 1; - args_info->skip_thunderbird_flag = 0; - args_info->skip_seamonkey_flag = 0; - -} - -static -void init_args_info(struct gengetopt_args_info *args_info) -{ - - - args_info->help_help = gengetopt_args_info_help[0] ; - args_info->version_help = gengetopt_args_info_help[1] ; - args_info->module_help = gengetopt_args_info_help[2] ; - args_info->skip_chrome_help = gengetopt_args_info_help[3] ; - args_info->skip_firefox_help = gengetopt_args_info_help[4] ; - args_info->skip_thunderbird_help = gengetopt_args_info_help[5] ; - args_info->skip_seamonkey_help = gengetopt_args_info_help[6] ; - -} - -void -cmdline_parser_print_version (void) -{ - printf ("%s %s\n", - (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE), - CMDLINE_PARSER_VERSION); - - if (strlen(gengetopt_args_info_versiontext) > 0) - printf("\n%s\n", gengetopt_args_info_versiontext); -} - -static void print_help_common(void) -{ - size_t len_purpose = strlen(gengetopt_args_info_purpose); - size_t len_usage = strlen(gengetopt_args_info_usage); - - if (len_usage > 0) { - printf("%s\n", gengetopt_args_info_usage); - } - if (len_purpose > 0) { - printf("%s\n", gengetopt_args_info_purpose); - } - - if (len_usage || len_purpose) { - printf("\n"); - } - - if (strlen(gengetopt_args_info_description) > 0) { - printf("%s\n\n", gengetopt_args_info_description); - } -} - -void -cmdline_parser_print_help (void) -{ - int i = 0; - print_help_common(); - while (gengetopt_args_info_help[i]) - printf("%s\n", gengetopt_args_info_help[i++]); -} - -void -cmdline_parser_init (struct gengetopt_args_info *args_info) -{ - clear_given (args_info); - clear_args (args_info); - init_args_info (args_info); -} - -void -cmdline_parser_params_init(struct cmdline_parser_params *params) -{ - if (params) - { - params->override = 0; - params->initialize = 1; - params->check_required = 1; - params->check_ambiguity = 0; - params->print_errors = 1; - } -} - -struct cmdline_parser_params * -cmdline_parser_params_create(void) -{ - struct cmdline_parser_params *params = - (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); - cmdline_parser_params_init(params); - return params; -} - -static void -free_string_field (char **s) -{ - if (*s) - { - free (*s); - *s = 0; - } -} - - -static void -cmdline_parser_release (struct gengetopt_args_info *args_info) -{ - - free_string_field (&(args_info->module_arg)); - free_string_field (&(args_info->module_orig)); - - - - clear_given (args_info); -} - - -static void -write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) -{ - FIX_UNUSED (values); - if (arg) { - fprintf(outfile, "%s=\"%s\"\n", opt, arg); - } else { - fprintf(outfile, "%s\n", opt); - } -} - - -int -cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) -{ - int i = 0; - - if (!outfile) - { - fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE); - return EXIT_FAILURE; - } - - if (args_info->help_given) - write_into_file(outfile, "help", 0, 0 ); - if (args_info->version_given) - write_into_file(outfile, "version", 0, 0 ); - if (args_info->module_given) - write_into_file(outfile, "module", args_info->module_orig, 0); - if (args_info->skip_chrome_given) - write_into_file(outfile, "skip-chrome", 0, 0 ); - if (args_info->skip_firefox_given) - write_into_file(outfile, "skip-firefox", 0, 0 ); - if (args_info->skip_thunderbird_given) - write_into_file(outfile, "skip-thunderbird", 0, 0 ); - if (args_info->skip_seamonkey_given) - write_into_file(outfile, "skip-seamonkey", 0, 0 ); - - - i = EXIT_SUCCESS; - return i; -} - -int -cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) -{ - FILE *outfile; - int i = 0; - - outfile = fopen(filename, "w"); - - if (!outfile) - { - fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); - return EXIT_FAILURE; - } - - i = cmdline_parser_dump(outfile, args_info); - fclose (outfile); - - return i; -} - -void -cmdline_parser_free (struct gengetopt_args_info *args_info) -{ - cmdline_parser_release (args_info); -} - -/** @brief replacement of strdup, which is not standard */ -char * -gengetopt_strdup (const char *s) -{ - char *result = 0; - if (!s) - return result; - - result = (char*)malloc(strlen(s) + 1); - if (result == (char*)0) - return (char*)0; - strcpy(result, s); - return result; -} - -int -cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info) -{ - return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); -} - -int -cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params) -{ - int result; - result = cmdline_parser_internal (argc, argv, args_info, params, 0); - - if (result == EXIT_FAILURE) - { - cmdline_parser_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) -{ - int result; - struct cmdline_parser_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0); - - if (result == EXIT_FAILURE) - { - cmdline_parser_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) -{ - FIX_UNUSED (args_info); - FIX_UNUSED (prog_name); - return EXIT_SUCCESS; -} - - -static char *package_name = 0; - -/** - * @brief updates an option - * @param field the generic pointer to the field to update - * @param orig_field the pointer to the orig field - * @param field_given the pointer to the number of occurrence of this option - * @param prev_given the pointer to the number of occurrence already seen - * @param value the argument for this option (if null no arg was specified) - * @param possible_values the possible values for this option (if specified) - * @param default_value the default value (in case the option only accepts fixed values) - * @param arg_type the type of this option - * @param check_ambiguity @see cmdline_parser_params.check_ambiguity - * @param override @see cmdline_parser_params.override - * @param no_free whether to free a possible previous value - * @param multiple_option whether this is a multiple option - * @param long_opt the corresponding long option - * @param short_opt the corresponding short option (or '-' if none) - * @param additional_error possible further error specification - */ -static -int update_arg(void *field, char **orig_field, - unsigned int *field_given, unsigned int *prev_given, - char *value, const char *possible_values[], - const char *default_value, - cmdline_parser_arg_type arg_type, - int check_ambiguity, int override, - int no_free, int multiple_option, - const char *long_opt, char short_opt, - const char *additional_error) -{ - char *stop_char = 0; - const char *val = value; - int found; - char **string_field; - FIX_UNUSED (field); - - stop_char = 0; - found = 0; - - if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) - { - if (short_opt != '-') - fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", - package_name, long_opt, short_opt, - (additional_error ? additional_error : "")); - else - fprintf (stderr, "%s: `--%s' option given more than once%s\n", - package_name, long_opt, - (additional_error ? additional_error : "")); - return 1; /* failure */ - } - - FIX_UNUSED (default_value); - - if (field_given && *field_given && ! override) - return 0; - if (prev_given) - (*prev_given)++; - if (field_given) - (*field_given)++; - if (possible_values) - val = possible_values[found]; - - switch(arg_type) { - case ARG_FLAG: - *((int *)field) = !*((int *)field); - break; - case ARG_STRING: - if (val) { - string_field = (char **)field; - if (!no_free && *string_field) - free (*string_field); /* free previous string */ - *string_field = gengetopt_strdup (val); - } - break; - default: - break; - }; - - FIX_UNUSED(stop_char); - - /* store the original value */ - switch(arg_type) { - case ARG_NO: - case ARG_FLAG: - break; - default: - if (value && orig_field) { - if (no_free) { - *orig_field = value; - } else { - if (*orig_field) - free (*orig_field); /* free previous string */ - *orig_field = gengetopt_strdup (value); - } - } - }; - - return 0; /* OK */ -} - - -int -cmdline_parser_internal ( - int argc, char **argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params, const char *additional_error) -{ - int c; /* Character of the parsed option. */ - - int error_occurred = 0; - struct gengetopt_args_info local_args_info; - - int override; - int initialize; - int check_required; - int check_ambiguity; - - package_name = argv[0]; - - /* TODO: Why is this here? It is not used anywhere. */ - override = params->override; - FIX_UNUSED(override); - - initialize = params->initialize; - check_required = params->check_required; - - /* TODO: Why is this here? It is not used anywhere. */ - check_ambiguity = params->check_ambiguity; - FIX_UNUSED(check_ambiguity); - - if (initialize) - cmdline_parser_init (args_info); - - cmdline_parser_init (&local_args_info); - - optarg = 0; - optind = 0; - opterr = params->print_errors; - optopt = '?'; - - while (1) - { - int option_index = 0; - - static struct option long_options[] = { - { "help", 0, NULL, 'h' }, - { "version", 0, NULL, 'V' }, - { "module", 1, NULL, 'm' }, - { "skip-chrome", 0, NULL, 0 }, - { "skip-firefox", 0, NULL, 0 }, - { "skip-thunderbird", 0, NULL, 0 }, - { "skip-seamonkey", 0, NULL, 0 }, - { 0, 0, 0, 0 } - }; - - c = getopt_long (argc, argv, "hVm:", long_options, &option_index); - - if (c == -1) break; /* Exit from `while (1)' loop. */ - - switch (c) - { - case 'h': /* Print help and exit. */ - cmdline_parser_print_help (); - cmdline_parser_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'V': /* Print version and exit. */ - cmdline_parser_print_version (); - cmdline_parser_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'm': /* Specify the module to load. */ - - - if (update_arg( (void *)&(args_info->module_arg), - &(args_info->module_orig), &(args_info->module_given), - &(local_args_info.module_given), optarg, 0, "OpenSC's PKCS#11 module", ARG_STRING, - check_ambiguity, override, 0, 0, - "module", 'm', - additional_error)) - goto failure; - - break; - - case 0: /* Long option with no short option */ - /* Don't install module to Chrome. */ - if (strcmp (long_options[option_index].name, "skip-chrome") == 0) - { - - - if (update_arg((void *)&(args_info->skip_chrome_flag), 0, &(args_info->skip_chrome_given), - &(local_args_info.skip_chrome_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "skip-chrome", '-', - additional_error)) - goto failure; - - } - /* Don't install module to Firefox. */ - else if (strcmp (long_options[option_index].name, "skip-firefox") == 0) - { - - - if (update_arg((void *)&(args_info->skip_firefox_flag), 0, &(args_info->skip_firefox_given), - &(local_args_info.skip_firefox_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "skip-firefox", '-', - additional_error)) - goto failure; - - } - /* Don't install module to Thunderbird. */ - else if (strcmp (long_options[option_index].name, "skip-thunderbird") == 0) - { - - - if (update_arg((void *)&(args_info->skip_thunderbird_flag), 0, &(args_info->skip_thunderbird_given), - &(local_args_info.skip_thunderbird_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "skip-thunderbird", '-', - additional_error)) - goto failure; - - } - /* Don't install module to SeaMonkey. */ - else if (strcmp (long_options[option_index].name, "skip-seamonkey") == 0) - { - - - if (update_arg((void *)&(args_info->skip_seamonkey_flag), 0, &(args_info->skip_seamonkey_given), - &(local_args_info.skip_seamonkey_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "skip-seamonkey", '-', - additional_error)) - goto failure; - - } - - break; - case '?': /* Invalid option. */ - /* `getopt_long' already printed an error message. */ - goto failure; - - default: /* bug: option not considered. */ - fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); - abort (); - } /* switch */ - } /* while */ - - - - FIX_UNUSED(check_required); - - cmdline_parser_release (&local_args_info); - - if ( error_occurred ) - return (EXIT_FAILURE); - - return 0; - -failure: - - cmdline_parser_release (&local_args_info); - return (EXIT_FAILURE); -} -/* vim: set ft=c noet ts=8 sts=8 sw=8 tw=80 nojs spell : */ diff --git a/src/tools/pkcs11-register-cmdline.h b/src/tools/pkcs11-register-cmdline.h deleted file mode 100644 index 8262da3e42..0000000000 --- a/src/tools/pkcs11-register-cmdline.h +++ /dev/null @@ -1,189 +0,0 @@ -/** @file pkcs11-register-cmdline.h - * @brief The header file for the command line option parser - * generated by GNU Gengetopt version 2.23 - * http://www.gnu.org/software/gengetopt. - * DO NOT modify this file, since it can be overwritten - * @author GNU Gengetopt */ - -#ifndef PKCS11_REGISTER_CMDLINE_H -#define PKCS11_REGISTER_CMDLINE_H - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for FILE */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifndef CMDLINE_PARSER_PACKAGE -/** @brief the program name (used for printing errors) */ -#define CMDLINE_PARSER_PACKAGE "pkcs11-register" -#endif - -#ifndef CMDLINE_PARSER_PACKAGE_NAME -/** @brief the complete program name (used for help and version) */ -#define CMDLINE_PARSER_PACKAGE_NAME "pkcs11-register" -#endif - -#ifndef CMDLINE_PARSER_VERSION -/** @brief the program version */ -#define CMDLINE_PARSER_VERSION VERSION -#endif - -/** @brief Where the command line options are stored */ -struct gengetopt_args_info -{ - const char *help_help; /**< @brief Print help and exit help description. */ - const char *version_help; /**< @brief Print version and exit help description. */ - char * module_arg; /**< @brief Specify the module to load (default='OpenSC's PKCS#11 module'). */ - char * module_orig; /**< @brief Specify the module to load original value given at command line. */ - const char *module_help; /**< @brief Specify the module to load help description. */ - int skip_chrome_flag; /**< @brief Don't install module to Chrome (default=on). */ - const char *skip_chrome_help; /**< @brief Don't install module to Chrome help description. */ - int skip_firefox_flag; /**< @brief Don't install module to Firefox (default=on). */ - const char *skip_firefox_help; /**< @brief Don't install module to Firefox help description. */ - int skip_thunderbird_flag; /**< @brief Don't install module to Thunderbird (default=off). */ - const char *skip_thunderbird_help; /**< @brief Don't install module to Thunderbird help description. */ - int skip_seamonkey_flag; /**< @brief Don't install module to SeaMonkey (default=off). */ - const char *skip_seamonkey_help; /**< @brief Don't install module to SeaMonkey help description. */ - - unsigned int help_given ; /**< @brief Whether help was given. */ - unsigned int version_given ; /**< @brief Whether version was given. */ - unsigned int module_given ; /**< @brief Whether module was given. */ - unsigned int skip_chrome_given ; /**< @brief Whether skip-chrome was given. */ - unsigned int skip_firefox_given ; /**< @brief Whether skip-firefox was given. */ - unsigned int skip_thunderbird_given ; /**< @brief Whether skip-thunderbird was given. */ - unsigned int skip_seamonkey_given ; /**< @brief Whether skip-seamonkey was given. */ - -} ; - -/** @brief The additional parameters to pass to parser functions */ -struct cmdline_parser_params -{ - int override; /**< @brief whether to override possibly already present options (default 0) */ - int initialize; /**< @brief whether to initialize the option structure gengetopt_args_info (default 1) */ - int check_required; /**< @brief whether to check that all required options were provided (default 1) */ - int check_ambiguity; /**< @brief whether to check for options already specified in the option structure gengetopt_args_info (default 0) */ - int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ -} ; - -/** @brief the purpose string of the program */ -extern const char *gengetopt_args_info_purpose; -/** @brief the usage string of the program */ -extern const char *gengetopt_args_info_usage; -/** @brief the description string of the program */ -extern const char *gengetopt_args_info_description; -/** @brief all the lines making the help output */ -extern const char *gengetopt_args_info_help[]; - -/** - * The command line parser - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser (int argc, char **argv, - struct gengetopt_args_info *args_info); - -/** - * The command line parser (version with additional parameters - deprecated) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_ext() instead - */ -int cmdline_parser2 (int argc, char **argv, - struct gengetopt_args_info *args_info, - int override, int initialize, int check_required); - -/** - * The command line parser (version with additional parameters) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_ext (int argc, char **argv, - struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params); - -/** - * Save the contents of the option struct into an already open FILE stream. - * @param outfile the stream where to dump options - * @param args_info the option struct to dump - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_dump(FILE *outfile, - struct gengetopt_args_info *args_info); - -/** - * Save the contents of the option struct into a (text) file. - * This file can be read by the config file parser (if generated by gengetopt) - * @param filename the file where to save - * @param args_info the option struct to save - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_file_save(const char *filename, - struct gengetopt_args_info *args_info); - -/** - * Print the help - */ -void cmdline_parser_print_help(void); -/** - * Print the version - */ -void cmdline_parser_print_version(void); - -/** - * Initializes all the fields a cmdline_parser_params structure - * to their default values - * @param params the structure to initialize - */ -void cmdline_parser_params_init(struct cmdline_parser_params *params); - -/** - * Allocates dynamically a cmdline_parser_params structure and initializes - * all its fields to their default values - * @return the created and initialized cmdline_parser_params structure - */ -struct cmdline_parser_params *cmdline_parser_params_create(void); - -/** - * Initializes the passed gengetopt_args_info structure's fields - * (also set default values for options that have a default) - * @param args_info the structure to initialize - */ -void cmdline_parser_init (struct gengetopt_args_info *args_info); -/** - * Deallocates the string fields of the gengetopt_args_info structure - * (but does not deallocate the structure itself) - * @param args_info the structure to deallocate - */ -void cmdline_parser_free (struct gengetopt_args_info *args_info); - -/** - * Checks that all the required options were specified - * @param args_info the structure to check - * @param prog_name the name of the program that will be used to print - * possible errors - * @return - */ -int cmdline_parser_required (struct gengetopt_args_info *args_info, - const char *prog_name); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* PKCS11_REGISTER_CMDLINE_H */ From 1dd714077ba59836d6e074affa8c952a517e8234 Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Sun, 10 Mar 2024 01:34:20 +0100 Subject: [PATCH 07/10] fixed dtrust-tool build (extension) --- src/tools/Makefile.mak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/Makefile.mak b/src/tools/Makefile.mak index abef3f6490..f8d5032cbe 100644 --- a/src/tools/Makefile.mak +++ b/src/tools/Makefile.mak @@ -6,7 +6,7 @@ default: all TARGETS = opensc-tool.exe opensc-explorer.exe pkcs15-tool.exe pkcs15-crypt.exe \ pkcs11-tool.exe cardos-tool.exe eidenv.exe openpgp-tool.exe iasecc-tool.exe \ - opensc-notify.exe egk-tool.exe goid-tool.exe dtrust-tool \ + opensc-notify.exe egk-tool.exe goid-tool.exe dtrust-tool.exe \ opensc-asn1.exe pkcs11-register.exe $(PROGRAMS_OPENSSL) $(PROGRAMS_OPENPACE) OBJECTS = util.obj versioninfo-tools.res From 0e742979fa17ef12f90c9b01ebe759749d307f31 Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Sun, 10 Mar 2024 02:26:11 +0100 Subject: [PATCH 08/10] fixed formatting --- src/tools/goid-tool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/goid-tool.c b/src/tools/goid-tool.c index 619bf742af..c8bdf6f63e 100644 --- a/src/tools/goid-tool.c +++ b/src/tools/goid-tool.c @@ -453,7 +453,7 @@ paccess_delete_file(struct sc_card *card, int fid) } int -paccess_get_security_attributes(struct sc_context *ctx, const char *ac, short* chatbits, size_t chatbits_len, u8 sec_attr[2]) +paccess_get_security_attributes(struct sc_context *ctx, const char *ac, short *chatbits, size_t chatbits_len, u8 sec_attr[2]) { int ok = 0; memset(sec_attr, 0, 2); From 82b2f474d9a6316027079ffb70f77211486d2287 Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Wed, 13 Mar 2024 23:56:06 +0100 Subject: [PATCH 09/10] CI: cache gengetopt in appveyor --- .appveyor.yml | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 3919761df0..7839f6fd1d 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -14,6 +14,7 @@ environment: PATH: C:\cygwin\bin;%PATH% OPENPACE_VER: 1.1.3 ZLIB_VER_DOT: 1.2.12 + GENGETOPT_VER: 2.23 matrix: # not compatible with OpenSSL 1.1.1: # - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 @@ -62,14 +63,12 @@ install: If (!(Test-Path cpdksetup.exe )) { appveyor DownloadFile "https://download.microsoft.com/download/1/7/6/176909B0-50F2-4DF3-B29B-830A17EA7E38/CPDK_RELEASE_UPDATE/cpdksetup.exe" } - - wget https://ftp.gnu.org/gnu/gengetopt/gengetopt-2.23.tar.xz - - tar xJf gengetopt-2.23.tar.xz - - cd gengetopt-2.23 - - bash -c "exec 0- + If (!(Test-Path C:\gengetopt )) { + appveyor DownloadFile "https://ftp.gnu.org/gnu/gengetopt/gengetopt-${env:GENGETOPT_VER}.tar.xz" -FileName gengetopt.tar.xz + 7z x gengetopt.tar.xz -oC:\ + Rename-Item -path "c:\gengetopt-${env:GENGETOPT_VER}" -newName "gengetopt" + } - echo "Using %APPVEYOR_BUILD_WORKER_IMAGE% with %VCVARSALL%" - call "%VCVARSALL%" %Platform% - cpdksetup.exe /quiet @@ -102,12 +101,18 @@ build_script: } $env:NMAKE_EXTRA+=" OPENPACE_DEF=/DENABLE_OPENPACE OPENPACE_DIR=C:\openpace-${env:OPENSSL_PF}" } + If (!(Test-Path -Path "C:\gengetopt\gengetopt" )) { + cd C:\gengetopt + bash -c "exec 0 .appveyor.yml - C:\openpace-Win32 -> .appveyor.yml - C:\openpace-Win64 -> .appveyor.yml + - C:\gengetopt -> .appveyor.yml - cpdksetup.exe -> .appveyor.yml From e7a0e37c9cf4dc82aeb84cf17cc0cce78a907be8 Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Thu, 14 Mar 2024 07:57:54 +0100 Subject: [PATCH 10/10] a --- .appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 7839f6fd1d..5d1920a160 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -66,8 +66,8 @@ install: - ps: >- If (!(Test-Path C:\gengetopt )) { appveyor DownloadFile "https://ftp.gnu.org/gnu/gengetopt/gengetopt-${env:GENGETOPT_VER}.tar.xz" -FileName gengetopt.tar.xz - 7z x gengetopt.tar.xz -oC:\ - Rename-Item -path "c:\gengetopt-${env:GENGETOPT_VER}" -newName "gengetopt" + tar xJf gengetopt.tar.xz + Rename-Item -path "gengetopt-${env:GENGETOPT_VER}" -newName "c:\gengetopt" } - echo "Using %APPVEYOR_BUILD_WORKER_IMAGE% with %VCVARSALL%" - call "%VCVARSALL%" %Platform%