Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mod_dav: add DavBasePath #377

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions docs/manual/mod/mod_dav.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,36 @@ Alias "/php-source" "/home/gstein/php_files"
</usage>
</directivesynopsis>

<directivesynopsis>
<name>DavBasePath</name>
<description>Configure repository root path</description>
<syntax>DavBasePath <var>root-path</var></syntax>
<default>None</default>
<contextlist><context>directory</context></contextlist>
<compatibility>Available in version 2.5.1 and later</compatibility>

<usage>
<p>If a DAV repository is configured using a regular expression
match (such as <directive module="core">LocationMatch</directive>)
then <module>mod_dav</module> will not be able to find the root of
the repository from the pathname alone. Third-party providers (for
example, Subversion's <a
href="https://svnbook.red-bean.com/en/1.7/svn.ref.mod_dav_svn.conf.html">mod_dav_svn</a>)
may fail to handle requests without the correct repository root.</p>

<p>To allow providers to work correctly in such a configuration,
<directive>DavBasePath</directive> must be used.</p>

<highlight language="config">
&lt;LocationMatch "^/repos/"&gt;
Dav svn
DavBasePath /repos
SVNParentPath /var/svn
&lt;/LocationMatch&gt;
</highlight>
</usage>
</directivesynopsis>

<directivesynopsis>
<name>DavMinTimeout</name>
<description>Minimum amount of time the server holds a lock on
Expand Down
38 changes: 36 additions & 2 deletions modules/dav/main/mod_dav.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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 */
Expand All @@ -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 *cdc = ap_get_core_module_config(r->per_dir_config);

notroj marked this conversation as resolved.
Show resolved Hide resolved
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?");
}
}

err = dav_push_error(r->pool, err->status, 0,
"Could not fetch resource information.", err);
return err;
Expand Down Expand Up @@ -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,
Expand Down
Loading