From 8bf293b76f13aa37c6f627057bd71e486cd29c65 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 2 May 2014 13:08:47 +0100 Subject: Serve files in subdirs. --- src/libutil/http.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/libutil/http.c b/src/libutil/http.c index 22f870262..2f649e477 100644 --- a/src/libutil/http.c +++ b/src/libutil/http.c @@ -1049,6 +1049,29 @@ rspamd_http_router_detect_ct (const gchar *path) return http_file_types[HTTP_MAGIC_PLAIN].ct; } +static gboolean +rspamd_http_router_is_subdir (const gchar *parent, const gchar *sub) +{ + if (parent == NULL || sub == NULL || *parent == '\0') { + return FALSE; + } + + while (*parent != '\0') { + if (*sub != *parent) { + return FALSE; + } + parent ++; + sub ++; + } + + parent --; + if (*parent == G_DIR_SEPARATOR) { + return TRUE; + } + + return (*sub == G_DIR_SEPARATOR || *sub == '\0'); +} + static gboolean rspamd_http_router_try_file (struct rspamd_http_connection_entry *entry, struct rspamd_http_message *msg, gboolean expand_path) @@ -1086,7 +1109,8 @@ rspamd_http_router_try_file (struct rspamd_http_connection_entry *entry, /* We also need to ensure that file is inside the defined dir */ rspamd_strlcpy (filebuf, realbuf, sizeof (filebuf)); dir = dirname (filebuf); - if (dir == NULL || strcmp (dir, entry->rt->default_fs_path) != 0) { + if (dir == NULL || !rspamd_http_router_is_subdir (entry->rt->default_fs_path, + dir)) { return FALSE; } -- cgit v1.2.3