From: Ralph Wuerthner Date: Tue, 2 Oct 2018 11:41:00 +0000 (+0200) Subject: nsswitch: protect access to wb_global_ctx by a mutex X-Git-Tag: tdb-1.3.17~1052 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=988182c3b8dab6511c75622e3484c9ef71e6d0db;p=thirdparty%2Fsamba.git 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 Reviewed-by: Volker Lendecke Reviewed-by: Jeremy Allison --- 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 +#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; }