From 9e8ae9766e5d4eb94972f2e7118ce8e9c2e09381 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sun, 3 Oct 2004 02:37:52 +0000 Subject: [PATCH] Only check versions against downloaded directories, not cached directories. svn:r2413 --- src/or/directory.c | 2 +- src/or/dirserv.c | 2 +- src/or/or.h | 6 ++++-- src/or/routerlist.c | 8 +++++--- src/or/routerparse.c | 6 ++++-- src/or/test.c | 2 +- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/or/directory.c b/src/or/directory.c index f6995305fa..c505d92523 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -445,7 +445,7 @@ connection_dir_client_reached_eof(connection_t *conn) tor_free(body); tor_free(headers); return -1; } - if(router_load_routerlist_from_directory(body, NULL) < 0){ + if(router_load_routerlist_from_directory(body, NULL, 1) < 0){ log_fn(LOG_WARN,"I failed to parse the directory I fetched from %s:%d. Ignoring.", conn->address, conn->port); } else { log_fn(LOG_INFO,"updated routers."); diff --git a/src/or/dirserv.c b/src/or/dirserv.c index 8158e6aedb..a0eaf28ac2 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -742,7 +742,7 @@ static int dirserv_regenerate_directory(void) * necessary, but safe is better than sorry. */ new_directory = tor_strdup(the_directory); /* use a new copy of the dir, since get_dir_from_string scribbles on it */ - if (router_load_routerlist_from_directory(new_directory, get_identity_key())) { + if (router_load_routerlist_from_directory(new_directory, get_identity_key(), 1)) { log_fn(LOG_ERR, "We just generated a directory we can't parse. Dying."); tor_cleanup(); exit(0); diff --git a/src/or/or.h b/src/or/or.h index eba01b8e61..5c14e4d69e 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1420,7 +1420,8 @@ void router_mark_as_down(const char *digest); void routerlist_remove_old_routers(int age); int router_load_routerlist_from_file(char *routerfile, int trusted); int router_load_routerlist_from_string(const char *s, int trusted); -int router_load_routerlist_from_directory(const char *s,crypto_pk_env_t *pkey); +int router_load_routerlist_from_directory(const char *s,crypto_pk_env_t *pkey, + int check_version); int router_compare_addr_to_exit_policy(uint32_t addr, uint16_t port, struct exit_policy_t *policy); #define ADDR_POLICY_ACCEPTED 0 @@ -1455,7 +1456,8 @@ int router_parse_list_from_string(const char **s, time_t published); int router_parse_routerlist_from_directory(const char *s, routerlist_t **dest, - crypto_pk_env_t *pkey); + crypto_pk_env_t *pkey, + int check_version); running_routers_t *router_parse_runningrouters(const char *str); routerinfo_t *router_parse_entry_from_string(const char *s, const char *end); int router_add_exit_policy_from_string(routerinfo_t *router, const char *s); diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 7f8261595d..f0756b3e0c 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -65,7 +65,7 @@ int router_reload_router_list(void) s = read_file_to_str(filename,0); if (s) { log_fn(LOG_INFO, "Loading cached directory from %s", filename); - if (router_load_routerlist_from_directory(s, NULL) < 0) { + if (router_load_routerlist_from_directory(s, NULL, 0) < 0) { log_fn(LOG_WARN, "Cached directory '%s' was unparseable; ignoring.", filename); } if(routerlist->published_on > time(NULL) - OLD_MIN_ONION_KEY_LIFETIME/2) { @@ -793,10 +793,12 @@ int router_load_routerlist_from_string(const char *s, int trusted) * signed directory s. If pkey is provided, check the signature against * pkey; else check against the pkey of the signing directory server. */ int router_load_routerlist_from_directory(const char *s, - crypto_pk_env_t *pkey) + crypto_pk_env_t *pkey, + int check_version) { routerlist_t *new_list = NULL; - if (router_parse_routerlist_from_directory(s, &new_list, pkey)) { + if (router_parse_routerlist_from_directory(s, &new_list, pkey, + check_version)) { log_fn(LOG_WARN, "Couldn't parse directory."); return -1; } diff --git a/src/or/routerparse.c b/src/or/routerparse.c index 773340dea0..52076ff1f0 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -285,7 +285,8 @@ int check_software_version_against_directory(const char *directory, int /* Should be static; exposed for unit tests */ router_parse_routerlist_from_directory(const char *str, routerlist_t **dest, - crypto_pk_env_t *pkey) + crypto_pk_env_t *pkey, + int check_version) { directory_token_t *tok; char digest[DIGEST_LEN]; @@ -335,7 +336,8 @@ router_parse_routerlist_from_directory(const char *str, tokens = NULL; /* Now that we know the signature is okay, check the version. */ - check_software_version_against_directory(str, options.IgnoreVersion); + if (check_version) + check_software_version_against_directory(str, options.IgnoreVersion); /* Now try to parse the first part of the directory. */ if ((end = strstr(str,"\nrouter "))) { diff --git a/src/or/test.c b/src/or/test.c index f09399144c..2482f3028c 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -968,7 +968,7 @@ test_dir_format() options.Nickname = "DirServer"; test_assert(!dirserv_dump_directory_to_string(buf,8192,pk3)); cp = buf; - test_assert(!router_parse_routerlist_from_directory(buf, &dir1, pk3)); + test_assert(!router_parse_routerlist_from_directory(buf, &dir1, pk3, 1)); test_eq(2, smartlist_len(dir1->routers)); dirserv_free_fingerprint_list();