summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2006-09-29 04:51:28 +0000
committerNick Mathewson <nickm@torproject.org>2006-09-29 04:51:28 +0000
commit8992bf6204b70436c2dc881ffa2d79db40384b38 (patch)
tree6739ca3668aef26968b872c15b70dee91b75330d /src
parent4feccecfe813313a8302a44ed560dd7b61c51c2a (diff)
downloadtor-8992bf6204b70436c2dc881ffa2d79db40384b38.tar.gz
tor-8992bf6204b70436c2dc881ffa2d79db40384b38.zip
r8776@totoro: nickm | 2006-09-29 00:50:46 -0400
Reserve the nickname "Unnamed" for routers that can't pick a hostname; any router can call itself Unnamed; directory servers will never allocate Unnamed to any particular router; clients won't believe that any router is the canonical Unnamed. svn:r8529
Diffstat (limited to 'src')
-rw-r--r--src/or/config.c35
-rw-r--r--src/or/dirserv.c14
-rw-r--r--src/or/or.h2
-rw-r--r--src/or/routerlist.c2
-rw-r--r--src/or/routerparse.c3
5 files changed, 44 insertions, 12 deletions
diff --git a/src/or/config.c b/src/or/config.c
index d785cae9aa..b4fdf46b34 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -1731,20 +1731,21 @@ resolve_my_address(int warn_severity, or_options_t *options,
static char *
get_default_nickname(void)
{
+ static const char * const bad_default_nicknames[] = {
+ "localhost",
+ NULL,
+ };
char localhostname[256];
char *cp, *out, *outp;
+ int i;
if (gethostname(localhostname, sizeof(localhostname)) < 0)
return NULL;
/* Put it in lowercase; stop at the first dot. */
- for (cp = localhostname; *cp; ++cp) {
- if (*cp == '.') {
- *cp = '\0';
- break;
- }
- *cp = TOR_TOLOWER(*cp);
- }
+ if ((cp = strchr(localhostname, '.')))
+ *cp = '\0';
+ tor_strlower(localhostname);
/* Strip invalid characters. */
cp = localhostname;
@@ -1761,6 +1762,14 @@ get_default_nickname(void)
if (strlen(out) > MAX_NICKNAME_LEN)
out[MAX_NICKNAME_LEN]='\0';
+ /* Check for dumb names. */
+ for (i = 0; bad_default_nicknames[i]; ++i) {
+ if (!strcmp(out, bad_default_nicknames[i])) {
+ tor_free(out);
+ return NULL;
+ }
+ }
+
return out;
}
@@ -2122,10 +2131,14 @@ options_validate(or_options_t *old_options, or_options_t *options,
if (options->Nickname == NULL) {
if (server_mode(options)) {
- if (!(options->Nickname = get_default_nickname()))
- REJECT("Error obtaining local hostname");
- log_notice(LD_CONFIG, "Choosing default nickname '%s'",
- options->Nickname);
+ if (!(options->Nickname = get_default_nickname())) {
+ log_notice(LD_CONFIG, "Couldn't pick a nickname hostname based on "
+ "our hostname; using %s instead.", UNNAMED_ROUTER_NICKNAME);
+ options->Nickname = tor_strdup(UNNAMED_ROUTER_NICKNAME);
+ } else {
+ log_notice(LD_CONFIG, "Choosing default nickname '%s'",
+ options->Nickname);
+ }
}
} else {
if (!is_legal_nickname(options->Nickname)) {
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 0c8e08032d..872f2f0652 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -89,6 +89,12 @@ add_fingerprint_to_dir(const char *nickname, const char *fp, smartlist_t *list)
fingerprint = tor_strdup(fp);
tor_strstrip(fingerprint, " ");
+ if (!strcasecmp(nickname, UNNAMED_ROUTER_NICKNAME)) {
+ log_warn(LD_DIRSERV, "Tried to add a mapping for reserved nickname %s",
+ UNNAMED_ROUTER_NICKNAME);
+ return 0;
+ }
+
if (nickname[0] != '!') {
for (i = 0; i < smartlist_len(list); ++i) {
ent = smartlist_get(list, i);
@@ -317,7 +323,10 @@ dirserv_get_status_impl(const char *fp, const char *nickname,
if (0==strcasecmp(nn_ent->fingerprint, fp)) {
if (should_log)
log_debug(LD_DIRSERV,"Good fingerprint for '%s'",nickname);
- return FP_NAMED; /* Right fingerprint. */
+ if (!strcasecmp(nickname, UNNAMED_ROUTER_NICKNAME))
+ return FP_VALID;
+ else
+ return FP_NAMED; /* Right fingerprint. */
} else {
if (should_log) {
char *esc_contact = esc_for_log(contact);
@@ -1448,6 +1457,9 @@ generate_v2_networkstatus(void)
char identity64[BASE64_DIGEST_LEN+1];
char digest64[BASE64_DIGEST_LEN+1];
+ if (!strcasecmp(ri->nickname, UNNAMED_ROUTER_NICKNAME))
+ f_named = 0;
+
format_iso_time(published, ri->cache_info.published_on);
digest_to_base64(identity64, ri->cache_info.identity_digest);
diff --git a/src/or/or.h b/src/or/or.h
index cba4db60dd..fbb9bcb98e 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2112,6 +2112,8 @@ char *directory_dump_request_log(void);
/********************************* dirserv.c ***************************/
+#define UNNAMED_ROUTER_NICKNAME "Unnamed"
+
int connection_dirserv_flushed_some(dir_connection_t *conn);
int dirserv_add_own_fingerprint(const char *nickname, crypto_pk_env_t *pk);
int dirserv_load_fingerprint_file(void);
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 031a08fef6..1f932469f1 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -1047,6 +1047,8 @@ router_get_by_nickname(const char *nickname, int warn_if_unnamed)
return NULL;
if (nickname[0] == '$')
return router_get_by_hexdigest(nickname);
+ if (!strcasecmp(nickname, UNNAMED_ROUTER_NICKNAME))
+ return NULL;
if (server_mode(get_options()) &&
!strcasecmp(nickname, get_options()->Nickname))
return router_get_my_routerinfo();
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index 2f214a1ef4..b73697ab40 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -1064,6 +1064,9 @@ routerstatus_parse_entry_from_string(const char **s, smartlist_t *tokens)
}
}
+ if (!strcasecmp(rs->nickname, UNNAMED_ROUTER_NICKNAME))
+ rs->is_named = 0;
+
goto done;
err:
if (rs)