1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

lib: Add tdb_fetch_talloc

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
Volker Lendecke 2014-10-21 10:39:53 +00:00 committed by Jeremy Allison
parent 7be1dfa05c
commit b306f16564
2 changed files with 36 additions and 0 deletions

View File

@ -483,3 +483,36 @@ int map_unix_error_from_tdb(enum TDB_ERROR err)
};
return result;
}
struct tdb_fetch_talloc_state {
TALLOC_CTX *mem_ctx;
uint8_t *buf;
};
static int tdb_fetch_talloc_parser(TDB_DATA key, TDB_DATA data,
void *private_data)
{
struct tdb_fetch_talloc_state *state = private_data;
state->buf = talloc_memdup(state->mem_ctx, data.dptr, data.dsize);
return 0;
}
int tdb_fetch_talloc(struct tdb_context *tdb, TDB_DATA key,
TALLOC_CTX *mem_ctx, uint8_t **buf)
{
struct tdb_fetch_talloc_state state = { .mem_ctx = mem_ctx };
int ret;
ret = tdb_parse_record(tdb, key, tdb_fetch_talloc_parser, &state);
if (ret == -1) {
enum TDB_ERROR err = tdb_error(tdb);
return map_unix_error_from_tdb(err);
}
if (state.buf == NULL) {
return ENOMEM;
}
*buf = state.buf;
return 0;
}

View File

@ -145,4 +145,7 @@ NTSTATUS map_nt_error_from_tdb(enum TDB_ERROR err);
int map_unix_error_from_tdb(enum TDB_ERROR err);
int tdb_fetch_talloc(struct tdb_context *tdb, TDB_DATA key,
TALLOC_CTX *mem_ctx, uint8_t **buf);
#endif /* _____LIB_UTIL_UTIL_TDB_H__ */