The test now works.
[gnutls.git] / src / cli-gaa.c
blob46b9c32e2a9cc31a52e1dac2dbdd504e556ba004
1 /* File generated by GAA 1.6.6
2 */
3 #define GAA_NO_WIN32
4 #line 1 "cli.gaa"
7 /* C declarations */
9 #include <common.h>
11 void print_license(void);
12 void cli_version(void);
14 #include <stdio.h>
15 #include <string.h>
16 #include <stdlib.h>
18 #ifndef GAA_NO_WIN32
19 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(WINDOWS)
20 #define GAA_WIN32
21 #endif
22 #endif
24 static void* gaa_malloc( size_t size) {
25 void* ret;
26 ret = malloc(size);
27 if (ret==NULL) {
28 fprintf(stderr, "gaa: could not allocate memory");
29 exit(1);
31 return ret;
34 static void __gaa_helpsingle(char short_name, char *name,
35 char *arg_desc, char *opt_help)
37 int col1, col3, col4, tabsize = 3, curr;
38 int i;
40 col1 = 5; /* Default values */
41 col3 = 30;
42 col4 = 70;
44 curr = 0;
45 for(i = 0; i < col1; i++)
47 printf(" ");
48 curr++;
50 if(short_name)
52 if(name && *name)
54 printf("-%c, ", short_name);
55 curr += 4;
57 else
59 printf("-%c ", short_name);
60 curr += 3;
63 if(name && *name)
65 printf("--%s ", name);
66 curr += 3 + strlen(name);
68 if(arg_desc && *arg_desc)
70 printf("%s ", arg_desc);
71 curr += 1 + strlen(arg_desc);
73 if(curr >= col3)
75 printf("\n");
76 curr = 0;
78 if(opt_help) /* let's print the option's help body */
80 const char *str = opt_help;
81 while(*str)
83 while(curr < col3)
85 printf(" ");
86 curr++;
88 switch(*str)
90 case '\n':
91 printf("\n");
92 curr = 0;
93 break;
94 case '\t':
97 printf(" ");
98 curr++;
100 while((curr - col3) % tabsize != 0 && curr < col4);
101 case ' ':
102 if(*str == ' ')
104 curr++;
105 printf(" ");
107 for(i = 1; str[i] && str[i] != ' ' && str[i] != '\n'
108 && str[i] != '\t'; i++);
109 if(curr + i - 1 >= col4)
110 curr = col4;
111 break;
112 default:
113 printf("%c", *str);
114 curr++;
116 if(curr >= col4)
118 printf("\n");
119 curr = 0;
121 str++;
124 printf("\n");
127 void gaa_help(void)
129 printf("GNU TLS test client\nUsage: gnutls-cli [options] hostname\n\n\n");
130 __gaa_helpsingle('d', "debug", "integer ", "Enable debugging");
131 __gaa_helpsingle('r', "resume", "", "Connect, establish a session. Connect again and resume this session.");
132 __gaa_helpsingle('s', "starttls", "", "Connect, establish a plain session and start TLS when EOF or a SIGALRM is received.");
133 __gaa_helpsingle(0, "crlf", "", "Send CR LF instead of LF.");
134 __gaa_helpsingle(0, "x509fmtder", "", "Use DER format for certificates to read from.");
135 __gaa_helpsingle('f', "fingerprint", "", "Send the openpgp fingerprint, instead of the key.");
136 __gaa_helpsingle(0, "disable-extensions", "", "Disable all the TLS extensions.");
137 __gaa_helpsingle(0, "print-cert", "", "Print the certificate in PEM format.");
138 __gaa_helpsingle(0, "recordsize", "integer ", "The maximum record size to advertize.");
139 __gaa_helpsingle('V', "verbose", "", "More verbose output.");
140 __gaa_helpsingle(0, "ciphers", "cipher1 cipher2... ", "Ciphers to enable.");
141 __gaa_helpsingle(0, "protocols", "protocol1 protocol2... ", "Protocols to enable.");
142 __gaa_helpsingle(0, "comp", "comp1 comp2... ", "Compression methods to enable.");
143 __gaa_helpsingle(0, "macs", "mac1 mac2... ", "MACs to enable.");
144 __gaa_helpsingle(0, "kx", "kx1 kx2... ", "Key exchange methods to enable.");
145 __gaa_helpsingle(0, "ctypes", "certType1 certType2... ", "Certificate types to enable.");
146 __gaa_helpsingle(0, "priority", "PRIORITY STRING ", "Priorities string.");
147 __gaa_helpsingle(0, "x509cafile", "FILE ", "Certificate file to use.");
148 __gaa_helpsingle(0, "x509crlfile", "FILE ", "CRL file to use.");
149 __gaa_helpsingle(0, "pgpkeyfile", "FILE ", "PGP Key file to use.");
150 __gaa_helpsingle(0, "pgpkeyring", "FILE ", "PGP Key ring file to use.");
151 __gaa_helpsingle(0, "pgpcertfile", "FILE ", "PGP Public Key (certificate) file to use.");
152 __gaa_helpsingle(0, "pgpsubkey", "HEX|auto ", "PGP subkey to use.");
153 __gaa_helpsingle(0, "x509keyfile", "FILE ", "X.509 key file to use.");
154 __gaa_helpsingle(0, "x509certfile", "FILE ", "X.509 Certificate file to use.");
155 __gaa_helpsingle(0, "srpusername", "NAME ", "SRP username to use.");
156 __gaa_helpsingle(0, "srppasswd", "PASSWD ", "SRP password to use.");
157 __gaa_helpsingle(0, "pskusername", "NAME ", "PSK username to use.");
158 __gaa_helpsingle(0, "pskkey", "KEY ", "PSK key (in hex) to use.");
159 __gaa_helpsingle(0, "opaque-prf-input", "DATA ", "Use Opaque PRF Input DATA.");
160 __gaa_helpsingle('p', "port", "PORT ", "The port to connect to.");
161 __gaa_helpsingle(0, "insecure", "", "Don't abort program if server certificate can't be validated.");
162 __gaa_helpsingle('l', "list", "", "Print a list of the supported algorithms and modes.");
163 __gaa_helpsingle('h', "help", "", "prints this help");
164 __gaa_helpsingle('v', "version", "", "prints the program's version number");
165 __gaa_helpsingle(0, "copyright", "", "prints the program's license");
167 #line 100 "gaa.skel"
169 /* Copy of C area */
171 #line 104 "gaa.skel"
172 /* GAA HEADER */
173 #ifndef GAA_HEADER_POKY
174 #define GAA_HEADER_POKY
176 typedef struct _gaainfo gaainfo;
178 struct _gaainfo
180 #line 122 "cli.gaa"
181 char *rest_args;
182 #line 113 "cli.gaa"
183 int insecure;
184 #line 110 "cli.gaa"
185 char *port;
186 #line 107 "cli.gaa"
187 char *opaque_prf_input;
188 #line 104 "cli.gaa"
189 char *psk_key;
190 #line 101 "cli.gaa"
191 char *psk_username;
192 #line 98 "cli.gaa"
193 char *srp_passwd;
194 #line 95 "cli.gaa"
195 char *srp_username;
196 #line 92 "cli.gaa"
197 char *x509_certfile;
198 #line 89 "cli.gaa"
199 char *x509_keyfile;
200 #line 86 "cli.gaa"
201 char *pgp_subkey;
202 #line 83 "cli.gaa"
203 char *pgp_certfile;
204 #line 80 "cli.gaa"
205 char *pgp_keyring;
206 #line 77 "cli.gaa"
207 char *pgp_keyfile;
208 #line 74 "cli.gaa"
209 char *x509_crlfile;
210 #line 71 "cli.gaa"
211 char *x509_cafile;
212 #line 68 "cli.gaa"
213 char *priorities;
214 #line 65 "cli.gaa"
215 char **ctype;
216 #line 64 "cli.gaa"
217 int nctype;
218 #line 61 "cli.gaa"
219 char **kx;
220 #line 60 "cli.gaa"
221 int nkx;
222 #line 57 "cli.gaa"
223 char **macs;
224 #line 56 "cli.gaa"
225 int nmacs;
226 #line 53 "cli.gaa"
227 char **comp;
228 #line 52 "cli.gaa"
229 int ncomp;
230 #line 49 "cli.gaa"
231 char **proto;
232 #line 48 "cli.gaa"
233 int nproto;
234 #line 45 "cli.gaa"
235 char **ciphers;
236 #line 44 "cli.gaa"
237 int nciphers;
238 #line 41 "cli.gaa"
239 int verbose;
240 #line 38 "cli.gaa"
241 int record_size;
242 #line 35 "cli.gaa"
243 int print_cert;
244 #line 32 "cli.gaa"
245 int disable_extensions;
246 #line 29 "cli.gaa"
247 int fingerprint;
248 #line 26 "cli.gaa"
249 int fmtder;
250 #line 23 "cli.gaa"
251 int crlf;
252 #line 20 "cli.gaa"
253 int starttls;
254 #line 17 "cli.gaa"
255 int resume;
256 #line 14 "cli.gaa"
257 int debug;
259 #line 114 "gaa.skel"
262 #ifdef __cplusplus
263 extern "C"
265 #endif
267 int gaa(int argc, char *argv[], gaainfo *gaaval);
269 void gaa_help(void);
271 int gaa_file(const char *name, gaainfo *gaaval);
273 #ifdef __cplusplus
275 #endif
278 #endif
280 #line 135 "gaa.skel"
282 /* C declarations */
284 #define GAAERROR(x) \
286 gaa_error = 1; \
287 return x; \
290 static char *gaa_current_option;
291 static int gaa_error = 0;
293 /* Generated by gaa */
295 #include <string.h>
296 #include <stdlib.h>
299 #define GAA_OK -1
301 #define GAA_ERROR_NOMATCH 0
302 #define GAA_ERROR_NOTENOUGH_ARGS 1
303 #define GAA_ERROR_INVALID_ARG 2
304 #define GAA_ERROR_UNKNOWN 3
306 #define GAA_NOT_AN_OPTION 0
307 #define GAA_WORD_OPTION 1
308 #define GAA_LETTER_OPTION 2
309 #define GAA_MULTIPLE_OPTION 3
311 #define GAA_REST 0
312 #define GAA_NB_OPTION 36
313 #define GAAOPTID_copyright 1
314 #define GAAOPTID_version 2
315 #define GAAOPTID_help 3
316 #define GAAOPTID_list 4
317 #define GAAOPTID_insecure 5
318 #define GAAOPTID_port 6
319 #define GAAOPTID_opaque_prf_input 7
320 #define GAAOPTID_pskkey 8
321 #define GAAOPTID_pskusername 9
322 #define GAAOPTID_srppasswd 10
323 #define GAAOPTID_srpusername 11
324 #define GAAOPTID_x509certfile 12
325 #define GAAOPTID_x509keyfile 13
326 #define GAAOPTID_pgpsubkey 14
327 #define GAAOPTID_pgpcertfile 15
328 #define GAAOPTID_pgpkeyring 16
329 #define GAAOPTID_pgpkeyfile 17
330 #define GAAOPTID_x509crlfile 18
331 #define GAAOPTID_x509cafile 19
332 #define GAAOPTID_priority 20
333 #define GAAOPTID_ctypes 21
334 #define GAAOPTID_kx 22
335 #define GAAOPTID_macs 23
336 #define GAAOPTID_comp 24
337 #define GAAOPTID_protocols 25
338 #define GAAOPTID_ciphers 26
339 #define GAAOPTID_verbose 27
340 #define GAAOPTID_recordsize 28
341 #define GAAOPTID_print_cert 29
342 #define GAAOPTID_disable_extensions 30
343 #define GAAOPTID_fingerprint 31
344 #define GAAOPTID_x509fmtder 32
345 #define GAAOPTID_crlf 33
346 #define GAAOPTID_starttls 34
347 #define GAAOPTID_resume 35
348 #define GAAOPTID_debug 36
350 #line 168 "gaa.skel"
352 #define GAA_CHECK1STR(a,b) \
353 if(a[0] == str[0]) \
355 gaa_current_option = a; \
356 return b; \
359 #define GAA_CHECKSTR(a,b) \
360 if(strcmp(a,str) == 0) \
362 gaa_current_option = a; \
363 return b; \
366 #define GAA_TESTMOREARGS \
367 if(!OK) \
369 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
370 gaa_index++; \
371 if(gaa_last_non_option == gaa_index) \
372 return GAA_ERROR_NOTENOUGH_ARGS; \
375 #define GAA_TESTMOREOPTIONALARGS \
376 if(!OK) \
378 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
379 gaa_index++; \
380 if(gaa_last_non_option == gaa_index) \
381 OK = 1; \
384 #define GAA_FILL_2ARGS(target, func) \
385 target = func(GAAargv[gaa_index]); \
386 gaa_arg_used[gaa_index] = 1; \
387 if(gaa_error == 1) \
389 gaa_error = 0; \
390 return GAA_ERROR_INVALID_ARG; \
395 #define GAA_FILL(target, func, num) \
396 if(!OK) \
398 target = func(GAAargv[gaa_index]); \
399 gaa_arg_used[gaa_index] = 1; \
400 if(gaa_error == 1) \
402 gaa_error = 0; \
403 return GAA_ERROR_INVALID_ARG; \
405 num = 1; \
407 else \
409 num = 0; \
412 #define GAA_LIST_FILL(target, func, type ,num) \
413 if(!OK) \
415 num = 0; \
416 target = NULL; \
417 if ( gaa_last_non_option - gaa_index > 0) \
418 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
419 for(; gaa_index < gaa_last_non_option; gaa_index++) \
421 if(gaa_arg_used[gaa_index] == 0) \
423 GAA_FILL_2ARGS(target[num], func); \
424 num++; \
427 if(num == 0) \
428 return GAA_ERROR_NOTENOUGH_ARGS; \
431 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
432 if(!OK) \
434 num = 0; \
435 target = NULL; \
436 if ( gaa_last_non_option - gaa_index > 0) \
437 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
438 for(; gaa_index < gaa_last_non_option; gaa_index++) \
440 if(gaa_arg_used[gaa_index] == 0) \
442 GAA_FILL_2ARGS(target[num], func); \
443 num++; \
448 #define GAA_OBLIGAT(str) \
449 k = 0; \
450 for(i = 0; i < strlen(str); i++) \
452 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
453 if(j == GAA_ERROR_NOMATCH) \
455 printf("Error: invalid 'obligat' set\n"); \
456 exit(-1); \
458 if(opt_list[j] == 1) \
459 k = 1; \
461 if(k == 0) \
463 if(strlen(str) == 1) \
464 printf("You must give the -%s option\n", str); \
465 else \
466 printf("You must give at least one option of '%s'\n", str); \
467 return 0; \
470 #define GAA_INCOMP(str) \
471 k = 0; \
472 for(i = 0; i < strlen(str); i++) \
474 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
475 if(j == GAA_ERROR_NOMATCH) \
477 printf("Error: invalid 'obligat' set\n"); \
478 exit(-1); \
480 if(opt_list[j] == 1) \
481 k++; \
483 if(k > 1) \
485 printf("The options '%s' are incompatible\n", str); \
486 return 0; \
490 static char **GAAargv;
491 static int GAAargc;
492 static char *gaa_arg_used;
493 static int gaa_processing_file = 0;
494 static int inited = 0;
496 static int gaa_getint(char *arg)
498 int tmp;
499 char a;
500 if(sscanf(arg, "%d%c", &tmp, &a) < 1)
502 printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
503 GAAERROR(-1);
505 return tmp;
508 static char gaa_getchar(char *arg)
510 if(strlen(arg) != 1)
512 printf("Option %s: '%s' isn't an character\n", gaa_current_option, arg);
513 GAAERROR(-1);
515 return arg[0];
518 static char* gaa_getstr(char *arg)
520 return arg;
522 static float gaa_getfloat(char *arg)
524 float tmp;
525 char a;
526 if(sscanf(arg, "%f%c", &tmp, &a) < 1)
528 printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg);
529 GAAERROR(-1);
531 return tmp;
533 /* option structures */
535 struct GAAOPTION_port
537 char* arg1;
538 int size1;
541 struct GAAOPTION_opaque_prf_input
543 char* arg1;
544 int size1;
547 struct GAAOPTION_pskkey
549 char* arg1;
550 int size1;
553 struct GAAOPTION_pskusername
555 char* arg1;
556 int size1;
559 struct GAAOPTION_srppasswd
561 char* arg1;
562 int size1;
565 struct GAAOPTION_srpusername
567 char* arg1;
568 int size1;
571 struct GAAOPTION_x509certfile
573 char* arg1;
574 int size1;
577 struct GAAOPTION_x509keyfile
579 char* arg1;
580 int size1;
583 struct GAAOPTION_pgpsubkey
585 char* arg1;
586 int size1;
589 struct GAAOPTION_pgpcertfile
591 char* arg1;
592 int size1;
595 struct GAAOPTION_pgpkeyring
597 char* arg1;
598 int size1;
601 struct GAAOPTION_pgpkeyfile
603 char* arg1;
604 int size1;
607 struct GAAOPTION_x509crlfile
609 char* arg1;
610 int size1;
613 struct GAAOPTION_x509cafile
615 char* arg1;
616 int size1;
619 struct GAAOPTION_priority
621 char* arg1;
622 int size1;
625 struct GAAOPTION_ctypes
627 char** arg1;
628 int size1;
631 struct GAAOPTION_kx
633 char** arg1;
634 int size1;
637 struct GAAOPTION_macs
639 char** arg1;
640 int size1;
643 struct GAAOPTION_comp
645 char** arg1;
646 int size1;
649 struct GAAOPTION_protocols
651 char** arg1;
652 int size1;
655 struct GAAOPTION_ciphers
657 char** arg1;
658 int size1;
661 struct GAAOPTION_recordsize
663 int arg1;
664 int size1;
667 struct GAAOPTION_debug
669 int arg1;
670 int size1;
672 #define GAA_REST_EXISTS
674 struct GAAREST
676 char* arg1;
677 int size1;
680 #line 349 "gaa.skel"
681 static int gaa_is_an_argument(char *str)
683 #ifdef GAA_WIN32
684 if(str[0] == '/' && str[1] != 0)
685 return GAA_MULTIPLE_OPTION;
686 #endif
687 if(str[0] != '-')
688 return GAA_NOT_AN_OPTION;
689 if(str[1] == 0)
690 return GAA_NOT_AN_OPTION;
691 if(str[1] == '-')
693 if(str[2] != 0)
694 return GAA_WORD_OPTION;
695 else
696 return GAA_NOT_AN_OPTION;
698 if(str[2] == 0)
699 return GAA_LETTER_OPTION;
700 else
701 return GAA_MULTIPLE_OPTION;
704 static int gaa_get_option_num(char *str, int status)
706 switch(status)
708 case GAA_LETTER_OPTION:
709 GAA_CHECK1STR("p", GAAOPTID_port);
710 GAA_CHECK1STR("", GAAOPTID_opaque_prf_input);
711 GAA_CHECK1STR("", GAAOPTID_pskkey);
712 GAA_CHECK1STR("", GAAOPTID_pskusername);
713 GAA_CHECK1STR("", GAAOPTID_srppasswd);
714 GAA_CHECK1STR("", GAAOPTID_srpusername);
715 GAA_CHECK1STR("", GAAOPTID_x509certfile);
716 GAA_CHECK1STR("", GAAOPTID_x509keyfile);
717 GAA_CHECK1STR("", GAAOPTID_pgpsubkey);
718 GAA_CHECK1STR("", GAAOPTID_pgpcertfile);
719 GAA_CHECK1STR("", GAAOPTID_pgpkeyring);
720 GAA_CHECK1STR("", GAAOPTID_pgpkeyfile);
721 GAA_CHECK1STR("", GAAOPTID_x509crlfile);
722 GAA_CHECK1STR("", GAAOPTID_x509cafile);
723 GAA_CHECK1STR("", GAAOPTID_priority);
724 GAA_CHECK1STR("", GAAOPTID_ctypes);
725 GAA_CHECK1STR("", GAAOPTID_kx);
726 GAA_CHECK1STR("", GAAOPTID_macs);
727 GAA_CHECK1STR("", GAAOPTID_comp);
728 GAA_CHECK1STR("", GAAOPTID_protocols);
729 GAA_CHECK1STR("", GAAOPTID_ciphers);
730 GAA_CHECK1STR("", GAAOPTID_recordsize);
731 GAA_CHECK1STR("d", GAAOPTID_debug);
732 case GAA_MULTIPLE_OPTION:
733 #line 375 "gaa.skel"
734 GAA_CHECK1STR("", GAAOPTID_copyright);
735 GAA_CHECK1STR("v", GAAOPTID_version);
736 GAA_CHECK1STR("h", GAAOPTID_help);
737 GAA_CHECK1STR("l", GAAOPTID_list);
738 GAA_CHECK1STR("", GAAOPTID_insecure);
739 GAA_CHECK1STR("V", GAAOPTID_verbose);
740 GAA_CHECK1STR("", GAAOPTID_print_cert);
741 GAA_CHECK1STR("", GAAOPTID_disable_extensions);
742 GAA_CHECK1STR("f", GAAOPTID_fingerprint);
743 GAA_CHECK1STR("", GAAOPTID_x509fmtder);
744 GAA_CHECK1STR("", GAAOPTID_crlf);
745 GAA_CHECK1STR("s", GAAOPTID_starttls);
746 GAA_CHECK1STR("r", GAAOPTID_resume);
748 #line 277 "gaa.skel"
749 break;
750 case GAA_WORD_OPTION:
751 GAA_CHECKSTR("copyright", GAAOPTID_copyright);
752 GAA_CHECKSTR("version", GAAOPTID_version);
753 GAA_CHECKSTR("help", GAAOPTID_help);
754 GAA_CHECKSTR("list", GAAOPTID_list);
755 GAA_CHECKSTR("insecure", GAAOPTID_insecure);
756 GAA_CHECKSTR("port", GAAOPTID_port);
757 GAA_CHECKSTR("opaque-prf-input", GAAOPTID_opaque_prf_input);
758 GAA_CHECKSTR("pskkey", GAAOPTID_pskkey);
759 GAA_CHECKSTR("pskusername", GAAOPTID_pskusername);
760 GAA_CHECKSTR("srppasswd", GAAOPTID_srppasswd);
761 GAA_CHECKSTR("srpusername", GAAOPTID_srpusername);
762 GAA_CHECKSTR("x509certfile", GAAOPTID_x509certfile);
763 GAA_CHECKSTR("x509keyfile", GAAOPTID_x509keyfile);
764 GAA_CHECKSTR("pgpsubkey", GAAOPTID_pgpsubkey);
765 GAA_CHECKSTR("pgpcertfile", GAAOPTID_pgpcertfile);
766 GAA_CHECKSTR("pgpkeyring", GAAOPTID_pgpkeyring);
767 GAA_CHECKSTR("pgpkeyfile", GAAOPTID_pgpkeyfile);
768 GAA_CHECKSTR("x509crlfile", GAAOPTID_x509crlfile);
769 GAA_CHECKSTR("x509cafile", GAAOPTID_x509cafile);
770 GAA_CHECKSTR("priority", GAAOPTID_priority);
771 GAA_CHECKSTR("ctypes", GAAOPTID_ctypes);
772 GAA_CHECKSTR("kx", GAAOPTID_kx);
773 GAA_CHECKSTR("macs", GAAOPTID_macs);
774 GAA_CHECKSTR("comp", GAAOPTID_comp);
775 GAA_CHECKSTR("protocols", GAAOPTID_protocols);
776 GAA_CHECKSTR("ciphers", GAAOPTID_ciphers);
777 GAA_CHECKSTR("verbose", GAAOPTID_verbose);
778 GAA_CHECKSTR("recordsize", GAAOPTID_recordsize);
779 GAA_CHECKSTR("print-cert", GAAOPTID_print_cert);
780 GAA_CHECKSTR("disable-extensions", GAAOPTID_disable_extensions);
781 GAA_CHECKSTR("fingerprint", GAAOPTID_fingerprint);
782 GAA_CHECKSTR("x509fmtder", GAAOPTID_x509fmtder);
783 GAA_CHECKSTR("crlf", GAAOPTID_crlf);
784 GAA_CHECKSTR("starttls", GAAOPTID_starttls);
785 GAA_CHECKSTR("resume", GAAOPTID_resume);
786 GAA_CHECKSTR("debug", GAAOPTID_debug);
788 #line 281 "gaa.skel"
789 break;
790 default: break;
792 return GAA_ERROR_NOMATCH;
795 static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
797 int OK = 0;
798 int gaa_last_non_option;
799 struct GAAOPTION_port GAATMP_port;
800 struct GAAOPTION_opaque_prf_input GAATMP_opaque_prf_input;
801 struct GAAOPTION_pskkey GAATMP_pskkey;
802 struct GAAOPTION_pskusername GAATMP_pskusername;
803 struct GAAOPTION_srppasswd GAATMP_srppasswd;
804 struct GAAOPTION_srpusername GAATMP_srpusername;
805 struct GAAOPTION_x509certfile GAATMP_x509certfile;
806 struct GAAOPTION_x509keyfile GAATMP_x509keyfile;
807 struct GAAOPTION_pgpsubkey GAATMP_pgpsubkey;
808 struct GAAOPTION_pgpcertfile GAATMP_pgpcertfile;
809 struct GAAOPTION_pgpkeyring GAATMP_pgpkeyring;
810 struct GAAOPTION_pgpkeyfile GAATMP_pgpkeyfile;
811 struct GAAOPTION_x509crlfile GAATMP_x509crlfile;
812 struct GAAOPTION_x509cafile GAATMP_x509cafile;
813 struct GAAOPTION_priority GAATMP_priority;
814 struct GAAOPTION_ctypes GAATMP_ctypes;
815 struct GAAOPTION_kx GAATMP_kx;
816 struct GAAOPTION_macs GAATMP_macs;
817 struct GAAOPTION_comp GAATMP_comp;
818 struct GAAOPTION_protocols GAATMP_protocols;
819 struct GAAOPTION_ciphers GAATMP_ciphers;
820 struct GAAOPTION_recordsize GAATMP_recordsize;
821 struct GAAOPTION_debug GAATMP_debug;
823 #line 393 "gaa.skel"
824 #ifdef GAA_REST_EXISTS
825 struct GAAREST GAAREST_tmp;
826 #endif
828 opt_list[gaa_num] = 1;
830 for(gaa_last_non_option = gaa_index;
831 (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION);
832 gaa_last_non_option++);
834 if(gaa_num == GAA_REST)
836 gaa_index = 1;
837 gaa_last_non_option = GAAargc;
840 switch(gaa_num)
842 case GAAOPTID_copyright:
843 OK = 0;
844 #line 120 "cli.gaa"
845 { print_license(); exit(0); ;};
847 return GAA_OK;
848 break;
849 case GAAOPTID_version:
850 OK = 0;
851 #line 119 "cli.gaa"
852 { cli_version(); exit(0); ;};
854 return GAA_OK;
855 break;
856 case GAAOPTID_help:
857 OK = 0;
858 #line 117 "cli.gaa"
859 { gaa_help(); exit(0); ;};
861 return GAA_OK;
862 break;
863 case GAAOPTID_list:
864 OK = 0;
865 #line 116 "cli.gaa"
866 { print_list(gaaval->verbose); exit(0); ;};
868 return GAA_OK;
869 break;
870 case GAAOPTID_insecure:
871 OK = 0;
872 #line 114 "cli.gaa"
873 { gaaval->insecure = 1 ;};
875 return GAA_OK;
876 break;
877 case GAAOPTID_port:
878 OK = 0;
879 GAA_TESTMOREARGS;
880 GAA_FILL(GAATMP_port.arg1, gaa_getstr, GAATMP_port.size1);
881 gaa_index++;
882 #line 111 "cli.gaa"
883 { gaaval->port = GAATMP_port.arg1 ;};
885 return GAA_OK;
886 break;
887 case GAAOPTID_opaque_prf_input:
888 OK = 0;
889 GAA_TESTMOREARGS;
890 GAA_FILL(GAATMP_opaque_prf_input.arg1, gaa_getstr, GAATMP_opaque_prf_input.size1);
891 gaa_index++;
892 #line 108 "cli.gaa"
893 { gaaval->opaque_prf_input = GAATMP_opaque_prf_input.arg1 ;};
895 return GAA_OK;
896 break;
897 case GAAOPTID_pskkey:
898 OK = 0;
899 GAA_TESTMOREARGS;
900 GAA_FILL(GAATMP_pskkey.arg1, gaa_getstr, GAATMP_pskkey.size1);
901 gaa_index++;
902 #line 105 "cli.gaa"
903 { gaaval->psk_key = GAATMP_pskkey.arg1 ;};
905 return GAA_OK;
906 break;
907 case GAAOPTID_pskusername:
908 OK = 0;
909 GAA_TESTMOREARGS;
910 GAA_FILL(GAATMP_pskusername.arg1, gaa_getstr, GAATMP_pskusername.size1);
911 gaa_index++;
912 #line 102 "cli.gaa"
913 { gaaval->psk_username = GAATMP_pskusername.arg1 ;};
915 return GAA_OK;
916 break;
917 case GAAOPTID_srppasswd:
918 OK = 0;
919 GAA_TESTMOREARGS;
920 GAA_FILL(GAATMP_srppasswd.arg1, gaa_getstr, GAATMP_srppasswd.size1);
921 gaa_index++;
922 #line 99 "cli.gaa"
923 { gaaval->srp_passwd = GAATMP_srppasswd.arg1 ;};
925 return GAA_OK;
926 break;
927 case GAAOPTID_srpusername:
928 OK = 0;
929 GAA_TESTMOREARGS;
930 GAA_FILL(GAATMP_srpusername.arg1, gaa_getstr, GAATMP_srpusername.size1);
931 gaa_index++;
932 #line 96 "cli.gaa"
933 { gaaval->srp_username = GAATMP_srpusername.arg1 ;};
935 return GAA_OK;
936 break;
937 case GAAOPTID_x509certfile:
938 OK = 0;
939 GAA_TESTMOREARGS;
940 GAA_FILL(GAATMP_x509certfile.arg1, gaa_getstr, GAATMP_x509certfile.size1);
941 gaa_index++;
942 #line 93 "cli.gaa"
943 { gaaval->x509_certfile = GAATMP_x509certfile.arg1 ;};
945 return GAA_OK;
946 break;
947 case GAAOPTID_x509keyfile:
948 OK = 0;
949 GAA_TESTMOREARGS;
950 GAA_FILL(GAATMP_x509keyfile.arg1, gaa_getstr, GAATMP_x509keyfile.size1);
951 gaa_index++;
952 #line 90 "cli.gaa"
953 { gaaval->x509_keyfile = GAATMP_x509keyfile.arg1 ;};
955 return GAA_OK;
956 break;
957 case GAAOPTID_pgpsubkey:
958 OK = 0;
959 GAA_TESTMOREARGS;
960 GAA_FILL(GAATMP_pgpsubkey.arg1, gaa_getstr, GAATMP_pgpsubkey.size1);
961 gaa_index++;
962 #line 87 "cli.gaa"
963 { gaaval->pgp_subkey = GAATMP_pgpsubkey.arg1 ;};
965 return GAA_OK;
966 break;
967 case GAAOPTID_pgpcertfile:
968 OK = 0;
969 GAA_TESTMOREARGS;
970 GAA_FILL(GAATMP_pgpcertfile.arg1, gaa_getstr, GAATMP_pgpcertfile.size1);
971 gaa_index++;
972 #line 84 "cli.gaa"
973 { gaaval->pgp_certfile = GAATMP_pgpcertfile.arg1 ;};
975 return GAA_OK;
976 break;
977 case GAAOPTID_pgpkeyring:
978 OK = 0;
979 GAA_TESTMOREARGS;
980 GAA_FILL(GAATMP_pgpkeyring.arg1, gaa_getstr, GAATMP_pgpkeyring.size1);
981 gaa_index++;
982 #line 81 "cli.gaa"
983 { gaaval->pgp_keyring = GAATMP_pgpkeyring.arg1 ;};
985 return GAA_OK;
986 break;
987 case GAAOPTID_pgpkeyfile:
988 OK = 0;
989 GAA_TESTMOREARGS;
990 GAA_FILL(GAATMP_pgpkeyfile.arg1, gaa_getstr, GAATMP_pgpkeyfile.size1);
991 gaa_index++;
992 #line 78 "cli.gaa"
993 { gaaval->pgp_keyfile = GAATMP_pgpkeyfile.arg1 ;};
995 return GAA_OK;
996 break;
997 case GAAOPTID_x509crlfile:
998 OK = 0;
999 GAA_TESTMOREARGS;
1000 GAA_FILL(GAATMP_x509crlfile.arg1, gaa_getstr, GAATMP_x509crlfile.size1);
1001 gaa_index++;
1002 #line 75 "cli.gaa"
1003 { gaaval->x509_crlfile = GAATMP_x509crlfile.arg1 ;};
1005 return GAA_OK;
1006 break;
1007 case GAAOPTID_x509cafile:
1008 OK = 0;
1009 GAA_TESTMOREARGS;
1010 GAA_FILL(GAATMP_x509cafile.arg1, gaa_getstr, GAATMP_x509cafile.size1);
1011 gaa_index++;
1012 #line 72 "cli.gaa"
1013 { gaaval->x509_cafile = GAATMP_x509cafile.arg1 ;};
1015 return GAA_OK;
1016 break;
1017 case GAAOPTID_priority:
1018 OK = 0;
1019 GAA_TESTMOREARGS;
1020 GAA_FILL(GAATMP_priority.arg1, gaa_getstr, GAATMP_priority.size1);
1021 gaa_index++;
1022 #line 69 "cli.gaa"
1023 { gaaval->priorities = GAATMP_priority.arg1 ;};
1025 return GAA_OK;
1026 break;
1027 case GAAOPTID_ctypes:
1028 OK = 0;
1029 GAA_LIST_FILL(GAATMP_ctypes.arg1, gaa_getstr, char*, GAATMP_ctypes.size1);
1030 #line 66 "cli.gaa"
1031 { gaaval->ctype = GAATMP_ctypes.arg1; gaaval->nctype = GAATMP_ctypes.size1 ;};
1033 return GAA_OK;
1034 break;
1035 case GAAOPTID_kx:
1036 OK = 0;
1037 GAA_LIST_FILL(GAATMP_kx.arg1, gaa_getstr, char*, GAATMP_kx.size1);
1038 #line 62 "cli.gaa"
1039 { gaaval->kx = GAATMP_kx.arg1; gaaval->nkx = GAATMP_kx.size1 ;};
1041 return GAA_OK;
1042 break;
1043 case GAAOPTID_macs:
1044 OK = 0;
1045 GAA_LIST_FILL(GAATMP_macs.arg1, gaa_getstr, char*, GAATMP_macs.size1);
1046 #line 58 "cli.gaa"
1047 { gaaval->macs = GAATMP_macs.arg1; gaaval->nmacs = GAATMP_macs.size1 ;};
1049 return GAA_OK;
1050 break;
1051 case GAAOPTID_comp:
1052 OK = 0;
1053 GAA_LIST_FILL(GAATMP_comp.arg1, gaa_getstr, char*, GAATMP_comp.size1);
1054 #line 54 "cli.gaa"
1055 { gaaval->comp = GAATMP_comp.arg1; gaaval->ncomp = GAATMP_comp.size1 ;};
1057 return GAA_OK;
1058 break;
1059 case GAAOPTID_protocols:
1060 OK = 0;
1061 GAA_LIST_FILL(GAATMP_protocols.arg1, gaa_getstr, char*, GAATMP_protocols.size1);
1062 #line 50 "cli.gaa"
1063 { gaaval->proto = GAATMP_protocols.arg1; gaaval->nproto = GAATMP_protocols.size1 ;};
1065 return GAA_OK;
1066 break;
1067 case GAAOPTID_ciphers:
1068 OK = 0;
1069 GAA_LIST_FILL(GAATMP_ciphers.arg1, gaa_getstr, char*, GAATMP_ciphers.size1);
1070 #line 46 "cli.gaa"
1071 { gaaval->ciphers = GAATMP_ciphers.arg1; gaaval->nciphers = GAATMP_ciphers.size1 ;};
1073 return GAA_OK;
1074 break;
1075 case GAAOPTID_verbose:
1076 OK = 0;
1077 #line 42 "cli.gaa"
1078 { gaaval->verbose = 1 ;};
1080 return GAA_OK;
1081 break;
1082 case GAAOPTID_recordsize:
1083 OK = 0;
1084 GAA_TESTMOREARGS;
1085 GAA_FILL(GAATMP_recordsize.arg1, gaa_getint, GAATMP_recordsize.size1);
1086 gaa_index++;
1087 #line 39 "cli.gaa"
1088 { gaaval->record_size = GAATMP_recordsize.arg1 ;};
1090 return GAA_OK;
1091 break;
1092 case GAAOPTID_print_cert:
1093 OK = 0;
1094 #line 36 "cli.gaa"
1095 { gaaval->print_cert = 1 ;};
1097 return GAA_OK;
1098 break;
1099 case GAAOPTID_disable_extensions:
1100 OK = 0;
1101 #line 33 "cli.gaa"
1102 { gaaval->disable_extensions = 1 ;};
1104 return GAA_OK;
1105 break;
1106 case GAAOPTID_fingerprint:
1107 OK = 0;
1108 #line 30 "cli.gaa"
1109 { gaaval->fingerprint = 1 ;};
1111 return GAA_OK;
1112 break;
1113 case GAAOPTID_x509fmtder:
1114 OK = 0;
1115 #line 27 "cli.gaa"
1116 { gaaval->fmtder = 1 ;};
1118 return GAA_OK;
1119 break;
1120 case GAAOPTID_crlf:
1121 OK = 0;
1122 #line 24 "cli.gaa"
1123 { gaaval->crlf = 1 ;};
1125 return GAA_OK;
1126 break;
1127 case GAAOPTID_starttls:
1128 OK = 0;
1129 #line 21 "cli.gaa"
1130 { gaaval->starttls = 1 ;};
1132 return GAA_OK;
1133 break;
1134 case GAAOPTID_resume:
1135 OK = 0;
1136 #line 18 "cli.gaa"
1137 { gaaval->resume = 1 ;};
1139 return GAA_OK;
1140 break;
1141 case GAAOPTID_debug:
1142 OK = 0;
1143 GAA_TESTMOREARGS;
1144 GAA_FILL(GAATMP_debug.arg1, gaa_getint, GAATMP_debug.size1);
1145 gaa_index++;
1146 #line 15 "cli.gaa"
1147 { gaaval->debug = GAATMP_debug.arg1 ;};
1149 return GAA_OK;
1150 break;
1151 case GAA_REST:
1152 GAA_TESTMOREARGS;
1153 GAA_FILL(GAAREST_tmp.arg1, gaa_getstr, GAAREST_tmp.size1);
1154 gaa_index++;
1155 #line 123 "cli.gaa"
1156 { gaaval->rest_args = GAAREST_tmp.arg1; ;};
1158 return GAA_OK;
1159 break;
1161 #line 413 "gaa.skel"
1162 default: break;
1164 return GAA_ERROR_UNKNOWN;
1167 int gaa(int argc, char **argv, gaainfo *gaaval)
1169 int tmp1, tmp2;
1170 int i, j;
1171 char *opt_list;
1173 GAAargv = argv;
1174 GAAargc = argc;
1176 opt_list = (char*) gaa_malloc(GAA_NB_OPTION + 1);
1178 for(i = 0; i < GAA_NB_OPTION + 1; i++)
1179 opt_list[i] = 0;
1180 /* initialization */
1181 if(inited == 0)
1184 #line 125 "cli.gaa"
1185 { gaaval->resume=0; gaaval->port="443"; gaaval->rest_args=NULL; gaaval->ciphers=NULL;
1186 gaaval->kx=NULL; gaaval->comp=NULL; gaaval->macs=NULL; gaaval->ctype=NULL; gaaval->nciphers=0;
1187 gaaval->nkx=0; gaaval->ncomp=0; gaaval->nmacs=0; gaaval->nctype = 0; gaaval->record_size=0;
1188 gaaval->fingerprint=0; gaaval->pgp_keyring=NULL; gaaval->x509_crlfile = NULL;
1189 gaaval->x509_cafile = NULL; gaaval->pgp_keyfile=NULL; gaaval->pgp_certfile=NULL; gaaval->disable_extensions = 0;
1190 gaaval->x509_keyfile=NULL; gaaval->x509_certfile=NULL; gaaval->crlf = 0;
1191 gaaval->srp_username=NULL; gaaval->srp_passwd=NULL; gaaval->fmtder = 0; gaaval->starttls =0;
1192 gaaval->debug = 0; gaaval->print_cert = 0; gaaval->verbose = 0; gaaval->psk_key = NULL;
1193 gaaval->psk_username = NULL; gaaval->priorities = NULL;
1194 gaaval->opaque_prf_input = NULL; gaaval->pgp_subkey = NULL; ;};
1197 inited = 1;
1198 #line 438 "gaa.skel"
1199 gaa_arg_used = NULL;
1201 if (argc > 0) {
1202 gaa_arg_used = gaa_malloc(argc * sizeof(char));
1205 for(i = 1; i < argc; i++)
1206 gaa_arg_used[i] = 0;
1207 for(i = 1; i < argc; i++)
1209 if(gaa_arg_used[i] == 0)
1211 j = 0;
1212 tmp1 = gaa_is_an_argument(GAAargv[i]);
1213 switch(tmp1)
1215 case GAA_WORD_OPTION:
1216 j++;
1217 case GAA_LETTER_OPTION:
1218 j++;
1219 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
1220 if(tmp2 == GAA_ERROR_NOMATCH)
1222 printf("Invalid option '%s'\n", argv[i]+j);
1223 return 0;
1225 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
1227 case GAA_ERROR_NOTENOUGH_ARGS:
1228 printf("'%s': not enough arguments\n",gaa_current_option);
1229 return 0;
1230 case GAA_ERROR_INVALID_ARG:
1231 printf("Invalid arguments\n");
1232 return 0;
1233 case GAA_OK:
1234 break;
1235 default:
1236 printf("Unknown error\n");
1238 gaa_arg_used[i] = 1;
1239 break;
1240 case GAA_MULTIPLE_OPTION:
1241 for(j = 1; j < strlen(argv[i]); j++)
1243 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
1244 if(tmp2 == GAA_ERROR_NOMATCH)
1246 printf("Invalid option '%c'\n", *(argv[i]+j));
1247 return 0;
1249 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
1251 case GAA_ERROR_NOTENOUGH_ARGS:
1252 printf("'%s': not enough arguments\n",gaa_current_option);
1253 return 0;
1254 case GAA_ERROR_INVALID_ARG:
1255 printf("Invalid arguments\n");
1256 return 0;
1257 case GAA_OK:
1258 break;
1259 default:
1260 printf("Unknown error\n");
1263 gaa_arg_used[i] = 1;
1264 break;
1265 default: break;
1269 if(gaa_processing_file == 0)
1272 #line 507 "gaa.skel"
1273 #ifdef GAA_REST_EXISTS
1274 switch(gaa_try(GAA_REST, 1, gaaval, opt_list))
1276 case GAA_ERROR_NOTENOUGH_ARGS:
1277 printf("Rest: not enough arguments\n");
1278 return 0;
1279 case GAA_ERROR_INVALID_ARG:
1280 printf("Invalid arguments\n");
1281 return 0;
1282 case GAA_OK:
1283 break;
1284 default:
1285 printf("Unknown error\n");
1287 #endif
1289 for(i = 1; i < argc; i++)
1291 if(gaa_arg_used[i] == 0)
1293 printf("Too many arguments\n");
1294 return 0;
1297 free(gaa_arg_used);
1298 free(opt_list);
1299 return -1;
1302 struct gaastrnode
1304 char *str;
1305 struct gaastrnode *next;
1308 typedef struct gaastrnode gaa_str_node;
1310 static int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc)
1312 int pos_ini;
1313 int a;
1314 int i = 0, len = 0, newline = 0;
1316 if(argc == 1) {
1317 newline = 1;
1318 len = 2;
1321 a = fgetc( file);
1322 if (a == EOF) return 0;
1324 while(a == ' ' || a == 9 || a == '\n')
1326 if(a == '\n')
1328 newline=1;
1329 len = 2;
1331 a = fgetc( file);
1332 if (a == EOF) return 0;
1335 pos_ini = ftell(file) - 1;
1337 while(a != ' ' && a != 9 && a != '\n')
1340 len++;
1341 a = fgetc( file);
1342 if(a==EOF) return 0; //a = ' ';
1345 len += 1;
1346 tmp_str->str = gaa_malloc((len) * sizeof(char));
1348 if(newline == 1)
1350 tmp_str->str[0] = '-';
1351 tmp_str->str[1] = '-';
1352 i = 2;
1354 else
1356 i = 0;
1359 fseek(file,pos_ini, SEEK_SET);
1362 a = fgetc( file);
1364 if (a == EOF) {
1365 i+=2;
1366 break;
1368 tmp_str->str[i] = a;
1369 i++;
1371 while(a != ' ' && a != 9 && a != '\n' && i < len);
1373 tmp_str->str[i - 1] = 0;
1375 fseek(file,- 1, SEEK_CUR);
1376 /* printf("%d\n", ftell(file)); */
1378 return -1;
1381 int gaa_file(const char *name, gaainfo *gaaval)
1383 gaa_str_node *first_str, **tmp_str, *tmp_str2;
1384 int rval, i;
1385 char **argv;
1386 int argc = 0;
1387 FILE *file;
1389 gaa_processing_file = 1;
1391 if((file = fopen(name, "r")) == NULL)
1393 printf("Couldn't open '%s' configuration file for reading\n", name);
1394 return 1;
1397 tmp_str = &first_str;
1400 argc++;
1401 *tmp_str = gaa_malloc(sizeof(gaa_str_node));
1403 (*tmp_str)->str = NULL;
1404 (*tmp_str)->next = NULL;
1406 rval = gaa_internal_get_next_str(file, *tmp_str, argc);
1407 tmp_str = &((*tmp_str)->next);
1409 while(rval == -1);
1411 if(rval == 1)
1412 return 0;
1414 argv = gaa_malloc((1 + argc) * sizeof(char*));
1416 tmp_str2 = first_str;
1417 argv[0] = "cfg";
1418 for(i = 1; i < argc; i++)
1420 argv[i] = tmp_str2->str;
1421 tmp_str2 = tmp_str2->next;
1424 rval = gaa(argc, argv, gaaval);
1425 gaa_processing_file = 0;
1426 return rval;