diff options
author | Volker Lendecke <vl@samba.org> | 2014-10-21 10:39:53 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2014-12-16 18:56:03 +0100 |
commit | b306f165648b54c8b302974e1938d694c571b23a (patch) | |
tree | fb727202a28c9e60fddb4040f60b9e61d9370146 /lib | |
parent | 7be1dfa05c6b3c9077f09fd29f6ffdd8ea4011ec (diff) | |
download | samba-b306f165648b54c8b302974e1938d694c571b23a.tar.gz samba-b306f165648b54c8b302974e1938d694c571b23a.tar.xz samba-b306f165648b54c8b302974e1938d694c571b23a.zip |
lib: Add tdb_fetch_talloc
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util/util_tdb.c | 33 | ||||
-rw-r--r-- | lib/util/util_tdb.h | 3 |
2 files changed, 36 insertions, 0 deletions
diff --git a/lib/util/util_tdb.c b/lib/util/util_tdb.c index f84ab3314e..9bf18dc092 100644 --- a/lib/util/util_tdb.c +++ b/lib/util/util_tdb.c @@ -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; +} diff --git a/lib/util/util_tdb.h b/lib/util/util_tdb.h index 7a457f736f..3b50789b01 100644 --- a/lib/util/util_tdb.h +++ b/lib/util/util_tdb.h @@ -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__ */ |