]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Allowing include directive to use glob expressions, e.g. include
authorDiego dos Santos Fronza <diego@isc.org>
Fri, 13 Sep 2019 15:08:56 +0000 (12:08 -0300)
committerDiego Fronza <diego@isc.org>
Tue, 22 Oct 2019 14:30:02 +0000 (11:30 -0300)
"/opt/named.conf/*.conf".

doc/arm/Bv9ARM-book.xml
lib/isccfg/parser.c

index f1722e104cfb9953eb9e41bd2b17a969cbd9e4ff..8b65f8b54d6202a6e795474381b9b6119711c581 100644 (file)
@@ -3491,7 +3491,8 @@ $ORIGIN 0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.
 
        <para>
          The <command>include</command> statement inserts the
-         specified file at the point where the <command>include</command>
+          specified file (or files if a valid glob expression is detected)
+          at the point where the <command>include</command>
          statement is encountered. The <command>include</command>
                statement facilitates the administration of configuration
          files
index 0c7987b8810273157556ba872fac4fb9db7f2fba..f1ad258c7f7180beed3584969fb520e3e27c5093 100644 (file)
 #include <inttypes.h>
 #include <stdbool.h>
 #include <stdlib.h>
+#include <errno.h>
+#include <glob.h>
 
 #include <isc/buffer.h>
 #include <isc/dir.h>
+#include <isc/errno.h>
 #include <isc/formatcheck.h>
 #include <isc/lex.h>
 #include <isc/log.h>
@@ -100,6 +103,9 @@ static void
 parser_complain(cfg_parser_t *pctx, bool is_warning,
                unsigned int flags, const char *format, va_list args);
 
+static isc_result_t
+glob_include(const char * restrict pattern, glob_t * restrict pglob); 
+
 #if defined(HAVE_GEOIP2)
 static isc_result_t
 parse_geoip(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
@@ -1960,10 +1966,18 @@ cfg_parse_mapbody(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret)
                         */
                        CHECK(cfg_parse_obj(pctx, &cfg_type_qstring, &includename));
                        CHECK(parse_semicolon(pctx));
-                       CHECK(parser_openfile(pctx, includename->
-                                             value.string.base));
-                        cfg_obj_destroy(pctx, &includename);
-                        goto redo;
+
+                       /* Allow include to specify a pattern that follows
+                        * the same rules as the shell e.g "/path/zone*.conf" */
+                       glob_t glob_obj;
+                       CHECK(glob_include(includename->value.string.base, &glob_obj));
+                       cfg_obj_destroy(pctx, &includename);
+
+                       for (int i = 0; i < glob_obj.gl_matchc; ++i) {
+                               CHECK(parser_openfile(pctx, glob_obj.gl_pathv[i]));
+                       }
+
+                       goto redo;
                }
 
                clause = NULL;
@@ -3635,3 +3649,28 @@ cfg_pluginlist_foreach(const cfg_obj_t *config, const cfg_obj_t *list,
 
        return (result);
 }
+
+
+static isc_result_t
+glob_include(const char * restrict pattern, glob_t * restrict pglob)
+{
+       int rc = glob(pattern, GLOB_ERR, NULL, pglob);
+
+       switch (rc) {
+               case 0:
+                       return (ISC_R_SUCCESS);
+               case GLOB_NOMATCH:
+                       /* if a magic char (*?[]) was in pattern
+                        * and no path matched we report error early,
+                        * otherwise proceed as normal */
+                       return (pglob->gl_flags & GLOB_MAGCHAR) ?
+                                       (ISC_R_FILENOTFOUND) : (ISC_R_SUCCESS);
+
+               case GLOB_NOSPACE:
+                       return (ISC_R_NOMEMORY);
+               default:
+                       return (errno != 0 ? isc_errno_toresult(errno) : ISC_R_IOERROR);
+       }
+
+}
+