summaryrefslogtreecommitdiff
path: root/nsswitch
diff options
context:
space:
mode:
authorRalph Wuerthner <ralph.wuerthner@de.ibm.com>2018-10-02 13:41:00 +0200
committerJeremy Allison <jra@samba.org>2018-11-01 01:59:10 +0100
commit988182c3b8dab6511c75622e3484c9ef71e6d0db (patch)
tree843b9d63a8d313210d1ebbf24d835ca43e850fbc /nsswitch
parente82b3ac0ae5b50993db3c85d77dd317f957beb7e (diff)
downloadsamba-988182c3b8dab6511c75622e3484c9ef71e6d0db.tar.gz
nsswitch: protect access to wb_global_ctx by a mutex
This change will make libwbclient thread safe for all API calls not using a context. Especially there are no more conflicts with threads using nsswitch and libwbclient in parallel. Signed-off-by: Ralph Wuerthner <ralph.wuerthner@de.ibm.com> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'nsswitch')
-rw-r--r--nsswitch/wb_common.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/nsswitch/wb_common.c b/nsswitch/wb_common.c
index 9ba74c35a6d..59370aa5bbc 100644
--- a/nsswitch/wb_common.c
+++ b/nsswitch/wb_common.c
@@ -27,6 +27,10 @@
#include "system/select.h"
#include "winbind_client.h"
+#if HAVE_PTHREAD_H
+#include <pthread.h>
+#endif
+
/* Global context */
struct winbindd_context {
@@ -35,6 +39,10 @@ struct winbindd_context {
pid_t our_pid; /* calling process pid */
};
+#if HAVE_PTHREAD
+static pthread_mutex_t wb_global_ctx_mutex = PTHREAD_MUTEX_INITIALIZER;
+#endif
+
static struct winbindd_context *get_wb_global_ctx(void)
{
static struct winbindd_context wb_global_ctx = {
@@ -43,12 +51,17 @@ static struct winbindd_context *get_wb_global_ctx(void)
.our_pid = 0
};
+#if HAVE_PTHREAD
+ pthread_mutex_lock(&wb_global_ctx_mutex);
+#endif
return &wb_global_ctx;
}
static void put_wb_global_ctx(void)
{
- /* noop for now */
+#if HAVE_PTHREAD
+ pthread_mutex_unlock(&wb_global_ctx_mutex);
+#endif
return;
}