Introduction
Introduction Statistics Contact Development Disclaimer Help
Adding support for index.cgi and index.dcgi. - geomyidae - A small C-based goph…
git clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfri…
Log
Files
Refs
Tags
README
LICENSE
---
commit 244ea008836ed16030d843c157877c4aa8e71a08
parent f4302a23294447764096dbe4ad39bcd67dfe53b6
Author: Christoph Lohmann <[email protected]>
Date: Sat, 26 Nov 2016 22:54:33 +0100
Adding support for index.cgi and index.dcgi.
Diffstat:
M main.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
---
diff --git a/main.c b/main.c
@@ -44,7 +44,7 @@ char *logfile = nil;
char *argv0;
char *stdbase = "/var/gopher";
char *stdport = "70";
-char *indexf = "/index.gph";
+char *indexf[] = {"/index.gph", "/index.cgi", "/index.dcgi"};
char *err = "3Sorry, but the requested token '%s' could not be found.\tErr"
"\tlocalhost\t70\r\n.\r\n\r\n";
char *htredir = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
@@ -131,7 +131,7 @@ handlerequest(int sock, char *base, char *ohost, char *port…
{
struct stat dir;
char recvc[1025], recvb[1025], path[1025], *args, *sear, *c;
- int len, fd;
+ int len, fd, i;
filetype *type;
memset(&dir, 0, sizeof(dir));
@@ -170,11 +170,26 @@ handlerequest(int sock, char *base, char *ohost, char *po…
*args++ = '\0';
securepath(recvb, len - 2);
+ if(strlen(recvb) == 0) {
+ recvb[0] = '/';
+ recvb[1] = '\0';
+ }
+
snprintf(path, sizeof(path), "%s%s", base, recvb);
- if(stat(path, &dir) != -1 && S_ISDIR(dir.st_mode))
- strncat(path, indexf, sizeof(path) - strlen(path));
- fd = open(path, O_RDONLY);
+ fd = -1;
+ if(stat(path, &dir) != -1 && S_ISDIR(dir.st_mode)) {
+ for(i = 0; i < sizeof(indexf)/sizeof(indexf)[0]; i++) {
+ strncat(path, indexf[i], sizeof(path) - strlen(path));
+ fd = open(path, O_RDONLY);
+ if(fd >= 0)
+ break;
+ path[strlen(path)-strlen(indexf[i])] = '\0';
+ }
+ } else {
+ fd = open(path, O_RDONLY);
+ }
+
if(fd >= 0) {
close(fd);
if(loglvl & FILES)
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.