- prev_alloc_pool_lo = prev_alloc_pool & 0xFFFFFFFF;
- prev_alloc_pool_hi = prev_alloc_pool >> 32;
- if (prev_rid >= prev_alloc_pool_hi) {
- if (prev_alloc_pool == 0) {
- ret = dsdb_module_set_integer(module, rid_set_dn, "rIDPreviousAllocationPool", alloc_pool);
- } else {
- ret = dsdb_module_constrainted_update_integer(module, rid_set_dn, "rIDPreviousAllocationPool",
- prev_alloc_pool, alloc_pool);
- }
- if (ret != LDB_SUCCESS) {
- ldb_asprintf_errstring(ldb, __location__ ": Failed to update rIDPreviousAllocationPool on %s - %s",
- ldb_dn_get_linearized(rid_set_dn), ldb_errstring(ldb));
- talloc_free(tmp_ctx);
- return ret;
+ nridset = oridset;
+
+ /*
+ * If we never used a pool, setup out first pool
+ */
+ if (nridset.prev_pool == UINT64_MAX ||
+ nridset.next_rid == UINT32_MAX) {
+ nridset.prev_pool = nridset.alloc_pool;
+ nridset.next_rid = nridset.prev_pool & 0xFFFFFFFF;
+ }
+
+ /*
+ * Now check if our current pool is still usable
+ */
+ nridset.next_rid += 1;
+ prev_pool_lo = nridset.prev_pool & 0xFFFFFFFF;
+ prev_pool_hi = nridset.prev_pool >> 32;
+ if (nridset.next_rid > prev_pool_hi) {
+ /*
+ * We need a new pool, check if we already have a new one
+ * Otherwise we need to get a new pool.
+ */
+ if (nridset.alloc_pool == nridset.prev_pool) {
+ /*
+ * if we are the RID Manager,
+ * we can get a new pool localy.
+ * Otherwise we fail the operation and
+ * ask async for a new pool.
+ */
+ ret = ridalloc_new_own_pool(module, &nridset.alloc_pool);
+ if (ret == LDB_ERR_UNWILLING_TO_PERFORM) {
+ ridalloc_poke_rid_manager(module);
+ talloc_free(tmp_ctx);
+ return ret;
+ }
+ if (ret != LDB_SUCCESS) {
+ talloc_free(tmp_ctx);
+ return ret;
+ }