mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 23:21:38 +01:00
Fallback to local DNS when no other nameservers are known
This commit is contained in:
parent
275e831cea
commit
91fa12aedc
1 changed files with 38 additions and 17 deletions
|
@ -1388,16 +1388,23 @@ configure_nameservers(int force)
|
||||||
evdns_set_log_fn(evdns_log_cb);
|
evdns_set_log_fn(evdns_log_cb);
|
||||||
if (conf_fname) {
|
if (conf_fname) {
|
||||||
log_debug(LD_FS, "stat()ing %s", conf_fname);
|
log_debug(LD_FS, "stat()ing %s", conf_fname);
|
||||||
if (stat(sandbox_intern_string(conf_fname), &st)) {
|
int missing_resolv_conf = 0;
|
||||||
|
int stat_res = stat(sandbox_intern_string(conf_fname), &st);
|
||||||
|
|
||||||
|
if (stat_res) {
|
||||||
log_warn(LD_EXIT, "Unable to stat resolver configuration in '%s': %s",
|
log_warn(LD_EXIT, "Unable to stat resolver configuration in '%s': %s",
|
||||||
conf_fname, strerror(errno));
|
conf_fname, strerror(errno));
|
||||||
goto err;
|
missing_resolv_conf = 1;
|
||||||
}
|
} else if (!force && resolv_conf_fname &&
|
||||||
if (!force && resolv_conf_fname && !strcmp(conf_fname,resolv_conf_fname)
|
!strcmp(conf_fname,resolv_conf_fname)
|
||||||
&& st.st_mtime == resolv_conf_mtime) {
|
&& st.st_mtime == resolv_conf_mtime) {
|
||||||
log_info(LD_EXIT, "No change to '%s'", conf_fname);
|
log_info(LD_EXIT, "No change to '%s'", conf_fname);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stat_res == 0 && st.st_size == 0)
|
||||||
|
missing_resolv_conf = 1;
|
||||||
|
|
||||||
if (nameservers_configured) {
|
if (nameservers_configured) {
|
||||||
evdns_base_search_clear(the_evdns_base);
|
evdns_base_search_clear(the_evdns_base);
|
||||||
evdns_base_clear_nameservers_and_suspend(the_evdns_base);
|
evdns_base_clear_nameservers_and_suspend(the_evdns_base);
|
||||||
|
@ -1410,20 +1417,34 @@ configure_nameservers(int force)
|
||||||
sandbox_intern_string("/etc/hosts"));
|
sandbox_intern_string("/etc/hosts"));
|
||||||
}
|
}
|
||||||
#endif /* defined(DNS_OPTION_HOSTSFILE) && defined(USE_LIBSECCOMP) */
|
#endif /* defined(DNS_OPTION_HOSTSFILE) && defined(USE_LIBSECCOMP) */
|
||||||
|
|
||||||
|
if (!missing_resolv_conf) {
|
||||||
log_info(LD_EXIT, "Parsing resolver configuration in '%s'", conf_fname);
|
log_info(LD_EXIT, "Parsing resolver configuration in '%s'", conf_fname);
|
||||||
if ((r = evdns_base_resolv_conf_parse(the_evdns_base, flags,
|
if ((r = evdns_base_resolv_conf_parse(the_evdns_base, flags,
|
||||||
sandbox_intern_string(conf_fname)))) {
|
sandbox_intern_string(conf_fname)))) {
|
||||||
log_warn(LD_EXIT, "Unable to parse '%s', or no nameservers in '%s' (%d)",
|
log_warn(LD_EXIT, "Unable to parse '%s', or no nameservers "
|
||||||
conf_fname, conf_fname, r);
|
"in '%s' (%d)", conf_fname, conf_fname, r);
|
||||||
goto err;
|
|
||||||
|
if (r != 6) // "r = 6" means "no DNS servers were in resolv.conf" -
|
||||||
|
goto err; // in which case we expect libevent to add 127.0.0.1 as
|
||||||
|
// fallback.
|
||||||
}
|
}
|
||||||
if (evdns_base_count_nameservers(the_evdns_base) == 0) {
|
if (evdns_base_count_nameservers(the_evdns_base) == 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'.",
|
||||||
goto err;
|
conf_fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
tor_free(resolv_conf_fname);
|
tor_free(resolv_conf_fname);
|
||||||
resolv_conf_fname = tor_strdup(conf_fname);
|
resolv_conf_fname = tor_strdup(conf_fname);
|
||||||
resolv_conf_mtime = st.st_mtime;
|
resolv_conf_mtime = st.st_mtime;
|
||||||
|
} else {
|
||||||
|
log_warn(LD_EXIT, "Could not read your DNS config from '%s' - "
|
||||||
|
"please investigate your DNS configuration. "
|
||||||
|
"This is possibly a problem. Meanwhile, falling"
|
||||||
|
" back to local DNS at 127.0.0.1.", conf_fname);
|
||||||
|
evdns_base_nameserver_ip_add(the_evdns_base, "127.0.0.1");
|
||||||
|
}
|
||||||
|
|
||||||
if (nameservers_configured)
|
if (nameservers_configured)
|
||||||
evdns_base_resume(the_evdns_base);
|
evdns_base_resume(the_evdns_base);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue