]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Windows port: Add support for the Windows machine DNS domain, and also automatically...
authorGuido Serassio <serassio@squid-cache.org>
Thu, 1 May 2008 17:12:56 +0000 (19:12 +0200)
committerGuido Serassio <serassio@squid-cache.org>
Thu, 1 May 2008 17:12:56 +0000 (19:12 +0200)
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.

src/dns_internal.cc [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index ae2c50a..7d33916
@@ -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);