Commit Diff


commit - 4f7492c36e5ae600b0e0ad2b2d271712d55e34b9
commit + 03d671e2aa44271e6feb5dc6b1f20f833735d917
blob - 7340aec6bcc56eeceaf3f07262f1d873972be388
blob + cd8f6679a6de6f9942f8e9ca63f2572b098b9780
--- fcgi.c
+++ fcgi.c
@@ -374,10 +374,9 @@ void
 fcgi_req(struct client *c, struct location *loc)
 {
 	char		 buf[22], path[GEMINI_URL_LEN];
-	char		*qs, *pathinfo, *scriptname = NULL;
+	char		*qs, *p, *pathinfo, *scriptname = NULL;
 	size_t		 l;
 	time_t		 tim;
-	int		 r;
 	struct tm	 tminfo;
 	struct envlist	*p;
 
@@ -390,12 +389,11 @@ fcgi_req(struct client *c, struct location *loc)
 	if (scriptname == NULL)
 		scriptname = "";
 
-	r = snprintf(path, sizeof(path), "/%s", c->iri.path);
-	if (r < 0 || (size_t)r >= sizeof(c->iri.path)) {
-		log_warn("snprintf failure?");
-		fcgi_error(c->cgibev, EVBUFFER_ERROR, c);
-		return;
-	}
+	p = strip_path(c->iri.path, loc->fcgi_strip);
+	if (*p != '/')
+		snprintf(path, sizeof(path), "/%s", p);
+	else
+		strlcpy(path, p, sizeof(path));
 
 	pathinfo = path;
 	l = strlen(scriptname);
blob - 7ae413926ec910f018b5155d1efaab8ac891ae79
blob + 5738e72613a9504aec57e8694007461b164bdeb5
--- gmid.conf.5
+++ gmid.conf.5
@@ -318,6 +318,10 @@ is interpreted as a hostname or an IP address.
 can be either a port number or the name of a service enclosed in
 double quotes.
 If not specified defaults to 9000.
+.It Ic strip Ar number
+Strip
+.Ar number
+leading path components from the
 .El
 .Pp
 The FastCGI handler will be given the following variables by default:
blob - 272d237f306c4fbd57625b0b9489e06a9bcbec93
blob + bdf38839422a91150fc3ded6145ef4ffc1de3afd
--- gmid.h
+++ gmid.h
@@ -183,6 +183,7 @@ struct location {
 	int		 disable_log;
 	int		 fcgi;
 	int		 nofcgi;
+	int		 fcgi_strip;
 	struct envhead	 params;
 
 	char		 dir[PATH_MAX];
blob - 82c9cbcad81cfe5862d7a72478c994d368ee468f
blob + fcb0219c28156bac972731822154833cb80c37c6
--- parse.y
+++ parse.y
@@ -601,6 +601,9 @@ fastcgiopt	: PARAM string '=' string {
 			free($3);
 			free($5);
 		}
+		| STRIP NUM {
+			loc->fcgi_strip = $2;
+		}
 		;
 
 types		: TYPES '{' optnl mediaopts_l '}' ;