summaryrefslogtreecommitdiffstats
path: root/source4/lib/ldb/ldb_tdb
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/ldb/ldb_tdb')
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_cache.c3
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_index.c12
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_pack.c4
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_search.c7
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c19
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.h13
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c76
7 files changed, 76 insertions, 58 deletions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c
index 697f7427a44..e54ceaaa98a 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_cache.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c
@@ -345,9 +345,6 @@ int ltdb_cache_load(struct ldb_module *module)
ltdb->check_base = false;
}
- talloc_free(ltdb->cache->last_attribute.name);
- memset(&ltdb->cache->last_attribute, 0, sizeof(ltdb->cache->last_attribute));
-
talloc_free(ltdb->cache->indexlist);
ltdb_attributes_unload(module); /* calls internally "talloc_free" */
diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c
index 02e4acbbdef..24cc93feb94 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_index.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_index.c
@@ -155,7 +155,7 @@ static int ltdb_dn_list_load(struct ldb_module *module,
key.dptr = discard_const_p(unsigned char, ldb_dn_get_linearized(dn));
key.dsize = strlen((char *)key.dptr);
- rec = tdb_fetch(ltdb->idxptr->itdb, key);
+ rec = tdb_fetch_compat(ltdb->idxptr->itdb, key);
if (rec.dptr == NULL) {
goto normal_index;
}
@@ -261,7 +261,7 @@ static int ltdb_dn_list_store(struct ldb_module *module, struct ldb_dn *dn,
}
if (ltdb->idxptr->itdb == NULL) {
- ltdb->idxptr->itdb = tdb_open(NULL, 1000, TDB_INTERNAL, O_RDWR, 0);
+ ltdb->idxptr->itdb = tdb_open_compat(NULL, 1000, TDB_INTERNAL, O_RDWR, 0, NULL, NULL);
if (ltdb->idxptr->itdb == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
}
@@ -270,7 +270,7 @@ static int ltdb_dn_list_store(struct ldb_module *module, struct ldb_dn *dn,
key.dptr = discard_const_p(unsigned char, ldb_dn_get_linearized(dn));
key.dsize = strlen((char *)key.dptr);
- rec = tdb_fetch(ltdb->idxptr->itdb, key);
+ rec = tdb_fetch_compat(ltdb->idxptr->itdb, key);
if (rec.dptr != NULL) {
list2 = ltdb_index_idxptr(module, rec, false);
if (list2 == NULL) {
@@ -294,7 +294,7 @@ static int ltdb_dn_list_store(struct ldb_module *module, struct ldb_dn *dn,
rec.dsize = sizeof(void *);
ret = tdb_store(ltdb->idxptr->itdb, key, rec, TDB_INSERT);
- if (ret == -1) {
+ if (ret != 0) {
return ltdb_err_map(tdb_error(ltdb->idxptr->itdb));
}
return LDB_SUCCESS;
@@ -1569,7 +1569,7 @@ int ltdb_reindex(struct ldb_module *module)
* putting NULL entries in the in-memory tdb
*/
ret = tdb_traverse(ltdb->tdb, delete_index, module);
- if (ret == -1) {
+ if (ret < 0) {
return LDB_ERR_OPERATIONS_ERROR;
}
@@ -1583,7 +1583,7 @@ int ltdb_reindex(struct ldb_module *module)
/* now traverse adding any indexes for normal LDB records */
ret = tdb_traverse(ltdb->tdb, re_index, &ctx);
- if (ret == -1) {
+ if (ret < 0) {
struct ldb_context *ldb = ldb_module_get_ctx(module);
ldb_asprintf_errstring(ldb, "reindexing traverse failed: %s", ldb_errstring(ldb));
return LDB_ERR_OPERATIONS_ERROR;
diff --git a/source4/lib/ldb/ldb_tdb/ldb_pack.c b/source4/lib/ldb/ldb_tdb/ldb_pack.c
index 8ab07cd347c..7c13065aeef 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_pack.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_pack.c
@@ -74,7 +74,7 @@ static int attribute_storable_values(const struct ldb_message_element *el)
*/
int ltdb_pack_data(struct ldb_module *module,
const struct ldb_message *message,
- struct TDB_DATA *data)
+ TDB_DATA *data)
{
struct ldb_context *ldb;
unsigned int i, j, real_elements=0;
@@ -155,7 +155,7 @@ int ltdb_pack_data(struct ldb_module *module,
Free with ltdb_unpack_data_free()
*/
int ltdb_unpack_data(struct ldb_module *module,
- const struct TDB_DATA *data,
+ const TDB_DATA *data,
struct ldb_message *message)
{
struct ldb_context *ldb;
diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c
index a49751de154..46e2d749984 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_search.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_search.c
@@ -32,6 +32,7 @@
*/
#include "ldb_tdb.h"
+#include <lib/tdb_compat/tdb_compat.h>
/*
add one element to a message
@@ -223,7 +224,7 @@ static int ltdb_search_base(struct ldb_module *module, struct ldb_dn *dn)
return LDB_ERR_OPERATIONS_ERROR;
}
- tdb_data = tdb_fetch(ltdb->tdb, tdb_key);
+ tdb_data = tdb_fetch_compat(ltdb->tdb, tdb_key);
talloc_free(tdb_key.dptr);
if (!tdb_data.dptr) {
return LDB_ERR_NO_SUCH_OBJECT;
@@ -255,7 +256,7 @@ int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_mes
return LDB_ERR_OPERATIONS_ERROR;
}
- tdb_data = tdb_fetch(ltdb->tdb, tdb_key);
+ tdb_data = tdb_fetch_compat(ltdb->tdb, tdb_key);
talloc_free(tdb_key.dptr);
if (!tdb_data.dptr) {
return LDB_ERR_NO_SUCH_OBJECT;
@@ -479,7 +480,7 @@ static int ltdb_search_full(struct ltdb_context *ctx)
ret = tdb_traverse_read(ltdb->tdb, search_func, ctx);
}
- if (ret == -1) {
+ if (ret < 0) {
return LDB_ERR_OPERATIONS_ERROR;
}
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
index 2f7f2220860..0d4be491235 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -50,6 +50,7 @@
*/
#include "ldb_tdb.h"
+#include <lib/tdb_compat/tdb_compat.h>
/*
@@ -67,9 +68,13 @@ int ltdb_err_map(enum TDB_ERROR tdb_code)
case TDB_ERR_IO:
return LDB_ERR_PROTOCOL_ERROR;
case TDB_ERR_LOCK:
+#ifndef BUILD_TDB2
case TDB_ERR_NOLOCK:
+#endif
return LDB_ERR_BUSY;
+#ifndef BUILD_TDB2
case TDB_ERR_LOCK_TIMEOUT:
+#endif
return LDB_ERR_TIME_LIMIT_EXCEEDED;
case TDB_ERR_EXISTS:
return LDB_ERR_ENTRY_ALREADY_EXISTS;
@@ -110,7 +115,8 @@ int ltdb_unlock_read(struct ldb_module *module)
void *data = ldb_module_get_private(module);
struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
if (ltdb->in_transaction == 0 && ltdb->read_lock_count == 1) {
- return tdb_unlockall_read(ltdb->tdb);
+ tdb_unlockall_read(ltdb->tdb);
+ return 0;
}
ltdb->read_lock_count--;
return 0;
@@ -124,7 +130,7 @@ int ltdb_unlock_read(struct ldb_module *module)
note that the key for a record can depend on whether the
dn refers to a case sensitive index record or not
*/
-struct TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn)
+TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn)
{
struct ldb_context *ldb = ldb_module_get_ctx(module);
TDB_DATA key;
@@ -263,7 +269,7 @@ int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flg
}
ret = tdb_store(ltdb->tdb, tdb_key, tdb_data, flgs);
- if (ret == -1) {
+ if (ret != 0) {
ret = ltdb_err_map(tdb_error(ltdb->tdb));
goto done;
}
@@ -653,7 +659,7 @@ int ltdb_modify_internal(struct ldb_module *module,
return LDB_ERR_OTHER;
}
- tdb_data = tdb_fetch(ltdb->tdb, tdb_key);
+ tdb_data = tdb_fetch_compat(ltdb->tdb, tdb_key);
if (!tdb_data.dptr) {
talloc_free(tdb_key.dptr);
return ltdb_err_map(tdb_error(ltdb->tdb));
@@ -1072,10 +1078,7 @@ static int ltdb_del_trans(struct ldb_module *module)
return ltdb_err_map(tdb_error(ltdb->tdb));
}
- if (tdb_transaction_cancel(ltdb->tdb) != 0) {
- return ltdb_err_map(tdb_error(ltdb->tdb));
- }
-
+ tdb_transaction_cancel(ltdb->tdb);
return LDB_SUCCESS;
}
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.h b/source4/lib/ldb/ldb_tdb/ldb_tdb.h
index 33313b00da9..96ad43fbd6c 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.h
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.h
@@ -1,7 +1,7 @@
#include "replace.h"
#include "system/filesys.h"
#include "system/time.h"
-#include "tdb.h"
+#include "tdb_compat.h"
#include "ldb_module.h"
/* this private structure is used by the ltdb backend in the
@@ -21,11 +21,6 @@ struct ltdb_private {
struct ldb_message *attributes;
bool one_level_indexes;
bool attribute_indexes;
-
- struct {
- char *name;
- int flags;
- } last_attribute;
} *cache;
int in_transaction;
@@ -107,11 +102,11 @@ int ltdb_index_transaction_cancel(struct ldb_module *module);
int ltdb_pack_data(struct ldb_module *module,
const struct ldb_message *message,
- struct TDB_DATA *data);
+ TDB_DATA *data);
void ltdb_unpack_data_free(struct ldb_module *module,
struct ldb_message *message);
int ltdb_unpack_data(struct ldb_module *module,
- const struct TDB_DATA *data,
+ const TDB_DATA *data,
struct ldb_message *message);
/* The following definitions come from lib/ldb/ldb_tdb/ldb_search.c */
@@ -132,7 +127,7 @@ int ltdb_search(struct ltdb_context *ctx);
/* The following definitions come from lib/ldb/ldb_tdb/ldb_tdb.c */
int ltdb_lock_read(struct ldb_module *module);
int ltdb_unlock_read(struct ldb_module *module);
-struct TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn);
+TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn);
int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs);
int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg, struct ldb_request *req);
int ltdb_delete_noindex(struct ldb_module *module, struct ldb_dn *dn);
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c
index b9f3e79f205..16a037a6c33 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c
@@ -24,29 +24,30 @@
#include "ldb_tdb.h"
#include "dlinklist.h"
-/*
- the purpose of this code is to work around the braindead posix locking
- rules, to allow us to have a ldb open more than once while allowing
- locking to work
-*/
-
-struct ltdb_wrap {
- struct ltdb_wrap *next, *prev;
- struct tdb_context *tdb;
- dev_t device;
- ino_t inode;
-};
-
-static struct ltdb_wrap *tdb_list;
-
-/* destroy the last connection to a tdb */
-static int ltdb_wrap_destructor(struct ltdb_wrap *w)
+/* FIXME: TDB2 does this internally, so no need to wrap multiple opens! */
+#if BUILD_TDB2
+static void ltdb_log_fn(struct tdb_context *tdb,
+ enum tdb_log_level level,
+ const char *message,
+ struct ldb_context *ldb)
{
- tdb_close(w->tdb);
- DLIST_REMOVE(tdb_list, w);
- return 0;
-}
+ enum ldb_debug_level ldb_level;
+ const char *name = tdb_name(tdb);
+
+ switch (level) {
+ case TDB_LOG_WARNING:
+ ldb_level = LDB_DEBUG_WARNING;
+ case TDB_LOG_USE_ERROR:
+ case TDB_LOG_ERROR:
+ ldb_level = LDB_DEBUG_FATAL;
+ break;
+ default:
+ ldb_level = LDB_DEBUG_FATAL;
+ }
+ ldb_debug(ldb, ldb_level, "ltdb: tdb(%s): %s", name, message);
+}
+#else /* !TDB2 */
static void ltdb_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
static void ltdb_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...)
{
@@ -83,6 +84,32 @@ static void ltdb_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, con
ldb_debug(ldb, ldb_level, "ltdb: tdb(%s): %s", name, message);
talloc_free(message);
}
+#endif
+
+/*
+ the purpose of this code is to work around the braindead posix locking
+ rules, to allow us to have a ldb open more than once while allowing
+ locking to work
+
+ TDB2 handles multiple opens, so we don't have this problem there.
+*/
+
+struct ltdb_wrap {
+ struct ltdb_wrap *next, *prev;
+ struct tdb_context *tdb;
+ dev_t device;
+ ino_t inode;
+};
+
+static struct ltdb_wrap *tdb_list;
+
+/* destroy the last connection to a tdb */
+static int ltdb_wrap_destructor(struct ltdb_wrap *w)
+{
+ tdb_close(w->tdb);
+ DLIST_REMOVE(tdb_list, w);
+ return 0;
+}
/*
wrapped connection to a tdb database. The caller should _not_ free
@@ -98,10 +125,6 @@ struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx,
{
struct ltdb_wrap *w;
struct stat st;
- struct tdb_logging_context log_ctx;
-
- log_ctx.log_fn = ltdb_log_fn;
- log_ctx.log_private = ldb;
if (stat(path, &st) == 0) {
for (w=tdb_list;w;w=w->next) {
@@ -119,7 +142,7 @@ struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx,
return NULL;
}
- w->tdb = tdb_open_ex(path, hash_size, tdb_flags, open_flags, mode, &log_ctx, NULL);
+ w->tdb = tdb_open_compat(path, hash_size, tdb_flags, open_flags, mode, ltdb_log_fn, ldb);
if (w->tdb == NULL) {
talloc_free(w);
return NULL;
@@ -140,4 +163,3 @@ struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx,
return w->tdb;
}
-