summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Beck <gbeck@sernet.de>2013-03-20 09:56:54 +0100
committerMichael Adam <obnox@samba.org>2013-04-18 13:15:11 +0200
commit037f57e12fb7b87e0c5c035ae85cb698bca64f4d (patch)
treea07e5a11db3116f674e8fcdb1e1b294996a713c3
parent450ebe97d1c36a8041e3567c0b1fe94822909ea2 (diff)
downloadsamba-037f57e12fb7b87e0c5c035ae85cb698bca64f4d.tar.gz
samba-037f57e12fb7b87e0c5c035ae85cb698bca64f4d.tar.bz2
samba-037f57e12fb7b87e0c5c035ae85cb698bca64f4d.zip
util_tdb: add function tdb_data_string()
Signed-off-by: Gregor Beck <gbeck@sernet.de> Reviewed-by: Michael Adam <obnox@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
-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;
+}