Use get_cert_callback() in server side.
[gnutls.git] / src / crypt-gaa.c
blobf83cf9d2748bac83c43f763e8764bcff585ed944
1 /* File generated by GAA 1.6.6
2 */
3 #define GAA_NO_WIN32
4 #line 1 "crypt.gaa"
7 /* C declarations */
9 #include <config.h>
10 #ifdef _WIN32
11 # include <io.h>
12 #endif
14 void srptool_version(void);
16 #include <stdio.h>
17 #include <string.h>
18 #include <stdlib.h>
20 #ifndef GAA_NO_WIN32
21 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(WINDOWS)
22 #define GAA_WIN32
23 #endif
24 #endif
26 static void* gaa_malloc( size_t size) {
27 void* ret;
28 ret = malloc(size);
29 if (ret==NULL) {
30 fprintf(stderr, "gaa: could not allocate memory");
31 exit(1);
33 return ret;
36 static void __gaa_helpsingle(char short_name, char *name,
37 char *arg_desc, char *opt_help)
39 int col1, col3, col4, tabsize = 3, curr;
40 int i;
42 col1 = 5; /* Default values */
43 col3 = 30;
44 col4 = 70;
46 curr = 0;
47 for(i = 0; i < col1; i++)
49 printf(" ");
50 curr++;
52 if(short_name)
54 if(name && *name)
56 printf("-%c, ", short_name);
57 curr += 4;
59 else
61 printf("-%c ", short_name);
62 curr += 3;
65 if(name && *name)
67 printf("--%s ", name);
68 curr += 3 + strlen(name);
70 if(arg_desc && *arg_desc)
72 printf("%s ", arg_desc);
73 curr += 1 + strlen(arg_desc);
75 if(curr >= col3)
77 printf("\n");
78 curr = 0;
80 if(opt_help) /* let's print the option's help body */
82 const char *str = opt_help;
83 while(*str)
85 while(curr < col3)
87 printf(" ");
88 curr++;
90 switch(*str)
92 case '\n':
93 printf("\n");
94 curr = 0;
95 break;
96 case '\t':
99 printf(" ");
100 curr++;
102 while((curr - col3) % tabsize != 0 && curr < col4);
103 case ' ':
104 if(*str == ' ')
106 curr++;
107 printf(" ");
109 for(i = 1; str[i] && str[i] != ' ' && str[i] != '\n'
110 && str[i] != '\t'; i++);
111 if(curr + i - 1 >= col4)
112 curr = col4;
113 break;
114 default:
115 printf("%c", *str);
116 curr++;
118 if(curr >= col4)
120 printf("\n");
121 curr = 0;
123 str++;
126 printf("\n");
129 void gaa_help(void)
131 printf("Srptool help\nUsage : srptool [options]\n");
132 __gaa_helpsingle('d', "debug", "integer ", "Enable debugging");
133 __gaa_helpsingle('u', "username", "username ", "specify username.");
134 __gaa_helpsingle('p', "passwd", "FILE ", "specify a password file.");
135 __gaa_helpsingle('i', "index", "INDEX ", "specify the index of the group parameters in tpasswd.conf to use.");
136 __gaa_helpsingle('s', "salt", "SALT ", "specify salt size for crypt algorithm.");
137 __gaa_helpsingle(0, "verify", "", "just verify password.");
138 __gaa_helpsingle('c', "passwd-conf", "FILE ", "specify a password conf file.");
139 __gaa_helpsingle(0, "create-conf", "FILE ", "Generate a tpasswd.conf file.");
140 __gaa_helpsingle('v', "version", "", "prints the program's version number");
141 __gaa_helpsingle('h', "help", "", "shows this help text");
143 #line 100 "gaa.skel"
145 /* Copy of C area */
147 #line 104 "gaa.skel"
148 /* GAA HEADER */
149 #ifndef GAA_HEADER_POKY
150 #define GAA_HEADER_POKY
152 typedef struct _gaainfo gaainfo;
154 struct _gaainfo
156 #line 37 "crypt.gaa"
157 char *create_conf;
158 #line 34 "crypt.gaa"
159 char *passwd_conf;
160 #line 31 "crypt.gaa"
161 int verify;
162 #line 28 "crypt.gaa"
163 int salt;
164 #line 25 "crypt.gaa"
165 int index;
166 #line 22 "crypt.gaa"
167 char *passwd;
168 #line 19 "crypt.gaa"
169 char *username;
170 #line 16 "crypt.gaa"
171 int debug;
173 #line 114 "gaa.skel"
176 #ifdef __cplusplus
177 extern "C"
179 #endif
181 int gaa(int argc, char *argv[], gaainfo *gaaval);
183 void gaa_help(void);
185 int gaa_file(const char *name, gaainfo *gaaval);
187 #ifdef __cplusplus
189 #endif
192 #endif
194 #line 135 "gaa.skel"
196 /* C declarations */
198 #define GAAERROR(x) \
200 gaa_error = 1; \
201 return x; \
204 static char *gaa_current_option;
205 static int gaa_error = 0;
207 /* Generated by gaa */
209 #include <string.h>
210 #include <stdlib.h>
213 #define GAA_OK -1
215 #define GAA_ERROR_NOMATCH 0
216 #define GAA_ERROR_NOTENOUGH_ARGS 1
217 #define GAA_ERROR_INVALID_ARG 2
218 #define GAA_ERROR_UNKNOWN 3
220 #define GAA_NOT_AN_OPTION 0
221 #define GAA_WORD_OPTION 1
222 #define GAA_LETTER_OPTION 2
223 #define GAA_MULTIPLE_OPTION 3
225 #define GAA_REST 0
226 #define GAA_NB_OPTION 10
227 #define GAAOPTID_help 1
228 #define GAAOPTID_version 2
229 #define GAAOPTID_create_conf 3
230 #define GAAOPTID_passwd_conf 4
231 #define GAAOPTID_verify 5
232 #define GAAOPTID_salt 6
233 #define GAAOPTID_index 7
234 #define GAAOPTID_passwd 8
235 #define GAAOPTID_username 9
236 #define GAAOPTID_debug 10
238 #line 168 "gaa.skel"
240 #define GAA_CHECK1STR(a,b) \
241 if(a[0] == str[0]) \
243 gaa_current_option = a; \
244 return b; \
247 #define GAA_CHECKSTR(a,b) \
248 if(strcmp(a,str) == 0) \
250 gaa_current_option = a; \
251 return b; \
254 #define GAA_TESTMOREARGS \
255 if(!OK) \
257 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
258 gaa_index++; \
259 if(gaa_last_non_option == gaa_index) \
260 return GAA_ERROR_NOTENOUGH_ARGS; \
263 #define GAA_TESTMOREOPTIONALARGS \
264 if(!OK) \
266 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
267 gaa_index++; \
268 if(gaa_last_non_option == gaa_index) \
269 OK = 1; \
272 #define GAA_FILL_2ARGS(target, func) \
273 target = func(GAAargv[gaa_index]); \
274 gaa_arg_used[gaa_index] = 1; \
275 if(gaa_error == 1) \
277 gaa_error = 0; \
278 return GAA_ERROR_INVALID_ARG; \
283 #define GAA_FILL(target, func, num) \
284 if(!OK) \
286 target = func(GAAargv[gaa_index]); \
287 gaa_arg_used[gaa_index] = 1; \
288 if(gaa_error == 1) \
290 gaa_error = 0; \
291 return GAA_ERROR_INVALID_ARG; \
293 num = 1; \
295 else \
297 num = 0; \
300 #define GAA_LIST_FILL(target, func, type ,num) \
301 if(!OK) \
303 num = 0; \
304 target = NULL; \
305 if ( gaa_last_non_option - gaa_index > 0) \
306 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
307 for(; gaa_index < gaa_last_non_option; gaa_index++) \
309 if(gaa_arg_used[gaa_index] == 0) \
311 GAA_FILL_2ARGS(target[num], func); \
312 num++; \
315 if(num == 0) \
316 return GAA_ERROR_NOTENOUGH_ARGS; \
319 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
320 if(!OK) \
322 num = 0; \
323 target = NULL; \
324 if ( gaa_last_non_option - gaa_index > 0) \
325 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
326 for(; gaa_index < gaa_last_non_option; gaa_index++) \
328 if(gaa_arg_used[gaa_index] == 0) \
330 GAA_FILL_2ARGS(target[num], func); \
331 num++; \
336 #define GAA_OBLIGAT(str) \
337 k = 0; \
338 for(i = 0; i < strlen(str); i++) \
340 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
341 if(j == GAA_ERROR_NOMATCH) \
343 printf("Error: invalid 'obligat' set\n"); \
344 exit(-1); \
346 if(opt_list[j] == 1) \
347 k = 1; \
349 if(k == 0) \
351 if(strlen(str) == 1) \
352 printf("You must give the -%s option\n", str); \
353 else \
354 printf("You must give at least one option of '%s'\n", str); \
355 return 0; \
358 #define GAA_INCOMP(str) \
359 k = 0; \
360 for(i = 0; i < strlen(str); i++) \
362 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
363 if(j == GAA_ERROR_NOMATCH) \
365 printf("Error: invalid 'obligat' set\n"); \
366 exit(-1); \
368 if(opt_list[j] == 1) \
369 k++; \
371 if(k > 1) \
373 printf("The options '%s' are incompatible\n", str); \
374 return 0; \
378 static char **GAAargv;
379 static int GAAargc;
380 static char *gaa_arg_used;
381 static int gaa_processing_file = 0;
382 static int inited = 0;
384 static int gaa_getint(char *arg)
386 int tmp;
387 char a;
388 if(sscanf(arg, "%d%c", &tmp, &a) < 1)
390 printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
391 GAAERROR(-1);
393 return tmp;
396 static char gaa_getchar(char *arg)
398 if(strlen(arg) != 1)
400 printf("Option %s: '%s' isn't an character\n", gaa_current_option, arg);
401 GAAERROR(-1);
403 return arg[0];
406 static char* gaa_getstr(char *arg)
408 return arg;
410 static float gaa_getfloat(char *arg)
412 float tmp;
413 char a;
414 if(sscanf(arg, "%f%c", &tmp, &a) < 1)
416 printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg);
417 GAAERROR(-1);
419 return tmp;
421 /* option structures */
423 struct GAAOPTION_create_conf
425 char* arg1;
426 int size1;
429 struct GAAOPTION_passwd_conf
431 char* arg1;
432 int size1;
435 struct GAAOPTION_salt
437 int arg1;
438 int size1;
441 struct GAAOPTION_index
443 int arg1;
444 int size1;
447 struct GAAOPTION_passwd
449 char* arg1;
450 int size1;
453 struct GAAOPTION_username
455 char* arg1;
456 int size1;
459 struct GAAOPTION_debug
461 int arg1;
462 int size1;
465 #line 349 "gaa.skel"
466 static int gaa_is_an_argument(char *str)
468 #ifdef GAA_WIN32
469 if(str[0] == '/' && str[1] != 0)
470 return GAA_MULTIPLE_OPTION;
471 #endif
472 if(str[0] != '-')
473 return GAA_NOT_AN_OPTION;
474 if(str[1] == 0)
475 return GAA_NOT_AN_OPTION;
476 if(str[1] == '-')
478 if(str[2] != 0)
479 return GAA_WORD_OPTION;
480 else
481 return GAA_NOT_AN_OPTION;
483 if(str[2] == 0)
484 return GAA_LETTER_OPTION;
485 else
486 return GAA_MULTIPLE_OPTION;
489 static int gaa_get_option_num(char *str, int status)
491 switch(status)
493 case GAA_LETTER_OPTION:
494 GAA_CHECK1STR("", GAAOPTID_create_conf);
495 GAA_CHECK1STR("c", GAAOPTID_passwd_conf);
496 GAA_CHECK1STR("s", GAAOPTID_salt);
497 GAA_CHECK1STR("i", GAAOPTID_index);
498 GAA_CHECK1STR("p", GAAOPTID_passwd);
499 GAA_CHECK1STR("u", GAAOPTID_username);
500 GAA_CHECK1STR("d", GAAOPTID_debug);
501 case GAA_MULTIPLE_OPTION:
502 #line 375 "gaa.skel"
503 GAA_CHECK1STR("h", GAAOPTID_help);
504 GAA_CHECK1STR("v", GAAOPTID_version);
505 GAA_CHECK1STR("", GAAOPTID_verify);
507 #line 277 "gaa.skel"
508 break;
509 case GAA_WORD_OPTION:
510 GAA_CHECKSTR("help", GAAOPTID_help);
511 GAA_CHECKSTR("version", GAAOPTID_version);
512 GAA_CHECKSTR("create-conf", GAAOPTID_create_conf);
513 GAA_CHECKSTR("passwd-conf", GAAOPTID_passwd_conf);
514 GAA_CHECKSTR("verify", GAAOPTID_verify);
515 GAA_CHECKSTR("salt", GAAOPTID_salt);
516 GAA_CHECKSTR("index", GAAOPTID_index);
517 GAA_CHECKSTR("passwd", GAAOPTID_passwd);
518 GAA_CHECKSTR("username", GAAOPTID_username);
519 GAA_CHECKSTR("debug", GAAOPTID_debug);
521 #line 281 "gaa.skel"
522 break;
523 default: break;
525 return GAA_ERROR_NOMATCH;
528 static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
530 int OK = 0;
531 int gaa_last_non_option;
532 struct GAAOPTION_create_conf GAATMP_create_conf;
533 struct GAAOPTION_passwd_conf GAATMP_passwd_conf;
534 struct GAAOPTION_salt GAATMP_salt;
535 struct GAAOPTION_index GAATMP_index;
536 struct GAAOPTION_passwd GAATMP_passwd;
537 struct GAAOPTION_username GAATMP_username;
538 struct GAAOPTION_debug GAATMP_debug;
540 #line 393 "gaa.skel"
541 #ifdef GAA_REST_EXISTS
542 struct GAAREST GAAREST_tmp;
543 #endif
545 opt_list[gaa_num] = 1;
547 for(gaa_last_non_option = gaa_index;
548 (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION);
549 gaa_last_non_option++);
551 if(gaa_num == GAA_REST)
553 gaa_index = 1;
554 gaa_last_non_option = GAAargc;
557 switch(gaa_num)
559 case GAAOPTID_help:
560 OK = 0;
561 #line 41 "crypt.gaa"
562 { gaa_help(); exit(0); ;};
564 return GAA_OK;
565 break;
566 case GAAOPTID_version:
567 OK = 0;
568 #line 40 "crypt.gaa"
569 { srptool_version(); exit(0); ;};
571 return GAA_OK;
572 break;
573 case GAAOPTID_create_conf:
574 OK = 0;
575 GAA_TESTMOREARGS;
576 GAA_FILL(GAATMP_create_conf.arg1, gaa_getstr, GAATMP_create_conf.size1);
577 gaa_index++;
578 #line 38 "crypt.gaa"
579 { gaaval->create_conf = GAATMP_create_conf.arg1 ;};
581 return GAA_OK;
582 break;
583 case GAAOPTID_passwd_conf:
584 OK = 0;
585 GAA_TESTMOREARGS;
586 GAA_FILL(GAATMP_passwd_conf.arg1, gaa_getstr, GAATMP_passwd_conf.size1);
587 gaa_index++;
588 #line 35 "crypt.gaa"
589 { gaaval->passwd_conf = GAATMP_passwd_conf.arg1 ;};
591 return GAA_OK;
592 break;
593 case GAAOPTID_verify:
594 OK = 0;
595 #line 32 "crypt.gaa"
596 { gaaval->verify = 1 ;};
598 return GAA_OK;
599 break;
600 case GAAOPTID_salt:
601 OK = 0;
602 GAA_TESTMOREARGS;
603 GAA_FILL(GAATMP_salt.arg1, gaa_getint, GAATMP_salt.size1);
604 gaa_index++;
605 #line 29 "crypt.gaa"
606 { gaaval->salt = GAATMP_salt.arg1 ;};
608 return GAA_OK;
609 break;
610 case GAAOPTID_index:
611 OK = 0;
612 GAA_TESTMOREARGS;
613 GAA_FILL(GAATMP_index.arg1, gaa_getint, GAATMP_index.size1);
614 gaa_index++;
615 #line 26 "crypt.gaa"
616 { gaaval->index = GAATMP_index.arg1 ;};
618 return GAA_OK;
619 break;
620 case GAAOPTID_passwd:
621 OK = 0;
622 GAA_TESTMOREARGS;
623 GAA_FILL(GAATMP_passwd.arg1, gaa_getstr, GAATMP_passwd.size1);
624 gaa_index++;
625 #line 23 "crypt.gaa"
626 { gaaval->passwd = GAATMP_passwd.arg1 ;};
628 return GAA_OK;
629 break;
630 case GAAOPTID_username:
631 OK = 0;
632 GAA_TESTMOREARGS;
633 GAA_FILL(GAATMP_username.arg1, gaa_getstr, GAATMP_username.size1);
634 gaa_index++;
635 #line 20 "crypt.gaa"
636 { gaaval->username = GAATMP_username.arg1 ;};
638 return GAA_OK;
639 break;
640 case GAAOPTID_debug:
641 OK = 0;
642 GAA_TESTMOREARGS;
643 GAA_FILL(GAATMP_debug.arg1, gaa_getint, GAATMP_debug.size1);
644 gaa_index++;
645 #line 17 "crypt.gaa"
646 { gaaval->debug = GAATMP_debug.arg1 ;};
648 return GAA_OK;
649 break;
651 #line 413 "gaa.skel"
652 default: break;
654 return GAA_ERROR_UNKNOWN;
657 int gaa(int argc, char **argv, gaainfo *gaaval)
659 int tmp1, tmp2;
660 int i, j;
661 char *opt_list;
663 GAAargv = argv;
664 GAAargc = argc;
666 opt_list = (char*) gaa_malloc(GAA_NB_OPTION + 1);
668 for(i = 0; i < GAA_NB_OPTION + 1; i++)
669 opt_list[i] = 0;
670 /* initialization */
671 if(inited == 0)
674 #line 43 "crypt.gaa"
675 { gaaval->username=NULL; gaaval->passwd=NULL; gaaval->salt=0;
676 gaaval->create_conf=NULL; gaaval->passwd_conf=NULL; gaaval->verify = 0;
677 gaaval->index = 1; gaaval->debug = 0; ;};
680 inited = 1;
681 #line 438 "gaa.skel"
682 gaa_arg_used = NULL;
684 if (argc > 0) {
685 gaa_arg_used = gaa_malloc(argc * sizeof(char));
688 for(i = 1; i < argc; i++)
689 gaa_arg_used[i] = 0;
690 for(i = 1; i < argc; i++)
692 if(gaa_arg_used[i] == 0)
694 j = 0;
695 tmp1 = gaa_is_an_argument(GAAargv[i]);
696 switch(tmp1)
698 case GAA_WORD_OPTION:
699 j++;
700 case GAA_LETTER_OPTION:
701 j++;
702 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
703 if(tmp2 == GAA_ERROR_NOMATCH)
705 printf("Invalid option '%s'\n", argv[i]+j);
706 return 0;
708 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
710 case GAA_ERROR_NOTENOUGH_ARGS:
711 printf("'%s': not enough arguments\n",gaa_current_option);
712 return 0;
713 case GAA_ERROR_INVALID_ARG:
714 printf("Invalid arguments\n");
715 return 0;
716 case GAA_OK:
717 break;
718 default:
719 printf("Unknown error\n");
721 gaa_arg_used[i] = 1;
722 break;
723 case GAA_MULTIPLE_OPTION:
724 for(j = 1; j < strlen(argv[i]); j++)
726 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
727 if(tmp2 == GAA_ERROR_NOMATCH)
729 printf("Invalid option '%c'\n", *(argv[i]+j));
730 return 0;
732 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
734 case GAA_ERROR_NOTENOUGH_ARGS:
735 printf("'%s': not enough arguments\n",gaa_current_option);
736 return 0;
737 case GAA_ERROR_INVALID_ARG:
738 printf("Invalid arguments\n");
739 return 0;
740 case GAA_OK:
741 break;
742 default:
743 printf("Unknown error\n");
746 gaa_arg_used[i] = 1;
747 break;
748 default: break;
752 if(gaa_processing_file == 0)
755 #line 507 "gaa.skel"
756 #ifdef GAA_REST_EXISTS
757 switch(gaa_try(GAA_REST, 1, gaaval, opt_list))
759 case GAA_ERROR_NOTENOUGH_ARGS:
760 printf("Rest: not enough arguments\n");
761 return 0;
762 case GAA_ERROR_INVALID_ARG:
763 printf("Invalid arguments\n");
764 return 0;
765 case GAA_OK:
766 break;
767 default:
768 printf("Unknown error\n");
770 #endif
772 for(i = 1; i < argc; i++)
774 if(gaa_arg_used[i] == 0)
776 printf("Too many arguments\n");
777 return 0;
780 free(gaa_arg_used);
781 free(opt_list);
782 return -1;
785 struct gaastrnode
787 char *str;
788 struct gaastrnode *next;
791 typedef struct gaastrnode gaa_str_node;
793 static int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc)
795 int pos_ini;
796 int a;
797 int i = 0, len = 0, newline = 0;
799 if(argc == 1) {
800 newline = 1;
801 len = 2;
804 a = fgetc( file);
805 if (a == EOF) return 0;
807 while(a == ' ' || a == 9 || a == '\n')
809 if(a == '\n')
811 newline=1;
812 len = 2;
814 a = fgetc( file);
815 if (a == EOF) return 0;
818 pos_ini = ftell(file) - 1;
820 while(a != ' ' && a != 9 && a != '\n')
823 len++;
824 a = fgetc( file);
825 if(a==EOF) return 0; //a = ' ';
828 len += 1;
829 tmp_str->str = gaa_malloc((len) * sizeof(char));
831 if(newline == 1)
833 tmp_str->str[0] = '-';
834 tmp_str->str[1] = '-';
835 i = 2;
837 else
839 i = 0;
842 fseek(file,pos_ini, SEEK_SET);
845 a = fgetc( file);
847 if (a == EOF) {
848 i+=2;
849 break;
851 tmp_str->str[i] = a;
852 i++;
854 while(a != ' ' && a != 9 && a != '\n' && i < len);
856 tmp_str->str[i - 1] = 0;
858 fseek(file,- 1, SEEK_CUR);
859 /* printf("%d\n", ftell(file)); */
861 return -1;
864 int gaa_file(const char *name, gaainfo *gaaval)
866 gaa_str_node *first_str, **tmp_str, *tmp_str2;
867 int rval, i;
868 char **argv;
869 int argc = 0;
870 FILE *file;
872 gaa_processing_file = 1;
874 if((file = fopen(name, "r")) == NULL)
876 printf("Couldn't open '%s' configuration file for reading\n", name);
877 return 1;
880 tmp_str = &first_str;
883 argc++;
884 *tmp_str = gaa_malloc(sizeof(gaa_str_node));
886 (*tmp_str)->str = NULL;
887 (*tmp_str)->next = NULL;
889 rval = gaa_internal_get_next_str(file, *tmp_str, argc);
890 tmp_str = &((*tmp_str)->next);
892 while(rval == -1);
894 if(rval == 1)
895 return 0;
897 argv = gaa_malloc((1 + argc) * sizeof(char*));
899 tmp_str2 = first_str;
900 argv[0] = "cfg";
901 for(i = 1; i < argc; i++)
903 argv[i] = tmp_str2->str;
904 tmp_str2 = tmp_str2->next;
907 rval = gaa(argc, argv, gaaval);
908 gaa_processing_file = 0;
909 return rval;