summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/include/util_tdb.h2
-rw-r--r--source3/lib/util_tdb.c33
2 files changed, 35 insertions, 0 deletions
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, "<NULL>", -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;
+}