Skip to content

Commit 9def76e

Browse files
authored
Autotools: Refactor crypt check in ext/standard (#14856)
- AH_TEMPLATE sets the CPP macro help text on a single place - AC_DEFINE can be used instead of AC_DEFINE_UNQUOTED - AS_VAR_IF used and CS synced - crypt() function is at this point required as all required algorithm checks are depending on it and error is thrown if not found when using external crypt library
1 parent 2acd4c2 commit 9def76e

File tree

1 file changed

+13
-31
lines changed

1 file changed

+13
-31
lines changed

ext/standard/config.m4

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,20 @@ PHP_ARG_WITH([external-libcrypt],
5656
[no],
5757
[no])
5858

59-
if test "$PHP_EXTERNAL_LIBCRYPT" != "no"; then
59+
AH_TEMPLATE([PHP_USE_PHP_CRYPT_R],
60+
[Define to 1 if PHP uses its own crypt_r, and to 0 if using the external crypt
61+
library.])
62+
63+
AS_VAR_IF([PHP_EXTERNAL_LIBCRYPT], [no], [
64+
AC_DEFINE([PHP_USE_PHP_CRYPT_R], [1])
65+
PHP_ADD_SOURCES([PHP_EXT_DIR([standard])],
66+
[crypt_freesec.c crypt_blowfish.c crypt_sha512.c crypt_sha256.c php_crypt_r.c])
67+
], [
6068
PHP_CHECK_FUNC(crypt, crypt)
6169
PHP_CHECK_FUNC(crypt_r, crypt)
6270
AC_CHECK_HEADERS([crypt.h])
71+
AS_VAR_IF([ac_cv_func_crypt], [yes],,
72+
[AC_MSG_ERROR([Cannot use external libcrypt as crypt() is missing.])])
6373
AS_VAR_IF([ac_cv_func_crypt_r], [yes],
6474
[PHP_CRYPT_R_STYLE],
6575
[AC_MSG_ERROR([Cannot use external libcrypt as crypt_r() is missing.])])
@@ -78,12 +88,8 @@ if test "$PHP_EXTERNAL_LIBCRYPT" != "no"; then
7888
#include <string.h>
7989
8090
int main(void) {
81-
#ifdef HAVE_CRYPT
8291
char *encrypted = crypt("rasmuslerdorf","rl");
8392
return !encrypted || strcmp(encrypted,"rl.3StKT.4T8M");
84-
#else
85-
return 1;
86-
#endif
8793
}]])],[
8894
ac_cv_crypt_des=yes
8995
],[
@@ -106,12 +112,8 @@ int main(void) {
106112
#include <string.h>
107113
108114
int main(void) {
109-
#ifdef HAVE_CRYPT
110115
char *encrypted = crypt("rasmuslerdorf","_J9..rasm");
111116
return !encrypted || strcmp(encrypted,"_J9..rasmBYk8r9AiWNc");
112-
#else
113-
return 1;
114-
#endif
115117
}]])],[
116118
ac_cv_crypt_ext_des=yes
117119
],[
@@ -134,7 +136,6 @@ int main(void) {
134136
#include <string.h>
135137
136138
int main(void) {
137-
#ifdef HAVE_CRYPT
138139
char salt[15], answer[40];
139140
char *encrypted;
140141
@@ -147,9 +148,6 @@ int main(void) {
147148
strcat(answer,"rISCgZzpwk3UhDidwXvin0");
148149
encrypted = crypt("rasmuslerdorf",salt);
149150
return !encrypted || strcmp(encrypted,answer);
150-
#else
151-
return 1;
152-
#endif
153151
}]])],[
154152
ac_cv_crypt_md5=yes
155153
],[
@@ -172,7 +170,6 @@ int main(void) {
172170
#include <string.h>
173171
174172
int main(void) {
175-
#ifdef HAVE_CRYPT
176173
char salt[30], answer[70];
177174
char *encrypted;
178175
@@ -182,9 +179,6 @@ int main(void) {
182179
strcpy(&answer[29],"nIdrcHdxcUxWomQX9j6kvERCFjTg7Ra");
183180
encrypted = crypt("rasmuslerdorf",salt);
184181
return !encrypted || strcmp(encrypted,answer);
185-
#else
186-
return 1;
187-
#endif
188182
}]])],[
189183
ac_cv_crypt_blowfish=yes
190184
],[
@@ -207,7 +201,6 @@ int main(void) {
207201
#include <string.h>
208202
209203
int main(void) {
210-
#ifdef HAVE_CRYPT
211204
char salt[21], answer[21+86];
212205
char *encrypted;
213206
@@ -216,9 +209,6 @@ int main(void) {
216209
strcat(answer, "EeHCRjm0bljalWuALHSTs1NB9ipEiLEXLhYeXdOpx22gmlmVejnVXFhd84cEKbYxCo.XuUTrW.RLraeEnsvWs/");
217210
encrypted = crypt("rasmuslerdorf",salt);
218211
return !encrypted || strcmp(encrypted,answer);
219-
#else
220-
return 1;
221-
#endif
222212
}]])],[
223213
ac_cv_crypt_sha512=yes
224214
],[
@@ -241,7 +231,6 @@ int main(void) {
241231
#include <string.h>
242232
243233
int main(void) {
244-
#ifdef HAVE_CRYPT
245234
char salt[21], answer[21+43];
246235
char *encrypted;
247236
@@ -250,9 +239,6 @@ int main(void) {
250239
strcat(answer, "cFAm2puLCujQ9t.0CxiFIIvFi4JyQx5UncCt/xRIX23");
251240
encrypted = crypt("rasmuslerdorf",salt);
252241
return !encrypted || strcmp(encrypted,answer);
253-
#else
254-
return 1;
255-
#endif
256242
}]])],[
257243
ac_cv_crypt_sha256=yes
258244
],[
@@ -266,12 +252,8 @@ int main(void) {
266252
AC_MSG_ERROR([Cannot use external libcrypt as some algo are missing])
267253
fi
268254
269-
AC_DEFINE_UNQUOTED(PHP_USE_PHP_CRYPT_R, 0, [Whether PHP has to use its own crypt_r])
270-
else
271-
AC_DEFINE_UNQUOTED(PHP_USE_PHP_CRYPT_R, 1, [Whether PHP has to use its own crypt_r])
272-
273-
PHP_ADD_SOURCES(PHP_EXT_DIR(standard), crypt_freesec.c crypt_blowfish.c crypt_sha512.c crypt_sha256.c php_crypt_r.c)
274-
fi
255+
AC_DEFINE([PHP_USE_PHP_CRYPT_R], [0])
256+
])
275257

276258
AS_VAR_IF([cross_compiling], [no], [AC_FUNC_FNMATCH],
277259
[AS_CASE([$host_alias], [*linux*],

0 commit comments

Comments
 (0)