1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-29 13:49:30 +03:00

ldb: Change remaining fetch prototypes to remove TDB_DATA

Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
This commit is contained in:
Garming Sam
2018-02-19 12:37:20 +13:00
committed by Andrew Bartlett
parent 7885181650
commit 7bf853950d
3 changed files with 52 additions and 18 deletions

View File

@ -180,17 +180,15 @@ struct ltdb_parse_data_unpack_ctx {
unsigned int unpack_flags;
};
static int ltdb_parse_data_unpack(TDB_DATA key, TDB_DATA data,
static int ltdb_parse_data_unpack(struct ldb_val key,
struct ldb_val data,
void *private_data)
{
struct ltdb_parse_data_unpack_ctx *ctx = private_data;
unsigned int nb_elements_in_db;
int ret;
struct ldb_context *ldb = ldb_module_get_ctx(ctx->module);
struct ldb_val data_parse = {
.data = data.dptr,
.length = data.dsize
};
struct ldb_val data_parse = data;
if (ctx->unpack_flags & LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC) {
/*
@ -200,13 +198,13 @@ static int ltdb_parse_data_unpack(TDB_DATA key, TDB_DATA data,
* and the caller needs a stable result.
*/
data_parse.data = talloc_memdup(ctx->msg,
data.dptr,
data.dsize);
data.data,
data.length);
if (data_parse.data == NULL) {
ldb_debug(ldb, LDB_DEBUG_ERROR,
"Unable to allocate data(%d) for %*.*s\n",
(int)data.dsize,
(int)key.dsize, (int)key.dsize, key.dptr);
(int)data.length,
(int)key.length, (int)key.length, key.data);
return LDB_ERR_OPERATIONS_ERROR;
}
}
@ -217,13 +215,13 @@ static int ltdb_parse_data_unpack(TDB_DATA key, TDB_DATA data,
ctx->unpack_flags,
&nb_elements_in_db);
if (ret == -1) {
if (data_parse.data != data.dptr) {
if (data_parse.data != data.data) {
talloc_free(data_parse.data);
}
ldb_debug(ldb, LDB_DEBUG_ERROR, "Invalid data for index %*.*s\n",
(int)key.dsize, (int)key.dsize, key.dptr);
return LDB_ERR_OPERATIONS_ERROR;
(int)key.length, (int)key.length, key.data);
return LDB_ERR_OPERATIONS_ERROR;
}
return ret;
}
@ -246,13 +244,17 @@ int ltdb_search_key(struct ldb_module *module, struct ltdb_private *ltdb,
.module = module,
.unpack_flags = unpack_flags
};
struct ldb_val ldb_key = {
.data = tdb_key.dptr,
.length = tdb_key.dsize
};
memset(msg, 0, sizeof(*msg));
msg->num_elements = 0;
msg->elements = NULL;
ret = ltdb->kv_ops->fetch_and_parse(ltdb, tdb_key,
ret = ltdb->kv_ops->fetch_and_parse(ltdb, ldb_key,
ltdb_parse_data_unpack, &ctx);
if (ret == -1) {

View File

@ -1765,6 +1765,9 @@ struct kv_ctx {
ldb_kv_traverse_fn kv_traverse_fn;
void *ctx;
struct ltdb_private *ltdb;
int (*parser)(struct ldb_val key,
struct ldb_val data,
void *private_data);
};
static int ldb_tdb_traverse_fn_wrapper(struct tdb_context *tdb, TDB_DATA tdb_key, TDB_DATA tdb_data, void *ctx)
@ -1847,12 +1850,41 @@ static int ltdb_tdb_update_in_iterate(struct ltdb_private *ltdb,
return tdb_ret;
}
static int ltdb_tdb_parse_record(struct ltdb_private *ltdb, TDB_DATA key,
int (*parser)(TDB_DATA key, TDB_DATA data,
static int ltdb_tdb_parse_record_wrapper(TDB_DATA tdb_key, TDB_DATA tdb_data,
void *ctx)
{
struct kv_ctx *kv_ctx = ctx;
struct ldb_val key = {
.length = tdb_key.dsize,
.data = tdb_key.dptr,
};
struct ldb_val data = {
.length = tdb_data.dsize,
.data = tdb_data.dptr,
};
return kv_ctx->parser(key, data, kv_ctx->ctx);
}
static int ltdb_tdb_parse_record(struct ltdb_private *ltdb,
struct ldb_val ldb_key,
int (*parser)(struct ldb_val key,
struct ldb_val data,
void *private_data),
void *ctx)
{
return tdb_parse_record(ltdb->tdb, key, parser, ctx);
struct kv_ctx kv_ctx = {
.parser = parser,
.ctx = ctx,
.ltdb = ltdb
};
TDB_DATA key = {
.dptr = ldb_key.data,
.dsize = ldb_key.length
};
return tdb_parse_record(ltdb->tdb, key, ltdb_tdb_parse_record_wrapper,
&kv_ctx);
}
static const char * ltdb_tdb_name(struct ltdb_private *ltdb)

View File

@ -15,8 +15,8 @@ struct kv_db_ops {
int (*iterate)(struct ltdb_private *ltdb, ldb_kv_traverse_fn fn, void *ctx);
int (*update_in_iterate)(struct ltdb_private *ltdb, struct ldb_val key,
struct ldb_val key2, struct ldb_val data, void *ctx);
int (*fetch_and_parse)(struct ltdb_private *ltdb, TDB_DATA key,
int (*parser)(TDB_DATA key, TDB_DATA data,
int (*fetch_and_parse)(struct ltdb_private *ltdb, struct ldb_val key,
int (*parser)(struct ldb_val key, struct ldb_val data,
void *private_data),
void *ctx);
int (*lock_read)(struct ldb_module *);