Commit Diff


commit - 91b9f2a8f9d39f2fb842c33049d966777027e5f4
commit + 1feaf2a618ee1c4771fee80ced7acf31fe40fdae
blob - 0dcad61216f0b57fcabd1836f1eeda0d377d0537
blob + 39eedecbfe8b001a04b1390f615c8bc627d37c17
--- ex.c
+++ ex.c
@@ -290,7 +290,7 @@ handle_imsg_cgi_req(struct imsgbuf *ibuf, struct imsg 
 	if ((h = host_nth(req.host_off)) == NULL)
 		abort();
 
-	if ((l = loc_nth(h, req.host_off)) == NULL)
+	if ((l = loc_nth(h, req.loc_off)) == NULL)
 		abort();
 
 	fd = launch_cgi(&iri, &req, h, l);
blob - e5794710320f8caa7b03cae78542f5c2c3f7d404
blob + 2fbec063ae2b3475075fa7c425a85fdd985d0f23
--- gmid.h
+++ gmid.h
@@ -245,6 +245,7 @@ struct client {
 
 	struct sockaddr_storage	 addr;
 	struct vhost	*host;	/* host they're talking to */
+	size_t		 loc;	/* location matched */
 };
 
 extern struct client clients[MAX_USERS];
@@ -342,7 +343,7 @@ const char	*vhost_index(struct vhost*, const char*);
 int		 vhost_auto_index(struct vhost*, const char*);
 int		 vhost_block_return(struct vhost*, const char*, int*, const char**);
 int		 vhost_fastcgi(struct vhost*, const char*);
-int		 vhost_dirfd(struct vhost*, const char*);
+int		 vhost_dirfd(struct vhost*, const char*, size_t*);
 int		 vhost_strip(struct vhost*, const char*);
 X509_STORE	*vhost_require_ca(struct vhost*, const char*);
 int		 vhost_disable_log(struct vhost*, const char*);
blob - b7a71f482439a267da4816463956e7120d387000
blob + 514782b572dd1a51ca37fdf68abb0f84e73e3192
--- server.c
+++ server.c
@@ -222,20 +222,25 @@ vhost_fastcgi(struct vhost *v, const char *path)
 }
 
 int
-vhost_dirfd(struct vhost *v, const char *path)
+vhost_dirfd(struct vhost *v, const char *path, size_t *retloc)
 {
 	struct location *loc;
+	size_t		 l = 0;
 
 	if (v == NULL || path == NULL)
 		return -1;
 
 	loc = TAILQ_FIRST(&v->locations);
 	while ((loc = TAILQ_NEXT(loc, locations)) != NULL) {
+		l++;
 		if (loc->dirfd != -1)
-			if (matches(loc->match, path))
+			if (matches(loc->match, path)) {
+				*retloc = l;
 				return loc->dirfd;
+			}
 	}
 
+	*retloc = 0;
 	loc = TAILQ_FIRST(&v->locations);
 	return loc->dirfd;
 }
@@ -322,7 +327,7 @@ check_path(struct client *c, const char *path, int *fd
 	if (*p == '\0')
 		p = ".";
 
-	dirfd = vhost_dirfd(c->host, path);
+	dirfd = vhost_dirfd(c->host, path, &c->loc);
 	log_debug(c, "check_path: strip=%d path=%s original=%s",
 	    strip, p, path);
 	flags = O_RDONLY | O_NOFOLLOW;
@@ -683,6 +688,7 @@ handle_open_conn(int fd, short ev, void *d)
 		return;
 
 	if (c->host->entrypoint != NULL) {
+		c->loc = 0;
 		start_cgi(c->host->entrypoint, c->iri.path, c);
 		return;
 	}
@@ -802,6 +808,7 @@ start_cgi(const char *spath, const char *relpath, stru
 	req.notafter = tls_peer_cert_notafter(c->ctx);
 
 	req.host_off = host_nth(c->host);
+	req.loc_off = c->loc;
 
 	imsg_compose(&exibuf, IMSG_CGI_REQ, c->id, 0, -1, &req, sizeof(req));
 	imsg_flush(&exibuf);