1 /* File generated by GAA 1.6.6
14 void srptool_version(void);
21 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(WINDOWS)
26 static void* gaa_malloc( size_t size) {
30 fprintf(stderr, "gaa: could not allocate memory");
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;
42 col1 = 5; /* Default values */
47 for(i = 0; i < col1; i++)
56 printf("-%c, ", short_name);
61 printf("-%c ", short_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);
80 if(opt_help) /* let's print the option's help body */
82 const char *str = opt_help;
102 while((curr - col3) % tabsize != 0 && curr < col4);
109 for(i = 1; str[i] && str[i] != ' ' && str[i] != '\n'
110 && str[i] != '\t'; i++);
111 if(curr + i - 1 >= col4)
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");
149 #ifndef GAA_HEADER_POKY
150 #define GAA_HEADER_POKY
152 typedef struct _gaainfo gaainfo;
181 int gaa(int argc, char *argv[], gaainfo *gaaval);
185 int gaa_file(const char *name, gaainfo *gaaval);
198 #define GAAERROR(x) \
204 static char *gaa_current_option;
205 static int gaa_error = 0;
207 /* Generated by gaa */
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
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
240 #define GAA_CHECK1STR(a,b) \
243 gaa_current_option = a; \
247 #define GAA_CHECKSTR(a,b) \
248 if(strcmp(a,str) == 0) \
250 gaa_current_option = a; \
254 #define GAA_TESTMOREARGS \
257 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
259 if(gaa_last_non_option == gaa_index) \
260 return GAA_ERROR_NOTENOUGH_ARGS; \
263 #define GAA_TESTMOREOPTIONALARGS \
266 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
268 if(gaa_last_non_option == gaa_index) \
272 #define GAA_FILL_2ARGS(target, func) \
273 target = func(GAAargv[gaa_index]); \
274 gaa_arg_used[gaa_index] = 1; \
278 return GAA_ERROR_INVALID_ARG; \
283 #define GAA_FILL(target, func, num) \
286 target = func(GAAargv[gaa_index]); \
287 gaa_arg_used[gaa_index] = 1; \
291 return GAA_ERROR_INVALID_ARG; \
300 #define GAA_LIST_FILL(target, func, type ,num) \
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); \
316 return GAA_ERROR_NOTENOUGH_ARGS; \
319 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
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); \
336 #define GAA_OBLIGAT(str) \
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"); \
346 if(opt_list[j] == 1) \
351 if(strlen(str) == 1) \
352 printf("You must give the -%s option\n", str); \
354 printf("You must give at least one option of '%s'\n", str); \
358 #define GAA_INCOMP(str) \
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"); \
368 if(opt_list[j] == 1) \
373 printf("The options '%s' are incompatible\n", str); \
378 static char **GAAargv;
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)
388 if(sscanf(arg, "%d%c", &tmp, &a) < 1)
390 printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
396 static char gaa_getchar(char *arg)
400 printf("Option %s: '%s' isn't an character\n", gaa_current_option, arg);
406 static char* gaa_getstr(char *arg)
410 static float gaa_getfloat(char *arg)
414 if(sscanf(arg, "%f%c", &tmp, &a) < 1)
416 printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg);
421 /* option structures */
423 struct GAAOPTION_create_conf
429 struct GAAOPTION_passwd_conf
435 struct GAAOPTION_salt
441 struct GAAOPTION_index
447 struct GAAOPTION_passwd
453 struct GAAOPTION_username
459 struct GAAOPTION_debug
466 static int gaa_is_an_argument(char *str)
469 if(str[0] == '/' && str[1] != 0)
470 return GAA_MULTIPLE_OPTION;
473 return GAA_NOT_AN_OPTION;
475 return GAA_NOT_AN_OPTION;
479 return GAA_WORD_OPTION;
481 return GAA_NOT_AN_OPTION;
484 return GAA_LETTER_OPTION;
486 return GAA_MULTIPLE_OPTION;
489 static int gaa_get_option_num(char *str, int 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:
503 GAA_CHECK1STR("h", GAAOPTID_help);
504 GAA_CHECK1STR("v", GAAOPTID_version);
505 GAA_CHECK1STR("", GAAOPTID_verify);
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);
525 return GAA_ERROR_NOMATCH;
528 static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
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;
541 #ifdef GAA_REST_EXISTS
542 struct GAAREST GAAREST_tmp;
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)
554 gaa_last_non_option = GAAargc;
562 { gaa_help(); exit(0); ;};
566 case GAAOPTID_version:
569 { srptool_version(); exit(0); ;};
573 case GAAOPTID_create_conf:
576 GAA_FILL(GAATMP_create_conf.arg1, gaa_getstr, GAATMP_create_conf.size1);
579 { gaaval->create_conf = GAATMP_create_conf.arg1 ;};
583 case GAAOPTID_passwd_conf:
586 GAA_FILL(GAATMP_passwd_conf.arg1, gaa_getstr, GAATMP_passwd_conf.size1);
589 { gaaval->passwd_conf = GAATMP_passwd_conf.arg1 ;};
593 case GAAOPTID_verify:
596 { gaaval->verify = 1 ;};
603 GAA_FILL(GAATMP_salt.arg1, gaa_getint, GAATMP_salt.size1);
606 { gaaval->salt = GAATMP_salt.arg1 ;};
613 GAA_FILL(GAATMP_index.arg1, gaa_getint, GAATMP_index.size1);
616 { gaaval->index = GAATMP_index.arg1 ;};
620 case GAAOPTID_passwd:
623 GAA_FILL(GAATMP_passwd.arg1, gaa_getstr, GAATMP_passwd.size1);
626 { gaaval->passwd = GAATMP_passwd.arg1 ;};
630 case GAAOPTID_username:
633 GAA_FILL(GAATMP_username.arg1, gaa_getstr, GAATMP_username.size1);
636 { gaaval->username = GAATMP_username.arg1 ;};
643 GAA_FILL(GAATMP_debug.arg1, gaa_getint, GAATMP_debug.size1);
646 { gaaval->debug = GAATMP_debug.arg1 ;};
654 return GAA_ERROR_UNKNOWN;
657 int gaa(int argc, char **argv, gaainfo *gaaval)
666 opt_list = (char*) gaa_malloc(GAA_NB_OPTION + 1);
668 for(i = 0; i < GAA_NB_OPTION + 1; i++)
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; ;};
685 gaa_arg_used = gaa_malloc(argc * sizeof(char));
688 for(i = 1; i < argc; i++)
690 for(i = 1; i < argc; i++)
692 if(gaa_arg_used[i] == 0)
695 tmp1 = gaa_is_an_argument(GAAargv[i]);
698 case GAA_WORD_OPTION:
700 case GAA_LETTER_OPTION:
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);
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);
713 case GAA_ERROR_INVALID_ARG:
714 printf("Invalid arguments\n");
719 printf("Unknown error\n");
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));
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);
737 case GAA_ERROR_INVALID_ARG:
738 printf("Invalid arguments\n");
743 printf("Unknown error\n");
752 if(gaa_processing_file == 0)
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");
762 case GAA_ERROR_INVALID_ARG:
763 printf("Invalid arguments\n");
768 printf("Unknown error\n");
772 for(i = 1; i < argc; i++)
774 if(gaa_arg_used[i] == 0)
776 printf("Too many arguments\n");
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)
797 int i = 0, len = 0, newline = 0;
805 if (a == EOF) return 0;
807 while(a == ' ' || a == 9 || a == '\n')
815 if (a == EOF) return 0;
818 pos_ini = ftell(file) - 1;
820 while(a != ' ' && a != 9 && a != '\n')
829 tmp_str->str = gaa_malloc((len) * sizeof(char));
833 tmp_str->str[0] = '-';
834 tmp_str->str[1] = '-';
842 fseek(file,pos_ini, SEEK_SET);
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)); */
864 int gaa_file(const char *name, gaainfo *gaaval)
866 gaa_str_node *first_str, **tmp_str, *tmp_str2;
872 gaa_processing_file = 1;
874 if((file = fopen(name, "r")) == NULL)
876 printf("Couldn't open '%s' configuration file for reading\n", name);
880 tmp_str = &first_str;
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);
897 argv = gaa_malloc((1 + argc) * sizeof(char*));
899 tmp_str2 = first_str;
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;