diff options
author | Volker Lendecke <vl@samba.org> | 2011-12-08 16:43:40 +0100 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2011-12-15 16:00:46 +0100 |
commit | b5d056ca231f67b4c6fd608ecbe6f83f1823a33b (patch) | |
tree | 71db86a7f78222075d97bb132d1bfb1eb7ab7d14 /source3/lib/dbwrap | |
parent | 77dca703504044412872b7e9ad4d2c9c1971ba32 (diff) | |
download | samba-b5d056ca231f67b4c6fd608ecbe6f83f1823a33b.tar.gz samba-b5d056ca231f67b4c6fd608ecbe6f83f1823a33b.tar.bz2 samba-b5d056ca231f67b4c6fd608ecbe6f83f1823a33b.zip |
s3-dbwrap: Rewrite dbwrap_fetch in terms of dbwrap_parse_record
Signed-off-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'source3/lib/dbwrap')
-rw-r--r-- | source3/lib/dbwrap/dbwrap.c | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/source3/lib/dbwrap/dbwrap.c b/source3/lib/dbwrap/dbwrap.c index 0635d76b2c..4df2474ea1 100644 --- a/source3/lib/dbwrap/dbwrap.c +++ b/source3/lib/dbwrap/dbwrap.c @@ -135,16 +135,43 @@ struct db_record *dbwrap_fetch_locked(struct db_context *db, return db->fetch_locked(db, mem_ctx, key); } +struct dbwrap_fetch_state { + TALLOC_CTX *mem_ctx; + TDB_DATA data; +}; + +static void dbwrap_fetch_parser(TDB_DATA key, TDB_DATA data, + void *private_data) +{ + struct dbwrap_fetch_state *state = + (struct dbwrap_fetch_state *)private_data; + + state->data.dsize = data.dsize; + state->data.dptr = (uint8_t *)talloc_memdup(state->mem_ctx, data.dptr, + data.dsize); +} + NTSTATUS dbwrap_fetch(struct db_context *db, TALLOC_CTX *mem_ctx, TDB_DATA key, TDB_DATA *value) { + struct dbwrap_fetch_state state; + NTSTATUS status; + if (value == NULL) { return NT_STATUS_INVALID_PARAMETER; } - if (db->fetch == NULL) { - return dbwrap_fallback_fetch(db, mem_ctx, key, value); + + state.mem_ctx = mem_ctx; + + status = dbwrap_parse_record(db, key, dbwrap_fetch_parser, &state); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + if ((state.data.dsize != 0) && (state.data.dptr == NULL)) { + return NT_STATUS_NO_MEMORY; } - return db->fetch(db, mem_ctx, key, value); + *value = state.data; + return NT_STATUS_OK; } bool dbwrap_exists(struct db_context *db, TDB_DATA key) |