com php-src: Merge branch 'PHP-5.6': ext/ldap/ldap.c

From: Date: Wed, 17 Jun 2015 13:08:47 +0000
Subject: com php-src: Merge branch 'PHP-5.6': ext/ldap/ldap.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-87317@lists.php.net to get a copy of this message
Commit: 78fe52475f8dc9b2e8551b478010c46a9822c5a9 Author: Côme Bernigaud <mcmic@php.net> Wed, 17 Jun 2015 14:48:19 +0200 Parents: a5629f8845031a2e5f56a56aee3cf850939e92c0 e7af0fe1eb89e40671e86a588aa1b78607b85461 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=78fe52475f8dc9b2e8551b478010c46a9822c5a9 Log: Merge branch 'PHP-5.6' * PHP-5.6: Replaced calls to deprecated openldap functions Fixed LDAP tests so that base can exists Conflicts: ext/ldap/ldap.c Changed paths: MM ext/ldap/ldap.c Diff: diff --cc ext/ldap/ldap.c index b1fc1e4,fe09c9c..ebc2b7b --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@@ -96,10 -96,21 +96,17 @@@ static void _close_ldap_link(zend_resou { 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)--; } @@@ -298,12 -305,18 +305,18 @@@ PHP_MINFO_FUNCTION(ldap 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; @@@ -335,21 -348,37 +348,37 @@@ 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; + char *url = host; + if (!ldap_is_ldap_url(url)) { + int urllen = hostlen + sizeof( "ldap://:65535" ); + + if (port <= 0 || port > 65535) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid port number: %ld", port); ++ 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); @@@ -439,8 -466,22 +468,22 @@@ PHP_FUNCTION(ldap_bind 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; @@@ -1311,10 -1307,15 +1354,15 @@@ PHP_FUNCTION(ldap_explode_dn 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 */ } /* }}} */

« previous php.cvs (#87317) next »