Dominick Meglio host file path discovery patch for windows
authorDaniel Stenberg <daniel@haxx.se>
Sun, 26 Sep 2004 18:20:58 +0000 (18:20 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Sun, 26 Sep 2004 18:20:58 +0000 (18:20 +0000)
ares/CHANGES
ares/ares_gethostbyaddr.c
ares/ares_gethostbyname.c
ares/ares_private.h

index 869ad02ffb3fb6c06b7864c2889007fb233a4f69..0c3d6a3d5532451ad0f7913d52ec801f5ec87921 100644 (file)
@@ -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.
index f44b3fb38ec01f6510d230550e8ef582a1e65dde..978beba4763d40b8af1cce874b60102dd336bd2e 100644 (file)
@@ -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);
index b39d53be66a83e00d0a8ca359bc4bfe2d444a3d5..decac5583f498886e12e04cc0f2338117ef2d6a0 100644 (file)
@@ -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);
index 0b16dc0df7d8df6836f9128b27e5e7a5a73e2122..06f8768360736bc340ee210877f486c7fb1aa4d9 100644 (file)
@@ -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)