summaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
Diffstat (limited to 'libexec')
-rw-r--r--libexec/httpd/bozohttpd.89
-rw-r--r--libexec/httpd/bozohttpd.c5
-rw-r--r--libexec/httpd/bozohttpd.h3
-rw-r--r--libexec/httpd/dir-index-bozo.c24
-rw-r--r--libexec/httpd/main.c9
5 files changed, 42 insertions, 8 deletions
diff --git a/libexec/httpd/bozohttpd.8 b/libexec/httpd/bozohttpd.8
index a23791e4875..d7926dd3e3c 100644
--- a/libexec/httpd/bozohttpd.8
+++ b/libexec/httpd/bozohttpd.8
@@ -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 .
diff --git a/libexec/httpd/bozohttpd.c b/libexec/httpd/bozohttpd.c
index bdd283a95f8..149633ae101 100644
--- a/libexec/httpd/bozohttpd.c
+++ b/libexec/httpd/bozohttpd.c
@@ -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_t *prefs, const char *vhost,
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);
}
diff --git a/libexec/httpd/bozohttpd.h b/libexec/httpd/bozohttpd.h
index f5feea4161a..d9f99920d47 100644
--- a/libexec/httpd/bozohttpd.h
+++ b/libexec/httpd/bozohttpd.h
@@ -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 */
diff --git a/libexec/httpd/dir-index-bozo.c b/libexec/httpd/dir-index-bozo.c
index 1a56c5fc73d..77f4455a63e 100644
--- a/libexec/httpd/dir-index-bozo.c
+++ b/libexec/httpd/dir-index-bozo.c
@@ -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, const char *dirpath, int isindex)
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, const char *dirpath, int isindex)
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);
diff --git a/libexec/httpd/main.c b/libexec/httpd/main.c
index be688cd195b..04e0312777f 100644
--- a/libexec/httpd/main.c
+++ b/libexec/httpd/main.c
@@ -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);