Module Name:    src
Committed By:   jmcneill
Date:           Mon Jul  6 23:31:36 UTC 2020

Modified Files:
        src/libexec/httpd: bozohttpd.8 bozohttpd.c bozohttpd.h dir-index-bozo.c
            main.c

Log Message:
Add -R flag to specify a README file to add at the bottom of directory
autoindex listings.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/libexec/httpd/bozohttpd.8
cvs rdiff -u -r1.114 -r1.115 src/libexec/httpd/bozohttpd.c
cvs rdiff -u -r1.60 -r1.61 src/libexec/httpd/bozohttpd.h
cvs rdiff -u -r1.32 -r1.33 src/libexec/httpd/dir-index-bozo.c
cvs rdiff -u -r1.22 -r1.23 src/libexec/httpd/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/libexec/httpd/bozohttpd.8
diff -u src/libexec/httpd/bozohttpd.8:1.79 src/libexec/httpd/bozohttpd.8:1.80
--- src/libexec/httpd/bozohttpd.8:1.79	Thu Feb 28 08:28:21 2019
+++ src/libexec/httpd/bozohttpd.8	Mon Jul  6 23:31:36 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: bozohttpd.8,v 1.79 2019/02/28 08:28:21 mrg Exp $
+.\"	$NetBSD: bozohttpd.8,v 1.80 2020/07/06 23:31:36 jmcneill Exp $
 .\"
 .\"	$eterna: bozohttpd.8,v 1.101 2011/11/18 01:25:11 mrg Exp $
 .\"
@@ -26,7 +26,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd February 27, 2019
+.Dd July 6, 2020
 .Dt BOZOHTTPD 8
 .Os
 .Sh NAME
@@ -40,6 +40,7 @@
 .Op Fl L Ar prefix script
 .Op Fl M Ar suffix type encoding encoding11
 .Op Fl P Ar pidfile
+.Op Fl R Ar readme
 .Op Fl S Ar server_software
 .Op Fl T Ar type timeout
 .Op Fl U Ar username
@@ -232,6 +233,10 @@ translations from
 .Dq public_html
 to
 .Ar pubdir .
+.It Fl R Ar readme
+When directory indexing is enabled, include the contents of the file
+.Ar readme
+in the footer of the directory index.
 .It Fl S Ar server_software
 Sets the internal server version to
 .Ar server_software .

Index: src/libexec/httpd/bozohttpd.c
diff -u src/libexec/httpd/bozohttpd.c:1.114 src/libexec/httpd/bozohttpd.c:1.115
--- src/libexec/httpd/bozohttpd.c:1.114	Sun Jun  7 23:33:02 2020
+++ src/libexec/httpd/bozohttpd.c	Mon Jul  6 23:31:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: bozohttpd.c,v 1.114 2020/06/07 23:33:02 fox Exp $	*/
+/*	$NetBSD: bozohttpd.c,v 1.115 2020/07/06 23:31:36 jmcneill Exp $	*/
 
 /*	$eterna: bozohttpd.c,v 1.178 2011/11/18 09:21:15 mrg Exp $	*/
 
@@ -2570,6 +2570,9 @@ bozo_setup(bozohttpd_t *httpd, bozoprefs
 	    strcmp(cp, "true") == 0) {
 		httpd->dir_indexing = 1;
 	}
+	if ((cp = bozo_get_pref(prefs, "directory index readme")) != NULL) {
+		httpd->dir_readme = bozostrdup(httpd, NULL, cp);
+	}
 	if ((cp = bozo_get_pref(prefs, "public_html")) != NULL) {
 		httpd->public_html = bozostrdup(httpd, NULL, cp);
 	}

Index: src/libexec/httpd/bozohttpd.h
diff -u src/libexec/httpd/bozohttpd.h:1.60 src/libexec/httpd/bozohttpd.h:1.61
--- src/libexec/httpd/bozohttpd.h:1.60	Fri Mar  8 03:12:28 2019
+++ src/libexec/httpd/bozohttpd.h	Mon Jul  6 23:31:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: bozohttpd.h,v 1.60 2019/03/08 03:12:28 mrg Exp $	*/
+/*	$NetBSD: bozohttpd.h,v 1.61 2020/07/06 23:31:36 jmcneill Exp $	*/
 
 /*	$eterna: bozohttpd.h,v 1.39 2011/11/18 09:21:15 mrg Exp $	*/
 
@@ -117,6 +117,7 @@ typedef struct bozohttpd_t {
 	struct pollfd	*fds;		/* current poll fd set */
 	int		 request_times;	/* # times a request was processed */
 	int		 dir_indexing;	/* handle directories */
+	const char	*dir_readme;	/* include README footer in indexes */
 	int		 hide_dots;	/* hide .* */
 	int		 process_cgi;	/* use the cgi handler */
 	char		*cgibin;	/* cgi-bin directory */

Index: src/libexec/httpd/dir-index-bozo.c
diff -u src/libexec/httpd/dir-index-bozo.c:1.32 src/libexec/httpd/dir-index-bozo.c:1.33
--- src/libexec/httpd/dir-index-bozo.c:1.32	Thu Feb 28 08:28:21 2019
+++ src/libexec/httpd/dir-index-bozo.c	Mon Jul  6 23:31:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir-index-bozo.c,v 1.32 2019/02/28 08:28:21 mrg Exp $	*/
+/*	$NetBSD: dir-index-bozo.c,v 1.33 2020/07/06 23:31:36 jmcneill Exp $	*/
 
 /*	$eterna: dir-index-bozo.c,v 1.20 2011/11/18 09:21:15 mrg Exp $	*/
 
@@ -38,9 +38,11 @@
 
 #include <dirent.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <string.h>
 #include <stdlib.h>
 #include <time.h>
+#include <unistd.h>
 #include <assert.h>
 
 #include "bozohttpd.h"
@@ -57,7 +59,8 @@ bozo_dir_index(bozo_httpreq_t *request, 
 	DIR *dp;
 	char buf[MAXPATHLEN];
 	char *file = NULL, *printname = NULL, *p;
-	int k, j;
+	int k, j, fd;
+	ssize_t rlen;
 
 	if (!isindex || !httpd->dir_indexing)
 		return 0;
@@ -197,6 +200,23 @@ bozo_dir_index(bozo_httpreq_t *request, 
         	free(deo[k]);
 	free(deo);
 	bozo_printf(httpd, "</table>\r\n");
+	if (httpd->dir_readme != NULL) {
+		if (httpd->dir_readme[0] == '/')
+			snprintf(buf, sizeof buf, "%s", httpd->dir_readme);
+		else
+			snprintf(buf, sizeof buf, "%s/%s", dirpath, httpd->dir_readme);
+		fd = open(buf, O_RDONLY);
+		if (fd != -1) {
+			bozo_flush(httpd, stdout);
+			do {
+				rlen = read(fd, buf, sizeof buf);
+				if (rlen <= 0)
+					break;
+				bozo_write(httpd, STDOUT_FILENO, buf, rlen);
+			} while (1);
+			close(fd);
+		}
+	}
 	bozo_printf(httpd, "</body></html>\r\n\r\n");
 	bozo_flush(httpd, stdout);
 

Index: src/libexec/httpd/main.c
diff -u src/libexec/httpd/main.c:1.22 src/libexec/httpd/main.c:1.23
--- src/libexec/httpd/main.c:1.22	Sun Nov 25 07:37:20 2018
+++ src/libexec/httpd/main.c	Mon Jul  6 23:31:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.22 2018/11/25 07:37:20 mrg Exp $	*/
+/*	$NetBSD: main.c,v 1.23 2020/07/06 23:31:36 jmcneill Exp $	*/
 
 /*	$eterna: main.c,v 1.6 2011/11/18 09:21:15 mrg Exp $	*/
 /* from: eterna: bozohttpd.c,v 1.159 2009/05/23 02:14:30 mrg Exp 	*/
@@ -160,7 +160,7 @@ main(int argc, char **argv)
 	 */
 
 	while ((c = getopt(argc, argv,
-	    "C:EGHI:L:M:P:S:T:U:VXZ:bc:defhi:np:st:uv:x:z:")) != -1) {
+	    "C:EGHI:L:M:P:R:S:T:U:VXZ:bc:defhi:np:st:uv:x:z:")) != -1) {
 		switch (c) {
 
 		case 'b':
@@ -299,6 +299,11 @@ main(int argc, char **argv)
 			bozo_set_pref(&httpd, &prefs, "public_html", optarg);
 			break;
 
+		case 'R':
+			bozo_set_pref(&httpd, &prefs, "directory index readme",
+				      optarg);
+			break;
+
 		case 'S':
 			bozo_set_pref(&httpd, &prefs, "server software",
 				      optarg);

Reply via email to