]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
followup to r1894456: use a DirectorySlash argument instead
authorEric Covener <covener@apache.org>
Fri, 22 Oct 2021 00:12:40 +0000 (00:12 +0000)
committerEric Covener <covener@apache.org>
Fri, 22 Oct 2021 00:12:40 +0000 (00:12 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1894460 13f79535-47bb-0310-9956-ffa450edef68

changes-entries/DirectorySlashNotFound.txt
docs/manual/mod/mod_dir.xml
modules/mappers/mod_dir.c

index 4f67264406126741561b4a395e923710c64d07e9..87a8c7ee26554403e829a7aa92561be2c7b4479d 100644 (file)
@@ -1,2 +1,2 @@
-  *) mod_dir: Add "DirectorySlashNotFound" to return 404 instead of a 
-     DirectorySlash redirect. [Eric Covener]
+  *) mod_dir: Add "NotFound" option to "DirectorySlash" directive to return 
+     404 instead of a DirectorySlash redirect. [Eric Covener]
index 187d690a1082950f88709b1e595b9060c4abc861..218d9f99edac28e35a103b5dbf7ebdbb91aaeea6 100644 (file)
@@ -178,19 +178,20 @@ a directory</description>
 <directivesynopsis>
 <name>DirectorySlash</name>
 <description>Toggle trailing slash redirects on or off</description>
-<syntax>DirectorySlash On|Off</syntax>
+<syntax>DirectorySlash On|Off|NotFound</syntax>
 <default>DirectorySlash On</default>
 <contextlist><context>server config</context><context>virtual host</context>
 <context>directory</context><context>.htaccess</context></contextlist>
 <override>Indexes</override>
+<compatibility>Argument NotFound added in 2.5.1</compatibility>
 
 <usage>
-    <p>The <directive>DirectorySlash</directive> directive determines whether
+    <p>The <directive>DirectorySlash</directive> directive determines how 
     <module>mod_dir</module> should fixup URLs pointing to a directory or
     not.</p>
 
     <p>Typically if a user requests a resource without a trailing slash, which
-    points to a directory, <module>mod_dir</module> redirects him to the same
+    points to a directory, <module>mod_dir</module> redirects them to the same
     resource, but <em>with</em> trailing slash for some good reasons:</p>
 
     <ul>
@@ -227,22 +228,12 @@ a directory</description>
     </note>
        <p>Also note that some browsers may erroneously change POST requests into GET
        (thus discarding POST data) when a redirect is issued.</p>
-</usage>
-</directivesynopsis>
-<directivesynopsis>
-<name>DirectorySlashNotFound</name>
-<description>Toggle sending a HTTP 404 error in place of a trailing slash</description>
-<syntax>DirectorySlashNotFound On|Off</syntax>
-<default>DirectorySlashNotFound  Off</default>
-<contextlist><context>server config</context><context>virtual host</context>
-<context>directory</context><context>.htaccess</context></contextlist>
-<override>Indexes</override>
-<compatibility>Added in 2.5.1</compatibility>
 
-<usage>
-    <p>The <directive>DirectorySlashNotFound</directive> directive determines whether
-    <module>mod_dir</module> should return an HTTP 404 status code where it would 
-    otherwise have redirected the request to include a trailing slash.  </p>
+    <p>To avoid the risks of the "off" behavior above, or to avoid disclosing 
+    that a directory is present via the behavior of "on", an argument of 
+    "NotFound" can be used to tell <module>mod_dir</module> to return an HTTP 
+    404 status code redirected the request to include a trailing slash.</p>
+
 </usage>
 </directivesynopsis>
 <directivesynopsis>
index 0bb6a274bbd6638889fb7ebf262e7070661d9e31..d13babf81853d0d4cf9b9ba0652700ccec179735 100644 (file)
@@ -39,16 +39,23 @@ typedef enum {
     MODDIR_UNSET
 } moddir_cfg;
 
+typedef enum {
+    SLASH_OFF = 0,
+    SLASH_ON,
+    SLASH_NOTFOUND,
+    SLASH_UNSET
+} moddir_doslash;
+
+
 #define REDIRECT_OFF   0
 #define REDIRECT_UNSET 1
 
 typedef struct dir_config_struct {
     apr_array_header_t *index_names;
-    moddir_cfg do_slash;
+    moddir_doslash do_slash;
     moddir_cfg checkhandler;
     int redirect_index;
     const char *dflt;
-    moddir_cfg do_slash_notfound;
 } dir_config_rec;
 
 #define DIR_CMD_PERMS OR_INDEXES
@@ -82,18 +89,22 @@ static const char *add_index(cmd_parms *cmd, void *dummy, const char *arg)
     return NULL;
 }
 
-static const char *configure_slash(cmd_parms *cmd, void *d_, int arg)
-{
-    dir_config_rec *d = d_;
-
-    d->do_slash = arg ? MODDIR_ON : MODDIR_OFF;
-    return NULL;
-}
-static const char *configure_slash_notfound(cmd_parms *cmd, void *d_, int arg)
+static const char *configure_slash(cmd_parms *cmd, void *d_, const char *arg1)
 {
     dir_config_rec *d = d_;
 
-    d->do_slash_notfound = arg ? MODDIR_ON : MODDIR_OFF;
+    if (!ap_cstr_casecmp(arg1, "on")) { 
+        d->do_slash = SLASH_ON;
+    }
+    else if (!ap_cstr_casecmp(arg1, "off")) { 
+        d->do_slash = SLASH_OFF;
+    }
+    else if (!ap_cstr_casecmp(arg1, "NotFound")) { 
+        d->do_slash = SLASH_NOTFOUND;
+    }
+    else { 
+        return "DirectorySlash only accepts ON, OFF, or 'NotFound'";
+    }
     return NULL;
 }
 static const char *configure_checkhandler(cmd_parms *cmd, void *d_, int arg)
@@ -138,9 +149,7 @@ static const command_rec dir_cmds[] =
                   DIR_CMD_PERMS, "Set a default handler"),
     AP_INIT_RAW_ARGS("DirectoryIndex", add_index, NULL, DIR_CMD_PERMS,
                     "a list of file names"),
-    AP_INIT_FLAG("DirectorySlash", configure_slash, NULL, DIR_CMD_PERMS,
-                 "On or Off"),
-    AP_INIT_FLAG("DirectorySlashNotFound", configure_slash_notfound, NULL, DIR_CMD_PERMS,
+    AP_INIT_TAKE1("DirectorySlash", configure_slash, NULL, DIR_CMD_PERMS,
                  "On or Off"),
     AP_INIT_FLAG("DirectoryCheckHandler", configure_checkhandler, NULL, DIR_CMD_PERMS,
                  "On or Off"),
@@ -155,8 +164,7 @@ 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 = MODDIR_UNSET;
-    new->do_slash_notfound = MODDIR_UNSET;
+    new->do_slash = SLASH_UNSET;
     new->checkhandler = MODDIR_UNSET;
     new->redirect_index = REDIRECT_UNSET;
     return (void *) new;
@@ -170,9 +178,7 @@ 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 == MODDIR_UNSET) ? base->do_slash : add->do_slash;
-    new->do_slash_notfound =
-        (add->do_slash_notfound == MODDIR_UNSET) ? base->do_slash_notfound : add->do_slash_notfound;
+        (add->do_slash == SLASH_UNSET) ? base->do_slash : add->do_slash;
     new->checkhandler =
         (add->checkhandler == MODDIR_UNSET) ? base->checkhandler : add->checkhandler;
     new->redirect_index=
@@ -260,14 +266,14 @@ static int fixup_dir(request_rec *r)
     {
         char *ifile;
 
-        if (!d->do_slash) {
+        if (d->do_slash == SLASH_OFF) {
             return DECLINED;
         }
-
-        if (d->do_slash_notfound == MODDIR_ON) { 
+        if (d->do_slash == SLASH_NOTFOUND) {
             return HTTP_NOT_FOUND;
         }
 
+
         /* Only redirect non-get requests if we have no note to warn
          * that this browser cannot handle redirs on non-GET requests
          * (such as Microsoft's WebFolders).