Bug Summary

File:oathtool/oathtool_cmd.c
Location:line 519, column 3
Description:Value stored to 'check_required' is never read

Annotated Source Code

1/*
2 File autogenerated by gengetopt version 2.22.5
3 generated with the following command:
4 gengetopt --unamed-opts=KEY [OTP] --no-handle-version --no-handle-help --input oathtool.ggo --file-name oathtool_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_H1
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) (void) (X) /* avoid warnings for unused params */
22#endif
23
24#include <getopt.h>
25
26#include "oathtool_cmd.h"
27
28const char *gengetopt_args_info_purpose = "Generate and validate OATH one-time passwords.";
29
30const char *gengetopt_args_info_usage = "Usage: " CMDLINE_PARSER_PACKAGE"oathtool" " [OPTIONS]... [KEY [OTP]]...";
31
32const char *gengetopt_args_info_description = "";
33
34const char *gengetopt_args_info_help[] = {
35 " -h, --help Print help and exit",
36 " -V, --version Print version and exit",
37 " --hotp use event-based HOTP mode (default=on)",
38 " --totp use time-variant TOTP mode (default=off)",
39 " -b, --base32 use base32 encoding of KEY instead of hex \n (default=off)",
40 " -c, --counter=COUNTER HOTP counter value",
41 " -s, --time-step-size=DURATION TOTP time-step duration (default=`30s')",
42 " -S, --start-time=TIME when to start counting time steps for TOTP \n (default=`1970-01-01 00:00:00 UTC')",
43 " -N, --now=TIME use this time as current time for TOTP \n (default=`now')",
44 " -d, --digits=DIGITS number of digits in one-time password",
45 " -w, --window=WIDTH window of counter values to test when \n validating OTPs",
46 " -v, --verbose explain what is being done (default=off)",
47 0
48};
49
50typedef enum {ARG_NO
51 , ARG_FLAG
52 , ARG_STRING
53 , ARG_INT
54 , ARG_LONGLONG
55} cmdline_parser_arg_type;
56
57static
58void clear_given (struct gengetopt_args_info *args_info);
59static
60void clear_args (struct gengetopt_args_info *args_info);
61
62static int
63cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
64 struct cmdline_parser_params *params, const char *additional_error);
65
66
67static char *
68gengetopt_strdup (const char *s);
69
70static
71void clear_given (struct gengetopt_args_info *args_info)
72{
73 args_info->help_given = 0 ;
74 args_info->version_given = 0 ;
75 args_info->hotp_given = 0 ;
76 args_info->totp_given = 0 ;
77 args_info->base32_given = 0 ;
78 args_info->counter_given = 0 ;
79 args_info->time_step_size_given = 0 ;
80 args_info->start_time_given = 0 ;
81 args_info->now_given = 0 ;
82 args_info->digits_given = 0 ;
83 args_info->window_given = 0 ;
84 args_info->verbose_given = 0 ;
85}
86
87static
88void clear_args (struct gengetopt_args_info *args_info)
89{
90 FIX_UNUSED (args_info)(void) (args_info);
91 args_info->hotp_flag = 1;
92 args_info->totp_flag = 0;
93 args_info->base32_flag = 0;
94 args_info->counter_orig = NULL((void*)0);
95 args_info->time_step_size_arg = gengetopt_strdup ("30s");
96 args_info->time_step_size_orig = NULL((void*)0);
97 args_info->start_time_arg = gengetopt_strdup ("1970-01-01 00:00:00 UTC");
98 args_info->start_time_orig = NULL((void*)0);
99 args_info->now_arg = gengetopt_strdup ("now");
100 args_info->now_orig = NULL((void*)0);
101 args_info->digits_orig = NULL((void*)0);
102 args_info->window_orig = NULL((void*)0);
103 args_info->verbose_flag = 0;
104
105}
106
107static
108void init_args_info(struct gengetopt_args_info *args_info)
109{
110
111
112 args_info->help_help = gengetopt_args_info_help[0] ;
113 args_info->version_help = gengetopt_args_info_help[1] ;
114 args_info->hotp_help = gengetopt_args_info_help[2] ;
115 args_info->totp_help = gengetopt_args_info_help[3] ;
116 args_info->base32_help = gengetopt_args_info_help[4] ;
117 args_info->counter_help = gengetopt_args_info_help[5] ;
118 args_info->time_step_size_help = gengetopt_args_info_help[6] ;
119 args_info->start_time_help = gengetopt_args_info_help[7] ;
120 args_info->now_help = gengetopt_args_info_help[8] ;
121 args_info->digits_help = gengetopt_args_info_help[9] ;
122 args_info->window_help = gengetopt_args_info_help[10] ;
123 args_info->verbose_help = gengetopt_args_info_help[11] ;
124
125}
126
127void
128cmdline_parser_print_version (void)
129{
130 printf ("%s %s\n",
131 (strlen(CMDLINE_PARSER_PACKAGE_NAME"oathtool") ? CMDLINE_PARSER_PACKAGE_NAME"oathtool" : CMDLINE_PARSER_PACKAGE"oathtool"),
132 CMDLINE_PARSER_VERSION"2.0.1");
133}
134
135static void print_help_common(void) {
136 cmdline_parser_print_version ();
137
138 if (strlen(gengetopt_args_info_purpose) > 0)
139 printf("\n%s\n", gengetopt_args_info_purpose);
140
141 if (strlen(gengetopt_args_info_usage) > 0)
142 printf("\n%s\n", gengetopt_args_info_usage);
143
144 printf("\n");
145
146 if (strlen(gengetopt_args_info_description) > 0)
147 printf("%s\n\n", gengetopt_args_info_description);
148}
149
150void
151cmdline_parser_print_help (void)
152{
153 int i = 0;
154 print_help_common();
155 while (gengetopt_args_info_help[i])
156 printf("%s\n", gengetopt_args_info_help[i++]);
157}
158
159void
160cmdline_parser_init (struct gengetopt_args_info *args_info)
161{
162 clear_given (args_info);
163 clear_args (args_info);
164 init_args_info (args_info);
165
166 args_info->inputs = 0;
167 args_info->inputs_num = 0;
168}
169
170void
171cmdline_parser_params_init(struct cmdline_parser_params *params)
172{
173 if (params)
174 {
175 params->override = 0;
176 params->initialize = 1;
177 params->check_required = 1;
178 params->check_ambiguity = 0;
179 params->print_errors = 1;
180 }
181}
182
183struct cmdline_parser_params *
184cmdline_parser_params_create(void)
185{
186 struct cmdline_parser_params *params =
187 (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
188 cmdline_parser_params_init(params);
189 return params;
190}
191
192static void
193free_string_field (char **s)
194{
195 if (*s)
196 {
197 free (*s);
198 *s = 0;
199 }
200}
201
202
203static void
204cmdline_parser_release (struct gengetopt_args_info *args_info)
205{
206 unsigned int i;
207 free_string_field (&(args_info->counter_orig));
208 free_string_field (&(args_info->time_step_size_arg));
209 free_string_field (&(args_info->time_step_size_orig));
210 free_string_field (&(args_info->start_time_arg));
211 free_string_field (&(args_info->start_time_orig));
212 free_string_field (&(args_info->now_arg));
213 free_string_field (&(args_info->now_orig));
214 free_string_field (&(args_info->digits_orig));
215 free_string_field (&(args_info->window_orig));
216
217
218 for (i = 0; i < args_info->inputs_num; ++i)
219 free (args_info->inputs [i]);
220
221 if (args_info->inputs_num)
222 free (args_info->inputs);
223
224 clear_given (args_info);
225}
226
227
228static void
229write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
230{
231 FIX_UNUSED (values)(void) (values);
232 if (arg) {
233 fprintf(outfile, "%s=\"%s\"\n", opt, arg);
234 } else {
235 fprintf(outfile, "%s\n", opt);
236 }
237}
238
239
240int
241cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
242{
243 int i = 0;
244
245 if (!outfile)
246 {
247 fprintf (stderrstderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE"oathtool");
248 return EXIT_FAILURE1;
249 }
250
251 if (args_info->help_given)
252 write_into_file(outfile, "help", 0, 0 );
253 if (args_info->version_given)
254 write_into_file(outfile, "version", 0, 0 );
255 if (args_info->hotp_given)
256 write_into_file(outfile, "hotp", 0, 0 );
257 if (args_info->totp_given)
258 write_into_file(outfile, "totp", 0, 0 );
259 if (args_info->base32_given)
260 write_into_file(outfile, "base32", 0, 0 );
261 if (args_info->counter_given)
262 write_into_file(outfile, "counter", args_info->counter_orig, 0);
263 if (args_info->time_step_size_given)
264 write_into_file(outfile, "time-step-size", args_info->time_step_size_orig, 0);
265 if (args_info->start_time_given)
266 write_into_file(outfile, "start-time", args_info->start_time_orig, 0);
267 if (args_info->now_given)
268 write_into_file(outfile, "now", args_info->now_orig, 0);
269 if (args_info->digits_given)
270 write_into_file(outfile, "digits", args_info->digits_orig, 0);
271 if (args_info->window_given)
272 write_into_file(outfile, "window", args_info->window_orig, 0);
273 if (args_info->verbose_given)
274 write_into_file(outfile, "verbose", 0, 0 );
275
276
277 i = EXIT_SUCCESS0;
278 return i;
279}
280
281int
282cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
283{
284 FILE *outfile;
285 int i = 0;
286
287 outfile = fopen(filename, "w");
288
289 if (!outfile)
290 {
291 fprintf (stderrstderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE"oathtool", filename);
292 return EXIT_FAILURE1;
293 }
294
295 i = cmdline_parser_dump(outfile, args_info);
296 fclose (outfile);
297
298 return i;
299}
300
301void
302cmdline_parser_free (struct gengetopt_args_info *args_info)
303{
304 cmdline_parser_release (args_info);
305}
306
307/** @brief replacement of strdup, which is not standard */
308char *
309gengetopt_strdup (const char *s)
310{
311 char *result = 0;
312 if (!s)
313 return result;
314
315 result = (char*)malloc(strlen(s) + 1);
316 if (result == (char*)0)
317 return (char*)0;
318 strcpy(result, s);
319 return result;
320}
321
322int
323cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
324{
325 return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
326}
327
328int
329cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
330 struct cmdline_parser_params *params)
331{
332 int result;
333 result = cmdline_parser_internal (argc, argv, args_info, params, 0);
334
335 if (result == EXIT_FAILURE1)
336 {
337 cmdline_parser_free (args_info);
338 exit (EXIT_FAILURE1);
339 }
340
341 return result;
342}
343
344int
345cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
346{
347 int result;
348 struct cmdline_parser_params params;
349
350 params.override = override;
351 params.initialize = initialize;
352 params.check_required = check_required;
353 params.check_ambiguity = 0;
354 params.print_errors = 1;
355
356 result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
357
358 if (result == EXIT_FAILURE1)
359 {
360 cmdline_parser_free (args_info);
361 exit (EXIT_FAILURE1);
362 }
363
364 return result;
365}
366
367int
368cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
369{
370 FIX_UNUSED (args_info)(void) (args_info);
371 FIX_UNUSED (prog_name)(void) (prog_name);
372 return EXIT_SUCCESS0;
373}
374
375
376static char *package_name = 0;
377
378/**
379 * @brief updates an option
380 * @param field the generic pointer to the field to update
381 * @param orig_field the pointer to the orig field
382 * @param field_given the pointer to the number of occurrence of this option
383 * @param prev_given the pointer to the number of occurrence already seen
384 * @param value the argument for this option (if null no arg was specified)
385 * @param possible_values the possible values for this option (if specified)
386 * @param default_value the default value (in case the option only accepts fixed values)
387 * @param arg_type the type of this option
388 * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
389 * @param override @see cmdline_parser_params.override
390 * @param no_free whether to free a possible previous value
391 * @param multiple_option whether this is a multiple option
392 * @param long_opt the corresponding long option
393 * @param short_opt the corresponding short option (or '-' if none)
394 * @param additional_error possible further error specification
395 */
396static
397int update_arg(void *field, char **orig_field,
398 unsigned int *field_given, unsigned int *prev_given,
399 char *value, const char *possible_values[],
400 const char *default_value,
401 cmdline_parser_arg_type arg_type,
402 int check_ambiguity, int override,
403 int no_free, int multiple_option,
404 const char *long_opt, char short_opt,
405 const char *additional_error)
406{
407 char *stop_char = 0;
408 const char *val = value;
409 int found;
410 char **string_field;
411 FIX_UNUSED (field)(void) (field);
412
413 stop_char = 0;
414 found = 0;
415
416 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
417 {
418 if (short_opt != '-')
419 fprintf (stderrstderr, "%s: `--%s' (`-%c') option given more than once%s\n",
420 package_name, long_opt, short_opt,
421 (additional_error ? additional_error : ""));
422 else
423 fprintf (stderrstderr, "%s: `--%s' option given more than once%s\n",
424 package_name, long_opt,
425 (additional_error ? additional_error : ""));
426 return 1; /* failure */
427 }
428
429 FIX_UNUSED (default_value)(void) (default_value);
430
431 if (field_given && *field_given && ! override)
432 return 0;
433 if (prev_given)
434 (*prev_given)++;
435 if (field_given)
436 (*field_given)++;
437 if (possible_values)
438 val = possible_values[found];
439
440 switch(arg_type) {
441 case ARG_FLAG:
442 *((int *)field) = !*((int *)field);
443 break;
444 case ARG_INT:
445 if (val) *((int *)field) = strtol (val, &stop_char, 0);
446 break;
447 case ARG_LONGLONG:
448#ifdef HAVE_LONG_LONG_INT1
449 if (val) *((long long int*)field) = (long long int) strtoll (val, &stop_char, 0);
450#else
451 if (val) *((long *)field) = (long)strtol (val, &stop_char, 0);
452#endif
453 break;
454 case ARG_STRING:
455 if (val) {
456 string_field = (char **)field;
457 if (!no_free && *string_field)
458 free (*string_field); /* free previous string */
459 *string_field = gengetopt_strdup (val);
460 }
461 break;
462 default:
463 break;
464 };
465
466 /* check numeric conversion */
467 switch(arg_type) {
468 case ARG_INT:
469 case ARG_LONGLONG:
470 if (val && !(stop_char && *stop_char == '\0')) {
471 fprintf(stderrstderr, "%s: invalid numeric value: %s\n", package_name, val);
472 return 1; /* failure */
473 }
474 break;
475 default:
476 ;
477 };
478
479 /* store the original value */
480 switch(arg_type) {
481 case ARG_NO:
482 case ARG_FLAG:
483 break;
484 default:
485 if (value && orig_field) {
486 if (no_free) {
487 *orig_field = value;
488 } else {
489 if (*orig_field)
490 free (*orig_field); /* free previous string */
491 *orig_field = gengetopt_strdup (value);
492 }
493 }
494 };
495
496 return 0; /* OK */
497}
498
499
500int
501cmdline_parser_internal (
502 int argc, char **argv, struct gengetopt_args_info *args_info,
503 struct cmdline_parser_params *params, const char *additional_error)
504{
505 int c; /* Character of the parsed option. */
506
507 int error = 0;
508 struct gengetopt_args_info local_args_info;
509
510 int override;
511 int initialize;
512 int check_required;
513 int check_ambiguity;
514
515 package_name = argv[0];
516
517 override = params->override;
518 initialize = params->initialize;
519 check_required = params->check_required;
Value stored to 'check_required' is never read
520 check_ambiguity = params->check_ambiguity;
521
522 if (initialize)
523 cmdline_parser_init (args_info);
524
525 cmdline_parser_init (&local_args_info);
526
527 optarg = 0;
528 optind = 0;
529 opterr = params->print_errors;
530 optopt = '?';
531
532 while (1)
533 {
534 int option_index = 0;
535
536 static struct option long_options[] = {
537 { "help", 0, NULL((void*)0), 'h' },
538 { "version", 0, NULL((void*)0), 'V' },
539 { "hotp", 0, NULL((void*)0), 0 },
540 { "totp", 0, NULL((void*)0), 0 },
541 { "base32", 0, NULL((void*)0), 'b' },
542 { "counter", 1, NULL((void*)0), 'c' },
543 { "time-step-size", 1, NULL((void*)0), 's' },
544 { "start-time", 1, NULL((void*)0), 'S' },
545 { "now", 1, NULL((void*)0), 'N' },
546 { "digits", 1, NULL((void*)0), 'd' },
547 { "window", 1, NULL((void*)0), 'w' },
548 { "verbose", 0, NULL((void*)0), 'v' },
549 { 0, 0, 0, 0 }
550 };
551
552 c = getopt_long (argc, argv, "hVbc:s:S:N:d:w:v", long_options, &option_index);
553
554 if (c == -1) break; /* Exit from `while (1)' loop. */
555
556 switch (c)
557 {
558 case 'h': /* Print help and exit. */
559
560
561 if (update_arg( 0 ,
562 0 , &(args_info->help_given),
563 &(local_args_info.help_given), optarg, 0, 0, ARG_NO,
564 check_ambiguity, override, 0, 0,
565 "help", 'h',
566 additional_error))
567 goto failure;
568 cmdline_parser_free (&local_args_info);
569 return 0;
570
571 break;
572 case 'V': /* Print version and exit. */
573
574
575 if (update_arg( 0 ,
576 0 , &(args_info->version_given),
577 &(local_args_info.version_given), optarg, 0, 0, ARG_NO,
578 check_ambiguity, override, 0, 0,
579 "version", 'V',
580 additional_error))
581 goto failure;
582 cmdline_parser_free (&local_args_info);
583 return 0;
584
585 break;
586 case 'b': /* use base32 encoding of KEY instead of hex. */
587
588
589 if (update_arg((void *)&(args_info->base32_flag), 0, &(args_info->base32_given),
590 &(local_args_info.base32_given), optarg, 0, 0, ARG_FLAG,
591 check_ambiguity, override, 1, 0, "base32", 'b',
592 additional_error))
593 goto failure;
594
595 break;
596 case 'c': /* HOTP counter value. */
597
598
599 if (update_arg( (void *)&(args_info->counter_arg),
600 &(args_info->counter_orig), &(args_info->counter_given),
601 &(local_args_info.counter_given), optarg, 0, 0, ARG_LONGLONG,
602 check_ambiguity, override, 0, 0,
603 "counter", 'c',
604 additional_error))
605 goto failure;
606
607 break;
608 case 's': /* TOTP time-step duration. */
609
610
611 if (update_arg( (void *)&(args_info->time_step_size_arg),
612 &(args_info->time_step_size_orig), &(args_info->time_step_size_given),
613 &(local_args_info.time_step_size_given), optarg, 0, "30s", ARG_STRING,
614 check_ambiguity, override, 0, 0,
615 "time-step-size", 's',
616 additional_error))
617 goto failure;
618
619 break;
620 case 'S': /* when to start counting time steps for TOTP. */
621
622
623 if (update_arg( (void *)&(args_info->start_time_arg),
624 &(args_info->start_time_orig), &(args_info->start_time_given),
625 &(local_args_info.start_time_given), optarg, 0, "1970-01-01 00:00:00 UTC", ARG_STRING,
626 check_ambiguity, override, 0, 0,
627 "start-time", 'S',
628 additional_error))
629 goto failure;
630
631 break;
632 case 'N': /* use this time as current time for TOTP. */
633
634
635 if (update_arg( (void *)&(args_info->now_arg),
636 &(args_info->now_orig), &(args_info->now_given),
637 &(local_args_info.now_given), optarg, 0, "now", ARG_STRING,
638 check_ambiguity, override, 0, 0,
639 "now", 'N',
640 additional_error))
641 goto failure;
642
643 break;
644 case 'd': /* number of digits in one-time password. */
645
646
647 if (update_arg( (void *)&(args_info->digits_arg),
648 &(args_info->digits_orig), &(args_info->digits_given),
649 &(local_args_info.digits_given), optarg, 0, 0, ARG_INT,
650 check_ambiguity, override, 0, 0,
651 "digits", 'd',
652 additional_error))
653 goto failure;
654
655 break;
656 case 'w': /* window of counter values to test when validating OTPs. */
657
658
659 if (update_arg( (void *)&(args_info->window_arg),
660 &(args_info->window_orig), &(args_info->window_given),
661 &(local_args_info.window_given), optarg, 0, 0, ARG_INT,
662 check_ambiguity, override, 0, 0,
663 "window", 'w',
664 additional_error))
665 goto failure;
666
667 break;
668 case 'v': /* explain what is being done. */
669
670
671 if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given),
672 &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG,
673 check_ambiguity, override, 1, 0, "verbose", 'v',
674 additional_error))
675 goto failure;
676
677 break;
678
679 case 0: /* Long option with no short option */
680 /* use event-based HOTP mode. */
681 if (strcmp (long_options[option_index].name, "hotp") == 0)
682 {
683
684
685 if (update_arg((void *)&(args_info->hotp_flag), 0, &(args_info->hotp_given),
686 &(local_args_info.hotp_given), optarg, 0, 0, ARG_FLAG,
687 check_ambiguity, override, 1, 0, "hotp", '-',
688 additional_error))
689 goto failure;
690
691 }
692 /* use time-variant TOTP mode. */
693 else if (strcmp (long_options[option_index].name, "totp") == 0)
694 {
695
696
697 if (update_arg((void *)&(args_info->totp_flag), 0, &(args_info->totp_given),
698 &(local_args_info.totp_given), optarg, 0, 0, ARG_FLAG,
699 check_ambiguity, override, 1, 0, "totp", '-',
700 additional_error))
701 goto failure;
702
703 }
704
705 break;
706 case '?': /* Invalid option. */
707 /* `getopt_long' already printed an error message. */
708 goto failure;
709
710 default: /* bug: option not considered. */
711 fprintf (stderrstderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE"oathtool", c, (additional_error ? additional_error : ""));
712 abort ();
713 } /* switch */
714 } /* while */
715
716
717
718
719 cmdline_parser_release (&local_args_info);
720
721 if ( error )
722 return (EXIT_FAILURE1);
723
724 if (optind < argc)
725 {
726 int i = 0 ;
727 int found_prog_name = 0;
728 /* whether program name, i.e., argv[0], is in the remaining args
729 (this may happen with some implementations of getopt,
730 but surely not with the one included by gengetopt) */
731
732 i = optind;
733 while (i < argc)
734 if (argv[i++] == argv[0]) {
735 found_prog_name = 1;
736 break;
737 }
738 i = 0;
739
740 args_info->inputs_num = argc - optind - found_prog_name;
741 args_info->inputs =
742 (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
743 while (optind < argc)
744 if (argv[optind++] != argv[0])
745 args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;
746 }
747
748 return 0;
749
750failure:
751
752 cmdline_parser_release (&local_args_info);
753 return (EXIT_FAILURE1);
754}