From e3d1d75a58dcc6bdb7fa7a9a3147ffd297407c76 Mon Sep 17 00:00:00 2001
From: Mark Andrews via RT <dhcp-bugs@isc.org>
Date: Wed, 15 Jan 2014 02:30:27 +0000
Subject: [PATCH] non-existance of resolv.conf should not be fatal
I've just put the following in for review. The open question is whether
we should return ISC_R_SUCCESS or some error code, when the file does not
exist, and fix the callers.
This should be enough to allow you to continue testing.
Mark
commit 1992f682728798ef73db89351285f03de6d52043
Author: Mark Andrews <marka@isc.org>
Date: Wed Jan 15 13:25:22 2014 +1100
---
lib/irs/resconf.c | 75 +++++++++++++++++++++++++++++--------------------------
1 file changed, 40 insertions(+), 35 deletions(-)
diff --git a/lib/irs/resconf.c b/lib/irs/resconf.c
index 88bdac1..8319dc6 100644
--- a/lib/irs/resconf.c
+++ b/lib/irs/resconf.c
@@ -507,45 +507,50 @@ irs_resconf_load(isc_mem_t *mctx, const char *filename, irs_resconf_t **confp)
conf->search[i] = NULL;
errno = 0;
- if ((fp = fopen(filename, "r")) == NULL) {
- isc_mem_put(mctx, conf, sizeof(*conf));
- return (ISC_R_INVALIDFILE);
- }
-
- ret = ISC_R_SUCCESS;
- do {
- stopchar = getword(fp, word, sizeof(word));
- if (stopchar == EOF) {
- rval = ISC_R_SUCCESS;
- POST(rval);
- break;
- }
-
- if (strlen(word) == 0U)
- rval = ISC_R_SUCCESS;
- else if (strcmp(word, "nameserver") == 0)
- rval = resconf_parsenameserver(conf, fp);
- else if (strcmp(word, "domain") == 0)
- rval = resconf_parsedomain(conf, fp);
- else if (strcmp(word, "search") == 0)
- rval = resconf_parsesearch(conf, fp);
- else if (strcmp(word, "sortlist") == 0)
- rval = resconf_parsesortlist(conf, fp);
- else if (strcmp(word, "options") == 0)
- rval = resconf_parseoption(conf, fp);
- else {
- /* unrecognised word. Ignore entire line */
- rval = ISC_R_SUCCESS;
- stopchar = eatline(fp);
+ if ((fp = fopen(filename, "r")) != NULL) {
+ ret = ISC_R_SUCCESS;
+ do {
+ stopchar = getword(fp, word, sizeof(word));
if (stopchar == EOF) {
+ rval = ISC_R_SUCCESS;
+ POST(rval);
break;
}
- }
- if (ret == ISC_R_SUCCESS && rval != ISC_R_SUCCESS)
- ret = rval;
- } while (1);
- fclose(fp);
+ if (strlen(word) == 0U)
+ rval = ISC_R_SUCCESS;
+ else if (strcmp(word, "nameserver") == 0)
+ rval = resconf_parsenameserver(conf, fp);
+ else if (strcmp(word, "domain") == 0)
+ rval = resconf_parsedomain(conf, fp);
+ else if (strcmp(word, "search") == 0)
+ rval = resconf_parsesearch(conf, fp);
+ else if (strcmp(word, "sortlist") == 0)
+ rval = resconf_parsesortlist(conf, fp);
+ else if (strcmp(word, "options") == 0)
+ rval = resconf_parseoption(conf, fp);
+ else {
+ /* unrecognised word. Ignore entire line */
+ rval = ISC_R_SUCCESS;
+ stopchar = eatline(fp);
+ if (stopchar == EOF) {
+ break;
+ }
+ }
+ if (ret == ISC_R_SUCCESS && rval != ISC_R_SUCCESS)
+ ret = rval;
+ } while (1);
+
+ fclose(fp);
+ } else {
+ switch (errno) {
+ case ENOENT:
+ break;
+ default:
+ isc_mem_put(mctx, conf, sizeof(*conf));
+ return (ISC_R_INVALIDFILE);
+ }
+ }
/* If we don't find a nameserver fall back to localhost */
if (conf->numns == 0) {
--
1.8.4.2