From baadf35c639022d81ae906e4c9b14f6c4583ae40 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 19 Dec 2006 19:49:03 +0000 Subject: [PATCH] r11646@Kushana: nickm | 2006-12-19 14:40:38 -0500 Resolve bug 363: do not fall back to 127.0.0.1 when no nameservers are configured. Instead, have the admin fix resolv.conf or configure a nameserver. svn:r9157 --- ChangeLog | 4 ++++ doc/TODO | 2 +- src/or/dns.c | 5 ++++- src/or/eventdns.c | 5 +++-- src/or/eventdns.h | 1 + 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9217f7aa4a..81f7b910bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -67,6 +67,10 @@ Changes in version 0.1.2.5-xxxx - 200?-??-?? - Remove an artificial (but quite high) restriction on expected bandwidth, so that accounting won't break once we all have gigabit connections to our homes. + - When running as a server, don't fall back to 127.0.0.1 when + no nameservers are configured in /etc/resolv.conf; instead, make + the user fix resolv.conf or specify nameservers explicitly. (Resolves + Bug 363.) o Controller features: - Have GETINFO dir/status/* work on hosts with DirPort disabled. diff --git a/doc/TODO b/doc/TODO index b02b396dcb..e476d615ca 100644 --- a/doc/TODO +++ b/doc/TODO @@ -104,7 +104,7 @@ d - Be a DNS proxy. o add a config option to turn it off. - Bug 364: notice when all the DNS requests we get back (including a few well-known sites) are all going to the same place. - - Bug 363: Warn and die if we can't find a nameserver and we're running a + o Bug 363: Warn and die if we can't find a nameserver and we're running a server; don't fall back to 127.0.0.1. ? - maybe re-check dns when we change IP addresses, rather than every 12 hours? diff --git a/src/or/dns.c b/src/or/dns.c index b0e87ac4ed..1369c7da1a 100644 --- a/src/or/dns.c +++ b/src/or/dns.c @@ -1465,8 +1465,11 @@ configure_nameservers(int force) evdns_clear_nameservers_and_suspend(); } log_info(LD_EXIT, "Parsing resolver configuration in '%s'", conf_fname); - if (evdns_resolv_conf_parse(DNS_OPTIONS_ALL, conf_fname)) + if (evdns_resolv_conf_parse(DNS_OPTIONS_ALL, conf_fname)) { + log_warn(LD_EXIT, "Unable to parse '%s', or no nameservers in '%s'", + conf_fname, conf_fname); return -1; + } if (evdns_count_nameservers() == 0) { log_warn(LD_EXIT, "Unable to find any nameservers in '%s'.", conf_fname); return -1; diff --git a/src/or/eventdns.c b/src/or/eventdns.c index 68a2f6c203..ebc110195d 100644 --- a/src/or/eventdns.c +++ b/src/or/eventdns.c @@ -2499,7 +2499,7 @@ resolv_conf_parse_line(char *const start, int flags) { char *const first_token = strtok_r(start, delims, &strtok_state); if (!first_token) return; - if (!strcmp(first_token, "nameserver")) { + if (!strcmp(first_token, "nameserver") && (flags & DNS_OPTION_NAMESERVERS)) { const char *const nameserver = NEXT_TOKEN; struct in_addr ina; @@ -2579,7 +2579,7 @@ evdns_resolv_conf_parse(int flags, const char *const filename) { if (fstat(fd, &st)) { err = 2; goto out1; } if (!st.st_size) { evdns_resolv_set_defaults(flags); - err = 0; + err = (flags & DNS_OPTION_NAMESERVERS) ? 6 : 0; goto out1; } if (st.st_size > 65535) { err = 3; goto out1; } // no resolv.conf should be any bigger @@ -2608,6 +2608,7 @@ evdns_resolv_conf_parse(int flags, const char *const filename) { if (!server_head && (flags & DNS_OPTION_NAMESERVERS)) { // no nameservers were configured. evdns_nameserver_ip_add("127.0.0.1"); + err = 6; } if (flags & DNS_OPTION_SEARCH && (!global_search_state || global_search_state->num_domains == 0)) { search_set_from_hostname(); diff --git a/src/or/eventdns.h b/src/or/eventdns.h index f49c82e045..f1c05d9f82 100644 --- a/src/or/eventdns.h +++ b/src/or/eventdns.h @@ -187,6 +187,7 @@ * 3 file too large * 4 out of memory * 5 short read from file + * 6 no nameservers in file * * Internals: *