--- /dev/null
+/*
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+ *
+ * SPDX-License-Identifier: MPL-2.0
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
+ *
+ * See the COPYRIGHT file distributed with this work for additional
+ * information regarding copyright ownership.
+ */
+
+include "";
#include <ctype.h>
#include <errno.h>
+#include <glob.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include <isc/dir.h>
#include <isc/errno.h>
#include <isc/formatcheck.h>
-#include <isc/glob.h>
#include <isc/lex.h>
#include <isc/log.h>
#include <isc/mem.h>
* clause can occur.
*/
if (strcasecmp(TOKEN_STRING(pctx), "include") == 0) {
+ glob_t g;
+ int rc;
+
/*
* Turn the file name into a temporary configuration
* object just so that it is not overwritten by the
&includename));
CHECK(parse_semicolon(pctx));
- /* Allow include to specify a pattern that follows
- * the same rules as the shell e.g "/path/zone*.conf" */
- glob_t glob_obj;
- CHECK(isc_glob(includename->value.string.base,
- &glob_obj));
- cfg_obj_destroy(pctx, &includename);
+ if (includename->value.string.length == 0) {
+ CHECK(ISC_R_FILENOTFOUND);
+ }
- for (size_t i = 0; i < glob_obj.gl_pathc; ++i) {
- CHECK(parser_openfile(pctx,
- glob_obj.gl_pathv[i]));
+ /*
+ * Allow include to specify a pattern that follows
+ * the same rules as the shell e.g "/path/zone*.conf"
+ */
+ rc = glob(cfg_obj_asstring(includename), GLOB_ERR, NULL,
+ &g);
+
+ switch (rc) {
+ case 0:
+ break;
+ case GLOB_NOMATCH:
+ CHECK(ISC_R_FILENOTFOUND);
+ break;
+ case GLOB_NOSPACE:
+ CHECK(ISC_R_NOMEMORY);
+ break;
+ default:
+ if (errno == 0) {
+ CHECK(ISC_R_IOERROR);
+ }
+ CHECK(isc_errno_toresult(errno));
}
- isc_globfree(&glob_obj);
+ for (size_t i = 0; i < g.gl_pathc; ++i) {
+ CHECK(parser_openfile(pctx, g.gl_pathv[i]));
+ }
+
+ cfg_obj_destroy(pctx, &includename);
+ globfree(&g);
goto redo;
}