summaryrefslogtreecommitdiff
path: root/source3/passdb
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2003-01-16 20:08:26 +0000
committerJeremy Allison <jra@samba.org>2003-01-16 20:08:26 +0000
commit6b2eb72df0bcf9143d013e64410ebde78d57b1c4 (patch)
tree95375431d54a8697750f0a12a04ef738cad166cc /source3/passdb
parent862d383781b5e3959e512df58714536f0374b92a (diff)
downloadsamba-6b2eb72df0bcf9143d013e64410ebde78d57b1c4.tar.gz
samba-6b2eb72df0bcf9143d013e64410ebde78d57b1c4.tar.bz2
samba-6b2eb72df0bcf9143d013e64410ebde78d57b1c4.zip
Fixed up mutex protection around winbindd logon code. Sync with APP-HEAD.
Jeremy. (This used to be commit daf179bcd6297b525bfc644efb154734723f4d58)
Diffstat (limited to 'source3/passdb')
-rw-r--r--source3/passdb/secrets.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/source3/passdb/secrets.c b/source3/passdb/secrets.c
index 5ba9f1dc1e..a52e264270 100644
--- a/source3/passdb/secrets.c
+++ b/source3/passdb/secrets.c
@@ -588,17 +588,24 @@ NTSTATUS secrets_get_trusted_domains(TALLOC_CTX* ctx, int* enum_ctx, int max_num
between smbd instances.
*******************************************************************************/
-BOOL secrets_named_mutex(const char *name, unsigned int timeout)
+BOOL secrets_named_mutex(const char *name, unsigned int timeout, size_t *p_ref_count)
{
- int ret;
+ size_t ref_count = *p_ref_count;
+ int ret = 0;
if (!message_init())
return False;
- ret = tdb_lock_bystring(tdb, name, timeout);
- if (ret == 0)
- DEBUG(10,("secrets_named_mutex: got mutex for %s\n", name ));
+ if (ref_count == 0) {
+ ret = tdb_lock_bystring(tdb, name, timeout);
+ if (ret == 0)
+ DEBUG(10,("secrets_named_mutex: got mutex for %s\n", name ));
+ }
+ if (ret == 0) {
+ *p_ref_count = ++ref_count;
+ DEBUG(10,("secrets_named_mutex: ref_count for mutex %s = %u\n", name, (unsigned int)ref_count ));
+ }
return (ret == 0);
}
@@ -606,10 +613,19 @@ BOOL secrets_named_mutex(const char *name, unsigned int timeout)
Unlock a named mutex.
*******************************************************************************/
-void secrets_named_mutex_release(const char *name)
+void secrets_named_mutex_release(const char *name, size_t *p_ref_count)
{
- tdb_unlock_bystring(tdb, name);
- DEBUG(10,("secrets_named_mutex: released mutex for %s\n", name ));
+ size_t ref_count = *p_ref_count;
+
+ SMB_ASSERT(ref_count != 0);
+
+ if (ref_count == 1) {
+ tdb_unlock_bystring(tdb, name);
+ DEBUG(10,("secrets_named_mutex: released mutex for %s\n", name ));
+ }
+
+ *p_ref_count = --ref_count;
+ DEBUG(10,("secrets_named_mutex_release: ref_count for mutex %s = %u\n", name, (unsigned int)ref_count ));
}
/*********************************************************