diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-07-13 18:23:40 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-07-13 18:23:40 +0000 |
commit | c2103eb63a15d2bb840e4ce7932ff12f21c95145 (patch) | |
tree | cc2ec74c32ea0957ac351cb0dea5ea3e774c412a /src/or/config.c | |
parent | e9365f9ed58c783efe93abe020fd6f53e0068a8b (diff) | |
download | tor-c2103eb63a15d2bb840e4ce7932ff12f21c95145.tar tor-c2103eb63a15d2bb840e4ce7932ff12f21c95145.tar.gz |
Finish most pre2 items: make running-routers list work right; rename secret key files; make even more lookup-by-nickname use lookup-by-id; default nicknames to hostname.
svn:r2043
Diffstat (limited to 'src/or/config.c')
-rw-r--r-- | src/or/config.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/src/or/config.c b/src/or/config.c index e9068bd2d..2941174a6 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -467,6 +467,40 @@ static int resolve_my_address(or_options_t *options) { return 0; } +static char *get_default_nickname(void) +{ + char localhostname[256]; + char *cp, *out, *outp; + + if(gethostname(localhostname,sizeof(localhostname)) < 0) { + log_fn(LOG_WARN,"Error obtaining local hostname"); + return NULL; + } + /* Put it in lowercase; stop at the first dot. */ + for(cp = localhostname; *cp; ++cp) { + if (*cp == '.') { + *cp = '\0'; + break; + } + *cp = tolower(*cp); + } + /* Strip invalid characters. */ + cp = localhostname; + out = outp = tor_malloc(strlen(localhostname)+1); + while (*cp) { + if (strchr(LEGAL_NICKNAME_CHARACTERS, *cp)) + *outp++ = *cp++; + else + cp++; + } + *outp = '\0'; + /* Enforce length. */ + if (strlen(out) > MAX_NICKNAME_LEN) + out[MAX_NICKNAME_LEN]='\0'; + + return out; +} + /** Release storage held by <b>options</b> */ static void free_options(or_options_t *options) { config_free_lines(options->LogOptions); @@ -633,8 +667,9 @@ int getconfig(int argc, char **argv, or_options_t *options) { if (options->ORPort) { if (options->Nickname == NULL) { - log_fn(LOG_WARN,"Nickname required if ORPort is set, but not found."); - result = -1; + if (!(options->Nickname = get_default_nickname())) + return -1; + log_fn(LOG_INFO, "Choosing default nickname %s", options->Nickname); } else { if (strspn(options->Nickname, LEGAL_NICKNAME_CHARACTERS) != strlen(options->Nickname)) { |