1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-25 17:57:42 +03:00

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>
This commit is contained in:
Ralph Wuerthner 2018-10-02 13:41:00 +02:00 committed by Jeremy Allison
parent e82b3ac0ae
commit 988182c3b8

View File

@ -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;
}