X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fpasswd.c;h=2e636b310b772a99c2246751c2cf323402e47904;hb=afa861bf22bbf49a93149bd25a01a0171b30ca93;hp=f8c9cccb0210d2167fa95dbe14e468a7c9cf66c3;hpb=dec097f8b0f6752f6fe16ccbb623accf211ca319;p=openldap
diff --git a/servers/slapd/passwd.c b/servers/slapd/passwd.c
index f8c9cccb02..2e636b310b 100644
--- a/servers/slapd/passwd.c
+++ b/servers/slapd/passwd.c
@@ -2,7 +2,7 @@
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
- * Copyright 1998-2015 The OpenLDAP Foundation.
+ * Copyright 1998-2017 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -23,8 +23,11 @@
#include
#ifdef SLAPD_CRYPT
+#ifdef HAVE_CRYPT_R
+#define __USE_GNU
+#endif /* HAVE_CRYPT_R */
#include
-#endif
+#endif /* SLAPD_CRYPT */
#include "slap.h"
@@ -590,6 +593,30 @@ slap_passwd_hash(
static ldap_pvt_thread_mutex_t passwd_mutex;
static lutil_cryptfunc slapd_crypt;
+#ifdef HAVE_CRYPT_R
+static int slapd_crypt( const char *key, const char *salt, char **hash )
+{
+ char *cr;
+ int rc;
+ struct crypt_data data;
+
+ data.initialized = 0;
+ cr = crypt_r( key, salt, &data );
+ if ( cr == NULL || cr[0] == '\0' ) {
+ /* salt must have been invalid */
+ rc = LUTIL_PASSWD_ERR;
+ } else {
+ if ( hash ) {
+ *hash = ber_strdup( cr );
+ rc = LUTIL_PASSWD_OK;
+ } else {
+ rc = strcmp( salt, cr ) ? LUTIL_PASSWD_ERR : LUTIL_PASSWD_OK;
+ }
+ }
+
+ return rc;
+}
+#else
static int slapd_crypt( const char *key, const char *salt, char **hash )
{
char *cr;
@@ -614,6 +641,8 @@ static int slapd_crypt( const char *key, const char *salt, char **hash )
ldap_pvt_thread_mutex_unlock( &passwd_mutex );
return rc;
}
+#endif /* HAVE_CRYPT_R */
+
#endif /* SLAPD_CRYPT */
void slap_passwd_init()