Add.
[gnutls.git] / src / serv-gaa.c
blobf0fe9c4b57039b69df3c336f5e495e9f39b98b06
1 /* File generated by GAA 1.6.6
2 */
3 #define GAA_NO_WIN32
4 #line 1 "serv.gaa"
7 #include <common.h>
9 void print_serv_license(void);
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, "http", "", "Act as an HTTP Server.");
134 __gaa_helpsingle(0, "echo", "", "Act as an Echo Server.");
135 __gaa_helpsingle(0, "dhparams", "FILE ", "DH params file to use.");
136 __gaa_helpsingle(0, "x509fmtder", "", "Use DER format for certificates");
137 __gaa_helpsingle(0, "x509cafile", "FILE ", "Certificate file to use.");
138 __gaa_helpsingle(0, "x509crlfile", "FILE ", "CRL file to use.");
139 __gaa_helpsingle(0, "pgpkeyring", "FILE ", "PGP Key ring file to use.");
140 __gaa_helpsingle(0, "pgptrustdb", "FILE ", "PGP trustdb 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, "x509keyfile", "FILE ", "X.509 key file to use.");
144 __gaa_helpsingle(0, "x509certfile", "FILE ", "X.509 Certificate file to use.");
145 __gaa_helpsingle(0, "x509dsakeyfile", "FILE ", "Alternative X.509 key file to use.");
146 __gaa_helpsingle(0, "x509dsacertfile", "FILE ", "Alternative X.509 certificate file to use.");
147 __gaa_helpsingle(0, "require-cert", "", "Require a valid certificate.");
148 __gaa_helpsingle(0, "pskpasswd", "FILE ", "PSK password file to use.");
149 __gaa_helpsingle(0, "srppasswd", "FILE ", "SRP password file to use.");
150 __gaa_helpsingle(0, "srppasswdconf", "FILE ", "SRP password conf file to use.");
151 __gaa_helpsingle(0, "authz-x509-attr-cert", "FILE ", "Use X.509 Attribute Certificate in FILE as authorization data.");
152 __gaa_helpsingle(0, "authz-saml-assertion", "FILE ", "Use SAML Assertion in FILE as authorization data.");
153 __gaa_helpsingle(0, "ciphers", "cipher1 cipher2... ", "Ciphers to enable.");
154 __gaa_helpsingle(0, "protocols", "protocol1 protocol2... ", "Protocols to enable.");
155 __gaa_helpsingle(0, "comp", "comp1 comp2... ", "Compression methods to enable.");
156 __gaa_helpsingle(0, "macs", "mac1 mac2... ", "MACs to enable.");
157 __gaa_helpsingle(0, "kx", "kx1 kx2... ", "Key exchange methods to enable.");
158 __gaa_helpsingle(0, "ctypes", "certType1 certType2... ", "Certificate types to enable.");
159 __gaa_helpsingle('l', "list", "", "Print a list of the supported algorithms and modes.");
160 __gaa_helpsingle('h', "help", "", "prints this help");
161 __gaa_helpsingle('v', "version", "", "prints the program's version number");
162 __gaa_helpsingle(0, "copyright", "", "prints the program's license");
164 #line 100 "gaa.skel"
166 /* Copy of C area */
168 #line 104 "gaa.skel"
169 /* GAA HEADER */
170 #ifndef GAA_HEADER_POKY
171 #define GAA_HEADER_POKY
173 typedef struct _gaainfo gaainfo;
175 struct _gaainfo
177 #line 106 "serv.gaa"
178 char **ctype;
179 #line 105 "serv.gaa"
180 int nctype;
181 #line 102 "serv.gaa"
182 char **kx;
183 #line 101 "serv.gaa"
184 int nkx;
185 #line 98 "serv.gaa"
186 char **macs;
187 #line 97 "serv.gaa"
188 int nmacs;
189 #line 94 "serv.gaa"
190 char **comp;
191 #line 93 "serv.gaa"
192 int ncomp;
193 #line 90 "serv.gaa"
194 char **proto;
195 #line 89 "serv.gaa"
196 int nproto;
197 #line 86 "serv.gaa"
198 char **ciphers;
199 #line 85 "serv.gaa"
200 int nciphers;
201 #line 82 "serv.gaa"
202 char *authz_saml_assertion;
203 #line 79 "serv.gaa"
204 char *authz_x509_attr_cert;
205 #line 76 "serv.gaa"
206 char *srp_passwd_conf;
207 #line 73 "serv.gaa"
208 char *srp_passwd;
209 #line 70 "serv.gaa"
210 char *psk_passwd;
211 #line 67 "serv.gaa"
212 int require_cert;
213 #line 64 "serv.gaa"
214 char *x509_dsacertfile;
215 #line 61 "serv.gaa"
216 char *x509_dsakeyfile;
217 #line 58 "serv.gaa"
218 char *x509_certfile;
219 #line 55 "serv.gaa"
220 char *x509_keyfile;
221 #line 52 "serv.gaa"
222 char *pgp_certfile;
223 #line 49 "serv.gaa"
224 char *pgp_keyfile;
225 #line 46 "serv.gaa"
226 char *pgp_trustdb;
227 #line 43 "serv.gaa"
228 char *pgp_keyring;
229 #line 40 "serv.gaa"
230 char *x509_crlfile;
231 #line 37 "serv.gaa"
232 char *x509_cafile;
233 #line 34 "serv.gaa"
234 int fmtder;
235 #line 31 "serv.gaa"
236 char *dh_params_file;
237 #line 27 "serv.gaa"
238 int http;
239 #line 24 "serv.gaa"
240 int nodb;
241 #line 21 "serv.gaa"
242 int quiet;
243 #line 18 "serv.gaa"
244 int port;
245 #line 15 "serv.gaa"
246 int generate;
247 #line 12 "serv.gaa"
248 int debug;
250 #line 114 "gaa.skel"
253 #ifdef __cplusplus
254 extern "C"
256 #endif
258 int gaa(int argc, char *argv[], gaainfo *gaaval);
260 void gaa_help(void);
262 int gaa_file(const char *name, gaainfo *gaaval);
264 #ifdef __cplusplus
266 #endif
269 #endif
271 #line 135 "gaa.skel"
273 /* C declarations */
275 #define GAAERROR(x) \
277 gaa_error = 1; \
278 return x; \
281 static char *gaa_current_option;
282 static int gaa_error = 0;
284 /* Generated by gaa */
286 #include <string.h>
287 #include <stdlib.h>
290 #define GAA_OK -1
292 #define GAA_ERROR_NOMATCH 0
293 #define GAA_ERROR_NOTENOUGH_ARGS 1
294 #define GAA_ERROR_INVALID_ARG 2
295 #define GAA_ERROR_UNKNOWN 3
297 #define GAA_NOT_AN_OPTION 0
298 #define GAA_WORD_OPTION 1
299 #define GAA_LETTER_OPTION 2
300 #define GAA_MULTIPLE_OPTION 3
302 #define GAA_REST 0
303 #define GAA_NB_OPTION 35
304 #define GAAOPTID_copyright 1
305 #define GAAOPTID_version 2
306 #define GAAOPTID_help 3
307 #define GAAOPTID_list 4
308 #define GAAOPTID_ctypes 5
309 #define GAAOPTID_kx 6
310 #define GAAOPTID_macs 7
311 #define GAAOPTID_comp 8
312 #define GAAOPTID_protocols 9
313 #define GAAOPTID_ciphers 10
314 #define GAAOPTID_authz_saml_assertion 11
315 #define GAAOPTID_authz_x509_attr_cert 12
316 #define GAAOPTID_srppasswdconf 13
317 #define GAAOPTID_srppasswd 14
318 #define GAAOPTID_pskpasswd 15
319 #define GAAOPTID_require_cert 16
320 #define GAAOPTID_x509dsacertfile 17
321 #define GAAOPTID_x509dsakeyfile 18
322 #define GAAOPTID_x509certfile 19
323 #define GAAOPTID_x509keyfile 20
324 #define GAAOPTID_pgpcertfile 21
325 #define GAAOPTID_pgpkeyfile 22
326 #define GAAOPTID_pgptrustdb 23
327 #define GAAOPTID_pgpkeyring 24
328 #define GAAOPTID_x509crlfile 25
329 #define GAAOPTID_x509cafile 26
330 #define GAAOPTID_x509fmtder 27
331 #define GAAOPTID_dhparams 28
332 #define GAAOPTID_echo 29
333 #define GAAOPTID_http 30
334 #define GAAOPTID_nodb 31
335 #define GAAOPTID_quiet 32
336 #define GAAOPTID_port 33
337 #define GAAOPTID_generate 34
338 #define GAAOPTID_debug 35
340 #line 168 "gaa.skel"
342 #define GAA_CHECK1STR(a,b) \
343 if(a[0] == str[0]) \
345 gaa_current_option = a; \
346 return b; \
349 #define GAA_CHECKSTR(a,b) \
350 if(strcmp(a,str) == 0) \
352 gaa_current_option = a; \
353 return b; \
356 #define GAA_TESTMOREARGS \
357 if(!OK) \
359 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
360 gaa_index++; \
361 if(gaa_last_non_option == gaa_index) \
362 return GAA_ERROR_NOTENOUGH_ARGS; \
365 #define GAA_TESTMOREOPTIONALARGS \
366 if(!OK) \
368 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
369 gaa_index++; \
370 if(gaa_last_non_option == gaa_index) \
371 OK = 1; \
374 #define GAA_FILL_2ARGS(target, func) \
375 target = func(GAAargv[gaa_index]); \
376 gaa_arg_used[gaa_index] = 1; \
377 if(gaa_error == 1) \
379 gaa_error = 0; \
380 return GAA_ERROR_INVALID_ARG; \
385 #define GAA_FILL(target, func, num) \
386 if(!OK) \
388 target = func(GAAargv[gaa_index]); \
389 gaa_arg_used[gaa_index] = 1; \
390 if(gaa_error == 1) \
392 gaa_error = 0; \
393 return GAA_ERROR_INVALID_ARG; \
395 num = 1; \
397 else \
399 num = 0; \
402 #define GAA_LIST_FILL(target, func, type ,num) \
403 if(!OK) \
405 num = 0; \
406 target = NULL; \
407 if ( gaa_last_non_option - gaa_index > 0) \
408 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
409 for(; gaa_index < gaa_last_non_option; gaa_index++) \
411 if(gaa_arg_used[gaa_index] == 0) \
413 GAA_FILL_2ARGS(target[num], func); \
414 num++; \
417 if(num == 0) \
418 return GAA_ERROR_NOTENOUGH_ARGS; \
421 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
422 if(!OK) \
424 num = 0; \
425 target = NULL; \
426 if ( gaa_last_non_option - gaa_index > 0) \
427 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
428 for(; gaa_index < gaa_last_non_option; gaa_index++) \
430 if(gaa_arg_used[gaa_index] == 0) \
432 GAA_FILL_2ARGS(target[num], func); \
433 num++; \
438 #define GAA_OBLIGAT(str) \
439 k = 0; \
440 for(i = 0; i < strlen(str); i++) \
442 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
443 if(j == GAA_ERROR_NOMATCH) \
445 printf("Error: invalid 'obligat' set\n"); \
446 exit(-1); \
448 if(opt_list[j] == 1) \
449 k = 1; \
451 if(k == 0) \
453 if(strlen(str) == 1) \
454 printf("You must give the -%s option\n", str); \
455 else \
456 printf("You must give at least one option of '%s'\n", str); \
457 return 0; \
460 #define GAA_INCOMP(str) \
461 k = 0; \
462 for(i = 0; i < strlen(str); i++) \
464 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
465 if(j == GAA_ERROR_NOMATCH) \
467 printf("Error: invalid 'obligat' set\n"); \
468 exit(-1); \
470 if(opt_list[j] == 1) \
471 k++; \
473 if(k > 1) \
475 printf("The options '%s' are incompatible\n", str); \
476 return 0; \
480 static char **GAAargv;
481 static int GAAargc;
482 static char *gaa_arg_used;
483 static int gaa_processing_file = 0;
484 static int inited = 0;
486 static int gaa_getint(char *arg)
488 int tmp;
489 char a;
490 if(sscanf(arg, "%d%c", &tmp, &a) < 1)
492 printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
493 GAAERROR(-1);
495 return tmp;
498 static char gaa_getchar(char *arg)
500 if(strlen(arg) != 1)
502 printf("Option %s: '%s' isn't an character\n", gaa_current_option, arg);
503 GAAERROR(-1);
505 return arg[0];
508 static char* gaa_getstr(char *arg)
510 return arg;
512 static float gaa_getfloat(char *arg)
514 float tmp;
515 char a;
516 if(sscanf(arg, "%f%c", &tmp, &a) < 1)
518 printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg);
519 GAAERROR(-1);
521 return tmp;
523 /* option structures */
525 struct GAAOPTION_ctypes
527 char** arg1;
528 int size1;
531 struct GAAOPTION_kx
533 char** arg1;
534 int size1;
537 struct GAAOPTION_macs
539 char** arg1;
540 int size1;
543 struct GAAOPTION_comp
545 char** arg1;
546 int size1;
549 struct GAAOPTION_protocols
551 char** arg1;
552 int size1;
555 struct GAAOPTION_ciphers
557 char** arg1;
558 int size1;
561 struct GAAOPTION_authz_saml_assertion
563 char* arg1;
564 int size1;
567 struct GAAOPTION_authz_x509_attr_cert
569 char* arg1;
570 int size1;
573 struct GAAOPTION_srppasswdconf
575 char* arg1;
576 int size1;
579 struct GAAOPTION_srppasswd
581 char* arg1;
582 int size1;
585 struct GAAOPTION_pskpasswd
587 char* arg1;
588 int size1;
591 struct GAAOPTION_x509dsacertfile
593 char* arg1;
594 int size1;
597 struct GAAOPTION_x509dsakeyfile
599 char* arg1;
600 int size1;
603 struct GAAOPTION_x509certfile
605 char* arg1;
606 int size1;
609 struct GAAOPTION_x509keyfile
611 char* arg1;
612 int size1;
615 struct GAAOPTION_pgpcertfile
617 char* arg1;
618 int size1;
621 struct GAAOPTION_pgpkeyfile
623 char* arg1;
624 int size1;
627 struct GAAOPTION_pgptrustdb
629 char* arg1;
630 int size1;
633 struct GAAOPTION_pgpkeyring
635 char* arg1;
636 int size1;
639 struct GAAOPTION_x509crlfile
641 char* arg1;
642 int size1;
645 struct GAAOPTION_x509cafile
647 char* arg1;
648 int size1;
651 struct GAAOPTION_dhparams
653 char* arg1;
654 int size1;
657 struct GAAOPTION_port
659 int arg1;
660 int size1;
663 struct GAAOPTION_debug
665 int arg1;
666 int size1;
669 #line 349 "gaa.skel"
670 static int gaa_is_an_argument(char *str)
672 #ifdef GAA_WIN32
673 if(str[0] == '/' && str[1] != 0)
674 return GAA_MULTIPLE_OPTION;
675 #endif
676 if(str[0] != '-')
677 return GAA_NOT_AN_OPTION;
678 if(str[1] == 0)
679 return GAA_NOT_AN_OPTION;
680 if(str[1] == '-')
682 if(str[2] != 0)
683 return GAA_WORD_OPTION;
684 else
685 return GAA_NOT_AN_OPTION;
687 if(str[2] == 0)
688 return GAA_LETTER_OPTION;
689 else
690 return GAA_MULTIPLE_OPTION;
693 static int gaa_get_option_num(char *str, int status)
695 switch(status)
697 case GAA_LETTER_OPTION:
698 GAA_CHECK1STR("", GAAOPTID_ctypes);
699 GAA_CHECK1STR("", GAAOPTID_kx);
700 GAA_CHECK1STR("", GAAOPTID_macs);
701 GAA_CHECK1STR("", GAAOPTID_comp);
702 GAA_CHECK1STR("", GAAOPTID_protocols);
703 GAA_CHECK1STR("", GAAOPTID_ciphers);
704 GAA_CHECK1STR("", GAAOPTID_authz_saml_assertion);
705 GAA_CHECK1STR("", GAAOPTID_authz_x509_attr_cert);
706 GAA_CHECK1STR("", GAAOPTID_srppasswdconf);
707 GAA_CHECK1STR("", GAAOPTID_srppasswd);
708 GAA_CHECK1STR("", GAAOPTID_pskpasswd);
709 GAA_CHECK1STR("", GAAOPTID_x509dsacertfile);
710 GAA_CHECK1STR("", GAAOPTID_x509dsakeyfile);
711 GAA_CHECK1STR("", GAAOPTID_x509certfile);
712 GAA_CHECK1STR("", GAAOPTID_x509keyfile);
713 GAA_CHECK1STR("", GAAOPTID_pgpcertfile);
714 GAA_CHECK1STR("", GAAOPTID_pgpkeyfile);
715 GAA_CHECK1STR("", GAAOPTID_pgptrustdb);
716 GAA_CHECK1STR("", GAAOPTID_pgpkeyring);
717 GAA_CHECK1STR("", GAAOPTID_x509crlfile);
718 GAA_CHECK1STR("", GAAOPTID_x509cafile);
719 GAA_CHECK1STR("", GAAOPTID_dhparams);
720 GAA_CHECK1STR("p", GAAOPTID_port);
721 GAA_CHECK1STR("d", GAAOPTID_debug);
722 case GAA_MULTIPLE_OPTION:
723 #line 375 "gaa.skel"
724 GAA_CHECK1STR("", GAAOPTID_copyright);
725 GAA_CHECK1STR("v", GAAOPTID_version);
726 GAA_CHECK1STR("h", GAAOPTID_help);
727 GAA_CHECK1STR("l", GAAOPTID_list);
728 GAA_CHECK1STR("", GAAOPTID_require_cert);
729 GAA_CHECK1STR("", GAAOPTID_x509fmtder);
730 GAA_CHECK1STR("", GAAOPTID_echo);
731 GAA_CHECK1STR("", GAAOPTID_http);
732 GAA_CHECK1STR("", GAAOPTID_nodb);
733 GAA_CHECK1STR("q", GAAOPTID_quiet);
734 GAA_CHECK1STR("g", GAAOPTID_generate);
736 #line 277 "gaa.skel"
737 break;
738 case GAA_WORD_OPTION:
739 GAA_CHECKSTR("copyright", GAAOPTID_copyright);
740 GAA_CHECKSTR("version", GAAOPTID_version);
741 GAA_CHECKSTR("help", GAAOPTID_help);
742 GAA_CHECKSTR("list", GAAOPTID_list);
743 GAA_CHECKSTR("ctypes", GAAOPTID_ctypes);
744 GAA_CHECKSTR("kx", GAAOPTID_kx);
745 GAA_CHECKSTR("macs", GAAOPTID_macs);
746 GAA_CHECKSTR("comp", GAAOPTID_comp);
747 GAA_CHECKSTR("protocols", GAAOPTID_protocols);
748 GAA_CHECKSTR("ciphers", GAAOPTID_ciphers);
749 GAA_CHECKSTR("authz-saml-assertion", GAAOPTID_authz_saml_assertion);
750 GAA_CHECKSTR("authz-x509-attr-cert", GAAOPTID_authz_x509_attr_cert);
751 GAA_CHECKSTR("srppasswdconf", GAAOPTID_srppasswdconf);
752 GAA_CHECKSTR("srppasswd", GAAOPTID_srppasswd);
753 GAA_CHECKSTR("pskpasswd", GAAOPTID_pskpasswd);
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("pgpcertfile", GAAOPTID_pgpcertfile);
760 GAA_CHECKSTR("pgpkeyfile", GAAOPTID_pgpkeyfile);
761 GAA_CHECKSTR("pgptrustdb", GAAOPTID_pgptrustdb);
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("nodb", GAAOPTID_nodb);
770 GAA_CHECKSTR("quiet", GAAOPTID_quiet);
771 GAA_CHECKSTR("port", GAAOPTID_port);
772 GAA_CHECKSTR("generate", GAAOPTID_generate);
773 GAA_CHECKSTR("debug", GAAOPTID_debug);
775 #line 281 "gaa.skel"
776 break;
777 default: break;
779 return GAA_ERROR_NOMATCH;
782 static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
784 int OK = 0;
785 int gaa_last_non_option;
786 struct GAAOPTION_ctypes GAATMP_ctypes;
787 struct GAAOPTION_kx GAATMP_kx;
788 struct GAAOPTION_macs GAATMP_macs;
789 struct GAAOPTION_comp GAATMP_comp;
790 struct GAAOPTION_protocols GAATMP_protocols;
791 struct GAAOPTION_ciphers GAATMP_ciphers;
792 struct GAAOPTION_authz_saml_assertion GAATMP_authz_saml_assertion;
793 struct GAAOPTION_authz_x509_attr_cert GAATMP_authz_x509_attr_cert;
794 struct GAAOPTION_srppasswdconf GAATMP_srppasswdconf;
795 struct GAAOPTION_srppasswd GAATMP_srppasswd;
796 struct GAAOPTION_pskpasswd GAATMP_pskpasswd;
797 struct GAAOPTION_x509dsacertfile GAATMP_x509dsacertfile;
798 struct GAAOPTION_x509dsakeyfile GAATMP_x509dsakeyfile;
799 struct GAAOPTION_x509certfile GAATMP_x509certfile;
800 struct GAAOPTION_x509keyfile GAATMP_x509keyfile;
801 struct GAAOPTION_pgpcertfile GAATMP_pgpcertfile;
802 struct GAAOPTION_pgpkeyfile GAATMP_pgpkeyfile;
803 struct GAAOPTION_pgptrustdb GAATMP_pgptrustdb;
804 struct GAAOPTION_pgpkeyring GAATMP_pgpkeyring;
805 struct GAAOPTION_x509crlfile GAATMP_x509crlfile;
806 struct GAAOPTION_x509cafile GAATMP_x509cafile;
807 struct GAAOPTION_dhparams GAATMP_dhparams;
808 struct GAAOPTION_port GAATMP_port;
809 struct GAAOPTION_debug GAATMP_debug;
811 #line 393 "gaa.skel"
812 #ifdef GAA_REST_EXISTS
813 struct GAAREST GAAREST_tmp;
814 #endif
816 opt_list[gaa_num] = 1;
818 for(gaa_last_non_option = gaa_index;
819 (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION);
820 gaa_last_non_option++);
822 if(gaa_num == GAA_REST)
824 gaa_index = 1;
825 gaa_last_non_option = GAAargc;
828 switch(gaa_num)
830 case GAAOPTID_copyright:
831 OK = 0;
832 #line 114 "serv.gaa"
833 { print_serv_license(); exit(0); ;};
835 return GAA_OK;
836 break;
837 case GAAOPTID_version:
838 OK = 0;
839 #line 113 "serv.gaa"
840 { serv_version(); exit(0); ;};
842 return GAA_OK;
843 break;
844 case GAAOPTID_help:
845 OK = 0;
846 #line 111 "serv.gaa"
847 { gaa_help(); exit(0); ;};
849 return GAA_OK;
850 break;
851 case GAAOPTID_list:
852 OK = 0;
853 #line 110 "serv.gaa"
854 { print_list(0); exit(0); ;};
856 return GAA_OK;
857 break;
858 case GAAOPTID_ctypes:
859 OK = 0;
860 GAA_LIST_FILL(GAATMP_ctypes.arg1, gaa_getstr, char*, GAATMP_ctypes.size1);
861 #line 107 "serv.gaa"
862 { gaaval->ctype = GAATMP_ctypes.arg1; gaaval->nctype = GAATMP_ctypes.size1 ;};
864 return GAA_OK;
865 break;
866 case GAAOPTID_kx:
867 OK = 0;
868 GAA_LIST_FILL(GAATMP_kx.arg1, gaa_getstr, char*, GAATMP_kx.size1);
869 #line 103 "serv.gaa"
870 { gaaval->kx = GAATMP_kx.arg1; gaaval->nkx = GAATMP_kx.size1 ;};
872 return GAA_OK;
873 break;
874 case GAAOPTID_macs:
875 OK = 0;
876 GAA_LIST_FILL(GAATMP_macs.arg1, gaa_getstr, char*, GAATMP_macs.size1);
877 #line 99 "serv.gaa"
878 { gaaval->macs = GAATMP_macs.arg1; gaaval->nmacs = GAATMP_macs.size1 ;};
880 return GAA_OK;
881 break;
882 case GAAOPTID_comp:
883 OK = 0;
884 GAA_LIST_FILL(GAATMP_comp.arg1, gaa_getstr, char*, GAATMP_comp.size1);
885 #line 95 "serv.gaa"
886 { gaaval->comp = GAATMP_comp.arg1; gaaval->ncomp = GAATMP_comp.size1 ;};
888 return GAA_OK;
889 break;
890 case GAAOPTID_protocols:
891 OK = 0;
892 GAA_LIST_FILL(GAATMP_protocols.arg1, gaa_getstr, char*, GAATMP_protocols.size1);
893 #line 91 "serv.gaa"
894 { gaaval->proto = GAATMP_protocols.arg1; gaaval->nproto = GAATMP_protocols.size1 ;};
896 return GAA_OK;
897 break;
898 case GAAOPTID_ciphers:
899 OK = 0;
900 GAA_LIST_FILL(GAATMP_ciphers.arg1, gaa_getstr, char*, GAATMP_ciphers.size1);
901 #line 87 "serv.gaa"
902 { gaaval->ciphers = GAATMP_ciphers.arg1; gaaval->nciphers = GAATMP_ciphers.size1 ;};
904 return GAA_OK;
905 break;
906 case GAAOPTID_authz_saml_assertion:
907 OK = 0;
908 GAA_TESTMOREARGS;
909 GAA_FILL(GAATMP_authz_saml_assertion.arg1, gaa_getstr, GAATMP_authz_saml_assertion.size1);
910 gaa_index++;
911 #line 83 "serv.gaa"
912 { gaaval->authz_saml_assertion = GAATMP_authz_saml_assertion.arg1 ;};
914 return GAA_OK;
915 break;
916 case GAAOPTID_authz_x509_attr_cert:
917 OK = 0;
918 GAA_TESTMOREARGS;
919 GAA_FILL(GAATMP_authz_x509_attr_cert.arg1, gaa_getstr, GAATMP_authz_x509_attr_cert.size1);
920 gaa_index++;
921 #line 80 "serv.gaa"
922 { gaaval->authz_x509_attr_cert = GAATMP_authz_x509_attr_cert.arg1 ;};
924 return GAA_OK;
925 break;
926 case GAAOPTID_srppasswdconf:
927 OK = 0;
928 GAA_TESTMOREARGS;
929 GAA_FILL(GAATMP_srppasswdconf.arg1, gaa_getstr, GAATMP_srppasswdconf.size1);
930 gaa_index++;
931 #line 77 "serv.gaa"
932 { gaaval->srp_passwd_conf = GAATMP_srppasswdconf.arg1 ;};
934 return GAA_OK;
935 break;
936 case GAAOPTID_srppasswd:
937 OK = 0;
938 GAA_TESTMOREARGS;
939 GAA_FILL(GAATMP_srppasswd.arg1, gaa_getstr, GAATMP_srppasswd.size1);
940 gaa_index++;
941 #line 74 "serv.gaa"
942 { gaaval->srp_passwd = GAATMP_srppasswd.arg1 ;};
944 return GAA_OK;
945 break;
946 case GAAOPTID_pskpasswd:
947 OK = 0;
948 GAA_TESTMOREARGS;
949 GAA_FILL(GAATMP_pskpasswd.arg1, gaa_getstr, GAATMP_pskpasswd.size1);
950 gaa_index++;
951 #line 71 "serv.gaa"
952 { gaaval->psk_passwd = GAATMP_pskpasswd.arg1 ;};
954 return GAA_OK;
955 break;
956 case GAAOPTID_require_cert:
957 OK = 0;
958 #line 68 "serv.gaa"
959 { gaaval->require_cert = 1 ;};
961 return GAA_OK;
962 break;
963 case GAAOPTID_x509dsacertfile:
964 OK = 0;
965 GAA_TESTMOREARGS;
966 GAA_FILL(GAATMP_x509dsacertfile.arg1, gaa_getstr, GAATMP_x509dsacertfile.size1);
967 gaa_index++;
968 #line 65 "serv.gaa"
969 { gaaval->x509_dsacertfile = GAATMP_x509dsacertfile.arg1 ;};
971 return GAA_OK;
972 break;
973 case GAAOPTID_x509dsakeyfile:
974 OK = 0;
975 GAA_TESTMOREARGS;
976 GAA_FILL(GAATMP_x509dsakeyfile.arg1, gaa_getstr, GAATMP_x509dsakeyfile.size1);
977 gaa_index++;
978 #line 62 "serv.gaa"
979 { gaaval->x509_dsakeyfile = GAATMP_x509dsakeyfile.arg1 ;};
981 return GAA_OK;
982 break;
983 case GAAOPTID_x509certfile:
984 OK = 0;
985 GAA_TESTMOREARGS;
986 GAA_FILL(GAATMP_x509certfile.arg1, gaa_getstr, GAATMP_x509certfile.size1);
987 gaa_index++;
988 #line 59 "serv.gaa"
989 { gaaval->x509_certfile = GAATMP_x509certfile.arg1 ;};
991 return GAA_OK;
992 break;
993 case GAAOPTID_x509keyfile:
994 OK = 0;
995 GAA_TESTMOREARGS;
996 GAA_FILL(GAATMP_x509keyfile.arg1, gaa_getstr, GAATMP_x509keyfile.size1);
997 gaa_index++;
998 #line 56 "serv.gaa"
999 { gaaval->x509_keyfile = GAATMP_x509keyfile.arg1 ;};
1001 return GAA_OK;
1002 break;
1003 case GAAOPTID_pgpcertfile:
1004 OK = 0;
1005 GAA_TESTMOREARGS;
1006 GAA_FILL(GAATMP_pgpcertfile.arg1, gaa_getstr, GAATMP_pgpcertfile.size1);
1007 gaa_index++;
1008 #line 53 "serv.gaa"
1009 { gaaval->pgp_certfile = GAATMP_pgpcertfile.arg1 ;};
1011 return GAA_OK;
1012 break;
1013 case GAAOPTID_pgpkeyfile:
1014 OK = 0;
1015 GAA_TESTMOREARGS;
1016 GAA_FILL(GAATMP_pgpkeyfile.arg1, gaa_getstr, GAATMP_pgpkeyfile.size1);
1017 gaa_index++;
1018 #line 50 "serv.gaa"
1019 { gaaval->pgp_keyfile = GAATMP_pgpkeyfile.arg1 ;};
1021 return GAA_OK;
1022 break;
1023 case GAAOPTID_pgptrustdb:
1024 OK = 0;
1025 GAA_TESTMOREARGS;
1026 GAA_FILL(GAATMP_pgptrustdb.arg1, gaa_getstr, GAATMP_pgptrustdb.size1);
1027 gaa_index++;
1028 #line 47 "serv.gaa"
1029 { gaaval->pgp_trustdb = GAATMP_pgptrustdb.arg1 ;};
1031 return GAA_OK;
1032 break;
1033 case GAAOPTID_pgpkeyring:
1034 OK = 0;
1035 GAA_TESTMOREARGS;
1036 GAA_FILL(GAATMP_pgpkeyring.arg1, gaa_getstr, GAATMP_pgpkeyring.size1);
1037 gaa_index++;
1038 #line 44 "serv.gaa"
1039 { gaaval->pgp_keyring = GAATMP_pgpkeyring.arg1 ;};
1041 return GAA_OK;
1042 break;
1043 case GAAOPTID_x509crlfile:
1044 OK = 0;
1045 GAA_TESTMOREARGS;
1046 GAA_FILL(GAATMP_x509crlfile.arg1, gaa_getstr, GAATMP_x509crlfile.size1);
1047 gaa_index++;
1048 #line 41 "serv.gaa"
1049 { gaaval->x509_crlfile = GAATMP_x509crlfile.arg1 ;};
1051 return GAA_OK;
1052 break;
1053 case GAAOPTID_x509cafile:
1054 OK = 0;
1055 GAA_TESTMOREARGS;
1056 GAA_FILL(GAATMP_x509cafile.arg1, gaa_getstr, GAATMP_x509cafile.size1);
1057 gaa_index++;
1058 #line 38 "serv.gaa"
1059 { gaaval->x509_cafile = GAATMP_x509cafile.arg1 ;};
1061 return GAA_OK;
1062 break;
1063 case GAAOPTID_x509fmtder:
1064 OK = 0;
1065 #line 35 "serv.gaa"
1066 { gaaval->fmtder = 1 ;};
1068 return GAA_OK;
1069 break;
1070 case GAAOPTID_dhparams:
1071 OK = 0;
1072 GAA_TESTMOREARGS;
1073 GAA_FILL(GAATMP_dhparams.arg1, gaa_getstr, GAATMP_dhparams.size1);
1074 gaa_index++;
1075 #line 32 "serv.gaa"
1076 { gaaval->dh_params_file = GAATMP_dhparams.arg1 ;};
1078 return GAA_OK;
1079 break;
1080 case GAAOPTID_echo:
1081 OK = 0;
1082 #line 29 "serv.gaa"
1083 { gaaval->http = 0 ;};
1085 return GAA_OK;
1086 break;
1087 case GAAOPTID_http:
1088 OK = 0;
1089 #line 28 "serv.gaa"
1090 { gaaval->http = 1 ;};
1092 return GAA_OK;
1093 break;
1094 case GAAOPTID_nodb:
1095 OK = 0;
1096 #line 25 "serv.gaa"
1097 { gaaval->nodb = 1 ;};
1099 return GAA_OK;
1100 break;
1101 case GAAOPTID_quiet:
1102 OK = 0;
1103 #line 22 "serv.gaa"
1104 { gaaval->quiet = 1 ;};
1106 return GAA_OK;
1107 break;
1108 case GAAOPTID_port:
1109 OK = 0;
1110 GAA_TESTMOREARGS;
1111 GAA_FILL(GAATMP_port.arg1, gaa_getint, GAATMP_port.size1);
1112 gaa_index++;
1113 #line 19 "serv.gaa"
1114 { gaaval->port = GAATMP_port.arg1 ;};
1116 return GAA_OK;
1117 break;
1118 case GAAOPTID_generate:
1119 OK = 0;
1120 #line 16 "serv.gaa"
1121 { gaaval->generate = 1 ;};
1123 return GAA_OK;
1124 break;
1125 case GAAOPTID_debug:
1126 OK = 0;
1127 GAA_TESTMOREARGS;
1128 GAA_FILL(GAATMP_debug.arg1, gaa_getint, GAATMP_debug.size1);
1129 gaa_index++;
1130 #line 13 "serv.gaa"
1131 { gaaval->debug = GAATMP_debug.arg1 ;};
1133 return GAA_OK;
1134 break;
1136 #line 413 "gaa.skel"
1137 default: break;
1139 return GAA_ERROR_UNKNOWN;
1142 int gaa(int argc, char **argv, gaainfo *gaaval)
1144 int tmp1, tmp2;
1145 int i, j;
1146 char *opt_list;
1148 GAAargv = argv;
1149 GAAargc = argc;
1151 opt_list = (char*) gaa_malloc(GAA_NB_OPTION + 1);
1153 for(i = 0; i < GAA_NB_OPTION + 1; i++)
1154 opt_list[i] = 0;
1155 /* initialization */
1156 if(inited == 0)
1159 #line 117 "serv.gaa"
1160 { gaaval->generate=0; gaaval->port=5556; gaaval->http=0; gaaval->ciphers=NULL;
1161 gaaval->kx=NULL; gaaval->comp=NULL; gaaval->macs=NULL; gaaval->ctype=NULL; gaaval->nciphers=0;
1162 gaaval->nkx=0; gaaval->ncomp=0; gaaval->nmacs=0; gaaval->nctype = 0; gaaval->nodb = 0;
1163 gaaval->x509_cafile = NULL; gaaval->pgp_keyfile=NULL; gaaval->pgp_certfile=NULL;
1164 gaaval->x509_keyfile=NULL; gaaval->x509_certfile=NULL; gaaval->x509_crlfile = NULL;
1165 gaaval->x509_dsakeyfile=NULL; gaaval->x509_dsacertfile=NULL;
1166 gaaval->srp_passwd=NULL; gaaval->srp_passwd_conf=NULL; gaaval->quiet = 0;
1167 gaaval->pgp_trustdb=NULL; gaaval->pgp_keyring=NULL; gaaval->fmtder = 0;
1168 gaaval->dh_params_file=NULL; gaaval->debug=0; gaaval->require_cert = 0; gaaval->psk_passwd = 0; ;};
1171 inited = 1;
1172 #line 438 "gaa.skel"
1173 gaa_arg_used = NULL;
1175 if (argc > 0) {
1176 gaa_arg_used = gaa_malloc(argc * sizeof(char));
1179 for(i = 1; i < argc; i++)
1180 gaa_arg_used[i] = 0;
1181 for(i = 1; i < argc; i++)
1183 if(gaa_arg_used[i] == 0)
1185 j = 0;
1186 tmp1 = gaa_is_an_argument(GAAargv[i]);
1187 switch(tmp1)
1189 case GAA_WORD_OPTION:
1190 j++;
1191 case GAA_LETTER_OPTION:
1192 j++;
1193 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
1194 if(tmp2 == GAA_ERROR_NOMATCH)
1196 printf("Invalid option '%s'\n", argv[i]+j);
1197 return 0;
1199 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
1201 case GAA_ERROR_NOTENOUGH_ARGS:
1202 printf("'%s': not enough arguments\n",gaa_current_option);
1203 return 0;
1204 case GAA_ERROR_INVALID_ARG:
1205 printf("Invalid arguments\n");
1206 return 0;
1207 case GAA_OK:
1208 break;
1209 default:
1210 printf("Unknown error\n");
1212 gaa_arg_used[i] = 1;
1213 break;
1214 case GAA_MULTIPLE_OPTION:
1215 for(j = 1; j < strlen(argv[i]); j++)
1217 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
1218 if(tmp2 == GAA_ERROR_NOMATCH)
1220 printf("Invalid option '%c'\n", *(argv[i]+j));
1221 return 0;
1223 switch(gaa_try(tmp2, i+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");
1237 gaa_arg_used[i] = 1;
1238 break;
1239 default: break;
1243 if(gaa_processing_file == 0)
1246 #line 507 "gaa.skel"
1247 #ifdef GAA_REST_EXISTS
1248 switch(gaa_try(GAA_REST, 1, gaaval, opt_list))
1250 case GAA_ERROR_NOTENOUGH_ARGS:
1251 printf("Rest: not enough arguments\n");
1252 return 0;
1253 case GAA_ERROR_INVALID_ARG:
1254 printf("Invalid arguments\n");
1255 return 0;
1256 case GAA_OK:
1257 break;
1258 default:
1259 printf("Unknown error\n");
1261 #endif
1263 for(i = 1; i < argc; i++)
1265 if(gaa_arg_used[i] == 0)
1267 printf("Too many arguments\n");
1268 return 0;
1271 free(gaa_arg_used);
1272 free(opt_list);
1273 return -1;
1276 struct gaastrnode
1278 char *str;
1279 struct gaastrnode *next;
1282 typedef struct gaastrnode gaa_str_node;
1284 static int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc)
1286 int pos_ini;
1287 int a;
1288 int i = 0, len = 0, newline = 0;
1290 if(argc == 1) {
1291 newline = 1;
1292 len = 2;
1295 a = fgetc( file);
1296 if (a == EOF) return 0;
1298 while(a == ' ' || a == 9 || a == '\n')
1300 if(a == '\n')
1302 newline=1;
1303 len = 2;
1305 a = fgetc( file);
1306 if (a == EOF) return 0;
1309 pos_ini = ftell(file) - 1;
1311 while(a != ' ' && a != 9 && a != '\n')
1314 len++;
1315 a = fgetc( file);
1316 if(a==EOF) return 0; /* a = ' '; */
1319 len += 1;
1320 tmp_str->str = gaa_malloc((len) * sizeof(char));
1322 if(newline == 1)
1324 tmp_str->str[0] = '-';
1325 tmp_str->str[1] = '-';
1326 i = 2;
1328 else
1330 i = 0;
1333 fseek(file,pos_ini, SEEK_SET);
1336 a = fgetc( file);
1338 if (a == EOF) {
1339 i+=2;
1340 break;
1342 tmp_str->str[i] = a;
1343 i++;
1345 while(a != ' ' && a != 9 && a != '\n' && i < len);
1347 tmp_str->str[i - 1] = 0;
1349 fseek(file,- 1, SEEK_CUR);
1350 /* printf("%d\n", ftell(file)); */
1352 return -1;
1355 int gaa_file(const char *name, gaainfo *gaaval)
1357 gaa_str_node *first_str, **tmp_str, *tmp_str2;
1358 int rval, i;
1359 char **argv;
1360 int argc = 0;
1361 FILE *file;
1363 gaa_processing_file = 1;
1365 if((file = fopen(name, "r")) == NULL)
1367 printf("Couldn't open '%s' configuration file for reading\n", name);
1368 return 1;
1371 tmp_str = &first_str;
1374 argc++;
1375 *tmp_str = gaa_malloc(sizeof(gaa_str_node));
1377 (*tmp_str)->str = NULL;
1378 (*tmp_str)->next = NULL;
1380 rval = gaa_internal_get_next_str(file, *tmp_str, argc);
1381 tmp_str = &((*tmp_str)->next);
1383 while(rval == -1);
1385 if(rval == 1)
1386 return 0;
1388 argv = gaa_malloc((1 + argc) * sizeof(char*));
1390 tmp_str2 = first_str;
1391 argv[0] = "cfg";
1392 for(i = 1; i < argc; i++)
1394 argv[i] = tmp_str2->str;
1395 tmp_str2 = tmp_str2->next;
1398 rval = gaa(argc, argv, gaaval);
1399 gaa_processing_file = 0;
1400 return rval;