From 2a3b82ae2373c39a0a113d75a27a196b5233fe32 Mon Sep 17 00:00:00 2001 From: Joseph Sutton Date: Tue, 1 Jun 2021 12:03:38 +1200 Subject: [PATCH] ridalloc: Don't skip the first RID of a pool 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 Reviewed-by: Andrew Bartlett Reviewed-by: Douglas Bagnall --- python/samba/samdb.py | 4 ++-- python/samba/tests/dsdb.py | 5 ++--- source4/dsdb/samdb/ldb_modules/ridalloc.c | 3 ++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/python/samba/samdb.py b/python/samba/samdb.py index 66e95edff78..424d6d2e88a 100644 --- a/python/samba/samdb.py +++ b/python/samba/samdb.py @@ -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 diff --git a/python/samba/tests/dsdb.py b/python/samba/tests/dsdb.py index f1d0557743e..f4f7a705626 100644 --- a/python/samba/tests/dsdb.py +++ b/python/samba/tests/dsdb.py @@ -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() diff --git a/source4/dsdb/samdb/ldb_modules/ridalloc.c b/source4/dsdb/samdb/ldb_modules/ridalloc.c index b436b9b5435..072a434b18d 100644 --- a/source4/dsdb/samdb/ldb_modules/ridalloc.c +++ b/source4/dsdb/samdb/ldb_modules/ridalloc.c @@ -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) { -- 2.34.1