From 96e6e98307b81f44363819f6e18227b2fb374b5e Mon Sep 17 00:00:00 2001 From: reyk Date: Fri, 29 Jul 2016 10:00:12 +0000 Subject: [PATCH] Add support for common WebDAV methods; from httpd. Found and tested by Michael Lechtermann OK benno@ --- usr.sbin/relayd/http.h | 58 ++++++++++++++++++++++++++++++++--- usr.sbin/relayd/relay_http.c | 29 ++++++++++++++++-- usr.sbin/relayd/relayd.conf.5 | 22 +++++++++++-- 3 files changed, 100 insertions(+), 9 deletions(-) diff --git a/usr.sbin/relayd/http.h b/usr.sbin/relayd/http.h index a043e20acbe..1d38631310c 100644 --- a/usr.sbin/relayd/http.h +++ b/usr.sbin/relayd/http.h @@ -1,7 +1,7 @@ -/* $OpenBSD: http.h,v 1.7 2015/06/11 18:49:09 reyk Exp $ */ +/* $OpenBSD: http.h,v 1.8 2016/07/29 10:00:12 reyk Exp $ */ /* - * Copyright (c) 2012 - 2014 Reyk Floeter + * Copyright (c) 2012 - 2015 Reyk Floeter * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -44,6 +44,32 @@ enum httpmethod { HTTP_METHOD_LOCK, HTTP_METHOD_UNLOCK, + /* WebDAV Versioning Extension, RFC 3253 */ + HTTP_METHOD_VERSION_CONTROL, + HTTP_METHOD_REPORT, + HTTP_METHOD_CHECKOUT, + HTTP_METHOD_CHECKIN, + HTTP_METHOD_UNCHECKOUT, + HTTP_METHOD_MKWORKSPACE, + HTTP_METHOD_UPDATE, + HTTP_METHOD_LABEL, + HTTP_METHOD_MERGE, + HTTP_METHOD_BASELINE_CONTROL, + HTTP_METHOD_MKACTIVITY, + + /* WebDAV Ordered Collections, RFC 3648 */ + HTTP_METHOD_ORDERPATCH, + + /* WebDAV Access Control, RFC 3744 */ + HTTP_METHOD_ACL, + + /* WebDAV Redirect Reference Resources, RFC 4437 */ + HTTP_METHOD_MKREDIRECTREF, + HTTP_METHOD_UPDATEREDIRECTREF, + + /* WebDAV Search, RFC 5323 */ + HTTP_METHOD_SEARCH, + /* PATCH, RFC 5789 */ HTTP_METHOD_PATCH, @@ -71,6 +97,22 @@ struct http_method { { HTTP_METHOD_MOVE, "MOVE" }, \ { HTTP_METHOD_LOCK, "LOCK" }, \ { HTTP_METHOD_UNLOCK, "UNLOCK" }, \ + { HTTP_METHOD_VERSION_CONTROL, "VERSION-CONTROL" }, \ + { HTTP_METHOD_REPORT, "REPORT" }, \ + { HTTP_METHOD_CHECKOUT, "CHECKOUT" }, \ + { HTTP_METHOD_CHECKIN, "CHECKIN" }, \ + { HTTP_METHOD_UNCHECKOUT, "UNCHECKOUT" }, \ + { HTTP_METHOD_MKWORKSPACE, "MKWORKSPACE" }, \ + { HTTP_METHOD_UPDATE, "UPDATE" }, \ + { HTTP_METHOD_LABEL, "LABEL" }, \ + { HTTP_METHOD_MERGE, "MERGE" }, \ + { HTTP_METHOD_BASELINE_CONTROL, "BASELINE-CONTROL" }, \ + { HTTP_METHOD_MKACTIVITY, "MKACTIVITY" }, \ + { HTTP_METHOD_ORDERPATCH, "ORDERPATCH" }, \ + { HTTP_METHOD_ACL, "ACL" }, \ + { HTTP_METHOD_MKREDIRECTREF, "MKREDIRECTREF" }, \ + { HTTP_METHOD_UPDATEREDIRECTREF, "UPDATEREDIRECTREF" }, \ + { HTTP_METHOD_SEARCH, "SEARCH" }, \ { HTTP_METHOD_PATCH, "PATCH" }, \ { HTTP_METHOD_NONE, NULL } \ } @@ -130,7 +172,8 @@ struct http_error { { 415, "Unsupported Media Type" }, \ { 416, "Range Not Satisfiable" }, \ { 417, "Expectation Failed" }, \ - /* 418-421 unassigned */ \ + { 418, "I'm a teapot" }, \ + /* 419-421 unassigned */ \ { 420, "Enhance Your Calm" }, \ { 422, "Unprocessable Entity" }, \ { 423, "Locked" }, \ @@ -142,7 +185,9 @@ struct http_error { { 429, "Too Many Requests" }, \ /* 430 unassigned */ \ { 431, "Request Header Fields Too Large" }, \ - /* 432-499 unassigned */ \ + /* 432-450 unassigned */ \ + { 451, "Unavailable For Legal Reasons" }, \ + /* 452-499 unassigned */ \ { 500, "Internal Server Error" }, \ { 501, "Not Implemented" }, \ { 502, "Bad Gateway" }, \ @@ -176,6 +221,7 @@ struct http_mediatype { { "jpeg", "image", "jpeg" }, \ { "jpg", "image", "jpeg" }, \ { "png", "image", "png" }, \ + { "svg", "image", "svg+xml" }, \ { "js", "application", "javascript" }, \ { NULL } \ } @@ -191,10 +237,14 @@ struct http_descriptor { #define query_key http_matchquery.kv_key #define query_val http_matchquery.kv_value + char *http_host; enum httpmethod http_method; int http_chunked; char *http_version; + /* Rewritten path remains NULL if not used */ + char *http_path_alias; + /* A tree of headers and attached lists for repeated headers. */ struct kv *http_lastheader; struct kvtree http_headers; diff --git a/usr.sbin/relayd/relay_http.c b/usr.sbin/relayd/relay_http.c index c933f992f35..510f7a2a418 100644 --- a/usr.sbin/relayd/relay_http.c +++ b/usr.sbin/relayd/relay_http.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relay_http.c,v 1.58 2016/07/27 11:02:41 reyk Exp $ */ +/* $OpenBSD: relay_http.c,v 1.59 2016/07/29 10:00:12 reyk Exp $ */ /* * Copyright (c) 2006 - 2015 Reyk Floeter @@ -401,13 +401,38 @@ relay_read_http(struct bufferevent *bev, void *arg) case HTTP_METHOD_DELETE: case HTTP_METHOD_GET: case HTTP_METHOD_HEAD: + /* WebDAV methods */ + case HTTP_METHOD_COPY: + case HTTP_METHOD_MOVE: cre->toread = 0; break; case HTTP_METHOD_OPTIONS: - case HTTP_METHOD_PATCH: case HTTP_METHOD_POST: case HTTP_METHOD_PUT: case HTTP_METHOD_RESPONSE: + /* WebDAV methods */ + case HTTP_METHOD_PROPFIND: + case HTTP_METHOD_PROPPATCH: + case HTTP_METHOD_MKCOL: + case HTTP_METHOD_LOCK: + case HTTP_METHOD_UNLOCK: + case HTTP_METHOD_VERSION_CONTROL: + case HTTP_METHOD_REPORT: + case HTTP_METHOD_CHECKOUT: + case HTTP_METHOD_CHECKIN: + case HTTP_METHOD_UNCHECKOUT: + case HTTP_METHOD_MKWORKSPACE: + case HTTP_METHOD_UPDATE: + case HTTP_METHOD_LABEL: + case HTTP_METHOD_MERGE: + case HTTP_METHOD_BASELINE_CONTROL: + case HTTP_METHOD_MKACTIVITY: + case HTTP_METHOD_ORDERPATCH: + case HTTP_METHOD_ACL: + case HTTP_METHOD_MKREDIRECTREF: + case HTTP_METHOD_UPDATEREDIRECTREF: + case HTTP_METHOD_SEARCH: + case HTTP_METHOD_PATCH: /* HTTP request payload */ if (cre->toread > 0) bev->readcb = relay_read_httpcontent; diff --git a/usr.sbin/relayd/relayd.conf.5 b/usr.sbin/relayd/relayd.conf.5 index 915f29a2124..fbe4f2a4f78 100644 --- a/usr.sbin/relayd/relayd.conf.5 +++ b/usr.sbin/relayd/relayd.conf.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: relayd.conf.5,v 1.168 2015/11/06 18:06:29 bentley Exp $ +.\" $OpenBSD: relayd.conf.5,v 1.169 2016/07/29 10:00:12 reyk Exp $ .\" .\" Copyright (c) 2006 - 2015 Reyk Floeter .\" Copyright (c) 2006, 2007 Pierre-Yves Ritschard @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: November 6 2015 $ +.Dd $Mdocdate: July 29 2016 $ .Dt RELAYD.CONF 5 .Os .Sh NAME @@ -1125,23 +1125,39 @@ Match the HTTP request method. The method is specified by .Ar name and can be either +.Ic ACL , +.Ic BASELINE-CONTROL , +.Ic CHECKIN , +.Ic CHECKOUT , .Ic CONNECT , .Ic COPY , .Ic DELETE , .Ic GET , .Ic HEAD , +.Ic LABEL , .Ic LOCK , +.Ic MERGE , +.Ic MKACTIVITY , .Ic MKCOL , +.Ic MKREDIRECTREF , +.Ic MKWORKSPACE , .Ic MOVE , .Ic OPTIONS , +.Ic ORDERPATCH , .Ic PATCH , .Ic POST , .Ic PROPFIND , .Ic PROPPATCH , .Ic PUT , +.Ic REPORT , +.Ic SEARCH , .Ic TRACE , +.Ic UNCHECKOUT , +.Ic UNLOCK , +.Ic UPDATE , +.Ic UPDATEREDIRECTREF , or -.Ic UNLOCK . +.Ic VERSION-CONTROL . .It Xo .Ar type Ar option .Oo Oo Ic digest Oc -- 2.20.1