summaryrefslogtreecommitdiff
path: root/source3/passdb
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2008-04-01 11:02:01 +0200
committerStefan Metzmacher <metze@samba.org>2008-04-01 14:04:20 +0200
commit663eb087e6ec3cd86345821ac08f22f625677d58 (patch)
tree58d76efe7079756b7378667b00e6402501490be3 /source3/passdb
parenta5f3911d70ed1401f24914090246d14e40d798d8 (diff)
downloadsamba-663eb087e6ec3cd86345821ac08f22f625677d58.tar.gz
samba-663eb087e6ec3cd86345821ac08f22f625677d58.tar.bz2
samba-663eb087e6ec3cd86345821ac08f22f625677d58.zip
passdb: guard pdb_generate_sam_sid() with a transaction
This prevents possible races with some dbwrap backends metze (This used to be commit 9322442510d9c2cf16c25f5109fe81b277c44881)
Diffstat (limited to 'source3/passdb')
-rw-r--r--source3/passdb/machine_sid.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/source3/passdb/machine_sid.c b/source3/passdb/machine_sid.c
index 8fafcbbbd4..ff2c9bcb0d 100644
--- a/source3/passdb/machine_sid.c
+++ b/source3/passdb/machine_sid.c
@@ -181,16 +181,38 @@ static DOM_SID *pdb_generate_sam_sid(void)
/* return our global_sam_sid */
DOM_SID *get_global_sam_sid(void)
{
+ struct db_context *db;
+
if (global_sam_sid != NULL)
return global_sam_sid;
- /* memory for global_sam_sid is allocated in
- pdb_generate_sam_sid() as needed */
+ /*
+ * memory for global_sam_sid is allocated in
+ * pdb_generate_sam_sid() as needed
+ *
+ * Note: this is garded by a transaction
+ * to prevent races on startup which
+ * can happen with some dbwrap backends
+ */
+
+ db = secrets_db_ctx();
+ if (!db) {
+ smb_panic("could not open secrets db");
+ }
+
+ if (db->transaction_start(db) != 0) {
+ smb_panic("could not start transaction on secrets db");
+ }
if (!(global_sam_sid = pdb_generate_sam_sid())) {
+ db->transaction_cancel(db);
smb_panic("could not generate a machine SID");
}
+ if (db->transaction_commit(db) != 0) {
+ smb_panic("could not start commit secrets db");
+ }
+
return global_sam_sid;
}