diff options
Diffstat (limited to 'source3/lib')
-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 | ||||
-rw-r--r-- | source3/lib/serverid.c | 10 |
6 files changed, 68 insertions, 41 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) diff --git a/source3/lib/serverid.c b/source3/lib/serverid.c index c1b87f7929..6d8a3c004f 100644 --- a/source3/lib/serverid.c +++ b/source3/lib/serverid.c @@ -230,13 +230,14 @@ struct serverid_exists_state { bool exists; }; -static int server_exists_parse(TDB_DATA key, TDB_DATA data, void *priv) +static void server_exists_parse(TDB_DATA key, TDB_DATA data, void *priv) { struct serverid_exists_state *state = (struct serverid_exists_state *)priv; if (data.dsize != sizeof(struct serverid_data)) { - return -1; + state->exists = false; + return; } /* @@ -245,7 +246,6 @@ static int server_exists_parse(TDB_DATA key, TDB_DATA data, void *priv) */ state->exists = (memcmp(&state->id->unique_id, data.dptr, sizeof(state->id->unique_id)) == 0); - return 0; } bool serverid_exists(const struct server_id *id) @@ -254,6 +254,7 @@ bool serverid_exists(const struct server_id *id) struct serverid_exists_state state; struct serverid_key key; TDB_DATA tdbkey; + NTSTATUS status; if (procid_is_me(id)) { return true; @@ -274,7 +275,8 @@ bool serverid_exists(const struct server_id *id) state.id = id; state.exists = false; - if (dbwrap_parse_record(db, tdbkey, server_exists_parse, &state) != 0) { + status = dbwrap_parse_record(db, tdbkey, server_exists_parse, &state); + if (!NT_STATUS_IS_OK(status)) { return false; } return state.exists; |