Skip to content

Commit 23f96a3

Browse files
committed
Fix GH-18529: ldap no longer respects TLS_CACERT from ldaprc in ldap_start_tls()
Regresion introduced in fix for GH-17776 - ensure TLS string options are properly inherited workaround to openldap issue https://bugs.openldap.org/show_bug.cgi?id=10337 - fix ldaps/start_tls tests using LDAPNOINIT in ldaps/tls tests
1 parent 8d2682f commit 23f96a3

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

ext/ldap/ldap.c

+45-4
Original file line numberDiff line numberDiff line change
@@ -3721,15 +3721,56 @@ PHP_FUNCTION(ldap_rename_ext)
37213721
/* }}} */
37223722

37233723
#ifdef HAVE_LDAP_START_TLS_S
3724+
/*
3725+
Force new tls context creation with string options inherited from global
3726+
Workaround to https://bugs.openldap.org/show_bug.cgi?id=10337
3727+
*/
3728+
static int _php_ldap_tls_newctx(LDAP *ld)
3729+
{
3730+
int val = 0, i, opts[] = {
3731+
#if (LDAP_API_VERSION > 2000)
3732+
LDAP_OPT_X_TLS_CACERTDIR,
3733+
LDAP_OPT_X_TLS_CACERTFILE,
3734+
LDAP_OPT_X_TLS_CERTFILE,
3735+
LDAP_OPT_X_TLS_CIPHER_SUITE,
3736+
LDAP_OPT_X_TLS_KEYFILE,
3737+
LDAP_OPT_X_TLS_RANDOM_FILE,
3738+
#endif
3739+
#ifdef LDAP_OPT_X_TLS_CRLFILE
3740+
LDAP_OPT_X_TLS_CRLFILE,
3741+
#endif
3742+
#ifdef LDAP_OPT_X_TLS_DHFILE
3743+
LDAP_OPT_X_TLS_DHFILE,
3744+
#endif
3745+
#ifdef LDAP_OPT_X_TLS_ECNAME
3746+
LDAP_OPT_X_TLS_ECNAME,
3747+
#endif
3748+
0};
3749+
3750+
for (i=0 ; opts[i] ; i++) {
3751+
char *path = NULL;
3752+
3753+
ldap_get_option(ld, opts[i], &path);
3754+
if (path) { /* already set locally */
3755+
ldap_memfree(path);
3756+
} else {
3757+
ldap_get_option(NULL, opts[i], &path);
3758+
if (path) { /* set globally, inherit */
3759+
ldap_set_option(ld, opts[i], path);
3760+
ldap_memfree(path);
3761+
}
3762+
}
3763+
}
3764+
3765+
return ldap_set_option(ld, LDAP_OPT_X_TLS_NEWCTX, &val);
3766+
}
3767+
37243768
/* {{{ Start TLS */
37253769
PHP_FUNCTION(ldap_start_tls)
37263770
{
37273771
zval *link;
37283772
ldap_linkdata *ld;
37293773
int rc, protocol = LDAP_VERSION3;
3730-
#ifdef LDAP_OPT_X_TLS_NEWCTX
3731-
int val = 0;
3732-
#endif
37333774

37343775
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &link, ldap_link_ce) != SUCCESS) {
37353776
RETURN_THROWS();
@@ -3740,7 +3781,7 @@ PHP_FUNCTION(ldap_start_tls)
37403781

37413782
if (((rc = ldap_set_option(ld->link, LDAP_OPT_PROTOCOL_VERSION, &protocol)) != LDAP_SUCCESS) ||
37423783
#ifdef LDAP_OPT_X_TLS_NEWCTX
3743-
(LDAPG(tls_newctx) && (rc = ldap_set_option(ld->link, LDAP_OPT_X_TLS_NEWCTX, &val)) != LDAP_OPT_SUCCESS) ||
3784+
(LDAPG(tls_newctx) && (rc = _php_ldap_tls_newctx(ld->link)) != LDAP_OPT_SUCCESS) ||
37443785
#endif
37453786
((rc = ldap_start_tls_s(ld->link, NULL, NULL)) != LDAP_SUCCESS)
37463787
) {

ext/ldap/tests/ldap_start_tls_basic.phpt

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Patrick Allaert <[email protected]>
55
# Belgian PHP Testfest 2009
66
--EXTENSIONS--
77
ldap
8+
--ENV--
9+
LDAPNOINIT=1
810
--SKIPIF--
911
<?php require_once __DIR__ .'/skipifbindfailure.inc'; ?>
1012
--FILE--

ext/ldap/tests/ldaps_basic.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
ldap_connect() - Basic ldaps test
33
--EXTENSIONS--
44
ldap
5-
--XFAIL--
6-
Passes locally but fails on CI - need investigation (configuration ?)
5+
--ENV--
6+
LDAPNOINIT=1
77
--SKIPIF--
88
<?php require_once __DIR__ .'/skipifbindfailure.inc'; ?>
99
--FILE--

0 commit comments

Comments
 (0)