[PHP-CVS] cvs: php-src /ext/ldap ldap.c /ext/ldap/tests bug48441.phpt

2009-06-28 Thread Patrick Allaert
patrickallaert  Sun Jun 28 22:38:23 2009 UTC

  Modified files:  
/php-src/ext/ldap   ldap.c 
/php-src/ext/ldap/tests bug48441.phpt 
  Log:
  unicode support in ext/ldap
  http://cvs.php.net/viewvc.cgi/php-src/ext/ldap/ldap.c?r1=1.204r2=1.205diff_format=u
Index: php-src/ext/ldap/ldap.c
diff -u php-src/ext/ldap/ldap.c:1.204 php-src/ext/ldap/ldap.c:1.205
--- php-src/ext/ldap/ldap.c:1.204   Thu Jun 25 14:48:53 2009
+++ php-src/ext/ldap/ldap.c Sun Jun 28 22:38:22 2009
@@ -23,7 +23,7 @@
+--+
  */
  
-/* $Id: ldap.c,v 1.204 2009/06/25 14:48:53 felipe Exp $ */
+/* $Id: ldap.c,v 1.205 2009/06/28 22:38:22 patrickallaert Exp $ */
 #define IS_EXT_MODULE
 
 #ifdef HAVE_CONFIG_H
@@ -235,7 +235,7 @@
 
php_info_print_table_start();
php_info_print_table_row(2, LDAP Support, enabled);
-   php_info_print_table_row(2, RCS Version, $Id: ldap.c,v 1.204 
2009/06/25 14:48:53 felipe Exp $);
+   php_info_print_table_row(2, RCS Version, $Id: ldap.c,v 1.205 
2009/06/28 22:38:22 patrickallaert Exp $);
 
if (LDAPG(max_links) == -1) {
snprintf(tmp, 31, %ld/unlimited, LDAPG(num_links));
@@ -286,7 +286,7 @@
 }
 /* }}} */
 
-/* {{{ proto resource ldap_connect([string host [, int port [, string wallet 
[, string wallet_passwd [, int authmode])
+/* {{{ proto resource ldap_connect([string host [, int port [, string wallet 
[, string wallet_passwd [, int authmode]) U
Connect to an LDAP server */
 PHP_FUNCTION(ldap_connect)
 {
@@ -307,7 +307,7 @@
WRONG_PARAM_COUNT;
}
 
-   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |slssl, host, 
hostlen, port, wallet, walletlen, walletpasswd, walletpasswdlen, 
authmode) != SUCCESS) {
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |slssl, 
host, hostlen, UG(utf8_conv), port, wallet, walletlen, UG(utf8_conv), 
walletpasswd, walletpasswdlen, UG(utf8_conv), authmode) != SUCCESS) {
RETURN_FALSE;
}
 
@@ -385,7 +385,7 @@
 }
 /* }}} */
 
-/* {{{ proto bool ldap_bind(resource link [, string dn [, string password]])
+/* {{{ proto bool ldap_bind(resource link [, string dn [, string password]]) U
Bind to LDAP directory */
 PHP_FUNCTION(ldap_bind)
 {
@@ -395,7 +395,7 @@
ldap_linkdata *ld;
int rc;
 
-   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, r|ss, link, 
ldap_bind_dn, ldap_bind_dnlen, ldap_bind_pw, ldap_bind_pwlen) != SUCCESS) {
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, r|ss, link, 
ldap_bind_dn, ldap_bind_dnlen, UG(utf8_conv), ldap_bind_pw, 
ldap_bind_pwlen, UG(utf8_conv)) != SUCCESS) {
RETURN_FALSE;
}
 
@@ -495,7 +495,7 @@
 }
 /* }}} */
 
-/* {{{ proto bool ldap_sasl_bind(resource link [, string binddn [, string 
password [, string sasl_mech [, string sasl_realm [, string sasl_authc_id [, 
string sasl_authz_id [, string props]]])
+/* {{{ proto bool ldap_sasl_bind(resource link [, string binddn [, string 
password [, string sasl_mech [, string sasl_realm [, string sasl_authc_id [, 
string sasl_authz_id [, string props]]]) U
Bind to LDAP directory using SASL */
 PHP_FUNCTION(ldap_sasl_bind)
 {
@@ -511,7 +511,7 @@
int rc, dn_len, passwd_len, mech_len, realm_len, authc_id_len, 
authz_id_len, props_len;
php_ldap_bictx *ctx;
 
-   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, r|sss, 
link, binddn, dn_len, passwd, passwd_len, sasl_mech, mech_len, 
sasl_realm, realm_len, sasl_authc_id, authc_id_len, sasl_authz_id, 
authz_id_len, props, props_len) != SUCCESS) {
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, 
r|sss, link, binddn, dn_len, UG(utf8_conv), passwd, 
passwd_len, UG(utf8_conv), sasl_mech, mech_len, UG(utf8_conv), sasl_realm, 
realm_len, UG(utf8_conv), sasl_authc_id, authc_id_len, UG(utf8_conv), 
sasl_authz_id, authz_id_len, UG(utf8_conv), props, props_len, 
UG(utf8_conv)) != SUCCESS) {
RETURN_FALSE;
}
 
@@ -535,7 +535,7 @@
 /* }}} */
 #endif /* HAVE_LDAP_SASL */
 
-/* {{{ proto bool ldap_unbind(resource link)
+/* {{{ proto bool ldap_unbind(resource link) U
Unbind from LDAP directory */
 PHP_FUNCTION(ldap_unbind)
 {
@@ -612,6 +612,7 @@
int num_attribs = 0;
int i, errno;
int myargcount = ZEND_NUM_ARGS();
+   int free_base_dn = 0;
int ret = 1;
 
if (zend_parse_parameters(myargcount TSRMLS_CC, ZZZ|Z, link, 
base_dn, filter, attrs, attrsonly, 
@@ -695,6 +696,11 @@
/* If anything else than string is passed, ldap_base_dn 
= NULL */
if (Z_TYPE_PP(base_dn) == IS_STRING) {
ldap_base_dn = Z_STRVAL_PP(base_dn);
+   } else if(Z_TYPE_PP(base_dn) == IS_UNICODE){
+   char *tmp = 
zend_unicode_to_ascii(Z_USTRVAL_PP(base_dn), Z_USTRLEN_PP(base_dn) 

[PHP-CVS] cvs: php-src /ext/ldap ldap.c /ext/ldap/tests bug48441.phpt connect.inc skipifbindfailure.inc

2009-06-15 Thread Patrick Allaert
patrickallaert  Mon Jun 15 15:18:13 2009 UTC

  Added files: 
/php-src/ext/ldap/tests connect.inc skipifbindfailure.inc 
bug48441.phpt 

  Modified files:  
/php-src/ext/ldap   ldap.c 
  Log:
  Fixing #48441 (ldap_search() with sizelimit/timelimit/deref options makes 
those options persistent)
  http://cvs.php.net/viewvc.cgi/php-src/ext/ldap/ldap.c?r1=1.202r2=1.203diff_format=u
Index: php-src/ext/ldap/ldap.c
diff -u php-src/ext/ldap/ldap.c:1.202 php-src/ext/ldap/ldap.c:1.203
--- php-src/ext/ldap/ldap.c:1.202   Mon Jun 15 15:03:31 2009
+++ php-src/ext/ldap/ldap.c Mon Jun 15 15:18:12 2009
@@ -23,7 +23,7 @@
+--+
  */
  
-/* $Id: ldap.c,v 1.202 2009/06/15 15:03:31 patrickallaert Exp $ */
+/* $Id: ldap.c,v 1.203 2009/06/15 15:18:12 patrickallaert Exp $ */
 #define IS_EXT_MODULE
 
 #ifdef HAVE_CONFIG_H
@@ -235,7 +235,7 @@
 
php_info_print_table_start();
php_info_print_table_row(2, LDAP Support, enabled);
-   php_info_print_table_row(2, RCS Version, $Id: ldap.c,v 1.202 
2009/06/15 15:03:31 patrickallaert Exp $);
+   php_info_print_table_row(2, RCS Version, $Id: ldap.c,v 1.203 
2009/06/15 15:18:12 patrickallaert Exp $);
 
if (LDAPG(max_links) == -1) {
snprintf(tmp, 31, %ld/unlimited, LDAPG(num_links));
@@ -555,13 +555,15 @@
 
 /* {{{ php_set_opts
  */
-static void php_set_opts(LDAP *ldap, int sizelimit, int timelimit, int deref)
+static void php_set_opts(LDAP *ldap, int sizelimit, int timelimit, int deref, 
int *old_sizelimit, int *old_timelimit, int *old_deref)
 {
/* sizelimit */
if (sizelimit  -1) {
 #if (LDAP_API_VERSION = 2004) || HAVE_NSLDAP || HAVE_ORALDAP_10
+   ldap_get_option(ldap, LDAP_OPT_SIZELIMIT, old_sizelimit);
ldap_set_option(ldap, LDAP_OPT_SIZELIMIT, sizelimit);
 #else
+   *old_sizelimit = ldap-ld_sizelimit; 
ldap-ld_sizelimit = sizelimit; 
 #endif
}
@@ -569,8 +571,10 @@
/* timelimit */
if (timelimit  -1) {
 #if (LDAP_API_VERSION = 2004) || HAVE_NSLDAP || HAVE_ORALDAP_10
+   ldap_get_option(ldap, LDAP_OPT_SIZELIMIT, old_timelimit);
ldap_set_option(ldap, LDAP_OPT_TIMELIMIT, timelimit);
 #else
+   *old_timelimit = ldap-ld_timelimit; 
ldap-ld_timelimit = timelimit; 
 #endif
}
@@ -578,8 +582,10 @@
/* deref */
if (deref  -1) {
 #if (LDAP_API_VERSION = 2004) || HAVE_NSLDAP || HAVE_ORALDAP_10
+   ldap_get_option(ldap, LDAP_OPT_SIZELIMIT, old_deref);
ldap_set_option(ldap, LDAP_OPT_DEREF, deref);
 #else
+   *old_deref = ldap-ld_deref; 
ldap-ld_deref = deref; 
 #endif
}
@@ -600,6 +606,9 @@
int ldap_sizelimit = -1; 
int ldap_timelimit = -1; 
int ldap_deref = -1; 
+   int old_ldap_sizelimit = -1; 
+   int old_ldap_timelimit = -1; 
+   int old_ldap_deref = -1; 
int num_attribs = 0;
int i, errno;
int myargcount = ZEND_NUM_ARGS();
@@ -735,7 +744,7 @@
ldap_filter = Z_STRVAL_PP(entry);
}
 
-   php_set_opts(ld-link, ldap_sizelimit, ldap_timelimit, 
ldap_deref);
+   php_set_opts(ld-link, ldap_sizelimit, ldap_timelimit, 
ldap_deref, old_ldap_sizelimit, old_ldap_timelimit, old_ldap_deref);
 
/* Run the actual search */ 
rcs[i] = ldap_search(ld-link, ldap_base_dn, scope, 
ldap_filter, ldap_attrs, ldap_attrsonly);
@@ -777,7 +786,7 @@
goto cleanup;
}
 
-   php_set_opts(ld-link, ldap_sizelimit, ldap_timelimit, 
ldap_deref);
+   php_set_opts(ld-link, ldap_sizelimit, ldap_timelimit, 
ldap_deref, old_ldap_sizelimit, old_ldap_timelimit, old_ldap_deref);
 
/* Run the actual search */ 
errno = ldap_search_s(ld-link, ldap_base_dn, scope, 
ldap_filter, ldap_attrs, ldap_attrsonly, ldap_res);
@@ -808,6 +817,8 @@
}
 
 cleanup:
+   // Restoring previous options
+   php_set_opts(ld-link, old_ldap_sizelimit, old_ldap_timelimit, 
old_ldap_deref, ldap_sizelimit, ldap_timelimit, ldap_deref);
if (ldap_attrs != NULL) {
efree(ldap_attrs);
}

http://cvs.php.net/viewvc.cgi/php-src/ext/ldap/tests/connect.inc?view=markuprev=1.1
Index: php-src/ext/ldap/tests/connect.inc
+++ php-src/ext/ldap/tests/connect.inc
?php

/*
Default values are localhost, root, database test and empty password.
Change the LDAP_TEST_* environment values if you want to use another 
configuration.
*/

$host   = getenv(LDAP_TEST_HOST)  ? 
getenv(LDAP_TEST_HOST)  : localhost;
$port   = getenv(LDAP_TEST_PORT)  ?