From 037f57e12fb7b87e0c5c035ae85cb698bca64f4d Mon Sep 17 00:00:00 2001 From: Gregor Beck Date: Wed, 20 Mar 2013 09:56:54 +0100 Subject: [PATCH] util_tdb: add function tdb_data_string() Signed-off-by: Gregor Beck Reviewed-by: Michael Adam Reviewed-by: Stefan Metzmacher --- source3/include/util_tdb.h | 2 ++ source3/lib/util_tdb.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/source3/include/util_tdb.h b/source3/include/util_tdb.h index e350413cf9..c9e9e409c4 100644 --- a/source3/include/util_tdb.h +++ b/source3/include/util_tdb.h @@ -44,4 +44,6 @@ NTSTATUS map_nt_error_from_tdb(enum TDB_ERROR err); int tdb_data_cmp(TDB_DATA t1, TDB_DATA t2); +char *tdb_data_string(TALLOC_CTX *mem_ctx, TDB_DATA d); + #endif /* __TDBUTIL_H__ */ diff --git a/source3/lib/util_tdb.c b/source3/lib/util_tdb.c index 8bfc75f18b..440c28b98d 100644 --- a/source3/lib/util_tdb.c +++ b/source3/lib/util_tdb.c @@ -22,6 +22,7 @@ #include "includes.h" #include "system/filesys.h" #include "util_tdb.h" +#include "cbuf.h" #undef malloc #undef realloc @@ -418,3 +419,35 @@ int tdb_data_cmp(TDB_DATA t1, TDB_DATA t2) } return ret; } + +char *tdb_data_string(TALLOC_CTX *mem_ctx, TDB_DATA d) +{ + int len; + char *ret = NULL; + cbuf *ost = cbuf_new(mem_ctx); + + if (ost == NULL) { + return NULL; + } + + len = cbuf_printf(ost, "%d:"); + if (len == -1) { + goto done; + } + + if (d.dptr == NULL) { + len = cbuf_puts(ost, "", -1); + } else { + len = cbuf_print_quoted(ost, (const char*)d.dptr, d.dsize); + } + if (len == -1) { + goto done; + } + + cbuf_swapptr(ost, &ret, 0); + talloc_steal(mem_ctx, ret); + +done: + talloc_free(ost); + return ret; +} -- 2.34.1