Add -R flag to specify a README file to add at the bottom of directory autoindex listings.diff -r1.79 -r1.80 src/libexec/httpd/bozohttpd.8
(jmcneill)
--- src/libexec/httpd/bozohttpd.8 2019/02/28 08:28:21 1.79
+++ src/libexec/httpd/bozohttpd.8 2020/07/06 23:31:36 1.80
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | .\" $NetBSD: bozohttpd.8,v 1.79 2019/02/28 08:28:21 mrg Exp $ | 1 | .\" $NetBSD: bozohttpd.8,v 1.80 2020/07/06 23:31:36 jmcneill Exp $ | |
2 | .\" | 2 | .\" | |
3 | .\" $eterna: bozohttpd.8,v 1.101 2011/11/18 01:25:11 mrg Exp $ | 3 | .\" $eterna: bozohttpd.8,v 1.101 2011/11/18 01:25:11 mrg Exp $ | |
4 | .\" | 4 | .\" | |
5 | .\" Copyright (c) 1997-2019 Matthew R. Green | 5 | .\" Copyright (c) 1997-2019 Matthew R. Green | |
6 | .\" All rights reserved. | 6 | .\" All rights reserved. | |
7 | .\" | 7 | .\" | |
8 | .\" Redistribution and use in source and binary forms, with or without | 8 | .\" Redistribution and use in source and binary forms, with or without | |
9 | .\" modification, are permitted provided that the following conditions | 9 | .\" modification, are permitted provided that the following conditions | |
10 | .\" are met: | 10 | .\" are met: | |
11 | .\" 1. Redistributions of source code must retain the above copyright | 11 | .\" 1. Redistributions of source code must retain the above copyright | |
12 | .\" notice, this list of conditions and the following disclaimer. | 12 | .\" notice, this list of conditions and the following disclaimer. | |
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the | |
@@ -16,40 +16,41 @@ | @@ -16,40 +16,41 @@ | |||
16 | .\" | 16 | .\" | |
17 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 17 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
18 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 18 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
19 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 19 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
20 | .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 20 | .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
21 | .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | 21 | .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
22 | .\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 22 | .\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
23 | .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | 23 | .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | |
24 | .\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 24 | .\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
25 | .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 25 | .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
26 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 26 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
27 | .\" SUCH DAMAGE. | 27 | .\" SUCH DAMAGE. | |
28 | .\" | 28 | .\" | |
29 | .Dd February 27, 2019 | 29 | .Dd July 6, 2020 | |
30 | .Dt BOZOHTTPD 8 | 30 | .Dt BOZOHTTPD 8 | |
31 | .Os | 31 | .Os | |
32 | .Sh NAME | 32 | .Sh NAME | |
33 | .Nm bozohttpd | 33 | .Nm bozohttpd | |
34 | .Nd hyper text transfer protocol version 1.1 daemon | 34 | .Nd hyper text transfer protocol version 1.1 daemon | |
35 | .Sh SYNOPSIS | 35 | .Sh SYNOPSIS | |
36 | .Nm | 36 | .Nm | |
37 | .Op Fl EGHVXefhnsu | 37 | .Op Fl EGHVXefhnsu | |
38 | .Op Fl C Ar suffix cgihandler | 38 | .Op Fl C Ar suffix cgihandler | |
39 | .Op Fl I Ar port | 39 | .Op Fl I Ar port | |
40 | .Op Fl L Ar prefix script | 40 | .Op Fl L Ar prefix script | |
41 | .Op Fl M Ar suffix type encoding encoding11 | 41 | .Op Fl M Ar suffix type encoding encoding11 | |
42 | .Op Fl P Ar pidfile | 42 | .Op Fl P Ar pidfile | |
43 | .Op Fl R Ar readme | |||
43 | .Op Fl S Ar server_software | 44 | .Op Fl S Ar server_software | |
44 | .Op Fl T Ar type timeout | 45 | .Op Fl T Ar type timeout | |
45 | .Op Fl U Ar username | 46 | .Op Fl U Ar username | |
46 | .Op Fl Z Ar cert privkey | 47 | .Op Fl Z Ar cert privkey | |
47 | .Op Fl c Ar cgibin | 48 | .Op Fl c Ar cgibin | |
48 | .Op Fl i Ar address | 49 | .Op Fl i Ar address | |
49 | .Op Fl p Ar pubdir | 50 | .Op Fl p Ar pubdir | |
50 | .Op Fl t Ar chrootdir | 51 | .Op Fl t Ar chrootdir | |
51 | .Op Fl v Ar virtualroot | 52 | .Op Fl v Ar virtualroot | |
52 | .Op Fl x Ar index | 53 | .Op Fl x Ar index | |
53 | .Op Fl z Ar ciphers | 54 | .Op Fl z Ar ciphers | |
54 | .Ar slashdir | 55 | .Ar slashdir | |
55 | .Op Ar myname | 56 | .Op Ar myname | |
@@ -222,26 +223,30 @@ Causes | @@ -222,26 +223,30 @@ Causes | |||
222 | .Nm | 223 | .Nm | |
223 | to create a PID file in | 224 | to create a PID file in | |
224 | .Ar pidfile | 225 | .Ar pidfile | |
225 | when run in daemon mode with the | 226 | when run in daemon mode with the | |
226 | .Fl b | 227 | .Fl b | |
227 | option. | 228 | option. | |
228 | .It Fl p Ar pubdir | 229 | .It Fl p Ar pubdir | |
229 | Changes the default user directory for | 230 | Changes the default user directory for | |
230 | .Em /~user/ | 231 | .Em /~user/ | |
231 | translations from | 232 | translations from | |
232 | .Dq public_html | 233 | .Dq public_html | |
233 | to | 234 | to | |
234 | .Ar pubdir . | 235 | .Ar pubdir . | |
236 | .It Fl R Ar readme | |||
237 | When directory indexing is enabled, include the contents of the file | |||
238 | .Ar readme | |||
239 | in the footer of the directory index. | |||
235 | .It Fl S Ar server_software | 240 | .It Fl S Ar server_software | |
236 | Sets the internal server version to | 241 | Sets the internal server version to | |
237 | .Ar server_software . | 242 | .Ar server_software . | |
238 | .It Fl s | 243 | .It Fl s | |
239 | Forces logging to be set to stderr always. | 244 | Forces logging to be set to stderr always. | |
240 | .It Fl T Ar type timeout | 245 | .It Fl T Ar type timeout | |
241 | Set the timeout for | 246 | Set the timeout for | |
242 | .Ar type | 247 | .Ar type | |
243 | to | 248 | to | |
244 | .Ar timeout . | 249 | .Ar timeout . | |
245 | The valid values of | 250 | The valid values of | |
246 | .Ar type | 251 | .Ar type | |
247 | are | 252 | are |
--- src/libexec/httpd/bozohttpd.c 2020/06/07 23:33:02 1.114
+++ src/libexec/httpd/bozohttpd.c 2020/07/06 23:31:36 1.115
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: bozohttpd.c,v 1.114 2020/06/07 23:33:02 fox Exp $ */ | 1 | /* $NetBSD: bozohttpd.c,v 1.115 2020/07/06 23:31:36 jmcneill Exp $ */ | |
2 | 2 | |||
3 | /* $eterna: bozohttpd.c,v 1.178 2011/11/18 09:21:15 mrg Exp $ */ | 3 | /* $eterna: bozohttpd.c,v 1.178 2011/11/18 09:21:15 mrg Exp $ */ | |
4 | 4 | |||
5 | /* | 5 | /* | |
6 | * Copyright (c) 1997-2019 Matthew R. Green | 6 | * Copyright (c) 1997-2019 Matthew R. Green | |
7 | * All rights reserved. | 7 | * All rights reserved. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright | |
@@ -2560,26 +2560,29 @@ bozo_setup(bozohttpd_t *httpd, bozoprefs | @@ -2560,26 +2560,29 @@ bozo_setup(bozohttpd_t *httpd, bozoprefs | |||
2560 | } | 2560 | } | |
2561 | if ((cp = bozo_get_pref(prefs, "dirty environment")) != NULL && | 2561 | if ((cp = bozo_get_pref(prefs, "dirty environment")) != NULL && | |
2562 | strcmp(cp, "true") == 0) { | 2562 | strcmp(cp, "true") == 0) { | |
2563 | dirtyenv = 1; | 2563 | dirtyenv = 1; | |
2564 | } | 2564 | } | |
2565 | if ((cp = bozo_get_pref(prefs, "hide dots")) != NULL && | 2565 | if ((cp = bozo_get_pref(prefs, "hide dots")) != NULL && | |
2566 | strcmp(cp, "true") == 0) { | 2566 | strcmp(cp, "true") == 0) { | |
2567 | httpd->hide_dots = 1; | 2567 | httpd->hide_dots = 1; | |
2568 | } | 2568 | } | |
2569 | if ((cp = bozo_get_pref(prefs, "directory indexing")) != NULL && | 2569 | if ((cp = bozo_get_pref(prefs, "directory indexing")) != NULL && | |
2570 | strcmp(cp, "true") == 0) { | 2570 | strcmp(cp, "true") == 0) { | |
2571 | httpd->dir_indexing = 1; | 2571 | httpd->dir_indexing = 1; | |
2572 | } | 2572 | } | |
2573 | if ((cp = bozo_get_pref(prefs, "directory index readme")) != NULL) { | |||
2574 | httpd->dir_readme = bozostrdup(httpd, NULL, cp); | |||
2575 | } | |||
2573 | if ((cp = bozo_get_pref(prefs, "public_html")) != NULL) { | 2576 | if ((cp = bozo_get_pref(prefs, "public_html")) != NULL) { | |
2574 | httpd->public_html = bozostrdup(httpd, NULL, cp); | 2577 | httpd->public_html = bozostrdup(httpd, NULL, cp); | |
2575 | } | 2578 | } | |
2576 | if ((cp = bozo_get_pref(prefs, "ssl timeout")) != NULL) { | 2579 | if ((cp = bozo_get_pref(prefs, "ssl timeout")) != NULL) { | |
2577 | httpd->ssl_timeout = atoi(cp); | 2580 | httpd->ssl_timeout = atoi(cp); | |
2578 | } | 2581 | } | |
2579 | if ((cp = bozo_get_pref(prefs, "initial timeout")) != NULL) { | 2582 | if ((cp = bozo_get_pref(prefs, "initial timeout")) != NULL) { | |
2580 | httpd->initial_timeout = atoi(cp); | 2583 | httpd->initial_timeout = atoi(cp); | |
2581 | } | 2584 | } | |
2582 | if ((cp = bozo_get_pref(prefs, "header timeout")) != NULL) { | 2585 | if ((cp = bozo_get_pref(prefs, "header timeout")) != NULL) { | |
2583 | httpd->header_timeout = atoi(cp); | 2586 | httpd->header_timeout = atoi(cp); | |
2584 | } | 2587 | } | |
2585 | if ((cp = bozo_get_pref(prefs, "request timeout")) != NULL) { | 2588 | if ((cp = bozo_get_pref(prefs, "request timeout")) != NULL) { |
--- src/libexec/httpd/bozohttpd.h 2019/03/08 03:12:28 1.60
+++ src/libexec/httpd/bozohttpd.h 2020/07/06 23:31:36 1.61
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: bozohttpd.h,v 1.60 2019/03/08 03:12:28 mrg Exp $ */ | 1 | /* $NetBSD: bozohttpd.h,v 1.61 2020/07/06 23:31:36 jmcneill Exp $ */ | |
2 | 2 | |||
3 | /* $eterna: bozohttpd.h,v 1.39 2011/11/18 09:21:15 mrg Exp $ */ | 3 | /* $eterna: bozohttpd.h,v 1.39 2011/11/18 09:21:15 mrg Exp $ */ | |
4 | 4 | |||
5 | /* | 5 | /* | |
6 | * Copyright (c) 1997-2019 Matthew R. Green | 6 | * Copyright (c) 1997-2019 Matthew R. Green | |
7 | * All rights reserved. | 7 | * All rights reserved. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright | |
@@ -107,26 +107,27 @@ typedef struct bozohttpd_t { | @@ -107,26 +107,27 @@ typedef struct bozohttpd_t { | |||
107 | char *bindaddress; /* address for binding - INADDR_ANY */ | 107 | char *bindaddress; /* address for binding - INADDR_ANY */ | |
108 | int debug; /* debugging level */ | 108 | int debug; /* debugging level */ | |
109 | char *virthostname; /* my name */ | 109 | char *virthostname; /* my name */ | |
110 | const char *server_software;/* our brand :-) */ | 110 | const char *server_software;/* our brand :-) */ | |
111 | const char *index_html; /* our home page */ | 111 | const char *index_html; /* our home page */ | |
112 | const char *public_html; /* ~user/public_html page */ | 112 | const char *public_html; /* ~user/public_html page */ | |
113 | int enable_users; /* enable public_html */ | 113 | int enable_users; /* enable public_html */ | |
114 | int enable_cgi_users; /* use the cgi handler */ | 114 | int enable_cgi_users; /* use the cgi handler */ | |
115 | int *sock; /* bound sockets */ | 115 | int *sock; /* bound sockets */ | |
116 | int nsock; /* number of above */ | 116 | int nsock; /* number of above */ | |
117 | struct pollfd *fds; /* current poll fd set */ | 117 | struct pollfd *fds; /* current poll fd set */ | |
118 | int request_times; /* # times a request was processed */ | 118 | int request_times; /* # times a request was processed */ | |
119 | int dir_indexing; /* handle directories */ | 119 | int dir_indexing; /* handle directories */ | |
120 | const char *dir_readme; /* include README footer in indexes */ | |||
120 | int hide_dots; /* hide .* */ | 121 | int hide_dots; /* hide .* */ | |
121 | int process_cgi; /* use the cgi handler */ | 122 | int process_cgi; /* use the cgi handler */ | |
122 | char *cgibin; /* cgi-bin directory */ | 123 | char *cgibin; /* cgi-bin directory */ | |
123 | unsigned ssl_timeout; /* ssl timeout */ | 124 | unsigned ssl_timeout; /* ssl timeout */ | |
124 | unsigned initial_timeout;/* first line timeout */ | 125 | unsigned initial_timeout;/* first line timeout */ | |
125 | unsigned header_timeout; /* header lines timeout */ | 126 | unsigned header_timeout; /* header lines timeout */ | |
126 | unsigned request_timeout;/* total session timeout */ | 127 | unsigned request_timeout;/* total session timeout */ | |
127 | #ifndef NO_LUA_SUPPORT | 128 | #ifndef NO_LUA_SUPPORT | |
128 | int process_lua; /* use the Lua handler */ | 129 | int process_lua; /* use the Lua handler */ | |
129 | SIMPLEQ_HEAD(, lua_state_map) lua_states; | 130 | SIMPLEQ_HEAD(, lua_state_map) lua_states; | |
130 | #endif | 131 | #endif | |
131 | void *sslinfo; /* pointer to ssl struct */ | 132 | void *sslinfo; /* pointer to ssl struct */ | |
132 | int dynamic_content_map_size;/* size of dyn cont map */ | 133 | int dynamic_content_map_size;/* size of dyn cont map */ |
--- src/libexec/httpd/dir-index-bozo.c 2019/02/28 08:28:21 1.32
+++ src/libexec/httpd/dir-index-bozo.c 2020/07/06 23:31:36 1.33
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: dir-index-bozo.c,v 1.32 2019/02/28 08:28:21 mrg Exp $ */ | 1 | /* $NetBSD: dir-index-bozo.c,v 1.33 2020/07/06 23:31:36 jmcneill Exp $ */ | |
2 | 2 | |||
3 | /* $eterna: dir-index-bozo.c,v 1.20 2011/11/18 09:21:15 mrg Exp $ */ | 3 | /* $eterna: dir-index-bozo.c,v 1.20 2011/11/18 09:21:15 mrg Exp $ */ | |
4 | 4 | |||
5 | /* | 5 | /* | |
6 | * Copyright (c) 1997-2019 Matthew R. Green | 6 | * Copyright (c) 1997-2019 Matthew R. Green | |
7 | * All rights reserved. | 7 | * All rights reserved. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright | |
@@ -28,46 +28,49 @@ | @@ -28,46 +28,49 @@ | |||
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. | |
30 | * | 30 | * | |
31 | */ | 31 | */ | |
32 | 32 | |||
33 | /* this code implements directory index generation for bozohttpd */ | 33 | /* this code implements directory index generation for bozohttpd */ | |
34 | 34 | |||
35 | #ifndef NO_DIRINDEX_SUPPORT | 35 | #ifndef NO_DIRINDEX_SUPPORT | |
36 | 36 | |||
37 | #include <sys/param.h> | 37 | #include <sys/param.h> | |
38 | 38 | |||
39 | #include <dirent.h> | 39 | #include <dirent.h> | |
40 | #include <errno.h> | 40 | #include <errno.h> | |
41 | #include <fcntl.h> | |||
41 | #include <string.h> | 42 | #include <string.h> | |
42 | #include <stdlib.h> | 43 | #include <stdlib.h> | |
43 | #include <time.h> | 44 | #include <time.h> | |
45 | #include <unistd.h> | |||
44 | #include <assert.h> | 46 | #include <assert.h> | |
45 | 47 | |||
46 | #include "bozohttpd.h" | 48 | #include "bozohttpd.h" | |
47 | 49 | |||
48 | /* | 50 | /* | |
49 | * output a directory index. return 1 if it actually did something.. | 51 | * output a directory index. return 1 if it actually did something.. | |
50 | */ | 52 | */ | |
51 | int | 53 | int | |
52 | bozo_dir_index(bozo_httpreq_t *request, const char *dirpath, int isindex) | 54 | bozo_dir_index(bozo_httpreq_t *request, const char *dirpath, int isindex) | |
53 | { | 55 | { | |
54 | bozohttpd_t *httpd = request->hr_httpd; | 56 | bozohttpd_t *httpd = request->hr_httpd; | |
55 | struct stat sb; | 57 | struct stat sb; | |
56 | struct dirent **de, **deo; | 58 | struct dirent **de, **deo; | |
57 | DIR *dp; | 59 | DIR *dp; | |
58 | char buf[MAXPATHLEN]; | 60 | char buf[MAXPATHLEN]; | |
59 | char *file = NULL, *printname = NULL, *p; | 61 | char *file = NULL, *printname = NULL, *p; | |
60 | int k, j; | 62 | int k, j, fd; | |
63 | ssize_t rlen; | |||
61 | 64 | |||
62 | if (!isindex || !httpd->dir_indexing) | 65 | if (!isindex || !httpd->dir_indexing) | |
63 | return 0; | 66 | return 0; | |
64 | 67 | |||
65 | if (strlen(dirpath) <= strlen(httpd->index_html)) | 68 | if (strlen(dirpath) <= strlen(httpd->index_html)) | |
66 | dirpath = "."; | 69 | dirpath = "."; | |
67 | else { | 70 | else { | |
68 | file = bozostrdup(httpd, request, dirpath); | 71 | file = bozostrdup(httpd, request, dirpath); | |
69 | 72 | |||
70 | file[strlen(file) - strlen(httpd->index_html)] = '\0'; | 73 | file[strlen(file) - strlen(httpd->index_html)] = '\0'; | |
71 | dirpath = file; | 74 | dirpath = file; | |
72 | } | 75 | } | |
73 | debug((httpd, DEBUG_FAT, "bozo_dir_index: dirpath '%s'", dirpath)); | 76 | debug((httpd, DEBUG_FAT, "bozo_dir_index: dirpath '%s'", dirpath)); | |
@@ -187,22 +190,39 @@ bozo_dir_index(bozo_httpreq_t *request, | @@ -187,22 +190,39 @@ bozo_dir_index(bozo_httpreq_t *request, | |||
187 | bozo_printf(httpd, "<td>%s", buf); | 190 | bozo_printf(httpd, "<td>%s", buf); | |
188 | 191 | |||
189 | len = ((unsigned long long)sb.st_size + 1023) / 1024; | 192 | len = ((unsigned long long)sb.st_size + 1023) / 1024; | |
190 | bozo_printf(httpd, "<td align=right>%llukB", len); | 193 | bozo_printf(httpd, "<td align=right>%llukB", len); | |
191 | } | 194 | } | |
192 | bozo_printf(httpd, "\r\n"); | 195 | bozo_printf(httpd, "\r\n"); | |
193 | } | 196 | } | |
194 | 197 | |||
195 | closedir(dp); | 198 | closedir(dp); | |
196 | while (k--) | 199 | while (k--) | |
197 | free(deo[k]); | 200 | free(deo[k]); | |
198 | free(deo); | 201 | free(deo); | |
199 | bozo_printf(httpd, "</table>\r\n"); | 202 | bozo_printf(httpd, "</table>\r\n"); | |
203 | if (httpd->dir_readme != NULL) { | |||
204 | if (httpd->dir_readme[0] == '/') | |||
205 | snprintf(buf, sizeof buf, "%s", httpd->dir_readme); | |||
206 | else | |||
207 | snprintf(buf, sizeof buf, "%s/%s", dirpath, httpd->dir_readme); | |||
208 | fd = open(buf, O_RDONLY); | |||
209 | if (fd != -1) { | |||
210 | bozo_flush(httpd, stdout); | |||
211 | do { | |||
212 | rlen = read(fd, buf, sizeof buf); | |||
213 | if (rlen <= 0) | |||
214 | break; | |||
215 | bozo_write(httpd, STDOUT_FILENO, buf, rlen); | |||
216 | } while (1); | |||
217 | close(fd); | |||
218 | } | |||
219 | } | |||
200 | bozo_printf(httpd, "</body></html>\r\n\r\n"); | 220 | bozo_printf(httpd, "</body></html>\r\n\r\n"); | |
201 | bozo_flush(httpd, stdout); | 221 | bozo_flush(httpd, stdout); | |
202 | 222 | |||
203 | done: | 223 | done: | |
204 | free(file); | 224 | free(file); | |
205 | free(printname); | 225 | free(printname); | |
206 | return 1; | 226 | return 1; | |
207 | } | 227 | } | |
208 | #endif /* NO_DIRINDEX_SUPPORT */ | 228 | #endif /* NO_DIRINDEX_SUPPORT */ |
--- src/libexec/httpd/main.c 2018/11/25 07:37:20 1.22
+++ src/libexec/httpd/main.c 2020/07/06 23:31:36 1.23
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: main.c,v 1.22 2018/11/25 07:37:20 mrg Exp $ */ | 1 | /* $NetBSD: main.c,v 1.23 2020/07/06 23:31:36 jmcneill Exp $ */ | |
2 | 2 | |||
3 | /* $eterna: main.c,v 1.6 2011/11/18 09:21:15 mrg Exp $ */ | 3 | /* $eterna: main.c,v 1.6 2011/11/18 09:21:15 mrg Exp $ */ | |
4 | /* from: eterna: bozohttpd.c,v 1.159 2009/05/23 02:14:30 mrg Exp */ | 4 | /* from: eterna: bozohttpd.c,v 1.159 2009/05/23 02:14:30 mrg Exp */ | |
5 | 5 | |||
6 | /* | 6 | /* | |
7 | * Copyright (c) 1997-2018 Matthew R. Green | 7 | * Copyright (c) 1997-2018 Matthew R. Green | |
8 | * All rights reserved. | 8 | * All rights reserved. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -150,27 +150,27 @@ main(int argc, char **argv) | @@ -150,27 +150,27 @@ main(int argc, char **argv) | |||
150 | progname = argv[0]; | 150 | progname = argv[0]; | |
151 | else | 151 | else | |
152 | progname++; | 152 | progname++; | |
153 | 153 | |||
154 | openlog(progname, LOG_PID|LOG_NDELAY, LOG_FTP); | 154 | openlog(progname, LOG_PID|LOG_NDELAY, LOG_FTP); | |
155 | 155 | |||
156 | bozo_set_defaults(&httpd, &prefs); | 156 | bozo_set_defaults(&httpd, &prefs); | |
157 | 157 | |||
158 | /* | 158 | /* | |
159 | * -r option was removed, do not reuse it for a while | 159 | * -r option was removed, do not reuse it for a while | |
160 | */ | 160 | */ | |
161 | 161 | |||
162 | while ((c = getopt(argc, argv, | 162 | while ((c = getopt(argc, argv, | |
163 | "C:EGHI:L:M:P:S:T:U:VXZ:bc:defhi:np:st:uv:x:z:")) != -1) { | 163 | "C:EGHI:L:M:P:R:S:T:U:VXZ:bc:defhi:np:st:uv:x:z:")) != -1) { | |
164 | switch (c) { | 164 | switch (c) { | |
165 | 165 | |||
166 | case 'b': | 166 | case 'b': | |
167 | if (!have_daemon_mode) | 167 | if (!have_daemon_mode) | |
168 | no_daemon_mode: | 168 | no_daemon_mode: | |
169 | bozoerr(&httpd, 1, "Daemon mode not enabled"); | 169 | bozoerr(&httpd, 1, "Daemon mode not enabled"); | |
170 | 170 | |||
171 | /* | 171 | /* | |
172 | * test suite support - undocumented | 172 | * test suite support - undocumented | |
173 | * background == 2 (aka, -b -b) means to | 173 | * background == 2 (aka, -b -b) means to | |
174 | * only process 1 per kid | 174 | * only process 1 per kid | |
175 | */ | 175 | */ | |
176 | val = bozo_get_pref(&prefs, "background") == NULL ? | 176 | val = bozo_get_pref(&prefs, "background") == NULL ? | |
@@ -289,26 +289,31 @@ main(int argc, char **argv) | @@ -289,26 +289,31 @@ main(int argc, char **argv) | |||
289 | goto no_daemon_mode; | 289 | goto no_daemon_mode; | |
290 | 290 | |||
291 | bozo_set_pref(&httpd, &prefs, "pid file", optarg); | 291 | bozo_set_pref(&httpd, &prefs, "pid file", optarg); | |
292 | break; | 292 | break; | |
293 | 293 | |||
294 | case 'p': | 294 | case 'p': | |
295 | if (!have_user) | 295 | if (!have_user) | |
296 | no_user_support: | 296 | no_user_support: | |
297 | bozoerr(&httpd, 1, "User support not enabled"); | 297 | bozoerr(&httpd, 1, "User support not enabled"); | |
298 | 298 | |||
299 | bozo_set_pref(&httpd, &prefs, "public_html", optarg); | 299 | bozo_set_pref(&httpd, &prefs, "public_html", optarg); | |
300 | break; | 300 | break; | |
301 | 301 | |||
302 | case 'R': | |||
303 | bozo_set_pref(&httpd, &prefs, "directory index readme", | |||
304 | optarg); | |||
305 | break; | |||
306 | ||||
302 | case 'S': | 307 | case 'S': | |
303 | bozo_set_pref(&httpd, &prefs, "server software", | 308 | bozo_set_pref(&httpd, &prefs, "server software", | |
304 | optarg); | 309 | optarg); | |
305 | break; | 310 | break; | |
306 | 311 | |||
307 | case 's': | 312 | case 's': | |
308 | bozo_set_pref(&httpd, &prefs, "log to stderr", "true"); | 313 | bozo_set_pref(&httpd, &prefs, "log to stderr", "true"); | |
309 | break; | 314 | break; | |
310 | 315 | |||
311 | case 'T': | 316 | case 'T': | |
312 | /* make sure there're two arguments */ | 317 | /* make sure there're two arguments */ | |
313 | if (argc - optind < 1) | 318 | if (argc - optind < 1) | |
314 | usage(&httpd, progname); | 319 | usage(&httpd, progname); |