diff options
author | Michael Adam <obnox@samba.org> | 2012-04-11 15:51:40 +0200 |
---|---|---|
committer | Andreas Schneider <asn@samba.org> | 2012-04-25 14:31:11 +0200 |
commit | 22451f7f45c1f692dc9d40af0e6ce82666359390 (patch) | |
tree | f813a407c8869e3b9ce964e511dd641f9b0d71c2 /source3/registry | |
parent | 7ea8bd3605adb3a53ca44ebdabfdcdb9c1aeaa18 (diff) | |
download | samba-22451f7f45c1f692dc9d40af0e6ce82666359390.tar.gz samba-22451f7f45c1f692dc9d40af0e6ce82666359390.tar.bz2 samba-22451f7f45c1f692dc9d40af0e6ce82666359390.zip |
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>
Diffstat (limited to 'source3/registry')
-rw-r--r-- | source3/registry/reg_backend_db.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/source3/registry/reg_backend_db.c b/source3/registry/reg_backend_db.c index abe9f7bdca..ed7fe4d116 100644 --- a/source3/registry/reg_backend_db.c +++ b/source3/registry/reg_backend_db.c @@ -1712,6 +1712,7 @@ static WERROR regdb_fetch_keys_internal(struct db_context *db, const char *key, fstring subkeyname; TALLOC_CTX *frame = talloc_stackframe(); TDB_DATA value; + int seqnum[2], count; 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); W_ERROR_NOT_OK_GOTO_DONE(werr); - werr = regsubkey_ctr_set_seqnum(ctr, dbwrap_get_seqnum(db)); - W_ERROR_NOT_OK_GOTO_DONE(werr); + count = 0; + ZERO_STRUCT(value); + seqnum[0] = dbwrap_get_seqnum(db); + + do { + count++; + TALLOC_FREE(value.dptr); + value = regdb_fetch_key_internal(db, frame, key); + seqnum[count % 2] = dbwrap_get_seqnum(db); - value = regdb_fetch_key_internal(db, frame, key); + } 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) { DEBUG(10, ("regdb_fetch_keys: no subkeys found for key [%s]\n", |