Skip to content

Commit f62f0e2

Browse files
authored
Merge pull request #37 from sartura/crypt_r_port
server session CHANGE use crypt where crypt_r is not available
2 parents cb8d929 + ce9a7ef commit f62f0e2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/session_server_ssh.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
#include "session_server_ch.h"
2929
#include "libnetconf.h"
3030

31+
#if !defined(HAVE_CRYPT_R)
32+
pthread_mutex_t crypt_lock = PTHREAD_MUTEX_INITIALIZER;
33+
#endif
34+
3135
extern struct nc_server_opts server_opts;
3236

3337
static char *
@@ -751,7 +755,9 @@ static int
751755
auth_password_compare_pwd(const char *pass_hash, const char *pass_clear)
752756
{
753757
char *new_pass_hash;
758+
#if defined(HAVE_CRYPT_R)
754759
struct crypt_data cdata;
760+
#endif
755761

756762
if (!pass_hash[0]) {
757763
if (!pass_clear[0]) {
@@ -764,8 +770,14 @@ auth_password_compare_pwd(const char *pass_hash, const char *pass_clear)
764770
}
765771
}
766772

773+
#if defined(HAVE_CRYPT_R)
767774
cdata.initialized = 0;
768775
new_pass_hash = crypt_r(pass_clear, pass_hash, &cdata);
776+
#else
777+
pthread_mutex_lock(&crypt_lock);
778+
new_pass_hash = crypt(pass_clear, pass_hash);
779+
pthread_mutex_unlock(&crypt_lock);
780+
#endif
769781
return strcmp(new_pass_hash, pass_hash);
770782
}
771783

0 commit comments

Comments
 (0)