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
);
381 static char* gaa_getstr(char *arg
)
386 /* option structures */
388 struct GAAOPTION_keysize
394 struct GAAOPTION_netconf_hint
400 struct GAAOPTION_passwd
406 struct GAAOPTION_username
413 static int gaa_is_an_argument(char *str
)
416 if(str
[0] == '/' && str
[1] != 0)
417 return GAA_MULTIPLE_OPTION
;
420 return GAA_NOT_AN_OPTION
;
422 return GAA_NOT_AN_OPTION
;
426 return GAA_WORD_OPTION
;
428 return GAA_NOT_AN_OPTION
;
431 return GAA_LETTER_OPTION
;
433 return GAA_MULTIPLE_OPTION
;
436 static int gaa_get_option_num(char *str
, int status
)
440 case GAA_LETTER_OPTION
:
441 GAA_CHECK1STR("s", GAAOPTID_keysize
);
442 GAA_CHECK1STR("n", GAAOPTID_netconf_hint
);
443 GAA_CHECK1STR("p", GAAOPTID_passwd
);
444 GAA_CHECK1STR("u", GAAOPTID_username
);
445 case GAA_MULTIPLE_OPTION
:
447 GAA_CHECK1STR("h", GAAOPTID_help
);
448 GAA_CHECK1STR("v", GAAOPTID_version
);
452 case GAA_WORD_OPTION
:
453 GAA_CHECKSTR("help", GAAOPTID_help
);
454 GAA_CHECKSTR("version", GAAOPTID_version
);
455 GAA_CHECKSTR("keysize", GAAOPTID_keysize
);
456 GAA_CHECKSTR("netconf-hint", GAAOPTID_netconf_hint
);
457 GAA_CHECKSTR("passwd", GAAOPTID_passwd
);
458 GAA_CHECKSTR("username", GAAOPTID_username
);
464 return GAA_ERROR_NOMATCH
;
467 static int gaa_try(int gaa_num
, int gaa_index
, gaainfo
*gaaval
, char *opt_list
)
470 int gaa_last_non_option
;
471 struct GAAOPTION_keysize GAATMP_keysize
;
472 struct GAAOPTION_netconf_hint GAATMP_netconf_hint
;
473 struct GAAOPTION_passwd GAATMP_passwd
;
474 struct GAAOPTION_username GAATMP_username
;
477 #ifdef GAA_REST_EXISTS
478 struct GAAREST GAAREST_tmp
;
481 opt_list
[gaa_num
] = 1;
483 for(gaa_last_non_option
= gaa_index
;
484 (gaa_last_non_option
!= GAAargc
) && (gaa_is_an_argument(GAAargv
[gaa_last_non_option
]) == GAA_NOT_AN_OPTION
);
485 gaa_last_non_option
++);
487 if(gaa_num
== GAA_REST
)
490 gaa_last_non_option
= GAAargc
;
498 { gaa_help(); exit(0); ;};
502 case GAAOPTID_version
:
505 { psktool_version(); exit(0); ;};
509 case GAAOPTID_keysize
:
512 GAA_FILL(GAATMP_keysize
.arg1
, gaa_getint
, GAATMP_keysize
.size1
);
515 { gaaval
->key_size
= GAATMP_keysize
.arg1
;};
519 case GAAOPTID_netconf_hint
:
522 GAA_FILL(GAATMP_netconf_hint
.arg1
, gaa_getstr
, GAATMP_netconf_hint
.size1
);
525 { gaaval
->netconf_hint
= GAATMP_netconf_hint
.arg1
;};
529 case GAAOPTID_passwd
:
532 GAA_FILL(GAATMP_passwd
.arg1
, gaa_getstr
, GAATMP_passwd
.size1
);
535 { gaaval
->passwd
= GAATMP_passwd
.arg1
;};
539 case GAAOPTID_username
:
542 GAA_FILL(GAATMP_username
.arg1
, gaa_getstr
, GAATMP_username
.size1
);
545 { gaaval
->username
= GAATMP_username
.arg1
;};
553 return GAA_ERROR_UNKNOWN
;
556 int gaa(int argc
, char **argv
, gaainfo
*gaaval
)
568 opt_list
= (char*) gaa_malloc(GAA_NB_OPTION
+ 1);
570 for(l
= 0; l
< GAA_NB_OPTION
+ 1; l
++)
577 { gaaval
->username
=NULL
; gaaval
->passwd
=NULL
; gaaval
->key_size
= 0; gaaval
->netconf_hint
= NULL
; ;};
585 gaa_arg_used
= gaa_malloc(argc
* sizeof(char));
588 for(l
= 1; l
< argc
; l
++)
590 for(l
= 1; l
< argc
; l
++)
592 if(gaa_arg_used
[l
] == 0)
595 tmp1
= gaa_is_an_argument(GAAargv
[l
]);
598 case GAA_WORD_OPTION
:
600 case GAA_LETTER_OPTION
:
602 tmp2
= gaa_get_option_num(argv
[l
]+j
, tmp1
);
603 if(tmp2
== GAA_ERROR_NOMATCH
)
605 printf("Invalid option '%s'\n", argv
[l
]+j
);
608 switch(gaa_try(tmp2
, l
+1, gaaval
, opt_list
))
610 case GAA_ERROR_NOTENOUGH_ARGS
:
611 printf("'%s': not enough arguments\n",gaa_current_option
);
613 case GAA_ERROR_INVALID_ARG
:
614 printf("Invalid arguments\n");
619 printf("Unknown error\n");
623 case GAA_MULTIPLE_OPTION
:
624 for(j
= 1; j
< strlen(argv
[l
]); j
++)
626 tmp2
= gaa_get_option_num(argv
[l
]+j
, tmp1
);
627 if(tmp2
== GAA_ERROR_NOMATCH
)
629 printf("Invalid option '%c'\n", *(argv
[l
]+j
));
632 switch(gaa_try(tmp2
, l
+1, gaaval
, opt_list
))
634 case GAA_ERROR_NOTENOUGH_ARGS
:
635 printf("'%s': not enough arguments\n",gaa_current_option
);
637 case GAA_ERROR_INVALID_ARG
:
638 printf("Invalid arguments\n");
643 printf("Unknown error\n");
652 if(gaa_processing_file
== 0)
656 #ifdef GAA_REST_EXISTS
657 switch(gaa_try(GAA_REST
, 1, gaaval
, opt_list
))
659 case GAA_ERROR_NOTENOUGH_ARGS
:
660 printf("Rest: not enough arguments\n");
662 case GAA_ERROR_INVALID_ARG
:
663 printf("Invalid arguments\n");
668 printf("Unknown error\n");
672 for(l
= 1; l
< argc
; l
++)
674 if(gaa_arg_used
[l
] == 0)
676 printf("Too many arguments\n");
688 struct gaastrnode
*next
;
691 typedef struct gaastrnode gaa_str_node
;
693 static int gaa_internal_get_next_str(FILE *file
, gaa_str_node
*tmp_str
, int argc
)
697 int i
= 0, len
= 0, newline
= 0;
705 if (a
== EOF
) return 0;
707 while(a
== ' ' || a
== 9 || a
== '\n')
715 if (a
== EOF
) return 0;
718 pos_ini
= ftell(file
) - 1;
720 while(a
!= ' ' && a
!= 9 && a
!= '\n')
725 if(a
==EOF
) return 0; /* a = ' '; */
729 tmp_str
->str
= gaa_malloc((len
) * sizeof(char));
733 tmp_str
->str
[0] = '-';
734 tmp_str
->str
[1] = '-';
742 fseek(file
,pos_ini
, SEEK_SET
);
754 while(a
!= ' ' && a
!= 9 && a
!= '\n' && i
< len
);
756 tmp_str
->str
[i
- 1] = 0;
758 fseek(file
,- 1, SEEK_CUR
);
759 /* printf("%d\n", ftell(file)); */
764 int gaa_file(const char *name
, gaainfo
*gaaval
)
766 gaa_str_node
*first_str
, **tmp_str
, *tmp_str2
;
772 gaa_processing_file
= 1;
774 if((file
= fopen(name
, "r")) == NULL
)
776 printf("Couldn't open '%s' configuration file for reading\n", name
);
780 tmp_str
= &first_str
;
784 *tmp_str
= gaa_malloc(sizeof(gaa_str_node
));
786 (*tmp_str
)->str
= NULL
;
787 (*tmp_str
)->next
= NULL
;
789 rval
= gaa_internal_get_next_str(file
, *tmp_str
, argc
);
790 tmp_str
= &((*tmp_str
)->next
);
797 argv
= gaa_malloc((1 + argc
) * sizeof(char*));
799 tmp_str2
= first_str
;
801 for(i
= 1; i
< argc
; i
++)
803 argv
[i
] = tmp_str2
->str
;
804 tmp_str2
= tmp_str2
->next
;
807 rval
= gaa(argc
, argv
, gaaval
);
808 gaa_processing_file
= 0;