From 262e2b2ca6ce3f29251bd34c8e1edf0a422e7aab Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Tue, 19 Sep 2006 12:45:18 +0000 Subject: [PATCH] - Windows 2003: Fixed UnrealIRCd unable to boot if no DNS server is configured, we now fallback to set::dns::nameserver in such a case. Thanks to Romeo (reporter, #0002802) and Bock for tracing this down. --- Changes | 3 +++ include/h.h | 2 ++ src/res.c | 41 ++++++++++++++++++++++++++++++++--------- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/Changes b/Changes index 2fc8bdfc7..a95b045a4 100644 --- a/Changes +++ b/Changes @@ -1307,3 +1307,6 @@ - The "looking up your hostname" message was always sent, regardless of show-connect-info. - Kick non-SSL users when the channel turns out to be +z during netmerge, reported by Ron2K (#0002942). +- Windows 2003: Fixed UnrealIRCd unable to boot if no DNS server is configured, we now + fallback to set::dns::nameserver in such a case. Thanks to Romeo (reporter, #0002802) + and Bock for tracing this down. diff --git a/include/h.h b/include/h.h index dd2d3c73e..0942c84d1 100644 --- a/include/h.h +++ b/include/h.h @@ -112,6 +112,8 @@ extern void module_loadall(int module_load); extern long set_usermode(char *umode); extern char *get_modestr(long umodes); extern void config_error(char *format, ...) __attribute__((format(printf,1,2))); +extern void config_warn(char *format, ...) __attribute__((format(printf,1,2))); + extern MODVAR int config_verbose; extern void config_progress(char *format, ...) __attribute__((format(printf,1,2))); extern void ipport_seperate(char *string, char **ip, char **port); diff --git a/src/res.c b/src/res.c index 191e874bd..a9ef3e5c7 100644 --- a/src/res.c +++ b/src/res.c @@ -42,6 +42,7 @@ #ifdef _WIN32 #include #endif +#include "inet.h" #include #include "h.h" @@ -79,6 +80,7 @@ void init_resolver(int firsttime) { struct ares_options options; int n; +int optmask; if (requests) abort(); /* should never happen */ @@ -89,23 +91,44 @@ int n; memset(&dnsstats, 0, sizeof(dnsstats)); } + memset(&options, 0, sizeof(options)); options.timeout = 3; options.tries = 2; options.flags = ARES_FLAG_NOALIASES|ARES_FLAG_IGNTC; -#ifdef _WIN32 - /* for windows, keep using the hosts file for now, until I'm sure it's safe to disable */ - n = ares_init_options(&resolver_channel, &options, ARES_OPT_TIMEOUT|ARES_OPT_TRIES|ARES_OPT_FLAGS); -#else - options.lookups = "b"; /* no hosts file shit plz */ - n = ares_init_options(&resolver_channel, &options, ARES_OPT_TIMEOUT|ARES_OPT_TRIES|ARES_OPT_FLAGS|ARES_OPT_LOOKUPS); + optmask = ARES_OPT_TIMEOUT|ARES_OPT_TRIES|ARES_OPT_FLAGS; +#ifndef _WIN32 + /* on *NIX don't use the hosts file, since it causes countless useless reads. + * on Windows we use it for now, this could be changed in the future. + */ + options.lookups = "b"; + optmask |= ARES_OPT_LOOKUPS; #endif + n = ares_init_options(&resolver_channel, &options, optmask); if (n != ARES_SUCCESS) { - config_error("resolver: ares_init_options() failed with error code %d [%s]", n, ares_strerror(n)); + /* Try again with set::dns::nameserver block */ + optmask |= ARES_OPT_SERVERS; + options.servers = MyMallocEx(sizeof(struct in_addr)); + options.servers[0].s_addr = inet_addr(NAME_SERVER); + options.nservers = 1; + n = ares_init_options(&resolver_channel, &options, optmask); + if (n != ARES_SUCCESS) + { + /* FATAL */ + config_error("resolver: ares_init_options() failed with error code %d [%s]", n, ares_strerror(n)); #ifdef _WIN32 - win_error(); + win_error(); #endif - exit(-7); + exit(-7); + } + ircd_log(LOG_ERROR, "[warning] Unable to get DNS server from %s. Using the one from set::dns::nameserver (%s) instead", +#ifdef _WIN32 + "registry", +#else + "resolv.conf", +#endif + NAME_SERVER); + MyFree(options.servers); } }