static int ldb_kv_delete_internal(struct ldb_module *module, struct ldb_dn *dn)
{
	struct ldb_message *msg;
	int ret = LDB_SUCCESS;

	msg = ldb_msg_new(module);
	if (msg == NULL) {
		return LDB_ERR_OPERATIONS_ERROR;
	}

	/* in case any attribute of the message was indexed, we need
	   to fetch the old record */
	ret = ldb_kv_search_dn1(module, dn, msg, 0);
	if (ret != LDB_SUCCESS) {
		/* not finding the old record is an error */
		goto done;
	}

	ret = ldb_kv_delete_noindex(module, msg);
	if (ret != LDB_SUCCESS) {
		goto done;
	}

	/* remove any indexed attributes */
	ret = ldb_kv_index_delete(module, msg);
	if (ret != LDB_SUCCESS) {
		goto done;
	}

	ret = ldb_kv_modified(module, dn);
	if (ret != LDB_SUCCESS) {
		goto done;
	}

done:
	talloc_free(msg);
	/*
	 * To allow testing of the error recovery code in ldb_kv_delete
	 * cmocka tests can define CMOCKA_UNIT_TEST_DELETE_INTERNAL_FAIL
	 * to inject failures at this point.
	 */
#ifdef CMOCKA_UNIT_TEST_DELETE_INTERNAL_FAIL
	CMOCKA_UNIT_TEST_DELETE_INTERNAL_FAIL
#endif
	return ret;
}
static int ldb_kv_delete_internal(struct ldb_module *module, struct ldb_dn *dn)
{
	struct ldb_message *msg;
	int ret = LDB_SUCCESS;

	msg = ldb_msg_new(module);
	if (msg == NULL) {
		return LDB_ERR_OPERATIONS_ERROR;
	}

	 
	ret = ldb_kv_search_dn1(module, dn, msg, 0);
	if (ret != LDB_SUCCESS) {
		 
		goto done;
	}

	ret = ldb_kv_delete_noindex(module, msg);
	if (ret != LDB_SUCCESS) {
		goto done;
	}

	 
	ret = ldb_kv_index_delete(module, msg);
	if (ret != LDB_SUCCESS) {
		goto done;
	}

	ret = ldb_kv_modified(module, dn);
	if (ret != LDB_SUCCESS) {
		goto done;
	}

done:
	talloc_free(msg);
	 
#ifdef CMOCKA_UNIT_TEST_DELETE_INTERNAL_FAIL
	CMOCKA_UNIT_TEST_DELETE_INTERNAL_FAIL
#endif
	return ret;
}