1 /* File generated by GAA 1.6.6
14 void psktool_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("PSKtool help\nUsage : psktool [options]\n");
132 __gaa_helpsingle('u', "username", "username ", "specify username.");
133 __gaa_helpsingle('p', "passwd", "FILE ", "specify a password file.");
134 __gaa_helpsingle('n', "netconf-hint", "HINT ", "derive key from Netconf password, using HINT as the psk_identity_hint.");
135 __gaa_helpsingle('s', "keysize", "SIZE ", "specify the key size in bytes.");
136 __gaa_helpsingle('v', "version", "", "prints the program's version number");
137 __gaa_helpsingle('h', "help", "", "shows this help text");
145 #ifndef GAA_HEADER_POKY
146 #define GAA_HEADER_POKY
148 typedef struct _gaainfo gaainfo
;
169 int gaa(int argc
, char *argv
[], gaainfo
*gaaval
);
173 int gaa_file(const char *name
, gaainfo
*gaaval
);
186 #define GAAERROR(x) \
192 static char *gaa_current_option
;
193 static int gaa_error
= 0;
195 /* Generated by gaa */
203 #define GAA_ERROR_NOMATCH 0
204 #define GAA_ERROR_NOTENOUGH_ARGS 1
205 #define GAA_ERROR_INVALID_ARG 2
206 #define GAA_ERROR_UNKNOWN 3
208 #define GAA_NOT_AN_OPTION 0
209 #define GAA_WORD_OPTION 1
210 #define GAA_LETTER_OPTION 2
211 #define GAA_MULTIPLE_OPTION 3
214 #define GAA_NB_OPTION 6
215 #define GAAOPTID_help 1
216 #define GAAOPTID_version 2
217 #define GAAOPTID_keysize 3
218 #define GAAOPTID_netconf_hint 4
219 #define GAAOPTID_passwd 5
220 #define GAAOPTID_username 6
224 #define GAA_CHECK1STR(a,b) \
227 gaa_current_option = a; \
231 #define GAA_CHECKSTR(a,b) \
232 if(strcmp(a,str) == 0) \
234 gaa_current_option = a; \
238 #define GAA_TESTMOREARGS \
241 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
243 if(gaa_last_non_option == gaa_index) \
244 return GAA_ERROR_NOTENOUGH_ARGS; \
247 #define GAA_TESTMOREOPTIONALARGS \
250 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
252 if(gaa_last_non_option == gaa_index) \
256 #define GAA_FILL_2ARGS(target, func) \
257 target = func(GAAargv[gaa_index]); \
258 gaa_arg_used[gaa_index] = 1; \
262 return GAA_ERROR_INVALID_ARG; \
267 #define GAA_FILL(target, func, num) \
270 target = func(GAAargv[gaa_index]); \
271 gaa_arg_used[gaa_index] = 1; \
275 return GAA_ERROR_INVALID_ARG; \
284 #define GAA_LIST_FILL(target, func, type ,num) \
289 if ( gaa_last_non_option - gaa_index > 0) \
290 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
291 for(; gaa_index < gaa_last_non_option; gaa_index++) \
293 if(gaa_arg_used[gaa_index] == 0) \
295 GAA_FILL_2ARGS(target[num], func); \
300 return GAA_ERROR_NOTENOUGH_ARGS; \
303 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
308 if ( gaa_last_non_option - gaa_index > 0) \
309 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
310 for(; gaa_index < gaa_last_non_option; gaa_index++) \
312 if(gaa_arg_used[gaa_index] == 0) \
314 GAA_FILL_2ARGS(target[num], func); \
320 #define GAA_OBLIGAT(str) \
322 for(i = 0; i < strlen(str); i++) \
324 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
325 if(j == GAA_ERROR_NOMATCH) \
327 printf("Error: invalid 'obligat' set\n"); \
330 if(opt_list[j] == 1) \
335 if(strlen(str) == 1) \
336 printf("You must give the -%s option\n", str); \
338 printf("You must give at least one option of '%s'\n", str); \
342 #define GAA_INCOMP(str) \
344 for(i = 0; i < strlen(str); i++) \
346 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
347 if(j == GAA_ERROR_NOMATCH) \
349 printf("Error: invalid 'obligat' set\n"); \
352 if(opt_list[j] == 1) \
357 printf("The options '%s' are incompatible\n", str); \
362 static char **GAAargv
;
364 static char *gaa_arg_used
;
365 static int gaa_processing_file
= 0;
366 static int inited
= 0;
368 static int gaa_getint(char *arg
)
372 if(sscanf(arg
, "%d%c", &tmp
, &a
) < 1)
374 printf("Option %s: '%s' isn't an integer\n", gaa_current_option
, arg
);
380 static char gaa_getchar(char *arg
)
384 printf("Option %s: '%s' isn't an character\n", gaa_current_option
, arg
);
390 static char* gaa_getstr(char *arg
)
394 static float gaa_getfloat(char *arg
)
398 if(sscanf(arg
, "%f%c", &tmp
, &a
) < 1)
400 printf("Option %s: '%s' isn't a float number\n", gaa_current_option
, arg
);
405 /* option structures */
407 struct GAAOPTION_keysize
413 struct GAAOPTION_netconf_hint
419 struct GAAOPTION_passwd
425 struct GAAOPTION_username
432 static int gaa_is_an_argument(char *str
)
435 if(str
[0] == '/' && str
[1] != 0)
436 return GAA_MULTIPLE_OPTION
;
439 return GAA_NOT_AN_OPTION
;
441 return GAA_NOT_AN_OPTION
;
445 return GAA_WORD_OPTION
;
447 return GAA_NOT_AN_OPTION
;
450 return GAA_LETTER_OPTION
;
452 return GAA_MULTIPLE_OPTION
;
455 static int gaa_get_option_num(char *str
, int status
)
459 case GAA_LETTER_OPTION
:
460 GAA_CHECK1STR("s", GAAOPTID_keysize
);
461 GAA_CHECK1STR("n", GAAOPTID_netconf_hint
);
462 GAA_CHECK1STR("p", GAAOPTID_passwd
);
463 GAA_CHECK1STR("u", GAAOPTID_username
);
464 case GAA_MULTIPLE_OPTION
:
466 GAA_CHECK1STR("h", GAAOPTID_help
);
467 GAA_CHECK1STR("v", GAAOPTID_version
);
471 case GAA_WORD_OPTION
:
472 GAA_CHECKSTR("help", GAAOPTID_help
);
473 GAA_CHECKSTR("version", GAAOPTID_version
);
474 GAA_CHECKSTR("keysize", GAAOPTID_keysize
);
475 GAA_CHECKSTR("netconf-hint", GAAOPTID_netconf_hint
);
476 GAA_CHECKSTR("passwd", GAAOPTID_passwd
);
477 GAA_CHECKSTR("username", GAAOPTID_username
);
483 return GAA_ERROR_NOMATCH
;
486 static int gaa_try(int gaa_num
, int gaa_index
, gaainfo
*gaaval
, char *opt_list
)
489 int gaa_last_non_option
;
490 struct GAAOPTION_keysize GAATMP_keysize
;
491 struct GAAOPTION_netconf_hint GAATMP_netconf_hint
;
492 struct GAAOPTION_passwd GAATMP_passwd
;
493 struct GAAOPTION_username GAATMP_username
;
496 #ifdef GAA_REST_EXISTS
497 struct GAAREST GAAREST_tmp
;
500 opt_list
[gaa_num
] = 1;
502 for(gaa_last_non_option
= gaa_index
;
503 (gaa_last_non_option
!= GAAargc
) && (gaa_is_an_argument(GAAargv
[gaa_last_non_option
]) == GAA_NOT_AN_OPTION
);
504 gaa_last_non_option
++);
506 if(gaa_num
== GAA_REST
)
509 gaa_last_non_option
= GAAargc
;
517 { gaa_help(); exit(0); ;};
521 case GAAOPTID_version
:
524 { psktool_version(); exit(0); ;};
528 case GAAOPTID_keysize
:
531 GAA_FILL(GAATMP_keysize
.arg1
, gaa_getint
, GAATMP_keysize
.size1
);
534 { gaaval
->key_size
= GAATMP_keysize
.arg1
;};
538 case GAAOPTID_netconf_hint
:
541 GAA_FILL(GAATMP_netconf_hint
.arg1
, gaa_getstr
, GAATMP_netconf_hint
.size1
);
544 { gaaval
->netconf_hint
= GAATMP_netconf_hint
.arg1
;};
548 case GAAOPTID_passwd
:
551 GAA_FILL(GAATMP_passwd
.arg1
, gaa_getstr
, GAATMP_passwd
.size1
);
554 { gaaval
->passwd
= GAATMP_passwd
.arg1
;};
558 case GAAOPTID_username
:
561 GAA_FILL(GAATMP_username
.arg1
, gaa_getstr
, GAATMP_username
.size1
);
564 { gaaval
->username
= GAATMP_username
.arg1
;};
572 return GAA_ERROR_UNKNOWN
;
575 int gaa(int argc
, char **argv
, gaainfo
*gaaval
)
584 opt_list
= (char*) gaa_malloc(GAA_NB_OPTION
+ 1);
586 for(i
= 0; i
< GAA_NB_OPTION
+ 1; i
++)
593 { gaaval
->username
=NULL
; gaaval
->passwd
=NULL
; gaaval
->key_size
= 0; gaaval
->netconf_hint
= NULL
; ;};
601 gaa_arg_used
= gaa_malloc(argc
* sizeof(char));
604 for(i
= 1; i
< argc
; i
++)
606 for(i
= 1; i
< argc
; i
++)
608 if(gaa_arg_used
[i
] == 0)
611 tmp1
= gaa_is_an_argument(GAAargv
[i
]);
614 case GAA_WORD_OPTION
:
616 case GAA_LETTER_OPTION
:
618 tmp2
= gaa_get_option_num(argv
[i
]+j
, tmp1
);
619 if(tmp2
== GAA_ERROR_NOMATCH
)
621 printf("Invalid option '%s'\n", argv
[i
]+j
);
624 switch(gaa_try(tmp2
, i
+1, gaaval
, opt_list
))
626 case GAA_ERROR_NOTENOUGH_ARGS
:
627 printf("'%s': not enough arguments\n",gaa_current_option
);
629 case GAA_ERROR_INVALID_ARG
:
630 printf("Invalid arguments\n");
635 printf("Unknown error\n");
639 case GAA_MULTIPLE_OPTION
:
640 for(j
= 1; j
< strlen(argv
[i
]); j
++)
642 tmp2
= gaa_get_option_num(argv
[i
]+j
, tmp1
);
643 if(tmp2
== GAA_ERROR_NOMATCH
)
645 printf("Invalid option '%c'\n", *(argv
[i
]+j
));
648 switch(gaa_try(tmp2
, i
+1, gaaval
, opt_list
))
650 case GAA_ERROR_NOTENOUGH_ARGS
:
651 printf("'%s': not enough arguments\n",gaa_current_option
);
653 case GAA_ERROR_INVALID_ARG
:
654 printf("Invalid arguments\n");
659 printf("Unknown error\n");
668 if(gaa_processing_file
== 0)
672 #ifdef GAA_REST_EXISTS
673 switch(gaa_try(GAA_REST
, 1, gaaval
, opt_list
))
675 case GAA_ERROR_NOTENOUGH_ARGS
:
676 printf("Rest: not enough arguments\n");
678 case GAA_ERROR_INVALID_ARG
:
679 printf("Invalid arguments\n");
684 printf("Unknown error\n");
688 for(i
= 1; i
< argc
; i
++)
690 if(gaa_arg_used
[i
] == 0)
692 printf("Too many arguments\n");
704 struct gaastrnode
*next
;
707 typedef struct gaastrnode gaa_str_node
;
709 static int gaa_internal_get_next_str(FILE *file
, gaa_str_node
*tmp_str
, int argc
)
713 int i
= 0, len
= 0, newline
= 0;
721 if (a
== EOF
) return 0;
723 while(a
== ' ' || a
== 9 || a
== '\n')
731 if (a
== EOF
) return 0;
734 pos_ini
= ftell(file
) - 1;
736 while(a
!= ' ' && a
!= 9 && a
!= '\n')
741 if(a
==EOF
) return 0; /* a = ' '; */
745 tmp_str
->str
= gaa_malloc((len
) * sizeof(char));
749 tmp_str
->str
[0] = '-';
750 tmp_str
->str
[1] = '-';
758 fseek(file
,pos_ini
, SEEK_SET
);
770 while(a
!= ' ' && a
!= 9 && a
!= '\n' && i
< len
);
772 tmp_str
->str
[i
- 1] = 0;
774 fseek(file
,- 1, SEEK_CUR
);
775 /* printf("%d\n", ftell(file)); */
780 int gaa_file(const char *name
, gaainfo
*gaaval
)
782 gaa_str_node
*first_str
, **tmp_str
, *tmp_str2
;
788 gaa_processing_file
= 1;
790 if((file
= fopen(name
, "r")) == NULL
)
792 printf("Couldn't open '%s' configuration file for reading\n", name
);
796 tmp_str
= &first_str
;
800 *tmp_str
= gaa_malloc(sizeof(gaa_str_node
));
802 (*tmp_str
)->str
= NULL
;
803 (*tmp_str
)->next
= NULL
;
805 rval
= gaa_internal_get_next_str(file
, *tmp_str
, argc
);
806 tmp_str
= &((*tmp_str
)->next
);
813 argv
= gaa_malloc((1 + argc
) * sizeof(char*));
815 tmp_str2
= first_str
;
817 for(i
= 1; i
< argc
; i
++)
819 argv
[i
] = tmp_str2
->str
;
820 tmp_str2
= tmp_str2
->next
;
823 rval
= gaa(argc
, argv
, gaaval
);
824 gaa_processing_file
= 0;