From 51e88d1688374d88b930f3007d1ef2ad43948597 Mon Sep 17 00:00:00 2001 From: Eric Covener Date: Mon, 3 Mar 2014 15:02:45 +0000 Subject: [PATCH] Backport r1557639 r1557640 from trunk restore http://svn.apache.org/viewvc?view=revision&revision=233369 under a configurable option: don't run mod_dir if r->handler is already set. Backported by: covner Reviewed By: jim, ylavic git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1573580 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 +++ STATUS | 9 --------- docs/manual/mod/mod_dir.xml | 26 ++++++++++++++++++++++++++ modules/mappers/mod_dir.c | 33 +++++++++++++++++++++++++-------- 4 files changed, 54 insertions(+), 17 deletions(-) diff --git a/CHANGES b/CHANGES index a36348cca4..64fe91d62d 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,9 @@ Changes with Apache 2.4.8 + *) mod_dir: Add DirectoryCheckHandler to allow a 2.2-like behavior, skipping + execution when a handler is already set. PR53929. [Eric Covener] + *) mod_ssl: Do not perform SNI / Host header comparison in case of a forward proxy request. [Ruediger Pluem] diff --git a/STATUS b/STATUS index 5e6622018c..feb41335e8 100644 --- a/STATUS +++ b/STATUS @@ -98,15 +98,6 @@ RELEASE SHOWSTOPPERS: PATCHES ACCEPTED TO BACKPORT FROM TRUNK: [ start all new proposals below, under PATCHES PROPOSED. ] - * mod_dir: provide a directive to skip mod_dir processing if any other - handler has been configured, as in 2.2. - trunk patch: http://svn.apache.org/r1557639 - http://svn.apache.org/r1557640 - 2.4.x patch: http://people.apache.org/~covener/patches/2.4.x-moddir-skiphandler.diff - +1: covener, jim, ylavic - (I could be convinced to flip the default here, but I think it's too late) - - PATCHES PROPOSED TO BACKPORT FROM TRUNK: [ New proposals should be added at the end of the list ] diff --git a/docs/manual/mod/mod_dir.xml b/docs/manual/mod/mod_dir.xml index dea3bd07da..23a982ad17 100644 --- a/docs/manual/mod/mod_dir.xml +++ b/docs/manual/mod/mod_dir.xml @@ -276,5 +276,31 @@ later + +DirectoryCheckHandler +Toggle how this module responds when another handler is configured +DirectoryCheckHandler On|Off +DirectorySlash Off +server configvirtual host +directory.htaccess +Indexes +Available in 2.4.8 and later. Releases prior to 2.4 implicitly +act as if "DirectorySlash Off" was specified. + +

The DirectoryCheckHandler directive determines + whether mod_dir should check for directory indexes or + add trailing slashes when some other handler has been configured for + the current URL. Handlers can be set by directives such as + SetHandler or by other modules, + such as mod_rewrite during per-directory substitutions. +

+ +

In releases prior to 2.4, this module did not take any action if any + other handler was configured for a URL. This allows directory indexes to + be served even when a SetHandler directive is + specified for an entire directory, but it can also result in some conflicts + with modules such as mod_rewrite.

+
+
diff --git a/modules/mappers/mod_dir.c b/modules/mappers/mod_dir.c index 2316c53220..2a359c7fa5 100644 --- a/modules/mappers/mod_dir.c +++ b/modules/mappers/mod_dir.c @@ -34,17 +34,18 @@ module AP_MODULE_DECLARE_DATA dir_module; typedef enum { - SLASH_OFF = 0, - SLASH_ON, - SLASH_UNSET -} slash_cfg; + MODDIR_OFF = 0, + MODDIR_ON, + MODDIR_UNSET +} moddir_cfg; #define REDIRECT_OFF 0 #define REDIRECT_UNSET 1 typedef struct dir_config_struct { apr_array_header_t *index_names; - slash_cfg do_slash; + moddir_cfg do_slash; + moddir_cfg checkhandler; int redirect_index; const char *dflt; } dir_config_rec; @@ -84,7 +85,14 @@ static const char *configure_slash(cmd_parms *cmd, void *d_, int arg) { dir_config_rec *d = d_; - d->do_slash = arg ? SLASH_ON : SLASH_OFF; + d->do_slash = arg ? MODDIR_ON : MODDIR_OFF; + return NULL; +} +static const char *configure_checkhandler(cmd_parms *cmd, void *d_, int arg) +{ + dir_config_rec *d = d_; + + d->checkhandler = arg ? MODDIR_ON : MODDIR_OFF; return NULL; } static const char *configure_redirect(cmd_parms *cmd, void *d_, const char *arg1) @@ -124,6 +132,8 @@ static const command_rec dir_cmds[] = "a list of file names"), AP_INIT_FLAG("DirectorySlash", configure_slash, NULL, DIR_CMD_PERMS, "On or Off"), + AP_INIT_FLAG("DirectoryCheckHandler", configure_checkhandler, NULL, DIR_CMD_PERMS, + "On or Off"), AP_INIT_TAKE1("DirectoryIndexRedirect", configure_redirect, NULL, DIR_CMD_PERMS, "On, Off, or a 3xx status code."), @@ -135,7 +145,8 @@ static void *create_dir_config(apr_pool_t *p, char *dummy) dir_config_rec *new = apr_pcalloc(p, sizeof(dir_config_rec)); new->index_names = NULL; - new->do_slash = SLASH_UNSET; + new->do_slash = MODDIR_UNSET; + new->checkhandler = MODDIR_UNSET; new->redirect_index = REDIRECT_UNSET; return (void *) new; } @@ -148,7 +159,9 @@ static void *merge_dir_configs(apr_pool_t *p, void *basev, void *addv) new->index_names = add->index_names ? add->index_names : base->index_names; new->do_slash = - (add->do_slash == SLASH_UNSET) ? base->do_slash : add->do_slash; + (add->do_slash == MODDIR_UNSET) ? base->do_slash : add->do_slash; + new->checkhandler = + (add->checkhandler == MODDIR_UNSET) ? base->checkhandler : add->checkhandler; new->redirect_index= (add->redirect_index == REDIRECT_UNSET) ? base->redirect_index : add->redirect_index; new->dflt = add->dflt ? add->dflt : base->dflt; @@ -266,6 +279,10 @@ static int fixup_dir(request_rec *r) return DECLINED; } + if (d->checkhandler == MODDIR_ON && strcmp(r->handler, DIR_MAGIC_TYPE)) { + return DECLINED; + } + if (d->index_names) { names_ptr = (char **)d->index_names->elts; num_names = d->index_names->nelts; -- 2.40.0