diff --git a/ChangeLog b/ChangeLog index fccc2e5be5..005834ff4a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -16,6 +16,8 @@ Changes in version 0.2.0.19-alpha - 2008-0?-?? 0.1.2.x. - Stop incorrectly truncating zlib responses to directory authority signature download requests. Fix for bug 593. Bugfix on 0.2.0.x. + - Don't trigger an assert if we start a directory authority with a + private IP address (like 127.0.0.1). Changes in version 0.2.0.18-alpha - 2008-01-25 diff --git a/src/or/config.c b/src/or/config.c index b0eeec6376..6a771909e5 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -2872,7 +2872,7 @@ options_validate(or_options_t *old_options, or_options_t *options, options->V1AuthoritativeDir || options->V2AuthoritativeDir || options->V3AuthoritativeDir)) REJECT("AuthoritativeDir is set, but none of " - "(Bridge/HS/V1/V2/V3)AuthoriativeDir is set."); + "(Bridge/HS/V1/V2/V3)AuthoritativeDir is set."); } if (options->AuthoritativeDir && !options->DirPort) @@ -3974,12 +3974,12 @@ parse_bridge_line(const char *line, int validate_only) return r; } -/** Read the contents of a DirServer line from line. Return 0 - * if the line is well-formed, and -1 if it isn't. If +/** Read the contents of a DirServer line from line. If * validate_only is 0, and the line is well-formed, and it * shares any bits with required_type or required_type * is 0, then add the dirserver described in the line (minus whatever - * bits it's missing) as a valid authority. */ + * bits it's missing) as a valid authority. Return 0 on success, + * or -1 if the line isn't well-formed or if we can't add it. */ static int parse_dir_server_line(const char *line, authority_type_t required_type, int validate_only) @@ -4088,8 +4088,9 @@ parse_dir_server_line(const char *line, authority_type_t required_type, * authority for. */ log_debug(LD_DIR, "Trusted %d dirserver at %s:%d (%s)", (int)type, address, (int)dir_port, (char*)smartlist_get(items,0)); - add_trusted_dir_server(nickname, address, dir_port, or_port, digest, - v3_digest, type); + if (!add_trusted_dir_server(nickname, address, dir_port, or_port, + digest, v3_digest, type)) + goto err; } r = 0; diff --git a/src/or/or.h b/src/or/or.h index d508a3241a..1b858a3327 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -3929,10 +3929,11 @@ void routerlist_retry_directory_downloads(time_t now); int router_exit_policy_all_routers_reject(uint32_t addr, uint16_t port, int need_uptime); int router_exit_policy_rejects_all(routerinfo_t *router); -void add_trusted_dir_server(const char *nickname, const char *address, - uint16_t dir_port, uint16_t or_port, - const char *digest, const char *v3_auth_digest, - authority_type_t type); +trusted_dir_server_t *add_trusted_dir_server(const char *nickname, + const char *address, + uint16_t dir_port, uint16_t or_port, + const char *digest, const char *v3_auth_digest, + authority_type_t type); void authority_cert_free(authority_cert_t *cert); void clear_trusted_dir_servers(void); int any_trusted_dir_is_v1_authority(void); diff --git a/src/or/router.c b/src/or/router.c index 1b098c3a1e..349c119547 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -559,16 +559,20 @@ init_keys(void) (options->BridgeAuthoritativeDir ? BRIDGE_AUTHORITY : NO_AUTHORITY) | (options->HSAuthoritativeDir ? HIDSERV_AUTHORITY : NO_AUTHORITY)); - if (!router_get_trusteddirserver_by_digest(digest)) { - add_trusted_dir_server(options->Nickname, NULL, - (uint16_t)options->DirPort, - (uint16_t)options->ORPort, - digest, - v3_digest, - type); - } ds = router_get_trusteddirserver_by_digest(digest); - tor_assert(ds); + if (!ds) { + ds = add_trusted_dir_server(options->Nickname, NULL, + (uint16_t)options->DirPort, + (uint16_t)options->ORPort, + digest, + v3_digest, + type); + if (!ds) { + log_err(LD_GENERAL,"We want to be a directory authority, but we " + "couldn't add ourselves to the authority list. Failing."); + return -1; + } + } if (ds->type != type) { log_warn(LD_DIR, "Configured authority type does not match authority " "type in DirServer list. Adjusting. (%d v %d)", diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 375ba6cf8b..5a347ae4f8 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -3366,8 +3366,9 @@ router_exit_policy_rejects_all(routerinfo_t *router) /** Add to the list of authorized directory servers one at * address:port, with identity key digest. If - * address is NULL, add ourself. */ -void + * address is NULL, add ourself. Return 0 if success, -1 if + * we couldn't add it. */ +trusted_dir_server_t * add_trusted_dir_server(const char *nickname, const char *address, uint16_t dir_port, uint16_t or_port, const char *digest, const char *v3_auth_digest, @@ -3385,14 +3386,14 @@ add_trusted_dir_server(const char *nickname, const char *address, log_warn(LD_CONFIG, "Couldn't find a suitable address when adding ourself as a " "trusted directory server."); - return; + return NULL; } } else { if (tor_lookup_hostname(address, &a)) { log_warn(LD_CONFIG, "Unable to lookup address for directory server at '%s'", address); - return; + return NULL; } hostname = tor_strdup(address); } @@ -3433,6 +3434,7 @@ add_trusted_dir_server(const char *nickname, const char *address, smartlist_add(trusted_dir_servers, ent); router_dir_info_changed(); + return ent; } /** Free storage held in cert. */