summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2012-01-19 21:46:15 +0100
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2012-01-21 01:07:09 +0100
commite6961e8222abb24ceda4d579cb3b5d7254016a00 (patch)
tree0f1d8a78ae31fab937c999c9ebde3c2aa1c643c5 /src
parentf8dabd58879c541f8dad387a97023e54ec7ce40b (diff)
downloadgnutls-e6961e8222abb24ceda4d579cb3b5d7254016a00.tar.gz
psktool also uses libopt.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am7
-rw-r--r--src/cli-args.c2
-rw-r--r--src/cli-args.h2
-rw-r--r--src/psk-args.def.in82
-rw-r--r--src/psk-gaa.c803
-rw-r--r--src/psk-gaa.h37
-rw-r--r--src/psk.c49
-rw-r--r--src/psk.gaa28
-rw-r--r--src/srptool-args.c2
-rw-r--r--src/srptool-args.h2
10 files changed, 117 insertions, 897 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index fcdeb7a033..7b8109e51b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -83,10 +83,10 @@ libcmd_ocsp_la_SOURCES = ocsptool.gaa ocsptool-gaa.h ocsptool-gaa.c
endif
psktool_SOURCES = psk.c
-psktool_LDADD = ../lib/libgnutls.la libcmd-psk.la ../gl/libgnu.la
+psktool_LDADD = ../lib/libgnutls.la libcmd-psk.la ../gl/libgnu.la $(LIBOPTS_LDADD)
noinst_LTLIBRARIES += libcmd-psk.la
libcmd_psk_la_CFLAGS =
-libcmd_psk_la_SOURCES = psk.gaa psk-gaa.h psk-gaa.c
+libcmd_psk_la_SOURCES = psk-args.def psk-args.c psk-args.h
BENCHMARK_SRCS = benchmark-cipher.c benchmark.c benchmark.h benchmark-tls.c
@@ -155,7 +155,6 @@ libcmd_p11tool_la_LIBADD += ../gl/libgnu.la $(INET_PTON_LIB)
endif # ENABLE_PKCS11
-
psk-gaa.c: $(srcdir)/psk.gaa
-$(GAA) $< -o psk-gaa.c -i psk-gaa.h
ocsptool-gaa.c: $(srcdir)/ocsptool.gaa
@@ -166,6 +165,8 @@ p11tool-gaa.c: $(srcdir)/p11tool.gaa
endif
certtool-gaa.c: $(srcdir)/certtool.gaa
-$(GAA) $< -o certtool-gaa.c -i certtool-gaa.h
+psk-args.c: $(srcdir)/psk-args.def
+ -autogen $<
cli-debug-args.c: $(srcdir)/cli-debug-args.def
-autogen $<
cli-args.c: $(srcdir)/cli-args.def
diff --git a/src/cli-args.c b/src/cli-args.c
index 9897a3aee4..441771dfaf 100644
--- a/src/cli-args.c
+++ b/src/cli-args.c
@@ -2,7 +2,7 @@
*
* DO NOT EDIT THIS FILE (cli-args.c)
*
- * It has been AutoGen-ed January 19, 2012 at 09:24:21 PM by AutoGen 5.12
+ * It has been AutoGen-ed January 19, 2012 at 09:42:06 PM by AutoGen 5.12
* From the definitions cli-args.def
* and the template file options
*
diff --git a/src/cli-args.h b/src/cli-args.h
index d789e3b797..72e15387a4 100644
--- a/src/cli-args.h
+++ b/src/cli-args.h
@@ -2,7 +2,7 @@
*
* DO NOT EDIT THIS FILE (cli-args.h)
*
- * It has been AutoGen-ed January 19, 2012 at 09:24:21 PM by AutoGen 5.12
+ * It has been AutoGen-ed January 19, 2012 at 09:42:05 PM by AutoGen 5.12
* From the definitions cli-args.def
* and the template file options
*
diff --git a/src/psk-args.def.in b/src/psk-args.def.in
new file mode 100644
index 0000000000..01130e8443
--- /dev/null
+++ b/src/psk-args.def.in
@@ -0,0 +1,82 @@
+AutoGen Definitions options;
+prog-name = psktool;
+prog-title = "GnuTLS PSK tool";
+prog-desc = "Program to create PSK parameters.\n";
+detail = "Program that generates random keys for use with TLS-PSK. The
+keys are stored in hexadecimal format in a key file.";
+short-usage = "psktool [options]\npsktool --help for usage instructions.\n";
+prog-group = "GnuTLS";
+gnu-usage;
+no-misuse-usage;
+reorder-args;
+disable-save;
+argument;
+long-opts;
+config-header = 'config.h';
+export = '#include <gettext.h>';
+
+copyright = {
+ date = "2000-2012";
+ owner = "Free Software Foundation";
+ author = "Nikos Mavrogiannopoulos and Simon Josefsson";
+ eaddr = "bug-gnutls@gnu.org";
+ type = gpl;
+};
+version = "@VERSION@";
+
+flag = {
+ name = debug;
+ value = d;
+ arg-type = number;
+ arg-range = "0 -> 9999";
+ descrip = "Enable debugging.";
+ doc = "Specifies the debug level.";
+};
+
+flag = {
+ name = keysize;
+ value = s;
+ arg-type = number;
+ arg-range = "0 -> 512";
+ descrip = "specify the key size in bytes";
+ doc = "";
+};
+
+flag = {
+ name = username;
+ value = u;
+ arg-type = string;
+ descrip = "specify a username";
+ doc = "";
+};
+
+flag = {
+ name = passwd;
+ value = p;
+ arg-type = string;
+ descrip = "specify a password file.";
+ doc = "";
+};
+
+doc-section = {
+ ds-type = 'SEE ALSO';
+ ds-format = 'man';
+ ds-text = <<-_EOT_
+ gnutls-cli-debug (1), gnutls-serv (1), srptool (1), certtool (1)
+_EOT_;
+};
+
+doc-section = {
+ ds-type = 'EXAMPLES';
+ ds-format = 'texi';
+ ds-text = <<-_EOT_
+To add a user 'test' in @file{passwd.psk} for use with GnuTLS run:
+@example
+$ psktool --passwd /etc/passwd.psk -u test
+@end example
+
+This command will create @file{/etc/passwd.psk} if it does not exist
+and will add user 'test' (you will also be prompted for a password).
+_EOT_;
+};
+
diff --git a/src/psk-gaa.c b/src/psk-gaa.c
deleted file mode 100644
index fda757fe80..0000000000
--- a/src/psk-gaa.c
+++ /dev/null
@@ -1,803 +0,0 @@
-/* File generated by GAA 1.6.6
- */
-#define GAA_NO_WIN32
-#line 1 "psk.gaa"
-
-
-/* C declarations */
-
-#include <config.h>
-#ifdef _WIN32
-# include <io.h>
-#endif
-
-void psktool_version(void);
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#ifndef GAA_NO_WIN32
-#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(WINDOWS)
-#define GAA_WIN32
-#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_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");
-}
-
-void gaa_help(void)
-{
- printf("PSKtool help\nUsage : psktool [options]\n");
- __gaa_helpsingle('u', "username", "username ", "specify username.");
- __gaa_helpsingle('p', "passwd", "FILE ", "specify a password file.");
- __gaa_helpsingle('s', "keysize", "SIZE ", "specify the key size in bytes.");
- __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"
-/* GAA HEADER */
-#ifndef GAA_HEADER_POKY
-#define GAA_HEADER_POKY
-
-typedef struct _gaainfo gaainfo;
-
-struct _gaainfo
-{
-#line 22 "psk.gaa"
- int key_size;
-#line 19 "psk.gaa"
- char *passwd;
-#line 16 "psk.gaa"
- char *username;
-
-#line 114 "gaa.skel"
-};
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
- int gaa(int argc, char *argv[], gaainfo *gaaval);
-
- void gaa_help(void);
-
- 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;
-
-/* Generated by gaa */
-
-#include <string.h>
-#include <stdlib.h>
-
-
-#define GAA_OK -1
-
-#define GAA_ERROR_NOMATCH 0
-#define GAA_ERROR_NOTENOUGH_ARGS 1
-#define GAA_ERROR_INVALID_ARG 2
-#define GAA_ERROR_UNKNOWN 3
-
-#define GAA_NOT_AN_OPTION 0
-#define GAA_WORD_OPTION 1
-#define GAA_LETTER_OPTION 2
-#define GAA_MULTIPLE_OPTION 3
-
-#define GAA_REST 0
-#define GAA_NB_OPTION 5
-#define GAAOPTID_help 1
-#define GAAOPTID_version 2
-#define GAAOPTID_keysize 3
-#define GAAOPTID_passwd 4
-#define GAAOPTID_username 5
-
-#line 168 "gaa.skel"
-
-#define GAA_CHECK1STR(a,b) \
-if(a[0] == str[0]) \
-{ \
- gaa_current_option = a; \
- return b; \
-}
-
-#define GAA_CHECKSTR(a,b) \
-if(strcmp(a,str) == 0) \
-{ \
- gaa_current_option = a; \
- return b; \
-}
-
-#define GAA_TESTMOREARGS \
-if(!OK) \
-{ \
-while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
- gaa_index++; \
-if(gaa_last_non_option == gaa_index) \
- return GAA_ERROR_NOTENOUGH_ARGS; \
-}
-
-#define GAA_TESTMOREOPTIONALARGS \
-if(!OK) \
-{ \
-while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
- gaa_index++; \
-if(gaa_last_non_option == gaa_index) \
- OK = 1; \
-}
-
-#define GAA_FILL_2ARGS(target, func) \
-target = func(GAAargv[gaa_index]); \
-gaa_arg_used[gaa_index] = 1; \
-if(gaa_error == 1) \
-{ \
- gaa_error = 0; \
- return GAA_ERROR_INVALID_ARG; \
-}
-
-
-
-#define GAA_FILL(target, func, num) \
-if(!OK) \
-{ \
-target = func(GAAargv[gaa_index]); \
-gaa_arg_used[gaa_index] = 1; \
-if(gaa_error == 1) \
-{ \
- gaa_error = 0; \
- return GAA_ERROR_INVALID_ARG; \
-} \
-num = 1; \
-} \
-else \
-{ \
-num = 0; \
-}
-
-#define GAA_LIST_FILL(target, func, type ,num) \
-if(!OK) \
-{ \
-num = 0; \
-target = NULL; \
-if ( gaa_last_non_option - gaa_index > 0) \
- target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
-for(; gaa_index < gaa_last_non_option; gaa_index++) \
-{ \
- if(gaa_arg_used[gaa_index] == 0) \
- { \
- GAA_FILL_2ARGS(target[num], func); \
- num++; \
- } \
-} \
-if(num == 0) \
- return GAA_ERROR_NOTENOUGH_ARGS; \
-}
-
-#define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
-if(!OK) \
-{ \
-num = 0; \
-target = NULL; \
-if ( gaa_last_non_option - gaa_index > 0) \
- target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
-for(; gaa_index < gaa_last_non_option; gaa_index++) \
-{ \
- if(gaa_arg_used[gaa_index] == 0) \
- { \
- GAA_FILL_2ARGS(target[num], func); \
- num++; \
- } \
-} \
-}
-
-#define GAA_OBLIGAT(str) \
-k = 0; \
-for(i = 0; i < strlen(str); i++) \
-{ \
- j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
- if(j == GAA_ERROR_NOMATCH) \
- { \
- printf("Error: invalid 'obligat' set\n"); \
- exit(-1); \
- } \
- if(opt_list[j] == 1) \
- k = 1; \
-} \
-if(k == 0) \
-{ \
- if(strlen(str) == 1) \
- printf("You must give the -%s option\n", str); \
- else \
- 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++) \
-{ \
- j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
- if(j == GAA_ERROR_NOMATCH) \
- { \
- printf("Error: invalid 'obligat' set\n"); \
- exit(-1); \
- } \
- if(opt_list[j] == 1) \
- k++; \
-} \
-if(k > 1) \
-{ \
- printf("The options '%s' are incompatible\n", str); \
- return 0; \
-}
-
-
-static char **GAAargv;
-static int GAAargc;
-static char *gaa_arg_used;
-static int gaa_processing_file = 0;
-static int inited = 0;
-
-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);
- }
- 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);
- }
- return arg[0];
-}
-
-static char* gaa_getstr(char *arg)
-{
- return arg;
-}
-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);
- }
- return tmp;
-}
-/* option structures */
-
-struct GAAOPTION_keysize
-{
- int arg1;
- int size1;
-};
-
-struct GAAOPTION_passwd
-{
- 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)
- 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[2] == 0)
- return GAA_LETTER_OPTION;
- else
- return GAA_MULTIPLE_OPTION;
-}
-
-static int gaa_get_option_num(char *str, int status)
-{
- switch(status)
- {
- case GAA_LETTER_OPTION:
- GAA_CHECK1STR("s", GAAOPTID_keysize);
- 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("v", GAAOPTID_version);
-
-#line 277 "gaa.skel"
- break;
- case GAA_WORD_OPTION:
- GAA_CHECKSTR("help", GAAOPTID_help);
- GAA_CHECKSTR("version", GAAOPTID_version);
- GAA_CHECKSTR("keysize", GAAOPTID_keysize);
- GAA_CHECKSTR("passwd", GAAOPTID_passwd);
- GAA_CHECKSTR("username", GAAOPTID_username);
-
-#line 281 "gaa.skel"
- break;
- default: break;
- }
- return GAA_ERROR_NOMATCH;
-}
-
-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_keysize GAATMP_keysize;
- struct GAAOPTION_passwd GAATMP_passwd;
- struct GAAOPTION_username GAATMP_username;
-
-#line 393 "gaa.skel"
-#ifdef GAA_REST_EXISTS
- struct GAAREST GAAREST_tmp;
-#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;
- }
-
- switch(gaa_num)
- {
- case GAAOPTID_help:
- OK = 0;
-#line 26 "psk.gaa"
-{ gaa_help(); exit(0); ;};
-
- return GAA_OK;
- break;
- case GAAOPTID_version:
- OK = 0;
-#line 25 "psk.gaa"
-{ psktool_version(); exit(0); ;};
-
- return GAA_OK;
- break;
- case GAAOPTID_keysize:
- OK = 0;
- GAA_TESTMOREARGS;
- GAA_FILL(GAATMP_keysize.arg1, gaa_getint, GAATMP_keysize.size1);
- gaa_index++;
-#line 23 "psk.gaa"
-{ gaaval->key_size = GAATMP_keysize.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 20 "psk.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 17 "psk.gaa"
-{ gaaval->username = GAATMP_username.arg1 ;};
-
- return GAA_OK;
- break;
-
-#line 413 "gaa.skel"
- default: break;
- }
- return GAA_ERROR_UNKNOWN;
-}
-
-int gaa(int argc, char **argv, gaainfo *gaaval)
-{
- int tmp1, tmp2;
- int i, j;
- char *opt_list;
-
- GAAargv = argv;
- GAAargc = argc;
-
- opt_list = (char*) gaa_malloc(GAA_NB_OPTION + 1);
-
- for(i = 0; i < GAA_NB_OPTION + 1; i++)
- opt_list[i] = 0;
- /* initialization */
- if(inited == 0)
- {
-
-#line 28 "psk.gaa"
-{ gaaval->username=NULL; gaaval->passwd=NULL; gaaval->key_size = 0; ;};
-
- }
- inited = 1;
-#line 438 "gaa.skel"
- gaa_arg_used = NULL;
-
- if (argc > 0) {
- 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;
- }
- }
- }
-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
-}
- 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
-{
- 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)
-{
- int pos_ini;
- int a;
- int i = 0, len = 0, newline = 0;
-
- 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;
- }
-
- pos_ini = ftell(file) - 1;
-
- while(a != ' ' && a != 9 && a != '\n')
- {
-
- 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;
- }
-
- 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);
-
- tmp_str->str[i - 1] = 0;
-
- fseek(file,- 1, SEEK_CUR);
-/* printf("%d\n", ftell(file)); */
-
- return -1;
-}
-
-int gaa_file(const char *name, gaainfo *gaaval)
-{
- gaa_str_node *first_str, **tmp_str, *tmp_str2;
- int rval, i;
- char **argv;
- int argc = 0;
- 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;
- }
-
- tmp_str = &first_str;
- do
- {
- argc++;
- *tmp_str = gaa_malloc(sizeof(gaa_str_node));
-
- (*tmp_str)->str = NULL;
- (*tmp_str)->next = NULL;
-
- 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*));
-
- tmp_str2 = first_str;
- argv[0] = "cfg";
- for(i = 1; i < argc; i++)
- {
- argv[i] = tmp_str2->str;
- tmp_str2 = tmp_str2->next;
- }
-
- rval = gaa(argc, argv, gaaval);
- gaa_processing_file = 0;
- return rval;
-}
diff --git a/src/psk-gaa.h b/src/psk-gaa.h
deleted file mode 100644
index 88c5de5aed..0000000000
--- a/src/psk-gaa.h
+++ /dev/null
@@ -1,37 +0,0 @@
-
-#line 104 "gaa.skel"
-/* GAA HEADER */
-#ifndef GAA_HEADER_POKY
-#define GAA_HEADER_POKY
-
-typedef struct _gaainfo gaainfo;
-
-struct _gaainfo
-{
-#line 22 "psk.gaa"
- int key_size;
-#line 19 "psk.gaa"
- char *passwd;
-#line 16 "psk.gaa"
- char *username;
-
-#line 114 "gaa.skel"
-};
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
- int gaa(int argc, char *argv[], gaainfo *gaaval);
-
- void gaa_help(void);
-
- int gaa_file(const char *name, gaainfo *gaaval);
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif
diff --git a/src/psk.c b/src/psk.c
index 3ff6748dc2..207e850140 100644
--- a/src/psk.c
+++ b/src/psk.c
@@ -41,7 +41,7 @@ main (int argc, char **argv)
#include <string.h>
#include <stdlib.h>
#include <gnutls/gnutls.h>
-#include <psk-gaa.h>
+#include <psk-args.h>
#include <gnutls/crypto.h> /* for random */
@@ -60,21 +60,22 @@ main (int argc, char **argv)
#include "getpass.h"
static int write_key (const char *username, const char *key, int key_size,
- char *passwd_file);
+ const char *passwd_file);
#define KPASSWD "/etc/passwd.psk"
#define MAX_KEY_SIZE 64
int
main (int argc, char **argv)
{
- gaainfo info;
int ret;
#ifndef _WIN32
struct passwd *pwd;
#endif
unsigned char key[MAX_KEY_SIZE];
char hex_key[MAX_KEY_SIZE * 2 + 1];
+ int optct, key_size;
gnutls_datum_t dkey;
+ const char* passwd, *username;
size_t hex_key_size = sizeof (hex_key);
set_program_name (argv[0]);
@@ -87,16 +88,16 @@ main (int argc, char **argv)
umask (066);
- if (gaa (argc, argv, &info) != -1)
- {
- fprintf (stderr, "Error in the arguments.\n");
- return -1;
- }
+ optct = optionProcess( &psktoolOptions, argc, argv);
+ argc -= optct;
+ argv += optct;
- if (info.passwd == NULL)
- info.passwd = (char *) KPASSWD;
+ if (!HAVE_OPT(PASSWD))
+ passwd = (char *) KPASSWD;
+ else
+ passwd = OPT_ARG(PASSWD);
- if (info.username == NULL)
+ if (!HAVE_OPT(USERNAME))
{
#ifndef _WIN32
pwd = getpwuid (getuid ());
@@ -107,25 +108,29 @@ main (int argc, char **argv)
return -1;
}
- info.username = pwd->pw_name;
+ username = pwd->pw_name;
#else
fprintf (stderr, "Please specify a user\n");
return -1;
#endif
}
+ else
+ username = OPT_ARG(USERNAME);
- if (info.key_size > MAX_KEY_SIZE)
+ if (HAVE_OPT(KEYSIZE) && OPT_VALUE_KEYSIZE > MAX_KEY_SIZE)
{
fprintf (stderr, "Key size is too long\n");
exit (1);
}
- if (info.key_size < 1)
- info.key_size = 16;
+ if (!HAVE_OPT(KEYSIZE) || OPT_VALUE_KEYSIZE < 1)
+ key_size = 16;
+ else
+ key_size = OPT_VALUE_KEYSIZE;
- printf ("Generating a random key for user '%s'\n", info.username);
+ printf ("Generating a random key for user '%s'\n", username);
- ret = gnutls_rnd (GNUTLS_RND_RANDOM, (char *) key, info.key_size);
+ ret = gnutls_rnd (GNUTLS_RND_RANDOM, (char *) key, key_size);
if (ret < 0)
{
fprintf (stderr, "Not enough randomness\n");
@@ -133,7 +138,7 @@ main (int argc, char **argv)
}
dkey.data = key;
- dkey.size = info.key_size;
+ dkey.size = key_size;
ret = gnutls_hex_encode (&dkey, hex_key, &hex_key_size);
if (ret < 0)
@@ -142,15 +147,15 @@ main (int argc, char **argv)
exit (1);
}
- ret = write_key (info.username, hex_key, hex_key_size, info.passwd);
+ ret = write_key (username, hex_key, hex_key_size, passwd);
if (ret == 0)
- printf ("Key stored to %s\n", info.passwd);
+ printf ("Key stored to %s\n", passwd);
return ret;
}
static int
-filecopy (char *src, char *dst)
+filecopy (const char *src, const char *dst)
{
FILE *fd, *fd2;
char line[5 * 1024];
@@ -190,7 +195,7 @@ filecopy (char *src, char *dst)
static int
write_key (const char *username, const char *key, int key_size,
- char *passwd_file)
+ const char *passwd_file)
{
FILE *fd;
char line[5 * 1024];
diff --git a/src/psk.gaa b/src/psk.gaa
deleted file mode 100644
index f8eb6b5b45..0000000000
--- a/src/psk.gaa
+++ /dev/null
@@ -1,28 +0,0 @@
-#{
-
-/* C declarations */
-
-#include <config.h>
-#ifdef _WIN32
-# include <io.h>
-#endif
-
-void psktool_version(void);
-
-#}
-
-helpnode "PSKtool help\nUsage : psktool [options]"
-
-#char *username;
-option (u,username) STR "username" { $username = $1 } "specify username."
-
-#char *passwd;
-option (p, passwd) STR "FILE" { $passwd = $1 } "specify a password file."
-
-#int key_size;
-option (s, keysize) INT "SIZE" { $key_size = $1 } "specify the key size in bytes."
-
-option (v, version) { psktool_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; $key_size = 0; }
diff --git a/src/srptool-args.c b/src/srptool-args.c
index 02e6e3efd5..c2b831f2ce 100644
--- a/src/srptool-args.c
+++ b/src/srptool-args.c
@@ -2,7 +2,7 @@
*
* DO NOT EDIT THIS FILE (srptool-args.c)
*
- * It has been AutoGen-ed January 19, 2012 at 09:24:17 PM by AutoGen 5.12
+ * It has been AutoGen-ed January 19, 2012 at 09:42:05 PM by AutoGen 5.12
* From the definitions srptool-args.def
* and the template file options
*
diff --git a/src/srptool-args.h b/src/srptool-args.h
index 18be37d821..20db86d1bb 100644
--- a/src/srptool-args.h
+++ b/src/srptool-args.h
@@ -2,7 +2,7 @@
*
* DO NOT EDIT THIS FILE (srptool-args.h)
*
- * It has been AutoGen-ed January 19, 2012 at 09:24:17 PM by AutoGen 5.12
+ * It has been AutoGen-ed January 19, 2012 at 09:42:05 PM by AutoGen 5.12
* From the definitions srptool-args.def
* and the template file options
*