Hi,

the reason is simple, it don't extract domains/search list anymore. Small patch using GetAdaptersAddresses&GetNetworkParams is attached, but it dosn't contain code reading lists from Windows registry, but only comments where and when to do that.


--
Yours sincerely, Eugeny.
GM of Enterprise Solutions Department
Doctor Web, Ltd.
http://www.drweb.com, +79119997425
--- ares_init.c.orig	2016-09-27 11:33:06.000000000 +0300
+++ ares_init.c	2017-01-13 17:37:17.234366674 +0300
@@ -536,16 +536,20 @@
 
 static int init_by_environment(ares_channel channel)
 {
-  const char *localdomain, *res_options;
+  const char *res_options;
   int status;
 
-  localdomain = getenv("LOCALDOMAIN");
-  if (localdomain && channel->ndomains == -1)
+  if (channel->ndomains == -1)
+    {
+      const char *localdomain = getenv("LOCALDOMAIN");
+      
+      if (localdomain)
     {
       status = set_search(channel, localdomain);
       if (status != ARES_SUCCESS)
         return status;
     }
+    }
 
   res_options = getenv("RES_OPTIONS");
   if (res_options)
@@ -767,6 +771,15 @@
   if (gotString)
     goto done;
 
+  /*
+   * !!!tbd:
+   * HKLM\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Domain and
+   * HKLM\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\SearchList
+   * need to be read. Also, we need to read
+   * HKLM\SOFTWARE\Policies\Microsoft\Windows NT\DNSClient\SearchList 
+   * registry value too if we dont get it before.
+   */
+
   /* Try adapter specific parameters */
   res = RegOpenKeyEx(hKey_Tcpip_Parameters, "Interfaces", 0,
                      KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS,
@@ -785,6 +798,8 @@
   /* Adapter specific DNS DHCP-configured parameters */
   gotString = get_enum_REG_SZ(hKey_Interfaces, DHCPNAMESERVER, outptr);
 
+  /* !!!tbd: 'Domain' value wants to be read */
+
 done:
   if (hKey_Interfaces)
     RegCloseKey(hKey_Interfaces);
@@ -856,6 +871,37 @@
 }
 
 /*
+ * add_Windows_domain()
+ *
+ * add domain into domains array if it wasn't added yet.
+ */
+static void add_Windows_domain(char *name, int *ndomains, char ***domains)
+{
+  int pos, old_ndomains = *ndomains;
+  char **new_domains, **old_domains = *domains;
+
+  /* do not add duplicates */
+  
+  if( old_domains )
+    for (pos = 0; pos < old_ndomains; ++pos)
+      if ( !strcmp(old_domains[pos], name) )
+        return;
+
+  pos = old_ndomains==-1 ? 0 : old_ndomains;
+  new_domains = ares_realloc(old_domains, sizeof(char**)*(1 + pos));
+
+  if (new_domains)
+    {
+      new_domains[pos] = ares_strdup(name);
+
+      if(new_domains[pos])
+        *ndomains = pos + 1;
+      
+      *domains = new_domains;
+    }
+}
+
+/*
  * get_DNS_NetworkParams()
  *
  * Locates DNS info using GetNetworkParams() function from the Internet
@@ -871,7 +917,7 @@
  *
  * Note: Ancient PSDK required in order to build a W98 target.
  */
-static int get_DNS_NetworkParams(char **outptr)
+static int get_DNS_NetworkParams(char **outptr, int *ndomains, char ***domains)
 {
   FIXED_INFO       *fi, *newfi;
   struct ares_addr namesrvr;
@@ -903,6 +949,9 @@
   if (res != ERROR_SUCCESS)
     goto done;
 
+  if (fi->DomainName[0])
+    add_Windows_domain(fi->DomainName, ndomains, domains);
+
   for (ipAddr = &fi->DnsServerList; ipAddr; ipAddr = ipAddr->Next)
   {
     txtaddr = &ipAddr->IpAddress.String[0];
@@ -955,7 +1004,7 @@
  */
 #define IPAA_INITIAL_BUF_SZ 15 * 1024
 #define IPAA_MAX_TRIES 3
-static int get_DNS_AdaptersAddresses(char **outptr)
+static int get_DNS_AdaptersAddresses(char **outptr, int *ndomains, char ***domains)
 {
   IP_ADAPTER_DNS_SERVER_ADDRESS *ipaDNSAddr;
   IP_ADAPTER_ADDRESSES *ipaa, *newipaa, *ipaaEntry;
@@ -1012,6 +1061,26 @@
     if(ipaaEntry->OperStatus != IfOperStatusUp)
         continue;
 
+    if (ipaaEntry->DnsSuffix && ipaaEntry->DnsSuffix[0]) {
+      char *name;
+      int   namelen = WideCharToMultiByte(CP_UTF8, 0, ipaaEntry->DnsSuffix, -1, NULL, 0, NULL, NULL);
+
+      if (namelen)
+        {
+          name = ares_malloc( namelen + 1 );
+          
+          if (name)
+            {
+              namelen = WideCharToMultiByte(CP_UTF8, 0, ipaaEntry->DnsSuffix, -1, name, namelen, NULL, NULL);
+              
+              if (namelen)
+                  add_Windows_domain(name, ndomains, domains);
+              
+              ares_free(name);
+            }
+        }
+    }
+    
     for (ipaDNSAddr = ipaaEntry->FirstDnsServerAddress;
          ipaDNSAddr;
          ipaDNSAddr = ipaDNSAddr->Next)
@@ -1070,7 +1139,7 @@
  *
  * Implementation supports Windows 95 and newer.
  */
-static int get_DNS_Windows(char **outptr)
+static int get_DNS_Windows(char **outptr, int *ndomains, char ***domains)
 {
   /*
      Use GetNetworkParams First in case of
@@ -1079,11 +1148,11 @@
      That will slowing DNS lookup.
   */
   /* Try using IP helper API GetNetworkParams() */
-  if (get_DNS_NetworkParams(outptr))
+  if (get_DNS_NetworkParams(outptr, ndomains, domains))
     return 1;
 
   /* Try using IP helper API GetAdaptersAddresses() */
-  if (get_DNS_AdaptersAddresses(outptr))
+  if (get_DNS_AdaptersAddresses(outptr, ndomains, domains))
     return 1;
 
   /* Fall-back to registry information */
@@ -1102,14 +1171,36 @@
   struct apattern *sortlist = NULL;
 
 #ifdef WIN32
+  int ndomains = -1;
+  char **domains = NULL;
 
-  if (channel->nservers > -1)  /* don't override ARES_OPT_SERVER */
+  if (channel->nservers != -1 && channel->ndomains != -1) /* everything is set already */
      return ARES_SUCCESS;
 
-  if (get_DNS_Windows(&line))
+  if (get_DNS_Windows(&line, &ndomains, &domains))
   {
+    if (channel->nservers == -1 ) /* don't override ARES_OPT_SERVER */
     status = config_nameserver(&servers, &nservers, line);
+    
     ares_free(line);
+
+    if (ndomains != -1) /* get_DNS_Windows() got something */
+      {
+        if (channel->ndomains != -1) /* don't override ARES_OPT_DOMAINS */
+          {
+            int pos;
+            
+            for( pos = 0; pos < ndomains; ++pos )
+              ares_free( domains[pos] );
+            
+            ares_free( domains );
+          }
+        else
+          {
+            channel->ndomains = ndomains;
+            channel->domains = domains;
+          }
+      }
   }
 
   if (status == ARES_SUCCESS)

Reply via email to