Bug Summary

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

Annotated Source Code

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