70
70
#define PHP_LDAP_ESCAPE_FILTER 0x01
71
71
#define PHP_LDAP_ESCAPE_DN 0x02
72
72
73
- #ifndef HAVE_LDAP_CONTROL_FIND
73
+ #if defined( LDAP_CONTROL_PAGEDRESULTS ) && !defined( HAVE_LDAP_CONTROL_FIND )
74
74
LDAPControl * ldap_control_find ( const char * oid , LDAPControl * * ctrls , LDAPControl * * * nextctrlp )
75
75
{
76
- assert (nextctrlp == NULL );
77
- return ldap_find_control (oid , ctrls );
76
+ assert (nextctrlp == NULL );
77
+ return ldap_find_control (oid , ctrls );
78
+ }
79
+ #endif
80
+
81
+ #if !defined(LDAP_API_FEATURE_X_OPENLDAP )
82
+ void ldap_memvfree (void * * v )
83
+ {
84
+ ldap_value_free ((char * * )v );
78
85
}
79
86
#endif
80
87
81
88
typedef struct {
82
89
LDAP * link ;
83
- #if defined(HAVE_3ARG_SETREBINDPROC )
90
+ #if defined(LDAP_API_FEATURE_X_OPENLDAP ) && defined( HAVE_3ARG_SETREBINDPROC )
84
91
zval * rebindproc ;
85
92
#endif
86
93
} ldap_linkdata ;
@@ -104,10 +111,8 @@ static void _close_ldap_link(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
104
111
{
105
112
ldap_linkdata * ld = (ldap_linkdata * )rsrc -> ptr ;
106
113
107
- /* ldap_unbind_s() is deprecated;
108
- * the distinction between ldap_unbind() and ldap_unbind_s() is moot */
109
114
ldap_unbind_ext (ld -> link , NULL , NULL );
110
- #ifdef HAVE_3ARG_SETREBINDPROC
115
+ #if defined( LDAP_API_FEATURE_X_OPENLDAP ) && defined( HAVE_3ARG_SETREBINDPROC )
111
116
112
117
if (ld -> rebindproc != NULL ) {
113
118
zval_dtor (ld -> rebindproc );
@@ -349,11 +354,8 @@ PHP_FUNCTION(ldap_connect)
349
354
350
355
ld = ecalloc (1 , sizeof (ldap_linkdata ));
351
356
352
- /* OpenLDAP provides a specific call to detect valid LDAP URIs;
353
- * ldap_init()/ldap_open() is deprecated, use ldap_initialize() instead.
354
- */
355
357
{
356
- int rc ;
358
+ int rc = LDAP_SUCCESS ;
357
359
char * url = host ;
358
360
if (!ldap_is_ldap_url (url )) {
359
361
int urllen = hostlen + sizeof ( "ldap://:65535" );
@@ -367,7 +369,21 @@ PHP_FUNCTION(ldap_connect)
367
369
snprintf ( url , urllen , "ldap://%s:%ld" , host ? host : "" , port );
368
370
}
369
371
372
+ #ifdef LDAP_API_FEATURE_X_OPENLDAP
373
+ /* ldap_init() is deprecated, use ldap_initialize() instead.
374
+ */
370
375
rc = ldap_initialize (& ldap , url );
376
+ #else /* ! LDAP_API_FEATURE_X_OPENLDAP */
377
+ /* ldap_init does not support URLs.
378
+ * We must try the original host and port information.
379
+ */
380
+ ldap = ldap_init (host , port );
381
+ if (ldap == NULL ) {
382
+ efree (ld );
383
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Could not create session handle" );
384
+ RETURN_FALSE ;
385
+ }
386
+ #endif /* ! LDAP_API_FEATURE_X_OPENLDAP */
371
387
if (url != host ) {
372
388
efree (url );
373
389
}
@@ -465,14 +481,19 @@ PHP_FUNCTION(ldap_bind)
465
481
}
466
482
467
483
{
484
+ #ifdef LDAP_API_FEATURE_X_OPENLDAP
485
+ /* ldap_simple_bind_s() is deprecated, use ldap_sasl_bind_s() instead.
486
+ */
468
487
struct berval cred ;
469
488
470
- /* ldap_bind_s() is deprecated; use ldap_sasl_bind_s() instead */
471
489
cred .bv_val = ldap_bind_pw ;
472
490
cred .bv_len = ldap_bind_pw ? ldap_bind_pwlen : 0 ;
473
491
rc = ldap_sasl_bind_s (ld -> link , ldap_bind_dn , LDAP_SASL_SIMPLE , & cred ,
474
492
NULL , NULL , /* no controls right now */
475
493
NULL ); /* we don't care about the server's credentials */
494
+ #else /* ! LDAP_API_FEATURE_X_OPENLDAP */
495
+ rc = ldap_simple_bind_s (ld -> link , ldap_bind_dn , ldap_bind_pw );
496
+ #endif /* ! LDAP_API_FEATURE_X_OPENLDAP */
476
497
}
477
498
if ( rc != LDAP_SUCCESS ) {
478
499
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Unable to bind to server: %s" , ldap_err2string (rc ));
@@ -1304,7 +1325,6 @@ PHP_FUNCTION(ldap_explode_dn)
1304
1325
add_index_string (return_value , i , ldap_value [i ], 1 );
1305
1326
}
1306
1327
1307
- /* ldap_value_free() is deprecated */
1308
1328
ldap_memvfree ((void * * )ldap_value );
1309
1329
}
1310
1330
/* }}} */
@@ -2485,7 +2505,7 @@ PHP_FUNCTION(ldap_start_tls)
2485
2505
#endif
2486
2506
#endif /* (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP */
2487
2507
2488
- #if defined(HAVE_3ARG_SETREBINDPROC )
2508
+ #if defined(LDAP_API_FEATURE_X_OPENLDAP ) && defined( HAVE_3ARG_SETREBINDPROC )
2489
2509
/* {{{ _ldap_rebind_proc()
2490
2510
*/
2491
2511
int _ldap_rebind_proc (LDAP * ldap , const char * url , ber_tag_t req , ber_int_t msgid , void * params )
@@ -3138,7 +3158,7 @@ ZEND_END_ARG_INFO()
3138
3158
#endif
3139
3159
#endif
3140
3160
3141
- #if defined(HAVE_3ARG_SETREBINDPROC )
3161
+ #if defined(LDAP_API_FEATURE_X_OPENLDAP ) && defined( HAVE_3ARG_SETREBINDPROC )
3142
3162
ZEND_BEGIN_ARG_INFO_EX (arginfo_ldap_set_rebind_proc , 0 , 0 , 2 )
3143
3163
ZEND_ARG_INFO (0 , link )
3144
3164
ZEND_ARG_INFO (0 , callback )
@@ -3226,7 +3246,7 @@ const zend_function_entry ldap_functions[] = {
3226
3246
#endif
3227
3247
#endif
3228
3248
3229
- #if defined(HAVE_3ARG_SETREBINDPROC )
3249
+ #if defined(LDAP_API_FEATURE_X_OPENLDAP ) && defined ( HAVE_3ARG_SETREBINDPROC )
3230
3250
PHP_FE (ldap_set_rebind_proc , arginfo_ldap_set_rebind_proc )
3231
3251
#endif
3232
3252
0 commit comments