diff options
author | Nick Mathewson <nickm@torproject.org> | 2006-09-29 04:51:28 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2006-09-29 04:51:28 +0000 |
commit | 8992bf6204b70436c2dc881ffa2d79db40384b38 (patch) | |
tree | 6739ca3668aef26968b872c15b70dee91b75330d /src/or/config.c | |
parent | 4feccecfe813313a8302a44ed560dd7b61c51c2a (diff) | |
download | tor-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/or/config.c')
-rw-r--r-- | src/or/config.c | 35 |
1 files changed, 24 insertions, 11 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)) { |