summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/util/util_tdb.c15
-rw-r--r--lib/util/util_tdb.h1
2 files changed, 16 insertions, 0 deletions
diff --git a/lib/util/util_tdb.c b/lib/util/util_tdb.c
index c005c82791..93df958f1a 100644
--- a/lib/util/util_tdb.c
+++ b/lib/util/util_tdb.c
@@ -63,6 +63,21 @@ TDB_DATA string_term_tdb_data(const char *string)
return make_tdb_data((const uint8_t *)string, string ? strlen(string) + 1 : 0);
}
+TDB_DATA tdb_data_talloc_copy(TALLOC_CTX* mem_ctx, TDB_DATA data) {
+ TDB_DATA ret = {
+ .dptr = (uint8_t *)talloc_size(mem_ctx, data.dsize+1),
+ .dsize = data.dsize
+ };
+ if (ret.dptr == NULL) {
+ ret.dsize = 0;
+ } else {
+ memcpy(ret.dptr, data.dptr, data.dsize);
+ ret.dptr[ret.dsize] = '\0';
+ }
+ return ret;
+}
+
+
/****************************************************************************
Lock a chain by string. Return non-zero if lock failed.
****************************************************************************/
diff --git a/lib/util/util_tdb.h b/lib/util/util_tdb.h
index d8a2333035..630bdf669b 100644
--- a/lib/util/util_tdb.h
+++ b/lib/util/util_tdb.h
@@ -30,6 +30,7 @@ bool tdb_data_equal(TDB_DATA t1, TDB_DATA t2);
bool tdb_data_is_empty(TDB_DATA d);
TDB_DATA string_tdb_data(const char *string);
TDB_DATA string_term_tdb_data(const char *string);
+TDB_DATA tdb_data_talloc_copy(TALLOC_CTX* mem_ctx, TDB_DATA data);
/****************************************************************************
Lock a chain by string. Return non-zero if lock failed.