]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Serve files in subdirs.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 2 May 2014 12:08:47 +0000 (13:08 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 2 May 2014 12:08:47 +0000 (13:08 +0100)
src/libutil/http.c

index 22f87026207eae92fe3b28aa9e5879873a146c15..2f649e4775ce5621f61a1b4a12cd12c2f05d5359 100644 (file)
@@ -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;
        }