b444af
From fc4e31467c352032ee709ac55d3c67bc22abcd8d Mon Sep 17 00:00:00 2001
b444af
From: Remi Collet <remi@remirepo.net>
b444af
Date: Fri, 15 Oct 2021 17:11:12 +0200
b444af
Subject: [PATCH] add --with-external-libcrypt build option display an error
b444af
 message if some algo not available in external libcrypt
b444af
b444af
---
b444af
 ext/standard/config.m4 | 21 ++++++++++++++++-----
b444af
 1 file changed, 16 insertions(+), 5 deletions(-)
b444af
b444af
diff --git a/ext/standard/config.m4 b/ext/standard/config.m4
b444af
index 58b9c5e658a4..3ec18be4d7df 100644
b444af
--- a/ext/standard/config.m4
b444af
+++ b/ext/standard/config.m4
b444af
@@ -267,14 +267,25 @@ int main() {
b444af
 ])])
b444af
 
b444af
 
b444af
+PHP_ARG_WITH([external-libcrypt],
b444af
+  [for external libcrypt or libxcrypt],
b444af
+  [AS_HELP_STRING([--with-external-libcrypt],
b444af
+    [Use external libcrypt or libxcrypt])],
b444af
+  [no],
b444af
+  [no])
b444af
+
b444af
 dnl
b444af
 dnl If one of them is missing, use our own implementation, portable code is then possible
b444af
 dnl
b444af
-dnl TODO This is currently always enabled
b444af
-if test "$ac_cv_crypt_blowfish" = "no" || test "$ac_cv_crypt_des" = "no" || test "$ac_cv_crypt_ext_des" = "no" || test "$ac_cv_crypt_md5" = "no" || test "$ac_cv_crypt_sha512" = "no" || test "$ac_cv_crypt_sha256" = "no" || test "$ac_cv_func_crypt_r" != "yes" || true; then
b444af
-  AC_DEFINE_UNQUOTED(PHP_USE_PHP_CRYPT_R, 1, [Whether PHP has to use its own crypt_r for blowfish, des, ext des and md5])
b444af
-
b444af
-  PHP_ADD_SOURCES(PHP_EXT_DIR(standard), crypt_freesec.c crypt_blowfish.c crypt_sha512.c crypt_sha256.c php_crypt_r.c)
b444af
+dnl This is currently enabled by default
b444af
+if test "$ac_cv_crypt_blowfish" = "no" || test "$ac_cv_crypt_des" = "no" || test "$ac_cv_crypt_ext_des" = "no" || test "$ac_cv_crypt_md5" = "no" || test "$ac_cv_crypt_sha512" = "no" || test "$ac_cv_crypt_sha256" = "no" || test "$ac_cv_func_crypt_r" != "yes" || test "$PHP_EXTERNAL_LIBCRYPT" = "no"; then
b444af
+  if test "$PHP_EXTERNAL_LIBCRYPT" = "no"; then
b444af
+    AC_DEFINE_UNQUOTED(PHP_USE_PHP_CRYPT_R, 1, [Whether PHP has to use its own crypt_r for blowfish, des, ext des and md5])
b444af
+
b444af
+    PHP_ADD_SOURCES(PHP_EXT_DIR(standard), crypt_freesec.c crypt_blowfish.c crypt_sha512.c crypt_sha256.c php_crypt_r.c)
b444af
+   else
b444af
+    AC_MSG_ERROR([Cannot use external libcrypt as some algo are missing])
b444af
+   fi
b444af
 else
b444af
   AC_DEFINE_UNQUOTED(PHP_USE_PHP_CRYPT_R, 0, [Whether PHP has to use its own crypt_r for blowfish, des and ext des])
b444af
 fi