summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2012-08-09 22:46:48 +1000
committerAndrew Bartlett <abartlet@samba.org>2012-08-10 10:18:27 +1000
commit1d1bdc315b4619f0ca5b2a0db602cbe283f8dca8 (patch)
tree27ae54190fdb5767995f7431d5d08a3ac8082d46 /lib
parenta5495bc6b073d29041d9a8e229d37693d6a0c513 (diff)
downloadsamba-1d1bdc315b4619f0ca5b2a0db602cbe283f8dca8.tar.gz
samba-1d1bdc315b4619f0ca5b2a0db602cbe283f8dca8.tar.bz2
samba-1d1bdc315b4619f0ca5b2a0db602cbe283f8dca8.zip
lib/ldb: Use tdb_parse_record and a callback rather than tdb_fetch()
This avoid allocation at the tdb layer as we will allocate this with talloc right away anyway. Andrew Bartlett
Diffstat (limited to 'lib')
-rw-r--r--lib/ldb/ldb_tdb/ldb_search.c54
1 files changed, 38 insertions, 16 deletions
diff --git a/lib/ldb/ldb_tdb/ldb_search.c b/lib/ldb/ldb_tdb/ldb_search.c
index e631f7baca..703ad6ad0e 100644
--- a/lib/ldb/ldb_tdb/ldb_search.c
+++ b/lib/ldb/ldb_tdb/ldb_search.c
@@ -234,6 +234,26 @@ static int ltdb_search_base(struct ldb_module *module, struct ldb_dn *dn)
return LDB_ERR_NO_SUCH_OBJECT;
}
+struct ltdb_parse_data_unpack_ctx {
+ struct ldb_message *msg;
+ struct ldb_module *module;
+};
+
+static int ltdb_parse_data_unpack(TDB_DATA key, TDB_DATA data,
+ void *private_data)
+{
+ struct ltdb_parse_data_unpack_ctx *ctx = private_data;
+
+ int ret = ltdb_unpack_data(ctx->module, &data, ctx->msg);
+ if (ret == -1) {
+ struct ldb_context *ldb = ldb_module_get_ctx(ctx->module);
+ ldb_debug(ldb, LDB_DEBUG_ERROR, "Invalid data for index %*.*s\n",
+ (int)key.dsize, (int)key.dsize, key.dptr);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+ return ret;
+}
+
/*
search the database for a single simple dn, returning all attributes
in a single message
@@ -246,9 +266,11 @@ int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_mes
void *data = ldb_module_get_private(module);
struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
int ret;
- TDB_DATA tdb_key, tdb_data;
-
- memset(msg, 0, sizeof(*msg));
+ TDB_DATA tdb_key;
+ struct ltdb_parse_data_unpack_ctx ctx = {
+ .msg = msg,
+ .module = module
+ };
/* form the key */
tdb_key = ltdb_key(module, dn);
@@ -256,24 +278,24 @@ 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);
- talloc_free(tdb_key.dptr);
- if (!tdb_data.dptr) {
- return LDB_ERR_NO_SUCH_OBJECT;
- }
-
+ memset(msg, 0, sizeof(*msg));
+
msg->num_elements = 0;
msg->elements = NULL;
- ret = ltdb_unpack_data(module, &tdb_data, msg);
- free(tdb_data.dptr);
+ ret = tdb_parse_record(ltdb->tdb, tdb_key,
+ ltdb_parse_data_unpack, &ctx);
+ talloc_free(tdb_key.dptr);
+
if (ret == -1) {
- struct ldb_context *ldb = ldb_module_get_ctx(module);
- ldb_debug(ldb, LDB_DEBUG_ERROR, "Invalid data for index %s\n",
- ldb_dn_get_linearized(msg->dn));
- return LDB_ERR_OPERATIONS_ERROR;
+ if (tdb_error(ltdb->tdb) == TDB_ERR_NOEXIST) {
+ return LDB_ERR_NO_SUCH_OBJECT;
+ }
+ return LDB_ERR_OPERATIONS_ERROR;
+ } else if (ret != LDB_SUCCESS) {
+ return ret;
}
-
+
if (!msg->dn) {
msg->dn = ldb_dn_copy(msg, dn);
}