summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/lib/dbwrap_util.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/source3/lib/dbwrap_util.c b/source3/lib/dbwrap_util.c
index fe3060c89a..118d681eb9 100644
--- a/source3/lib/dbwrap_util.c
+++ b/source3/lib/dbwrap_util.c
@@ -106,30 +106,40 @@ int dbwrap_store_uint32(struct db_context *db, const char *keystr, uint32_t v)
* return old value in *oldval.
* store *oldval + change_val to db.
*/
-NTSTATUS dbwrap_change_uint32_atomic(struct db_context *db, const char *keystr,
- uint32_t *oldval, uint32_t change_val)
+
+struct dbwrap_change_uint32_atomic_context {
+ const char *keystr;
+ uint32_t *oldval;
+ uint32_t change_val;
+};
+
+static NTSTATUS dbwrap_change_uint32_atomic_action(struct db_context *db,
+ void *private_data)
{
struct db_record *rec;
uint32 val = -1;
TDB_DATA data;
NTSTATUS ret;
+ struct dbwrap_change_uint32_atomic_context *state;
- rec = db->fetch_locked(db, NULL, string_term_tdb_data(keystr));
+ state = (struct dbwrap_change_uint32_atomic_context *)private_data;
+
+ rec = db->fetch_locked(db, NULL, string_term_tdb_data(state->keystr));
if (!rec) {
return NT_STATUS_UNSUCCESSFUL;
}
if (rec->value.dptr == NULL) {
- val = *oldval;
+ val = *(state->oldval);
} else if (rec->value.dsize == sizeof(val)) {
val = IVAL(rec->value.dptr, 0);
- *oldval = val;
+ *(state->oldval) = val;
} else {
ret = NT_STATUS_UNSUCCESSFUL;
goto done;
}
- val += change_val;
+ val += state->change_val;
data.dsize = sizeof(val);
data.dptr = (uint8 *)&val;
@@ -141,6 +151,21 @@ done:
return ret;
}
+NTSTATUS dbwrap_change_uint32_atomic(struct db_context *db, const char *keystr,
+ uint32_t *oldval, uint32_t change_val)
+{
+ NTSTATUS ret;
+ struct dbwrap_change_uint32_atomic_context state;
+
+ state.keystr = keystr;
+ state.oldval = oldval;
+ state.change_val = change_val;
+
+ ret = dbwrap_change_uint32_atomic_action(db, &state);
+
+ return ret;
+}
+
/**
* Atomic integer change (addition):
*