summaryrefslogtreecommitdiff
path: root/ares_init.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2004-09-26 22:35:18 +0000
committerDaniel Stenberg <daniel@haxx.se>2004-09-26 22:35:18 +0000
commit405d83852a38c17cf9e681aa9b087d659a9438ae (patch)
tree0f1c211582026c822a488d16a732da11fec53a6b /ares_init.c
parent2bf866b0ce6084e28af061d68bbc351b3be55e84 (diff)
downloadc-ares-405d83852a38c17cf9e681aa9b087d659a9438ae.tar.gz
c-ares-405d83852a38c17cf9e681aa9b087d659a9438ae.tar.bz2
c-ares-405d83852a38c17cf9e681aa9b087d659a9438ae.zip
- Henrik Stoerner: found out that C-ARES does not look at the /etc/host.conf
file to determine the sequence in which to search /etc/hosts and DNS. So on systems where this order is defined by /etc/host.conf instead of a "lookup" entry in /etc/resolv.conf, C-ARES will always default to looking in DNS first, and /etc/hosts second. c-ares now looks at 1) resolv.conf (for the "lookup" line); 2) nsswitch.fon (for the "hosts:" line); 3) host.conf (for the "order" line). First match wins.
Diffstat (limited to 'ares_init.c')
-rw-r--r--ares_init.c44
1 files changed, 36 insertions, 8 deletions
diff --git a/ares_init.c b/ares_init.c
index 1d4a015..78d865c 100644
--- a/ares_init.c
+++ b/ares_init.c
@@ -55,7 +55,8 @@ static int init_by_environment(ares_channel channel);
static int init_by_resolv_conf(ares_channel channel);
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_lookup(ares_channel channel, const char *str,
+ const char *bindch, const char *filech);
static int config_nameserver(struct server_state **servers, int *nservers,
char *str);
static int config_sortlist(struct apattern **sortlist, int *nsort,
@@ -549,7 +550,7 @@ DhcpNameServer
if ((p = try_config(line, "domain")))
status = config_domain(channel, p);
else if ((p = try_config(line, "lookup")) && !channel->lookups)
- status = config_lookup(channel, p);
+ status = config_lookup(channel, p, "bind", "file");
else if ((p = try_config(line, "search")))
status = set_search(channel, p);
else if ((p = try_config(line, "nameserver")) && channel->nservers == -1)
@@ -563,9 +564,33 @@ DhcpNameServer
if (status != ARES_SUCCESS)
break;
}
+ fclose(fp);
+
+ if (!channel->lookups) {
+ fp = fopen("/etc/nsswitch.conf", "r");
+ if (fp) {
+ while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
+ {
+ if ((p = try_config(line, "hosts:")) && !channel->lookups)
+ status = config_lookup(channel, p, "dns", "files");
+ }
+ fclose(fp);
+ }
+ }
+ if (!channel->lookups) {
+ fp = fopen("/etc/host.conf", "r");
+ if (fp) {
+ while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
+ {
+ if ((p = try_config(line, "order")) && !channel->lookups)
+ status = config_lookup(channel, p, "bind", "hosts");
+ }
+ fclose(fp);
+ }
+ }
+
if(line)
free(line);
- fclose(fp);
}
#endif
@@ -679,7 +704,8 @@ static int config_domain(ares_channel channel, char *str)
return set_search(channel, str);
}
-static int config_lookup(ares_channel channel, const char *str)
+static int config_lookup(ares_channel channel, const char *str,
+ const char *bindch, const char *filech)
{
char lookups[3], *l;
const char *p;
@@ -692,11 +718,13 @@ static int config_lookup(ares_channel channel, const char *str)
p = str;
while (*p)
{
- if ((*p == 'b' || *p == 'f') && l < lookups + 2)
- *l++ = *p;
- while (*p && !isspace((unsigned char)*p))
+ if ((*p == *bindch || *p == *filech) && l < lookups + 2) {
+ if (*p == *bindch) *l++ = 'b';
+ else *l++ = 'f';
+ }
+ while (*p && !isspace((unsigned char)*p) && (*p != ','))
p++;
- while (isspace((unsigned char)*p))
+ while (*p && (isspace((unsigned char)*p) || (*p == ',')))
p++;
}
*l = 0;