From: Jeff Trawick Date: Mon, 8 Nov 2010 13:15:17 +0000 (+0000) Subject: Add Error directive for aborting startup or htaccess processing X-Git-Tag: 2.3.9~80 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=66e4cc46767585749277c58684d5ddd3b1586af1;p=apache Add Error directive for aborting startup or htaccess processing with a specified error message. Be nice and strip off any quotes, which aren't necessary. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1032565 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index f683bc55e5..81d6db7ebe 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,9 @@ Changes with Apache 2.3.9 Fix a denial of service attack against mod_reqtimeout. [Stefan Fritsch] + *) core: Add Error directive for aborting startup or htaccess processing + with a specified error message. [Jeff Trawick] + *) mod_rewrite: Fix the RewriteEngine directive to work within a location. Previously, once RewriteEngine was switched on globally, it was impossible to switch off. [Graham Leggett] diff --git a/docs/manual/mod/core.xml b/docs/manual/mod/core.xml index 878ecea993..c2bbd8ab4c 100644 --- a/docs/manual/mod/core.xml +++ b/docs/manual/mod/core.xml @@ -889,6 +889,43 @@ version 2.3.9. + +Error +Abort configuration parsing with a custom error message +Error message +server configvirtual host +directory.htaccess + +2.3.9 and later + + +

If an error can be detected within the configuration, this + directive can be used to generate a custom error message, and halt + configuration parsing. The typical use is for reporting required + modules which are missing from the configuration.

+ + Example + # ensure that mod_include is loaded
+ <IfModule !include_module>
+ Error mod_include is required by mod_foo. Load it with LoadModule.
+ </IfModule>
+
+ # ensure that exactly one of SSL,NOSSL is defined
+ <IfDefine SSL>
+ <IfDefine NOSSL>
+ Error Both SSL and NOSSL are defined. Define only one of them.
+ </IfDefine>
+ </IfDefine>
+ <IfDefine !SSL>
+ <IfDefine !NOSSL>
+ Error Either SSL or NOSSL must be defined.
+ </IfDefine>
+ </IfDefine>
+
+ +
+
+ ErrorDocument What the server will return to the client diff --git a/server/core.c b/server/core.c index d41ff648f5..cf0d6c6750 100644 --- a/server/core.c +++ b/server/core.c @@ -1092,6 +1092,25 @@ static const char *unset_define(cmd_parms *cmd, void *dummy, return NULL; } +static const char *generate_error(cmd_parms *cmd, void *dummy, + const char *arg) +{ + if (!arg || !*arg) { + return "The Error directive was used with no message."; + } + + if (*arg == '"' || *arg == '\'') { /* strip off quotes */ + apr_size_t len = strlen(arg); + char last = *(arg + len - 1); + + if (*arg == last) { + return apr_pstrndup(cmd->pool, arg + 1, len - 2); + } + } + + return arg; +} + #ifdef GPROF static const char *set_gprof_dir(cmd_parms *cmd, void *dummy, const char *arg) { @@ -3432,6 +3451,8 @@ AP_INIT_TAKE1("Define", set_define, NULL, RSRC_CONF, "Define the existence of a variable. Same as passing -D to the command line."), AP_INIT_TAKE1("UnDefine", unset_define, NULL, RSRC_CONF, "Undefine the existence of a variable. Undo a Define."), +AP_INIT_RAW_ARGS("Error", generate_error, NULL, OR_ALL, + "Generate error message from within configuration"), AP_INIT_RAW_ARGS("