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