static int ldb_kv_rename_internal(struct ldb_module *module,
			   struct ldb_request *req,
			   struct ldb_message *msg)
{
	void *data = ldb_module_get_private(module);
	struct ldb_kv_private *ldb_kv =
	    talloc_get_type(data, struct ldb_kv_private);
	int ret = LDB_SUCCESS;

	/* Always delete first then add, to avoid conflicts with
	 * unique indexes. We rely on the transaction to make this
	 * atomic
	 */
	ret = ldb_kv_delete_internal(module, msg->dn);
	if (ret != LDB_SUCCESS) {
		return ret;
	}

	msg->dn = ldb_dn_copy(msg, req->op.rename.newdn);
	if (msg->dn == NULL) {
		return LDB_ERR_OPERATIONS_ERROR;
	}

	/* We don't check single value as we can have more than 1 with
	 * deleted attributes. We could go through all elements but that's
	 * maybe not the most efficient way
	 */
	ret = ldb_kv_add_internal(module, ldb_kv, msg, false);

	/*
	 * To allow testing of the error recovery code in ldb_kv_rename
	 * cmocka tests can define CMOCKA_UNIT_TEST_RENAME_INTERNAL_FAIL
	 * to inject failures at this point.
	 */
#ifdef CMOCKA_UNIT_TEST_RENAME_INTERNAL_FAIL
	CMOCKA_UNIT_TEST_RENAME_INTERNAL_FAIL
#endif
	return ret;
}
static int ldb_kv_rename_internal(struct ldb_module *module,
			   struct ldb_request *req,
			   struct ldb_message *msg)
{
	void *data = ldb_module_get_private(module);
	struct ldb_kv_private *ldb_kv =
	    talloc_get_type(data, struct ldb_kv_private);
	int ret = LDB_SUCCESS;

	 
	ret = ldb_kv_delete_internal(module, msg->dn);
	if (ret != LDB_SUCCESS) {
		return ret;
	}

	msg->dn = ldb_dn_copy(msg, req->op.rename.newdn);
	if (msg->dn == NULL) {
		return LDB_ERR_OPERATIONS_ERROR;
	}

	 
	ret = ldb_kv_add_internal(module, ldb_kv, msg, false);

	 
#ifdef CMOCKA_UNIT_TEST_RENAME_INTERNAL_FAIL
	CMOCKA_UNIT_TEST_RENAME_INTERNAL_FAIL
#endif
	return ret;
}