Skip to content

Commit

Permalink
mod_dav_fs: add DAVLockDBType directive.
Browse files Browse the repository at this point in the history
* modules/dav/fs/dbm.c (dav_dbm_open_direct): Take a dbmtype argument
  and use it to select the apr_dbm driver type.
  (dav_dbm_open): Continue to use the "default" propdb type to open
  the property databases.

* modules/dav/fs/lock.c: Store and pass through the lockdb_type
  through.

* modules/dav/fs/mod_dav_fs.c (dav_get_lockdb_path): Return the dbm
  type via an output argument.
  (dav_fs_cmd_davlockdbtype): New config directive.
  (dav_fs_merge_server_config): Merge the dbm type.
  (dav_fs_post_config): Set the default lockdb type.

* modules/dav/fs/repos.h: Update prototypes as above; internal API
  only so no compat concerns.

Github: closes apache#386


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1912718 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
notroj committed Oct 3, 2023
1 parent 7faee2a commit afcdbee
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 20 deletions.
1 change: 1 addition & 0 deletions changes-entries/davlockdbtype.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*) mod_dav_fs: Add DavLockDBType directive. [Joe Orton]
26 changes: 22 additions & 4 deletions docs/manual/mod/mod_dav_fs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@

<usage>
<p>Use the <directive>DavLockDB</directive> directive to specify
the full path to the lock database, excluding an extension. If
the path is not absolute, it will be taken relative to <directive
the full path to the lock database, excluding an extension. If the
path is not absolute, it will be taken relative to <directive
module="core">ServerRoot</directive>. The implementation of
<module>mod_dav_fs</module> uses a SDBM database to track user
locks.</p>
<module>mod_dav_fs</module> uses a database to track user
locks. The type of database file can be changed using
<directive module="mod_dav_fs">DavLockDBType</directive>.</p>

<!-- XXX: someone should add that tool to the support directory...
The utility <code>modules/dav/util/lockview</code> can be used from
Expand Down Expand Up @@ -95,6 +96,23 @@
</usage>
</directivesynopsis>

<directivesynopsis>
<name>DavLockDBType</name>
<description>Database type of the DAV lock database</description>
<syntax>DavLockDBType <var>dbm-type</var></syntax>
<contextlist><context>server config</context><context>virtual host</context>
</contextlist>
<default>DavLockDBType default</default>
<compatibility>Available in version 2.5.1 and later.</compatibility>
<usage>
<p>Use the <directive>DavLockDBType</directive> directive to
specify the type of the database file. If the directive is not
used, the <code>apr_dbm</code> hard-coded default database type is
used, which is equivalent to using <code>DavLockDBType default</code>.</p>

</usage>
</directivesynopsis>

<directivesynopsis>
<name>DavLockDiscovery</name>
<description>Enable lock discovery</description>
Expand Down
22 changes: 13 additions & 9 deletions modules/dav/fs/dbm.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
#include "http_log.h"
#include "http_main.h" /* for ap_server_conf */

#ifndef DEFAULT_PROPDB_DBM_TYPE
#define DEFAULT_PROPDB_DBM_TYPE "default"
#endif

APLOG_USE_MODULE(dav_fs);

struct dav_db {
Expand Down Expand Up @@ -129,8 +133,8 @@ void dav_fs_ensure_state_dir(apr_pool_t * p, const char *dirname)
/* dav_dbm_open_direct: Opens a *dbm database specified by path.
* ro = boolean read-only flag.
*/
dav_error * dav_dbm_open_direct(apr_pool_t *p, const char *pathname, int ro,
dav_db **pdb)
dav_error * dav_dbm_open_direct(apr_pool_t *p, const char *pathname,
const char *dbmtype, int ro, dav_db **pdb)
{
#if APR_MAJOR_VERSION > 1 || (APU_MAJOR_VERSION == 1 && APU_MINOR_VERSION >= 7)
const apr_dbm_driver_t *driver;
Expand All @@ -142,10 +146,10 @@ dav_error * dav_dbm_open_direct(apr_pool_t *p, const char *pathname, int ro,
*pdb = NULL;

#if APR_MAJOR_VERSION > 1 || (APU_MAJOR_VERSION == 1 && APU_MINOR_VERSION >= 7)
if ((status = apr_dbm_get_driver(&driver, NULL, &err, p)) != APR_SUCCESS) {
if ((status = apr_dbm_get_driver(&driver, dbmtype, &err, p)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, status, ap_server_conf, APLOGNO(10289)
"mod_dav_fs: The DBM library '%s' could not be loaded: %s",
err->reason, err->msg);
"mod_dav_fs: The DBM library '%s' for '%s' could not be loaded: %s",
err->reason, dbmtype, err->msg);
return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 1, status,
"Could not load library for database.");
}
Expand All @@ -156,9 +160,9 @@ dav_error * dav_dbm_open_direct(apr_pool_t *p, const char *pathname, int ro,
return dav_fs_dbm_error(NULL, p, status);
}
#else
if ((status = apr_dbm_open(&file, pathname,
ro ? APR_DBM_READONLY : APR_DBM_RWCREATE,
APR_OS_DEFAULT, p))
if ((status = apr_dbm_open_ex(&file, dbmtype, pathname,
ro ? APR_DBM_READONLY : APR_DBM_RWCREATE,
APR_OS_DEFAULT, p))
!= APR_SUCCESS
&& !ro) {
/* ### do something with 'status' */
Expand Down Expand Up @@ -206,7 +210,7 @@ static dav_error * dav_dbm_open(apr_pool_t * p, const dav_resource *resource,

/* ### do we need to deal with the umask? */

return dav_dbm_open_direct(p, pathname, ro, pdb);
return dav_dbm_open_direct(p, pathname, DEFAULT_PROPDB_DBM_TYPE, ro, pdb);
}

void dav_dbm_close(dav_db *db)
Expand Down
4 changes: 3 additions & 1 deletion modules/dav/fs/lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ struct dav_lockdb_private
request_rec *r; /* for accessing the uuid state */
apr_pool_t *pool; /* a pool to use */
const char *lockdb_path; /* where is the lock database? */
const char *lockdb_type; /* where is the lock database? */

int opened; /* we opened the database */
dav_db *db; /* if non-NULL, the lock database */
Expand Down Expand Up @@ -306,6 +307,7 @@ static dav_error * dav_fs_really_open_lockdb(dav_lockdb *lockdb)

err = dav_dbm_open_direct(lockdb->info->pool,
lockdb->info->lockdb_path,
lockdb->info->lockdb_type,
lockdb->ro,
&lockdb->info->db);
if (err != NULL) {
Expand Down Expand Up @@ -342,7 +344,7 @@ static dav_error * dav_fs_open_lockdb(request_rec *r, int ro, int force,
comb->priv.r = r;
comb->priv.pool = r->pool;

comb->priv.lockdb_path = dav_get_lockdb_path(r);
comb->priv.lockdb_path = dav_get_lockdb_path(r, &comb->priv.lockdb_type);
if (comb->priv.lockdb_path == NULL) {
return dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR,
DAV_ERR_LOCK_NO_DB, 0,
Expand Down
31 changes: 29 additions & 2 deletions modules/dav/fs/mod_dav_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,27 @@ typedef struct {
/* per-server configuration */
typedef struct {
const char *lockdb_path;

const char *lockdb_type;
} dav_fs_server_conf;

extern module AP_MODULE_DECLARE_DATA dav_fs_module;

#ifndef DEFAULT_DAV_LOCKDB
#define DEFAULT_DAV_LOCKDB "davlockdb"
#endif
#ifndef DEFAULT_DAV_LOCKDB_TYPE
#define DEFAULT_DAV_LOCKDB_TYPE "default"
#endif

const char *dav_get_lockdb_path(const request_rec *r)

const char *dav_get_lockdb_path(const request_rec *r, const char **dbmtype)
{
dav_fs_server_conf *conf;

conf = ap_get_module_config(r->server->module_config, &dav_fs_module);

*dbmtype = conf->lockdb_type;

return conf->lockdb_path;
}

Expand Down Expand Up @@ -119,6 +126,8 @@ static void *dav_fs_merge_server_config(apr_pool_t *p,

newconf->lockdb_path =
child->lockdb_path ? child->lockdb_path : parent->lockdb_path;
newconf->lockdb_type =
child->lockdb_type ? child->lockdb_type : parent->lockdb_type;

return newconf;
}
Expand Down Expand Up @@ -167,6 +176,9 @@ static apr_status_t dav_fs_post_config(apr_pool_t *p, apr_pool_t *plog,
if (!conf->lockdb_path) {
conf->lockdb_path = ap_state_dir_relative(p, DEFAULT_DAV_LOCKDB);
}
if (!conf->lockdb_type) {
conf->lockdb_type = DEFAULT_DAV_LOCKDB_TYPE;
}
}

return OK;
Expand All @@ -191,6 +203,19 @@ static const char *dav_fs_cmd_davlockdb(cmd_parms *cmd, void *config,
return NULL;
}

/*
* Command handler for the DAVLockDBType directive, which is TAKE1
*/
static const char *dav_fs_cmd_davlockdbtype(cmd_parms *cmd, void *config,
const char *arg1)
{
dav_fs_server_conf *conf = ap_get_module_config(cmd->server->module_config,
&dav_fs_module);
conf->lockdb_type = arg1;

return NULL;
}

/*
* Command handler for the DAVquota directive, which is TAKE1
*/
Expand All @@ -215,6 +240,8 @@ static const command_rec dav_fs_cmds[] =
/* per server */
AP_INIT_TAKE1("DAVLockDB", dav_fs_cmd_davlockdb, NULL, RSRC_CONF,
"specify a lock database"),
AP_INIT_TAKE1("DAVLockDBType", dav_fs_cmd_davlockdbtype, NULL, RSRC_CONF,
"specify a lock database DBM type"),

/* per directory */
AP_INIT_TAKE1("DAVquota", dav_fs_cmd_quota, NULL, ACCESS_CONF|RSRC_CONF,
Expand Down
9 changes: 5 additions & 4 deletions modules/dav/fs/repos.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ dav_error * dav_fs_get_locknull_members(const dav_resource *resource,
/* DBM functions used by the repository and locking providers */
extern const dav_hooks_db dav_hooks_db_dbm;

dav_error * dav_dbm_open_direct(apr_pool_t *p, const char *pathname, int ro,
dav_db **pdb);
dav_error * dav_dbm_open_direct(apr_pool_t *p, const char *pathname,
const char *dbmtype, int ro, dav_db **pdb);
void dav_dbm_get_statefiles(apr_pool_t *p, const char *fname,
const char **state1, const char **state2);
dav_error * dav_dbm_delete(dav_db *db, apr_datum_t key);
Expand All @@ -77,8 +77,9 @@ void dav_dbm_freedatum(dav_db *db, apr_datum_t data);
int dav_dbm_exists(dav_db *db, apr_datum_t key);
void dav_dbm_close(dav_db *db);

/* where is the lock database located? */
const char *dav_get_lockdb_path(const request_rec *r);
/* Returns path to lock database and configured dbm type as
* *dbmtype. */
const char *dav_get_lockdb_path(const request_rec *r, const char **dbmtype);

dav_error *dav_fs_get_quota(const request_rec *r, const char *path,
apr_off_t *quota_bytes);
Expand Down

0 comments on commit afcdbee

Please sign in to comment.