]> git.ipfire.org Git - people/ms/dnsmasq.git/commitdiff
Extend --conf-dir to allow filtering on file suffixes.
authorSimon Kelley <simon@thekelleys.org.uk>
Tue, 9 Sep 2014 20:46:07 +0000 (21:46 +0100)
committerSimon Kelley <simon@thekelleys.org.uk>
Tue, 9 Sep 2014 20:46:07 +0000 (21:46 +0100)
CHANGELOG
dnsmasq.conf.example
man/dnsmasq.8
src/option.c

index d709adfacb8fdf1428afc2ca38598d84358890d4..941b56f26a81e90b5ab45c2830bbddfa3d6614df 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -30,6 +30,10 @@ version 2.72
            Include an RFC4191 route information option in router 
            advertisements for the prefix we're advertising. Thanks to 
            Ilya Ponetaev for the patch.
+
+           Extend --conf-dir to allow filtering of files. So
+           --conf-dir=/etc/dnsmasq.d,\*.conf
+           will load all the files in /etc/dnsmasq.d which end in .conf
  
 
 version 2.71
index 206f4d184e96f3d8aea21b541662b2ba27094017..83924fc4a9b4f77deaed7430a87275eb94e3d190 100644 (file)
 # Include another lot of configuration options.
 #conf-file=/etc/dnsmasq.more.conf
 #conf-dir=/etc/dnsmasq.d
+
+# Include all the files in a directory except those ending in .bak
+#conf-dir=/etc/dnsmasq.d,.bak
+
+# Include all files in a directory which end in .conf
+#conf-dir=/etc/dnsmasq.d/*.conf
\ No newline at end of file
index 7b4cc98965988fdcfe92ff37872e00ce45592f55..0b8e04f0a8971238993f360d2f809a62320d803e 100644 (file)
@@ -1725,12 +1725,16 @@ Specify a different configuration file. The conf-file option is also allowed in
 configuration files, to include multiple configuration files. A
 filename of "-" causes dnsmasq to read configuration from stdin.
 .TP
-.B \-7, --conf-dir=<directory>[,<file-extension>......]
+.B \-7, --conf-dir=<directory>[,<file-extension>......],
 Read all the files in the given directory as configuration
 files. If extension(s) are given, any files which end in those
 extensions are skipped. Any files whose names end in ~ or start with . or start and end
-with # are always skipped. This flag may be given on the command
-line or in a configuration file.
+with # are always skipped. If the extension starts with * then only files 
+which have that extension are loaded. So
+.B --conf-dir=/path/to/dir,*.conf
+loads all files with the suffix .conf in /path/to/dir. This flag may be given on the command
+line or in a configuration file. If giving it on the command line, be sure to
+escape * characters.
 .TP
 .B --servers-file=<file>
 A special case of 
index 07e7d36b2f3e884f13610098355d861eefb879d4..45d8875fb7f9cce5d71016e7331c927fbdbf246c 100644 (file)
@@ -1465,7 +1465,7 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
        struct list {
          char *suffix;
          struct list *next;
-       } *ignore_suffix = NULL, *li;
+       } *ignore_suffix = NULL, *match_suffix = NULL, *li;
        
        comma = split(arg);
        if (!(directory = opt_string_alloc(arg)))
@@ -1475,10 +1475,20 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
          {
            comma = split(arg);
            li = opt_malloc(sizeof(struct list));
-           li->next = ignore_suffix;
-           ignore_suffix = li;
-           /* Have to copy: buffer is overwritten */
-           li->suffix = opt_string_alloc(arg);
+           if (*arg == '*')
+             {
+               li->next = match_suffix;
+               match_suffix = li;
+               /* Have to copy: buffer is overwritten */
+               li->suffix = opt_string_alloc(arg+1);
+             }
+           else
+             {
+               li->next = ignore_suffix;
+               ignore_suffix = li;
+               /* Have to copy: buffer is overwritten */
+               li->suffix = opt_string_alloc(arg);
+             }
          };
        
        if (!(dir_stream = opendir(directory)))
@@ -1496,6 +1506,20 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
                ent->d_name[0] == '.')
              continue;
 
+           if (match_suffix)
+             {
+               for (li = match_suffix; li; li = li->next)
+                 {
+                   /* check for required suffices */
+                   size_t ls = strlen(li->suffix);
+                   if (len > ls &&
+                       strcmp(li->suffix, &ent->d_name[len - ls]) == 0)
+                     break;
+                 }
+               if (!li)
+                 continue;
+             }
+           
            for (li = ignore_suffix; li; li = li->next)
              {
                /* check for proscribed suffices */