From: Guido Serassio Date: Thu, 1 May 2008 17:12:56 +0000 (+0200) Subject: Windows port: Add support for the Windows machine DNS domain, and also automatically... X-Git-Tag: SQUID_3_1_0_1~49^2~263 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a16cb11f3ce7900a89dbdc085cad2a8481c5800b;p=thirdparty%2Fsquid.git Windows port: Add support for the Windows machine DNS domain, and also automatically derived default domain This patch adds the capacity to get the machine DNS domain from the registry, similar to search but only accepting a single domain. In addition it adds support for automatically deriving the domain from the fully qualified hostname. Also fixed some memory leaks during the DNS configuration parse in the registry. --- diff --git a/src/dns_internal.cc b/src/dns_internal.cc old mode 100644 new mode 100755 index ae2c50af09..7d339162d7 --- a/src/dns_internal.cc +++ b/src/dns_internal.cc @@ -372,7 +372,7 @@ idnsParseResolvConf(void) static void idnsParseWIN32SearchList(const char * Separator) { - BYTE *t; + char *t; char *token; HKEY hndKey; @@ -382,36 +382,52 @@ idnsParseWIN32SearchList(const char * Separator) DWORD Type = 0; DWORD Size = 0; LONG Result; + Result = + RegQueryValueEx(hndKey, "Domain", NULL, &Type, NULL, + &Size); + + if (Result == ERROR_SUCCESS && Size) { + t = (char *) xmalloc(Size); + RegQueryValueEx(hndKey, "Domain", NULL, &Type, (LPBYTE) t, + &Size); + debugs(78, 1, "Adding domain " << token << " from Registry"); + idnsAddPathComponent(t); + xfree(t); + } Result = RegQueryValueEx(hndKey, "SearchList", NULL, &Type, NULL, &Size); if (Result == ERROR_SUCCESS && Size) { - t = (unsigned char *) xmalloc(Size); - RegQueryValueEx(hndKey, "SearchList", NULL, &Type, t, + t = (char *) xmalloc(Size); + RegQueryValueEx(hndKey, "SearchList", NULL, &Type, (LPBYTE) t, &Size); - token = strtok((char *) t, Separator); + token = strtok(t, Separator); while (token) { idnsAddPathComponent(token); debugs(78, 1, "Adding domain " << token << " from Registry"); token = strtok(NULL, Separator); } + xfree(t); } RegCloseKey(hndKey); } + if (npc == 0 && ((const char *) t = getMyHostname())) { + t = strchr(t, '.'); + if (t) + idnsAddPathComponent(t + 1); + } } static void idnsParseWIN32Registry(void) { - BYTE *t; + char *t; char *token; HKEY hndKey, hndKey2; - idnsFreeNameservers(); - switch (WIN32_OS_version) { case _WIN_OS_WINNT: @@ -428,31 +444,33 @@ idnsParseWIN32Registry(void) &Size); if (Result == ERROR_SUCCESS && Size) { - t = (unsigned char *) xmalloc(Size); + t = (char *) xmalloc(Size); RegQueryValueEx(hndKey, "DhcpNameServer", NULL, &Type, t, &Size); - token = strtok((char *) t, ", "); + token = strtok(t, ", "); while (token) { idnsAddNameserver(token); debugs(78, 1, "Adding DHCP nameserver " << token << " from Registry"); token = strtok(NULL, ","); } + xfree(t); } Result = RegQueryValueEx(hndKey, "NameServer", NULL, &Type, NULL, &Size); if (Result == ERROR_SUCCESS && Size) { - t = (unsigned char *) xmalloc(Size); + t = (char *) xmalloc(Size); RegQueryValueEx(hndKey, "NameServer", NULL, &Type, t, &Size); - token = strtok((char *) t, ", "); + token = strtok(t, ", "); while (token) { debugs(78, 1, "Adding nameserver " << token << " from Registry"); idnsAddNameserver(token); token = strtok(NULL, ", "); } + xfree(t); } RegCloseKey(hndKey); @@ -496,16 +514,17 @@ idnsParseWIN32Registry(void) &Type, NULL, &Size); if (Result == ERROR_SUCCESS && Size) { - t = (unsigned char *) xmalloc(Size); + t = (char *) xmalloc(Size); RegQueryValueEx(hndKey2, "DhcpNameServer", NULL, &Type, t, &Size); - token = strtok((char *) t, ", "); + token = strtok(t, ", "); while (token) { debugs(78, 1, "Adding DHCP nameserver " << token << " from Registry"); idnsAddNameserver(token); token = strtok(NULL, ", "); } + xfree(t); } Result = @@ -513,16 +532,17 @@ idnsParseWIN32Registry(void) NULL, &Size); if (Result == ERROR_SUCCESS && Size) { - t = (unsigned char *) xmalloc(Size); + t = (char *) xmalloc(Size); RegQueryValueEx(hndKey2, "NameServer", NULL, &Type, t, &Size); - token = strtok((char *) t, ", "); + token = strtok(t, ", "); while (token) { debugs(78, 1, "Adding nameserver " << token << " from Registry"); idnsAddNameserver(token); token = strtok(NULL, ", "); } + xfree(t); } RegCloseKey(hndKey2); @@ -554,15 +574,16 @@ idnsParseWIN32Registry(void) RegQueryValueEx(hndKey, "NameServer", NULL, &Type, NULL, &Size); if (Result == ERROR_SUCCESS && Size) { - t = (unsigned char *) xmalloc(Size); + t = (char *) xmalloc(Size); RegQueryValueEx(hndKey, "NameServer", NULL, &Type, t, &Size); - token = strtok((char *) t, ", "); + token = strtok(t, ", "); while (token) { debugs(78, 1, "Adding nameserver " << token << " from Registry"); idnsAddNameserver(token); token = strtok(NULL, ", "); } + xfree(t); } RegCloseKey(hndKey);