From 5166d65ea22213e9aae00e17f0f00a5cc533bd27 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Thu, 9 Aug 2007 15:16:25 +0000 Subject: [PATCH] debug override date config option. git-svn-id: file:///svn/unbound/trunk@505 be551aaa-1e26-0410-a405-d3ace91eadb9 --- doc/Changelog | 1 + doc/example.conf | 5 +++++ util/config_file.c | 23 +++++++++++++++++++++++ util/config_file.h | 7 +++++++ util/configlexer.lex | 1 + util/configparser.y | 22 ++++++++++++++++++++-- validator/val_sigcrypt.c | 5 +++-- 7 files changed, 60 insertions(+), 4 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index 06f9f4105..56295e5a4 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -4,6 +4,7 @@ - added debug heap size print to memory printout. - typo fixup in worker.c - -R needed on solaris. + - validator override option for date check testing. 8 August 2007: Wouter - ldns _raw routines created (in ldns trunk). diff --git a/doc/example.conf b/doc/example.conf index 30db19437..caabbf9de 100644 --- a/doc/example.conf +++ b/doc/example.conf @@ -162,6 +162,11 @@ server: # (These examples are from August 2007 and may not be valid anymore). # trust-anchor: "nlnetlabs.nl. DNSKEY 257 3 5 AQPzzTWMz8qSWIQlfRnPckx2BiVmkVN6LPupO3mbz7FhLSnm26n6iG9N Lby97Ji453aWZY3M5/xJBSOS2vWtco2t8C0+xeO1bc/d6ZTy32DHchpW 6rDH1vp86Ll+ha0tmwyy9QP7y2bVw5zSbFCrefk8qCUBgfHm9bHzMG1U BYtEIQ==" # trust-anchor: "jelte.nlnetlabs.nl. DS 42860 5 1 14D739EB566D2B1A5E216A0BA4D17FA9B038BE4A" + + # Override the date for validation with a specific fixed date. + # Do not set this unless you are debugging signature inception + # and expiration. "" or "0" turns the feature off. + # val-override-date: "" # Stub zones. # Create entries like below, to make all queries for 'example.com' and diff --git a/util/config_file.c b/util/config_file.c index 2be1ff784..5d831a4b0 100644 --- a/util/config_file.c +++ b/util/config_file.c @@ -258,3 +258,26 @@ cfg_strlist_insert(struct config_strlist** head, char* item) *head = s; return 1; } + +uint32_t +cfg_convert_timeval(const char* str) +{ + uint32_t t; + struct tm tm; + memset(&tm, 0, sizeof(tm)); + if(sscanf(str, "%4d%2d%2d%2d%2d%2d", &tm.tm_year, &tm.tm_mon, + &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) + return 0; + tm.tm_year -= 1900; + tm.tm_mon--; + /* Check values */ + if (tm.tm_year < 70) return 0; + if (tm.tm_mon < 0 || tm.tm_mon > 11) return 0; + if (tm.tm_mday < 1 || tm.tm_mday > 31) return 0; + if (tm.tm_hour < 0 || tm.tm_hour > 23) return 0; + if (tm.tm_min < 0 || tm.tm_min > 59) return 0; + if (tm.tm_sec < 0 || tm.tm_sec > 59) return 0; + /* call ldns conversion function */ + t = mktime_from_utc(&tm); + return t; +} diff --git a/util/config_file.h b/util/config_file.h index d70f33c28..42f383ad3 100644 --- a/util/config_file.h +++ b/util/config_file.h @@ -203,6 +203,13 @@ void config_delete(struct config_file* config); */ int cfg_strlist_insert(struct config_strlist** head, char* item); +/** + * Convert 14digit to time value + * @param str: string of 14 digits + * @return time value or 0 for error. + */ +uint32_t cfg_convert_timeval(const char* str); + /** * Used during options parsing */ diff --git a/util/configlexer.lex b/util/configlexer.lex index 5f128ec4c..775797412 100644 --- a/util/configlexer.lex +++ b/util/configlexer.lex @@ -144,6 +144,7 @@ version{COLON} { YDOUT; return VAR_VERSION;} module-conf{COLON} { YDOUT; return VAR_MODULE_CONF;} trust-anchor-file{COLON} { YDOUT; return VAR_TRUST_ANCHOR_FILE;} trust-anchor{COLON} { YDOUT; return VAR_TRUST_ANCHOR;} +val-override-date{COLON} { YDOUT; return VAR_VAL_OVERRIDE_DATE;} {NEWLINE} { LEXOUT(("NL\n")); cfg_parser->line++;} /* Quoted strings. Strip leading and ending quotes */ diff --git a/util/configparser.y b/util/configparser.y index fa2a57bfd..bc921b930 100644 --- a/util/configparser.y +++ b/util/configparser.y @@ -80,7 +80,7 @@ extern struct config_parser_state* cfg_parser; %token VAR_FORWARD_ZONE VAR_FORWARD_HOST VAR_FORWARD_ADDR %token VAR_DO_NOT_QUERY_ADDRESS VAR_HIDE_IDENTITY VAR_HIDE_VERSION %token VAR_IDENTITY VAR_VERSION VAR_HARDEN_GLUE VAR_MODULE_CONF -%token VAR_TRUST_ANCHOR_FILE VAR_TRUST_ANCHOR +%token VAR_TRUST_ANCHOR_FILE VAR_TRUST_ANCHOR VAR_VAL_OVERRIDE_DATE %% toplevelvars: /* empty */ | toplevelvars toplevelvar ; @@ -114,7 +114,7 @@ content_server: server_num_threads | server_verbosity | server_port | server_do_not_query_address | server_hide_identity | server_hide_version | server_identity | server_version | server_harden_glue | server_module_conf | server_trust_anchor_file | - server_trust_anchor + server_trust_anchor | server_val_override_date ; stubstart: VAR_STUB_ZONE { @@ -486,6 +486,24 @@ server_module_conf: VAR_MODULE_CONF STRING cfg_parser->cfg->module_conf = $2; } ; +server_val_override_date: VAR_VAL_OVERRIDE_DATE STRING + { + OUTYY(("P(server_val_override_date:%s)\n", $2)); + if(strlen($2) == 0 || strcmp($2, "0") == 0) { + cfg_parser->cfg->val_date_override = 0; + } else if(strlen($2) == 14) { + cfg_parser->cfg->val_date_override = + cfg_convert_timeval($2); + if(!cfg_parser->cfg->val_date_override) + yyerror("bad date/time specification"); + } else { + if(atoi($2) == 0) + yyerror("number expected"); + cfg_parser->cfg->outgoing_num_ports = atoi($2); + } + free($2); + } + ; stub_name: VAR_NAME STRING { OUTYY(("P(name:%s)\n", $2)); diff --git a/validator/val_sigcrypt.c b/validator/val_sigcrypt.c index 614310d7a..f1a2e6e84 100644 --- a/validator/val_sigcrypt.c +++ b/validator/val_sigcrypt.c @@ -659,9 +659,10 @@ check_dates(struct val_env* ve, uint8_t* expi_p, uint8_t* incep_p) incep = ntohl(incep); /* get current date */ - if(ve->date_override) + if(ve->date_override) { now = ve->date_override; - else now = (int32_t)time(0); + verbose(VERB_ALGO, "date override option %d", (int)now); + } else now = (int32_t)time(0); /* check them */ if(incep - expi > 0) { -- 2.47.2