Update `NEWS'.
[gnutls.git] / src / serv-gaa.c
blobcd1b11bf543dc84103bc6c1217c891eabef04395
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('r', "require-cert", "", "Require a valid certificate.");
148 __gaa_helpsingle('a', "disable-client-cert", "", "Disable request for a client certificate.");
149 __gaa_helpsingle(0, "pskpasswd", "FILE ", "PSK password file to use.");
150 __gaa_helpsingle(0, "srppasswd", "FILE ", "SRP password file to use.");
151 __gaa_helpsingle(0, "srppasswdconf", "FILE ", "SRP password conf file to use.");
152 __gaa_helpsingle(0, "authz-x509-attr-cert", "FILE ", "Use X.509 Attribute Certificate in FILE as authorization data.");
153 __gaa_helpsingle(0, "authz-saml-assertion", "FILE ", "Use SAML Assertion in FILE as authorization data.");
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('l', "list", "", "Print a list of the supported algorithms and modes.");
162 __gaa_helpsingle('h', "help", "", "prints this help");
163 __gaa_helpsingle('v', "version", "", "prints the program's version number");
164 __gaa_helpsingle(0, "copyright", "", "prints the program's license");
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 112 "serv.gaa"
180 char **ctype;
181 #line 111 "serv.gaa"
182 int nctype;
183 #line 108 "serv.gaa"
184 char **kx;
185 #line 107 "serv.gaa"
186 int nkx;
187 #line 104 "serv.gaa"
188 char **macs;
189 #line 103 "serv.gaa"
190 int nmacs;
191 #line 100 "serv.gaa"
192 char **comp;
193 #line 99 "serv.gaa"
194 int ncomp;
195 #line 96 "serv.gaa"
196 char **proto;
197 #line 95 "serv.gaa"
198 int nproto;
199 #line 92 "serv.gaa"
200 char **ciphers;
201 #line 91 "serv.gaa"
202 int nciphers;
203 #line 88 "serv.gaa"
204 char *opaque_prf_input;
205 #line 85 "serv.gaa"
206 char *authz_saml_assertion;
207 #line 82 "serv.gaa"
208 char *authz_x509_attr_cert;
209 #line 79 "serv.gaa"
210 char *srp_passwd_conf;
211 #line 76 "serv.gaa"
212 char *srp_passwd;
213 #line 73 "serv.gaa"
214 char *psk_passwd;
215 #line 70 "serv.gaa"
216 int disable_client_cert;
217 #line 67 "serv.gaa"
218 int require_cert;
219 #line 64 "serv.gaa"
220 char *x509_dsacertfile;
221 #line 61 "serv.gaa"
222 char *x509_dsakeyfile;
223 #line 58 "serv.gaa"
224 char *x509_certfile;
225 #line 55 "serv.gaa"
226 char *x509_keyfile;
227 #line 52 "serv.gaa"
228 char *pgp_certfile;
229 #line 49 "serv.gaa"
230 char *pgp_keyfile;
231 #line 46 "serv.gaa"
232 char *pgp_trustdb;
233 #line 43 "serv.gaa"
234 char *pgp_keyring;
235 #line 40 "serv.gaa"
236 char *x509_crlfile;
237 #line 37 "serv.gaa"
238 char *x509_cafile;
239 #line 34 "serv.gaa"
240 int fmtder;
241 #line 31 "serv.gaa"
242 char *dh_params_file;
243 #line 27 "serv.gaa"
244 int http;
245 #line 24 "serv.gaa"
246 int nodb;
247 #line 21 "serv.gaa"
248 int quiet;
249 #line 18 "serv.gaa"
250 int port;
251 #line 15 "serv.gaa"
252 int generate;
253 #line 12 "serv.gaa"
254 int debug;
256 #line 114 "gaa.skel"
259 #ifdef __cplusplus
260 extern "C"
262 #endif
264 int gaa(int argc, char *argv[], gaainfo *gaaval);
266 void gaa_help(void);
268 int gaa_file(const char *name, gaainfo *gaaval);
270 #ifdef __cplusplus
272 #endif
275 #endif
277 #line 135 "gaa.skel"
279 /* C declarations */
281 #define GAAERROR(x) \
283 gaa_error = 1; \
284 return x; \
287 static char *gaa_current_option;
288 static int gaa_error = 0;
290 /* Generated by gaa */
292 #include <string.h>
293 #include <stdlib.h>
296 #define GAA_OK -1
298 #define GAA_ERROR_NOMATCH 0
299 #define GAA_ERROR_NOTENOUGH_ARGS 1
300 #define GAA_ERROR_INVALID_ARG 2
301 #define GAA_ERROR_UNKNOWN 3
303 #define GAA_NOT_AN_OPTION 0
304 #define GAA_WORD_OPTION 1
305 #define GAA_LETTER_OPTION 2
306 #define GAA_MULTIPLE_OPTION 3
308 #define GAA_REST 0
309 #define GAA_NB_OPTION 37
310 #define GAAOPTID_copyright 1
311 #define GAAOPTID_version 2
312 #define GAAOPTID_help 3
313 #define GAAOPTID_list 4
314 #define GAAOPTID_ctypes 5
315 #define GAAOPTID_kx 6
316 #define GAAOPTID_macs 7
317 #define GAAOPTID_comp 8
318 #define GAAOPTID_protocols 9
319 #define GAAOPTID_ciphers 10
320 #define GAAOPTID_opaque_prf_input 11
321 #define GAAOPTID_authz_saml_assertion 12
322 #define GAAOPTID_authz_x509_attr_cert 13
323 #define GAAOPTID_srppasswdconf 14
324 #define GAAOPTID_srppasswd 15
325 #define GAAOPTID_pskpasswd 16
326 #define GAAOPTID_disable_client_cert 17
327 #define GAAOPTID_require_cert 18
328 #define GAAOPTID_x509dsacertfile 19
329 #define GAAOPTID_x509dsakeyfile 20
330 #define GAAOPTID_x509certfile 21
331 #define GAAOPTID_x509keyfile 22
332 #define GAAOPTID_pgpcertfile 23
333 #define GAAOPTID_pgpkeyfile 24
334 #define GAAOPTID_pgptrustdb 25
335 #define GAAOPTID_pgpkeyring 26
336 #define GAAOPTID_x509crlfile 27
337 #define GAAOPTID_x509cafile 28
338 #define GAAOPTID_x509fmtder 29
339 #define GAAOPTID_dhparams 30
340 #define GAAOPTID_echo 31
341 #define GAAOPTID_http 32
342 #define GAAOPTID_nodb 33
343 #define GAAOPTID_quiet 34
344 #define GAAOPTID_port 35
345 #define GAAOPTID_generate 36
346 #define GAAOPTID_debug 37
348 #line 168 "gaa.skel"
350 #define GAA_CHECK1STR(a,b) \
351 if(a[0] == str[0]) \
353 gaa_current_option = a; \
354 return b; \
357 #define GAA_CHECKSTR(a,b) \
358 if(strcmp(a,str) == 0) \
360 gaa_current_option = a; \
361 return b; \
364 #define GAA_TESTMOREARGS \
365 if(!OK) \
367 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
368 gaa_index++; \
369 if(gaa_last_non_option == gaa_index) \
370 return GAA_ERROR_NOTENOUGH_ARGS; \
373 #define GAA_TESTMOREOPTIONALARGS \
374 if(!OK) \
376 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
377 gaa_index++; \
378 if(gaa_last_non_option == gaa_index) \
379 OK = 1; \
382 #define GAA_FILL_2ARGS(target, func) \
383 target = func(GAAargv[gaa_index]); \
384 gaa_arg_used[gaa_index] = 1; \
385 if(gaa_error == 1) \
387 gaa_error = 0; \
388 return GAA_ERROR_INVALID_ARG; \
393 #define GAA_FILL(target, func, num) \
394 if(!OK) \
396 target = func(GAAargv[gaa_index]); \
397 gaa_arg_used[gaa_index] = 1; \
398 if(gaa_error == 1) \
400 gaa_error = 0; \
401 return GAA_ERROR_INVALID_ARG; \
403 num = 1; \
405 else \
407 num = 0; \
410 #define GAA_LIST_FILL(target, func, type ,num) \
411 if(!OK) \
413 num = 0; \
414 target = NULL; \
415 if ( gaa_last_non_option - gaa_index > 0) \
416 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
417 for(; gaa_index < gaa_last_non_option; gaa_index++) \
419 if(gaa_arg_used[gaa_index] == 0) \
421 GAA_FILL_2ARGS(target[num], func); \
422 num++; \
425 if(num == 0) \
426 return GAA_ERROR_NOTENOUGH_ARGS; \
429 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
430 if(!OK) \
432 num = 0; \
433 target = NULL; \
434 if ( gaa_last_non_option - gaa_index > 0) \
435 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
436 for(; gaa_index < gaa_last_non_option; gaa_index++) \
438 if(gaa_arg_used[gaa_index] == 0) \
440 GAA_FILL_2ARGS(target[num], func); \
441 num++; \
446 #define GAA_OBLIGAT(str) \
447 k = 0; \
448 for(i = 0; i < strlen(str); i++) \
450 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
451 if(j == GAA_ERROR_NOMATCH) \
453 printf("Error: invalid 'obligat' set\n"); \
454 exit(-1); \
456 if(opt_list[j] == 1) \
457 k = 1; \
459 if(k == 0) \
461 if(strlen(str) == 1) \
462 printf("You must give the -%s option\n", str); \
463 else \
464 printf("You must give at least one option of '%s'\n", str); \
465 return 0; \
468 #define GAA_INCOMP(str) \
469 k = 0; \
470 for(i = 0; i < strlen(str); i++) \
472 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
473 if(j == GAA_ERROR_NOMATCH) \
475 printf("Error: invalid 'obligat' set\n"); \
476 exit(-1); \
478 if(opt_list[j] == 1) \
479 k++; \
481 if(k > 1) \
483 printf("The options '%s' are incompatible\n", str); \
484 return 0; \
488 static char **GAAargv;
489 static int GAAargc;
490 static char *gaa_arg_used;
491 static int gaa_processing_file = 0;
492 static int inited = 0;
494 static int gaa_getint(char *arg)
496 int tmp;
497 char a;
498 if(sscanf(arg, "%d%c", &tmp, &a) < 1)
500 printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
501 GAAERROR(-1);
503 return tmp;
506 static char gaa_getchar(char *arg)
508 if(strlen(arg) != 1)
510 printf("Option %s: '%s' isn't an character\n", gaa_current_option, arg);
511 GAAERROR(-1);
513 return arg[0];
516 static char* gaa_getstr(char *arg)
518 return arg;
520 static float gaa_getfloat(char *arg)
522 float tmp;
523 char a;
524 if(sscanf(arg, "%f%c", &tmp, &a) < 1)
526 printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg);
527 GAAERROR(-1);
529 return tmp;
531 /* option structures */
533 struct GAAOPTION_ctypes
535 char** arg1;
536 int size1;
539 struct GAAOPTION_kx
541 char** arg1;
542 int size1;
545 struct GAAOPTION_macs
547 char** arg1;
548 int size1;
551 struct GAAOPTION_comp
553 char** arg1;
554 int size1;
557 struct GAAOPTION_protocols
559 char** arg1;
560 int size1;
563 struct GAAOPTION_ciphers
565 char** arg1;
566 int size1;
569 struct GAAOPTION_opaque_prf_input
571 char* arg1;
572 int size1;
575 struct GAAOPTION_authz_saml_assertion
577 char* arg1;
578 int size1;
581 struct GAAOPTION_authz_x509_attr_cert
583 char* arg1;
584 int size1;
587 struct GAAOPTION_srppasswdconf
589 char* arg1;
590 int size1;
593 struct GAAOPTION_srppasswd
595 char* arg1;
596 int size1;
599 struct GAAOPTION_pskpasswd
601 char* arg1;
602 int size1;
605 struct GAAOPTION_x509dsacertfile
607 char* arg1;
608 int size1;
611 struct GAAOPTION_x509dsakeyfile
613 char* arg1;
614 int size1;
617 struct GAAOPTION_x509certfile
619 char* arg1;
620 int size1;
623 struct GAAOPTION_x509keyfile
625 char* arg1;
626 int size1;
629 struct GAAOPTION_pgpcertfile
631 char* arg1;
632 int size1;
635 struct GAAOPTION_pgpkeyfile
637 char* arg1;
638 int size1;
641 struct GAAOPTION_pgptrustdb
643 char* arg1;
644 int size1;
647 struct GAAOPTION_pgpkeyring
649 char* arg1;
650 int size1;
653 struct GAAOPTION_x509crlfile
655 char* arg1;
656 int size1;
659 struct GAAOPTION_x509cafile
661 char* arg1;
662 int size1;
665 struct GAAOPTION_dhparams
667 char* arg1;
668 int size1;
671 struct GAAOPTION_port
673 int arg1;
674 int size1;
677 struct GAAOPTION_debug
679 int arg1;
680 int size1;
683 #line 349 "gaa.skel"
684 static int gaa_is_an_argument(char *str)
686 #ifdef GAA_WIN32
687 if(str[0] == '/' && str[1] != 0)
688 return GAA_MULTIPLE_OPTION;
689 #endif
690 if(str[0] != '-')
691 return GAA_NOT_AN_OPTION;
692 if(str[1] == 0)
693 return GAA_NOT_AN_OPTION;
694 if(str[1] == '-')
696 if(str[2] != 0)
697 return GAA_WORD_OPTION;
698 else
699 return GAA_NOT_AN_OPTION;
701 if(str[2] == 0)
702 return GAA_LETTER_OPTION;
703 else
704 return GAA_MULTIPLE_OPTION;
707 static int gaa_get_option_num(char *str, int status)
709 switch(status)
711 case GAA_LETTER_OPTION:
712 GAA_CHECK1STR("", GAAOPTID_ctypes);
713 GAA_CHECK1STR("", GAAOPTID_kx);
714 GAA_CHECK1STR("", GAAOPTID_macs);
715 GAA_CHECK1STR("", GAAOPTID_comp);
716 GAA_CHECK1STR("", GAAOPTID_protocols);
717 GAA_CHECK1STR("", GAAOPTID_ciphers);
718 GAA_CHECK1STR("", GAAOPTID_opaque_prf_input);
719 GAA_CHECK1STR("", GAAOPTID_authz_saml_assertion);
720 GAA_CHECK1STR("", GAAOPTID_authz_x509_attr_cert);
721 GAA_CHECK1STR("", GAAOPTID_srppasswdconf);
722 GAA_CHECK1STR("", GAAOPTID_srppasswd);
723 GAA_CHECK1STR("", GAAOPTID_pskpasswd);
724 GAA_CHECK1STR("", GAAOPTID_x509dsacertfile);
725 GAA_CHECK1STR("", GAAOPTID_x509dsakeyfile);
726 GAA_CHECK1STR("", GAAOPTID_x509certfile);
727 GAA_CHECK1STR("", GAAOPTID_x509keyfile);
728 GAA_CHECK1STR("", GAAOPTID_pgpcertfile);
729 GAA_CHECK1STR("", GAAOPTID_pgpkeyfile);
730 GAA_CHECK1STR("", GAAOPTID_pgptrustdb);
731 GAA_CHECK1STR("", GAAOPTID_pgpkeyring);
732 GAA_CHECK1STR("", GAAOPTID_x509crlfile);
733 GAA_CHECK1STR("", GAAOPTID_x509cafile);
734 GAA_CHECK1STR("", GAAOPTID_dhparams);
735 GAA_CHECK1STR("p", GAAOPTID_port);
736 GAA_CHECK1STR("d", GAAOPTID_debug);
737 case GAA_MULTIPLE_OPTION:
738 #line 375 "gaa.skel"
739 GAA_CHECK1STR("", GAAOPTID_copyright);
740 GAA_CHECK1STR("v", GAAOPTID_version);
741 GAA_CHECK1STR("h", GAAOPTID_help);
742 GAA_CHECK1STR("l", GAAOPTID_list);
743 GAA_CHECK1STR("a", GAAOPTID_disable_client_cert);
744 GAA_CHECK1STR("r", GAAOPTID_require_cert);
745 GAA_CHECK1STR("", GAAOPTID_x509fmtder);
746 GAA_CHECK1STR("", GAAOPTID_echo);
747 GAA_CHECK1STR("", GAAOPTID_http);
748 GAA_CHECK1STR("", GAAOPTID_nodb);
749 GAA_CHECK1STR("q", GAAOPTID_quiet);
750 GAA_CHECK1STR("g", GAAOPTID_generate);
752 #line 277 "gaa.skel"
753 break;
754 case GAA_WORD_OPTION:
755 GAA_CHECKSTR("copyright", GAAOPTID_copyright);
756 GAA_CHECKSTR("version", GAAOPTID_version);
757 GAA_CHECKSTR("help", GAAOPTID_help);
758 GAA_CHECKSTR("list", GAAOPTID_list);
759 GAA_CHECKSTR("ctypes", GAAOPTID_ctypes);
760 GAA_CHECKSTR("kx", GAAOPTID_kx);
761 GAA_CHECKSTR("macs", GAAOPTID_macs);
762 GAA_CHECKSTR("comp", GAAOPTID_comp);
763 GAA_CHECKSTR("protocols", GAAOPTID_protocols);
764 GAA_CHECKSTR("ciphers", GAAOPTID_ciphers);
765 GAA_CHECKSTR("opaque-prf-input", GAAOPTID_opaque_prf_input);
766 GAA_CHECKSTR("authz-saml-assertion", GAAOPTID_authz_saml_assertion);
767 GAA_CHECKSTR("authz-x509-attr-cert", GAAOPTID_authz_x509_attr_cert);
768 GAA_CHECKSTR("srppasswdconf", GAAOPTID_srppasswdconf);
769 GAA_CHECKSTR("srppasswd", GAAOPTID_srppasswd);
770 GAA_CHECKSTR("pskpasswd", GAAOPTID_pskpasswd);
771 GAA_CHECKSTR("disable-client-cert", GAAOPTID_disable_client_cert);
772 GAA_CHECKSTR("require-cert", GAAOPTID_require_cert);
773 GAA_CHECKSTR("x509dsacertfile", GAAOPTID_x509dsacertfile);
774 GAA_CHECKSTR("x509dsakeyfile", GAAOPTID_x509dsakeyfile);
775 GAA_CHECKSTR("x509certfile", GAAOPTID_x509certfile);
776 GAA_CHECKSTR("x509keyfile", GAAOPTID_x509keyfile);
777 GAA_CHECKSTR("pgpcertfile", GAAOPTID_pgpcertfile);
778 GAA_CHECKSTR("pgpkeyfile", GAAOPTID_pgpkeyfile);
779 GAA_CHECKSTR("pgptrustdb", GAAOPTID_pgptrustdb);
780 GAA_CHECKSTR("pgpkeyring", GAAOPTID_pgpkeyring);
781 GAA_CHECKSTR("x509crlfile", GAAOPTID_x509crlfile);
782 GAA_CHECKSTR("x509cafile", GAAOPTID_x509cafile);
783 GAA_CHECKSTR("x509fmtder", GAAOPTID_x509fmtder);
784 GAA_CHECKSTR("dhparams", GAAOPTID_dhparams);
785 GAA_CHECKSTR("echo", GAAOPTID_echo);
786 GAA_CHECKSTR("http", GAAOPTID_http);
787 GAA_CHECKSTR("nodb", GAAOPTID_nodb);
788 GAA_CHECKSTR("quiet", GAAOPTID_quiet);
789 GAA_CHECKSTR("port", GAAOPTID_port);
790 GAA_CHECKSTR("generate", GAAOPTID_generate);
791 GAA_CHECKSTR("debug", GAAOPTID_debug);
793 #line 281 "gaa.skel"
794 break;
795 default: break;
797 return GAA_ERROR_NOMATCH;
800 static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
802 int OK = 0;
803 int gaa_last_non_option;
804 struct GAAOPTION_ctypes GAATMP_ctypes;
805 struct GAAOPTION_kx GAATMP_kx;
806 struct GAAOPTION_macs GAATMP_macs;
807 struct GAAOPTION_comp GAATMP_comp;
808 struct GAAOPTION_protocols GAATMP_protocols;
809 struct GAAOPTION_ciphers GAATMP_ciphers;
810 struct GAAOPTION_opaque_prf_input GAATMP_opaque_prf_input;
811 struct GAAOPTION_authz_saml_assertion GAATMP_authz_saml_assertion;
812 struct GAAOPTION_authz_x509_attr_cert GAATMP_authz_x509_attr_cert;
813 struct GAAOPTION_srppasswdconf GAATMP_srppasswdconf;
814 struct GAAOPTION_srppasswd GAATMP_srppasswd;
815 struct GAAOPTION_pskpasswd GAATMP_pskpasswd;
816 struct GAAOPTION_x509dsacertfile GAATMP_x509dsacertfile;
817 struct GAAOPTION_x509dsakeyfile GAATMP_x509dsakeyfile;
818 struct GAAOPTION_x509certfile GAATMP_x509certfile;
819 struct GAAOPTION_x509keyfile GAATMP_x509keyfile;
820 struct GAAOPTION_pgpcertfile GAATMP_pgpcertfile;
821 struct GAAOPTION_pgpkeyfile GAATMP_pgpkeyfile;
822 struct GAAOPTION_pgptrustdb GAATMP_pgptrustdb;
823 struct GAAOPTION_pgpkeyring GAATMP_pgpkeyring;
824 struct GAAOPTION_x509crlfile GAATMP_x509crlfile;
825 struct GAAOPTION_x509cafile GAATMP_x509cafile;
826 struct GAAOPTION_dhparams GAATMP_dhparams;
827 struct GAAOPTION_port GAATMP_port;
828 struct GAAOPTION_debug GAATMP_debug;
830 #line 393 "gaa.skel"
831 #ifdef GAA_REST_EXISTS
832 struct GAAREST GAAREST_tmp;
833 #endif
835 opt_list[gaa_num] = 1;
837 for(gaa_last_non_option = gaa_index;
838 (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION);
839 gaa_last_non_option++);
841 if(gaa_num == GAA_REST)
843 gaa_index = 1;
844 gaa_last_non_option = GAAargc;
847 switch(gaa_num)
849 case GAAOPTID_copyright:
850 OK = 0;
851 #line 119 "serv.gaa"
852 { print_serv_license(); exit(0); ;};
854 return GAA_OK;
855 break;
856 case GAAOPTID_version:
857 OK = 0;
858 #line 118 "serv.gaa"
859 { serv_version(); exit(0); ;};
861 return GAA_OK;
862 break;
863 case GAAOPTID_help:
864 OK = 0;
865 #line 116 "serv.gaa"
866 { gaa_help(); exit(0); ;};
868 return GAA_OK;
869 break;
870 case GAAOPTID_list:
871 OK = 0;
872 #line 115 "serv.gaa"
873 { print_list(0); exit(0); ;};
875 return GAA_OK;
876 break;
877 case GAAOPTID_ctypes:
878 OK = 0;
879 GAA_LIST_FILL(GAATMP_ctypes.arg1, gaa_getstr, char*, GAATMP_ctypes.size1);
880 #line 113 "serv.gaa"
881 { gaaval->ctype = GAATMP_ctypes.arg1; gaaval->nctype = GAATMP_ctypes.size1 ;};
883 return GAA_OK;
884 break;
885 case GAAOPTID_kx:
886 OK = 0;
887 GAA_LIST_FILL(GAATMP_kx.arg1, gaa_getstr, char*, GAATMP_kx.size1);
888 #line 109 "serv.gaa"
889 { gaaval->kx = GAATMP_kx.arg1; gaaval->nkx = GAATMP_kx.size1 ;};
891 return GAA_OK;
892 break;
893 case GAAOPTID_macs:
894 OK = 0;
895 GAA_LIST_FILL(GAATMP_macs.arg1, gaa_getstr, char*, GAATMP_macs.size1);
896 #line 105 "serv.gaa"
897 { gaaval->macs = GAATMP_macs.arg1; gaaval->nmacs = GAATMP_macs.size1 ;};
899 return GAA_OK;
900 break;
901 case GAAOPTID_comp:
902 OK = 0;
903 GAA_LIST_FILL(GAATMP_comp.arg1, gaa_getstr, char*, GAATMP_comp.size1);
904 #line 101 "serv.gaa"
905 { gaaval->comp = GAATMP_comp.arg1; gaaval->ncomp = GAATMP_comp.size1 ;};
907 return GAA_OK;
908 break;
909 case GAAOPTID_protocols:
910 OK = 0;
911 GAA_LIST_FILL(GAATMP_protocols.arg1, gaa_getstr, char*, GAATMP_protocols.size1);
912 #line 97 "serv.gaa"
913 { gaaval->proto = GAATMP_protocols.arg1; gaaval->nproto = GAATMP_protocols.size1 ;};
915 return GAA_OK;
916 break;
917 case GAAOPTID_ciphers:
918 OK = 0;
919 GAA_LIST_FILL(GAATMP_ciphers.arg1, gaa_getstr, char*, GAATMP_ciphers.size1);
920 #line 93 "serv.gaa"
921 { gaaval->ciphers = GAATMP_ciphers.arg1; gaaval->nciphers = GAATMP_ciphers.size1 ;};
923 return GAA_OK;
924 break;
925 case GAAOPTID_opaque_prf_input:
926 OK = 0;
927 GAA_TESTMOREARGS;
928 GAA_FILL(GAATMP_opaque_prf_input.arg1, gaa_getstr, GAATMP_opaque_prf_input.size1);
929 gaa_index++;
930 #line 89 "serv.gaa"
931 { gaaval->opaque_prf_input = GAATMP_opaque_prf_input.arg1 ;};
933 return GAA_OK;
934 break;
935 case GAAOPTID_authz_saml_assertion:
936 OK = 0;
937 GAA_TESTMOREARGS;
938 GAA_FILL(GAATMP_authz_saml_assertion.arg1, gaa_getstr, GAATMP_authz_saml_assertion.size1);
939 gaa_index++;
940 #line 86 "serv.gaa"
941 { gaaval->authz_saml_assertion = GAATMP_authz_saml_assertion.arg1 ;};
943 return GAA_OK;
944 break;
945 case GAAOPTID_authz_x509_attr_cert:
946 OK = 0;
947 GAA_TESTMOREARGS;
948 GAA_FILL(GAATMP_authz_x509_attr_cert.arg1, gaa_getstr, GAATMP_authz_x509_attr_cert.size1);
949 gaa_index++;
950 #line 83 "serv.gaa"
951 { gaaval->authz_x509_attr_cert = GAATMP_authz_x509_attr_cert.arg1 ;};
953 return GAA_OK;
954 break;
955 case GAAOPTID_srppasswdconf:
956 OK = 0;
957 GAA_TESTMOREARGS;
958 GAA_FILL(GAATMP_srppasswdconf.arg1, gaa_getstr, GAATMP_srppasswdconf.size1);
959 gaa_index++;
960 #line 80 "serv.gaa"
961 { gaaval->srp_passwd_conf = GAATMP_srppasswdconf.arg1 ;};
963 return GAA_OK;
964 break;
965 case GAAOPTID_srppasswd:
966 OK = 0;
967 GAA_TESTMOREARGS;
968 GAA_FILL(GAATMP_srppasswd.arg1, gaa_getstr, GAATMP_srppasswd.size1);
969 gaa_index++;
970 #line 77 "serv.gaa"
971 { gaaval->srp_passwd = GAATMP_srppasswd.arg1 ;};
973 return GAA_OK;
974 break;
975 case GAAOPTID_pskpasswd:
976 OK = 0;
977 GAA_TESTMOREARGS;
978 GAA_FILL(GAATMP_pskpasswd.arg1, gaa_getstr, GAATMP_pskpasswd.size1);
979 gaa_index++;
980 #line 74 "serv.gaa"
981 { gaaval->psk_passwd = GAATMP_pskpasswd.arg1 ;};
983 return GAA_OK;
984 break;
985 case GAAOPTID_disable_client_cert:
986 OK = 0;
987 #line 71 "serv.gaa"
988 { gaaval->disable_client_cert = 1 ;};
990 return GAA_OK;
991 break;
992 case GAAOPTID_require_cert:
993 OK = 0;
994 #line 68 "serv.gaa"
995 { gaaval->require_cert = 1 ;};
997 return GAA_OK;
998 break;
999 case GAAOPTID_x509dsacertfile:
1000 OK = 0;
1001 GAA_TESTMOREARGS;
1002 GAA_FILL(GAATMP_x509dsacertfile.arg1, gaa_getstr, GAATMP_x509dsacertfile.size1);
1003 gaa_index++;
1004 #line 65 "serv.gaa"
1005 { gaaval->x509_dsacertfile = GAATMP_x509dsacertfile.arg1 ;};
1007 return GAA_OK;
1008 break;
1009 case GAAOPTID_x509dsakeyfile:
1010 OK = 0;
1011 GAA_TESTMOREARGS;
1012 GAA_FILL(GAATMP_x509dsakeyfile.arg1, gaa_getstr, GAATMP_x509dsakeyfile.size1);
1013 gaa_index++;
1014 #line 62 "serv.gaa"
1015 { gaaval->x509_dsakeyfile = GAATMP_x509dsakeyfile.arg1 ;};
1017 return GAA_OK;
1018 break;
1019 case GAAOPTID_x509certfile:
1020 OK = 0;
1021 GAA_TESTMOREARGS;
1022 GAA_FILL(GAATMP_x509certfile.arg1, gaa_getstr, GAATMP_x509certfile.size1);
1023 gaa_index++;
1024 #line 59 "serv.gaa"
1025 { gaaval->x509_certfile = GAATMP_x509certfile.arg1 ;};
1027 return GAA_OK;
1028 break;
1029 case GAAOPTID_x509keyfile:
1030 OK = 0;
1031 GAA_TESTMOREARGS;
1032 GAA_FILL(GAATMP_x509keyfile.arg1, gaa_getstr, GAATMP_x509keyfile.size1);
1033 gaa_index++;
1034 #line 56 "serv.gaa"
1035 { gaaval->x509_keyfile = GAATMP_x509keyfile.arg1 ;};
1037 return GAA_OK;
1038 break;
1039 case GAAOPTID_pgpcertfile:
1040 OK = 0;
1041 GAA_TESTMOREARGS;
1042 GAA_FILL(GAATMP_pgpcertfile.arg1, gaa_getstr, GAATMP_pgpcertfile.size1);
1043 gaa_index++;
1044 #line 53 "serv.gaa"
1045 { gaaval->pgp_certfile = GAATMP_pgpcertfile.arg1 ;};
1047 return GAA_OK;
1048 break;
1049 case GAAOPTID_pgpkeyfile:
1050 OK = 0;
1051 GAA_TESTMOREARGS;
1052 GAA_FILL(GAATMP_pgpkeyfile.arg1, gaa_getstr, GAATMP_pgpkeyfile.size1);
1053 gaa_index++;
1054 #line 50 "serv.gaa"
1055 { gaaval->pgp_keyfile = GAATMP_pgpkeyfile.arg1 ;};
1057 return GAA_OK;
1058 break;
1059 case GAAOPTID_pgptrustdb:
1060 OK = 0;
1061 GAA_TESTMOREARGS;
1062 GAA_FILL(GAATMP_pgptrustdb.arg1, gaa_getstr, GAATMP_pgptrustdb.size1);
1063 gaa_index++;
1064 #line 47 "serv.gaa"
1065 { gaaval->pgp_trustdb = GAATMP_pgptrustdb.arg1 ;};
1067 return GAA_OK;
1068 break;
1069 case GAAOPTID_pgpkeyring:
1070 OK = 0;
1071 GAA_TESTMOREARGS;
1072 GAA_FILL(GAATMP_pgpkeyring.arg1, gaa_getstr, GAATMP_pgpkeyring.size1);
1073 gaa_index++;
1074 #line 44 "serv.gaa"
1075 { gaaval->pgp_keyring = GAATMP_pgpkeyring.arg1 ;};
1077 return GAA_OK;
1078 break;
1079 case GAAOPTID_x509crlfile:
1080 OK = 0;
1081 GAA_TESTMOREARGS;
1082 GAA_FILL(GAATMP_x509crlfile.arg1, gaa_getstr, GAATMP_x509crlfile.size1);
1083 gaa_index++;
1084 #line 41 "serv.gaa"
1085 { gaaval->x509_crlfile = GAATMP_x509crlfile.arg1 ;};
1087 return GAA_OK;
1088 break;
1089 case GAAOPTID_x509cafile:
1090 OK = 0;
1091 GAA_TESTMOREARGS;
1092 GAA_FILL(GAATMP_x509cafile.arg1, gaa_getstr, GAATMP_x509cafile.size1);
1093 gaa_index++;
1094 #line 38 "serv.gaa"
1095 { gaaval->x509_cafile = GAATMP_x509cafile.arg1 ;};
1097 return GAA_OK;
1098 break;
1099 case GAAOPTID_x509fmtder:
1100 OK = 0;
1101 #line 35 "serv.gaa"
1102 { gaaval->fmtder = 1 ;};
1104 return GAA_OK;
1105 break;
1106 case GAAOPTID_dhparams:
1107 OK = 0;
1108 GAA_TESTMOREARGS;
1109 GAA_FILL(GAATMP_dhparams.arg1, gaa_getstr, GAATMP_dhparams.size1);
1110 gaa_index++;
1111 #line 32 "serv.gaa"
1112 { gaaval->dh_params_file = GAATMP_dhparams.arg1 ;};
1114 return GAA_OK;
1115 break;
1116 case GAAOPTID_echo:
1117 OK = 0;
1118 #line 29 "serv.gaa"
1119 { gaaval->http = 0 ;};
1121 return GAA_OK;
1122 break;
1123 case GAAOPTID_http:
1124 OK = 0;
1125 #line 28 "serv.gaa"
1126 { gaaval->http = 1 ;};
1128 return GAA_OK;
1129 break;
1130 case GAAOPTID_nodb:
1131 OK = 0;
1132 #line 25 "serv.gaa"
1133 { gaaval->nodb = 1 ;};
1135 return GAA_OK;
1136 break;
1137 case GAAOPTID_quiet:
1138 OK = 0;
1139 #line 22 "serv.gaa"
1140 { gaaval->quiet = 1 ;};
1142 return GAA_OK;
1143 break;
1144 case GAAOPTID_port:
1145 OK = 0;
1146 GAA_TESTMOREARGS;
1147 GAA_FILL(GAATMP_port.arg1, gaa_getint, GAATMP_port.size1);
1148 gaa_index++;
1149 #line 19 "serv.gaa"
1150 { gaaval->port = GAATMP_port.arg1 ;};
1152 return GAA_OK;
1153 break;
1154 case GAAOPTID_generate:
1155 OK = 0;
1156 #line 16 "serv.gaa"
1157 { gaaval->generate = 1 ;};
1159 return GAA_OK;
1160 break;
1161 case GAAOPTID_debug:
1162 OK = 0;
1163 GAA_TESTMOREARGS;
1164 GAA_FILL(GAATMP_debug.arg1, gaa_getint, GAATMP_debug.size1);
1165 gaa_index++;
1166 #line 13 "serv.gaa"
1167 { gaaval->debug = GAATMP_debug.arg1 ;};
1169 return GAA_OK;
1170 break;
1172 #line 413 "gaa.skel"
1173 default: break;
1175 return GAA_ERROR_UNKNOWN;
1178 int gaa(int argc, char **argv, gaainfo *gaaval)
1180 int tmp1, tmp2;
1181 int i, j, k;
1182 char *opt_list;
1184 GAAargv = argv;
1185 GAAargc = argc;
1187 opt_list = (char*) gaa_malloc(GAA_NB_OPTION + 1);
1189 for(i = 0; i < GAA_NB_OPTION + 1; i++)
1190 opt_list[i] = 0;
1191 /* initialization */
1192 if(inited == 0)
1195 #line 123 "serv.gaa"
1196 { gaaval->generate=0; gaaval->port=5556; gaaval->http=0; gaaval->ciphers=NULL;
1197 gaaval->kx=NULL; gaaval->comp=NULL; gaaval->macs=NULL; gaaval->ctype=NULL; gaaval->nciphers=0;
1198 gaaval->nkx=0; gaaval->ncomp=0; gaaval->nmacs=0; gaaval->nctype = 0; gaaval->nodb = 0;
1199 gaaval->x509_cafile = NULL; gaaval->pgp_keyfile=NULL; gaaval->pgp_certfile=NULL;
1200 gaaval->x509_keyfile=NULL; gaaval->x509_certfile=NULL; gaaval->x509_crlfile = NULL;
1201 gaaval->x509_dsakeyfile=NULL; gaaval->x509_dsacertfile=NULL;
1202 gaaval->srp_passwd=NULL; gaaval->srp_passwd_conf=NULL; gaaval->quiet = 0;
1203 gaaval->pgp_trustdb=NULL; gaaval->pgp_keyring=NULL; gaaval->fmtder = 0;
1204 gaaval->disable_client_cert = 0;
1205 gaaval->dh_params_file=NULL; gaaval->debug=0; gaaval->require_cert = 0; gaaval->psk_passwd = 0;
1206 gaaval->authz_x509_attr_cert = NULL; gaaval->authz_saml_assertion = NULL;
1207 gaaval->opaque_prf_input=NULL; ;};
1210 inited = 1;
1211 #line 438 "gaa.skel"
1212 gaa_arg_used = NULL;
1214 if (argc > 0) {
1215 gaa_arg_used = gaa_malloc(argc * sizeof(char));
1218 for(i = 1; i < argc; i++)
1219 gaa_arg_used[i] = 0;
1220 for(i = 1; i < argc; i++)
1222 if(gaa_arg_used[i] == 0)
1224 j = 0;
1225 tmp1 = gaa_is_an_argument(GAAargv[i]);
1226 switch(tmp1)
1228 case GAA_WORD_OPTION:
1229 j++;
1230 case GAA_LETTER_OPTION:
1231 j++;
1232 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
1233 if(tmp2 == GAA_ERROR_NOMATCH)
1235 printf("Invalid option '%s'\n", argv[i]+j);
1236 return 0;
1238 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
1240 case GAA_ERROR_NOTENOUGH_ARGS:
1241 printf("'%s': not enough arguments\n",gaa_current_option);
1242 return 0;
1243 case GAA_ERROR_INVALID_ARG:
1244 printf("Invalid arguments\n");
1245 return 0;
1246 case GAA_OK:
1247 break;
1248 default:
1249 printf("Unknown error\n");
1251 gaa_arg_used[i] = 1;
1252 break;
1253 case GAA_MULTIPLE_OPTION:
1254 for(j = 1; j < strlen(argv[i]); j++)
1256 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
1257 if(tmp2 == GAA_ERROR_NOMATCH)
1259 printf("Invalid option '%c'\n", *(argv[i]+j));
1260 return 0;
1262 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
1264 case GAA_ERROR_NOTENOUGH_ARGS:
1265 printf("'%s': not enough arguments\n",gaa_current_option);
1266 return 0;
1267 case GAA_ERROR_INVALID_ARG:
1268 printf("Invalid arguments\n");
1269 return 0;
1270 case GAA_OK:
1271 break;
1272 default:
1273 printf("Unknown error\n");
1276 gaa_arg_used[i] = 1;
1277 break;
1278 default: break;
1282 if(gaa_processing_file == 0)
1284 GAA_INCOMP("ra");
1286 #line 507 "gaa.skel"
1287 #ifdef GAA_REST_EXISTS
1288 switch(gaa_try(GAA_REST, 1, gaaval, opt_list))
1290 case GAA_ERROR_NOTENOUGH_ARGS:
1291 printf("Rest: not enough arguments\n");
1292 return 0;
1293 case GAA_ERROR_INVALID_ARG:
1294 printf("Invalid arguments\n");
1295 return 0;
1296 case GAA_OK:
1297 break;
1298 default:
1299 printf("Unknown error\n");
1301 #endif
1303 for(i = 1; i < argc; i++)
1305 if(gaa_arg_used[i] == 0)
1307 printf("Too many arguments\n");
1308 return 0;
1311 free(gaa_arg_used);
1312 free(opt_list);
1313 return -1;
1316 struct gaastrnode
1318 char *str;
1319 struct gaastrnode *next;
1322 typedef struct gaastrnode gaa_str_node;
1324 static int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc)
1326 int pos_ini;
1327 int a;
1328 int i = 0, len = 0, newline = 0;
1330 if(argc == 1) {
1331 newline = 1;
1332 len = 2;
1335 a = fgetc( file);
1336 if (a == EOF) return 0;
1338 while(a == ' ' || a == 9 || a == '\n')
1340 if(a == '\n')
1342 newline=1;
1343 len = 2;
1345 a = fgetc( file);
1346 if (a == EOF) return 0;
1349 pos_ini = ftell(file) - 1;
1351 while(a != ' ' && a != 9 && a != '\n')
1354 len++;
1355 a = fgetc( file);
1356 if(a==EOF) return 0; /* a = ' '; */
1359 len += 1;
1360 tmp_str->str = gaa_malloc((len) * sizeof(char));
1362 if(newline == 1)
1364 tmp_str->str[0] = '-';
1365 tmp_str->str[1] = '-';
1366 i = 2;
1368 else
1370 i = 0;
1373 fseek(file,pos_ini, SEEK_SET);
1376 a = fgetc( file);
1378 if (a == EOF) {
1379 i+=2;
1380 break;
1382 tmp_str->str[i] = a;
1383 i++;
1385 while(a != ' ' && a != 9 && a != '\n' && i < len);
1387 tmp_str->str[i - 1] = 0;
1389 fseek(file,- 1, SEEK_CUR);
1390 /* printf("%d\n", ftell(file)); */
1392 return -1;
1395 int gaa_file(const char *name, gaainfo *gaaval)
1397 gaa_str_node *first_str, **tmp_str, *tmp_str2;
1398 int rval, i;
1399 char **argv;
1400 int argc = 0;
1401 FILE *file;
1403 gaa_processing_file = 1;
1405 if((file = fopen(name, "r")) == NULL)
1407 printf("Couldn't open '%s' configuration file for reading\n", name);
1408 return 1;
1411 tmp_str = &first_str;
1414 argc++;
1415 *tmp_str = gaa_malloc(sizeof(gaa_str_node));
1417 (*tmp_str)->str = NULL;
1418 (*tmp_str)->next = NULL;
1420 rval = gaa_internal_get_next_str(file, *tmp_str, argc);
1421 tmp_str = &((*tmp_str)->next);
1423 while(rval == -1);
1425 if(rval == 1)
1426 return 0;
1428 argv = gaa_malloc((1 + argc) * sizeof(char*));
1430 tmp_str2 = first_str;
1431 argv[0] = "cfg";
1432 for(i = 1; i < argc; i++)
1434 argv[i] = tmp_str2->str;
1435 tmp_str2 = tmp_str2->next;
1438 rval = gaa(argc, argv, gaaval);
1439 gaa_processing_file = 0;
1440 return rval;