summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2004-09-26 18:20:58 +0000
committerDaniel Stenberg <daniel@haxx.se>2004-09-26 18:20:58 +0000
commit2bf866b0ce6084e28af061d68bbc351b3be55e84 (patch)
tree7e8ac4d57a5c5e6ad224ad2e764945a3bd5320b6
parentdb2efff373dcffabfd1f94eb689127aee8a733f5 (diff)
downloadc-ares-2bf866b0ce6084e28af061d68bbc351b3be55e84.tar.gz
c-ares-2bf866b0ce6084e28af061d68bbc351b3be55e84.tar.bz2
c-ares-2bf866b0ce6084e28af061d68bbc351b3be55e84.zip
Dominick Meglio host file path discovery patch for windows
-rw-r--r--CHANGES14
-rw-r--r--ares_gethostbyaddr.c21
-rw-r--r--ares_gethostbyname.c22
-rw-r--r--ares_private.h4
4 files changed, 48 insertions, 13 deletions
diff --git a/CHANGES b/CHANGES
index 869ad02..0c3d6a3 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,19 @@
Changelog for the c-ares project
+* September 26
+
+- Dominick Meglio patched: C-ares on Windows assumed that the HOSTS file is
+ located in a static location. It assumed
+ C:\Windows\System32\Drivers\Etc. This is a poor assumption to make. In fact,
+ the location of the HOSTS file can be changed via a registry setting.
+
+ There is a key called DatabasePath which specifies the path to the HOSTS
+ file:
+ http://www.microsoft.com/technet/itsolutions/network/deploy/depovg/tcpip2k.mspx
+
+ The patch will make c-ares correctly consult the registry for the location
+ of this file.
+
* August 29
- Gisle Vanem fixed the MSVC build files.
diff --git a/ares_gethostbyaddr.c b/ares_gethostbyaddr.c
index f44b3fb..978beba 100644
--- a/ares_gethostbyaddr.c
+++ b/ares_gethostbyaddr.c
@@ -150,12 +150,23 @@ static int file_lookup(struct in_addr *addr, struct hostent **host)
char PATH_HOSTS[MAX_PATH];
if (IsNT) {
- GetSystemDirectory(PATH_HOSTS, MAX_PATH);
- strcat(PATH_HOSTS, PATH_HOSTS_NT);
- } else {
+ char tmp[MAX_PATH];
+ HKEY hkeyHosts;
+
+ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ, &hkeyHosts)
+ == ERROR_SUCCESS)
+ {
+ DWORD dwLength = MAX_PATH;
+ RegQueryValueEx(hkeyHosts, DATABASEPATH, NULL, NULL, tmp,
+ &dwLength);
+ ExpandEnvironmentStrings(tmp, PATH_HOSTS, MAX_PATH);
+ RegCloseKey(hkeyHosts);
+ }
+ }
+ else
GetWindowsDirectory(PATH_HOSTS, MAX_PATH);
- strcat(PATH_HOSTS, PATH_HOSTS_9X);
- }
+
+ strcat(PATH_HOSTS, WIN_PATH_HOSTS);
#elif defined(WATT32)
extern const char *_w32_GetHostsFile (void);
diff --git a/ares_gethostbyname.c b/ares_gethostbyname.c
index b39d53b..decac55 100644
--- a/ares_gethostbyname.c
+++ b/ares_gethostbyname.c
@@ -220,15 +220,25 @@ static int file_lookup(const char *name, struct hostent **host)
int status;
#ifdef WIN32
-
char PATH_HOSTS[MAX_PATH];
if (IsNT) {
- GetSystemDirectory(PATH_HOSTS, MAX_PATH);
- strcat(PATH_HOSTS, PATH_HOSTS_NT);
- } else {
+ char tmp[MAX_PATH];
+ HKEY hkeyHosts;
+
+ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ, &hkeyHosts)
+ == ERROR_SUCCESS)
+ {
+ DWORD dwLength = MAX_PATH;
+ RegQueryValueEx(hkeyHosts, DATABASEPATH, NULL, NULL, tmp,
+ &dwLength);
+ ExpandEnvironmentStrings(tmp, PATH_HOSTS, MAX_PATH);
+ RegCloseKey(hkeyHosts);
+ }
+ }
+ else
GetWindowsDirectory(PATH_HOSTS, MAX_PATH);
- strcat(PATH_HOSTS, PATH_HOSTS_9X);
- }
+
+ strcat(PATH_HOSTS, WIN_PATH_HOSTS);
#elif defined(WATT32)
extern const char *_w32_GetHostsFile (void);
diff --git a/ares_private.h b/ares_private.h
index 0b16dc0..06f8768 100644
--- a/ares_private.h
+++ b/ares_private.h
@@ -46,8 +46,8 @@
#define WIN_NS_NT_KEY "System\\CurrentControlSet\\Services\\Tcpip\\Parameters"
#define NAMESERVER "NameServer"
#define DHCPNAMESERVER "DhcpNameServer"
-#define PATH_HOSTS_NT "\\drivers\\etc\\hosts"
-#define PATH_HOSTS_9X "\\hosts"
+#define DATABASEPATH "DatabasePath"
+#define WIN_PATH_HOSTS "\\hosts"
#elif defined(WATT32)