From 1ee7b9348bef4480fdc8b154bdd9bc2f023072d6 Mon Sep 17 00:00:00 2001 From: Yann Ylavic Date: Sat, 14 Oct 2017 16:27:14 +0000 Subject: [PATCH] Follow up to r1740928: including NOT_IN_PROXY in NOT_IN_DIR_LOC_FILE is both incomplete and not backportable, fix it by introducing NOT_IN_DIR_CONTEXT and restoring NOT_IN_DIR_LOC_FILE to its previous value. Per ap_check_cmd_context(), NOT_IN_DIR_LOC_FILE actually/really means "not in any directory context", while the definition itself does not include all the existing directory contexts (e.g. , or before r1740928). This is a bit of a misnomer, at least, so instead of (ab)using it by adding the missing contexts (in an incompatible way), let's define NOT_IN_DIR_CONTEXT to really exclude all directory context (i.e. NOT_IN_DIR_LOC_FILE + NOT_IN_LIMIT + NOT_IN_PROXY) and use it wherever NOT_IN_DIR_LOC_FILE was used. This is by itself a major MMN bump (modules not compiled with this commit and having directives checked against NOT_IN_DIR_LOC_FILE won't be caught the same way by NOT_IN_DIR_CONTEXT in the new ap_check_cmd_context() code), but with the below change, 2.4.x should work as before: - if ((forbidden & NOT_IN_DIR_CONTEXT) == NOT_IN_DIR_CONTEXT) { + if ((forbidden & NOT_IN_DIR_LOC_FILE) == NOT_IN_DIR_LOC_FILE) { if (cmd->path != NULL) { return apr_pstrcat(cmd->pool, cmd->cmd->name, gt, - " cannot occur within directory context", NULL); + " cannot occur within " + "section", NULL); } ... } git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1812193 13f79535-47bb-0310-9956-ffa450edef68 --- include/ap_mmn.h | 2 ++ include/http_config.h | 6 +++-- modules/generators/mod_suexec.c | 2 +- modules/http/http_core.c | 6 ++--- modules/mappers/mod_alias.c | 2 +- modules/md/mod_md_config.c | 2 +- modules/proxy/mod_proxy.c | 2 +- server/core.c | 43 +++++++++++++++------------------ 8 files changed, 33 insertions(+), 32 deletions(-) diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 8874d4dfe4..f751254a71 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -557,6 +557,8 @@ * 20161018.6 (2.5.0-dev) Add ap_update_sb_handle() * 20161018.7 (2.5.0-dev) Add flags field to module_struct and function * ap_get_module_flags() + * 20171014.1 (2.5.0-dev) Add NOT_IN_DIR_CONTEXT replacing NOT_IN_DIR_LOC_FILE + * semantics */ #define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */ diff --git a/include/http_config.h b/include/http_config.h index 37e0b382ab..549e1d16be 100644 --- a/include/http_config.h +++ b/include/http_config.h @@ -950,10 +950,12 @@ AP_DECLARE(const char *) ap_check_cmd_context(cmd_parms *cmd, #define NOT_IN_FILES 0x10 /**< Forbidden in <Files> or <If>*/ #define NOT_IN_HTACCESS 0x20 /**< Forbidden in .htaccess files */ #define NOT_IN_PROXY 0x40 /**< Forbidden in <Proxy> */ +/** Forbidden in <Directory>/<Location>/<Files><If>*/ +#define NOT_IN_DIR_LOC_FILE (NOT_IN_DIRECTORY|NOT_IN_LOCATION|NOT_IN_FILES) /** Forbidden in <Directory>/<Location>/<Files><If><Proxy>*/ -#define NOT_IN_DIR_LOC_FILE (NOT_IN_DIRECTORY|NOT_IN_LOCATION|NOT_IN_FILES|NOT_IN_PROXY) +#define NOT_IN_DIR_CONTEXT (NOT_IN_LIMIT|NOT_IN_DIR_LOC_FILE|NOT_IN_PROXY) /** Forbidden in <VirtualHost>/<Limit>/<Directory>/<Location>/<Files>/<If><Proxy>*/ -#define GLOBAL_ONLY (NOT_IN_VIRTUALHOST|NOT_IN_LIMIT|NOT_IN_DIR_LOC_FILE) +#define GLOBAL_ONLY (NOT_IN_VIRTUALHOST|NOT_IN_DIR_CONTEXT) /** @} */ diff --git a/modules/generators/mod_suexec.c b/modules/generators/mod_suexec.c index 75e96404c0..a71b0a8597 100644 --- a/modules/generators/mod_suexec.c +++ b/modules/generators/mod_suexec.c @@ -59,7 +59,7 @@ static const char *set_suexec_ugid(cmd_parms *cmd, void *mconfig, const char *uid, const char *gid) { suexec_config_t *cfg = (suexec_config_t *) mconfig; - const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); if (err != NULL) { return err; diff --git a/modules/http/http_core.c b/modules/http/http_core.c index 6d4b0fbb0e..d256856aab 100644 --- a/modules/http/http_core.c +++ b/modules/http/http_core.c @@ -52,7 +52,7 @@ static const char *set_keep_alive_timeout(cmd_parms *cmd, void *dummy, const char *arg) { apr_interval_time_t timeout; - const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); if (err != NULL) { return err; } @@ -78,7 +78,7 @@ static const char *set_keep_alive_timeout(cmd_parms *cmd, void *dummy, static const char *set_keep_alive(cmd_parms *cmd, void *dummy, int arg) { - const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); if (err != NULL) { return err; } @@ -90,7 +90,7 @@ static const char *set_keep_alive(cmd_parms *cmd, void *dummy, static const char *set_keep_alive_max(cmd_parms *cmd, void *dummy, const char *arg) { - const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); if (err != NULL) { return err; } diff --git a/modules/mappers/mod_alias.c b/modules/mappers/mod_alias.c index 22a90aa80c..79d58d8263 100644 --- a/modules/mappers/mod_alias.c +++ b/modules/mappers/mod_alias.c @@ -131,7 +131,7 @@ static const char *add_alias_internal(cmd_parms *cmd, void *dummy, /* XXX: real can NOT be relative to DocumentRoot here... compat bug. */ - const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); if (err != NULL) { return err; diff --git a/modules/md/mod_md_config.c b/modules/md/mod_md_config.c index 33cc274433..3dddf723b9 100644 --- a/modules/md/mod_md_config.c +++ b/modules/md/mod_md_config.c @@ -346,7 +346,7 @@ static const char *md_config_set_names(cmd_parms *cmd, void *dc, int i, transitive = -1; (void)dc; - err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); if (err) { return err; } diff --git a/modules/proxy/mod_proxy.c b/modules/proxy/mod_proxy.c index ef3c73e813..2aa491e372 100644 --- a/modules/proxy/mod_proxy.c +++ b/modules/proxy/mod_proxy.c @@ -2498,7 +2498,7 @@ static const char *proxysection(cmd_parms *cmd, void *mconfig, const char *arg) proxy_worker *worker = NULL; int use_regex = 0; - const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); proxy_server_conf *sconf = (proxy_server_conf *) ap_get_module_config(cmd->server->module_config, &proxy_module); diff --git a/server/core.c b/server/core.c index c9b6837bd4..b8892a9a6b 100644 --- a/server/core.c +++ b/server/core.c @@ -1285,8 +1285,7 @@ AP_DECLARE(const char *) ap_check_cmd_context(cmd_parms *cmd, " cannot occur within section", NULL); } - if ((forbidden & (NOT_IN_LIMIT | NOT_IN_DIR_LOC_FILE)) - && cmd->limited != -1) { + if ((forbidden & NOT_IN_DIR_CONTEXT) && cmd->limited != -1) { return apr_pstrcat(cmd->pool, cmd->cmd->name, gt, " cannot occur within or " "section", NULL); @@ -1297,14 +1296,13 @@ AP_DECLARE(const char *) ap_check_cmd_context(cmd_parms *cmd, " cannot occur within htaccess files", NULL); } - if ((forbidden & NOT_IN_DIR_LOC_FILE) == NOT_IN_DIR_LOC_FILE) { + if ((forbidden & NOT_IN_DIR_CONTEXT) == NOT_IN_DIR_CONTEXT) { if (cmd->path != NULL) { return apr_pstrcat(cmd->pool, cmd->cmd->name, gt, - " cannot occur within " - "section", NULL); + " cannot occur within directory context", NULL); } if (cmd->cmd->req_override & EXEC_ON_READ) { - /* EXEC_ON_READ must be NOT_IN_DIR_LOC_FILE, if not, it will + /* EXEC_ON_READ must be NOT_IN_DIR_CONTEXT, if not, it will * (deliberately) segfault below in the individual tests... */ return NULL; @@ -1340,7 +1338,7 @@ static const char *set_access_name(cmd_parms *cmd, void *dummy, void *sconf = cmd->server->module_config; core_server_config *conf = ap_get_core_module_config(sconf); - const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); if (err != NULL) { return err; } @@ -1577,7 +1575,7 @@ static const char *set_gprof_dir(cmd_parms *cmd, void *dummy, const char *arg) void *sconf = cmd->server->module_config; core_server_config *conf = ap_get_core_module_config(sconf); - const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); if (err != NULL) { return err; } @@ -1613,7 +1611,7 @@ static const char *set_document_root(cmd_parms *cmd, void *dummy, void *sconf = cmd->server->module_config; core_server_config *conf = ap_get_core_module_config(sconf); - const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); if (err != NULL) { return err; } @@ -2391,7 +2389,7 @@ static const char *dirsection(cmd_parms *cmd, void *mconfig, const char *arg) ap_regex_t *r = NULL; const command_rec *thiscmd = cmd->cmd; - const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); if (err != NULL) { return err; } @@ -2492,7 +2490,7 @@ static const char *urlsection(cmd_parms *cmd, void *mconfig, const char *arg) ap_regex_t *r = NULL; const command_rec *thiscmd = cmd->cmd; ap_conf_vector_t *new_url_conf = ap_create_per_dir_config(cmd->pool); - const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); if (err != NULL) { return err; } @@ -2970,7 +2968,7 @@ AP_DECLARE(void) ap_set_server_protocol(server_rec* s, const char* proto) static const char *set_protocol(cmd_parms *cmd, void *dummy, const char *arg) { - const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); core_server_config *conf = ap_get_core_module_config(cmd->server->module_config); char* proto; @@ -2994,8 +2992,7 @@ static const char *set_server_string_slot(cmd_parms *cmd, void *dummy, int offset = (int)(long)cmd->info; char *struct_ptr = (char *)cmd->server; - const char *err = ap_check_cmd_context(cmd, - NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); if (err != NULL) { return err; } @@ -3014,7 +3011,7 @@ static const char *set_server_string_slot(cmd_parms *cmd, void *dummy, static const char *server_hostname_port(cmd_parms *cmd, void *dummy, const char *arg) { - const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); const char *portstr, *part; char *scheme; int port; @@ -3118,7 +3115,7 @@ static const char *set_runtime_dir(cmd_parms *cmd, void *dummy, const char *arg) static const char *set_timeout(cmd_parms *cmd, void *dummy, const char *arg) { - const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); if (err != NULL) { return err; @@ -3177,7 +3174,7 @@ static const char *set_hostname_lookups(cmd_parms *cmd, void *d_, static const char *set_serverpath(cmd_parms *cmd, void *dummy, const char *arg) { - const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); if (err != NULL) { return err; @@ -3609,7 +3606,7 @@ static const char *set_serv_tokens(cmd_parms *cmd, void *dummy, static const char *set_limit_req_line(cmd_parms *cmd, void *dummy, const char *arg) { - const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); int lim; if (err != NULL) { @@ -3629,7 +3626,7 @@ static const char *set_limit_req_line(cmd_parms *cmd, void *dummy, static const char *set_limit_req_fieldsize(cmd_parms *cmd, void *dummy, const char *arg) { - const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); int lim; if (err != NULL) { @@ -3650,7 +3647,7 @@ static const char *set_limit_req_fieldsize(cmd_parms *cmd, void *dummy, static const char *set_limit_req_fields(cmd_parms *cmd, void *dummy, const char *arg) { - const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); int lim; if (err != NULL) { @@ -3987,7 +3984,7 @@ static const char *set_protocols(cmd_parms *cmd, void *dummy, core_server_config *conf = ap_get_core_module_config(cmd->server->module_config); const char **np; - const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); if (err) { return err; @@ -4004,7 +4001,7 @@ static const char *set_protocols_honor_order(cmd_parms *cmd, void *dummy, { core_server_config *conf = ap_get_core_module_config(cmd->server->module_config); - const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); if (err) { return err; @@ -4070,7 +4067,7 @@ static const char *set_async_filter(cmd_parms *cmd, void *dummy, { core_server_config *conf = ap_get_core_module_config(cmd->server->module_config); - const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE); + const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); if (err) { return err; -- 2.40.0