From 15530b642aa64f780a6b31d835bd18e6f2c5df0f Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Tue, 29 Dec 2020 11:05:38 +0100 Subject: [PATCH] Non-existent webroot bugfix --- src/client.c | 6 +++--- src/necronda-server.h | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/client.c b/src/client.c index 222cb0b..4904b47 100644 --- a/src/client.c +++ b/src/client.c @@ -25,7 +25,7 @@ char *get_webroot(const char *http_host) { while (webroot_base[len - 1] == '/') len--; long pos = strchr(http_host, ':') - http_host; sprintf(webroot, "%.*s/%.*s", (int) len, webroot_base, (int) (pos < 0 ? strlen(http_host) : pos), http_host); - return webroot; + return path_is_directory(webroot) ? webroot : NULL; } void client_terminate() { @@ -114,8 +114,8 @@ int client_request_handler(sock *client, unsigned long client_num, unsigned int webroot = get_webroot(host); if (webroot == NULL) { res.status = http_get_status(307); - sprintf(buf0, "https://%s%s", NECRONDA_DEFAULT, req.uri); - http_add_header_field(&req.hdr, "Location", buf0); + sprintf(buf0, "https://%s%s", DEFAULT_HOST, req.uri); + http_add_header_field(&res.hdr, "Location", buf0); goto respond; } diff --git a/src/necronda-server.h b/src/necronda-server.h index 3c71da3..a13b214 100644 --- a/src/necronda-server.h +++ b/src/necronda-server.h @@ -53,9 +53,11 @@ #define NECRONDA_VERSION "4.0" #define SERVER_STR "Necronda/" NECRONDA_VERSION -#define NECRONDA_DEFAULT "www.necronda.net" #define NECRONDA_ZLIB_LEVEL 9 +#ifndef DEFAULT_HOST +#define DEFAULT_HOST "www.necronda.net" +#endif #ifndef MAGIC_FILE #define MAGIC_FILE "/usr/share/file/misc/magic.mgc" #endif