Fix license.
[gnutls.git] / src / serv-gaa.c
blob3bab62df871a2e44a326480528d04e8e4b30faaf
1 /* File generated by GAA 1.6.6
2 */
3 #define GAA_NO_WIN32
4 #line 1 "serv.gaa"
7 #include <config.h>
8 #include <common.h>
10 void serv_version(void);
12 #include <stdio.h>
13 #include <string.h>
14 #include <stdlib.h>
16 #ifndef GAA_NO_WIN32
17 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(WINDOWS)
18 #define GAA_WIN32
19 #endif
20 #endif
22 static void* gaa_malloc( size_t size) {
23 void* ret;
24 ret = malloc(size);
25 if (ret==NULL) {
26 fprintf(stderr, "gaa: could not allocate memory");
27 exit(1);
29 return ret;
32 static void __gaa_helpsingle(char short_name, char *name,
33 char *arg_desc, char *opt_help)
35 int col1, col3, col4, tabsize = 3, curr;
36 int i;
38 col1 = 5; /* Default values */
39 col3 = 30;
40 col4 = 70;
42 curr = 0;
43 for(i = 0; i < col1; i++)
45 printf(" ");
46 curr++;
48 if(short_name)
50 if(name && *name)
52 printf("-%c, ", short_name);
53 curr += 4;
55 else
57 printf("-%c ", short_name);
58 curr += 3;
61 if(name && *name)
63 printf("--%s ", name);
64 curr += 3 + strlen(name);
66 if(arg_desc && *arg_desc)
68 printf("%s ", arg_desc);
69 curr += 1 + strlen(arg_desc);
71 if(curr >= col3)
73 printf("\n");
74 curr = 0;
76 if(opt_help) /* let's print the option's help body */
78 const char *str = opt_help;
79 while(*str)
81 while(curr < col3)
83 printf(" ");
84 curr++;
86 switch(*str)
88 case '\n':
89 printf("\n");
90 curr = 0;
91 break;
92 case '\t':
95 printf(" ");
96 curr++;
98 while((curr - col3) % tabsize != 0 && curr < col4);
99 case ' ':
100 if(*str == ' ')
102 curr++;
103 printf(" ");
105 for(i = 1; str[i] && str[i] != ' ' && str[i] != '\n'
106 && str[i] != '\t'; i++);
107 if(curr + i - 1 >= col4)
108 curr = col4;
109 break;
110 default:
111 printf("%c", *str);
112 curr++;
114 if(curr >= col4)
116 printf("\n");
117 curr = 0;
119 str++;
122 printf("\n");
125 void gaa_help(void)
127 printf("GNU TLS test server\nUsage: gnutls-serv [options]\n\n\n");
128 __gaa_helpsingle('d', "debug", "integer ", "Enable debugging");
129 __gaa_helpsingle('g', "generate", "", "Generate Diffie-Hellman Parameters.");
130 __gaa_helpsingle('p', "port", "integer ", "The port to connect to.");
131 __gaa_helpsingle('q', "quiet", "", "Suppress some messages.");
132 __gaa_helpsingle(0, "nodb", "", "Does not use the resume database.");
133 __gaa_helpsingle(0, "noticket", "", "Does not issue session tickets.");
134 __gaa_helpsingle(0, "http", "", "Act as an HTTP Server.");
135 __gaa_helpsingle(0, "echo", "", "Act as an Echo Server.");
136 __gaa_helpsingle(0, "dhparams", "FILE ", "DH params file to use.");
137 __gaa_helpsingle(0, "x509fmtder", "", "Use DER format for certificates");
138 __gaa_helpsingle(0, "x509cafile", "FILE ", "Certificate file to use.");
139 __gaa_helpsingle(0, "x509crlfile", "FILE ", "CRL file to use.");
140 __gaa_helpsingle(0, "pgpkeyring", "FILE ", "PGP Key ring file to use.");
141 __gaa_helpsingle(0, "pgpkeyfile", "FILE ", "PGP Key file to use.");
142 __gaa_helpsingle(0, "pgpcertfile", "FILE ", "PGP Public Key (certificate) file to use.");
143 __gaa_helpsingle(0, "pgpsubkey", "HEX|auto ", "PGP subkey to use.");
144 __gaa_helpsingle(0, "x509keyfile", "FILE ", "X.509 key file to use.");
145 __gaa_helpsingle(0, "x509certfile", "FILE ", "X.509 Certificate file to use.");
146 __gaa_helpsingle(0, "x509dsakeyfile", "FILE ", "Alternative X.509 key file to use.");
147 __gaa_helpsingle(0, "x509dsacertfile", "FILE ", "Alternative X.509 certificate file to use.");
148 __gaa_helpsingle('r', "require-cert", "", "Require a valid certificate.");
149 __gaa_helpsingle('a', "disable-client-cert", "", "Disable request for a client certificate.");
150 __gaa_helpsingle(0, "pskpasswd", "FILE ", "PSK password file to use.");
151 __gaa_helpsingle(0, "pskhint", "HINT ", "PSK identity hint to use.");
152 __gaa_helpsingle(0, "srppasswd", "FILE ", "SRP password file to use.");
153 __gaa_helpsingle(0, "srppasswdconf", "FILE ", "SRP password conf file to use.");
154 __gaa_helpsingle(0, "opaque-prf-input", "DATA ", "Use Opaque PRF Input DATA.");
155 __gaa_helpsingle(0, "ciphers", "cipher1 cipher2... ", "Ciphers to enable.");
156 __gaa_helpsingle(0, "protocols", "protocol1 protocol2... ", "Protocols to enable.");
157 __gaa_helpsingle(0, "comp", "comp1 comp2... ", "Compression methods to enable.");
158 __gaa_helpsingle(0, "macs", "mac1 mac2... ", "MACs to enable.");
159 __gaa_helpsingle(0, "kx", "kx1 kx2... ", "Key exchange methods to enable.");
160 __gaa_helpsingle(0, "ctypes", "certType1 certType2... ", "Certificate types to enable.");
161 __gaa_helpsingle(0, "priority", "PRIORITY STRING ", "Priorities string.");
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");
166 #line 100 "gaa.skel"
168 /* Copy of C area */
170 #line 104 "gaa.skel"
171 /* GAA HEADER */
172 #ifndef GAA_HEADER_POKY
173 #define GAA_HEADER_POKY
175 typedef struct _gaainfo gaainfo;
177 struct _gaainfo
179 #line 115 "serv.gaa"
180 char *priorities;
181 #line 112 "serv.gaa"
182 char **ctype;
183 #line 111 "serv.gaa"
184 int nctype;
185 #line 108 "serv.gaa"
186 char **kx;
187 #line 107 "serv.gaa"
188 int nkx;
189 #line 104 "serv.gaa"
190 char **macs;
191 #line 103 "serv.gaa"
192 int nmacs;
193 #line 100 "serv.gaa"
194 char **comp;
195 #line 99 "serv.gaa"
196 int ncomp;
197 #line 96 "serv.gaa"
198 char **proto;
199 #line 95 "serv.gaa"
200 int nproto;
201 #line 92 "serv.gaa"
202 char **ciphers;
203 #line 91 "serv.gaa"
204 int nciphers;
205 #line 88 "serv.gaa"
206 char *opaque_prf_input;
207 #line 85 "serv.gaa"
208 char *srp_passwd_conf;
209 #line 82 "serv.gaa"
210 char *srp_passwd;
211 #line 79 "serv.gaa"
212 char *psk_hint;
213 #line 76 "serv.gaa"
214 char *psk_passwd;
215 #line 73 "serv.gaa"
216 int disable_client_cert;
217 #line 70 "serv.gaa"
218 int require_cert;
219 #line 67 "serv.gaa"
220 char *x509_dsacertfile;
221 #line 64 "serv.gaa"
222 char *x509_dsakeyfile;
223 #line 61 "serv.gaa"
224 char *x509_certfile;
225 #line 58 "serv.gaa"
226 char *x509_keyfile;
227 #line 55 "serv.gaa"
228 char *pgp_subkey;
229 #line 52 "serv.gaa"
230 char *pgp_certfile;
231 #line 49 "serv.gaa"
232 char *pgp_keyfile;
233 #line 46 "serv.gaa"
234 char *pgp_keyring;
235 #line 43 "serv.gaa"
236 char *x509_crlfile;
237 #line 40 "serv.gaa"
238 char *x509_cafile;
239 #line 37 "serv.gaa"
240 int fmtder;
241 #line 34 "serv.gaa"
242 char *dh_params_file;
243 #line 30 "serv.gaa"
244 int http;
245 #line 27 "serv.gaa"
246 int noticket;
247 #line 24 "serv.gaa"
248 int nodb;
249 #line 21 "serv.gaa"
250 int quiet;
251 #line 18 "serv.gaa"
252 int port;
253 #line 15 "serv.gaa"
254 int generate;
255 #line 12 "serv.gaa"
256 int debug;
258 #line 114 "gaa.skel"
261 #ifdef __cplusplus
262 extern "C"
264 #endif
266 int gaa(int argc, char *argv[], gaainfo *gaaval);
268 void gaa_help(void);
270 int gaa_file(const char *name, gaainfo *gaaval);
272 #ifdef __cplusplus
274 #endif
277 #endif
279 #line 135 "gaa.skel"
281 /* C declarations */
283 #define GAAERROR(x) \
285 gaa_error = 1; \
286 return x; \
289 static char *gaa_current_option;
290 static int gaa_error = 0;
292 /* Generated by gaa */
294 #include <string.h>
295 #include <stdlib.h>
298 #define GAA_OK -1
300 #define GAA_ERROR_NOMATCH 0
301 #define GAA_ERROR_NOTENOUGH_ARGS 1
302 #define GAA_ERROR_INVALID_ARG 2
303 #define GAA_ERROR_UNKNOWN 3
305 #define GAA_NOT_AN_OPTION 0
306 #define GAA_WORD_OPTION 1
307 #define GAA_LETTER_OPTION 2
308 #define GAA_MULTIPLE_OPTION 3
310 #define GAA_REST 0
311 #define GAA_NB_OPTION 37
312 #define GAAOPTID_version 1
313 #define GAAOPTID_help 2
314 #define GAAOPTID_list 3
315 #define GAAOPTID_priority 4
316 #define GAAOPTID_ctypes 5
317 #define GAAOPTID_kx 6
318 #define GAAOPTID_macs 7
319 #define GAAOPTID_comp 8
320 #define GAAOPTID_protocols 9
321 #define GAAOPTID_ciphers 10
322 #define GAAOPTID_opaque_prf_input 11
323 #define GAAOPTID_srppasswdconf 12
324 #define GAAOPTID_srppasswd 13
325 #define GAAOPTID_pskhint 14
326 #define GAAOPTID_pskpasswd 15
327 #define GAAOPTID_disable_client_cert 16
328 #define GAAOPTID_require_cert 17
329 #define GAAOPTID_x509dsacertfile 18
330 #define GAAOPTID_x509dsakeyfile 19
331 #define GAAOPTID_x509certfile 20
332 #define GAAOPTID_x509keyfile 21
333 #define GAAOPTID_pgpsubkey 22
334 #define GAAOPTID_pgpcertfile 23
335 #define GAAOPTID_pgpkeyfile 24
336 #define GAAOPTID_pgpkeyring 25
337 #define GAAOPTID_x509crlfile 26
338 #define GAAOPTID_x509cafile 27
339 #define GAAOPTID_x509fmtder 28
340 #define GAAOPTID_dhparams 29
341 #define GAAOPTID_echo 30
342 #define GAAOPTID_http 31
343 #define GAAOPTID_noticket 32
344 #define GAAOPTID_nodb 33
345 #define GAAOPTID_quiet 34
346 #define GAAOPTID_port 35
347 #define GAAOPTID_generate 36
348 #define GAAOPTID_debug 37
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;
509 static char* gaa_getstr(char *arg)
511 return arg;
514 /* option structures */
516 struct GAAOPTION_priority
518 char* arg1;
519 int size1;
522 struct GAAOPTION_ctypes
524 char** arg1;
525 int size1;
528 struct GAAOPTION_kx
530 char** arg1;
531 int size1;
534 struct GAAOPTION_macs
536 char** arg1;
537 int size1;
540 struct GAAOPTION_comp
542 char** arg1;
543 int size1;
546 struct GAAOPTION_protocols
548 char** arg1;
549 int size1;
552 struct GAAOPTION_ciphers
554 char** arg1;
555 int size1;
558 struct GAAOPTION_opaque_prf_input
560 char* arg1;
561 int size1;
564 struct GAAOPTION_srppasswdconf
566 char* arg1;
567 int size1;
570 struct GAAOPTION_srppasswd
572 char* arg1;
573 int size1;
576 struct GAAOPTION_pskhint
578 char* arg1;
579 int size1;
582 struct GAAOPTION_pskpasswd
584 char* arg1;
585 int size1;
588 struct GAAOPTION_x509dsacertfile
590 char* arg1;
591 int size1;
594 struct GAAOPTION_x509dsakeyfile
596 char* arg1;
597 int size1;
600 struct GAAOPTION_x509certfile
602 char* arg1;
603 int size1;
606 struct GAAOPTION_x509keyfile
608 char* arg1;
609 int size1;
612 struct GAAOPTION_pgpsubkey
614 char* arg1;
615 int size1;
618 struct GAAOPTION_pgpcertfile
620 char* arg1;
621 int size1;
624 struct GAAOPTION_pgpkeyfile
626 char* arg1;
627 int size1;
630 struct GAAOPTION_pgpkeyring
632 char* arg1;
633 int size1;
636 struct GAAOPTION_x509crlfile
638 char* arg1;
639 int size1;
642 struct GAAOPTION_x509cafile
644 char* arg1;
645 int size1;
648 struct GAAOPTION_dhparams
650 char* arg1;
651 int size1;
654 struct GAAOPTION_port
656 int arg1;
657 int size1;
660 struct GAAOPTION_debug
662 int arg1;
663 int size1;
666 #line 349 "gaa.skel"
667 static int gaa_is_an_argument(char *str)
669 #ifdef GAA_WIN32
670 if(str[0] == '/' && str[1] != 0)
671 return GAA_MULTIPLE_OPTION;
672 #endif
673 if(str[0] != '-')
674 return GAA_NOT_AN_OPTION;
675 if(str[1] == 0)
676 return GAA_NOT_AN_OPTION;
677 if(str[1] == '-')
679 if(str[2] != 0)
680 return GAA_WORD_OPTION;
681 else
682 return GAA_NOT_AN_OPTION;
684 if(str[2] == 0)
685 return GAA_LETTER_OPTION;
686 else
687 return GAA_MULTIPLE_OPTION;
690 static int gaa_get_option_num(char *str, int status)
692 switch(status)
694 case GAA_LETTER_OPTION:
695 GAA_CHECK1STR("", GAAOPTID_priority);
696 GAA_CHECK1STR("", GAAOPTID_ctypes);
697 GAA_CHECK1STR("", GAAOPTID_kx);
698 GAA_CHECK1STR("", GAAOPTID_macs);
699 GAA_CHECK1STR("", GAAOPTID_comp);
700 GAA_CHECK1STR("", GAAOPTID_protocols);
701 GAA_CHECK1STR("", GAAOPTID_ciphers);
702 GAA_CHECK1STR("", GAAOPTID_opaque_prf_input);
703 GAA_CHECK1STR("", GAAOPTID_srppasswdconf);
704 GAA_CHECK1STR("", GAAOPTID_srppasswd);
705 GAA_CHECK1STR("", GAAOPTID_pskhint);
706 GAA_CHECK1STR("", GAAOPTID_pskpasswd);
707 GAA_CHECK1STR("", GAAOPTID_x509dsacertfile);
708 GAA_CHECK1STR("", GAAOPTID_x509dsakeyfile);
709 GAA_CHECK1STR("", GAAOPTID_x509certfile);
710 GAA_CHECK1STR("", GAAOPTID_x509keyfile);
711 GAA_CHECK1STR("", GAAOPTID_pgpsubkey);
712 GAA_CHECK1STR("", GAAOPTID_pgpcertfile);
713 GAA_CHECK1STR("", GAAOPTID_pgpkeyfile);
714 GAA_CHECK1STR("", GAAOPTID_pgpkeyring);
715 GAA_CHECK1STR("", GAAOPTID_x509crlfile);
716 GAA_CHECK1STR("", GAAOPTID_x509cafile);
717 GAA_CHECK1STR("", GAAOPTID_dhparams);
718 GAA_CHECK1STR("p", GAAOPTID_port);
719 GAA_CHECK1STR("d", GAAOPTID_debug);
720 case GAA_MULTIPLE_OPTION:
721 #line 375 "gaa.skel"
722 GAA_CHECK1STR("v", GAAOPTID_version);
723 GAA_CHECK1STR("h", GAAOPTID_help);
724 GAA_CHECK1STR("l", GAAOPTID_list);
725 GAA_CHECK1STR("a", GAAOPTID_disable_client_cert);
726 GAA_CHECK1STR("r", GAAOPTID_require_cert);
727 GAA_CHECK1STR("", GAAOPTID_x509fmtder);
728 GAA_CHECK1STR("", GAAOPTID_echo);
729 GAA_CHECK1STR("", GAAOPTID_http);
730 GAA_CHECK1STR("", GAAOPTID_noticket);
731 GAA_CHECK1STR("", GAAOPTID_nodb);
732 GAA_CHECK1STR("q", GAAOPTID_quiet);
733 GAA_CHECK1STR("g", GAAOPTID_generate);
735 #line 277 "gaa.skel"
736 break;
737 case GAA_WORD_OPTION:
738 GAA_CHECKSTR("version", GAAOPTID_version);
739 GAA_CHECKSTR("help", GAAOPTID_help);
740 GAA_CHECKSTR("list", GAAOPTID_list);
741 GAA_CHECKSTR("priority", GAAOPTID_priority);
742 GAA_CHECKSTR("ctypes", GAAOPTID_ctypes);
743 GAA_CHECKSTR("kx", GAAOPTID_kx);
744 GAA_CHECKSTR("macs", GAAOPTID_macs);
745 GAA_CHECKSTR("comp", GAAOPTID_comp);
746 GAA_CHECKSTR("protocols", GAAOPTID_protocols);
747 GAA_CHECKSTR("ciphers", GAAOPTID_ciphers);
748 GAA_CHECKSTR("opaque-prf-input", GAAOPTID_opaque_prf_input);
749 GAA_CHECKSTR("srppasswdconf", GAAOPTID_srppasswdconf);
750 GAA_CHECKSTR("srppasswd", GAAOPTID_srppasswd);
751 GAA_CHECKSTR("pskhint", GAAOPTID_pskhint);
752 GAA_CHECKSTR("pskpasswd", GAAOPTID_pskpasswd);
753 GAA_CHECKSTR("disable-client-cert", GAAOPTID_disable_client_cert);
754 GAA_CHECKSTR("require-cert", GAAOPTID_require_cert);
755 GAA_CHECKSTR("x509dsacertfile", GAAOPTID_x509dsacertfile);
756 GAA_CHECKSTR("x509dsakeyfile", GAAOPTID_x509dsakeyfile);
757 GAA_CHECKSTR("x509certfile", GAAOPTID_x509certfile);
758 GAA_CHECKSTR("x509keyfile", GAAOPTID_x509keyfile);
759 GAA_CHECKSTR("pgpsubkey", GAAOPTID_pgpsubkey);
760 GAA_CHECKSTR("pgpcertfile", GAAOPTID_pgpcertfile);
761 GAA_CHECKSTR("pgpkeyfile", GAAOPTID_pgpkeyfile);
762 GAA_CHECKSTR("pgpkeyring", GAAOPTID_pgpkeyring);
763 GAA_CHECKSTR("x509crlfile", GAAOPTID_x509crlfile);
764 GAA_CHECKSTR("x509cafile", GAAOPTID_x509cafile);
765 GAA_CHECKSTR("x509fmtder", GAAOPTID_x509fmtder);
766 GAA_CHECKSTR("dhparams", GAAOPTID_dhparams);
767 GAA_CHECKSTR("echo", GAAOPTID_echo);
768 GAA_CHECKSTR("http", GAAOPTID_http);
769 GAA_CHECKSTR("noticket", GAAOPTID_noticket);
770 GAA_CHECKSTR("nodb", GAAOPTID_nodb);
771 GAA_CHECKSTR("quiet", GAAOPTID_quiet);
772 GAA_CHECKSTR("port", GAAOPTID_port);
773 GAA_CHECKSTR("generate", GAAOPTID_generate);
774 GAA_CHECKSTR("debug", GAAOPTID_debug);
776 #line 281 "gaa.skel"
777 break;
778 default: break;
780 return GAA_ERROR_NOMATCH;
783 static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
785 int OK = 0;
786 int gaa_last_non_option;
787 struct GAAOPTION_priority GAATMP_priority;
788 struct GAAOPTION_ctypes GAATMP_ctypes;
789 struct GAAOPTION_kx GAATMP_kx;
790 struct GAAOPTION_macs GAATMP_macs;
791 struct GAAOPTION_comp GAATMP_comp;
792 struct GAAOPTION_protocols GAATMP_protocols;
793 struct GAAOPTION_ciphers GAATMP_ciphers;
794 struct GAAOPTION_opaque_prf_input GAATMP_opaque_prf_input;
795 struct GAAOPTION_srppasswdconf GAATMP_srppasswdconf;
796 struct GAAOPTION_srppasswd GAATMP_srppasswd;
797 struct GAAOPTION_pskhint GAATMP_pskhint;
798 struct GAAOPTION_pskpasswd GAATMP_pskpasswd;
799 struct GAAOPTION_x509dsacertfile GAATMP_x509dsacertfile;
800 struct GAAOPTION_x509dsakeyfile GAATMP_x509dsakeyfile;
801 struct GAAOPTION_x509certfile GAATMP_x509certfile;
802 struct GAAOPTION_x509keyfile GAATMP_x509keyfile;
803 struct GAAOPTION_pgpsubkey GAATMP_pgpsubkey;
804 struct GAAOPTION_pgpcertfile GAATMP_pgpcertfile;
805 struct GAAOPTION_pgpkeyfile GAATMP_pgpkeyfile;
806 struct GAAOPTION_pgpkeyring GAATMP_pgpkeyring;
807 struct GAAOPTION_x509crlfile GAATMP_x509crlfile;
808 struct GAAOPTION_x509cafile GAATMP_x509cafile;
809 struct GAAOPTION_dhparams GAATMP_dhparams;
810 struct GAAOPTION_port GAATMP_port;
811 struct GAAOPTION_debug GAATMP_debug;
813 #line 393 "gaa.skel"
814 #ifdef GAA_REST_EXISTS
815 struct GAAREST GAAREST_tmp;
816 #endif
818 opt_list[gaa_num] = 1;
820 for(gaa_last_non_option = gaa_index;
821 (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION);
822 gaa_last_non_option++);
824 if(gaa_num == GAA_REST)
826 gaa_index = 1;
827 gaa_last_non_option = GAAargc;
830 switch(gaa_num)
832 case GAAOPTID_version:
833 OK = 0;
834 #line 121 "serv.gaa"
835 { serv_version(); exit(0); ;};
837 return GAA_OK;
838 break;
839 case GAAOPTID_help:
840 OK = 0;
841 #line 119 "serv.gaa"
842 { gaa_help(); exit(0); ;};
844 return GAA_OK;
845 break;
846 case GAAOPTID_list:
847 OK = 0;
848 #line 118 "serv.gaa"
849 { print_list(0); exit(0); ;};
851 return GAA_OK;
852 break;
853 case GAAOPTID_priority:
854 OK = 0;
855 GAA_TESTMOREARGS;
856 GAA_FILL(GAATMP_priority.arg1, gaa_getstr, GAATMP_priority.size1);
857 gaa_index++;
858 #line 116 "serv.gaa"
859 { gaaval->priorities = GAATMP_priority.arg1 ;};
861 return GAA_OK;
862 break;
863 case GAAOPTID_ctypes:
864 OK = 0;
865 GAA_LIST_FILL(GAATMP_ctypes.arg1, gaa_getstr, char*, GAATMP_ctypes.size1);
866 #line 113 "serv.gaa"
867 { gaaval->ctype = GAATMP_ctypes.arg1; gaaval->nctype = GAATMP_ctypes.size1 ;};
869 return GAA_OK;
870 break;
871 case GAAOPTID_kx:
872 OK = 0;
873 GAA_LIST_FILL(GAATMP_kx.arg1, gaa_getstr, char*, GAATMP_kx.size1);
874 #line 109 "serv.gaa"
875 { gaaval->kx = GAATMP_kx.arg1; gaaval->nkx = GAATMP_kx.size1 ;};
877 return GAA_OK;
878 break;
879 case GAAOPTID_macs:
880 OK = 0;
881 GAA_LIST_FILL(GAATMP_macs.arg1, gaa_getstr, char*, GAATMP_macs.size1);
882 #line 105 "serv.gaa"
883 { gaaval->macs = GAATMP_macs.arg1; gaaval->nmacs = GAATMP_macs.size1 ;};
885 return GAA_OK;
886 break;
887 case GAAOPTID_comp:
888 OK = 0;
889 GAA_LIST_FILL(GAATMP_comp.arg1, gaa_getstr, char*, GAATMP_comp.size1);
890 #line 101 "serv.gaa"
891 { gaaval->comp = GAATMP_comp.arg1; gaaval->ncomp = GAATMP_comp.size1 ;};
893 return GAA_OK;
894 break;
895 case GAAOPTID_protocols:
896 OK = 0;
897 GAA_LIST_FILL(GAATMP_protocols.arg1, gaa_getstr, char*, GAATMP_protocols.size1);
898 #line 97 "serv.gaa"
899 { gaaval->proto = GAATMP_protocols.arg1; gaaval->nproto = GAATMP_protocols.size1 ;};
901 return GAA_OK;
902 break;
903 case GAAOPTID_ciphers:
904 OK = 0;
905 GAA_LIST_FILL(GAATMP_ciphers.arg1, gaa_getstr, char*, GAATMP_ciphers.size1);
906 #line 93 "serv.gaa"
907 { gaaval->ciphers = GAATMP_ciphers.arg1; gaaval->nciphers = GAATMP_ciphers.size1 ;};
909 return GAA_OK;
910 break;
911 case GAAOPTID_opaque_prf_input:
912 OK = 0;
913 GAA_TESTMOREARGS;
914 GAA_FILL(GAATMP_opaque_prf_input.arg1, gaa_getstr, GAATMP_opaque_prf_input.size1);
915 gaa_index++;
916 #line 89 "serv.gaa"
917 { gaaval->opaque_prf_input = GAATMP_opaque_prf_input.arg1 ;};
919 return GAA_OK;
920 break;
921 case GAAOPTID_srppasswdconf:
922 OK = 0;
923 GAA_TESTMOREARGS;
924 GAA_FILL(GAATMP_srppasswdconf.arg1, gaa_getstr, GAATMP_srppasswdconf.size1);
925 gaa_index++;
926 #line 86 "serv.gaa"
927 { gaaval->srp_passwd_conf = GAATMP_srppasswdconf.arg1 ;};
929 return GAA_OK;
930 break;
931 case GAAOPTID_srppasswd:
932 OK = 0;
933 GAA_TESTMOREARGS;
934 GAA_FILL(GAATMP_srppasswd.arg1, gaa_getstr, GAATMP_srppasswd.size1);
935 gaa_index++;
936 #line 83 "serv.gaa"
937 { gaaval->srp_passwd = GAATMP_srppasswd.arg1 ;};
939 return GAA_OK;
940 break;
941 case GAAOPTID_pskhint:
942 OK = 0;
943 GAA_TESTMOREARGS;
944 GAA_FILL(GAATMP_pskhint.arg1, gaa_getstr, GAATMP_pskhint.size1);
945 gaa_index++;
946 #line 80 "serv.gaa"
947 { gaaval->psk_hint = GAATMP_pskhint.arg1 ;};
949 return GAA_OK;
950 break;
951 case GAAOPTID_pskpasswd:
952 OK = 0;
953 GAA_TESTMOREARGS;
954 GAA_FILL(GAATMP_pskpasswd.arg1, gaa_getstr, GAATMP_pskpasswd.size1);
955 gaa_index++;
956 #line 77 "serv.gaa"
957 { gaaval->psk_passwd = GAATMP_pskpasswd.arg1 ;};
959 return GAA_OK;
960 break;
961 case GAAOPTID_disable_client_cert:
962 OK = 0;
963 #line 74 "serv.gaa"
964 { gaaval->disable_client_cert = 1 ;};
966 return GAA_OK;
967 break;
968 case GAAOPTID_require_cert:
969 OK = 0;
970 #line 71 "serv.gaa"
971 { gaaval->require_cert = 1 ;};
973 return GAA_OK;
974 break;
975 case GAAOPTID_x509dsacertfile:
976 OK = 0;
977 GAA_TESTMOREARGS;
978 GAA_FILL(GAATMP_x509dsacertfile.arg1, gaa_getstr, GAATMP_x509dsacertfile.size1);
979 gaa_index++;
980 #line 68 "serv.gaa"
981 { gaaval->x509_dsacertfile = GAATMP_x509dsacertfile.arg1 ;};
983 return GAA_OK;
984 break;
985 case GAAOPTID_x509dsakeyfile:
986 OK = 0;
987 GAA_TESTMOREARGS;
988 GAA_FILL(GAATMP_x509dsakeyfile.arg1, gaa_getstr, GAATMP_x509dsakeyfile.size1);
989 gaa_index++;
990 #line 65 "serv.gaa"
991 { gaaval->x509_dsakeyfile = GAATMP_x509dsakeyfile.arg1 ;};
993 return GAA_OK;
994 break;
995 case GAAOPTID_x509certfile:
996 OK = 0;
997 GAA_TESTMOREARGS;
998 GAA_FILL(GAATMP_x509certfile.arg1, gaa_getstr, GAATMP_x509certfile.size1);
999 gaa_index++;
1000 #line 62 "serv.gaa"
1001 { gaaval->x509_certfile = GAATMP_x509certfile.arg1 ;};
1003 return GAA_OK;
1004 break;
1005 case GAAOPTID_x509keyfile:
1006 OK = 0;
1007 GAA_TESTMOREARGS;
1008 GAA_FILL(GAATMP_x509keyfile.arg1, gaa_getstr, GAATMP_x509keyfile.size1);
1009 gaa_index++;
1010 #line 59 "serv.gaa"
1011 { gaaval->x509_keyfile = GAATMP_x509keyfile.arg1 ;};
1013 return GAA_OK;
1014 break;
1015 case GAAOPTID_pgpsubkey:
1016 OK = 0;
1017 GAA_TESTMOREARGS;
1018 GAA_FILL(GAATMP_pgpsubkey.arg1, gaa_getstr, GAATMP_pgpsubkey.size1);
1019 gaa_index++;
1020 #line 56 "serv.gaa"
1021 { gaaval->pgp_subkey = GAATMP_pgpsubkey.arg1 ;};
1023 return GAA_OK;
1024 break;
1025 case GAAOPTID_pgpcertfile:
1026 OK = 0;
1027 GAA_TESTMOREARGS;
1028 GAA_FILL(GAATMP_pgpcertfile.arg1, gaa_getstr, GAATMP_pgpcertfile.size1);
1029 gaa_index++;
1030 #line 53 "serv.gaa"
1031 { gaaval->pgp_certfile = GAATMP_pgpcertfile.arg1 ;};
1033 return GAA_OK;
1034 break;
1035 case GAAOPTID_pgpkeyfile:
1036 OK = 0;
1037 GAA_TESTMOREARGS;
1038 GAA_FILL(GAATMP_pgpkeyfile.arg1, gaa_getstr, GAATMP_pgpkeyfile.size1);
1039 gaa_index++;
1040 #line 50 "serv.gaa"
1041 { gaaval->pgp_keyfile = GAATMP_pgpkeyfile.arg1 ;};
1043 return GAA_OK;
1044 break;
1045 case GAAOPTID_pgpkeyring:
1046 OK = 0;
1047 GAA_TESTMOREARGS;
1048 GAA_FILL(GAATMP_pgpkeyring.arg1, gaa_getstr, GAATMP_pgpkeyring.size1);
1049 gaa_index++;
1050 #line 47 "serv.gaa"
1051 { gaaval->pgp_keyring = GAATMP_pgpkeyring.arg1 ;};
1053 return GAA_OK;
1054 break;
1055 case GAAOPTID_x509crlfile:
1056 OK = 0;
1057 GAA_TESTMOREARGS;
1058 GAA_FILL(GAATMP_x509crlfile.arg1, gaa_getstr, GAATMP_x509crlfile.size1);
1059 gaa_index++;
1060 #line 44 "serv.gaa"
1061 { gaaval->x509_crlfile = GAATMP_x509crlfile.arg1 ;};
1063 return GAA_OK;
1064 break;
1065 case GAAOPTID_x509cafile:
1066 OK = 0;
1067 GAA_TESTMOREARGS;
1068 GAA_FILL(GAATMP_x509cafile.arg1, gaa_getstr, GAATMP_x509cafile.size1);
1069 gaa_index++;
1070 #line 41 "serv.gaa"
1071 { gaaval->x509_cafile = GAATMP_x509cafile.arg1 ;};
1073 return GAA_OK;
1074 break;
1075 case GAAOPTID_x509fmtder:
1076 OK = 0;
1077 #line 38 "serv.gaa"
1078 { gaaval->fmtder = 1 ;};
1080 return GAA_OK;
1081 break;
1082 case GAAOPTID_dhparams:
1083 OK = 0;
1084 GAA_TESTMOREARGS;
1085 GAA_FILL(GAATMP_dhparams.arg1, gaa_getstr, GAATMP_dhparams.size1);
1086 gaa_index++;
1087 #line 35 "serv.gaa"
1088 { gaaval->dh_params_file = GAATMP_dhparams.arg1 ;};
1090 return GAA_OK;
1091 break;
1092 case GAAOPTID_echo:
1093 OK = 0;
1094 #line 32 "serv.gaa"
1095 { gaaval->http = 0 ;};
1097 return GAA_OK;
1098 break;
1099 case GAAOPTID_http:
1100 OK = 0;
1101 #line 31 "serv.gaa"
1102 { gaaval->http = 1 ;};
1104 return GAA_OK;
1105 break;
1106 case GAAOPTID_noticket:
1107 OK = 0;
1108 #line 28 "serv.gaa"
1109 { gaaval->noticket = 1 ;};
1111 return GAA_OK;
1112 break;
1113 case GAAOPTID_nodb:
1114 OK = 0;
1115 #line 25 "serv.gaa"
1116 { gaaval->nodb = 1 ;};
1118 return GAA_OK;
1119 break;
1120 case GAAOPTID_quiet:
1121 OK = 0;
1122 #line 22 "serv.gaa"
1123 { gaaval->quiet = 1 ;};
1125 return GAA_OK;
1126 break;
1127 case GAAOPTID_port:
1128 OK = 0;
1129 GAA_TESTMOREARGS;
1130 GAA_FILL(GAATMP_port.arg1, gaa_getint, GAATMP_port.size1);
1131 gaa_index++;
1132 #line 19 "serv.gaa"
1133 { gaaval->port = GAATMP_port.arg1 ;};
1135 return GAA_OK;
1136 break;
1137 case GAAOPTID_generate:
1138 OK = 0;
1139 #line 16 "serv.gaa"
1140 { gaaval->generate = 1 ;};
1142 return GAA_OK;
1143 break;
1144 case GAAOPTID_debug:
1145 OK = 0;
1146 GAA_TESTMOREARGS;
1147 GAA_FILL(GAATMP_debug.arg1, gaa_getint, GAATMP_debug.size1);
1148 gaa_index++;
1149 #line 13 "serv.gaa"
1150 { gaaval->debug = GAATMP_debug.arg1 ;};
1152 return GAA_OK;
1153 break;
1155 #line 413 "gaa.skel"
1156 default: break;
1158 return GAA_ERROR_UNKNOWN;
1161 int gaa(int argc, char **argv, gaainfo *gaaval)
1163 int tmp1, tmp2;
1164 int l;
1165 size_t i, j, k;
1166 char *opt_list;
1168 i = 0;
1170 GAAargv = argv;
1171 GAAargc = argc;
1173 opt_list = (char*) gaa_malloc(GAA_NB_OPTION + 1);
1175 for(l = 0; l < GAA_NB_OPTION + 1; l++)
1176 opt_list[l] = 0;
1177 /* initialization */
1178 if(inited == 0)
1181 #line 125 "serv.gaa"
1182 { gaaval->generate=0; gaaval->port=5556; gaaval->http=0; gaaval->ciphers=NULL;
1183 gaaval->kx=NULL; gaaval->comp=NULL; gaaval->macs=NULL; gaaval->ctype=NULL; gaaval->nciphers=0;
1184 gaaval->nkx=0; gaaval->ncomp=0; gaaval->nmacs=0; gaaval->nctype = 0; gaaval->nodb = 0; gaaval->noticket = 0;
1185 gaaval->x509_cafile = NULL; gaaval->pgp_keyfile=NULL; gaaval->pgp_certfile=NULL;
1186 gaaval->x509_keyfile=NULL; gaaval->x509_certfile=NULL; gaaval->x509_crlfile = NULL;
1187 gaaval->x509_dsakeyfile=NULL; gaaval->x509_dsacertfile=NULL;
1188 gaaval->srp_passwd=NULL; gaaval->srp_passwd_conf=NULL; gaaval->quiet = 0;
1189 gaaval->pgp_keyring=NULL; gaaval->fmtder = 0;
1190 gaaval->disable_client_cert = 0; gaaval->priorities = NULL;
1191 gaaval->dh_params_file=NULL; gaaval->debug=0; gaaval->require_cert = 0; gaaval->psk_passwd = 0;
1192 gaaval->opaque_prf_input=NULL; gaaval->pgp_subkey = NULL;;};
1195 inited = 1;
1196 #line 438 "gaa.skel"
1197 gaa_arg_used = NULL;
1199 if (argc > 0) {
1200 gaa_arg_used = gaa_malloc(argc * sizeof(char));
1203 for(l = 1; l < argc; l++)
1204 gaa_arg_used[l] = 0;
1205 for(l = 1; l < argc; l++)
1207 if(gaa_arg_used[l] == 0)
1209 j = 0;
1210 tmp1 = gaa_is_an_argument(GAAargv[l]);
1211 switch(tmp1)
1213 case GAA_WORD_OPTION:
1214 j++;
1215 case GAA_LETTER_OPTION:
1216 j++;
1217 tmp2 = gaa_get_option_num(argv[l]+j, tmp1);
1218 if(tmp2 == GAA_ERROR_NOMATCH)
1220 printf("Invalid option '%s'\n", argv[l]+j);
1221 return 0;
1223 switch(gaa_try(tmp2, l+1, gaaval, opt_list))
1225 case GAA_ERROR_NOTENOUGH_ARGS:
1226 printf("'%s': not enough arguments\n",gaa_current_option);
1227 return 0;
1228 case GAA_ERROR_INVALID_ARG:
1229 printf("Invalid arguments\n");
1230 return 0;
1231 case GAA_OK:
1232 break;
1233 default:
1234 printf("Unknown error\n");
1236 gaa_arg_used[l] = 1;
1237 break;
1238 case GAA_MULTIPLE_OPTION:
1239 for(j = 1; j < strlen(argv[l]); j++)
1241 tmp2 = gaa_get_option_num(argv[l]+j, tmp1);
1242 if(tmp2 == GAA_ERROR_NOMATCH)
1244 printf("Invalid option '%c'\n", *(argv[l]+j));
1245 return 0;
1247 switch(gaa_try(tmp2, l+1, gaaval, opt_list))
1249 case GAA_ERROR_NOTENOUGH_ARGS:
1250 printf("'%s': not enough arguments\n",gaa_current_option);
1251 return 0;
1252 case GAA_ERROR_INVALID_ARG:
1253 printf("Invalid arguments\n");
1254 return 0;
1255 case GAA_OK:
1256 break;
1257 default:
1258 printf("Unknown error\n");
1261 gaa_arg_used[l] = 1;
1262 break;
1263 default: break;
1267 if(gaa_processing_file == 0)
1269 GAA_INCOMP("ra");
1271 #line 507 "gaa.skel"
1272 #ifdef GAA_REST_EXISTS
1273 switch(gaa_try(GAA_REST, 1, gaaval, opt_list))
1275 case GAA_ERROR_NOTENOUGH_ARGS:
1276 printf("Rest: not enough arguments\n");
1277 return 0;
1278 case GAA_ERROR_INVALID_ARG:
1279 printf("Invalid arguments\n");
1280 return 0;
1281 case GAA_OK:
1282 break;
1283 default:
1284 printf("Unknown error\n");
1286 #endif
1288 for(l = 1; l < argc; l++)
1290 if(gaa_arg_used[l] == 0)
1292 printf("Too many arguments\n");
1293 return 0;
1296 free(gaa_arg_used);
1297 free(opt_list);
1298 return -1;
1301 struct gaastrnode
1303 char *str;
1304 struct gaastrnode *next;
1307 typedef struct gaastrnode gaa_str_node;
1309 static int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc)
1311 int pos_ini;
1312 int a;
1313 int i = 0, len = 0, newline = 0;
1315 if(argc == 1) {
1316 newline = 1;
1317 len = 2;
1320 a = fgetc( file);
1321 if (a == EOF) return 0;
1323 while(a == ' ' || a == 9 || a == '\n')
1325 if(a == '\n')
1327 newline=1;
1328 len = 2;
1330 a = fgetc( file);
1331 if (a == EOF) return 0;
1334 pos_ini = ftell(file) - 1;
1336 while(a != ' ' && a != 9 && a != '\n')
1339 len++;
1340 a = fgetc( file);
1341 if(a==EOF) return 0; /* a = ' '; */
1344 len += 1;
1345 tmp_str->str = gaa_malloc((len) * sizeof(char));
1347 if(newline == 1)
1349 tmp_str->str[0] = '-';
1350 tmp_str->str[1] = '-';
1351 i = 2;
1353 else
1355 i = 0;
1358 fseek(file,pos_ini, SEEK_SET);
1361 a = fgetc( file);
1363 if (a == EOF) {
1364 i+=2;
1365 break;
1367 tmp_str->str[i] = a;
1368 i++;
1370 while(a != ' ' && a != 9 && a != '\n' && i < len);
1372 tmp_str->str[i - 1] = 0;
1374 fseek(file,- 1, SEEK_CUR);
1375 /* printf("%d\n", ftell(file)); */
1377 return -1;
1380 int gaa_file(const char *name, gaainfo *gaaval)
1382 gaa_str_node *first_str, **tmp_str, *tmp_str2;
1383 int rval, i;
1384 char **argv;
1385 int argc = 0;
1386 FILE *file;
1388 gaa_processing_file = 1;
1390 if((file = fopen(name, "r")) == NULL)
1392 printf("Couldn't open '%s' configuration file for reading\n", name);
1393 return 1;
1396 tmp_str = &first_str;
1399 argc++;
1400 *tmp_str = gaa_malloc(sizeof(gaa_str_node));
1402 (*tmp_str)->str = NULL;
1403 (*tmp_str)->next = NULL;
1405 rval = gaa_internal_get_next_str(file, *tmp_str, argc);
1406 tmp_str = &((*tmp_str)->next);
1408 while(rval == -1);
1410 if(rval == 1)
1411 return 0;
1413 argv = gaa_malloc((1 + argc) * sizeof(char*));
1415 tmp_str2 = first_str;
1416 argv[0] = "cfg";
1417 for(i = 1; i < argc; i++)
1419 argv[i] = tmp_str2->str;
1420 tmp_str2 = tmp_str2->next;
1423 rval = gaa(argc, argv, gaaval);
1424 gaa_processing_file = 0;
1425 return rval;