mirror of
https://github.com/samba-team/samba.git
synced 2025-01-12 09:18:10 +03:00
s3:registry: fix seqnum race in regdb_fetch_keys_internal
This prevents race between fetching seqnum and key content. Because there is currently no way to atomically fetch the record along with the seqnum, I use a loop. This is far from optimal and should should ideally be done differently. But for now it fixes the race. Signed-off-by: Andreas Schneider <asn@samba.org>
This commit is contained in:
parent
7ea8bd3605
commit
22451f7f45
@ -1712,6 +1712,7 @@ static WERROR regdb_fetch_keys_internal(struct db_context *db, const char *key,
|
|||||||
fstring subkeyname;
|
fstring subkeyname;
|
||||||
TALLOC_CTX *frame = talloc_stackframe();
|
TALLOC_CTX *frame = talloc_stackframe();
|
||||||
TDB_DATA value;
|
TDB_DATA value;
|
||||||
|
int seqnum[2], count;
|
||||||
|
|
||||||
DEBUG(11,("regdb_fetch_keys: Enter key => [%s]\n", key ? key : "NULL"));
|
DEBUG(11,("regdb_fetch_keys: Enter key => [%s]\n", key ? key : "NULL"));
|
||||||
|
|
||||||
@ -1724,10 +1725,28 @@ static WERROR regdb_fetch_keys_internal(struct db_context *db, const char *key,
|
|||||||
werr = regsubkey_ctr_reinit(ctr);
|
werr = regsubkey_ctr_reinit(ctr);
|
||||||
W_ERROR_NOT_OK_GOTO_DONE(werr);
|
W_ERROR_NOT_OK_GOTO_DONE(werr);
|
||||||
|
|
||||||
werr = regsubkey_ctr_set_seqnum(ctr, dbwrap_get_seqnum(db));
|
count = 0;
|
||||||
W_ERROR_NOT_OK_GOTO_DONE(werr);
|
ZERO_STRUCT(value);
|
||||||
|
seqnum[0] = dbwrap_get_seqnum(db);
|
||||||
|
|
||||||
value = regdb_fetch_key_internal(db, frame, key);
|
do {
|
||||||
|
count++;
|
||||||
|
TALLOC_FREE(value.dptr);
|
||||||
|
value = regdb_fetch_key_internal(db, frame, key);
|
||||||
|
seqnum[count % 2] = dbwrap_get_seqnum(db);
|
||||||
|
|
||||||
|
} while (seqnum[0] != seqnum[1]);
|
||||||
|
|
||||||
|
if (count > 1) {
|
||||||
|
DEBUG(5, ("regdb_fetch_keys_internal: it took %d attempts to "
|
||||||
|
"fetch key '%s' with constant seqnum\n",
|
||||||
|
count, key));
|
||||||
|
}
|
||||||
|
|
||||||
|
werr = regsubkey_ctr_set_seqnum(ctr, seqnum[0]);
|
||||||
|
if (!W_ERROR_IS_OK(werr)) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
if (value.dsize == 0 || value.dptr == NULL) {
|
if (value.dsize == 0 || value.dptr == NULL) {
|
||||||
DEBUG(10, ("regdb_fetch_keys: no subkeys found for key [%s]\n",
|
DEBUG(10, ("regdb_fetch_keys: no subkeys found for key [%s]\n",
|
||||||
|
Loading…
Reference in New Issue
Block a user