diff options
author | Volker Lendecke <vl@samba.org> | 2011-12-08 15:50:33 +0100 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2011-12-15 16:00:45 +0100 |
commit | 26fc72921f7b72dfebfe8394baa85b81ef66d26d (patch) | |
tree | ad66ef76af07e27e13a956ff79431ce80590b97c /source3/lib/dbwrap | |
parent | 19078b9b0564ed2654a1dae1d23488f89aadb41f (diff) | |
download | samba-26fc72921f7b72dfebfe8394baa85b81ef66d26d.tar.gz samba-26fc72921f7b72dfebfe8394baa85b81ef66d26d.tar.bz2 samba-26fc72921f7b72dfebfe8394baa85b81ef66d26d.zip |
s3-dbwrap: Make dbwrap_parse_record return NTSTATUS
Also, the parser now returns void. The parser is called if and only if
dbwrap_parse_record returns NT_STATUS_OK.
Signed-off-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'source3/lib/dbwrap')
-rw-r--r-- | source3/lib/dbwrap/dbwrap.c | 34 | ||||
-rw-r--r-- | source3/lib/dbwrap/dbwrap.h | 8 | ||||
-rw-r--r-- | source3/lib/dbwrap/dbwrap_private.h | 8 | ||||
-rw-r--r-- | source3/lib/dbwrap/dbwrap_rbt.c | 13 | ||||
-rw-r--r-- | source3/lib/dbwrap/dbwrap_tdb.c | 36 |
5 files changed, 62 insertions, 37 deletions
diff --git a/source3/lib/dbwrap/dbwrap.c b/source3/lib/dbwrap/dbwrap.c index a806c6add9..8ad6c946e9 100644 --- a/source3/lib/dbwrap/dbwrap.c +++ b/source3/lib/dbwrap/dbwrap.c @@ -51,32 +51,30 @@ static NTSTATUS dbwrap_fallback_fetch(struct db_context *db, static int dbwrap_fallback_exists(struct db_context *db, TDB_DATA key) { - int res = dbwrap_parse_record(db, key, NULL, NULL); - return ( res == -1) ? 0 : 1; + NTSTATUS status = dbwrap_parse_record(db, key, NULL, NULL); + return NT_STATUS_IS_OK(status) ? 1 : 0; } /* * Fall back using fetch if no genuine parse operation is provided */ -static int dbwrap_fallback_parse_record(struct db_context *db, TDB_DATA key, - int (*parser)(TDB_DATA key, - TDB_DATA data, - void *private_data), - void *private_data) +static NTSTATUS dbwrap_fallback_parse_record(struct db_context *db, TDB_DATA key, + void (*parser)(TDB_DATA key, + TDB_DATA data, + void *private_data), + void *private_data) { TDB_DATA data; - int res; NTSTATUS status; status = dbwrap_fetch(db, talloc_tos(), key, &data); if (!NT_STATUS_IS_OK(status)) { - return -1; + return status; } - - res = parser(key, data, private_data); + parser(key, data, private_data); TALLOC_FREE(data.dptr); - return res; + return NT_STATUS_OK; } @@ -217,15 +215,15 @@ NTSTATUS dbwrap_traverse_read(struct db_context *db, return NT_STATUS_OK; } -static int dbwrap_null_parser(TDB_DATA key, TDB_DATA val, void* data) +static void dbwrap_null_parser(TDB_DATA key, TDB_DATA val, void* data) { - return 0; + return; } -int dbwrap_parse_record(struct db_context *db, TDB_DATA key, - int (*parser)(TDB_DATA key, TDB_DATA data, - void *private_data), - void *private_data) +NTSTATUS dbwrap_parse_record(struct db_context *db, TDB_DATA key, + void (*parser)(TDB_DATA key, TDB_DATA data, + void *private_data), + void *private_data) { if (parser == NULL) { parser = dbwrap_null_parser; diff --git a/source3/lib/dbwrap/dbwrap.h b/source3/lib/dbwrap/dbwrap.h index 41e6833d79..386a9fa2a4 100644 --- a/source3/lib/dbwrap/dbwrap.h +++ b/source3/lib/dbwrap/dbwrap.h @@ -49,10 +49,10 @@ NTSTATUS dbwrap_traverse_read(struct db_context *db, int (*f)(struct db_record*, void*), void *private_data, int *count); -int dbwrap_parse_record(struct db_context *db, TDB_DATA key, - int (*parser)(TDB_DATA key, TDB_DATA data, - void *private_data), - void *private_data); +NTSTATUS dbwrap_parse_record(struct db_context *db, TDB_DATA key, + void (*parser)(TDB_DATA key, TDB_DATA data, + void *private_data), + void *private_data); int dbwrap_wipe(struct db_context *db); int dbwrap_get_seqnum(struct db_context *db); int dbwrap_get_flags(struct db_context *db); diff --git a/source3/lib/dbwrap/dbwrap_private.h b/source3/lib/dbwrap/dbwrap_private.h index 1491a134e7..a814cf61ba 100644 --- a/source3/lib/dbwrap/dbwrap_private.h +++ b/source3/lib/dbwrap/dbwrap_private.h @@ -49,10 +49,10 @@ struct db_context { int (*transaction_start)(struct db_context *db); int (*transaction_commit)(struct db_context *db); int (*transaction_cancel)(struct db_context *db); - int (*parse_record)(struct db_context *db, TDB_DATA key, - int (*parser)(TDB_DATA key, TDB_DATA data, - void *private_data), - void *private_data); + NTSTATUS (*parse_record)(struct db_context *db, TDB_DATA key, + void (*parser)(TDB_DATA key, TDB_DATA data, + void *private_data), + void *private_data); int (*exists)(struct db_context *db,TDB_DATA key); int (*wipe)(struct db_context *db); void *private_data; diff --git a/source3/lib/dbwrap/dbwrap_rbt.c b/source3/lib/dbwrap/dbwrap_rbt.c index 3f280c27de..09bc210f9e 100644 --- a/source3/lib/dbwrap/dbwrap_rbt.c +++ b/source3/lib/dbwrap/dbwrap_rbt.c @@ -330,18 +330,19 @@ static int db_rbt_wipe(struct db_context *db) return 0; } -static int db_rbt_parse_record(struct db_context *db, TDB_DATA key, - int (*parser)(TDB_DATA key, TDB_DATA data, - void *private_data), - void *private_data) +static NTSTATUS db_rbt_parse_record(struct db_context *db, TDB_DATA key, + void (*parser)(TDB_DATA key, TDB_DATA data, + void *private_data), + void *private_data) { struct db_rbt_search_result res; bool found = db_rbt_search_internal(db, key, &res); if (!found) { - return -1; + return NT_STATUS_NOT_FOUND; } - return parser(res.key, res.val, private_data); + parser(res.key, res.val, private_data); + return NT_STATUS_OK; } static NTSTATUS db_rbt_fetch(struct db_context *db, TALLOC_CTX *mem_ctx, diff --git a/source3/lib/dbwrap/dbwrap_tdb.c b/source3/lib/dbwrap/dbwrap_tdb.c index fbb05cc2a8..efdb5dbee4 100644 --- a/source3/lib/dbwrap/dbwrap_tdb.c +++ b/source3/lib/dbwrap/dbwrap_tdb.c @@ -218,15 +218,41 @@ static int db_tdb_wipe(struct db_context *db) return tdb_wipe_all(ctx->wtdb->tdb); } -static int db_tdb_parse(struct db_context *db, TDB_DATA key, - int (*parser)(TDB_DATA key, TDB_DATA data, - void *private_data), - void *private_data) +struct db_tdb_parse_state { + void (*parser)(TDB_DATA key, TDB_DATA data, + void *private_data); + void *private_data; +}; + +/* + * tdb_parse_record expects a parser returning int, mixing up tdb and + * parser errors. Wrap around that by always returning 0 and have + * dbwrap_parse_record expect a parser returning void. + */ + +static int db_tdb_parser(TDB_DATA key, TDB_DATA data, void *private_data) +{ + struct db_tdb_parse_state *state = + (struct db_tdb_parse_state *)private_data; + state->parser(key, data, state->private_data); + return 0; +} + +static NTSTATUS db_tdb_parse(struct db_context *db, TDB_DATA key, + void (*parser)(TDB_DATA key, TDB_DATA data, + void *private_data), + void *private_data) { struct db_tdb_ctx *ctx = talloc_get_type_abort( db->private_data, struct db_tdb_ctx); + struct db_tdb_parse_state state; + int ret; + + state.parser = parser; + state.private_data = private_data; - return tdb_parse_record(ctx->wtdb->tdb, key, parser, private_data) ? -1 : 0; + ret = tdb_parse_record(ctx->wtdb->tdb, key, db_tdb_parser, &state); + return map_nt_error_from_tdb(ret); } static NTSTATUS db_tdb_store(struct db_record *rec, TDB_DATA data, int flag) |