geomyidae

A small C-based gopherd. (gopher://bitreich.org/1/scm/geomyidae)
git clone git://r-36.net/geomyidae
Log | Files | Refs | README | LICENSE

commit 3a876cbe4fb9b93ecf98decfa79e7f9b27dbc320
parent 646c0c9ac1c8944393c3640c63ffefd6f400c2a5
Author: Christoph Lohmann <20h@r-36.net>
Date:   Sat, 22 Jul 2023 17:14:59 +0200

First stub for new http-compatibility feature.

Diffstat:
Mmain.c | 19+++++++++++++++++++
1 file changed, 19 insertions(+), 0 deletions(-)

diff --git a/main.c b/main.c @@ -187,6 +187,25 @@ handlerequest(int sock, char *req, int rlen, char *base, char *ohost, if (c) c[0] = '\0'; + /* + * Try to guess if we have some HTTP-like protocol compatibility + * mode. + */ + if (!nocgi && recvb[0] != '/' && (c = strchr(recvb, " "))) { + *c = '\0'; + if (strchr(recvb, '/')) + goto dothegopher; + if (snprintf(path, "%s/%s", base, recvb) <= sizeof(path)) { + if (realpath(path, (char *)rpath)) { + if (stat(rpath, &dir)) { + handlecgi(sock, rpath, port, base, NULL, NULL, ohost, + clienth, serverh, istls, req, NULL); + } + } + } + } +dothegopher: + /* Do not allow requests including "..". */ if (strstr(recvb, "..")) { dprintf(sock, "%s", selinval);