]> granicus.if.org Git - apache/commitdiff
core: Introduce the IncludeStrict directive, which explicitly fails
authorGraham Leggett <minfrin@apache.org>
Mon, 29 Mar 2010 22:09:35 +0000 (22:09 +0000)
committerGraham Leggett <minfrin@apache.org>
Mon, 29 Mar 2010 22:09:35 +0000 (22:09 +0000)
server startup if no files or directories match a wildcard path.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@928916 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
docs/manual/mod/core.xml
server/config.c
server/core.c

diff --git a/CHANGES b/CHANGES
index 413ed65f440e04357e25b1563883dce166157829..ab616cc91e6f803e25591ac9555b7c1c0360b0b7 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -28,6 +28,10 @@ Changes with Apache 2.3.7
      processing is completed, avoiding orphaned callback pointers.
      [Brett Gervasoni <brettg senseofsecurity.com>, Jeff Trawick]
 
+  *) core: Introduce the IncludeStrict directive, which explicitly fails
+     server startup if no files or directories match a wildcard path.
+     [Graham Leggett]
+
   *) htcacheclean: Report additional statistics about entries deleted.
      PR 48944. [Mark Drayton mark markdrayton.info]
 
index 3f9e1d33018f0676772a620712ae8f6a65342cbe..69fe0ccc5b19914a3d43740256310ac9063668a9 100644 (file)
@@ -1539,7 +1539,8 @@ later.</compatibility>
 <name>Include</name>
 <description>Includes other configuration files from within
 the server configuration files</description>
-<syntax>Include <var>file-path</var>|<var>directory-path</var></syntax>
+<syntax>Include <var>file-path</var>|<var>directory-path</var>|
+<var>wildcard</var></syntax>
 <contextlist><context>server config</context><context>virtual host</context>
 <context>directory</context>
 </contextlist>
@@ -1571,6 +1572,11 @@ wildcard matching available in 2.3.6 and later</compatibility>
     for placeholder files to exist so that at least one file or directory is
     found by the wildcard.</p>
 
+    <p>Under certain circumstances, it may be required for the server to fail
+    explicitly when no files or directories match a specific wildcard. In these
+    cases, use the <directive module="code">IncludeStrict</directive>
+    directive instead.</p>
+
     <p>The file path specified may be an absolute path, or may be relative 
     to the <directive module="core">ServerRoot</directive> directory.</p>
 
@@ -1602,6 +1608,47 @@ wildcard matching available in 2.3.6 and later</compatibility>
 <seealso><program>apachectl</program></seealso>
 </directivesynopsis>
 
+<directivesynopsis>
+<name>IncludeStrict</name>
+<description>Includes other configuration files from within the server
+configuration files, throwing an error if no files or directories match
+a wildcard
+</description>
+<syntax>IncludeStrict <var>file-path</var>|<var>directory-path</var>|
+<var>wildcard</var></syntax>
+<contextlist><context>server config</context><context>virtual host</context>
+<context>directory</context>
+</contextlist>
+<compatibility>Available in 2.3.6 and later</compatibility>
+
+<usage>
+      <p>This directive allows inclusion of other configuration files
+      from within the server configuration files.</p>
+
+      <p>It is functionally equivalent to the
+      <directive module="core">Include</directive> directive, with the additional
+      restriction that any wildcards are required to match at least one file or
+      directory.</p>
+
+      <p>The file path specified may be an absolute path, or may be relative 
+      to the <directive module="core">ServerRoot</directive> directory.</p>
+
+      <p>Example:</p>
+
+      <p>The server will fail to load if the wildcard path
+      <var>/usr/local/apache2/conf/vhosts/*.conf</var> does not match at least
+      one file or directory.</p>
+
+      <example>
+        IncludeStrict /usr/local/apache2/conf/ssl.conf<br />
+        IncludeStrict /usr/local/apache2/conf/vhosts/*.conf
+      </example>
+
+</usage>
+
+<seealso><program>apachectl</program></seealso>
+</directivesynopsis>
+  
 <directivesynopsis>
 <name>KeepAlive</name>
 <description>Enables HTTP persistent connections</description>
index 7378e8263d01dec246e400ed08400a28d628fd49..5c48256236a4bffea4449801dfffd848a1232d5f 100644 (file)
@@ -1558,7 +1558,8 @@ static const char *process_resource_config_nofnmatch(server_rec *s,
                                                      ap_directive_t **conftree,
                                                      apr_pool_t *p,
                                                      apr_pool_t *ptemp,
-                                                     unsigned depth)
+                                                     unsigned depth,
+                                                     int strict)
 {
     cmd_parms parms;
     ap_configfile_t *cfp;
@@ -1615,7 +1616,7 @@ static const char *process_resource_config_nofnmatch(server_rec *s,
                 fnew = &((fnames *) candidates->elts)[current];
                 error = process_resource_config_nofnmatch(s, fnew->fname,
                                                           conftree, p, ptemp,
-                                                          depth);
+                                                          depth, strict);
                 if (error) {
                     return error;
                 }
@@ -1659,7 +1660,8 @@ static const char *process_resource_config_fnmatch(server_rec *s,
                                                    ap_directive_t **conftree,
                                                    apr_pool_t *p,
                                                    apr_pool_t *ptemp,
-                                                   unsigned depth)
+                                                   unsigned depth,
+                                                   int strict)
 {
     const char *rest;
     apr_status_t rv;
@@ -1682,12 +1684,12 @@ static const char *process_resource_config_fnmatch(server_rec *s,
         if (!rest) {
             return process_resource_config_nofnmatch(s, path,
                                                      conftree, p,
-                                                     ptemp, 0);
+                                                     ptemp, 0, strict);
         }
         else {
             return process_resource_config_fnmatch(s, path, rest,
                                                    conftree, p,
-                                                   ptemp, 0);
+                                                   ptemp, 0, strict);
         }
     }
 
@@ -1738,27 +1740,32 @@ static const char *process_resource_config_fnmatch(server_rec *s,
             if (!rest) {
                 error = process_resource_config_nofnmatch(s, fnew->fname,
                                                           conftree, p,
-                                                          ptemp, 0);
+                                                          ptemp, 0, strict);
             }
             else {
                 error = process_resource_config_fnmatch(s, fnew->fname, rest,
                                                         conftree, p,
-                                                        ptemp, 0);
+                                                        ptemp, 0, strict);
             }
             if (error) {
                 return error;
             }
         }
     }
+    else if (strict) {
+        return apr_psprintf(p, "No matches for the wildcard '%s' in %s",
+                            fname, path);
+    }
 
     return NULL;
 }
 
-AP_DECLARE(const char *) ap_process_resource_config(server_rec *s,
-                                                    const char *fname,
-                                                    ap_directive_t **conftree,
-                                                    apr_pool_t *p,
-                                                    apr_pool_t *ptemp)
+AP_DECLARE(const char *) ap_process_resource_config_ex(server_rec *s,
+                                                       const char *fname,
+                                                       ap_directive_t **conftree,
+                                                       apr_pool_t *p,
+                                                       apr_pool_t *ptemp,
+                                                       int strict)
 {
     /* XXX: lstat() won't work on the wildcard pattern...
      */
@@ -1775,7 +1782,7 @@ AP_DECLARE(const char *) ap_process_resource_config(server_rec *s,
 
     if (!apr_fnmatch_test(fname)) {
         return process_resource_config_nofnmatch(s, fname, conftree, p, ptemp,
-                                                 0);
+                                                 0, strict);
     }
     else {
         apr_status_t status;
@@ -1794,13 +1801,22 @@ AP_DECLARE(const char *) ap_process_resource_config(server_rec *s,
 
         /* walk the filepath */
         return process_resource_config_fnmatch(s, rootpath, filepath, conftree, p, ptemp,
-                                                 0);
+                                                 0, strict);
 
     }
 
     return NULL;
 }
 
+AP_DECLARE(const char *) ap_process_resource_config(server_rec *s,
+                                                    const char *fname,
+                                                    ap_directive_t **conftree,
+                                                    apr_pool_t *p,
+                                                    apr_pool_t *ptemp)
+{
+    return ap_process_resource_config_ex(s, fname, conftree, p, ptemp, 0);
+}
+
 AP_DECLARE(int) ap_process_config_tree(server_rec *s,
                                        ap_directive_t *conftree,
                                        apr_pool_t *p,
index 27fc034abda364fc6aa57960da5835c0c2887800..4e333ace2be7e97c3dc56148822aa4f46387b62e 100644 (file)
@@ -2566,9 +2566,8 @@ static const char *set_use_canonical_phys_port(cmd_parms *cmd, void *d_,
     return NULL;
 }
 
-
 static const char *include_config (cmd_parms *cmd, void *dummy,
-                                   const char *name)
+                                   const char *name, int strict)
 {
     ap_directive_t *conftree = NULL;
     const char* conffile, *error;
@@ -2599,8 +2598,8 @@ static const char *include_config (cmd_parms *cmd, void *dummy,
                            name, NULL);
     }
 
-    error = ap_process_resource_config(cmd->server, conffile,
-                                       &conftree, cmd->pool, cmd->temp_pool);
+    error = ap_process_resource_config_ex(cmd->server, conffile,
+                                       &conftree, cmd->pool, cmd->temp_pool, strict);
     if (error) {
         *recursion = 0;
         return error;
@@ -2616,6 +2615,18 @@ static const char *include_config (cmd_parms *cmd, void *dummy,
     return NULL;
 }
 
+static const char *include_regular_config(cmd_parms *cmd, void *dummy,
+                                          const char *name)
+{
+    return include_config(cmd, dummy, name, 0);
+}
+
+static const char *include_strict_config(cmd_parms *cmd, void *dummy,
+                                          const char *name)
+{
+    return include_config(cmd, dummy, name, 1);
+}
+
 static const char *set_loglevel(cmd_parms *cmd, void *dummy, const char *arg)
 {
     char *str;
@@ -3302,9 +3313,12 @@ AP_INIT_TAKE1("UseCanonicalPhysicalPort", set_use_canonical_phys_port, NULL,
   "Whether to use the physical Port when constructing URLs"),
 /* TODO: RlimitFoo should all be part of mod_cgi, not in the core */
 /* TODO: ListenBacklog in MPM */
-AP_INIT_TAKE1("Include", include_config, NULL,
+AP_INIT_TAKE1("Include", include_regular_config, NULL,
+  (RSRC_CONF | ACCESS_CONF | EXEC_ON_READ),
+  "Name of the config file to be included, ignore wildcards with no match"),
+AP_INIT_TAKE1("IncludeStrict", include_strict_config, NULL,
   (RSRC_CONF | ACCESS_CONF | EXEC_ON_READ),
-  "Name of the config file to be included"),
+  "Name of the config file to be included, fail if wildcards don't match"),
 AP_INIT_TAKE1("LogLevel", set_loglevel, NULL, RSRC_CONF,
   "Level of verbosity in error logging"),
 AP_INIT_TAKE1("NameVirtualHost", ap_set_name_virtual_host, NULL, RSRC_CONF,