1 /*
2   File autogenerated by gengetopt version 2.22.6
3   generated with the following command:
4   gengetopt --unamed-opts=FILE --no-handle-version --no-handle-help --input pskctool.ggo --file-name pskctool_cmd
5 
6   The developers of gengetopt consider the fixed text that goes in all
7   gengetopt output files to be in the public domain:
8   we make no copyright claims on it.
9 */
10 
11 /* If we use autoconf.  */
12 #ifdef HAVE_CONFIG_H
13 #include "config.h"
14 #endif
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 
20 #ifndef FIX_UNUSED
21 #define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
22 #endif
23 
24 #include <getopt.h>
25 
26 #include "pskctool_cmd.h"
27 
28 const char *gengetopt_args_info_purpose = "Manipulate Portable Symmetric Key Container (PSKC) data.";
29 
30 const char *gengetopt_args_info_usage = "Usage: " CMDLINE_PARSER_PACKAGE " [OPTIONS]... [FILE]...";
31 
32 const char *gengetopt_args_info_versiontext = "";
33 
34 const char *gengetopt_args_info_description = "This tool allows you to parse, print, validate, sign and verify PSKC data.  The\ninput is provided in FILE or on standard input.";
35 
36 const char *gengetopt_args_info_help[] = {
37   "  -h, --help             Print help and exit",
38   "  -V, --version          Print version and exit",
39   "      --strict           Fail hard on PSKC parse error  (default=off)",
40   "  -d, --debug            Show debug mesages on stderr  (default=off)",
41   "  -q, --quiet            Quiet operation  (default=off)",
42   "  -v, --verbose          Produce more output  (default=off)",
43   "\nSelecting one of the following modes is required:",
44   "\n Mode: info",
45   "  -i, --info             Parse and print human readable summary of PSKC input\n                           (default=off)",
46   "\n Mode: validate",
47   "  -e, --validate         Validate PSKC input against XML Schema  (default=off)",
48   "\n Mode: sign\n  Digitally sign PSKC data",
49   "      --sign             Sign PSKC input  (default=off)",
50   "      --sign-key=FILE    Private key to sign with",
51   "      --sign-crt=FILE    X.509 certificate to sign with",
52   "\n Mode: verify\n  Verify digitally signed PSKC data",
53   "      --verify           Verify signed PSKC input  (default=off)",
54   "      --verify-crt=FILE  Trusted X.509 certificate for verification",
55     0
56 };
57 
58 typedef enum {ARG_NO
59   , ARG_FLAG
60   , ARG_STRING
61 } cmdline_parser_arg_type;
62 
63 static
64 void clear_given (struct gengetopt_args_info *args_info);
65 static
66 void clear_args (struct gengetopt_args_info *args_info);
67 
68 static int
69 cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
70                         struct cmdline_parser_params *params, const char *additional_error);
71 
72 static int
73 cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error);
74 
75 static char *
76 gengetopt_strdup (const char *s);
77 
78 static
clear_given(struct gengetopt_args_info * args_info)79 void clear_given (struct gengetopt_args_info *args_info)
80 {
81   args_info->help_given = 0 ;
82   args_info->version_given = 0 ;
83   args_info->strict_given = 0 ;
84   args_info->debug_given = 0 ;
85   args_info->quiet_given = 0 ;
86   args_info->verbose_given = 0 ;
87   args_info->info_given = 0 ;
88   args_info->validate_given = 0 ;
89   args_info->sign_given = 0 ;
90   args_info->sign_key_given = 0 ;
91   args_info->sign_crt_given = 0 ;
92   args_info->verify_given = 0 ;
93   args_info->verify_crt_given = 0 ;
94   args_info->info_mode_counter = 0 ;
95   args_info->sign_mode_counter = 0 ;
96   args_info->validate_mode_counter = 0 ;
97   args_info->verify_mode_counter = 0 ;
98 }
99 
100 static
clear_args(struct gengetopt_args_info * args_info)101 void clear_args (struct gengetopt_args_info *args_info)
102 {
103   FIX_UNUSED (args_info);
104   args_info->strict_flag = 0;
105   args_info->debug_flag = 0;
106   args_info->quiet_flag = 0;
107   args_info->verbose_flag = 0;
108   args_info->info_flag = 0;
109   args_info->validate_flag = 0;
110   args_info->sign_flag = 0;
111   args_info->sign_key_arg = NULL;
112   args_info->sign_key_orig = NULL;
113   args_info->sign_crt_arg = NULL;
114   args_info->sign_crt_orig = NULL;
115   args_info->verify_flag = 0;
116   args_info->verify_crt_arg = NULL;
117   args_info->verify_crt_orig = NULL;
118 
119 }
120 
121 static
init_args_info(struct gengetopt_args_info * args_info)122 void init_args_info(struct gengetopt_args_info *args_info)
123 {
124 
125 
126   args_info->help_help = gengetopt_args_info_help[0] ;
127   args_info->version_help = gengetopt_args_info_help[1] ;
128   args_info->strict_help = gengetopt_args_info_help[2] ;
129   args_info->debug_help = gengetopt_args_info_help[3] ;
130   args_info->quiet_help = gengetopt_args_info_help[4] ;
131   args_info->verbose_help = gengetopt_args_info_help[5] ;
132   args_info->info_help = gengetopt_args_info_help[8] ;
133   args_info->validate_help = gengetopt_args_info_help[10] ;
134   args_info->sign_help = gengetopt_args_info_help[12] ;
135   args_info->sign_key_help = gengetopt_args_info_help[13] ;
136   args_info->sign_crt_help = gengetopt_args_info_help[14] ;
137   args_info->verify_help = gengetopt_args_info_help[16] ;
138   args_info->verify_crt_help = gengetopt_args_info_help[17] ;
139 
140 }
141 
142 void
cmdline_parser_print_version(void)143 cmdline_parser_print_version (void)
144 {
145   printf ("%s %s\n",
146      (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
147      CMDLINE_PARSER_VERSION);
148 
149   if (strlen(gengetopt_args_info_versiontext) > 0)
150     printf("\n%s\n", gengetopt_args_info_versiontext);
151 }
152 
print_help_common(void)153 static void print_help_common(void) {
154   cmdline_parser_print_version ();
155 
156   if (strlen(gengetopt_args_info_purpose) > 0)
157     printf("\n%s\n", gengetopt_args_info_purpose);
158 
159   if (strlen(gengetopt_args_info_usage) > 0)
160     printf("\n%s\n", gengetopt_args_info_usage);
161 
162   printf("\n");
163 
164   if (strlen(gengetopt_args_info_description) > 0)
165     printf("%s\n\n", gengetopt_args_info_description);
166 }
167 
168 void
cmdline_parser_print_help(void)169 cmdline_parser_print_help (void)
170 {
171   int i = 0;
172   print_help_common();
173   while (gengetopt_args_info_help[i])
174     printf("%s\n", gengetopt_args_info_help[i++]);
175 }
176 
177 void
cmdline_parser_init(struct gengetopt_args_info * args_info)178 cmdline_parser_init (struct gengetopt_args_info *args_info)
179 {
180   clear_given (args_info);
181   clear_args (args_info);
182   init_args_info (args_info);
183 
184   args_info->inputs = 0;
185   args_info->inputs_num = 0;
186 }
187 
188 void
cmdline_parser_params_init(struct cmdline_parser_params * params)189 cmdline_parser_params_init(struct cmdline_parser_params *params)
190 {
191   if (params)
192     {
193       params->override = 0;
194       params->initialize = 1;
195       params->check_required = 1;
196       params->check_ambiguity = 0;
197       params->print_errors = 1;
198     }
199 }
200 
201 struct cmdline_parser_params *
cmdline_parser_params_create(void)202 cmdline_parser_params_create(void)
203 {
204   struct cmdline_parser_params *params =
205     (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
206   cmdline_parser_params_init(params);
207   return params;
208 }
209 
210 static void
free_string_field(char ** s)211 free_string_field (char **s)
212 {
213   if (*s)
214     {
215       free (*s);
216       *s = 0;
217     }
218 }
219 
220 
221 static void
cmdline_parser_release(struct gengetopt_args_info * args_info)222 cmdline_parser_release (struct gengetopt_args_info *args_info)
223 {
224   unsigned int i;
225   free_string_field (&(args_info->sign_key_arg));
226   free_string_field (&(args_info->sign_key_orig));
227   free_string_field (&(args_info->sign_crt_arg));
228   free_string_field (&(args_info->sign_crt_orig));
229   free_string_field (&(args_info->verify_crt_arg));
230   free_string_field (&(args_info->verify_crt_orig));
231 
232 
233   for (i = 0; i < args_info->inputs_num; ++i)
234     free (args_info->inputs [i]);
235 
236   if (args_info->inputs_num)
237     free (args_info->inputs);
238 
239   clear_given (args_info);
240 }
241 
242 
243 static void
write_into_file(FILE * outfile,const char * opt,const char * arg,const char * values[])244 write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
245 {
246   FIX_UNUSED (values);
247   if (arg) {
248     fprintf(outfile, "%s=\"%s\"\n", opt, arg);
249   } else {
250     fprintf(outfile, "%s\n", opt);
251   }
252 }
253 
254 
255 int
cmdline_parser_dump(FILE * outfile,struct gengetopt_args_info * args_info)256 cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
257 {
258   int i = 0;
259 
260   if (!outfile)
261     {
262       fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
263       return EXIT_FAILURE;
264     }
265 
266   if (args_info->help_given)
267     write_into_file(outfile, "help", 0, 0 );
268   if (args_info->version_given)
269     write_into_file(outfile, "version", 0, 0 );
270   if (args_info->strict_given)
271     write_into_file(outfile, "strict", 0, 0 );
272   if (args_info->debug_given)
273     write_into_file(outfile, "debug", 0, 0 );
274   if (args_info->quiet_given)
275     write_into_file(outfile, "quiet", 0, 0 );
276   if (args_info->verbose_given)
277     write_into_file(outfile, "verbose", 0, 0 );
278   if (args_info->info_given)
279     write_into_file(outfile, "info", 0, 0 );
280   if (args_info->validate_given)
281     write_into_file(outfile, "validate", 0, 0 );
282   if (args_info->sign_given)
283     write_into_file(outfile, "sign", 0, 0 );
284   if (args_info->sign_key_given)
285     write_into_file(outfile, "sign-key", args_info->sign_key_orig, 0);
286   if (args_info->sign_crt_given)
287     write_into_file(outfile, "sign-crt", args_info->sign_crt_orig, 0);
288   if (args_info->verify_given)
289     write_into_file(outfile, "verify", 0, 0 );
290   if (args_info->verify_crt_given)
291     write_into_file(outfile, "verify-crt", args_info->verify_crt_orig, 0);
292 
293 
294   i = EXIT_SUCCESS;
295   return i;
296 }
297 
298 int
cmdline_parser_file_save(const char * filename,struct gengetopt_args_info * args_info)299 cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
300 {
301   FILE *outfile;
302   int i = 0;
303 
304   outfile = fopen(filename, "w");
305 
306   if (!outfile)
307     {
308       fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
309       return EXIT_FAILURE;
310     }
311 
312   i = cmdline_parser_dump(outfile, args_info);
313   fclose (outfile);
314 
315   return i;
316 }
317 
318 void
cmdline_parser_free(struct gengetopt_args_info * args_info)319 cmdline_parser_free (struct gengetopt_args_info *args_info)
320 {
321   cmdline_parser_release (args_info);
322 }
323 
324 /** @brief replacement of strdup, which is not standard */
325 char *
gengetopt_strdup(const char * s)326 gengetopt_strdup (const char *s)
327 {
328   char *result = 0;
329   if (!s)
330     return result;
331 
332   result = (char*)malloc(strlen(s) + 1);
333   if (result == (char*)0)
334     return (char*)0;
335   strcpy(result, s);
336   return result;
337 }
338 
339 int
cmdline_parser(int argc,char ** argv,struct gengetopt_args_info * args_info)340 cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
341 {
342   return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
343 }
344 
345 int
cmdline_parser_ext(int argc,char ** argv,struct gengetopt_args_info * args_info,struct cmdline_parser_params * params)346 cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
347                    struct cmdline_parser_params *params)
348 {
349   int result;
350   result = cmdline_parser_internal (argc, argv, args_info, params, 0);
351 
352   if (result == EXIT_FAILURE)
353     {
354       cmdline_parser_free (args_info);
355       exit (EXIT_FAILURE);
356     }
357 
358   return result;
359 }
360 
361 int
cmdline_parser2(int argc,char ** argv,struct gengetopt_args_info * args_info,int override,int initialize,int check_required)362 cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
363 {
364   int result;
365   struct cmdline_parser_params params;
366 
367   params.override = override;
368   params.initialize = initialize;
369   params.check_required = check_required;
370   params.check_ambiguity = 0;
371   params.print_errors = 1;
372 
373   result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
374 
375   if (result == EXIT_FAILURE)
376     {
377       cmdline_parser_free (args_info);
378       exit (EXIT_FAILURE);
379     }
380 
381   return result;
382 }
383 
384 int
cmdline_parser_required(struct gengetopt_args_info * args_info,const char * prog_name)385 cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
386 {
387   int result = EXIT_SUCCESS;
388 
389   if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
390     result = EXIT_FAILURE;
391 
392   if (result == EXIT_FAILURE)
393     {
394       cmdline_parser_free (args_info);
395       exit (EXIT_FAILURE);
396     }
397 
398   return result;
399 }
400 
401 int
cmdline_parser_required2(struct gengetopt_args_info * args_info,const char * prog_name,const char * additional_error)402 cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)
403 {
404   int error_occurred = 0;
405   FIX_UNUSED (additional_error);
406 
407   /* checks for required options */
408   if (args_info->sign_mode_counter && ! args_info->sign_key_given)
409     {
410       fprintf (stderr, "%s: '--sign-key' option required%s\n", prog_name, (additional_error ? additional_error : ""));
411       error_occurred = 1;
412     }
413 
414   if (args_info->sign_mode_counter && ! args_info->sign_crt_given)
415     {
416       fprintf (stderr, "%s: '--sign-crt' option required%s\n", prog_name, (additional_error ? additional_error : ""));
417       error_occurred = 1;
418     }
419 
420   if (args_info->verify_mode_counter && ! args_info->verify_crt_given)
421     {
422       fprintf (stderr, "%s: '--verify-crt' option required%s\n", prog_name, (additional_error ? additional_error : ""));
423       error_occurred = 1;
424     }
425 
426 
427   /* checks for dependences among options */
428   if (args_info->sign_key_given && ! args_info->sign_given)
429     {
430       fprintf (stderr, "%s: '--sign-key' option depends on option 'sign'%s\n", prog_name, (additional_error ? additional_error : ""));
431       error_occurred = 1;
432     }
433   if (args_info->sign_crt_given && ! args_info->sign_given)
434     {
435       fprintf (stderr, "%s: '--sign-crt' option depends on option 'sign'%s\n", prog_name, (additional_error ? additional_error : ""));
436       error_occurred = 1;
437     }
438   if (args_info->verify_crt_given && ! args_info->verify_given)
439     {
440       fprintf (stderr, "%s: '--verify-crt' option depends on option 'verify'%s\n", prog_name, (additional_error ? additional_error : ""));
441       error_occurred = 1;
442     }
443 
444   return error_occurred;
445 }
446 
447 
448 static char *package_name = 0;
449 
450 /**
451  * @brief updates an option
452  * @param field the generic pointer to the field to update
453  * @param orig_field the pointer to the orig field
454  * @param field_given the pointer to the number of occurrence of this option
455  * @param prev_given the pointer to the number of occurrence already seen
456  * @param value the argument for this option (if null no arg was specified)
457  * @param possible_values the possible values for this option (if specified)
458  * @param default_value the default value (in case the option only accepts fixed values)
459  * @param arg_type the type of this option
460  * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
461  * @param override @see cmdline_parser_params.override
462  * @param no_free whether to free a possible previous value
463  * @param multiple_option whether this is a multiple option
464  * @param long_opt the corresponding long option
465  * @param short_opt the corresponding short option (or '-' if none)
466  * @param additional_error possible further error specification
467  */
468 static
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)469 int update_arg(void *field, char **orig_field,
470                unsigned int *field_given, unsigned int *prev_given,
471                char *value, const char *possible_values[],
472                const char *default_value,
473                cmdline_parser_arg_type arg_type,
474                int check_ambiguity, int override,
475                int no_free, int multiple_option,
476                const char *long_opt, char short_opt,
477                const char *additional_error)
478 {
479   char *stop_char = 0;
480   const char *val = value;
481   int found;
482   char **string_field;
483   FIX_UNUSED (field);
484 
485   stop_char = 0;
486   found = 0;
487 
488   if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
489     {
490       if (short_opt != '-')
491         fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
492                package_name, long_opt, short_opt,
493                (additional_error ? additional_error : ""));
494       else
495         fprintf (stderr, "%s: `--%s' option given more than once%s\n",
496                package_name, long_opt,
497                (additional_error ? additional_error : ""));
498       return 1; /* failure */
499     }
500 
501   FIX_UNUSED (default_value);
502 
503   if (field_given && *field_given && ! override)
504     return 0;
505   if (prev_given)
506     (*prev_given)++;
507   if (field_given)
508     (*field_given)++;
509   if (possible_values)
510     val = possible_values[found];
511 
512   switch(arg_type) {
513   case ARG_FLAG:
514     *((int *)field) = !*((int *)field);
515     break;
516   case ARG_STRING:
517     if (val) {
518       string_field = (char **)field;
519       if (!no_free && *string_field)
520         free (*string_field); /* free previous string */
521       *string_field = gengetopt_strdup (val);
522     }
523     break;
524   default:
525     break;
526   };
527 
528 
529   /* store the original value */
530   switch(arg_type) {
531   case ARG_NO:
532   case ARG_FLAG:
533     break;
534   default:
535     if (value && orig_field) {
536       if (no_free) {
537         *orig_field = value;
538       } else {
539         if (*orig_field)
540           free (*orig_field); /* free previous string */
541         *orig_field = gengetopt_strdup (value);
542       }
543     }
544   };
545 
546   return 0; /* OK */
547 }
548 
549 
check_modes(int given1[],const char * options1[],int given2[],const char * options2[])550 static int check_modes(
551   int given1[], const char *options1[],
552                        int given2[], const char *options2[])
553 {
554   int i = 0, j = 0, errors = 0;
555 
556   while (given1[i] >= 0) {
557     if (given1[i]) {
558       while (given2[j] >= 0) {
559         if (given2[j]) {
560           ++errors;
561           fprintf(stderr, "%s: option %s conflicts with option %s\n",
562                   package_name, options1[i], options2[j]);
563         }
564         ++j;
565       }
566     }
567     ++i;
568   }
569 
570   return errors;
571 }
572 
573 int
cmdline_parser_internal(int argc,char ** argv,struct gengetopt_args_info * args_info,struct cmdline_parser_params * params,const char * additional_error)574 cmdline_parser_internal (
575   int argc, char **argv, struct gengetopt_args_info *args_info,
576                         struct cmdline_parser_params *params, const char *additional_error)
577 {
578   int c;	/* Character of the parsed option.  */
579 
580   int error_occurred = 0;
581   struct gengetopt_args_info local_args_info;
582 
583   int override;
584   int initialize;
585   int check_required;
586   int check_ambiguity;
587 
588   package_name = argv[0];
589 
590   override = params->override;
591   initialize = params->initialize;
592   check_required = params->check_required;
593   check_ambiguity = params->check_ambiguity;
594 
595   if (initialize)
596     cmdline_parser_init (args_info);
597 
598   cmdline_parser_init (&local_args_info);
599 
600   optarg = 0;
601   optind = 0;
602   opterr = params->print_errors;
603   optopt = '?';
604 
605   while (1)
606     {
607       int option_index = 0;
608 
609       static struct option long_options[] = {
610         { "help",	0, NULL, 'h' },
611         { "version",	0, NULL, 'V' },
612         { "strict",	0, NULL, 0 },
613         { "debug",	0, NULL, 'd' },
614         { "quiet",	0, NULL, 'q' },
615         { "verbose",	0, NULL, 'v' },
616         { "info",	0, NULL, 'i' },
617         { "validate",	0, NULL, 'e' },
618         { "sign",	0, NULL, 0 },
619         { "sign-key",	1, NULL, 0 },
620         { "sign-crt",	1, NULL, 0 },
621         { "verify",	0, NULL, 0 },
622         { "verify-crt",	1, NULL, 0 },
623         { 0,  0, 0, 0 }
624       };
625 
626       c = getopt_long (argc, argv, "hVdqvie", long_options, &option_index);
627 
628       if (c == -1) break;	/* Exit from `while (1)' loop.  */
629 
630       switch (c)
631         {
632         case 'h':	/* Print help and exit.  */
633 
634 
635           if (update_arg( 0 ,
636                0 , &(args_info->help_given),
637               &(local_args_info.help_given), optarg, 0, 0, ARG_NO,
638               check_ambiguity, override, 0, 0,
639               "help", 'h',
640               additional_error))
641             goto failure;
642           cmdline_parser_free (&local_args_info);
643           return 0;
644 
645           break;
646         case 'V':	/* Print version and exit.  */
647 
648 
649           if (update_arg( 0 ,
650                0 , &(args_info->version_given),
651               &(local_args_info.version_given), optarg, 0, 0, ARG_NO,
652               check_ambiguity, override, 0, 0,
653               "version", 'V',
654               additional_error))
655             goto failure;
656           cmdline_parser_free (&local_args_info);
657           return 0;
658 
659           break;
660         case 'd':	/* Show debug mesages on stderr.  */
661 
662 
663           if (update_arg((void *)&(args_info->debug_flag), 0, &(args_info->debug_given),
664               &(local_args_info.debug_given), optarg, 0, 0, ARG_FLAG,
665               check_ambiguity, override, 1, 0, "debug", 'd',
666               additional_error))
667             goto failure;
668 
669           break;
670         case 'q':	/* Quiet operation.  */
671 
672 
673           if (update_arg((void *)&(args_info->quiet_flag), 0, &(args_info->quiet_given),
674               &(local_args_info.quiet_given), optarg, 0, 0, ARG_FLAG,
675               check_ambiguity, override, 1, 0, "quiet", 'q',
676               additional_error))
677             goto failure;
678 
679           break;
680         case 'v':	/* Produce more output.  */
681 
682 
683           if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given),
684               &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG,
685               check_ambiguity, override, 1, 0, "verbose", 'v',
686               additional_error))
687             goto failure;
688 
689           break;
690         case 'i':	/* Parse and print human readable summary of PSKC input.  */
691           args_info->info_mode_counter += 1;
692 
693 
694           if (update_arg((void *)&(args_info->info_flag), 0, &(args_info->info_given),
695               &(local_args_info.info_given), optarg, 0, 0, ARG_FLAG,
696               check_ambiguity, override, 1, 0, "info", 'i',
697               additional_error))
698             goto failure;
699 
700           break;
701         case 'e':	/* Validate PSKC input against XML Schema.  */
702           args_info->validate_mode_counter += 1;
703 
704 
705           if (update_arg((void *)&(args_info->validate_flag), 0, &(args_info->validate_given),
706               &(local_args_info.validate_given), optarg, 0, 0, ARG_FLAG,
707               check_ambiguity, override, 1, 0, "validate", 'e',
708               additional_error))
709             goto failure;
710 
711           break;
712 
713         case 0:	/* Long option with no short option */
714           /* Fail hard on PSKC parse error.  */
715           if (strcmp (long_options[option_index].name, "strict") == 0)
716           {
717 
718 
719             if (update_arg((void *)&(args_info->strict_flag), 0, &(args_info->strict_given),
720                 &(local_args_info.strict_given), optarg, 0, 0, ARG_FLAG,
721                 check_ambiguity, override, 1, 0, "strict", '-',
722                 additional_error))
723               goto failure;
724 
725           }
726           /* Sign PSKC input.  */
727           else if (strcmp (long_options[option_index].name, "sign") == 0)
728           {
729             args_info->sign_mode_counter += 1;
730 
731 
732             if (update_arg((void *)&(args_info->sign_flag), 0, &(args_info->sign_given),
733                 &(local_args_info.sign_given), optarg, 0, 0, ARG_FLAG,
734                 check_ambiguity, override, 1, 0, "sign", '-',
735                 additional_error))
736               goto failure;
737 
738           }
739           /* Private key to sign with.  */
740           else if (strcmp (long_options[option_index].name, "sign-key") == 0)
741           {
742             args_info->sign_mode_counter += 1;
743 
744 
745             if (update_arg( (void *)&(args_info->sign_key_arg),
746                  &(args_info->sign_key_orig), &(args_info->sign_key_given),
747                 &(local_args_info.sign_key_given), optarg, 0, 0, ARG_STRING,
748                 check_ambiguity, override, 0, 0,
749                 "sign-key", '-',
750                 additional_error))
751               goto failure;
752 
753           }
754           /* X.509 certificate to sign with.  */
755           else if (strcmp (long_options[option_index].name, "sign-crt") == 0)
756           {
757             args_info->sign_mode_counter += 1;
758 
759 
760             if (update_arg( (void *)&(args_info->sign_crt_arg),
761                  &(args_info->sign_crt_orig), &(args_info->sign_crt_given),
762                 &(local_args_info.sign_crt_given), optarg, 0, 0, ARG_STRING,
763                 check_ambiguity, override, 0, 0,
764                 "sign-crt", '-',
765                 additional_error))
766               goto failure;
767 
768           }
769           /* Verify signed PSKC input.  */
770           else if (strcmp (long_options[option_index].name, "verify") == 0)
771           {
772             args_info->verify_mode_counter += 1;
773 
774 
775             if (update_arg((void *)&(args_info->verify_flag), 0, &(args_info->verify_given),
776                 &(local_args_info.verify_given), optarg, 0, 0, ARG_FLAG,
777                 check_ambiguity, override, 1, 0, "verify", '-',
778                 additional_error))
779               goto failure;
780 
781           }
782           /* Trusted X.509 certificate for verification.  */
783           else if (strcmp (long_options[option_index].name, "verify-crt") == 0)
784           {
785             args_info->verify_mode_counter += 1;
786 
787 
788             if (update_arg( (void *)&(args_info->verify_crt_arg),
789                  &(args_info->verify_crt_orig), &(args_info->verify_crt_given),
790                 &(local_args_info.verify_crt_given), optarg, 0, 0, ARG_STRING,
791                 check_ambiguity, override, 0, 0,
792                 "verify-crt", '-',
793                 additional_error))
794               goto failure;
795 
796           }
797 
798           break;
799         case '?':	/* Invalid option.  */
800           /* `getopt_long' already printed an error message.  */
801           goto failure;
802 
803         default:	/* bug: option not considered.  */
804           fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
805           abort ();
806         } /* switch */
807     } /* while */
808 
809 
810 
811   if (args_info->info_mode_counter && args_info->sign_mode_counter) {
812     int info_given[] = {args_info->info_given,  -1};
813     const char *info_desc[] = {"--info",  0};
814     int sign_given[] = {args_info->sign_given, args_info->sign_key_given, args_info->sign_crt_given,  -1};
815     const char *sign_desc[] = {"--sign", "--sign-key", "--sign-crt",  0};
816     error_occurred += check_modes(info_given, info_desc, sign_given, sign_desc);
817   }
818   if (args_info->info_mode_counter && args_info->validate_mode_counter) {
819     int info_given[] = {args_info->info_given,  -1};
820     const char *info_desc[] = {"--info",  0};
821     int validate_given[] = {args_info->validate_given,  -1};
822     const char *validate_desc[] = {"--validate",  0};
823     error_occurred += check_modes(info_given, info_desc, validate_given, validate_desc);
824   }
825   if (args_info->info_mode_counter && args_info->verify_mode_counter) {
826     int info_given[] = {args_info->info_given,  -1};
827     const char *info_desc[] = {"--info",  0};
828     int verify_given[] = {args_info->verify_given, args_info->verify_crt_given,  -1};
829     const char *verify_desc[] = {"--verify", "--verify-crt",  0};
830     error_occurred += check_modes(info_given, info_desc, verify_given, verify_desc);
831   }
832   if (args_info->sign_mode_counter && args_info->validate_mode_counter) {
833     int sign_given[] = {args_info->sign_given, args_info->sign_key_given, args_info->sign_crt_given,  -1};
834     const char *sign_desc[] = {"--sign", "--sign-key", "--sign-crt",  0};
835     int validate_given[] = {args_info->validate_given,  -1};
836     const char *validate_desc[] = {"--validate",  0};
837     error_occurred += check_modes(sign_given, sign_desc, validate_given, validate_desc);
838   }
839   if (args_info->sign_mode_counter && args_info->verify_mode_counter) {
840     int sign_given[] = {args_info->sign_given, args_info->sign_key_given, args_info->sign_crt_given,  -1};
841     const char *sign_desc[] = {"--sign", "--sign-key", "--sign-crt",  0};
842     int verify_given[] = {args_info->verify_given, args_info->verify_crt_given,  -1};
843     const char *verify_desc[] = {"--verify", "--verify-crt",  0};
844     error_occurred += check_modes(sign_given, sign_desc, verify_given, verify_desc);
845   }
846   if (args_info->validate_mode_counter && args_info->verify_mode_counter) {
847     int validate_given[] = {args_info->validate_given,  -1};
848     const char *validate_desc[] = {"--validate",  0};
849     int verify_given[] = {args_info->verify_given, args_info->verify_crt_given,  -1};
850     const char *verify_desc[] = {"--verify", "--verify-crt",  0};
851     error_occurred += check_modes(validate_given, validate_desc, verify_given, verify_desc);
852   }
853 
854   if (check_required)
855     {
856       error_occurred += cmdline_parser_required2 (args_info, argv[0], additional_error);
857     }
858 
859   cmdline_parser_release (&local_args_info);
860 
861   if ( error_occurred )
862     return (EXIT_FAILURE);
863 
864   if (optind < argc)
865     {
866       int i = 0 ;
867       int found_prog_name = 0;
868       /* whether program name, i.e., argv[0], is in the remaining args
869          (this may happen with some implementations of getopt,
870           but surely not with the one included by gengetopt) */
871 
872       i = optind;
873       while (i < argc)
874         if (argv[i++] == argv[0]) {
875           found_prog_name = 1;
876           break;
877         }
878       i = 0;
879 
880       args_info->inputs_num = argc - optind - found_prog_name;
881       args_info->inputs =
882         (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
883       while (optind < argc)
884         if (argv[optind++] != argv[0])
885           args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;
886     }
887 
888   return 0;
889 
890 failure:
891 
892   cmdline_parser_release (&local_args_info);
893   return (EXIT_FAILURE);
894 }
895