Use mutex with pam auth, because pam is not thread safe

This commit is contained in:
z3APA3A 2016-05-11 19:03:16 +03:00
parent 8e820b28c0
commit 4cb43b438f

View File

@ -12,7 +12,7 @@ Kirill Lopuchov <lopuchov@mail.ru>
#include <security/pam_appl.h> #include <security/pam_appl.h>
pthread_mutex_t pam_mutex;
static int already_loaded = 0; static int already_loaded = 0;
@ -89,6 +89,7 @@ static int pamfunc(struct clientparam *param)
/*start process auth */ /*start process auth */
conv.appdata_ptr = (char *) param->password; conv.appdata_ptr = (char *) param->password;
pthread_mutex_lock(&pam_mutex);
if (!pamh) if (!pamh)
{ {
retval = pam_start ((char *)service, "3proxy@" , &conv, &pamh); retval = pam_start ((char *)service, "3proxy@" , &conv, &pamh);
@ -110,6 +111,7 @@ static int pamfunc(struct clientparam *param)
retval = pam_end (pamh, retval); retval = pam_end (pamh, retval);
if (retval != PAM_SUCCESS) if (retval != PAM_SUCCESS)
{ pamh = NULL; } { pamh = NULL; }
pthread_mutex_unlock(&pam_mutex);
return rc; return rc;
@ -130,6 +132,7 @@ int start(struct pluginlink * pluginlink, int argc, unsigned char** argv)
already_loaded = 1; already_loaded = 1;
pthread_mutex_init(&pam_mutex, NULL);
pamauth.authenticate = pamfunc; pamauth.authenticate = pamfunc;
pamauth.authorize = pluginlink->checkACL; pamauth.authorize = pluginlink->checkACL;
pamauth.desc = "pam"; pamauth.desc = "pam";