summaryrefslogtreecommitdiff
path: root/usr.sbin/httpd/config.c
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2014-07-30 10:05:15 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2014-07-30 10:05:15 +0000
commitbac000acea86b46f8c7c5176257dca0c9977a05c (patch)
treedc0109f11a5706092b8f3a5bf9a96892533b8ee5 /usr.sbin/httpd/config.c
parent229bb6da6741516656d06e0243c39d62fcb0c7b5 (diff)
Add "location" keyword to specify path-specific configuration in
servers, for example auto index for a sub-directory only. Internally, a "location" is just a special type of a "virtual" server.
Diffstat (limited to 'usr.sbin/httpd/config.c')
-rw-r--r--usr.sbin/httpd/config.c48
1 files changed, 42 insertions, 6 deletions
diff --git a/usr.sbin/httpd/config.c b/usr.sbin/httpd/config.c
index 762a7a392a5..9e9d2c3754d 100644
--- a/usr.sbin/httpd/config.c
+++ b/usr.sbin/httpd/config.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: config.c,v 1.5 2014/07/25 23:30:58 reyk Exp $ */
+/* $OpenBSD: config.c,v 1.6 2014/07/30 10:05:14 reyk Exp $ */
/*
* Copyright (c) 2011 - 2014 Reyk Floeter <reyk@openbsd.org>
@@ -185,7 +185,8 @@ config_setserver(struct httpd *env, struct server *srv)
iov[c].iov_base = &s;
iov[c++].iov_len = sizeof(s);
- if (id == PROC_SERVER) {
+ if (id == PROC_SERVER &&
+ (srv->srv_conf.flags & SRVFLAG_LOCATION) == 0) {
/* XXX imsg code will close the fd after 1st call */
n = -1;
proc_range(ps, id, &n, &m);
@@ -216,6 +217,7 @@ config_getserver_config(struct httpd *env, struct server *srv,
#endif
struct server_config *srv_conf;
u_int8_t *p = imsg->data;
+ u_int f;
if ((srv_conf = calloc(1, sizeof(*srv_conf))) == NULL)
return (-1);
@@ -223,11 +225,37 @@ config_getserver_config(struct httpd *env, struct server *srv,
IMSG_SIZE_CHECK(imsg, srv_conf);
memcpy(srv_conf, p, sizeof(*srv_conf));
- TAILQ_INSERT_TAIL(&srv->srv_hosts, srv_conf, entry);
+ if (srv_conf->flags & SRVFLAG_LOCATION) {
+ /* Inherit configuration from the parent */
+ f = SRVFLAG_INDEX|SRVFLAG_NO_INDEX;
+ if ((srv_conf->flags & f) == 0) {
+ srv_conf->flags |= srv->srv_conf.flags & f;
+ (void)strlcpy(srv_conf->index, srv->srv_conf.index,
+ sizeof(srv_conf->index));
+ }
+
+ f = SRVFLAG_AUTO_INDEX|SRVFLAG_NO_AUTO_INDEX;
+ if ((srv_conf->flags & f) == 0)
+ srv_conf->flags |= srv->srv_conf.flags & f;
+
+ f = SRVFLAG_DOCROOT;
+ if ((srv_conf->flags & f) == 0) {
+ (void)strlcpy(srv_conf->docroot,
+ srv->srv_conf.docroot,
+ sizeof(srv_conf->docroot));
+ }
+
+ DPRINTF("%s: %s %d received location \"%s\", parent \"%s\"",
+ __func__, ps->ps_title[privsep_process], ps->ps_instance,
+ srv_conf->location, srv->srv_conf.name);
+ } else {
+ /* Add a new "virtual" server */
+ DPRINTF("%s: %s %d received server \"%s\", parent \"%s\"",
+ __func__, ps->ps_title[privsep_process], ps->ps_instance,
+ srv_conf->name, srv->srv_conf.name);
+ }
- DPRINTF("%s: %s %d received configuration \"%s\", parent \"%s\"",
- __func__, ps->ps_title[privsep_process], ps->ps_instance,
- srv_conf->name, srv->srv_conf.name);
+ TAILQ_INSERT_TAIL(&srv->srv_hosts, srv_conf, entry);
return (0);
}
@@ -247,6 +275,14 @@ config_getserver(struct httpd *env, struct imsg *imsg)
memcpy(&srv_conf, p, sizeof(srv_conf));
s = sizeof(srv_conf);
+ if (srv_conf.flags & SRVFLAG_LOCATION) {
+ if ((srv = server_byname(srv_conf.name)) == NULL) {
+ log_warnx("%s: invalid location", __func__);
+ return (-1);
+ }
+ return (config_getserver_config(env, srv, imsg));
+ }
+
/* Check if server with matching listening socket already exists */
if ((srv = server_byaddr((struct sockaddr *)
&srv_conf.ss, srv_conf.port)) != NULL) {