diff options
author | Andrew Bartlett <abartlet@samba.org> | 2017-08-16 12:51:09 +1200 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2017-08-29 11:13:50 +0200 |
commit | 3164c0ac54685d6ae430e2cb3bb50a9ad7f3e7fc (patch) | |
tree | 55dae35c5417240756569590d24d91c652f293ef | |
parent | bff81a2c9cc43a2cfec822dde94944d0295dd87f (diff) | |
download | samba-3164c0ac54685d6ae430e2cb3bb50a9ad7f3e7fc.tar.gz |
ldb_tdb: Rework ltdb_modify_internal() to use ltdb_search_dn1() internally
This avoids duplicate code and allows us to use the allocation-avoiding
LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC flag.
We can not use LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC as el2->values
is talloc_realloc()ed in the routine.
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Tue Aug 29 11:13:50 CEST 2017 on sn-devel-144
-rw-r--r-- | lib/ldb/ldb_tdb/ldb_tdb.c | 40 |
1 files changed, 11 insertions, 29 deletions
diff --git a/lib/ldb/ldb_tdb/ldb_tdb.c b/lib/ldb/ldb_tdb/ldb_tdb.c index 2ac1967ee15..bc8780ad7ee 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/lib/ldb/ldb_tdb/ldb_tdb.c @@ -686,52 +686,34 @@ int ltdb_modify_internal(struct ldb_module *module, struct ldb_request *req) { struct ldb_context *ldb = ldb_module_get_ctx(module); - void *data = ldb_module_get_private(module); - struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); - TDB_DATA tdb_key, tdb_data; - struct ldb_val ldb_data; struct ldb_message *msg2; unsigned int i, j; int ret = LDB_SUCCESS, idx; struct ldb_control *control_permissive = NULL; + TALLOC_CTX *mem_ctx = talloc_new(req); + if (mem_ctx == NULL) { + return ldb_module_oom(module); + } + if (req) { control_permissive = ldb_request_get_control(req, LDB_CONTROL_PERMISSIVE_MODIFY_OID); } - tdb_key = ltdb_key(module, msg->dn); - if (!tdb_key.dptr) { - return LDB_ERR_OTHER; - } - - tdb_data = tdb_fetch(ltdb->tdb, tdb_key); - if (!tdb_data.dptr) { - talloc_free(tdb_key.dptr); - return ltdb_err_map(tdb_error(ltdb->tdb)); - } - - msg2 = ldb_msg_new(tdb_key.dptr); + msg2 = ldb_msg_new(mem_ctx); if (msg2 == NULL) { - free(tdb_data.dptr); ret = LDB_ERR_OTHER; goto done; } - ldb_data.data = tdb_data.dptr; - ldb_data.length = tdb_data.dsize; - - ret = ldb_unpack_data(ldb_module_get_ctx(module), &ldb_data, msg2); - free(tdb_data.dptr); - if (ret == -1) { - ret = LDB_ERR_OTHER; + ret = ltdb_search_dn1(module, msg->dn, + msg2, + LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC); + if (ret != LDB_SUCCESS) { goto done; } - if (!msg2->dn) { - msg2->dn = msg->dn; - } - for (i=0; i<msg->num_elements; i++) { struct ldb_message_element *el = &msg->elements[i], *el2; struct ldb_val *vals; @@ -1018,7 +1000,7 @@ int ltdb_modify_internal(struct ldb_module *module, } done: - talloc_free(tdb_key.dptr); + TALLOC_FREE(mem_ctx); return ret; } |