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('u', "username", "username ", "specify username.");
133 __gaa_helpsingle('p', "passwd", "FILE ", "specify a password file.");
134 __gaa_helpsingle('i', "index", "INDEX ", "specify the index of the group parameters in tpasswd.conf to use.");
135 __gaa_helpsingle('s', "salt", "SALT ", "specify salt size for crypt algorithm.");
136 __gaa_helpsingle(0, "verify", "", "just verify password.");
137 __gaa_helpsingle('c', "passwd-conf", "FILE ", "specify a password conf file.");
138 __gaa_helpsingle(0, "create-conf", "FILE ", "Generate a tpasswd.conf file.");
139 __gaa_helpsingle('v', "version", "", "prints the program's version number");
140 __gaa_helpsingle('h', "help", "", "shows this help text");
148 #ifndef GAA_HEADER_POKY
149 #define GAA_HEADER_POKY
151 typedef struct _gaainfo gaainfo
;
178 int gaa(int argc
, char *argv
[], gaainfo
*gaaval
);
182 int gaa_file(const char *name
, gaainfo
*gaaval
);
195 #define GAAERROR(x) \
201 static char *gaa_current_option
;
202 static int gaa_error
= 0;
204 /* Generated by gaa */
212 #define GAA_ERROR_NOMATCH 0
213 #define GAA_ERROR_NOTENOUGH_ARGS 1
214 #define GAA_ERROR_INVALID_ARG 2
215 #define GAA_ERROR_UNKNOWN 3
217 #define GAA_NOT_AN_OPTION 0
218 #define GAA_WORD_OPTION 1
219 #define GAA_LETTER_OPTION 2
220 #define GAA_MULTIPLE_OPTION 3
223 #define GAA_NB_OPTION 9
224 #define GAAOPTID_help 1
225 #define GAAOPTID_version 2
226 #define GAAOPTID_create_conf 3
227 #define GAAOPTID_passwd_conf 4
228 #define GAAOPTID_verify 5
229 #define GAAOPTID_salt 6
230 #define GAAOPTID_index 7
231 #define GAAOPTID_passwd 8
232 #define GAAOPTID_username 9
236 #define GAA_CHECK1STR(a,b) \
239 gaa_current_option = a; \
243 #define GAA_CHECKSTR(a,b) \
244 if(strcmp(a,str) == 0) \
246 gaa_current_option = a; \
250 #define GAA_TESTMOREARGS \
253 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
255 if(gaa_last_non_option == gaa_index) \
256 return GAA_ERROR_NOTENOUGH_ARGS; \
259 #define GAA_TESTMOREOPTIONALARGS \
262 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
264 if(gaa_last_non_option == gaa_index) \
268 #define GAA_FILL_2ARGS(target, func) \
269 target = func(GAAargv[gaa_index]); \
270 gaa_arg_used[gaa_index] = 1; \
274 return GAA_ERROR_INVALID_ARG; \
279 #define GAA_FILL(target, func, num) \
282 target = func(GAAargv[gaa_index]); \
283 gaa_arg_used[gaa_index] = 1; \
287 return GAA_ERROR_INVALID_ARG; \
296 #define GAA_LIST_FILL(target, func, type ,num) \
301 if ( gaa_last_non_option - gaa_index > 0) \
302 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
303 for(; gaa_index < gaa_last_non_option; gaa_index++) \
305 if(gaa_arg_used[gaa_index] == 0) \
307 GAA_FILL_2ARGS(target[num], func); \
312 return GAA_ERROR_NOTENOUGH_ARGS; \
315 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
320 if ( gaa_last_non_option - gaa_index > 0) \
321 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
322 for(; gaa_index < gaa_last_non_option; gaa_index++) \
324 if(gaa_arg_used[gaa_index] == 0) \
326 GAA_FILL_2ARGS(target[num], func); \
332 #define GAA_OBLIGAT(str) \
334 for(i = 0; i < strlen(str); i++) \
336 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
337 if(j == GAA_ERROR_NOMATCH) \
339 printf("Error: invalid 'obligat' set\n"); \
342 if(opt_list[j] == 1) \
347 if(strlen(str) == 1) \
348 printf("You must give the -%s option\n", str); \
350 printf("You must give at least one option of '%s'\n", str); \
354 #define GAA_INCOMP(str) \
356 for(i = 0; i < strlen(str); i++) \
358 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
359 if(j == GAA_ERROR_NOMATCH) \
361 printf("Error: invalid 'obligat' set\n"); \
364 if(opt_list[j] == 1) \
369 printf("The options '%s' are incompatible\n", str); \
374 static char **GAAargv
;
376 static char *gaa_arg_used
;
377 static int gaa_processing_file
= 0;
378 static int inited
= 0;
380 static int gaa_getint(char *arg
)
384 if(sscanf(arg
, "%d%c", &tmp
, &a
) < 1)
386 printf("Option %s: '%s' isn't an integer\n", gaa_current_option
, arg
);
392 static char gaa_getchar(char *arg
)
396 printf("Option %s: '%s' isn't an character\n", gaa_current_option
, arg
);
402 static char* gaa_getstr(char *arg
)
406 static float gaa_getfloat(char *arg
)
410 if(sscanf(arg
, "%f%c", &tmp
, &a
) < 1)
412 printf("Option %s: '%s' isn't a float number\n", gaa_current_option
, arg
);
417 /* option structures */
419 struct GAAOPTION_create_conf
425 struct GAAOPTION_passwd_conf
431 struct GAAOPTION_salt
437 struct GAAOPTION_index
443 struct GAAOPTION_passwd
449 struct GAAOPTION_username
456 static int gaa_is_an_argument(char *str
)
459 if(str
[0] == '/' && str
[1] != 0)
460 return GAA_MULTIPLE_OPTION
;
463 return GAA_NOT_AN_OPTION
;
465 return GAA_NOT_AN_OPTION
;
469 return GAA_WORD_OPTION
;
471 return GAA_NOT_AN_OPTION
;
474 return GAA_LETTER_OPTION
;
476 return GAA_MULTIPLE_OPTION
;
479 static int gaa_get_option_num(char *str
, int status
)
483 case GAA_LETTER_OPTION
:
484 GAA_CHECK1STR("", GAAOPTID_create_conf
);
485 GAA_CHECK1STR("c", GAAOPTID_passwd_conf
);
486 GAA_CHECK1STR("s", GAAOPTID_salt
);
487 GAA_CHECK1STR("i", GAAOPTID_index
);
488 GAA_CHECK1STR("p", GAAOPTID_passwd
);
489 GAA_CHECK1STR("u", GAAOPTID_username
);
490 case GAA_MULTIPLE_OPTION
:
492 GAA_CHECK1STR("h", GAAOPTID_help
);
493 GAA_CHECK1STR("v", GAAOPTID_version
);
494 GAA_CHECK1STR("", GAAOPTID_verify
);
498 case GAA_WORD_OPTION
:
499 GAA_CHECKSTR("help", GAAOPTID_help
);
500 GAA_CHECKSTR("version", GAAOPTID_version
);
501 GAA_CHECKSTR("create-conf", GAAOPTID_create_conf
);
502 GAA_CHECKSTR("passwd-conf", GAAOPTID_passwd_conf
);
503 GAA_CHECKSTR("verify", GAAOPTID_verify
);
504 GAA_CHECKSTR("salt", GAAOPTID_salt
);
505 GAA_CHECKSTR("index", GAAOPTID_index
);
506 GAA_CHECKSTR("passwd", GAAOPTID_passwd
);
507 GAA_CHECKSTR("username", GAAOPTID_username
);
513 return GAA_ERROR_NOMATCH
;
516 static int gaa_try(int gaa_num
, int gaa_index
, gaainfo
*gaaval
, char *opt_list
)
519 int gaa_last_non_option
;
520 struct GAAOPTION_create_conf GAATMP_create_conf
;
521 struct GAAOPTION_passwd_conf GAATMP_passwd_conf
;
522 struct GAAOPTION_salt GAATMP_salt
;
523 struct GAAOPTION_index GAATMP_index
;
524 struct GAAOPTION_passwd GAATMP_passwd
;
525 struct GAAOPTION_username GAATMP_username
;
528 #ifdef GAA_REST_EXISTS
529 struct GAAREST GAAREST_tmp
;
532 opt_list
[gaa_num
] = 1;
534 for(gaa_last_non_option
= gaa_index
;
535 (gaa_last_non_option
!= GAAargc
) && (gaa_is_an_argument(GAAargv
[gaa_last_non_option
]) == GAA_NOT_AN_OPTION
);
536 gaa_last_non_option
++);
538 if(gaa_num
== GAA_REST
)
541 gaa_last_non_option
= GAAargc
;
549 { gaa_help(); exit(0); ;};
553 case GAAOPTID_version
:
556 { srptool_version(); exit(0); ;};
560 case GAAOPTID_create_conf
:
563 GAA_FILL(GAATMP_create_conf
.arg1
, gaa_getstr
, GAATMP_create_conf
.size1
);
566 { gaaval
->create_conf
= GAATMP_create_conf
.arg1
;};
570 case GAAOPTID_passwd_conf
:
573 GAA_FILL(GAATMP_passwd_conf
.arg1
, gaa_getstr
, GAATMP_passwd_conf
.size1
);
576 { gaaval
->passwd_conf
= GAATMP_passwd_conf
.arg1
;};
580 case GAAOPTID_verify
:
583 { gaaval
->verify
= 1 ;};
590 GAA_FILL(GAATMP_salt
.arg1
, gaa_getint
, GAATMP_salt
.size1
);
593 { gaaval
->salt
= GAATMP_salt
.arg1
;};
600 GAA_FILL(GAATMP_index
.arg1
, gaa_getint
, GAATMP_index
.size1
);
603 { gaaval
->index
= GAATMP_index
.arg1
;};
607 case GAAOPTID_passwd
:
610 GAA_FILL(GAATMP_passwd
.arg1
, gaa_getstr
, GAATMP_passwd
.size1
);
613 { gaaval
->passwd
= GAATMP_passwd
.arg1
;};
617 case GAAOPTID_username
:
620 GAA_FILL(GAATMP_username
.arg1
, gaa_getstr
, GAATMP_username
.size1
);
623 { gaaval
->username
= GAATMP_username
.arg1
;};
631 return GAA_ERROR_UNKNOWN
;
634 int gaa(int argc
, char **argv
, gaainfo
*gaaval
)
643 opt_list
= (char*) gaa_malloc(GAA_NB_OPTION
+ 1);
645 for(i
= 0; i
< GAA_NB_OPTION
+ 1; i
++)
652 { gaaval
->username
=NULL
; gaaval
->passwd
=NULL
; gaaval
->salt
=0;
653 gaaval
->create_conf
=NULL
; gaaval
->passwd_conf
=NULL
; gaaval
->verify
= 0;
654 gaaval
->index
= 1; ;};
662 gaa_arg_used
= gaa_malloc(argc
* sizeof(char));
665 for(i
= 1; i
< argc
; i
++)
667 for(i
= 1; i
< argc
; i
++)
669 if(gaa_arg_used
[i
] == 0)
672 tmp1
= gaa_is_an_argument(GAAargv
[i
]);
675 case GAA_WORD_OPTION
:
677 case GAA_LETTER_OPTION
:
679 tmp2
= gaa_get_option_num(argv
[i
]+j
, tmp1
);
680 if(tmp2
== GAA_ERROR_NOMATCH
)
682 printf("Invalid option '%s'\n", argv
[i
]+j
);
685 switch(gaa_try(tmp2
, i
+1, gaaval
, opt_list
))
687 case GAA_ERROR_NOTENOUGH_ARGS
:
688 printf("'%s': not enough arguments\n",gaa_current_option
);
690 case GAA_ERROR_INVALID_ARG
:
691 printf("Invalid arguments\n");
696 printf("Unknown error\n");
700 case GAA_MULTIPLE_OPTION
:
701 for(j
= 1; j
< strlen(argv
[i
]); j
++)
703 tmp2
= gaa_get_option_num(argv
[i
]+j
, tmp1
);
704 if(tmp2
== GAA_ERROR_NOMATCH
)
706 printf("Invalid option '%c'\n", *(argv
[i
]+j
));
709 switch(gaa_try(tmp2
, i
+1, gaaval
, opt_list
))
711 case GAA_ERROR_NOTENOUGH_ARGS
:
712 printf("'%s': not enough arguments\n",gaa_current_option
);
714 case GAA_ERROR_INVALID_ARG
:
715 printf("Invalid arguments\n");
720 printf("Unknown error\n");
729 if(gaa_processing_file
== 0)
733 #ifdef GAA_REST_EXISTS
734 switch(gaa_try(GAA_REST
, 1, gaaval
, opt_list
))
736 case GAA_ERROR_NOTENOUGH_ARGS
:
737 printf("Rest: not enough arguments\n");
739 case GAA_ERROR_INVALID_ARG
:
740 printf("Invalid arguments\n");
745 printf("Unknown error\n");
749 for(i
= 1; i
< argc
; i
++)
751 if(gaa_arg_used
[i
] == 0)
753 printf("Too many arguments\n");
765 struct gaastrnode
*next
;
768 typedef struct gaastrnode gaa_str_node
;
770 static int gaa_internal_get_next_str(FILE *file
, gaa_str_node
*tmp_str
, int argc
)
774 int i
= 0, len
= 0, newline
= 0;
782 if (a
== EOF
) return 0;
784 while(a
== ' ' || a
== 9 || a
== '\n')
792 if (a
== EOF
) return 0;
795 pos_ini
= ftell(file
) - 1;
797 while(a
!= ' ' && a
!= 9 && a
!= '\n')
802 if(a
==EOF
) return 0; //a = ' ';
806 tmp_str
->str
= gaa_malloc((len
) * sizeof(char));
810 tmp_str
->str
[0] = '-';
811 tmp_str
->str
[1] = '-';
819 fseek(file
,pos_ini
, SEEK_SET
);
831 while(a
!= ' ' && a
!= 9 && a
!= '\n' && i
< len
);
833 tmp_str
->str
[i
- 1] = 0;
835 fseek(file
,- 1, SEEK_CUR
);
836 /* printf("%d\n", ftell(file)); */
841 int gaa_file(const char *name
, gaainfo
*gaaval
)
843 gaa_str_node
*first_str
, **tmp_str
, *tmp_str2
;
849 gaa_processing_file
= 1;
851 if((file
= fopen(name
, "r")) == NULL
)
853 printf("Couldn't open '%s' configuration file for reading\n", name
);
857 tmp_str
= &first_str
;
861 *tmp_str
= gaa_malloc(sizeof(gaa_str_node
));
863 (*tmp_str
)->str
= NULL
;
864 (*tmp_str
)->next
= NULL
;
866 rval
= gaa_internal_get_next_str(file
, *tmp_str
, argc
);
867 tmp_str
= &((*tmp_str
)->next
);
874 argv
= gaa_malloc((1 + argc
) * sizeof(char*));
876 tmp_str2
= first_str
;
878 for(i
= 1; i
< argc
; i
++)
880 argv
[i
] = tmp_str2
->str
;
881 tmp_str2
= tmp_str2
->next
;
884 rval
= gaa(argc
, argv
, gaaval
);
885 gaa_processing_file
= 0;