Given the following httpd.conf snippet
server "example.com" {
...
directory no index
...
location "/foo" {
...
directory auto index
...
}
}
the URL http://example.com/foo surprisingly results in a 403
response.
With the directory option of the "/foo" location changed to
location "/foo" {
directory {
index "index.html"
auto index
}
}
the auto-index is being generated (as expected).
I was wondering if there is any reason why the 'auto index' of
the location shouldn't implicitly override the 'no index' option
of the enclosing server (as it happens with the patch below).
Index: usr.sbin/httpd/config.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/config.c,v
retrieving revision 1.61
diff -u -p -u -p -r1.61 config.c
--- usr.sbin/httpd/config.c 21 Sep 2020 09:42:07 -0000 1.61
+++ usr.sbin/httpd/config.c 17 Oct 2020 12:26:20 -0000
@@ -488,11 +488,10 @@ config_getserver_config(struct httpd *en
if (srv_conf->flags & SRVFLAG_LOCATION) {
/* Inherit configuration from the parent */
f = SRVFLAG_INDEX|SRVFLAG_NO_INDEX;
- if ((srv_conf->flags & f) == 0) {
+ if ((srv_conf->flags & f) == 0)
srv_conf->flags |= parent->flags & f;
- (void)strlcpy(srv_conf->index, parent->index,
- sizeof(srv_conf->index));
- }
+ (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)
Index: usr.sbin/httpd/parse.y
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/parse.y,v
retrieving revision 1.118
diff -u -p -u -p -r1.118 parse.y
--- usr.sbin/httpd/parse.y 11 Oct 2020 03:21:44 -0000 1.118
+++ usr.sbin/httpd/parse.y 17 Oct 2020 12:26:20 -0000
@@ -1006,6 +1006,8 @@ dirflags : INDEX STRING {
srv_conf->flags |= SRVFLAG_NO_INDEX;
}
| AUTO INDEX {
+ srv_conf->flags &= ~SRVFLAG_NO_INDEX;
+ srv_conf->flags |= SRVFLAG_INDEX;
srv_conf->flags &= ~SRVFLAG_NO_AUTO_INDEX;
srv_conf->flags |= SRVFLAG_AUTO_INDEX;
}