@@ -987,6 +987,17 @@ PHP_FUNCTION(ldap_connect)
987
987
snprintf ( url , urllen , "ldap://%s:" ZEND_LONG_FMT , host , port );
988
988
}
989
989
990
+ #ifdef LDAP_OPT_X_TLS_NEWCTX
991
+ if (url && !strncmp (url , "ldaps:" , 6 )) {
992
+ int val = 0 ;
993
+
994
+ /* ensure all pending TLS options are applied in a new context */
995
+ if (ldap_set_option (NULL , LDAP_OPT_X_TLS_NEWCTX , & val ) != LDAP_OPT_SUCCESS ) {
996
+ php_error_docref (NULL , E_WARNING , "Could not create new security context" );
997
+ }
998
+ }
999
+ #endif
1000
+
990
1001
#ifdef LDAP_API_FEATURE_X_OPENLDAP
991
1002
/* ldap_init() is deprecated, use ldap_initialize() instead.
992
1003
*/
@@ -3688,6 +3699,9 @@ PHP_FUNCTION(ldap_start_tls)
3688
3699
zval * link ;
3689
3700
ldap_linkdata * ld ;
3690
3701
int rc , protocol = LDAP_VERSION3 ;
3702
+ #ifdef LDAP_OPT_X_TLS_NEWCTX
3703
+ int val = 0 ;
3704
+ #endif
3691
3705
3692
3706
if (zend_parse_parameters (ZEND_NUM_ARGS (), "O" , & link , ldap_link_ce ) != SUCCESS ) {
3693
3707
RETURN_THROWS ();
@@ -3697,6 +3711,9 @@ PHP_FUNCTION(ldap_start_tls)
3697
3711
VERIFY_LDAP_LINK_CONNECTED (ld );
3698
3712
3699
3713
if (((rc = ldap_set_option (ld -> link , LDAP_OPT_PROTOCOL_VERSION , & protocol )) != LDAP_SUCCESS ) ||
3714
+ #ifdef LDAP_OPT_X_TLS_NEWCTX
3715
+ ((rc = ldap_set_option (ld -> link , LDAP_OPT_X_TLS_NEWCTX , & val )) != LDAP_OPT_SUCCESS ) ||
3716
+ #endif
3700
3717
((rc = ldap_start_tls_s (ld -> link , NULL , NULL )) != LDAP_SUCCESS )
3701
3718
) {
3702
3719
php_error_docref (NULL , E_WARNING ,"Unable to start TLS: %s" , ldap_err2string (rc ));
0 commit comments