-
-
Save Ranguvar/7fdec9c8f0a55edad4cdabb4c5c59f79 to your computer and use it in GitHub Desktop.
OpenBSD httpd errordocs patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: httpd.conf.5 | |
=================================================================== | |
RCS file: /cvs/src/usr.sbin/httpd/httpd.conf.5,v | |
retrieving revision 1.101 | |
diff -u -p -u -r1.101 httpd.conf.5 | |
--- httpd.conf.5 20 Jun 2018 16:43:05 -0000 1.101 | |
+++ httpd.conf.5 23 Oct 2018 19:54:11 -0000 | |
@@ -128,6 +128,9 @@ If not specified, it defaults to | |
within the | |
.Xr chroot 2 | |
directory. | |
+.It Ic errordocs Ar directory | |
+Specifies the full path in the chroot of the directory where custom error | |
+documents are held. The filenames are named like 404.html, ... | |
.It Ic prefork Ar number | |
Run the specified number of server processes. | |
This increases the performance and prevents delays when connecting | |
Index: httpd.h | |
=================================================================== | |
RCS file: /cvs/src/usr.sbin/httpd/httpd.h,v | |
retrieving revision 1.142 | |
diff -u -p -u -r1.142 httpd.h | |
--- httpd.h 11 Oct 2018 09:52:22 -0000 1.142 | |
+++ httpd.h 23 Oct 2018 19:54:11 -0000 | |
@@ -581,6 +581,7 @@ struct httpd { | |
int sc_paused; | |
char *sc_chroot; | |
char *sc_logdir; | |
+ char *sc_errordocs; | |
uint8_t sc_tls_sid[TLS_MAX_SESSION_ID_LENGTH]; | |
Index: parse.y | |
=================================================================== | |
RCS file: /cvs/src/usr.sbin/httpd/parse.y,v | |
retrieving revision 1.106 | |
diff -u -p -u -r1.106 parse.y | |
--- parse.y 7 Sep 2018 07:35:30 -0000 1.106 | |
+++ parse.y 23 Oct 2018 19:54:11 -0000 | |
@@ -139,7 +139,7 @@ typedef struct { | |
%token LISTEN LOCATION LOG LOGDIR MATCH MAXIMUM NO NODELAY OCSP ON PORT PREFORK | |
%token PROTOCOLS REQUESTS ROOT SACK SERVER SOCKET STRIP STYLE SYSLOG TCP TICKET | |
%token TIMEOUT TLS TYPE TYPES HSTS MAXAGE SUBDOMAINS DEFAULT PRELOAD REQUEST | |
-%token ERROR INCLUDE AUTHENTICATE WITH BLOCK DROP RETURN PASS REWRITE | |
+%token ERROR INCLUDE AUTHENTICATE WITH BLOCK DROP RETURN PASS REWRITE ERRORDOCS | |
%token CA CLIENT CRL OPTIONAL | |
%token <v.string> STRING | |
%token <v.number> NUMBER | |
@@ -214,6 +214,9 @@ main : PREFORK NUMBER { | |
| LOGDIR STRING { | |
conf->sc_logdir = $2; | |
} | |
+ | ERRORDOCS STRING { | |
+ conf->sc_errordocs = $2; | |
+ } | |
| DEFAULT TYPE mediastring { | |
memcpy(&conf->sc_default_type, &media, | |
sizeof(struct media_type)); | |
@@ -1266,6 +1269,7 @@ lookup(char *s) | |
{ "drop", DROP }, | |
{ "ecdhe", ECDHE }, | |
{ "error", ERR }, | |
+ { "errordocs", ERRORDOCS }, | |
{ "fastcgi", FCGI }, | |
{ "hsts", HSTS }, | |
{ "include", INCLUDE }, | |
Index: server_http.c | |
=================================================================== | |
RCS file: /cvs/src/usr.sbin/httpd/server_http.c,v | |
retrieving revision 1.125 | |
diff -u -p -u -r1.125 server_http.c | |
--- server_http.c 11 Oct 2018 09:52:22 -0000 1.125 | |
+++ server_http.c 23 Oct 2018 19:54:11 -0000 | |
@@ -850,6 +850,8 @@ server_abort_http(struct client *clt, un | |
char buf[IBUF_READ_SIZE]; | |
char *escapedmsg = NULL; | |
int bodylen; | |
+ char *errordoc_name; | |
+ FILE *errordoc_fd; | |
if (code == 0) { | |
server_close(clt, "dropped"); | |
@@ -925,29 +927,69 @@ server_abort_http(struct client *clt, un | |
free(escapedmsg); | |
- /* A CSS stylesheet allows minimal customization by the user */ | |
- style = "body { background-color: white; color: black; font-family: " | |
- "'Comic Sans MS', 'Chalkboard SE', 'Comic Neue', sans-serif; }\n" | |
- "hr { border: 0; border-bottom: 1px dashed; }\n"; | |
- | |
- /* Generate simple HTML error document */ | |
- if ((bodylen = asprintf(&body, | |
- "<!DOCTYPE html>\n" | |
- "<html>\n" | |
- "<head>\n" | |
- "<meta http-equiv=\"Content-Type\" content=\"text/html; " | |
- "charset=utf-8\"/>\n" | |
- "<title>%03d %s</title>\n" | |
- "<style type=\"text/css\"><!--\n%s\n--></style>\n" | |
- "</head>\n" | |
- "<body>\n" | |
- "<h1>%03d %s</h1>\n" | |
- "<hr>\n<address>%s</address>\n" | |
- "</body>\n" | |
- "</html>\n", | |
- code, httperr, style, code, httperr, HTTPD_SERVERNAME)) == -1) { | |
- body = NULL; | |
- goto done; | |
+ if (httpd_env->sc_errordocs != NULL) { | |
+ errordoc_name = malloc(strlen(httpd_env->sc_errordocs + 10)); // 10 = /xxx.html\0 | |
+ asprintf(&errordoc_name, "%s/%d.html", httpd_env->sc_errordocs, code); | |
+ } | |
+ | |
+ if (httpd_env->sc_errordocs != NULL && access(errordoc_name, F_OK) != -1) { | |
+ errordoc_fd = fopen(errordoc_name, "r"); | |
+ if (! errordoc_fd) { | |
+ log_debug("Error file exists but can't be read."); | |
+ body = NULL; | |
+ goto done; | |
+ } | |
+ | |
+ fseek(errordoc_fd, 0L, SEEK_END); | |
+ bodylen = ftell(errordoc_fd); | |
+ rewind(errordoc_fd); | |
+ | |
+ /* allocate memory for the entire error document */ | |
+ body = malloc(bodylen + 1); | |
+ if (! body) { | |
+ log_debug("Can't allocate memory for error document."); | |
+ fclose(errordoc_fd); | |
+ bodylen = 0; | |
+ body = NULL; | |
+ goto done; | |
+ } | |
+ | |
+ /* copy the error document into the buffer */ | |
+ if (fread(body, bodylen, 1, errordoc_fd) != 1) { | |
+ log_debug("Cannot copy the error document into the buffer."); | |
+ fclose(errordoc_fd); | |
+ bodylen = 0; | |
+ body = NULL; | |
+ goto done; | |
+ } | |
+ body[bodylen] = 0; | |
+ | |
+ fclose(errordoc_fd); | |
+ } else { | |
+ /* A CSS stylesheet allows minimal customization by the user */ | |
+ style = "body { background-color: white; color: black; font-family: " | |
+ "'Comic Sans MS', 'Chalkboard SE', 'Comic Neue', sans-serif; }\n" | |
+ "hr { border: 0; border-bottom: 1px dashed; }\n"; | |
+ | |
+ /* Generate simple HTML error document */ | |
+ if ((bodylen = asprintf(&body, | |
+ "<!DOCTYPE html>\n" | |
+ "<html>\n" | |
+ "<head>\n" | |
+ "<meta http-equiv=\"Content-Type\" content=\"text/html; " | |
+ "charset=utf-8\"/>\n" | |
+ "<title>%03d %s</title>\n" | |
+ "<style type=\"text/css\"><!--\n%s\n--></style>\n" | |
+ "</head>\n" | |
+ "<body>\n" | |
+ "<h1>%03d %s</h1>\n" | |
+ "<hr>\n<address>%s</address>\n" | |
+ "</body>\n" | |
+ "</html>\n", | |
+ code, httperr, style, code, httperr, HTTPD_SERVERNAME)) == -1) { | |
+ body = NULL; | |
+ goto done; | |
+ } | |
} | |
if (srv_conf->flags & SRVFLAG_SERVER_HSTS) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not working for me on 6.4, may be patch issue or something else.