Commit 32a678ea authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

Dominick Meglio's fix for supporting multiple names in the Nameserver key

on Windows.
parent bd7ba3bd
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
* February 22, 2004
- Dominick Meglio made ares init support multiple name servers in the
  NameServer key on Windows.

* February 16, 2004
- Modified ares_private.h to include libcurl's memory debug header if
  CURLDEBUG is set. This makes all the ares-functions supervised properly by
+167 −116
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ static int init_by_defaults(ares_channel channel);
static int config_domain(ares_channel channel, char *str);
static int config_lookup(ares_channel channel, const char *str);
static int config_nameserver(struct server_state **servers, int *nservers,
			     const char *str);
			     char *str);
static int config_sortlist(struct apattern **sortlist, int *nsort,
			   const char *str);
static int set_search(ares_channel channel, const char *str);
@@ -265,10 +265,12 @@ static int get_res_interfaces_nt(HKEY hKey, char *subkey, char **obuf)
  int enum_size = 39;
  int idx = 0;
  HKEY hVal;
	while (RegEnumKeyEx(hKey, idx++, enumbuf, &enum_size, 0, NULL, NULL, NULL) != ERROR_NO_MORE_ITEMS)
  while (RegEnumKeyEx(hKey, idx++, enumbuf, &enum_size, 0,
                      NULL, NULL, NULL) != ERROR_NO_MORE_ITEMS)
  {
    enum_size = 39;
		if (RegOpenKeyEx(hKey, enumbuf, 0, KEY_QUERY_VALUE, &hVal) != ERROR_SUCCESS)
    if (RegOpenKeyEx(hKey, enumbuf, 0, KEY_QUERY_VALUE, &hVal) !=
        ERROR_SUCCESS)
      continue;
    if (!get_res_nt(hVal, subkey, obuf))
      RegCloseKey(hVal);
@@ -284,9 +286,8 @@ static int get_res_interfaces_nt(HKEY hKey, char *subkey, char **obuf)

static int init_by_resolv_conf(ares_channel channel)
{
  FILE *fp;
  char *line = NULL, *p;
  int linesize, status, nservers = 0, nsort = 0;
  char *line = NULL;
  int status, nservers = 0, nsort = 0;
  struct server_state *servers = NULL;
  struct apattern *sortlist = NULL;

@@ -315,8 +316,6 @@ DhcpNameServer
  DWORD data_type;
  DWORD bytes;
  DWORD result;
  DWORD index;
  char name[MAX_PATH];
  DWORD keysize = MAX_PATH;

  status = ARES_EFILE;
@@ -328,7 +327,8 @@ DhcpNameServer
          KEY_READ, &mykey
          ) == ERROR_SUCCESS)
    {
		RegOpenKeyEx(mykey, "Interfaces", 0, KEY_QUERY_VALUE|KEY_ENUMERATE_SUB_KEYS, &subkey);
      RegOpenKeyEx(mykey, "Interfaces", 0,
                   KEY_QUERY_VALUE|KEY_ENUMERATE_SUB_KEYS, &subkey);
      if (get_res_nt(mykey, NAMESERVER, &line))
      {
        status = config_nameserver(&servers, &nservers, line);
@@ -353,7 +353,9 @@ DhcpNameServer
      RegCloseKey(subkey);
      RegCloseKey(mykey);
    }
  } else {
  }
  else
  {
    if (RegOpenKeyEx(
          HKEY_LOCAL_MACHINE, WIN_NS_9X, 0,
          KEY_READ, &mykey
@@ -366,12 +368,13 @@ DhcpNameServer
            ) == ERROR_SUCCESS ||
          result == ERROR_MORE_DATA)
      {
            if (bytes) {
        if (bytes)
        {
          line = (char *)malloc(bytes+1);
                if (RegQueryValueEx(
                    mykey, NAMESERVER, NULL, &data_type,
                    (unsigned char *)line, &bytes
                    ) == ERROR_SUCCESS) {
          if (RegQueryValueEx(mykey, NAMESERVER, NULL, &data_type,
                              (unsigned char *)line, &bytes) ==
              ERROR_SUCCESS)
          {
            status = config_nameserver(&servers, &nservers, line);
          }
          free(line);
@@ -381,7 +384,8 @@ DhcpNameServer
    RegCloseKey(mykey);
  }
  
  if (status != ARES_EFILE) {
  if (status != ARES_EFILE)
  {
    /*
      if (!channel->lookups) {
      status = config_lookup(channel, "file bind");
@@ -421,6 +425,10 @@ DhcpNameServer
  }

#else
  {
    char *p;
    FILE *fp;
    int linesize;
   
    fp = fopen(PATH_RESOLV_CONF, "r");
    if (!fp)
@@ -446,6 +454,7 @@ DhcpNameServer
    }
    free(line);
    fclose(fp);
  }

#endif

@@ -579,11 +588,52 @@ static int config_lookup(ares_channel channel, const char *str)
}

static int config_nameserver(struct server_state **servers, int *nservers,
			     const char *str)
			     char *str)
{
  struct in_addr addr;
  struct server_state *newserv;
  /* On Windows, there may be more than one nameserver specified in the same
   * registry key, so we parse it as a space or comma seperated list.
   */
#ifdef WIN32
  char *p = str;
  char *begin = str;
  int more = 1;
  while (more)
  {
    more = 0;
    while (*p && !isspace(*p) && *str != ',')
      p++;

    if (*p)
    {
      *p = 0;
      more = 1;
    }

    /* Skip multiple spaces or trailing spaces */
    if (!*begin)
    {
      begin = ++p;
      continue;
    }

    /* This is the part that actually sets the nameserver */
    addr.s_addr = inet_addr(begin);
    if (addr.s_addr == INADDR_NONE)
      continue;
    newserv = realloc(*servers, (*nservers + 1) * sizeof(struct server_state));
    if (!newserv)
      return ARES_ENOMEM;
    newserv[*nservers].addr = addr;
    *servers = newserv;
    (*nservers)++;

    if (!more)
      break;
    begin = ++p;
  }
#else
  /* Add a nameserver entry, if this is a valid address. */
  addr.s_addr = inet_addr(str);
  if (addr.s_addr == INADDR_NONE)
@@ -594,6 +644,7 @@ static int config_nameserver(struct server_state **servers, int *nservers,
  newserv[*nservers].addr = addr;
  *servers = newserv;
  (*nservers)++;
#endif
  return ARES_SUCCESS;
}