diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2005-01-26 22:38:54 +0000 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2005-01-26 22:38:54 +0000 |
commit | dbdb62493cae64f3f70d906822f7fb496e2c5a94 (patch) | |
tree | 9df04c8eb5a9c39f2ffe9937d416c648607b3c9f | |
parent | 3ae3dfea572bfca35dc7e3d8a9d6ea7cd227188b (diff) | |
download | gnutls-dbdb62493cae64f3f70d906822f7fb496e2c5a94.tar.gz |
srptool has now the --version parameter.
-rw-r--r-- | src/crypt-gaa.c | 948 | ||||
-rw-r--r-- | src/crypt-gaa.h | 14 | ||||
-rw-r--r-- | src/crypt.gaa | 3 |
3 files changed, 497 insertions, 468 deletions
diff --git a/src/crypt-gaa.c b/src/crypt-gaa.c index 0f71f3c1d7..f969853ca7 100644 --- a/src/crypt-gaa.c +++ b/src/crypt-gaa.c @@ -11,6 +11,8 @@ # include <io.h> #endif +void srptool_version(void); + #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -21,114 +23,124 @@ #endif #endif -static void *gaa_malloc(size_t size) -{ - void *ret; - ret = malloc(size); - if (ret == NULL) { - fprintf(stderr, "gaa: could not allocate memory"); - exit(1); - } - return ret; +static void* gaa_malloc( size_t size) { +void* ret; + ret = malloc(size); + if (ret==NULL) { + fprintf(stderr, "gaa: could not allocate memory"); + exit(1); + } + return ret; } -static void __gaa_helpsingle(char short_name, char *name, - char *arg_desc, char *opt_help) +static void __gaa_helpsingle(char short_name, char *name, + char *arg_desc, char *opt_help) { - int col1, col3, col4, tabsize = 3, curr; - int i; - - col1 = 5; /* Default values */ - col3 = 30; - col4 = 70; - - curr = 0; - for (i = 0; i < col1; i++) { - printf(" "); - curr++; - } - if (short_name) { - if (name && *name) { - printf("-%c, ", short_name); - curr += 4; - } else { - printf("-%c ", short_name); - curr += 3; - } - } - if (name && *name) { - printf("--%s ", name); - curr += 3 + strlen(name); - } - if (arg_desc && *arg_desc) { - printf("%s ", arg_desc); - curr += 1 + strlen(arg_desc); - } - if (curr >= col3) { - printf("\n"); - curr = 0; - } - if (opt_help) { /* let's print the option's help body */ - const char *str = opt_help; - while (*str) { - while (curr < col3) { - printf(" "); - curr++; - } - switch (*str) { - case '\n': - printf("\n"); - curr = 0; - break; - case '\t': - do { - printf(" "); - curr++; - } - while ((curr - col3) % tabsize != 0 && curr < col4); - case ' ': - if (*str == ' ') { - curr++; - printf(" "); - } - for (i = 1; str[i] && str[i] != ' ' && str[i] != '\n' - && str[i] != '\t'; i++); - if (curr + i - 1 >= col4) - curr = col4; - break; - default: - printf("%c", *str); - curr++; - } - if (curr >= col4) { - printf("\n"); - curr = 0; - } - str++; - } - } - printf("\n"); + int col1, col3, col4, tabsize = 3, curr; + int i; + + col1 = 5; /* Default values */ + col3 = 30; + col4 = 70; + + curr = 0; + for(i = 0; i < col1; i++) + { + printf(" "); + curr++; + } + if(short_name) + { + if(name && *name) + { + printf("-%c, ", short_name); + curr += 4; + } + else + { + printf("-%c ", short_name); + curr += 3; + } + } + if(name && *name) + { + printf("--%s ", name); + curr += 3 + strlen(name); + } + if(arg_desc && *arg_desc) + { + printf("%s ", arg_desc); + curr += 1 + strlen(arg_desc); + } + if(curr >= col3) + { + printf("\n"); + curr = 0; + } + if(opt_help) /* let's print the option's help body */ + { + const char *str = opt_help; + while(*str) + { + while(curr < col3) + { + printf(" "); + curr++; + } + switch(*str) + { + case '\n': + printf("\n"); + curr = 0; + break; + case '\t': + do + { + printf(" "); + curr++; + } + while((curr - col3) % tabsize != 0 && curr < col4); + case ' ': + if(*str == ' ') + { + curr++; + printf(" "); + } + for(i = 1; str[i] && str[i] != ' ' && str[i] != '\n' + && str[i] != '\t'; i++); + if(curr + i - 1 >= col4) + curr = col4; + break; + default: + printf("%c", *str); + curr++; + } + if(curr >= col4) + { + printf("\n"); + curr = 0; + } + str++; + } + } + printf("\n"); } void gaa_help(void) { - printf("Srptool help\nUsage : srptool [options]\n"); - __gaa_helpsingle('u', "username", "username ", "specify username."); - __gaa_helpsingle('p', "passwd", "FILE ", "specify a password file."); - __gaa_helpsingle('i', "index", "INDEX ", - "specify the index of the parameters in tpasswd.conf to use."); - __gaa_helpsingle('s', "salt", "SALT ", - "specify salt size for crypt algorithm."); - __gaa_helpsingle(0, "verify", "", "just verify password."); - __gaa_helpsingle('c', "passwd-conf", "FILE ", - "specify a password conf file."); - __gaa_helpsingle(0, "create-conf", "FILE ", - "Generate a tpasswd.conf file."); - __gaa_helpsingle('h', "help", "", "shows this help text"); + printf("Srptool help\nUsage : srptool [options]\n"); + __gaa_helpsingle('u', "username", "username ", "specify username."); + __gaa_helpsingle('p', "passwd", "FILE ", "specify a password file."); + __gaa_helpsingle('i', "index", "INDEX ", "specify the index of the parameters in tpasswd.conf to use."); + __gaa_helpsingle('s', "salt", "SALT ", "specify salt size for crypt algorithm."); + __gaa_helpsingle(0, "verify", "", "just verify password."); + __gaa_helpsingle('c', "passwd-conf", "FILE ", "specify a password conf file."); + __gaa_helpsingle(0, "create-conf", "FILE ", "Generate a tpasswd.conf file."); + __gaa_helpsingle('v', "version", "", "prints the program's version number"); + __gaa_helpsingle('h', "help", "", "shows this help text"); #line 100 "gaa.skel" } - /* Copy of C area */ #line 104 "gaa.skel" @@ -138,46 +150,54 @@ void gaa_help(void) typedef struct _gaainfo gaainfo; -struct _gaainfo { -#line 32 "crypt.gaa" - char *create_conf; -#line 29 "crypt.gaa" - char *passwd_conf; -#line 26 "crypt.gaa" - int verify; -#line 23 "crypt.gaa" - int salt; -#line 20 "crypt.gaa" - int index; -#line 17 "crypt.gaa" - char *passwd; -#line 14 "crypt.gaa" - char *username; +struct _gaainfo +{ +#line 34 "crypt.gaa" + char *create_conf; +#line 31 "crypt.gaa" + char *passwd_conf; +#line 28 "crypt.gaa" + int verify; +#line 25 "crypt.gaa" + int salt; +#line 22 "crypt.gaa" + int index; +#line 19 "crypt.gaa" + char *passwd; +#line 16 "crypt.gaa" + char *username; #line 114 "gaa.skel" }; #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif - int gaa(int argc, char *argv[], gaainfo * gaaval); + int gaa(int argc, char *argv[], gaainfo *gaaval); void gaa_help(void); - - int gaa_file(const char *name, gaainfo * gaaval); - + + int gaa_file(const char *name, gaainfo *gaaval); + #ifdef __cplusplus } #endif + + #endif + #line 135 "gaa.skel" + /* C declarations */ + #define GAAERROR(x) \ { \ gaa_error = 1; \ return x; \ } + static char *gaa_current_option; static int gaa_error = 0; @@ -200,15 +220,16 @@ static int gaa_error = 0; #define GAA_MULTIPLE_OPTION 3 #define GAA_REST 0 -#define GAA_NB_OPTION 8 +#define GAA_NB_OPTION 9 #define GAAOPTID_help 1 -#define GAAOPTID_create_conf 2 -#define GAAOPTID_passwd_conf 3 -#define GAAOPTID_verify 4 -#define GAAOPTID_salt 5 -#define GAAOPTID_index 6 -#define GAAOPTID_passwd 7 -#define GAAOPTID_username 8 +#define GAAOPTID_version 2 +#define GAAOPTID_create_conf 3 +#define GAAOPTID_passwd_conf 4 +#define GAAOPTID_verify 5 +#define GAAOPTID_salt 6 +#define GAAOPTID_index 7 +#define GAAOPTID_passwd 8 +#define GAAOPTID_username 9 #line 168 "gaa.skel" @@ -251,7 +272,7 @@ if(gaa_error == 1) \ { \ gaa_error = 0; \ return GAA_ERROR_INVALID_ARG; \ -} +} @@ -329,7 +350,7 @@ if(k == 0) \ printf("You must give at least one option of '%s'\n", str); \ return 0; \ } - + #define GAA_INCOMP(str) \ k = 0; \ for(i = 0; i < strlen(str); i++) \ @@ -348,7 +369,7 @@ if(k > 1) \ printf("The options '%s' are incompatible\n", str); \ return 0; \ } - + static char **GAAargv; static int GAAargc; @@ -360,25 +381,25 @@ static int gaa_getint(char *arg) { int tmp; char a; - if (sscanf(arg, "%d%c", &tmp, &a) < 1) { - printf("Option %s: '%s' isn't an integer\n", gaa_current_option, - arg); - GAAERROR(-1); + if(sscanf(arg, "%d%c", &tmp, &a) < 1) + { + printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg); + GAAERROR(-1); } return tmp; } static char gaa_getchar(char *arg) { - if (strlen(arg) != 1) { - printf("Option %s: '%s' isn't an character\n", gaa_current_option, - arg); - GAAERROR(-1); + if(strlen(arg) != 1) + { + printf("Option %s: '%s' isn't an character\n", gaa_current_option, arg); + GAAERROR(-1); } return arg[0]; } -static char *gaa_getstr(char *arg) +static char* gaa_getstr(char *arg) { return arg; } @@ -386,115 +407,122 @@ static float gaa_getfloat(char *arg) { float tmp; char a; - if (sscanf(arg, "%f%c", &tmp, &a) < 1) { - printf("Option %s: '%s' isn't a float number\n", - gaa_current_option, arg); - GAAERROR(-1); + if(sscanf(arg, "%f%c", &tmp, &a) < 1) + { + printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg); + GAAERROR(-1); } return tmp; } - /* option structures */ -struct GAAOPTION_create_conf { - char *arg1; - int size1; +struct GAAOPTION_create_conf +{ + char* arg1; + int size1; }; -struct GAAOPTION_passwd_conf { - char *arg1; - int size1; +struct GAAOPTION_passwd_conf +{ + char* arg1; + int size1; }; -struct GAAOPTION_salt { - int arg1; - int size1; +struct GAAOPTION_salt +{ + int arg1; + int size1; }; -struct GAAOPTION_index { - int arg1; - int size1; +struct GAAOPTION_index +{ + int arg1; + int size1; }; -struct GAAOPTION_passwd { - char *arg1; - int size1; +struct GAAOPTION_passwd +{ + char* arg1; + int size1; }; -struct GAAOPTION_username { - char *arg1; - int size1; +struct GAAOPTION_username +{ + char* arg1; + int size1; }; - + #line 349 "gaa.skel" static int gaa_is_an_argument(char *str) { #ifdef GAA_WIN32 - if (str[0] == '/' && str[1] != 0) + if(str[0] == '/' && str[1] != 0) return GAA_MULTIPLE_OPTION; #endif - if (str[0] != '-') - return GAA_NOT_AN_OPTION; - if (str[1] == 0) - return GAA_NOT_AN_OPTION; - if (str[1] == '-') { - if (str[2] != 0) - return GAA_WORD_OPTION; - else - return GAA_NOT_AN_OPTION; + if(str[0] != '-') + return GAA_NOT_AN_OPTION; + if(str[1] == 0) + return GAA_NOT_AN_OPTION; + if(str[1] == '-') + { + if(str[2] != 0) + return GAA_WORD_OPTION; + else + return GAA_NOT_AN_OPTION; } - if (str[2] == 0) - return GAA_LETTER_OPTION; + if(str[2] == 0) + return GAA_LETTER_OPTION; else - return GAA_MULTIPLE_OPTION; + return GAA_MULTIPLE_OPTION; } static int gaa_get_option_num(char *str, int status) { - switch (status) { - case GAA_LETTER_OPTION: - GAA_CHECK1STR("", GAAOPTID_create_conf); - GAA_CHECK1STR("c", GAAOPTID_passwd_conf); - GAA_CHECK1STR("s", GAAOPTID_salt); - GAA_CHECK1STR("i", GAAOPTID_index); - GAA_CHECK1STR("p", GAAOPTID_passwd); - GAA_CHECK1STR("u", GAAOPTID_username); - case GAA_MULTIPLE_OPTION: + switch(status) + { + case GAA_LETTER_OPTION: + GAA_CHECK1STR("", GAAOPTID_create_conf); + GAA_CHECK1STR("c", GAAOPTID_passwd_conf); + GAA_CHECK1STR("s", GAAOPTID_salt); + GAA_CHECK1STR("i", GAAOPTID_index); + GAA_CHECK1STR("p", GAAOPTID_passwd); + GAA_CHECK1STR("u", GAAOPTID_username); + case GAA_MULTIPLE_OPTION: #line 375 "gaa.skel" - GAA_CHECK1STR("h", GAAOPTID_help); - GAA_CHECK1STR("", GAAOPTID_verify); + GAA_CHECK1STR("h", GAAOPTID_help); + GAA_CHECK1STR("v", GAAOPTID_version); + GAA_CHECK1STR("", GAAOPTID_verify); #line 277 "gaa.skel" - break; - case GAA_WORD_OPTION: - GAA_CHECKSTR("help", GAAOPTID_help); - GAA_CHECKSTR("create-conf", GAAOPTID_create_conf); - GAA_CHECKSTR("passwd-conf", GAAOPTID_passwd_conf); - GAA_CHECKSTR("verify", GAAOPTID_verify); - GAA_CHECKSTR("salt", GAAOPTID_salt); - GAA_CHECKSTR("index", GAAOPTID_index); - GAA_CHECKSTR("passwd", GAAOPTID_passwd); - GAA_CHECKSTR("username", GAAOPTID_username); + break; + case GAA_WORD_OPTION: + GAA_CHECKSTR("help", GAAOPTID_help); + GAA_CHECKSTR("version", GAAOPTID_version); + GAA_CHECKSTR("create-conf", GAAOPTID_create_conf); + GAA_CHECKSTR("passwd-conf", GAAOPTID_passwd_conf); + GAA_CHECKSTR("verify", GAAOPTID_verify); + GAA_CHECKSTR("salt", GAAOPTID_salt); + GAA_CHECKSTR("index", GAAOPTID_index); + GAA_CHECKSTR("passwd", GAAOPTID_passwd); + GAA_CHECKSTR("username", GAAOPTID_username); #line 281 "gaa.skel" break; - default: - break; - } + default: break; + } return GAA_ERROR_NOMATCH; } -static int gaa_try(int gaa_num, int gaa_index, gaainfo * gaaval, - char *opt_list) +static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list) { int OK = 0; int gaa_last_non_option; - struct GAAOPTION_create_conf GAATMP_create_conf; - struct GAAOPTION_passwd_conf GAATMP_passwd_conf; - struct GAAOPTION_salt GAATMP_salt; - struct GAAOPTION_index GAATMP_index; - struct GAAOPTION_passwd GAATMP_passwd; - struct GAAOPTION_username GAATMP_username; + struct GAAOPTION_create_conf GAATMP_create_conf; + struct GAAOPTION_passwd_conf GAATMP_passwd_conf; + struct GAAOPTION_salt GAATMP_salt; + struct GAAOPTION_index GAATMP_index; + struct GAAOPTION_passwd GAATMP_passwd; + struct GAAOPTION_username GAATMP_username; #line 393 "gaa.skel" #ifdef GAA_REST_EXISTS @@ -502,120 +530,108 @@ static int gaa_try(int gaa_num, int gaa_index, gaainfo * gaaval, #endif opt_list[gaa_num] = 1; - - for (gaa_last_non_option = gaa_index; - (gaa_last_non_option != GAAargc) - && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == - GAA_NOT_AN_OPTION); gaa_last_non_option++); - - if (gaa_num == GAA_REST) { - gaa_index = 1; - gaa_last_non_option = GAAargc; + + for(gaa_last_non_option = gaa_index; + (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION); + gaa_last_non_option++); + + if(gaa_num == GAA_REST) + { + gaa_index = 1; + gaa_last_non_option = GAAargc; } + + switch(gaa_num) + { + case GAAOPTID_help: + OK = 0; +#line 38 "crypt.gaa" +{ gaa_help(); exit(0); ;}; - switch (gaa_num) { - case GAAOPTID_help: + return GAA_OK; + break; + case GAAOPTID_version: OK = 0; -#line 35 "crypt.gaa" - { - gaa_help(); - exit(0);; - }; +#line 37 "crypt.gaa" +{ srptool_version(); exit(0); ;}; - return GAA_OK; - break; - case GAAOPTID_create_conf: + return GAA_OK; + break; + case GAAOPTID_create_conf: OK = 0; - GAA_TESTMOREARGS; - GAA_FILL(GAATMP_create_conf.arg1, gaa_getstr, - GAATMP_create_conf.size1); - gaa_index++; -#line 33 "crypt.gaa" - { - gaaval->create_conf = GAATMP_create_conf.arg1; - }; - - return GAA_OK; - break; - case GAAOPTID_passwd_conf: + GAA_TESTMOREARGS; + GAA_FILL(GAATMP_create_conf.arg1, gaa_getstr, GAATMP_create_conf.size1); + gaa_index++; +#line 35 "crypt.gaa" +{ gaaval->create_conf = GAATMP_create_conf.arg1 ;}; + + return GAA_OK; + break; + case GAAOPTID_passwd_conf: OK = 0; - GAA_TESTMOREARGS; - GAA_FILL(GAATMP_passwd_conf.arg1, gaa_getstr, - GAATMP_passwd_conf.size1); - gaa_index++; -#line 30 "crypt.gaa" - { - gaaval->passwd_conf = GAATMP_passwd_conf.arg1; - }; - - return GAA_OK; - break; - case GAAOPTID_verify: + GAA_TESTMOREARGS; + GAA_FILL(GAATMP_passwd_conf.arg1, gaa_getstr, GAATMP_passwd_conf.size1); + gaa_index++; +#line 32 "crypt.gaa" +{ gaaval->passwd_conf = GAATMP_passwd_conf.arg1 ;}; + + return GAA_OK; + break; + case GAAOPTID_verify: OK = 0; -#line 27 "crypt.gaa" - { - gaaval->verify = 1; - }; +#line 29 "crypt.gaa" +{ gaaval->verify = 1 ;}; - return GAA_OK; - break; - case GAAOPTID_salt: + return GAA_OK; + break; + case GAAOPTID_salt: OK = 0; - GAA_TESTMOREARGS; - GAA_FILL(GAATMP_salt.arg1, gaa_getint, GAATMP_salt.size1); - gaa_index++; -#line 24 "crypt.gaa" - { - gaaval->salt = GAATMP_salt.arg1; - }; - - return GAA_OK; - break; - case GAAOPTID_index: + GAA_TESTMOREARGS; + GAA_FILL(GAATMP_salt.arg1, gaa_getint, GAATMP_salt.size1); + gaa_index++; +#line 26 "crypt.gaa" +{ gaaval->salt = GAATMP_salt.arg1 ;}; + + return GAA_OK; + break; + case GAAOPTID_index: OK = 0; - GAA_TESTMOREARGS; - GAA_FILL(GAATMP_index.arg1, gaa_getint, GAATMP_index.size1); - gaa_index++; -#line 21 "crypt.gaa" - { - gaaval->index = GAATMP_index.arg1; - }; - - return GAA_OK; - break; - case GAAOPTID_passwd: + GAA_TESTMOREARGS; + GAA_FILL(GAATMP_index.arg1, gaa_getint, GAATMP_index.size1); + gaa_index++; +#line 23 "crypt.gaa" +{ gaaval->index = GAATMP_index.arg1 ;}; + + return GAA_OK; + break; + case GAAOPTID_passwd: OK = 0; - GAA_TESTMOREARGS; - GAA_FILL(GAATMP_passwd.arg1, gaa_getstr, GAATMP_passwd.size1); - gaa_index++; -#line 18 "crypt.gaa" - { - gaaval->passwd = GAATMP_passwd.arg1; - }; - - return GAA_OK; - break; - case GAAOPTID_username: + GAA_TESTMOREARGS; + GAA_FILL(GAATMP_passwd.arg1, gaa_getstr, GAATMP_passwd.size1); + gaa_index++; +#line 20 "crypt.gaa" +{ gaaval->passwd = GAATMP_passwd.arg1 ;}; + + return GAA_OK; + break; + case GAAOPTID_username: OK = 0; - GAA_TESTMOREARGS; - GAA_FILL(GAATMP_username.arg1, gaa_getstr, GAATMP_username.size1); - gaa_index++; -#line 15 "crypt.gaa" - { - gaaval->username = GAATMP_username.arg1; - }; - - return GAA_OK; - break; + GAA_TESTMOREARGS; + GAA_FILL(GAATMP_username.arg1, gaa_getstr, GAATMP_username.size1); + gaa_index++; +#line 17 "crypt.gaa" +{ gaaval->username = GAATMP_username.arg1 ;}; + + return GAA_OK; + break; #line 413 "gaa.skel" - default: - break; + default: break; } return GAA_ERROR_UNKNOWN; } -int gaa(int argc, char **argv, gaainfo * gaaval) +int gaa(int argc, char **argv, gaainfo *gaaval) { int tmp1, tmp2; int i, j; @@ -624,23 +640,18 @@ int gaa(int argc, char **argv, gaainfo * gaaval) GAAargv = argv; GAAargc = argc; - opt_list = (char *) gaa_malloc(GAA_NB_OPTION + 1); + opt_list = (char*) gaa_malloc(GAA_NB_OPTION + 1); - for (i = 0; i < GAA_NB_OPTION + 1; i++) - opt_list[i] = 0; + for(i = 0; i < GAA_NB_OPTION + 1; i++) + opt_list[i] = 0; /* initialization */ - if (inited == 0) { + if(inited == 0) + { -#line 37 "crypt.gaa" - { - gaaval->username = NULL; - gaaval->passwd = NULL; - gaaval->salt = 0; - gaaval->create_conf = NULL; - gaaval->passwd_conf = NULL; - gaaval->verify = 0; - gaaval->index = 1;; - }; +#line 40 "crypt.gaa" +{ gaaval->username=NULL; gaaval->passwd=NULL; gaaval->salt=0; + gaaval->create_conf=NULL; gaaval->passwd_conf=NULL; gaaval->verify = 0; + gaaval->index = 1; ;}; } inited = 1; @@ -648,173 +659,186 @@ int gaa(int argc, char **argv, gaainfo * gaaval) gaa_arg_used = NULL; if (argc > 0) { - gaa_arg_used = gaa_malloc(argc * sizeof(char)); + gaa_arg_used = gaa_malloc(argc * sizeof(char)); } - for (i = 1; i < argc; i++) - gaa_arg_used[i] = 0; - for (i = 1; i < argc; i++) { - if (gaa_arg_used[i] == 0) { - j = 0; - tmp1 = gaa_is_an_argument(GAAargv[i]); - switch (tmp1) { - case GAA_WORD_OPTION: - j++; - case GAA_LETTER_OPTION: - j++; - tmp2 = gaa_get_option_num(argv[i] + j, tmp1); - if (tmp2 == GAA_ERROR_NOMATCH) { - printf("Invalid option '%s'\n", argv[i] + j); - return 0; - } - switch (gaa_try(tmp2, i + 1, gaaval, opt_list)) { - case GAA_ERROR_NOTENOUGH_ARGS: - printf("'%s': not enough arguments\n", - gaa_current_option); - return 0; - case GAA_ERROR_INVALID_ARG: - printf("Invalid arguments\n"); - return 0; - case GAA_OK: - break; - default: - printf("Unknown error\n"); - } - gaa_arg_used[i] = 1; - break; - case GAA_MULTIPLE_OPTION: - for (j = 1; j < strlen(argv[i]); j++) { - tmp2 = gaa_get_option_num(argv[i] + j, tmp1); - if (tmp2 == GAA_ERROR_NOMATCH) { - printf("Invalid option '%c'\n", *(argv[i] + j)); - return 0; - } - switch (gaa_try(tmp2, i + 1, gaaval, opt_list)) { - case GAA_ERROR_NOTENOUGH_ARGS: - printf("'%s': not enough arguments\n", - gaa_current_option); - return 0; - case GAA_ERROR_INVALID_ARG: - printf("Invalid arguments\n"); - return 0; - case GAA_OK: - break; - default: - printf("Unknown error\n"); - } - } - gaa_arg_used[i] = 1; - break; - default: - break; - } - } + for(i = 1; i < argc; i++) + gaa_arg_used[i] = 0; + for(i = 1; i < argc; i++) + { + if(gaa_arg_used[i] == 0) + { + j = 0; + tmp1 = gaa_is_an_argument(GAAargv[i]); + switch(tmp1) + { + case GAA_WORD_OPTION: + j++; + case GAA_LETTER_OPTION: + j++; + tmp2 = gaa_get_option_num(argv[i]+j, tmp1); + if(tmp2 == GAA_ERROR_NOMATCH) + { + printf("Invalid option '%s'\n", argv[i]+j); + return 0; + } + switch(gaa_try(tmp2, i+1, gaaval, opt_list)) + { + case GAA_ERROR_NOTENOUGH_ARGS: + printf("'%s': not enough arguments\n",gaa_current_option); + return 0; + case GAA_ERROR_INVALID_ARG: + printf("Invalid arguments\n"); + return 0; + case GAA_OK: + break; + default: + printf("Unknown error\n"); + } + gaa_arg_used[i] = 1; + break; + case GAA_MULTIPLE_OPTION: + for(j = 1; j < strlen(argv[i]); j++) + { + tmp2 = gaa_get_option_num(argv[i]+j, tmp1); + if(tmp2 == GAA_ERROR_NOMATCH) + { + printf("Invalid option '%c'\n", *(argv[i]+j)); + return 0; + } + switch(gaa_try(tmp2, i+1, gaaval, opt_list)) + { + case GAA_ERROR_NOTENOUGH_ARGS: + printf("'%s': not enough arguments\n",gaa_current_option); + return 0; + case GAA_ERROR_INVALID_ARG: + printf("Invalid arguments\n"); + return 0; + case GAA_OK: + break; + default: + printf("Unknown error\n"); + } + } + gaa_arg_used[i] = 1; + break; + default: break; + } + } } - if (gaa_processing_file == 0) { +if(gaa_processing_file == 0) +{ #line 507 "gaa.skel" #ifdef GAA_REST_EXISTS - switch (gaa_try(GAA_REST, 1, gaaval, opt_list)) { - case GAA_ERROR_NOTENOUGH_ARGS: - printf("Rest: not enough arguments\n"); - return 0; - case GAA_ERROR_INVALID_ARG: - printf("Invalid arguments\n"); - return 0; - case GAA_OK: - break; - default: - printf("Unknown error\n"); - } -#endif + switch(gaa_try(GAA_REST, 1, gaaval, opt_list)) + { + case GAA_ERROR_NOTENOUGH_ARGS: + printf("Rest: not enough arguments\n"); + return 0; + case GAA_ERROR_INVALID_ARG: + printf("Invalid arguments\n"); + return 0; + case GAA_OK: + break; + default: + printf("Unknown error\n"); } - for (i = 1; i < argc; i++) { - if (gaa_arg_used[i] == 0) { - printf("Too many arguments\n"); - return 0; - } +#endif +} + for(i = 1; i < argc; i++) + { + if(gaa_arg_used[i] == 0) + { + printf("Too many arguments\n"); + return 0; + } } free(gaa_arg_used); free(opt_list); return -1; } -struct gaastrnode { +struct gaastrnode +{ char *str; struct gaastrnode *next; }; typedef struct gaastrnode gaa_str_node; -static int gaa_internal_get_next_str(FILE * file, gaa_str_node * tmp_str, - int argc) +static int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc) { int pos_ini; int a; int i = 0, len = 0, newline = 0; - if (argc == 1) { - newline = 1; - len = 2; + if(argc == 1) { + newline = 1; + len = 2; } - - a = fgetc(file); - if (a == EOF) - return 0; - - while (a == ' ' || a == 9 || a == '\n') { - if (a == '\n') { - newline = 1; - len = 2; - } - a = fgetc(file); - if (a == EOF) - return 0; + + a = fgetc( file); + if (a == EOF) return 0; + + while(a == ' ' || a == 9 || a == '\n') + { + if(a == '\n') + { + newline=1; + len = 2; + } + a = fgetc( file); + if (a == EOF) return 0; } pos_ini = ftell(file) - 1; - while (a != ' ' && a != 9 && a != '\n') { + while(a != ' ' && a != 9 && a != '\n') + { - len++; - a = fgetc(file); - if (a == EOF) - return 0; //a = ' '; + len++; + a = fgetc( file); + if(a==EOF) return 0; //a = ' '; } len += 1; tmp_str->str = gaa_malloc((len) * sizeof(char)); - if (newline == 1) { - tmp_str->str[0] = '-'; - tmp_str->str[1] = '-'; - i = 2; - } else { - i = 0; + if(newline == 1) + { + tmp_str->str[0] = '-'; + tmp_str->str[1] = '-'; + i = 2; + } + else + { + i = 0; } - fseek(file, pos_ini, SEEK_SET); - do { - a = fgetc(file); - - if (a == EOF) { - i += 2; - break; - } - tmp_str->str[i] = a; - i++; + fseek(file,pos_ini, SEEK_SET); + do + { + a = fgetc( file); + + if (a == EOF) { + i+=2; + break; + } + tmp_str->str[i] = a; + i++; } - while (a != ' ' && a != 9 && a != '\n' && i < len); + while(a != ' ' && a != 9 && a != '\n' && i < len); tmp_str->str[i - 1] = 0; - fseek(file, -1, SEEK_CUR); + fseek(file,- 1, SEEK_CUR); /* printf("%d\n", ftell(file)); */ - + return -1; } -int gaa_file(const char *name, gaainfo * gaaval) +int gaa_file(const char *name, gaainfo *gaaval) { gaa_str_node *first_str, **tmp_str, *tmp_str2; int rval, i; @@ -823,36 +847,38 @@ int gaa_file(const char *name, gaainfo * gaaval) FILE *file; gaa_processing_file = 1; - - if ((file = fopen(name, "r")) == NULL) { - printf("Couldn't open '%s' configuration file for reading\n", - name); - return 1; + + if((file = fopen(name, "r")) == NULL) + { + printf("Couldn't open '%s' configuration file for reading\n", name); + return 1; } - + tmp_str = &first_str; - do { - argc++; - *tmp_str = gaa_malloc(sizeof(gaa_str_node)); + do + { + argc++; + *tmp_str = gaa_malloc(sizeof(gaa_str_node)); - (*tmp_str)->str = NULL; - (*tmp_str)->next = NULL; + (*tmp_str)->str = NULL; + (*tmp_str)->next = NULL; - rval = gaa_internal_get_next_str(file, *tmp_str, argc); - tmp_str = &((*tmp_str)->next); + rval = gaa_internal_get_next_str(file, *tmp_str, argc); + tmp_str = &((*tmp_str)->next); } - while (rval == -1); - - if (rval == 1) - return 0; - - argv = gaa_malloc((1 + argc) * sizeof(char *)); + while(rval == -1); + + if(rval == 1) + return 0; + + argv = gaa_malloc((1 + argc) * sizeof(char*)); tmp_str2 = first_str; argv[0] = "cfg"; - for (i = 1; i < argc; i++) { - argv[i] = tmp_str2->str; - tmp_str2 = tmp_str2->next; + for(i = 1; i < argc; i++) + { + argv[i] = tmp_str2->str; + tmp_str2 = tmp_str2->next; } rval = gaa(argc, argv, gaaval); diff --git a/src/crypt-gaa.h b/src/crypt-gaa.h index ba3ddf43b2..42eac7dfcb 100644 --- a/src/crypt-gaa.h +++ b/src/crypt-gaa.h @@ -8,19 +8,19 @@ typedef struct _gaainfo gaainfo; struct _gaainfo { -#line 32 "crypt.gaa" +#line 34 "crypt.gaa" char *create_conf; -#line 29 "crypt.gaa" +#line 31 "crypt.gaa" char *passwd_conf; -#line 26 "crypt.gaa" +#line 28 "crypt.gaa" int verify; -#line 23 "crypt.gaa" +#line 25 "crypt.gaa" int salt; -#line 20 "crypt.gaa" +#line 22 "crypt.gaa" int index; -#line 17 "crypt.gaa" +#line 19 "crypt.gaa" char *passwd; -#line 14 "crypt.gaa" +#line 16 "crypt.gaa" char *username; #line 114 "gaa.skel" diff --git a/src/crypt.gaa b/src/crypt.gaa index 5ef440b964..11b461e367 100644 --- a/src/crypt.gaa +++ b/src/crypt.gaa @@ -7,6 +7,8 @@ # include <io.h> #endif +void srptool_version(void); + #} helpnode "Srptool help\nUsage : srptool [options]" @@ -32,6 +34,7 @@ option (c, passwd-conf) STR "FILE" { $passwd_conf = $1 } "specify a password con #char *create_conf; option ( create-conf) STR "FILE" { $create_conf = $1 } "Generate a tpasswd.conf file." +option (v, version) { srptool_version(); exit(0); } "prints the program's version number" option (h, help) { gaa_help(); exit(0); } "shows this help text" init { $username=NULL; $passwd=NULL; $salt=0; |