summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2009-01-25 00:48:34 +0100
committerMichael Adam <obnox@samba.org>2009-02-06 10:20:06 +0100
commite4035ab304208ebb1876b1485291a048564b0c27 (patch)
treeb2dc4f5b5d0d6ce9ba72ed498abe122c25f33320
parenta9184d5c62c2c89cf473e189c8beeed6fa7da1b2 (diff)
downloadsamba-e4035ab304208ebb1876b1485291a048564b0c27.tar.gz
samba-e4035ab304208ebb1876b1485291a048564b0c27.tar.bz2
samba-e4035ab304208ebb1876b1485291a048564b0c27.zip
s3:idmap_tdb: use transactions in idmap_tdb_allocate_id()
Michael
-rw-r--r--source3/winbindd/idmap_tdb.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/source3/winbindd/idmap_tdb.c b/source3/winbindd/idmap_tdb.c
index f2557cc2e6..8e7137d579 100644
--- a/source3/winbindd/idmap_tdb.c
+++ b/source3/winbindd/idmap_tdb.c
@@ -402,6 +402,7 @@ static NTSTATUS idmap_tdb_allocate_id(struct unixid *xid)
const char *hwmtype;
uint32_t high_hwm;
uint32_t hwm;
+ int res;
/* Get current high water mark */
switch (xid->type) {
@@ -423,7 +424,14 @@ static NTSTATUS idmap_tdb_allocate_id(struct unixid *xid)
return NT_STATUS_INVALID_PARAMETER;
}
+ res = idmap_alloc_db->transaction_start(idmap_alloc_db);
+ if (res != 0) {
+ DEBUG(1, (__location__ " Failed to start transaction.\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
if ((hwm = dbwrap_fetch_int32(idmap_alloc_db, hwmkey)) == -1) {
+ idmap_alloc_db->transaction_cancel(idmap_alloc_db);
return NT_STATUS_INTERNAL_DB_ERROR;
}
@@ -431,6 +439,7 @@ static NTSTATUS idmap_tdb_allocate_id(struct unixid *xid)
if (hwm > high_hwm) {
DEBUG(1, ("Fatal Error: %s range full!! (max: %lu)\n",
hwmtype, (unsigned long)high_hwm));
+ idmap_alloc_db->transaction_cancel(idmap_alloc_db);
return NT_STATUS_UNSUCCESSFUL;
}
@@ -438,6 +447,7 @@ static NTSTATUS idmap_tdb_allocate_id(struct unixid *xid)
ret = dbwrap_change_uint32_atomic(idmap_alloc_db, hwmkey, &hwm, 1);
if (ret != 0) {
DEBUG(0, ("Fatal error while fetching a new %s value\n!", hwmtype));
+ idmap_alloc_db->transaction_cancel(idmap_alloc_db);
return NT_STATUS_UNSUCCESSFUL;
}
@@ -445,9 +455,16 @@ static NTSTATUS idmap_tdb_allocate_id(struct unixid *xid)
if (hwm > high_hwm) {
DEBUG(1, ("Fatal Error: %s range full!! (max: %lu)\n",
hwmtype, (unsigned long)high_hwm));
+ idmap_alloc_db->transaction_cancel(idmap_alloc_db);
return NT_STATUS_UNSUCCESSFUL;
}
-
+
+ res = idmap_alloc_db->transaction_commit(idmap_alloc_db);
+ if (res != 0) {
+ DEBUG(1, (__location__ " Failed to commit transaction.\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
xid->id = hwm;
DEBUG(10,("New %s = %d\n", hwmtype, hwm));