{
ldap_linkdata *ld = (ldap_linkdata *)rsrc->ptr;
- ldap_unbind_s(ld->link);
- #if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
+ /* ldap_unbind_s() is deprecated;
+ * the distinction between ldap_unbind() and ldap_unbind_s() is moot */
+ #ifdef LDAP_API_FEATURE_X_OPENLDAP
+ ldap_unbind_ext(ld->link, NULL, NULL);
+ #ifdef HAVE_3ARG_SETREBINDPROC
-
- if (ld->rebindproc != NULL) {
- zval_dtor(ld->rebindproc);
- FREE_ZVAL(ld->rebindproc);
- }
+ zval_ptr_dtor(&ld->rebindproc);
#endif
+ #else /* ! LDAP_API_FEATURE_X_OPENLDAP */
+ ldap_unbind_s(ld->link);
+ #endif /* ! LDAP_API_FEATURE_X_OPENLDAP */
+
efree(ld);
LDAPG(num_links)--;
}
PHP_FUNCTION(ldap_connect)
{
char *host = NULL;
- size_t hostlen;
- zend_long port = 389; /* Default port */
- int hostlen;
- long port =
++ size_t hostlen = 0;
++ zend_long port =
+ #ifdef LDAP_API_FEATURE_X_OPENLDAP
+ LDAP_PORT
+ #else /* ! LDAP_API_FEATURE_X_OPENLDAP */
+ 389 /* Default port */
+ #endif /* ! LDAP_API_FEATURE_X_OPENLDAP */
+ ;
#ifdef HAVE_ORALDAP
char *wallet = NULL, *walletpasswd = NULL;
- int walletlen = 0, walletpasswdlen = 0;
- long authmode = GSLC_SSL_NO_AUTH;
+ size_t walletlen = 0, walletpasswdlen = 0;
+ zend_long authmode = GSLC_SSL_NO_AUTH;
int ssl=0;
#endif
ldap_linkdata *ld;
ld = ecalloc(1, sizeof(ldap_linkdata));
#ifdef LDAP_API_FEATURE_X_OPENLDAP
- if (host != NULL && strchr(host, '/')) {
+ /* OpenLDAP provides a specific call to detect valid LDAP URIs;
+ * ldap_init()/ldap_open() is deprecated, use ldap_initialize() instead.
+ */
+ {
int rc;
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid port number: %ld", port);
+ char *url = host;
+ if (!ldap_is_ldap_url(url)) {
+ int urllen = hostlen + sizeof( "ldap://:65535" );
+
+ if (port <= 0 || port > 65535) {
++ php_error_docref(NULL, E_WARNING, "invalid port number: %ld", port);
+ RETURN_FALSE;
+ }
+
+ url = emalloc(urllen);
+ snprintf( url, urllen, "ldap://%s:%ld", host ? host : "", port );
+ }
- rc = ldap_initialize(&ldap, host);
+ rc = ldap_initialize(&ldap, url);
+ if (url != host) {
+ efree(url);
+ }
if (rc != LDAP_SUCCESS) {
efree(ld);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not create session handle: %s", ldap_err2string(rc));
+ php_error_docref(NULL, E_WARNING, "Could not create session handle: %s", ldap_err2string(rc));
RETURN_FALSE;
}
- } else {
- ldap = ldap_init(host, port);
}
- #else
+ #else /* ! LDAP_API_FEATURE_X_OPENLDAP */
ldap = ldap_open(host, port);
- #endif
+ #endif /* ! LDAP_API_FEATURE_X_OPENLDAP */
if (ldap == NULL) {
efree(ld);
RETURN_FALSE;
}
- if ((rc = ldap_bind_s(ld->link, ldap_bind_dn, ldap_bind_pw, LDAP_AUTH_SIMPLE)) != LDAP_SUCCESS) {
+ #ifdef LDAP_API_FEATURE_X_OPENLDAP
+ {
+ struct berval cred;
+
+ /* ldap_bind_s() is deprecated; use ldap_sasl_bind_s() instead */
+ cred.bv_val = ldap_bind_pw;
+ cred.bv_len = ldap_bind_pw ? ldap_bind_pwlen : 0;
+ rc = ldap_sasl_bind_s(ld->link, ldap_bind_dn, LDAP_SASL_SIMPLE, &cred,
+ NULL, NULL, /* no controls right now */
+ NULL); /* we don't care about the server's credentials */
+ }
+ #else
+ rc = ldap_bind_s(ld->link, ldap_bind_dn, ldap_bind_pw, LDAP_AUTH_SIMPLE);
+ #endif
+ if ( rc != LDAP_SUCCESS) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to bind to server: %s", ldap_err2string(rc));
+ php_error_docref(NULL, E_WARNING, "Unable to bind to server: %s", ldap_err2string(rc));
RETURN_FALSE;
} else {
RETURN_TRUE;
add_assoc_long(return_value, "count", count);
for (i = 0; i<count; i++) {
- add_index_string(return_value, i, ldap_value[i], 1);
+ add_index_string(return_value, i, ldap_value[i]);
}
+ #ifdef LDAP_API_FEATURE_X_OPENLDAP
+ /* ldap_value_free() is deprecated */
+ ber_memvfree((void **)ldap_value);
+ #else /* ! LDAP_API_FEATURE_X_OPENLDAP */
ldap_value_free(ldap_value);
+ #endif /* ! LDAP_API_FEATURE_X_OPENLDAP */
}
/* }}} */