ridalloc: Don't skip the first RID of a pool
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Tue, 1 Jun 2021 00:03:38 +0000 (12:03 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 11 Jun 2021 07:41:38 +0000 (07:41 +0000)
Previously, if either of the rIDPreviousAllocation and rIDNextRID
attributes were not present in a RID Set, the first RID in
rIDAllocationPool was skipped over when determining their values.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/samdb.py
python/samba/tests/dsdb.py
source4/dsdb/samdb/ldb_modules/ridalloc.c

index 66e95edff78d16d94c425b3b0a5fe435aa3aede8..424d6d2e88ae1e45bb0ca09478a3053dc8982a26 100644 (file)
@@ -1469,8 +1469,8 @@ schemaUpdateNow: 1
         if prev_pool == uint64_max or next_rid == uint32_max:
             prev_pool = alloc_pool
             next_rid = prev_pool & uint32_max
-
-        next_rid += 1
+        else:
+            next_rid += 1
 
         # Now check if our current pool is still usable
         prev_pool_lo = prev_pool & uint32_max
index f1d0557743ebe37348b14a8b6dab93c01630c010..f4f7a7056268864948f31a9d62e284cbf31c2488 100644 (file)
@@ -136,10 +136,9 @@ class DsdbTests(TestCase):
                                    "rIDAllocationPool"))
             self.samdb.modify(msg)
 
-            # Ensure that next_free_rid() returns the start of the next pool
-            # plus one.
+            # Ensure that next_free_rid() returns the start of the next pool.
             next_free_rid3 = self.samdb.next_free_rid()
-            self.assertEqual(next_lo + 1, next_free_rid3)
+            self.assertEqual(next_lo, next_free_rid3)
 
             # Check the result of allocate_rid() matches.
             rid = self.samdb.allocate_rid()
index b436b9b5435e996ca9b487bdde6bc13a8e515dd3..072a434b18d0f84a92c4985ee111c5da5516e2c6 100644 (file)
@@ -594,12 +594,13 @@ int ridalloc_allocate_rid(struct ldb_module *module, uint32_t *rid, struct ldb_r
            nridset.next_rid == UINT32_MAX) {
                nridset.prev_pool = nridset.alloc_pool;
                nridset.next_rid = nridset.prev_pool & 0xFFFFFFFF;
+       } else {
+               nridset.next_rid += 1;
        }
 
        /*
         * 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) {