From: Volker Lendecke Date: Fri, 2 Dec 2016 15:37:49 +0000 (+0000) Subject: idmap_autorid: Fix a race condition when acquiring ranges X-Git-Tag: samba-4.6.0rc1~242 X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=9c6c2ad26d1936f8a731b18198b47e35e4938d96;p=samba.git idmap_autorid: Fix a race condition when acquiring ranges Here we are in a transaction to create a range, but we already found one to exist. We need to return the information about this range to the caller, just as we do when actually allocating the range. This does not hit us with current code, as we just have one idmap child. However, if we parallelize that, two children might have found a domain to not exist and call idmap_autorid_acquire_range simultaneously. One will create the range, the other one will find it to already exist. The second child will also have to pass the info up. Signed-off-by: Volker Lendecke Reviewed-by: Andreas Schneider --- diff --git a/source3/winbindd/idmap_autorid_tdb.c b/source3/winbindd/idmap_autorid_tdb.c index 3386380cda4..702a2f6f369 100644 --- a/source3/winbindd/idmap_autorid_tdb.c +++ b/source3/winbindd/idmap_autorid_tdb.c @@ -127,6 +127,26 @@ static NTSTATUS idmap_autorid_addrange_action(struct db_context *db, if (acquire) { DEBUG(10, ("domain range already allocated - " "Not adding!\n")); + + mem_ctx = talloc_stackframe(); + + ret = idmap_autorid_loadconfig(db, mem_ctx, + &globalcfg); + if (!NT_STATUS_IS_OK(ret)) { + DEBUG(1, ("Fatal error while fetching " + "configuration: %s\n", + nt_errstr(ret))); + goto error; + } + + range->rangenum = stored_rangenum; + range->low_id = globalcfg->minvalue + + range->rangenum * globalcfg->rangesize; + range->high_id = + range->low_id + globalcfg->rangesize - 1; + + TALLOC_FREE(mem_ctx); + return NT_STATUS_OK; }