From 07e57e24c2201ef80ded0f9625b04213298a736d Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Fri, 28 Jul 2017 00:07:01 -0400 Subject: [PATCH] [mod_dirlisting] treat README and HEADER as paths (fixes #2818) Treat README and HEADER as filepaths. If absolute path, take as-is. If relative path, then take relative to directory physical path. This extends dir-listing.show-header and dir-listing.show-readme feature to take a filename, which was introduced in lighttpd 1.4.43 x-ref: "Custom HEADER and README filepaths in mod_dirlisting are treated as relative paths instead of absolute paths when file name starts with '/'" https://redmine.lighttpd.net/issue/2818 --- src/mod_dirlisting.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/mod_dirlisting.c b/src/mod_dirlisting.c index 2ea0d94c..382fa09a 100644 --- a/src/mod_dirlisting.c +++ b/src/mod_dirlisting.c @@ -786,11 +786,15 @@ static void http_list_directory_header(server *srv, connection *con, plugin_data if (!buffer_string_is_empty(p->conf.show_header)) { /* if we have a HEADER file, display it in
 */
 
-		buffer_copy_buffer(p->tmp_buf, con->physical.path);
-		buffer_append_slash(p->tmp_buf);
-		buffer_append_string_buffer(p->tmp_buf, p->conf.show_header);
+		buffer *hb = p->conf.show_header;
+		if (hb->ptr[0] != '/') {
+			buffer_copy_buffer(p->tmp_buf, con->physical.path);
+			buffer_append_slash(p->tmp_buf);
+			buffer_append_string_buffer(p->tmp_buf, p->conf.show_header);
+			hb = p->tmp_buf;
+		}
 
-		http_list_directory_include_file(out, p->tmp_buf, "header", p->conf.encode_header);
+		http_list_directory_include_file(out, hb, "header", p->conf.encode_header);
 	}
 
 	buffer_append_string_len(out, CONST_STR_LEN("

Index of ")); @@ -833,11 +837,15 @@ static void http_list_directory_footer(server *srv, connection *con, plugin_data if (!buffer_string_is_empty(p->conf.show_readme)) { /* if we have a README file, display it in
 */
 
-		buffer_copy_buffer(p->tmp_buf,  con->physical.path);
-		buffer_append_slash(p->tmp_buf);
-		buffer_append_string_buffer(p->tmp_buf, p->conf.show_readme);
+		buffer *rb = p->conf.show_readme;
+		if (rb->ptr[0] != '/') {
+			buffer_copy_buffer(p->tmp_buf,  con->physical.path);
+			buffer_append_slash(p->tmp_buf);
+			buffer_append_string_buffer(p->tmp_buf, p->conf.show_readme);
+			rb = p->tmp_buf;
+		}
 
-		http_list_directory_include_file(out, p->tmp_buf, "readme", p->conf.encode_readme);
+		http_list_directory_include_file(out, rb, "readme", p->conf.encode_readme);
 	}
 
 	if(p->conf.auto_layout) {