]> granicus.if.org Git - php/commitdiff
Merge branch 'PHP-5.6'
authorCôme Bernigaud <mcmic@php.net>
Wed, 17 Jun 2015 12:48:19 +0000 (14:48 +0200)
committerCôme Bernigaud <mcmic@php.net>
Wed, 17 Jun 2015 13:08:47 +0000 (15:08 +0200)
* PHP-5.6:
  Replaced calls to deprecated openldap functions
  Fixed LDAP tests so that base can exists

Conflicts:
ext/ldap/ldap.c

1  2 
ext/ldap/ldap.c

diff --cc ext/ldap/ldap.c
index b1fc1e45663fdc3e90a6520999b8ed4803d599ff,fe09c9c27745f07b734185f79ec38467ba2b827c..ebc2b7ba8bcb6191bfa9f3f3bf78795916e958de
@@@ -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;
        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);
@@@ -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 */
  }
  /* }}} */