summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2008-01-07 00:41:26 +0100
committerVolker Lendecke <vl@samba.org>2008-01-07 21:18:12 +0100
commitc3c19615c16a2a2dc7d3620d7117b9f261e5c35a (patch)
tree92918f04b0a61d2508d1654032dcd5f97ab4f002 /source3
parent6dc988c918d7909b6eec052e6c3511467e9be697 (diff)
downloadsamba-c3c19615c16a2a2dc7d3620d7117b9f261e5c35a.tar.gz
samba-c3c19615c16a2a2dc7d3620d7117b9f261e5c35a.tar.bz2
samba-c3c19615c16a2a2dc7d3620d7117b9f261e5c35a.zip
make db_tdb_fetch use tdb_parse_record
(This used to be commit 88d82d0623e71ae1ef4f8fdefba10e3a230ea526)
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/dbwrap_tdb.c46
1 files changed, 33 insertions, 13 deletions
diff --git a/source3/lib/dbwrap_tdb.c b/source3/lib/dbwrap_tdb.c
index cce987d789..83a0d111aa 100644
--- a/source3/lib/dbwrap_tdb.c
+++ b/source3/lib/dbwrap_tdb.c
@@ -70,7 +70,7 @@ static int db_tdb_fetchlock_parse(TDB_DATA key, TDB_DATA data,
state->result->value.dsize = data.dsize;
if (data.dsize > 0) {
- state->result->value.dptr = state->result->key.dptr + key.dsize;
+ state->result->value.dptr = state->result->key.dptr+key.dsize;
memcpy(state->result->value.dptr, data.dptr, data.dsize);
}
else {
@@ -127,29 +127,49 @@ static struct db_record *db_tdb_fetch_locked(struct db_context *db,
return state.result;
}
+struct tdb_fetch_state {
+ TALLOC_CTX *mem_ctx;
+ int result;
+ TDB_DATA data;
+};
+
+static int db_tdb_fetch_parse(TDB_DATA key, TDB_DATA data,
+ void *private_data)
+{
+ struct tdb_fetch_state *state =
+ (struct tdb_fetch_state *)private_data;
+
+ state->data.dptr = (uint8 *)talloc_memdup(state->mem_ctx, data.dptr,
+ data.dsize);
+ if (state->data.dptr == NULL) {
+ state->result = -1;
+ return 0;
+ }
+
+ state->data.dsize = data.dsize;
+ return 0;
+}
+
static int db_tdb_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
TDB_DATA key, TDB_DATA *pdata)
{
struct db_tdb_ctx *ctx = talloc_get_type_abort(
db->private_data, struct db_tdb_ctx);
- TDB_DATA data;
-
- data = tdb_fetch(ctx->wtdb->tdb, key);
+ struct tdb_fetch_state state;
- if (data.dptr == NULL) {
- pdata->dptr = NULL;
- pdata->dsize = 0;
- return 0;
- }
+ state.mem_ctx = mem_ctx;
+ state.result = 0;
+ state.data.dptr = NULL;
+ state.data.dsize = 0;
- pdata->dptr = (uint8 *)talloc_memdup(mem_ctx, data.dptr, data.dsize);
- SAFE_FREE(data.dptr);
+ tdb_parse_record(ctx->wtdb->tdb, key, db_tdb_fetch_parse, &state);
- if (pdata->dptr == NULL) {
+ if (state.result == -1) {
return -1;
}
- pdata->dsize = data.dsize;
+
+ *pdata = state.data;
return 0;
}