Skip to content

Commit 40befb9

Browse files
author
Côme Bernigaud
committed
Patch from Rainer Jung to provide Solaris LDAP support
1 parent 3ed58fb commit 40befb9

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

ext/ldap/ldap.c

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,24 @@
7070
#define PHP_LDAP_ESCAPE_FILTER 0x01
7171
#define PHP_LDAP_ESCAPE_DN 0x02
7272

73-
#ifndef HAVE_LDAP_CONTROL_FIND
73+
#if defined(LDAP_CONTROL_PAGEDRESULTS) && !defined(HAVE_LDAP_CONTROL_FIND)
7474
LDAPControl *ldap_control_find( const char *oid, LDAPControl **ctrls, LDAPControl ***nextctrlp)
7575
{
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);
7885
}
7986
#endif
8087

8188
typedef struct {
8289
LDAP *link;
83-
#if defined(HAVE_3ARG_SETREBINDPROC)
90+
#if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
8491
zval *rebindproc;
8592
#endif
8693
} ldap_linkdata;
@@ -104,10 +111,8 @@ static void _close_ldap_link(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
104111
{
105112
ldap_linkdata *ld = (ldap_linkdata *)rsrc->ptr;
106113

107-
/* ldap_unbind_s() is deprecated;
108-
* the distinction between ldap_unbind() and ldap_unbind_s() is moot */
109114
ldap_unbind_ext(ld->link, NULL, NULL);
110-
#ifdef HAVE_3ARG_SETREBINDPROC
115+
#if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
111116

112117
if (ld->rebindproc != NULL) {
113118
zval_dtor(ld->rebindproc);
@@ -349,11 +354,8 @@ PHP_FUNCTION(ldap_connect)
349354

350355
ld = ecalloc(1, sizeof(ldap_linkdata));
351356

352-
/* OpenLDAP provides a specific call to detect valid LDAP URIs;
353-
* ldap_init()/ldap_open() is deprecated, use ldap_initialize() instead.
354-
*/
355357
{
356-
int rc;
358+
int rc = LDAP_SUCCESS;
357359
char *url = host;
358360
if (!ldap_is_ldap_url(url)) {
359361
int urllen = hostlen + sizeof( "ldap://:65535" );
@@ -367,7 +369,21 @@ PHP_FUNCTION(ldap_connect)
367369
snprintf( url, urllen, "ldap://%s:%ld", host ? host : "", port );
368370
}
369371

372+
#ifdef LDAP_API_FEATURE_X_OPENLDAP
373+
/* ldap_init() is deprecated, use ldap_initialize() instead.
374+
*/
370375
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 */
371387
if (url != host) {
372388
efree(url);
373389
}
@@ -465,14 +481,19 @@ PHP_FUNCTION(ldap_bind)
465481
}
466482

467483
{
484+
#ifdef LDAP_API_FEATURE_X_OPENLDAP
485+
/* ldap_simple_bind_s() is deprecated, use ldap_sasl_bind_s() instead.
486+
*/
468487
struct berval cred;
469488

470-
/* ldap_bind_s() is deprecated; use ldap_sasl_bind_s() instead */
471489
cred.bv_val = ldap_bind_pw;
472490
cred.bv_len = ldap_bind_pw ? ldap_bind_pwlen : 0;
473491
rc = ldap_sasl_bind_s(ld->link, ldap_bind_dn, LDAP_SASL_SIMPLE, &cred,
474492
NULL, NULL, /* no controls right now */
475493
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 */
476497
}
477498
if ( rc != LDAP_SUCCESS) {
478499
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)
13041325
add_index_string(return_value, i, ldap_value[i], 1);
13051326
}
13061327

1307-
/* ldap_value_free() is deprecated */
13081328
ldap_memvfree((void **)ldap_value);
13091329
}
13101330
/* }}} */
@@ -2485,7 +2505,7 @@ PHP_FUNCTION(ldap_start_tls)
24852505
#endif
24862506
#endif /* (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP */
24872507

2488-
#if defined(HAVE_3ARG_SETREBINDPROC)
2508+
#if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
24892509
/* {{{ _ldap_rebind_proc()
24902510
*/
24912511
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()
31383158
#endif
31393159
#endif
31403160

3141-
#if defined(HAVE_3ARG_SETREBINDPROC)
3161+
#if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
31423162
ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_set_rebind_proc, 0, 0, 2)
31433163
ZEND_ARG_INFO(0, link)
31443164
ZEND_ARG_INFO(0, callback)
@@ -3226,7 +3246,7 @@ const zend_function_entry ldap_functions[] = {
32263246
#endif
32273247
#endif
32283248

3229-
#if defined(HAVE_3ARG_SETREBINDPROC)
3249+
#if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
32303250
PHP_FE(ldap_set_rebind_proc, arginfo_ldap_set_rebind_proc)
32313251
#endif
32323252

0 commit comments

Comments
 (0)