From cb4eb2940eaab5103d9055e2fe25e5a3e717a132 Mon Sep 17 00:00:00 2001 From: Joe Orton Date: Mon, 14 Aug 2023 14:40:00 +0000 Subject: [PATCH 1/4] Add DAVBasePath directive to allow users to configure the real repos root path, useful where the DAV repos is configured with a regex match. * modules/dav/main/mod_dav.c (dav_get_resource): If available, pass the configured base path as the repos root to repos provider. On the error path for fetching a resource, detect and warn specifically when the location is configured via a regex. (dav_cmd_davbasepath): New function. PR: 35077 Github: closes #376 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1911651 13f79535-47bb-0310-9956-ffa450edef68 (cherry picked from commit 82434376765dd81f47cbfcffe796903eca8805bc) --- modules/dav/main/mod_dav.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/modules/dav/main/mod_dav.c b/modules/dav/main/mod_dav.c index d16ab4a1b27..215127fa046 100644 --- a/modules/dav/main/mod_dav.c +++ b/modules/dav/main/mod_dav.c @@ -81,6 +81,7 @@ typedef struct { const char *provider_name; const dav_provider *provider; const char *dir; + const char *base; int locktimeout; int allow_depthinfinity; int allow_lockdiscovery; @@ -196,6 +197,7 @@ static void *dav_merge_dir_config(apr_pool_t *p, void *base, void *overrides) newconf->locktimeout = DAV_INHERIT_VALUE(parent, child, locktimeout); newconf->dir = DAV_INHERIT_VALUE(parent, child, dir); + newconf->base = DAV_INHERIT_VALUE(parent, child, base); newconf->allow_depthinfinity = DAV_INHERIT_VALUE(parent, child, allow_depthinfinity); newconf->allow_lockdiscovery = DAV_INHERIT_VALUE(parent, child, @@ -282,6 +284,18 @@ static const char *dav_cmd_dav(cmd_parms *cmd, void *config, const char *arg1) return NULL; } +/* + * Command handler for the DAVBasePath directive, which is TAKE1 + */ +static const char *dav_cmd_davbasepath(cmd_parms *cmd, void *config, const char *arg1) +{ + dav_dir_conf *conf = config; + + conf->base = arg1; + + return NULL; +} + /* * Command handler for the DAVDepthInfinity directive, which is FLAG. */ @@ -748,7 +762,7 @@ DAV_DECLARE(dav_error *) dav_get_resource(request_rec *r, int label_allowed, int use_checked_in, dav_resource **res_p) { dav_dir_conf *conf; - const char *label = NULL; + const char *label = NULL, *base; dav_error *err; /* if the request target can be overridden, get any target selector */ @@ -765,11 +779,27 @@ DAV_DECLARE(dav_error *) dav_get_resource(request_rec *r, int label_allowed, ap_escape_html(r->pool, r->uri))); } + /* Take the repos root from DAVBasePath if configured, else the + * path of the enclosing section. */ + base = conf->base ? conf->base : conf->dir; + /* resolve the resource */ - err = (*conf->provider->repos->get_resource)(r, conf->dir, + err = (*conf->provider->repos->get_resource)(r, base, label, use_checked_in, res_p); if (err != NULL) { + /* In the error path, give a hint that DavBasePath needs to be + * used if the location was configured via a regex match. */ + if (!conf->base) { + core_dir_config *conf = ap_get_core_module_config(r->per_dir_config); + + if (conf->r) { + ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, APLOGNO(10484) + "failed to find repository for location configured " + "via regex match - missing DAVBasePath?"); + } + } + err = dav_push_error(r->pool, err->status, 0, "Could not fetch resource information.", err); return err; @@ -5164,6 +5194,10 @@ static const command_rec dav_cmds[] = AP_INIT_TAKE1("DAV", dav_cmd_dav, NULL, ACCESS_CONF, "specify the DAV provider for a directory or location"), + /* per directory/location */ + AP_INIT_TAKE1("DAVBasePath", dav_cmd_davbasepath, NULL, ACCESS_CONF, + "specify the DAV repository base URL"), + /* per directory/location, or per server */ AP_INIT_TAKE1("DAVMinTimeout", dav_cmd_davmintimeout, NULL, ACCESS_CONF|RSRC_CONF, From f8ea180d1ecc5c795c558df12123ca39f2c93240 Mon Sep 17 00:00:00 2001 From: Joe Orton Date: Wed, 16 Aug 2023 07:33:45 +0000 Subject: [PATCH 2/4] Add docs for DavBasePath. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1911715 13f79535-47bb-0310-9956-ffa450edef68 (cherry picked from commit ed4cb1db3c7efd861bab87dfa84534b81582cb94) --- docs/manual/mod/mod_dav.xml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/manual/mod/mod_dav.xml b/docs/manual/mod/mod_dav.xml index c4eb0bb4dae..5e3cbf0507e 100644 --- a/docs/manual/mod/mod_dav.xml +++ b/docs/manual/mod/mod_dav.xml @@ -194,6 +194,36 @@ Alias "/php-source" "/home/gstein/php_files" + +DavBasePath +Configure repository root path +DavBasePath root-path +DavBasePath /repos/ +directory +Available in version 2.5.1 and later + + +

If a DAV repository is configured using a regular expression + match (such as LocationMatch) + then mod_dav will not be able to find the root of + the repository from the pathname alone. Third-party providers (for + example, Subversion's mod_dav_svn) + may fail to handle requests without the correct repository root.

+ +

To allow providers to work correctly in such a configuration, + DavBasePath must be used.

+ + +<LocationMatch "^/repos/"> + Dav svn + DavBasePath /repos + SVNParentPath /var/svn +</LocationMatch> + +
+
+ DavMinTimeout Minimum amount of time the server holds a lock on From 13dd94ff4b55d26af58ee5fff6f3e8e61cdd0531 Mon Sep 17 00:00:00 2001 From: Joe Orton Date: Fri, 25 Aug 2023 07:44:08 +0000 Subject: [PATCH 3/4] * modules/dav/main/mod_dav.c (dav_get_resource): Don't mask "conf" variable. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1911906 13f79535-47bb-0310-9956-ffa450edef68 (cherry picked from commit 706af916933612750c1cf8f165e23d37c9b865b2) --- modules/dav/main/mod_dav.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/dav/main/mod_dav.c b/modules/dav/main/mod_dav.c index 215127fa046..a035f254f4d 100644 --- a/modules/dav/main/mod_dav.c +++ b/modules/dav/main/mod_dav.c @@ -791,9 +791,9 @@ DAV_DECLARE(dav_error *) dav_get_resource(request_rec *r, int label_allowed, /* In the error path, give a hint that DavBasePath needs to be * used if the location was configured via a regex match. */ if (!conf->base) { - core_dir_config *conf = ap_get_core_module_config(r->per_dir_config); + core_dir_config *cdc = ap_get_core_module_config(r->per_dir_config); - if (conf->r) { + if (cdc->r) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, APLOGNO(10484) "failed to find repository for location configured " "via regex match - missing DAVBasePath?"); From 53fd751b7478c7bdb1e7e5a598c91b940ded6b6f Mon Sep 17 00:00:00 2001 From: Joe Orton Date: Fri, 25 Aug 2023 07:46:53 +0000 Subject: [PATCH 4/4] Fix documented default for DavBasePath to match code. Submitted by: rpluem Github: pull #377 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1911907 13f79535-47bb-0310-9956-ffa450edef68 (cherry picked from commit 59c725adeb25dc97b8ebad4a4c24627dca6ccf50) --- docs/manual/mod/mod_dav.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/manual/mod/mod_dav.xml b/docs/manual/mod/mod_dav.xml index 5e3cbf0507e..cac5c9cf880 100644 --- a/docs/manual/mod/mod_dav.xml +++ b/docs/manual/mod/mod_dav.xml @@ -198,7 +198,7 @@ Alias "/php-source" "/home/gstein/php_files" DavBasePath Configure repository root path DavBasePath root-path -DavBasePath /repos/ +None directory Available in version 2.5.1 and later