summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2012-04-11 15:48:02 +0200
committerAndreas Schneider <asn@samba.org>2012-04-25 14:31:11 +0200
commit7ea8bd3605adb3a53ca44ebdabfdcdb9c1aeaa18 (patch)
treef2391dbe4b5a8f19a42d9c8635a59f3cb25a4f95
parentab83005b30c621230db674faa1d123f44c9122e7 (diff)
downloadsamba-7ea8bd3605adb3a53ca44ebdabfdcdb9c1aeaa18.tar.gz
samba-7ea8bd3605adb3a53ca44ebdabfdcdb9c1aeaa18.tar.bz2
samba-7ea8bd3605adb3a53ca44ebdabfdcdb9c1aeaa18.zip
s3:registry: fix seqnum race in fetch_values_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>
-rw-r--r--source3/registry/reg_backend_db.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/source3/registry/reg_backend_db.c b/source3/registry/reg_backend_db.c
index 65355aec23..abe9f7bdca 100644
--- a/source3/registry/reg_backend_db.c
+++ b/source3/registry/reg_backend_db.c
@@ -1862,6 +1862,7 @@ static int regdb_fetch_values_internal(struct db_context *db, const char* key,
int ret = 0;
TDB_DATA value;
WERROR werr;
+ int seqnum[2], count;
DEBUG(10,("regdb_fetch_values: Looking for values of key [%s]\n", key));
@@ -1874,10 +1875,27 @@ static int regdb_fetch_values_internal(struct db_context *db, const char* key,
goto done;
}
- werr = regval_ctr_set_seqnum(values, dbwrap_get_seqnum(db));
- W_ERROR_NOT_OK_GOTO_DONE(werr);
+ ZERO_STRUCT(value);
+ count = 0;
+ seqnum[0] = dbwrap_get_seqnum(db);
+
+ do {
+ count++;
+ TALLOC_FREE(value.dptr);
+ value = regdb_fetch_key_internal(db, ctx, keystr);
+ seqnum[count % 2] = dbwrap_get_seqnum(db);
+ } while (seqnum[0] != seqnum[1]);
+
+ if (count > 1) {
+ DEBUG(5, ("regdb_fetch_values_internal: it took %d attempts "
+ "to fetch key '%s' with constant seqnum\n",
+ count, key));
+ }
- value = regdb_fetch_key_internal(db, ctx, keystr);
+ werr = regval_ctr_set_seqnum(values, seqnum[0]);
+ if (!W_ERROR_IS_OK(werr)) {
+ goto done;
+ }
if (!value.dptr) {
/* all keys have zero values by default */