Revamp cf/db.m4; test LMDB

This commit is contained in:
Nicolas Williams
2015-06-01 11:48:31 -05:00
parent 76c26281a7
commit c6f24e99f0
18 changed files with 111 additions and 64 deletions

View File

@@ -110,8 +110,7 @@ libhdb_la_LIBADD = \
$(LIBADD_roken) \
$(ldap_lib) \
$(LIB_dlopen) \
$(DBLIB) \
$(LIB_NDBM)
$(DB3LIB) $(DB1LIB) $(LMDBLIB) $(NDBMLIB)
HDB_PROTOS = $(srcdir)/hdb-protos.h $(srcdir)/hdb-private.h

View File

@@ -157,6 +157,10 @@ DB_rename(krb5_context context, HDB *db, const char *new_name)
int ret;
char *old, *new;
if (strncmp(new_name, "db:", sizeof("db:") - 1) == 0)
new_name += sizeof("db:") - 1;
else if (strncmp(new_name, "db1:", sizeof("db1:") - 1) == 0)
new_name += sizeof("db1:") - 1;
asprintf(&old, "%s.db", db->hdb_name);
asprintf(&new, "%s.db", new_name);
ret = rename(old, new);

View File

@@ -168,6 +168,11 @@ DB_rename(krb5_context context, HDB *db, const char *new_name)
int ret;
char *old, *new;
if (strncmp(new_name, "db:", sizeof("db:") - 1) == 0)
new_name += sizeof("db:") - 1;
else if (strncmp(new_name, "db3:", sizeof("db3:") - 1) == 0)
new_name += sizeof("db3:") - 1;
ret = asprintf(&old, "%s.db", db->hdb_name);
if (ret == -1)
return ENOMEM;

View File

@@ -34,11 +34,11 @@
#include "hdb_locl.h"
#if HAVE_MDB
#if HAVE_LMDB
/* OpenLDAP MDB */
/* LMDB */
#include <mdb.h>
#include <lmdb.h>
#define KILO 1024
@@ -172,12 +172,16 @@ DB_rename(krb5_context context, HDB *db, const char *new_name)
int ret;
char *old, *new;
if (strncmp(new_name, "mdb:", sizeof("mdb:") - 1) == 0)
new_name += sizeof("mdb:") - 1;
else if (strncmp(new_name, "lmdb:", sizeof("lmdb:") - 1) == 0)
new_name += sizeof("lmdb:") - 1;
if (asprintf(&old, "%s.mdb", db->hdb_name) == -1)
return ENOMEM;
if (asprintf(&new, "%s.mdb", new_name) == -1) {
free(old);
return ENOMEM;
}
}
ret = rename(old, new);
free(old);
free(new);
@@ -394,4 +398,4 @@ hdb_mdb_create(krb5_context context, HDB **db,
(*db)->hdb_destroy = DB_destroy;
return 0;
}
#endif /* HAVE_MDB */
#endif /* HAVE_LMDB */

View File

@@ -70,8 +70,9 @@ static struct hdb_method methods[] = {
#if HAVE_DB1
{ HDB_INTERFACE_VERSION, NULL, NULL, "mit-db:", hdb_mitdb_create},
#endif
#if HAVE_MDB
#if HAVE_LMDB
{ HDB_INTERFACE_VERSION, NULL, NULL, "mdb:", hdb_mdb_create},
{ HDB_INTERFACE_VERSION, NULL, NULL, "lmdb:", hdb_mdb_create},
#endif
#if HAVE_NDBM
{ HDB_INTERFACE_VERSION, NULL, NULL, "ndbm:", hdb_ndbm_create},
@@ -90,6 +91,9 @@ static struct hdb_method methods[] = {
#if HAVE_DB1 || HAVE_DB3
static struct hdb_method dbmetod =
{ HDB_INTERFACE_VERSION, NULL, NULL, "", hdb_db_create };
#elif defined(HAVE_LMDB)
static struct hdb_method dbmetod =
{ HDB_INTERFACE_VERSION, NULL, NULL, "", hdb_mdb_create };
#elif defined(HAVE_NDBM)
static struct hdb_method dbmetod =
{ HDB_INTERFACE_VERSION, NULL, NULL, "", hdb_ndbm_create };
@@ -310,7 +314,8 @@ find_method (const char *filename, const char **rest)
return h;
}
}
#if defined(HAVE_DB1) || defined(HAVE_DB3) || defined(HAVE_NDBM)
#if defined(HAVE_DB1) || defined(HAVE_DB3) || defined(HAVE_LMDB) || defined(HAVE_NDBM)
/* XXX This doesn't handle Windows */
if (strncmp(filename, "/", 1) == 0
|| strncmp(filename, "./", 2) == 0
|| strncmp(filename, "../", 3) == 0)