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 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | #ifdef HAVE_CONFIG_H |
13 | #include "config.h" |
14 | #endif |
15 | |
16 | #include <stdio.h> |
17 | #include <stdlib.h> |
18 | #include <string.h> |
19 | |
20 | #ifndef FIX_UNUSED |
21 | #define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ |
22 | #endif |
23 | |
24 | #include <getopt.h> |
25 | |
26 | #include "shishi_cmd.h" |
27 | |
28 | const 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 | |
30 | const char *gengetopt_args_info_usage = "Usage: shishi [OPTION]... [CLIENT [SERVER]]..."; |
31 | |
32 | const char *gengetopt_args_info_versiontext = ""; |
33 | |
34 | const char *gengetopt_args_info_description = ""; |
35 | |
36 | const 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 | |
69 | typedef enum {ARG_NO |
70 | , ARG_FLAG |
71 | , ARG_STRING |
72 | } cmdline_parser_arg_type; |
73 | |
74 | static |
75 | void clear_given (struct gengetopt_args_info *args_info); |
76 | static |
77 | void clear_args (struct gengetopt_args_info *args_info); |
78 | |
79 | static int |
80 | cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info, |
81 | struct cmdline_parser_params *params, const char *additional_error); |
82 | |
83 | static int |
84 | cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error); |
85 | |
86 | static char * |
87 | gengetopt_strdup (const char *s); |
88 | |
89 | static |
90 | void 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 | |
119 | static |
120 | void clear_args (struct gengetopt_args_info *args_info) |
121 | { |
122 | FIX_UNUSED (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; |
132 | args_info->client_name_orig = NULL; |
133 | args_info->encryption_type_arg = NULL; |
134 | args_info->encryption_type_orig = NULL; |
135 | args_info->endtime_arg = NULL; |
136 | args_info->endtime_orig = NULL; |
137 | args_info->realm_arg = NULL; |
138 | args_info->realm_orig = NULL; |
139 | args_info->renew_till_arg = NULL; |
140 | args_info->renew_till_orig = NULL; |
141 | args_info->server_name_arg = NULL; |
142 | args_info->server_name_orig = NULL; |
143 | args_info->starttime_arg = NULL; |
144 | args_info->starttime_orig = NULL; |
145 | args_info->ticket_granter_arg = NULL; |
146 | args_info->ticket_granter_orig = NULL; |
147 | args_info->configuration_file_arg = NULL; |
148 | args_info->configuration_file_orig = NULL; |
149 | args_info->ticket_file_arg = NULL; |
150 | args_info->ticket_file_orig = NULL; |
151 | args_info->library_options_arg = NULL; |
152 | args_info->library_options_orig = NULL; |
153 | args_info->quiet_flag = 0; |
154 | args_info->system_configuration_file_arg = NULL; |
155 | args_info->system_configuration_file_orig = NULL; |
156 | args_info->ticket_write_file_arg = NULL; |
157 | args_info->ticket_write_file_orig = NULL; |
158 | |
159 | } |
160 | |
161 | static |
162 | void 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 | |
196 | void |
197 | cmdline_parser_print_version (void) |
198 | { |
199 | printf ("%s %s\n", |
200 | (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE), |
201 | CMDLINE_PARSER_VERSION); |
202 | |
203 | if (strlen(gengetopt_args_info_versiontext) > 0) |
204 | printf("\n%s\n", gengetopt_args_info_versiontext); |
205 | } |
206 | |
207 | static 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 | |
228 | void |
229 | cmdline_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 | |
237 | void |
238 | cmdline_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 | |
248 | void |
249 | cmdline_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 | |
261 | struct cmdline_parser_params * |
262 | cmdline_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 | |
270 | static void |
271 | free_string_field (char **s) |
272 | { |
273 | if (*s) |
274 | { |
275 | free (*s); |
276 | *s = 0; |
277 | } |
278 | } |
279 | |
280 | |
281 | static void |
282 | cmdline_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 | |
323 | static void |
324 | write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) |
325 | { |
326 | FIX_UNUSED (values); |
327 | if (arg) { |
328 | fprintf(outfile, "%s=\"%s\"\n", opt, arg); |
329 | } else { |
330 | fprintf(outfile, "%s\n", opt); |
331 | } |
332 | } |
333 | |
334 | static void |
335 | write_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 | |
343 | int |
344 | cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) |
345 | { |
346 | int i = 0; |
347 | |
348 | if (!outfile) |
349 | { |
350 | fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE); |
351 | return EXIT_FAILURE; |
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_SUCCESS; |
406 | return i; |
407 | } |
408 | |
409 | int |
410 | cmdline_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 (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); |
420 | return EXIT_FAILURE; |
421 | } |
422 | |
423 | i = cmdline_parser_dump(outfile, args_info); |
424 | fclose (outfile); |
425 | |
426 | return i; |
427 | } |
428 | |
429 | void |
430 | cmdline_parser_free (struct gengetopt_args_info *args_info) |
431 | { |
432 | cmdline_parser_release (args_info); |
433 | } |
434 | |
435 | |
436 | char * |
437 | gengetopt_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 | |
450 | static int |
451 | check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc); |
452 | |
453 | int |
454 | check_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 | |
465 | if (option_given != (unsigned int) min) |
466 | { |
467 | fprintf (stderr, "%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 | |
476 | fprintf (stderr, "%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 | |
484 | if (option_given < min) |
485 | { |
486 | fprintf (stderr, "%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 | |
494 | if (option_given > max) |
495 | { |
496 | fprintf (stderr, "%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 | } |
505 | int |
506 | cmdline_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 | |
511 | int |
512 | cmdline_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 | |
521 | int |
522 | cmdline_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, ¶ms, 0); |
534 | |
535 | return result; |
536 | } |
537 | |
538 | int |
539 | cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) |
540 | { |
541 | int result = EXIT_SUCCESS; |
542 | |
543 | if (cmdline_parser_required2(args_info, prog_name, 0) > 0) |
544 | result = EXIT_FAILURE; |
545 | |
546 | return result; |
547 | } |
548 | |
549 | int |
550 | cmdline_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); |
554 | |
555 | |
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 | |
561 | |
562 | return error_occurred; |
563 | } |
564 | |
565 | |
566 | static char *package_name = 0; |
567 | |
568 | |
569 | |
570 | |
571 | |
572 | |
573 | |
574 | |
575 | |
576 | |
577 | |
578 | |
579 | |
580 | |
581 | |
582 | |
583 | |
584 | |
585 | |
586 | static |
587 | int 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); |
602 | |
603 | stop_char = 0; |
604 | found = 0; |
605 | |
606 | if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) |
| 9 | | Assuming 'check_ambiguity' is 0 | |
|
607 | { |
608 | if (short_opt != '-') |
609 | fprintf (stderr, "%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 (stderr, "%s: `--%s' option given more than once%s\n", |
614 | package_name, long_opt, |
615 | (additional_error ? additional_error : "")); |
616 | return 1; |
617 | } |
618 | |
619 | FIX_UNUSED (default_value); |
620 | |
621 | if (field_given && *field_given && ! override) |
| 10 | | Assuming 'field_given' is null | |
|
622 | return 0; |
623 | if (prev_given) |
| |
624 | (*prev_given)++; |
625 | if (field_given) |
| |
626 | (*field_given)++; |
627 | if (possible_values) |
| |
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); |
639 | *string_field = gengetopt_strdup (val); |
640 | } |
641 | break; |
642 | default: |
643 | break; |
644 | }; |
645 | |
646 | FIX_UNUSED(stop_char); |
647 | |
648 | |
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); |
660 | *orig_field = gengetopt_strdup (value); |
661 | } |
662 | } |
663 | }; |
664 | |
665 | return 0; |
666 | } |
667 | |
668 | |
669 | int |
670 | cmdline_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; |
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 | |
687 | override = params->override; |
688 | FIX_UNUSED(override); |
689 | |
690 | initialize = params->initialize; |
691 | check_required = params->check_required; |
692 | |
693 | |
694 | check_ambiguity = params->check_ambiguity; |
695 | FIX_UNUSED(check_ambiguity); |
696 | |
697 | if (initialize) |
| 1 | Assuming 'initialize' is 0 | |
|
| |
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, 'h' }, |
713 | { "version", 0, NULL, 'V' }, |
714 | { "destroy", 0, NULL, 'd' }, |
715 | { "list", 0, NULL, 'l' }, |
716 | { "renew", 0, NULL, 'r' }, |
717 | { "forwardable", 0, NULL, 0 }, |
718 | { "forwarded", 0, NULL, 0 }, |
719 | { "proxiable", 0, NULL, 0 }, |
720 | { "proxy", 0, NULL, 0 }, |
721 | { "renewable", 0, NULL, 0 }, |
722 | { "client-name", 1, NULL, 0 }, |
723 | { "encryption-type", 1, NULL, 'E' }, |
724 | { "endtime", 1, NULL, 'e' }, |
725 | { "realm", 1, NULL, 0 }, |
726 | { "renew-till", 1, NULL, 0 }, |
727 | { "server-name", 1, NULL, 0 }, |
728 | { "starttime", 1, NULL, 's' }, |
729 | { "ticket-granter", 1, NULL, 0 }, |
730 | { "configuration-file", 1, NULL, 0 }, |
731 | { "ticket-file", 1, NULL, 'c' }, |
732 | { "library-options", 1, NULL, 'o' }, |
733 | { "quiet", 0, NULL, 'q' }, |
734 | { "system-configuration-file", 1, NULL, 0 }, |
735 | { "ticket-write-file", 1, NULL, 0 }, |
736 | { "verbose", 0, NULL, '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; |
| 4 | | Assuming the condition is false | |
|
| |
743 | |
744 | switch (c) |
| 6 | | Control jumps to 'case 113:' at line 864 | |
|
745 | { |
746 | case 'h': |
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': |
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': |
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': |
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': |
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': |
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': |
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': |
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': |
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': |
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': |
865 | |
866 | |
867 | |
868 | if (update_arg((void *)&(args_info->quiet_flag), 0, &(args_info->quiet_given), |
| 7 | | Passing value via 1st parameter 'field' | |
|
| |
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': |
876 | |
877 | |
878 | local_args_info.verbose_given++; |
879 | |
880 | break; |
881 | |
882 | case 0: |
883 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 '?': |
1058 | |
1059 | goto failure; |
1060 | |
1061 | default: |
1062 | fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); |
1063 | abort (); |
1064 | } |
1065 | } |
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_FAILURE); |
1081 | |
1082 | if (optind < argc) |
1083 | { |
1084 | int i = 0 ; |
1085 | int found_prog_name = 0; |
1086 | |
1087 | |
1088 | |
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 | |
1108 | failure: |
1109 | |
1110 | cmdline_parser_release (&local_args_info); |
1111 | return (EXIT_FAILURE); |
1112 | } |
1113 | |