DN_LIST_WILL_BE_READ_ONLY = 1,
};
+struct ldb_dn_list_state {
+ struct ldb_module *module;
+ struct dn_list *list;
+};
+
+static int ldb_kv_index_idxptr_wrapper(TDB_DATA tdb_key,
+ TDB_DATA tdb_data,
+ void *private_data)
+{
+ struct ldb_dn_list_state *state = private_data;
+
+ /* The caller will check for NULL */
+ state->list = ldb_kv_index_idxptr(state->module, tdb_data);
+
+ return 0;
+}
+
/*
return the @IDX list in an index entry for a dn as a
struct dn_list
enum dn_list_will_be_read_only read_only)
{
struct ldb_message *msg;
- int ret, version;
+ int ret = -1, version;
struct ldb_message_element *el;
- TDB_DATA rec = {0};
- struct dn_list *list2;
bool from_primary_cache = false;
TDB_DATA key = {0};
+ struct ldb_dn_list_state state = {
+ .module = module,
+ };
*list = (struct dn_list){};
/*
* if the record is not cached it will need to be read from disk.
*/
if (ldb_kv->nested_idx_ptr != NULL) {
- rec = tdb_fetch(ldb_kv->nested_idx_ptr->itdb, key);
+ ret = tdb_parse_record(ldb_kv->nested_idx_ptr->itdb,
+ key,
+ ldb_kv_index_idxptr_wrapper,
+ &state);
}
- if (rec.dptr == NULL) {
+ if (ret == -1 /* not found */) {
from_primary_cache = true;
- rec = tdb_fetch(ldb_kv->idxptr->itdb, key);
+ ret = tdb_parse_record(ldb_kv->idxptr->itdb,
+ key,
+ ldb_kv_index_idxptr_wrapper,
+ &state);
}
- if (rec.dptr == NULL) {
+ if (ret == -1 /* not found */) {
goto normal_index;
}
- /* we've found an in-memory index entry */
- list2 = ldb_kv_index_idxptr(module, rec);
- if (list2 == NULL) {
- free(rec.dptr);
+ if (ret != 0 || state.list == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
}
- free(rec.dptr);
/*
* If this is a read only transaction the indexes will not be
* In this case make an early return
*/
if (read_only == DN_LIST_WILL_BE_READ_ONLY) {
- *list = *list2;
+ *list = *state.list;
return LDB_SUCCESS;
}
* already copied the primary cache record
*/
if (!from_primary_cache) {
- *list = *list2;
+ *list = *state.list;
return LDB_SUCCESS;
}
* No index sub transaction active, so no need to cache a copy
*/
if (ldb_kv->nested_idx_ptr == NULL) {
- *list = *list2;
+ *list = *state.list;
return LDB_SUCCESS;
}
* These acrobatics do not affect read-only operations.
*/
list->dn = talloc_memdup(list,
- list2->dn,
- talloc_get_size(list2->dn));
+ state.list->dn,
+ talloc_get_size(state.list->dn));
if (list->dn == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
}
- list->count = list2->count;
+ list->count = state.list->count;
return LDB_SUCCESS;
/*