From: Remi Gacogne Date: Mon, 31 Jan 2022 13:47:54 +0000 (+0100) Subject: rec-4.6.x: Fix build with OpenSSL 3.0.0 X-Git-Tag: rec-4.6.2~17^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F11260%2Fhead;p=thirdparty%2Fpdns.git rec-4.6.x: Fix build with OpenSSL 3.0.0 (cherry picked from commit 8535f66672ec9d1eebf5835d3e53238973a80478) --- diff --git a/pdns/credentials.cc b/pdns/credentials.cc index b3a09e5c81..d058a948ac 100644 --- a/pdns/credentials.cc +++ b/pdns/credentials.cc @@ -31,6 +31,7 @@ #ifdef HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT #include #include +#include #include #endif @@ -105,8 +106,13 @@ static std::string hashPasswordInternal(const std::string& password, const std:: throw std::runtime_error("Error intializing the scrypt context to hash the supplied password"); } - // OpenSSL 3.0 changed the string arg to const unsigned char*, other versions use const char *, so cast to const void * to satisfy both - if (EVP_PKEY_CTX_set1_pbe_pass(pctx.get(), reinterpret_cast(password.data()), password.size()) <= 0) { + // OpenSSL 3.0 changed the string arg to const unsigned char*, other versions use const char * +#if OPENSSL_VERSION_MAJOR >= 3 + auto passwordData = reinterpret_cast(password.data()); +#else + auto passwordData = reinterpret_cast(password.data()); +#endif + if (EVP_PKEY_CTX_set1_pbe_pass(pctx.get(), passwordData, password.size()) <= 0) { throw std::runtime_error("Error adding the password to the scrypt context to hash the supplied password"); }