소스 검색

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

Nick Mathewson 19 년 전
부모
커밋
baadf35c63
5개의 변경된 파일13개의 추가작업 그리고 4개의 파일을 삭제
  1. 4 0
      ChangeLog
  2. 1 1
      doc/TODO
  3. 4 1
      src/or/dns.c
  4. 3 2
      src/or/eventdns.c
  5. 1 0
      src/or/eventdns.h

+ 4 - 0
ChangeLog

@@ -67,6 +67,10 @@ Changes in version 0.1.2.5-xxxx - 200?-??-??
     - Remove an artificial (but quite high) restriction on expected
     - Remove an artificial (but quite high) restriction on expected
       bandwidth, so that accounting won't break once we all have gigabit
       bandwidth, so that accounting won't break once we all have gigabit
       connections to our homes.
       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:
   o Controller features:
     - Have GETINFO dir/status/* work on hosts with DirPort disabled.
     - Have GETINFO dir/status/* work on hosts with DirPort disabled.

+ 1 - 1
doc/TODO

@@ -104,7 +104,7 @@ d   - Be a DNS proxy.
       o add a config option to turn it off.
       o add a config option to turn it off.
     - Bug 364: notice when all the DNS requests we get back (including a few
     - Bug 364: notice when all the DNS requests we get back (including a few
       well-known sites) are all going to the same place.
       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.
       server; don't fall back to 127.0.0.1.
 ?   - maybe re-check dns when we change IP addresses, rather than
 ?   - maybe re-check dns when we change IP addresses, rather than
       every 12 hours?
       every 12 hours?

+ 4 - 1
src/or/dns.c

@@ -1465,8 +1465,11 @@ configure_nameservers(int force)
       evdns_clear_nameservers_and_suspend();
       evdns_clear_nameservers_and_suspend();
     }
     }
     log_info(LD_EXIT, "Parsing resolver configuration in '%s'", conf_fname);
     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;
       return -1;
+    }
     if (evdns_count_nameservers() == 0) {
     if (evdns_count_nameservers() == 0) {
       log_warn(LD_EXIT, "Unable to find any nameservers in '%s'.", conf_fname);
       log_warn(LD_EXIT, "Unable to find any nameservers in '%s'.", conf_fname);
       return -1;
       return -1;

+ 3 - 2
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);
 	char *const first_token = strtok_r(start, delims, &strtok_state);
 	if (!first_token) return;
 	if (!first_token) return;
 
 
-	if (!strcmp(first_token, "nameserver")) {
+	if (!strcmp(first_token, "nameserver") && (flags & DNS_OPTION_NAMESERVERS)) {
 		const char *const nameserver = NEXT_TOKEN;
 		const char *const nameserver = NEXT_TOKEN;
 		struct in_addr ina;
 		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 (fstat(fd, &st)) { err = 2; goto out1; }
 	if (!st.st_size) {
 	if (!st.st_size) {
 		evdns_resolv_set_defaults(flags);
 		evdns_resolv_set_defaults(flags);
-		err = 0;
+		err = (flags & DNS_OPTION_NAMESERVERS) ? 6 : 0;
 		goto out1;
 		goto out1;
 	}
 	}
 	if (st.st_size > 65535) { err = 3; goto out1; }	 // no resolv.conf should be any bigger
 	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)) {
 	if (!server_head && (flags & DNS_OPTION_NAMESERVERS)) {
 		// no nameservers were configured.
 		// no nameservers were configured.
 		evdns_nameserver_ip_add("127.0.0.1");
 		evdns_nameserver_ip_add("127.0.0.1");
+        err = 6;
 	}
 	}
 	if (flags & DNS_OPTION_SEARCH && (!global_search_state || global_search_state->num_domains == 0)) {
 	if (flags & DNS_OPTION_SEARCH && (!global_search_state || global_search_state->num_domains == 0)) {
 		search_set_from_hostname();
 		search_set_from_hostname();

+ 1 - 0
src/or/eventdns.h

@@ -187,6 +187,7 @@
  *	  3 file too large
  *	  3 file too large
  *	  4 out of memory
  *	  4 out of memory
  *	  5 short read from file
  *	  5 short read from file
+ *        6 no nameservers in file
  *
  *
  * Internals:
  * Internals:
  *
  *