summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2012-11-08 11:52:43 +0100
committerMichael Adam <obnox@samba.org>2012-11-29 17:50:36 +0100
commit71273448637e65b920535c077959e8dbb5444299 (patch)
tree76c4989476def8870debd372dd303e750cdce130 /source3
parent560ed93147b4da8b6124837133b90b4f95dbd6fc (diff)
downloadsamba-71273448637e65b920535c077959e8dbb5444299.tar.gz
samba-71273448637e65b920535c077959e8dbb5444299.tar.bz2
samba-71273448637e65b920535c077959e8dbb5444299.zip
s3: Use db_ctdb_ltdb_parse in db_ctdb_ltdb_fetch
Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/dbwrap/dbwrap_ctdb.c76
1 files changed, 46 insertions, 30 deletions
diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c
index abcdd35244..5e09e1d4c9 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap/dbwrap_ctdb.c
@@ -131,6 +131,39 @@ static NTSTATUS db_ctdb_ltdb_parse(
return NT_STATUS_OK;
}
+struct db_ctdb_ltdb_fetch_state {
+ struct ctdb_ltdb_header *header;
+ TALLOC_CTX *mem_ctx;
+ TDB_DATA *data;
+ bool oom;
+};
+
+static void db_ctdb_ltdb_fetch_parser(
+ TDB_DATA key, struct ctdb_ltdb_header *header,
+ TDB_DATA data, void *private_data)
+{
+ struct db_ctdb_ltdb_fetch_state *state =
+ (struct db_ctdb_ltdb_fetch_state *)private_data;
+
+ if (state->header != NULL) {
+ memcpy(state->header, header, sizeof(struct ctdb_ltdb_header));
+ }
+ if (state->data == NULL) {
+ return;
+ }
+ state->data->dsize = data.dsize;
+ if (data.dsize == 0) {
+ state->data->dptr = NULL;
+ return;
+ }
+ state->data->dptr = talloc_memdup(state->mem_ctx, data.dptr,
+ data.dsize);
+ if (state->data->dptr == NULL) {
+ state->oom = true;
+ return;
+ }
+}
+
/**
* fetch a record from the tdb, separating out the header
* information and returning the body of the record.
@@ -141,12 +174,17 @@ static NTSTATUS db_ctdb_ltdb_fetch(struct db_ctdb_ctx *db,
TALLOC_CTX *mem_ctx,
TDB_DATA *data)
{
- TDB_DATA rec;
+ struct db_ctdb_ltdb_fetch_state state;
NTSTATUS status;
- rec = tdb_fetch_compat(db->wtdb->tdb, key);
- if (rec.dsize < sizeof(struct ctdb_ltdb_header)) {
- status = NT_STATUS_NOT_FOUND;
+ state.header = header;
+ state.mem_ctx = mem_ctx;
+ state.data = data;
+ state.oom = false;
+
+ status = db_ctdb_ltdb_parse(db, key, db_ctdb_ltdb_fetch_parser,
+ &state);
+ if (!NT_STATUS_IS_OK(status)) {
if (data) {
ZERO_STRUCTP(data);
}
@@ -154,34 +192,12 @@ static NTSTATUS db_ctdb_ltdb_fetch(struct db_ctdb_ctx *db,
header->dmaster = (uint32_t)-1;
header->rsn = 0;
}
- goto done;
- }
-
- if (header) {
- *header = *(struct ctdb_ltdb_header *)rec.dptr;
+ return status;
}
-
- if (data) {
- data->dsize = rec.dsize - sizeof(struct ctdb_ltdb_header);
- if (data->dsize == 0) {
- data->dptr = NULL;
- } else {
- data->dptr = (unsigned char *)talloc_memdup(mem_ctx,
- rec.dptr
- + sizeof(struct ctdb_ltdb_header),
- data->dsize);
- if (data->dptr == NULL) {
- status = NT_STATUS_NO_MEMORY;
- goto done;
- }
- }
+ if (state.oom) {
+ return NT_STATUS_NO_MEMORY;
}
-
- status = NT_STATUS_OK;
-
-done:
- SAFE_FREE(rec.dptr);
- return status;
+ return NT_STATUS_OK;
}
/*