From 4cb43b438fd5bd6006d30c280ca11b7fa532b9a6 Mon Sep 17 00:00:00 2001 From: z3APA3A <3APA3A@3proxy.ru> Date: Wed, 11 May 2016 19:03:16 +0300 Subject: [PATCH] Use mutex with pam auth, because pam is not thread safe --- src/plugins/PamAuth/pamauth.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/plugins/PamAuth/pamauth.c b/src/plugins/PamAuth/pamauth.c index 4e182c6..da8869d 100644 --- a/src/plugins/PamAuth/pamauth.c +++ b/src/plugins/PamAuth/pamauth.c @@ -12,7 +12,7 @@ Kirill Lopuchov #include - +pthread_mutex_t pam_mutex; static int already_loaded = 0; @@ -89,9 +89,10 @@ static int pamfunc(struct clientparam *param) /*start process auth */ conv.appdata_ptr = (char *) param->password; + pthread_mutex_lock(&pam_mutex); if (!pamh) { - retval = pam_start ((char *)service, "3proxy@" , &conv, &pamh); + retval = pam_start ((char *)service, "3proxy@" , &conv, &pamh); } if (retval == PAM_SUCCESS) retval = pam_set_item (pamh, PAM_USER, param->username); @@ -110,6 +111,7 @@ static int pamfunc(struct clientparam *param) retval = pam_end (pamh, retval); if (retval != PAM_SUCCESS) { pamh = NULL; } + pthread_mutex_unlock(&pam_mutex); return rc; @@ -130,6 +132,7 @@ int start(struct pluginlink * pluginlink, int argc, unsigned char** argv) already_loaded = 1; + pthread_mutex_init(&pam_mutex, NULL); pamauth.authenticate = pamfunc; pamauth.authorize = pluginlink->checkACL; pamauth.desc = "pam";