>From 331701daa0fdebc0635cab02509d98916cccc0e5 Mon Sep 17 00:00:00 2001 From: Frank Dittrich Date: Fri, 15 Jun 2012 16:19:16 +0200 Subject: [PATCH 3/4] Markov: different error messages for missing [Markov:Default] section and for missing Statsfile definition in an existing [Markov:Default] section --- src/config.c | 2 +- src/config.h | 6 ++++++ src/mkv.c | 43 ++++++++++++++++++++++++++++++------------- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/config.c b/src/config.c index a48f608..eb88563 100644 --- a/src/config.c +++ b/src/config.c @@ -162,7 +162,7 @@ void cfg_init(char *name, int allow_missing) if (fclose(file)) pexit("fclose"); } -static struct cfg_section *cfg_get_section(char *section, char *subsection) +struct cfg_section *cfg_get_section(char *section, char *subsection) { struct cfg_section *current; char *p1, *p2; diff --git a/src/config.h b/src/config.h index bc932d5..62888ef 100644 --- a/src/config.h +++ b/src/config.h @@ -59,6 +59,12 @@ extern char *cfg_name; */ extern void cfg_init(char *name, int allow_missing); + +/* + * Returns a section list entry, or NULL if not found + */ +extern struct cfg_section *cfg_get_section(char *section, char *subsection); + /* * Searches for a section with the supplied name, and returns its line list * structure, or NULL if the search fails. diff --git a/src/mkv.c b/src/mkv.c index e72188f..04c8c37 100644 --- a/src/mkv.c +++ b/src/mkv.c @@ -246,7 +246,9 @@ void get_markov_options(struct db_main *db, unsigned int *minlen, unsigned int *maxlen, char **statfile) { - char * token; + //struct cfg_section *section; + char *token; + //char *mode; *level = 0; *start = 0; @@ -255,6 +257,29 @@ void get_markov_options(struct db_main *db, *minlevel = 0; *minlen = 0; + if(cfg_get_section(SECTION_MARKOV, SUBSECTION_DEFAULT) == NULL) + { +#ifdef HAVE_MPI + if (mpi_id == 0) +#endif + fprintf(stderr, + "Section [" SECTION_MARKOV "%s] not found\n", + SUBSECTION_DEFAULT); + error(); + } + *statfile = cfg_get_param(SECTION_MARKOV, SUBSECTION_DEFAULT, "Statsfile"); + if(*statfile == NULL) + { + log_event("Statsfile not defined"); +#ifdef HAVE_MPI + if (mpi_id == 0) +#endif + fprintf(stderr, + "Statsfile not defined in section [" + SECTION_MARKOV SUBSECTION_DEFAULT "]\n"); + error(); + } + if (mkv_param) { token = strtok(mkv_param, ":"); @@ -318,7 +343,8 @@ void get_markov_options(struct db_main *db, } if (db->format->params.plaintext_length <= MAX_MKV_LEN && - *maxlen > db->format->params.plaintext_length) { + *maxlen > db->format->params.plaintext_length) + { log_event("! MaxLen = %d is too large for this hash type", *maxlen); #ifdef HAVE_MPI @@ -331,7 +357,8 @@ void get_markov_options(struct db_main *db, *maxlen = db->format->params.plaintext_length; } else - if (*maxlen > MAX_MKV_LEN) { + if (*maxlen > MAX_MKV_LEN) + { log_event("! MaxLen = %d is too large (max=%d)", *maxlen, MAX_MKV_LEN); #ifdef HAVE_MPI if (mpi_id == 0) @@ -357,16 +384,6 @@ void get_markov_options(struct db_main *db, *minlen = *maxlen; } - *statfile = cfg_get_param(SECTION_MARKOV, SUBSECTION_DEFAULT, "Statsfile"); - if(*statfile == NULL) - { - log_event("statfile not defined"); -#ifdef HAVE_MPI - if (mpi_id == 0) -#endif - fprintf(stderr, "Statfile not defined\n"); - error(); - } } void do_markov_crack(struct db_main *db, char *mkv_param) { -- 1.7.7.6