From 8a2e5dcbe47996628477d4ddfa040e017c4de156 Mon Sep 17 00:00:00 2001 From: peavey Date: Sat, 17 Oct 2009 20:48:20 +0000 Subject: Fix up finding dns server to use for windows to match latest configreader changes. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11892 e03df62e-2008-0410-955e-edbf42e46eb7 --- win/inspircd_win32wrapper.cpp | 47 ++++++++++++++++++++++++++----------------- win/inspircd_win32wrapper.h | 2 +- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/win/inspircd_win32wrapper.cpp b/win/inspircd_win32wrapper.cpp index 1309e6064..3cc4f240e 100644 --- a/win/inspircd_win32wrapper.cpp +++ b/win/inspircd_win32wrapper.cpp @@ -354,7 +354,7 @@ bool GetInterface(HKEY regkey, const char *key, char* &output) std::string FindNameServerWin() { - std::string returnval = "127.0.0.1"; + std::string returnval; HKEY top, key; char* dns = NULL; @@ -517,27 +517,36 @@ void WindowsForkKillOwner() CloseHandle(hProcess); } -bool ValidateDnsServer(ServerConfig* conf, const char* tag, const char* value, ValueItem &data) +void FindDNS(std::string& server) { - if (!*(data.GetString())) + if (!server.empty()) + return; + + ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: not defined, attempting to find working server in the registry..."); + std::string nameserver = FindNameServerWin(); + + /* If empty use default to 127.0.0.1 */ + if (nameserver.empty()) { - std::string nameserver; - ServerInstance->Logs->Log("win32",DEFAULT,"WARNING: not defined, attempting to find working server in the registry..."); - nameserver = FindNameServerWin(); - /* Windows stacks multiple nameservers in one registry key, seperated by commas. - * Spotted by Cataclysm. - */ - if (nameserver.find(',') != std::string::npos) - nameserver = nameserver.substr(0, nameserver.find(',')); - /* Just to be FUCKING AKWARD, windows fister... err i mean vista... - * seperates the nameservers with spaces instead. - */ - if (nameserver.find(' ') != std::string::npos) - nameserver = nameserver.substr(0, nameserver.find(' ')); - data.Set(nameserver.c_str()); - ServerInstance->Logs->Log("win32",DEFAULT," set to '%s' as first active resolver in registry.", nameserver.c_str()); + ServerInstance->Logs->Log("CONFIG",DEFAULT,"/etc/resolv.conf contains no viable nameserver entries! Defaulting to nameserver '127.0.0.1'!"); + server = "127.0.0.1"; + return; } - return true; + + /* Windows stacks multiple nameservers in one registry key, seperated by commas. + * Spotted by Cataclysm. + */ + if (nameserver.find(',') != std::string::npos) + nameserver = nameserver.substr(0, nameserver.find(',')); + + /* Just to be FUCKING AKWARD, windows fister... err i mean vista... + * seperates the nameservers with spaces instead. + */ + if (nameserver.find(' ') != std::string::npos) + nameserver = nameserver.substr(0, nameserver.find(' ')); + + server = nameserver; + ServerInstance->Logs->Log("CONFIG",DEFAULT," set to '%s' as first active resolver in registry.", nameserver.c_str()); } int gettimeofday(struct timeval * tv, void * tz) diff --git a/win/inspircd_win32wrapper.h b/win/inspircd_win32wrapper.h index 740436d93..4397d2ad3 100644 --- a/win/inspircd_win32wrapper.h +++ b/win/inspircd_win32wrapper.h @@ -240,7 +240,7 @@ CoreExport void WindowsForkKillOwner(); CoreExport void ChangeWindowsSpecificPointers(); -CoreExport bool ValidateWindowsDnsServer(ServerConfig* conf, const char* tag, const char* value, ValueItem &data); +CoreExport void FindDNS(std::string& server); CoreExport bool initwmi(); CoreExport void donewmi(); -- cgit v1.2.3