Hello,

It's been noted that the "directory no index" configuration
always shadow any other directory index configuration,
for example:

directory no index
location "/foo/" {
        directory auto index
}

Even when requesting /foo/,
the global no index option
overrides the location-specific auto index.

This looks a bit too restrictive
and contrary to having location-specific options.

Here's a patch proposal modifying the current behaviour.
Note that if multiple contradictory options
are defined at the same level,
the most restrictive option, no index,
will still have priority over the others.

What do you think?

Index: config.c
===================================================================
RCS file: /var/cvs/src/usr.sbin/httpd/config.c,v
retrieving revision 1.61
diff -u -p -u -r1.61 config.c
--- config.c    21 Sep 2020 09:42:07 -0000      1.61
+++ config.c    24 Mar 2021 21:26:39 -0000
@@ -451,7 +451,7 @@ config_getserver_config(struct httpd *en
 #endif
        struct server_config    *srv_conf, *parent;
        uint8_t                 *p = imsg->data;
-       unsigned int             f;
+       unsigned int             f, fo;
        size_t                   s;
 
        if ((srv_conf = calloc(1, sizeof(*srv_conf))) == NULL)
@@ -489,14 +489,19 @@ config_getserver_config(struct httpd *en
                /* Inherit configuration from the parent */
                f = SRVFLAG_INDEX|SRVFLAG_NO_INDEX;
                if ((srv_conf->flags & f) == 0) {
-                       srv_conf->flags |= parent->flags & f;
+                       fo = SRVFLAG_AUTO_INDEX|SRVFLAG_NO_AUTO_INDEX;
+                       if ((srv_conf->flags & fo) == 0)
+                               srv_conf->flags |= parent->flags & f;
                        (void)strlcpy(srv_conf->index, parent->index,
                            sizeof(srv_conf->index));
                }
 
                f = SRVFLAG_AUTO_INDEX|SRVFLAG_NO_AUTO_INDEX;
-               if ((srv_conf->flags & f) == 0)
-                       srv_conf->flags |= parent->flags & f;
+               if ((srv_conf->flags & f) == 0) {
+                       fo = SRVFLAG_INDEX|SRVFLAG_NO_INDEX;
+                       if ((srv_conf->flags & fo) == 0)
+                               srv_conf->flags |= parent->flags & f;
+               }
 
                f = SRVFLAG_ROOT;
                if ((srv_conf->flags & f) == 0) {

Reply via email to