X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fpasswd.c;h=2e636b310b772a99c2246751c2cf323402e47904;hb=434c306cbefeafe40f638ed3df93d630c996f9e5;hp=dfa370c333e89221a80fafe911f0f99a5e633a08;hpb=5e028ae83938177473d26ceb6b12d1c0728d9766;p=openldap diff --git a/servers/slapd/passwd.c b/servers/slapd/passwd.c index dfa370c333..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-2014 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()