diff options
author | Michael Adam <obnox@samba.org> | 2011-11-11 00:49:11 +0100 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2011-11-29 18:20:06 +0100 |
commit | efb993b686e397e06ba647089535c92ec08c4345 (patch) | |
tree | 470e5e6cd40991409f66e8ddcdac88cfce68fceb /source3/lib/dbwrap/dbwrap_tdb.c | |
parent | 819ca3b697e1b396b83308341cf81c19362c2626 (diff) | |
download | samba-efb993b686e397e06ba647089535c92ec08c4345.tar.gz samba-efb993b686e397e06ba647089535c92ec08c4345.tar.bz2 samba-efb993b686e397e06ba647089535c92ec08c4345.zip |
s3:dbwrap: turn the fetch dbwrap method to NTSTATUS return code.
This implement more correct NTSTATUS handling inside the backends.
This ensures that data.dptr != NULL if return code is NT_STATUS_OK.
Diffstat (limited to 'source3/lib/dbwrap/dbwrap_tdb.c')
-rw-r--r-- | source3/lib/dbwrap/dbwrap_tdb.c | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/source3/lib/dbwrap/dbwrap_tdb.c b/source3/lib/dbwrap/dbwrap_tdb.c index e9e4900068..cf761e24f0 100644 --- a/source3/lib/dbwrap/dbwrap_tdb.c +++ b/source3/lib/dbwrap/dbwrap_tdb.c @@ -23,6 +23,7 @@ #include "dbwrap/dbwrap_tdb.h" #include "lib/util/tdb_wrap.h" #include "lib/param/param.h" +#include "util_tdb.h" struct db_tdb_ctx { struct tdb_wrap *wtdb; @@ -135,7 +136,7 @@ static struct db_record *db_tdb_fetch_locked(struct db_context *db, struct tdb_fetch_state { TALLOC_CTX *mem_ctx; - int result; + NTSTATUS result; TDB_DATA data; }; @@ -145,19 +146,25 @@ static int db_tdb_fetch_parse(TDB_DATA key, TDB_DATA data, struct tdb_fetch_state *state = (struct tdb_fetch_state *)private_data; + if (data.dptr == NULL) { + /* should not happen */ + state->result = NT_STATUS_INTERNAL_DB_ERROR; + return -1; + } + state->data.dptr = (uint8 *)talloc_memdup(state->mem_ctx, data.dptr, data.dsize); if (state->data.dptr == NULL) { - state->result = -1; - return 0; + state->result = NT_STATUS_NO_MEMORY; + return -1; } 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) +static NTSTATUS 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); @@ -166,21 +173,29 @@ static int db_tdb_fetch(struct db_context *db, TALLOC_CTX *mem_ctx, int ret; state.mem_ctx = mem_ctx; - state.result = 0; + state.result = NT_STATUS_OK; state.data = tdb_null; ret = tdb_parse_record(ctx->wtdb->tdb, key, db_tdb_fetch_parse, &state); if (ret != 0) { - return -1; + NTSTATUS status; + + if (!NT_STATUS_IS_OK(state.result)) { + /* the parser has set an error code. return it */ + return state.result; + } + + status = map_nt_error_from_tdb(tdb_error(ctx->wtdb->tdb)); + return status; } - if (state.result == -1) { - return -1; + if (!NT_STATUS_IS_OK(state.result)) { + return NT_STATUS_INTERNAL_DB_CORRUPTION; } *pdata = state.data; - return 0; + return NT_STATUS_OK; } static int db_tdb_exists(struct db_context *db, TDB_DATA key) |