Bug Summary

File:src/shishi_cmd.c
Warning:line 632, column 24
Dereference of null pointer

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-redhat-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name shishi_cmd.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/builds/gsasl/shishi/src -resource-dir /usr/lib64/clang/14.0.0 -D HAVE_CONFIG_H -I . -I .. -I ./gl -I ./gl -I ../lib/gl -I ../lib/gl -I ../lib -I ../lib -I ../db -D LOCALEDIR="/usr/local/share/locale" -D SYSTEMCFGFILE="/usr/local/etc/shishi/shishi.conf" -D HOSTKEYSFILE="/usr/local/etc/shishi/shishi.keys" -D PIC -internal-isystem /usr/lib64/clang/14.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/12/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/builds/gsasl/shishi/src -ferror-limit 19 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /builds/gsasl/shishi/clang-analyzer/2022-08-08-065803-50050-1 -x c shishi_cmd.c
1/*
2 File autogenerated by gengetopt version 2.23
3 generated with the following command:
4 gengetopt --unamed-opts=CLIENT [SERVER] --no-handle-help --no-handle-error --no-handle-version --input ./shishi.ggo --file-name shishi_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 "shishi_cmd.h"
27
28const char *gengetopt_args_info_purpose = "Shishi command line client. If no command is given, Shishi\nacquire or list a valid ticket for you, identified by CLIENT (if\nempty, default username in default realm), for the service SERVER (if\nempty, ticket granting ticket for client realm).";
29
30const char *gengetopt_args_info_usage = "Usage: shishi [OPTION]... [CLIENT [SERVER]]...";
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 "\nCommands:",
40 " -d, --destroy Destroy tickets in local cache, limited by any\n --client-name or --server-name.\n (default=off)",
41 " -l, --list List tickets in local cache, limited by any\n --client-name and --server-name.\n (default=off)",
42 " -r, --renew Renew ticket. Use --server-name to specify\n ticket, default is the most recent renewable\n ticket granting ticket for the default realm.\n (default=off)",
43 "\nFlags:",
44 " --forwardable Get a forwardable ticket, i.e., one that can be\n used to get forwarded tickets. (default=off)",
45 " --forwarded Get a forwarded ticket. (default=off)",
46 " --proxiable Get a proxiable ticket, i.e., one that can be\n used to get proxy tickets. (default=off)",
47 " --proxy Get a proxy ticket. (default=off)",
48 " --renewable Get a renewable ticket. (default=off)",
49 "\nOptions:",
50 " --client-name=NAME Client name. Default is login username.",
51 " -E, --encryption-type=ETYPE,[ETYPE...]\n Encryption types to use. ETYPE is either\n registered name or integer. Valid values\n include 'aes128', 'aes256', 'aes' (same as\n 'aes256'), '3des', 'des-md5', 'des-md4',\n 'des-crc', 'des' (same as 'des-md5'), and\n 'arcfour'.",
52 " -e, --endtime=STRING Specify when ticket validity should expire.\n The time syntax may be relative (to the start\n time), such as '20 hours', or absolute, such\n as '2001-02-03 04:05:06 CET'. The default is\n 8 hours after the start time.",
53 " --realm=STRING Set default realm.",
54 " --renew-till=STRING Specify renewable life of ticket. Implies\n --renewable. Accepts same time syntax as\n --endtime. If --renewable is specified, the\n default is 1 week after the start time.",
55 " --server-name=NAME Server name. Default is 'krbtgt/REALM' where\n REALM is client realm.",
56 " -s, --starttime=STRING Specify when ticket should start to be valid.\n Accepts same time syntax as --endtime. The\n default is to become valid immediately.",
57 " --ticket-granter=NAME Service name in ticket to use for\n authenticating request. Only for TGS.\n Defaults to 'krbtgt/REALM@REALM' where REALM\n is client realm.",
58 "\nOther options:",
59 " --configuration-file=FILE Read user configuration from FILE.",
60 " -c, --ticket-file=FILE Read tickets from FILE.",
61 " -o, --library-options=STRING Parse STRING as a configuration file statement.",
62 " -q, --quiet Don't produce any diagnostic output.\n (default=off)",
63 " --system-configuration-file=FILE\n Read system configuration from FILE.",
64 " --ticket-write-file=FILE Write tickets from FILE. Default is to write\n them back to where they were read from.",
65 " -v, --verbose Produce verbose output.\n Use multiple times to increase amount of\n information.",
66 0
67};
68
69typedef enum {ARG_NO
70 , ARG_FLAG
71 , ARG_STRING
72} cmdline_parser_arg_type;
73
74static
75void clear_given (struct gengetopt_args_info *args_info);
76static
77void clear_args (struct gengetopt_args_info *args_info);
78
79static int
80cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
81 struct cmdline_parser_params *params, const char *additional_error);
82
83static int
84cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error);
85
86static char *
87gengetopt_strdup (const char *s);
88
89static
90void clear_given (struct gengetopt_args_info *args_info)
91{
92 args_info->help_given = 0 ;
93 args_info->version_given = 0 ;
94 args_info->destroy_given = 0 ;
95 args_info->list_given = 0 ;
96 args_info->renew_given = 0 ;
97 args_info->forwardable_given = 0 ;
98 args_info->forwarded_given = 0 ;
99 args_info->proxiable_given = 0 ;
100 args_info->proxy_given = 0 ;
101 args_info->renewable_given = 0 ;
102 args_info->client_name_given = 0 ;
103 args_info->encryption_type_given = 0 ;
104 args_info->endtime_given = 0 ;
105 args_info->realm_given = 0 ;
106 args_info->renew_till_given = 0 ;
107 args_info->server_name_given = 0 ;
108 args_info->starttime_given = 0 ;
109 args_info->ticket_granter_given = 0 ;
110 args_info->configuration_file_given = 0 ;
111 args_info->ticket_file_given = 0 ;
112 args_info->library_options_given = 0 ;
113 args_info->quiet_given = 0 ;
114 args_info->system_configuration_file_given = 0 ;
115 args_info->ticket_write_file_given = 0 ;
116 args_info->verbose_given = 0 ;
117}
118
119static
120void clear_args (struct gengetopt_args_info *args_info)
121{
122 FIX_UNUSED (args_info)(void) (args_info);
123 args_info->destroy_flag = 0;
124 args_info->list_flag = 0;
125 args_info->renew_flag = 0;
126 args_info->forwardable_flag = 0;
127 args_info->forwarded_flag = 0;
128 args_info->proxiable_flag = 0;
129 args_info->proxy_flag = 0;
130 args_info->renewable_flag = 0;
131 args_info->client_name_arg = NULL((void*)0);
132 args_info->client_name_orig = NULL((void*)0);
133 args_info->encryption_type_arg = NULL((void*)0);
134 args_info->encryption_type_orig = NULL((void*)0);
135 args_info->endtime_arg = NULL((void*)0);
136 args_info->endtime_orig = NULL((void*)0);
137 args_info->realm_arg = NULL((void*)0);
138 args_info->realm_orig = NULL((void*)0);
139 args_info->renew_till_arg = NULL((void*)0);
140 args_info->renew_till_orig = NULL((void*)0);
141 args_info->server_name_arg = NULL((void*)0);
142 args_info->server_name_orig = NULL((void*)0);
143 args_info->starttime_arg = NULL((void*)0);
144 args_info->starttime_orig = NULL((void*)0);
145 args_info->ticket_granter_arg = NULL((void*)0);
146 args_info->ticket_granter_orig = NULL((void*)0);
147 args_info->configuration_file_arg = NULL((void*)0);
148 args_info->configuration_file_orig = NULL((void*)0);
149 args_info->ticket_file_arg = NULL((void*)0);
150 args_info->ticket_file_orig = NULL((void*)0);
151 args_info->library_options_arg = NULL((void*)0);
152 args_info->library_options_orig = NULL((void*)0);
153 args_info->quiet_flag = 0;
154 args_info->system_configuration_file_arg = NULL((void*)0);
155 args_info->system_configuration_file_orig = NULL((void*)0);
156 args_info->ticket_write_file_arg = NULL((void*)0);
157 args_info->ticket_write_file_orig = NULL((void*)0);
158
159}
160
161static
162void init_args_info(struct gengetopt_args_info *args_info)
163{
164
165
166 args_info->help_help = gengetopt_args_info_help[0] ;
167 args_info->version_help = gengetopt_args_info_help[1] ;
168 args_info->destroy_help = gengetopt_args_info_help[3] ;
169 args_info->list_help = gengetopt_args_info_help[4] ;
170 args_info->renew_help = gengetopt_args_info_help[5] ;
171 args_info->forwardable_help = gengetopt_args_info_help[7] ;
172 args_info->forwarded_help = gengetopt_args_info_help[8] ;
173 args_info->proxiable_help = gengetopt_args_info_help[9] ;
174 args_info->proxy_help = gengetopt_args_info_help[10] ;
175 args_info->renewable_help = gengetopt_args_info_help[11] ;
176 args_info->client_name_help = gengetopt_args_info_help[13] ;
177 args_info->encryption_type_help = gengetopt_args_info_help[14] ;
178 args_info->endtime_help = gengetopt_args_info_help[15] ;
179 args_info->realm_help = gengetopt_args_info_help[16] ;
180 args_info->renew_till_help = gengetopt_args_info_help[17] ;
181 args_info->server_name_help = gengetopt_args_info_help[18] ;
182 args_info->starttime_help = gengetopt_args_info_help[19] ;
183 args_info->ticket_granter_help = gengetopt_args_info_help[20] ;
184 args_info->configuration_file_help = gengetopt_args_info_help[22] ;
185 args_info->ticket_file_help = gengetopt_args_info_help[23] ;
186 args_info->library_options_help = gengetopt_args_info_help[24] ;
187 args_info->quiet_help = gengetopt_args_info_help[25] ;
188 args_info->system_configuration_file_help = gengetopt_args_info_help[26] ;
189 args_info->ticket_write_file_help = gengetopt_args_info_help[27] ;
190 args_info->verbose_help = gengetopt_args_info_help[28] ;
191 args_info->verbose_min = 0;
192 args_info->verbose_max = 0;
193
194}
195
196void
197cmdline_parser_print_version (void)
198{
199 printf ("%s %s\n",
200 (strlen(CMDLINE_PARSER_PACKAGE_NAME"shishi") ? CMDLINE_PARSER_PACKAGE_NAME"shishi" : CMDLINE_PARSER_PACKAGE"shishi"),
201 CMDLINE_PARSER_VERSION"1.0.3.7-c46a");
202
203 if (strlen(gengetopt_args_info_versiontext) > 0)
204 printf("\n%s\n", gengetopt_args_info_versiontext);
205}
206
207static void print_help_common(void)
208{
209 size_t len_purpose = strlen(gengetopt_args_info_purpose);
210 size_t len_usage = strlen(gengetopt_args_info_usage);
211
212 if (len_usage > 0) {
213 printf("%s\n", gengetopt_args_info_usage);
214 }
215 if (len_purpose > 0) {
216 printf("%s\n", gengetopt_args_info_purpose);
217 }
218
219 if (len_usage || len_purpose) {
220 printf("\n");
221 }
222
223 if (strlen(gengetopt_args_info_description) > 0) {
224 printf("%s\n\n", gengetopt_args_info_description);
225 }
226}
227
228void
229cmdline_parser_print_help (void)
230{
231 int i = 0;
232 print_help_common();
233 while (gengetopt_args_info_help[i])
234 printf("%s\n", gengetopt_args_info_help[i++]);
235}
236
237void
238cmdline_parser_init (struct gengetopt_args_info *args_info)
239{
240 clear_given (args_info);
241 clear_args (args_info);
242 init_args_info (args_info);
243
244 args_info->inputs = 0;
245 args_info->inputs_num = 0;
246}
247
248void
249cmdline_parser_params_init(struct cmdline_parser_params *params)
250{
251 if (params)
252 {
253 params->override = 0;
254 params->initialize = 1;
255 params->check_required = 1;
256 params->check_ambiguity = 0;
257 params->print_errors = 1;
258 }
259}
260
261struct cmdline_parser_params *
262cmdline_parser_params_create(void)
263{
264 struct cmdline_parser_params *params =
265 (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
266 cmdline_parser_params_init(params);
267 return params;
268}
269
270static void
271free_string_field (char **s)
272{
273 if (*s)
274 {
275 free (*s);
276 *s = 0;
277 }
278}
279
280
281static void
282cmdline_parser_release (struct gengetopt_args_info *args_info)
283{
284 unsigned int i;
285 free_string_field (&(args_info->client_name_arg));
286 free_string_field (&(args_info->client_name_orig));
287 free_string_field (&(args_info->encryption_type_arg));
288 free_string_field (&(args_info->encryption_type_orig));
289 free_string_field (&(args_info->endtime_arg));
290 free_string_field (&(args_info->endtime_orig));
291 free_string_field (&(args_info->realm_arg));
292 free_string_field (&(args_info->realm_orig));
293 free_string_field (&(args_info->renew_till_arg));
294 free_string_field (&(args_info->renew_till_orig));
295 free_string_field (&(args_info->server_name_arg));
296 free_string_field (&(args_info->server_name_orig));
297 free_string_field (&(args_info->starttime_arg));
298 free_string_field (&(args_info->starttime_orig));
299 free_string_field (&(args_info->ticket_granter_arg));
300 free_string_field (&(args_info->ticket_granter_orig));
301 free_string_field (&(args_info->configuration_file_arg));
302 free_string_field (&(args_info->configuration_file_orig));
303 free_string_field (&(args_info->ticket_file_arg));
304 free_string_field (&(args_info->ticket_file_orig));
305 free_string_field (&(args_info->library_options_arg));
306 free_string_field (&(args_info->library_options_orig));
307 free_string_field (&(args_info->system_configuration_file_arg));
308 free_string_field (&(args_info->system_configuration_file_orig));
309 free_string_field (&(args_info->ticket_write_file_arg));
310 free_string_field (&(args_info->ticket_write_file_orig));
311
312
313 for (i = 0; i < args_info->inputs_num; ++i)
314 free (args_info->inputs [i]);
315
316 if (args_info->inputs_num)
317 free (args_info->inputs);
318
319 clear_given (args_info);
320}
321
322
323static void
324write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
325{
326 FIX_UNUSED (values)(void) (values);
327 if (arg) {
328 fprintf(outfile, "%s=\"%s\"\n", opt, arg);
329 } else {
330 fprintf(outfile, "%s\n", opt);
331 }
332}
333
334static void
335write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, const char *values[])
336{
337 int i;
338
339 for (i = 0; i < len; ++i)
340 write_into_file(outfile, opt, (arg ? arg[i] : 0), values);
341}
342
343int
344cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
345{
346 int i = 0;
347
348 if (!outfile)
349 {
350 fprintf (stderrstderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE"shishi");
351 return EXIT_FAILURE1;
352 }
353
354 if (args_info->help_given)
355 write_into_file(outfile, "help", 0, 0 );
356 if (args_info->version_given)
357 write_into_file(outfile, "version", 0, 0 );
358 if (args_info->destroy_given)
359 write_into_file(outfile, "destroy", 0, 0 );
360 if (args_info->list_given)
361 write_into_file(outfile, "list", 0, 0 );
362 if (args_info->renew_given)
363 write_into_file(outfile, "renew", 0, 0 );
364 if (args_info->forwardable_given)
365 write_into_file(outfile, "forwardable", 0, 0 );
366 if (args_info->forwarded_given)
367 write_into_file(outfile, "forwarded", 0, 0 );
368 if (args_info->proxiable_given)
369 write_into_file(outfile, "proxiable", 0, 0 );
370 if (args_info->proxy_given)
371 write_into_file(outfile, "proxy", 0, 0 );
372 if (args_info->renewable_given)
373 write_into_file(outfile, "renewable", 0, 0 );
374 if (args_info->client_name_given)
375 write_into_file(outfile, "client-name", args_info->client_name_orig, 0);
376 if (args_info->encryption_type_given)
377 write_into_file(outfile, "encryption-type", args_info->encryption_type_orig, 0);
378 if (args_info->endtime_given)
379 write_into_file(outfile, "endtime", args_info->endtime_orig, 0);
380 if (args_info->realm_given)
381 write_into_file(outfile, "realm", args_info->realm_orig, 0);
382 if (args_info->renew_till_given)
383 write_into_file(outfile, "renew-till", args_info->renew_till_orig, 0);
384 if (args_info->server_name_given)
385 write_into_file(outfile, "server-name", args_info->server_name_orig, 0);
386 if (args_info->starttime_given)
387 write_into_file(outfile, "starttime", args_info->starttime_orig, 0);
388 if (args_info->ticket_granter_given)
389 write_into_file(outfile, "ticket-granter", args_info->ticket_granter_orig, 0);
390 if (args_info->configuration_file_given)
391 write_into_file(outfile, "configuration-file", args_info->configuration_file_orig, 0);
392 if (args_info->ticket_file_given)
393 write_into_file(outfile, "ticket-file", args_info->ticket_file_orig, 0);
394 if (args_info->library_options_given)
395 write_into_file(outfile, "library-options", args_info->library_options_orig, 0);
396 if (args_info->quiet_given)
397 write_into_file(outfile, "quiet", 0, 0 );
398 if (args_info->system_configuration_file_given)
399 write_into_file(outfile, "system-configuration-file", args_info->system_configuration_file_orig, 0);
400 if (args_info->ticket_write_file_given)
401 write_into_file(outfile, "ticket-write-file", args_info->ticket_write_file_orig, 0);
402 write_multiple_into_file(outfile, args_info->verbose_given, "verbose", 0, 0);
403
404
405 i = EXIT_SUCCESS0;
406 return i;
407}
408
409int
410cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
411{
412 FILE *outfile;
413 int i = 0;
414
415 outfile = fopen(filename, "w");
416
417 if (!outfile)
418 {
419 fprintf (stderrstderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE"shishi", filename);
420 return EXIT_FAILURE1;
421 }
422
423 i = cmdline_parser_dump(outfile, args_info);
424 fclose (outfile);
425
426 return i;
427}
428
429void
430cmdline_parser_free (struct gengetopt_args_info *args_info)
431{
432 cmdline_parser_release (args_info);
433}
434
435/** @brief replacement of strdup, which is not standard */
436char *
437gengetopt_strdup (const char *s)
438{
439 char *result = 0;
440 if (!s)
441 return result;
442
443 result = (char*)malloc(strlen(s) + 1);
444 if (result == (char*)0)
445 return (char*)0;
446 strcpy(result, s);
447 return result;
448}
449
450static int
451check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc);
452
453int
454check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc)
455{
456 int error_occurred = 0;
457
458 if (option_given && (min > 0 || max > 0))
459 {
460 if (min > 0 && max > 0)
461 {
462 if (min == max)
463 {
464 /* specific occurrences */
465 if (option_given != (unsigned int) min)
466 {
467 fprintf (stderrstderr, "%s: %s option occurrences must be %d\n",
468 prog_name, option_desc, min);
469 error_occurred = 1;
470 }
471 }
472 else if (option_given < (unsigned int) min
473 || option_given > (unsigned int) max)
474 {
475 /* range occurrences */
476 fprintf (stderrstderr, "%s: %s option occurrences must be between %d and %d\n",
477 prog_name, option_desc, min, max);
478 error_occurred = 1;
479 }
480 }
481 else if (min > 0)
482 {
483 /* at least check */
484 if (option_given < min)
485 {
486 fprintf (stderrstderr, "%s: %s option occurrences must be at least %d\n",
487 prog_name, option_desc, min);
488 error_occurred = 1;
489 }
490 }
491 else if (max > 0)
492 {
493 /* at most check */
494 if (option_given > max)
495 {
496 fprintf (stderrstderr, "%s: %s option occurrences must be at most %d\n",
497 prog_name, option_desc, max);
498 error_occurred = 1;
499 }
500 }
501 }
502
503 return error_occurred;
504}
505int
506cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
507{
508 return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
509}
510
511int
512cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
513 struct cmdline_parser_params *params)
514{
515 int result;
516 result = cmdline_parser_internal (argc, argv, args_info, params, 0);
517
518 return result;
519}
520
521int
522cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
523{
524 int result;
525 struct cmdline_parser_params params;
526
527 params.override = override;
528 params.initialize = initialize;
529 params.check_required = check_required;
530 params.check_ambiguity = 0;
531 params.print_errors = 1;
532
533 result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
534
535 return result;
536}
537
538int
539cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
540{
541 int result = EXIT_SUCCESS0;
542
543 if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
544 result = EXIT_FAILURE1;
545
546 return result;
547}
548
549int
550cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)
551{
552 int error_occurred = 0;
553 FIX_UNUSED (additional_error)(void) (additional_error);
554
555 /* checks for required options */
556 if (check_multiple_option_occurrences(prog_name, args_info->verbose_given, args_info->verbose_min, args_info->verbose_max, "'--verbose' ('-v')"))
557 error_occurred = 1;
558
559
560 /* checks for dependences among options */
561
562 return error_occurred;
563}
564
565
566static char *package_name = 0;
567
568/**
569 * @brief updates an option
570 * @param field the generic pointer to the field to update
571 * @param orig_field the pointer to the orig field
572 * @param field_given the pointer to the number of occurrence of this option
573 * @param prev_given the pointer to the number of occurrence already seen
574 * @param value the argument for this option (if null no arg was specified)
575 * @param possible_values the possible values for this option (if specified)
576 * @param default_value the default value (in case the option only accepts fixed values)
577 * @param arg_type the type of this option
578 * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
579 * @param override @see cmdline_parser_params.override
580 * @param no_free whether to free a possible previous value
581 * @param multiple_option whether this is a multiple option
582 * @param long_opt the corresponding long option
583 * @param short_opt the corresponding short option (or '-' if none)
584 * @param additional_error possible further error specification
585 */
586static
587int update_arg(void *field, char **orig_field,
588 unsigned int *field_given, unsigned int *prev_given,
589 char *value, const char *possible_values[],
590 const char *default_value,
591 cmdline_parser_arg_type arg_type,
592 int check_ambiguity, int override,
593 int no_free, int multiple_option,
594 const char *long_opt, char short_opt,
595 const char *additional_error)
596{
597 char *stop_char = 0;
598 const char *val = value;
599 int found;
600 char **string_field;
601 FIX_UNUSED (field)(void) (field);
602
603 stop_char = 0;
604 found = 0;
605
606 if (!multiple_option
8.1
'multiple_option' is 0
&& prev_given
8.2
'prev_given' is non-null
&& (*prev_given || (check_ambiguity && *field_given)))
9
Assuming 'check_ambiguity' is 0
607 {
608 if (short_opt != '-')
609 fprintf (stderrstderr, "%s: `--%s' (`-%c') option given more than once%s\n",
610 package_name, long_opt, short_opt,
611 (additional_error ? additional_error : ""));
612 else
613 fprintf (stderrstderr, "%s: `--%s' option given more than once%s\n",
614 package_name, long_opt,
615 (additional_error ? additional_error : ""));
616 return 1; /* failure */
617 }
618
619 FIX_UNUSED (default_value)(void) (default_value);
620
621 if (field_given && *field_given && ! override)
10
Assuming 'field_given' is null
622 return 0;
623 if (prev_given
10.1
'prev_given' is non-null
)
11
Taking true branch
624 (*prev_given)++;
625 if (field_given
11.1
'field_given' is null
)
12
Taking false branch
626 (*field_given)++;
627 if (possible_values
12.1
'possible_values' is null
)
13
Taking false branch
628 val = possible_values[found];
629
630 switch(arg_type) {
14
Control jumps to 'case ARG_FLAG:' at line 631
631 case ARG_FLAG:
632 *((int *)field) = !*((int *)field);
15
Dereference of null pointer
633 break;
634 case ARG_STRING:
635 if (val) {
636 string_field = (char **)field;
637 if (!no_free && *string_field)
638 free (*string_field); /* free previous string */
639 *string_field = gengetopt_strdup (val);
640 }
641 break;
642 default:
643 break;
644 };
645
646 FIX_UNUSED(stop_char)(void) (stop_char);
647
648 /* store the original value */
649 switch(arg_type) {
650 case ARG_NO:
651 case ARG_FLAG:
652 break;
653 default:
654 if (value && orig_field) {
655 if (no_free) {
656 *orig_field = value;
657 } else {
658 if (*orig_field)
659 free (*orig_field); /* free previous string */
660 *orig_field = gengetopt_strdup (value);
661 }
662 }
663 };
664
665 return 0; /* OK */
666}
667
668
669int
670cmdline_parser_internal (
671 int argc, char **argv, struct gengetopt_args_info *args_info,
672 struct cmdline_parser_params *params, const char *additional_error)
673{
674 int c; /* Character of the parsed option. */
675
676 int error_occurred = 0;
677 struct gengetopt_args_info local_args_info;
678
679 int override;
680 int initialize;
681 int check_required;
682 int check_ambiguity;
683
684 package_name = argv[0];
685
686 /* TODO: Why is this here? It is not used anywhere. */
687 override = params->override;
688 FIX_UNUSED(override)(void) (override);
689
690 initialize = params->initialize;
691 check_required = params->check_required;
692
693 /* TODO: Why is this here? It is not used anywhere. */
694 check_ambiguity = params->check_ambiguity;
695 FIX_UNUSED(check_ambiguity)(void) (check_ambiguity);
696
697 if (initialize)
1
Assuming 'initialize' is 0
2
Taking false branch
698 cmdline_parser_init (args_info);
699
700 cmdline_parser_init (&local_args_info);
701
702 optarg = 0;
703 optind = 0;
704 opterr = params->print_errors;
705 optopt = '?';
706
707 while (1)
3
Loop condition is true. Entering loop body
708 {
709 int option_index = 0;
710
711 static struct option long_options[] = {
712 { "help", 0, NULL((void*)0), 'h' },
713 { "version", 0, NULL((void*)0), 'V' },
714 { "destroy", 0, NULL((void*)0), 'd' },
715 { "list", 0, NULL((void*)0), 'l' },
716 { "renew", 0, NULL((void*)0), 'r' },
717 { "forwardable", 0, NULL((void*)0), 0 },
718 { "forwarded", 0, NULL((void*)0), 0 },
719 { "proxiable", 0, NULL((void*)0), 0 },
720 { "proxy", 0, NULL((void*)0), 0 },
721 { "renewable", 0, NULL((void*)0), 0 },
722 { "client-name", 1, NULL((void*)0), 0 },
723 { "encryption-type", 1, NULL((void*)0), 'E' },
724 { "endtime", 1, NULL((void*)0), 'e' },
725 { "realm", 1, NULL((void*)0), 0 },
726 { "renew-till", 1, NULL((void*)0), 0 },
727 { "server-name", 1, NULL((void*)0), 0 },
728 { "starttime", 1, NULL((void*)0), 's' },
729 { "ticket-granter", 1, NULL((void*)0), 0 },
730 { "configuration-file", 1, NULL((void*)0), 0 },
731 { "ticket-file", 1, NULL((void*)0), 'c' },
732 { "library-options", 1, NULL((void*)0), 'o' },
733 { "quiet", 0, NULL((void*)0), 'q' },
734 { "system-configuration-file", 1, NULL((void*)0), 0 },
735 { "ticket-write-file", 1, NULL((void*)0), 0 },
736 { "verbose", 0, NULL((void*)0), 'v' },
737 { 0, 0, 0, 0 }
738 };
739
740 c = getopt_long (argc, argv, "hVdlrE:e:s:c:o:qv", long_options, &option_index);
741
742 if (c == -1) break; /* Exit from `while (1)' loop. */
4
Assuming the condition is false
5
Taking false branch
743
744 switch (c)
6
Control jumps to 'case 113:' at line 864
745 {
746 case 'h': /* Print help and exit. */
747
748
749 if (update_arg( 0 ,
750 0 , &(args_info->help_given),
751 &(local_args_info.help_given), optarg, 0, 0, ARG_NO,
752 check_ambiguity, override, 0, 0,
753 "help", 'h',
754 additional_error))
755 goto failure;
756 cmdline_parser_free (&local_args_info);
757 return 0;
758
759 break;
760 case 'V': /* Print version and exit. */
761
762
763 if (update_arg( 0 ,
764 0 , &(args_info->version_given),
765 &(local_args_info.version_given), optarg, 0, 0, ARG_NO,
766 check_ambiguity, override, 0, 0,
767 "version", 'V',
768 additional_error))
769 goto failure;
770 cmdline_parser_free (&local_args_info);
771 return 0;
772
773 break;
774 case 'd': /* Destroy tickets in local cache, limited by any --client-name or --server-name.. */
775
776
777 if (update_arg((void *)&(args_info->destroy_flag), 0, &(args_info->destroy_given),
778 &(local_args_info.destroy_given), optarg, 0, 0, ARG_FLAG,
779 check_ambiguity, override, 1, 0, "destroy", 'd',
780 additional_error))
781 goto failure;
782
783 break;
784 case 'l': /* List tickets in local cache, limited by any --client-name and --server-name.. */
785
786
787 if (update_arg((void *)&(args_info->list_flag), 0, &(args_info->list_given),
788 &(local_args_info.list_given), optarg, 0, 0, ARG_FLAG,
789 check_ambiguity, override, 1, 0, "list", 'l',
790 additional_error))
791 goto failure;
792
793 break;
794 case 'r': /* Renew ticket. Use --server-name to specify ticket, default is the most recent renewable ticket granting ticket for the default realm.. */
795
796
797 if (update_arg((void *)&(args_info->renew_flag), 0, &(args_info->renew_given),
798 &(local_args_info.renew_given), optarg, 0, 0, ARG_FLAG,
799 check_ambiguity, override, 1, 0, "renew", 'r',
800 additional_error))
801 goto failure;
802
803 break;
804 case 'E': /* Encryption types to use. ETYPE is either registered name or integer. Valid values include 'aes128', 'aes256', 'aes' (same as 'aes256'), '3des', 'des-md5', 'des-md4', 'des-crc', 'des' (same as 'des-md5'), and 'arcfour'.. */
805
806
807 if (update_arg( (void *)&(args_info->encryption_type_arg),
808 &(args_info->encryption_type_orig), &(args_info->encryption_type_given),
809 &(local_args_info.encryption_type_given), optarg, 0, 0, ARG_STRING,
810 check_ambiguity, override, 0, 0,
811 "encryption-type", 'E',
812 additional_error))
813 goto failure;
814
815 break;
816 case 'e': /* Specify when ticket validity should expire. The time syntax may be relative (to the start time), such as '20 hours', or absolute, such as '2001-02-03 04:05:06 CET'. The default is 8 hours after the start time.. */
817
818
819 if (update_arg( (void *)&(args_info->endtime_arg),
820 &(args_info->endtime_orig), &(args_info->endtime_given),
821 &(local_args_info.endtime_given), optarg, 0, 0, ARG_STRING,
822 check_ambiguity, override, 0, 0,
823 "endtime", 'e',
824 additional_error))
825 goto failure;
826
827 break;
828 case 's': /* Specify when ticket should start to be valid. Accepts same time syntax as --endtime. The default is to become valid immediately.. */
829
830
831 if (update_arg( (void *)&(args_info->starttime_arg),
832 &(args_info->starttime_orig), &(args_info->starttime_given),
833 &(local_args_info.starttime_given), optarg, 0, 0, ARG_STRING,
834 check_ambiguity, override, 0, 0,
835 "starttime", 's',
836 additional_error))
837 goto failure;
838
839 break;
840 case 'c': /* Read tickets from FILE.. */
841
842
843 if (update_arg( (void *)&(args_info->ticket_file_arg),
844 &(args_info->ticket_file_orig), &(args_info->ticket_file_given),
845 &(local_args_info.ticket_file_given), optarg, 0, 0, ARG_STRING,
846 check_ambiguity, override, 0, 0,
847 "ticket-file", 'c',
848 additional_error))
849 goto failure;
850
851 break;
852 case 'o': /* Parse STRING as a configuration file statement.. */
853
854
855 if (update_arg( (void *)&(args_info->library_options_arg),
856 &(args_info->library_options_orig), &(args_info->library_options_given),
857 &(local_args_info.library_options_given), optarg, 0, 0, ARG_STRING,
858 check_ambiguity, override, 0, 0,
859 "library-options", 'o',
860 additional_error))
861 goto failure;
862
863 break;
864 case 'q': /* Don't produce any diagnostic output.
865. */
866
867
868 if (update_arg((void *)&(args_info->quiet_flag), 0, &(args_info->quiet_given),
7
Passing value via 1st parameter 'field'
8
Calling 'update_arg'
869 &(local_args_info.quiet_given), optarg, 0, 0, ARG_FLAG,
870 check_ambiguity, override, 1, 0, "quiet", 'q',
871 additional_error))
872 goto failure;
873
874 break;
875 case 'v': /* Produce verbose output.
876 Use multiple times to increase amount of information.. */
877
878 local_args_info.verbose_given++;
879
880 break;
881
882 case 0: /* Long option with no short option */
883 /* Get a forwardable ticket, i.e., one that can be used to get forwarded tickets.. */
884 if (strcmp (long_options[option_index].name, "forwardable") == 0)
885 {
886
887
888 if (update_arg((void *)&(args_info->forwardable_flag), 0, &(args_info->forwardable_given),
889 &(local_args_info.forwardable_given), optarg, 0, 0, ARG_FLAG,
890 check_ambiguity, override, 1, 0, "forwardable", '-',
891 additional_error))
892 goto failure;
893
894 }
895 /* Get a forwarded ticket.. */
896 else if (strcmp (long_options[option_index].name, "forwarded") == 0)
897 {
898
899
900 if (update_arg((void *)&(args_info->forwarded_flag), 0, &(args_info->forwarded_given),
901 &(local_args_info.forwarded_given), optarg, 0, 0, ARG_FLAG,
902 check_ambiguity, override, 1, 0, "forwarded", '-',
903 additional_error))
904 goto failure;
905
906 }
907 /* Get a proxiable ticket, i.e., one that can be used to get proxy tickets.. */
908 else if (strcmp (long_options[option_index].name, "proxiable") == 0)
909 {
910
911
912 if (update_arg((void *)&(args_info->proxiable_flag), 0, &(args_info->proxiable_given),
913 &(local_args_info.proxiable_given), optarg, 0, 0, ARG_FLAG,
914 check_ambiguity, override, 1, 0, "proxiable", '-',
915 additional_error))
916 goto failure;
917
918 }
919 /* Get a proxy ticket.. */
920 else if (strcmp (long_options[option_index].name, "proxy") == 0)
921 {
922
923
924 if (update_arg((void *)&(args_info->proxy_flag), 0, &(args_info->proxy_given),
925 &(local_args_info.proxy_given), optarg, 0, 0, ARG_FLAG,
926 check_ambiguity, override, 1, 0, "proxy", '-',
927 additional_error))
928 goto failure;
929
930 }
931 /* Get a renewable ticket.. */
932 else if (strcmp (long_options[option_index].name, "renewable") == 0)
933 {
934
935
936 if (update_arg((void *)&(args_info->renewable_flag), 0, &(args_info->renewable_given),
937 &(local_args_info.renewable_given), optarg, 0, 0, ARG_FLAG,
938 check_ambiguity, override, 1, 0, "renewable", '-',
939 additional_error))
940 goto failure;
941
942 }
943 /* Client name. Default is login username.. */
944 else if (strcmp (long_options[option_index].name, "client-name") == 0)
945 {
946
947
948 if (update_arg( (void *)&(args_info->client_name_arg),
949 &(args_info->client_name_orig), &(args_info->client_name_given),
950 &(local_args_info.client_name_given), optarg, 0, 0, ARG_STRING,
951 check_ambiguity, override, 0, 0,
952 "client-name", '-',
953 additional_error))
954 goto failure;
955
956 }
957 /* Set default realm.. */
958 else if (strcmp (long_options[option_index].name, "realm") == 0)
959 {
960
961
962 if (update_arg( (void *)&(args_info->realm_arg),
963 &(args_info->realm_orig), &(args_info->realm_given),
964 &(local_args_info.realm_given), optarg, 0, 0, ARG_STRING,
965 check_ambiguity, override, 0, 0,
966 "realm", '-',
967 additional_error))
968 goto failure;
969
970 }
971 /* Specify renewable life of ticket. Implies --renewable. Accepts same time syntax as --endtime. If --renewable is specified, the default is 1 week after the start time.. */
972 else if (strcmp (long_options[option_index].name, "renew-till") == 0)
973 {
974
975
976 if (update_arg( (void *)&(args_info->renew_till_arg),
977 &(args_info->renew_till_orig), &(args_info->renew_till_given),
978 &(local_args_info.renew_till_given), optarg, 0, 0, ARG_STRING,
979 check_ambiguity, override, 0, 0,
980 "renew-till", '-',
981 additional_error))
982 goto failure;
983
984 }
985 /* Server name. Default is 'krbtgt/REALM' where REALM is client realm.. */
986 else if (strcmp (long_options[option_index].name, "server-name") == 0)
987 {
988
989
990 if (update_arg( (void *)&(args_info->server_name_arg),
991 &(args_info->server_name_orig), &(args_info->server_name_given),
992 &(local_args_info.server_name_given), optarg, 0, 0, ARG_STRING,
993 check_ambiguity, override, 0, 0,
994 "server-name", '-',
995 additional_error))
996 goto failure;
997
998 }
999 /* Service name in ticket to use for authenticating request. Only for TGS. Defaults to 'krbtgt/REALM@REALM' where REALM is client realm.. */
1000 else if (strcmp (long_options[option_index].name, "ticket-granter") == 0)
1001 {
1002
1003
1004 if (update_arg( (void *)&(args_info->ticket_granter_arg),
1005 &(args_info->ticket_granter_orig), &(args_info->ticket_granter_given),
1006 &(local_args_info.ticket_granter_given), optarg, 0, 0, ARG_STRING,
1007 check_ambiguity, override, 0, 0,
1008 "ticket-granter", '-',
1009 additional_error))
1010 goto failure;
1011
1012 }
1013 /* Read user configuration from FILE.. */
1014 else if (strcmp (long_options[option_index].name, "configuration-file") == 0)
1015 {
1016
1017
1018 if (update_arg( (void *)&(args_info->configuration_file_arg),
1019 &(args_info->configuration_file_orig), &(args_info->configuration_file_given),
1020 &(local_args_info.configuration_file_given), optarg, 0, 0, ARG_STRING,
1021 check_ambiguity, override, 0, 0,
1022 "configuration-file", '-',
1023 additional_error))
1024 goto failure;
1025
1026 }
1027 /* Read system configuration from FILE.. */
1028 else if (strcmp (long_options[option_index].name, "system-configuration-file") == 0)
1029 {
1030
1031
1032 if (update_arg( (void *)&(args_info->system_configuration_file_arg),
1033 &(args_info->system_configuration_file_orig), &(args_info->system_configuration_file_given),
1034 &(local_args_info.system_configuration_file_given), optarg, 0, 0, ARG_STRING,
1035 check_ambiguity, override, 0, 0,
1036 "system-configuration-file", '-',
1037 additional_error))
1038 goto failure;
1039
1040 }
1041 /* Write tickets from FILE. Default is to write them back to where they were read from.. */
1042 else if (strcmp (long_options[option_index].name, "ticket-write-file") == 0)
1043 {
1044
1045
1046 if (update_arg( (void *)&(args_info->ticket_write_file_arg),
1047 &(args_info->ticket_write_file_orig), &(args_info->ticket_write_file_given),
1048 &(local_args_info.ticket_write_file_given), optarg, 0, 0, ARG_STRING,
1049 check_ambiguity, override, 0, 0,
1050 "ticket-write-file", '-',
1051 additional_error))
1052 goto failure;
1053
1054 }
1055
1056 break;
1057 case '?': /* Invalid option. */
1058 /* `getopt_long' already printed an error message. */
1059 goto failure;
1060
1061 default: /* bug: option not considered. */
1062 fprintf (stderrstderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE"shishi", c, (additional_error ? additional_error : ""));
1063 abort ();
1064 } /* switch */
1065 } /* while */
1066
1067
1068
1069 args_info->verbose_given += local_args_info.verbose_given;
1070 local_args_info.verbose_given = 0;
1071
1072 if (check_required)
1073 {
1074 error_occurred += cmdline_parser_required2 (args_info, argv[0], additional_error);
1075 }
1076
1077 cmdline_parser_release (&local_args_info);
1078
1079 if ( error_occurred )
1080 return (EXIT_FAILURE1);
1081
1082 if (optind < argc)
1083 {
1084 int i = 0 ;
1085 int found_prog_name = 0;
1086 /* whether program name, i.e., argv[0], is in the remaining args
1087 (this may happen with some implementations of getopt,
1088 but surely not with the one included by gengetopt) */
1089
1090 i = optind;
1091 while (i < argc)
1092 if (argv[i++] == argv[0]) {
1093 found_prog_name = 1;
1094 break;
1095 }
1096 i = 0;
1097
1098 args_info->inputs_num = argc - optind - found_prog_name;
1099 args_info->inputs =
1100 (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
1101 while (optind < argc)
1102 if (argv[optind++] != argv[0])
1103 args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;
1104 }
1105
1106 return 0;
1107
1108failure:
1109
1110 cmdline_parser_release (&local_args_info);
1111 return (EXIT_FAILURE1);
1112}
1113/* vim: set ft=c noet ts=8 sts=8 sw=8 tw=80 nojs spell : */