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
);
393 static char* gaa_getstr(char *arg
)
398 /* option structures */
400 struct GAAOPTION_create_conf
406 struct GAAOPTION_passwd_conf
412 struct GAAOPTION_salt
418 struct GAAOPTION_index
424 struct GAAOPTION_passwd
430 struct GAAOPTION_username
437 static int gaa_is_an_argument(char *str
)
440 if(str
[0] == '/' && str
[1] != 0)
441 return GAA_MULTIPLE_OPTION
;
444 return GAA_NOT_AN_OPTION
;
446 return GAA_NOT_AN_OPTION
;
450 return GAA_WORD_OPTION
;
452 return GAA_NOT_AN_OPTION
;
455 return GAA_LETTER_OPTION
;
457 return GAA_MULTIPLE_OPTION
;
460 static int gaa_get_option_num(char *str
, int status
)
464 case GAA_LETTER_OPTION
:
465 GAA_CHECK1STR("", GAAOPTID_create_conf
);
466 GAA_CHECK1STR("c", GAAOPTID_passwd_conf
);
467 GAA_CHECK1STR("s", GAAOPTID_salt
);
468 GAA_CHECK1STR("i", GAAOPTID_index
);
469 GAA_CHECK1STR("p", GAAOPTID_passwd
);
470 GAA_CHECK1STR("u", GAAOPTID_username
);
471 case GAA_MULTIPLE_OPTION
:
473 GAA_CHECK1STR("h", GAAOPTID_help
);
474 GAA_CHECK1STR("v", GAAOPTID_version
);
475 GAA_CHECK1STR("", GAAOPTID_verify
);
479 case GAA_WORD_OPTION
:
480 GAA_CHECKSTR("help", GAAOPTID_help
);
481 GAA_CHECKSTR("version", GAAOPTID_version
);
482 GAA_CHECKSTR("create-conf", GAAOPTID_create_conf
);
483 GAA_CHECKSTR("passwd-conf", GAAOPTID_passwd_conf
);
484 GAA_CHECKSTR("verify", GAAOPTID_verify
);
485 GAA_CHECKSTR("salt", GAAOPTID_salt
);
486 GAA_CHECKSTR("index", GAAOPTID_index
);
487 GAA_CHECKSTR("passwd", GAAOPTID_passwd
);
488 GAA_CHECKSTR("username", GAAOPTID_username
);
494 return GAA_ERROR_NOMATCH
;
497 static int gaa_try(int gaa_num
, int gaa_index
, gaainfo
*gaaval
, char *opt_list
)
500 int gaa_last_non_option
;
501 struct GAAOPTION_create_conf GAATMP_create_conf
;
502 struct GAAOPTION_passwd_conf GAATMP_passwd_conf
;
503 struct GAAOPTION_salt GAATMP_salt
;
504 struct GAAOPTION_index GAATMP_index
;
505 struct GAAOPTION_passwd GAATMP_passwd
;
506 struct GAAOPTION_username GAATMP_username
;
509 #ifdef GAA_REST_EXISTS
510 struct GAAREST GAAREST_tmp
;
513 opt_list
[gaa_num
] = 1;
515 for(gaa_last_non_option
= gaa_index
;
516 (gaa_last_non_option
!= GAAargc
) && (gaa_is_an_argument(GAAargv
[gaa_last_non_option
]) == GAA_NOT_AN_OPTION
);
517 gaa_last_non_option
++);
519 if(gaa_num
== GAA_REST
)
522 gaa_last_non_option
= GAAargc
;
530 { gaa_help(); exit(0); ;};
534 case GAAOPTID_version
:
537 { srptool_version(); exit(0); ;};
541 case GAAOPTID_create_conf
:
544 GAA_FILL(GAATMP_create_conf
.arg1
, gaa_getstr
, GAATMP_create_conf
.size1
);
547 { gaaval
->create_conf
= GAATMP_create_conf
.arg1
;};
551 case GAAOPTID_passwd_conf
:
554 GAA_FILL(GAATMP_passwd_conf
.arg1
, gaa_getstr
, GAATMP_passwd_conf
.size1
);
557 { gaaval
->passwd_conf
= GAATMP_passwd_conf
.arg1
;};
561 case GAAOPTID_verify
:
564 { gaaval
->verify
= 1 ;};
571 GAA_FILL(GAATMP_salt
.arg1
, gaa_getint
, GAATMP_salt
.size1
);
574 { gaaval
->salt
= GAATMP_salt
.arg1
;};
581 GAA_FILL(GAATMP_index
.arg1
, gaa_getint
, GAATMP_index
.size1
);
584 { gaaval
->index
= GAATMP_index
.arg1
;};
588 case GAAOPTID_passwd
:
591 GAA_FILL(GAATMP_passwd
.arg1
, gaa_getstr
, GAATMP_passwd
.size1
);
594 { gaaval
->passwd
= GAATMP_passwd
.arg1
;};
598 case GAAOPTID_username
:
601 GAA_FILL(GAATMP_username
.arg1
, gaa_getstr
, GAATMP_username
.size1
);
604 { gaaval
->username
= GAATMP_username
.arg1
;};
612 return GAA_ERROR_UNKNOWN
;
615 int gaa(int argc
, char **argv
, gaainfo
*gaaval
)
627 opt_list
= (char*) gaa_malloc(GAA_NB_OPTION
+ 1);
629 for(l
= 0; l
< GAA_NB_OPTION
+ 1; l
++)
636 { gaaval
->username
=NULL
; gaaval
->passwd
=NULL
; gaaval
->salt
=0;
637 gaaval
->create_conf
=NULL
; gaaval
->passwd_conf
=NULL
; gaaval
->verify
= 0;
638 gaaval
->index
= 1; ;};
646 gaa_arg_used
= gaa_malloc(argc
* sizeof(char));
649 for(l
= 1; l
< argc
; l
++)
651 for(l
= 1; l
< argc
; l
++)
653 if(gaa_arg_used
[l
] == 0)
656 tmp1
= gaa_is_an_argument(GAAargv
[l
]);
659 case GAA_WORD_OPTION
:
661 case GAA_LETTER_OPTION
:
663 tmp2
= gaa_get_option_num(argv
[l
]+j
, tmp1
);
664 if(tmp2
== GAA_ERROR_NOMATCH
)
666 printf("Invalid option '%s'\n", argv
[l
]+j
);
669 switch(gaa_try(tmp2
, l
+1, gaaval
, opt_list
))
671 case GAA_ERROR_NOTENOUGH_ARGS
:
672 printf("'%s': not enough arguments\n",gaa_current_option
);
674 case GAA_ERROR_INVALID_ARG
:
675 printf("Invalid arguments\n");
680 printf("Unknown error\n");
684 case GAA_MULTIPLE_OPTION
:
685 for(j
= 1; j
< strlen(argv
[l
]); j
++)
687 tmp2
= gaa_get_option_num(argv
[l
]+j
, tmp1
);
688 if(tmp2
== GAA_ERROR_NOMATCH
)
690 printf("Invalid option '%c'\n", *(argv
[l
]+j
));
693 switch(gaa_try(tmp2
, l
+1, gaaval
, opt_list
))
695 case GAA_ERROR_NOTENOUGH_ARGS
:
696 printf("'%s': not enough arguments\n",gaa_current_option
);
698 case GAA_ERROR_INVALID_ARG
:
699 printf("Invalid arguments\n");
704 printf("Unknown error\n");
713 if(gaa_processing_file
== 0)
717 #ifdef GAA_REST_EXISTS
718 switch(gaa_try(GAA_REST
, 1, gaaval
, opt_list
))
720 case GAA_ERROR_NOTENOUGH_ARGS
:
721 printf("Rest: not enough arguments\n");
723 case GAA_ERROR_INVALID_ARG
:
724 printf("Invalid arguments\n");
729 printf("Unknown error\n");
733 for(l
= 1; l
< argc
; l
++)
735 if(gaa_arg_used
[l
] == 0)
737 printf("Too many arguments\n");
749 struct gaastrnode
*next
;
752 typedef struct gaastrnode gaa_str_node
;
754 static int gaa_internal_get_next_str(FILE *file
, gaa_str_node
*tmp_str
, int argc
)
758 int i
= 0, len
= 0, newline
= 0;
766 if (a
== EOF
) return 0;
768 while(a
== ' ' || a
== 9 || a
== '\n')
776 if (a
== EOF
) return 0;
779 pos_ini
= ftell(file
) - 1;
781 while(a
!= ' ' && a
!= 9 && a
!= '\n')
786 if(a
==EOF
) return 0; /* a = ' '; */
790 tmp_str
->str
= gaa_malloc((len
) * sizeof(char));
794 tmp_str
->str
[0] = '-';
795 tmp_str
->str
[1] = '-';
803 fseek(file
,pos_ini
, SEEK_SET
);
815 while(a
!= ' ' && a
!= 9 && a
!= '\n' && i
< len
);
817 tmp_str
->str
[i
- 1] = 0;
819 fseek(file
,- 1, SEEK_CUR
);
820 /* printf("%d\n", ftell(file)); */
825 int gaa_file(const char *name
, gaainfo
*gaaval
)
827 gaa_str_node
*first_str
, **tmp_str
, *tmp_str2
;
833 gaa_processing_file
= 1;
835 if((file
= fopen(name
, "r")) == NULL
)
837 printf("Couldn't open '%s' configuration file for reading\n", name
);
841 tmp_str
= &first_str
;
845 *tmp_str
= gaa_malloc(sizeof(gaa_str_node
));
847 (*tmp_str
)->str
= NULL
;
848 (*tmp_str
)->next
= NULL
;
850 rval
= gaa_internal_get_next_str(file
, *tmp_str
, argc
);
851 tmp_str
= &((*tmp_str
)->next
);
858 argv
= gaa_malloc((1 + argc
) * sizeof(char*));
860 tmp_str2
= first_str
;
862 for(i
= 1; i
< argc
; i
++)
864 argv
[i
] = tmp_str2
->str
;
865 tmp_str2
= tmp_str2
->next
;
868 rval
= gaa(argc
, argv
, gaaval
);
869 gaa_processing_file
= 0;