summaryrefslogtreecommitdiff
path: root/ext/ldap
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2013-03-14 05:42:27 +0000
committer <>2013-04-03 16:25:08 +0000
commitc4dd7a1a684490673e25aaf4fabec5df138854c4 (patch)
tree4d57c44caae4480efff02b90b9be86f44bf25409 /ext/ldap
downloadphp2-c4dd7a1a684490673e25aaf4fabec5df138854c4.tar.gz
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'ext/ldap')
-rw-r--r--ext/ldap/CREDITS2
-rw-r--r--ext/ldap/LDAP_Win32_HOWTO.txt33
-rw-r--r--ext/ldap/config.m4195
-rw-r--r--ext/ldap/config.w3230
-rw-r--r--ext/ldap/ldap.c2744
-rw-r--r--ext/ldap/ldap.dsp288
-rw-r--r--ext/ldap/ldap.mak173
-rw-r--r--ext/ldap/php_ldap.h53
-rw-r--r--ext/ldap/tests/README53
-rw-r--r--ext/ldap/tests/bug48441.phpt169
-rw-r--r--ext/ldap/tests/bug48696.phpt15
-rw-r--r--ext/ldap/tests/connect.inc61
-rw-r--r--ext/ldap/tests/ldap_add_basic.phpt83
-rw-r--r--ext/ldap/tests/ldap_add_error.phpt136
-rw-r--r--ext/ldap/tests/ldap_bind_basic.phpt20
-rw-r--r--ext/ldap/tests/ldap_bind_error.phpt35
-rw-r--r--ext/ldap/tests/ldap_bind_variation.phpt20
-rw-r--r--ext/ldap/tests/ldap_compare_basic.phpt31
-rw-r--r--ext/ldap/tests/ldap_compare_error.phpt55
-rw-r--r--ext/ldap/tests/ldap_connect_basic.phpt18
-rw-r--r--ext/ldap/tests/ldap_connect_error.phpt31
-rw-r--r--ext/ldap/tests/ldap_connect_variation.phpt39
-rw-r--r--ext/ldap/tests/ldap_control_paged_results_variation1.phpt56
-rw-r--r--ext/ldap/tests/ldap_control_paged_results_variation2.phpt72
-rw-r--r--ext/ldap/tests/ldap_control_paged_results_variation3.phpt100
-rw-r--r--ext/ldap/tests/ldap_count_entries_basic.phpt28
-rw-r--r--ext/ldap/tests/ldap_count_entries_error.phpt23
-rw-r--r--ext/ldap/tests/ldap_delete_basic.phpt40
-rw-r--r--ext/ldap/tests/ldap_delete_error.phpt62
-rw-r--r--ext/ldap/tests/ldap_dn2ufn.phpt33
-rw-r--r--ext/ldap/tests/ldap_err2str_basic.phpt15
-rw-r--r--ext/ldap/tests/ldap_err2str_error.phpt28
-rw-r--r--ext/ldap/tests/ldap_errno_basic.phpt30
-rw-r--r--ext/ldap/tests/ldap_errno_error.phpt23
-rw-r--r--ext/ldap/tests/ldap_error_basic.phpt30
-rw-r--r--ext/ldap/tests/ldap_error_error.phpt23
-rw-r--r--ext/ldap/tests/ldap_explode_dn.phpt94
-rw-r--r--ext/ldap/tests/ldap_first_attribute_basic.phpt31
-rw-r--r--ext/ldap/tests/ldap_first_attribute_error.phpt23
-rw-r--r--ext/ldap/tests/ldap_first_entry_basic.phpt37
-rw-r--r--ext/ldap/tests/ldap_first_entry_error.phpt27
-rw-r--r--ext/ldap/tests/ldap_first_reference_basic.phpt43
-rw-r--r--ext/ldap/tests/ldap_first_reference_error.phpt27
-rw-r--r--ext/ldap/tests/ldap_free_result_basic.phpt28
-rw-r--r--ext/ldap/tests/ldap_free_result_error.phpt23
-rw-r--r--ext/ldap/tests/ldap_get_attributes_basic.phpt65
-rw-r--r--ext/ldap/tests/ldap_get_attributes_error.phpt23
-rw-r--r--ext/ldap/tests/ldap_get_dn_basic.phpt31
-rw-r--r--ext/ldap/tests/ldap_get_dn_error.phpt23
-rw-r--r--ext/ldap/tests/ldap_get_entries_basic.phpt74
-rw-r--r--ext/ldap/tests/ldap_get_entries_error.phpt33
-rw-r--r--ext/ldap/tests/ldap_get_entries_variation.phpt36
-rw-r--r--ext/ldap/tests/ldap_get_option_basic.phpt25
-rw-r--r--ext/ldap/tests/ldap_get_option_error.phpt40
-rw-r--r--ext/ldap/tests/ldap_get_option_variation.phpt66
-rw-r--r--ext/ldap/tests/ldap_get_values_len_basic.phpt36
-rw-r--r--ext/ldap/tests/ldap_get_values_len_error.phpt45
-rw-r--r--ext/ldap/tests/ldap_list_basic.phpt150
-rw-r--r--ext/ldap/tests/ldap_list_error.phpt35
-rw-r--r--ext/ldap/tests/ldap_mod_add_basic.phpt90
-rw-r--r--ext/ldap/tests/ldap_mod_add_error.phpt83
-rw-r--r--ext/ldap/tests/ldap_mod_del_basic.phpt43
-rw-r--r--ext/ldap/tests/ldap_mod_del_error.phpt62
-rw-r--r--ext/ldap/tests/ldap_mod_replace_basic.phpt59
-rw-r--r--ext/ldap/tests/ldap_mod_replace_error.phpt62
-rw-r--r--ext/ldap/tests/ldap_modify_basic.phpt96
-rw-r--r--ext/ldap/tests/ldap_modify_error.phpt83
-rw-r--r--ext/ldap/tests/ldap_next_attribute_basic.phpt36
-rw-r--r--ext/ldap/tests/ldap_next_attribute_error.phpt40
-rw-r--r--ext/ldap/tests/ldap_next_entry_basic.phpt40
-rw-r--r--ext/ldap/tests/ldap_next_entry_error.phpt27
-rw-r--r--ext/ldap/tests/ldap_next_reference_basic.phpt49
-rw-r--r--ext/ldap/tests/ldap_next_reference_error.phpt27
-rw-r--r--ext/ldap/tests/ldap_parse_reference_basic.phpt45
-rw-r--r--ext/ldap/tests/ldap_parse_reference_error.phpt31
-rw-r--r--ext/ldap/tests/ldap_parse_result_basic.phpt47
-rw-r--r--ext/ldap/tests/ldap_parse_result_error.phpt17
-rw-r--r--ext/ldap/tests/ldap_read_basic.phpt75
-rw-r--r--ext/ldap/tests/ldap_read_error.phpt35
-rw-r--r--ext/ldap/tests/ldap_rename_basic.phpt62
-rw-r--r--ext/ldap/tests/ldap_rename_error.phpt21
-rw-r--r--ext/ldap/tests/ldap_sasl_bind_basic.phpt27
-rw-r--r--ext/ldap/tests/ldap_sasl_bind_error.phpt53
-rw-r--r--ext/ldap/tests/ldap_search_basic.phpt194
-rw-r--r--ext/ldap/tests/ldap_search_error.phpt61
-rw-r--r--ext/ldap/tests/ldap_search_variation1.phpt56
-rw-r--r--ext/ldap/tests/ldap_search_variation2.phpt80
-rw-r--r--ext/ldap/tests/ldap_search_variation3.phpt108
-rw-r--r--ext/ldap/tests/ldap_search_variation4.phpt55
-rw-r--r--ext/ldap/tests/ldap_search_variation5.phpt105
-rw-r--r--ext/ldap/tests/ldap_search_variation6.phpt230
-rw-r--r--ext/ldap/tests/ldap_set_option_basic.phpt23
-rw-r--r--ext/ldap/tests/ldap_set_option_error.phpt66
-rw-r--r--ext/ldap/tests/ldap_set_option_variation.phpt84
-rw-r--r--ext/ldap/tests/ldap_set_rebind_proc_basic.phpt34
-rw-r--r--ext/ldap/tests/ldap_set_rebind_proc_error.phpt50
-rw-r--r--ext/ldap/tests/ldap_sort_basic.phpt200
-rw-r--r--ext/ldap/tests/ldap_sort_error.phpt35
-rw-r--r--ext/ldap/tests/ldap_sort_variation.phpt200
-rw-r--r--ext/ldap/tests/ldap_start_tls_basic.phpt20
-rw-r--r--ext/ldap/tests/ldap_start_tls_error.phpt27
-rw-r--r--ext/ldap/tests/ldap_unbind_basic.phpt20
-rw-r--r--ext/ldap/tests/ldap_unbind_error.phpt42
-rw-r--r--ext/ldap/tests/ldap_unbind_variation.phpt34
-rw-r--r--ext/ldap/tests/skipif.inc5
-rw-r--r--ext/ldap/tests/skipifbindfailure.inc13
106 files changed, 8814 insertions, 0 deletions
diff --git a/ext/ldap/CREDITS b/ext/ldap/CREDITS
new file mode 100644
index 0000000..5dc3d01
--- /dev/null
+++ b/ext/ldap/CREDITS
@@ -0,0 +1,2 @@
+LDAP
+Amitay Isaacs, Eric Warnke, Rasmus Lerdorf, Gerrit Thomson, Stig Venaas
diff --git a/ext/ldap/LDAP_Win32_HOWTO.txt b/ext/ldap/LDAP_Win32_HOWTO.txt
new file mode 100644
index 0000000..bcee731
--- /dev/null
+++ b/ext/ldap/LDAP_Win32_HOWTO.txt
@@ -0,0 +1,33 @@
+Rules for building LDAP
+-----------------------
+
+Note 1: During the entire build process, you can ignore warnings about
+ inconsistent DLL linkage.
+
+
+- Open LDAP under php_build. Rename this directory to 'OpenLDAP'.
+- Rename OpenLDAP\include\portable.h.nt to OpenLDAP\include\portable.h
+- Rename OpenLDAP\include\ldapconfig.h.nt to OpenLDAP\include\ldapconfig.h
+- Launch Visual Studio with OpenLDAP\libraries\libldap\libldap.dsw
+- Enter Project->Settings.
+ Select the C/C++ tab, and select 'Code Generation' in the Category box.
+ For 'Win32 Debug', change the runtime library to 'Debug Multithreaded DLL'
+ For 'Win32 Release', change the runtime library to 'Multithreaded DLL'
+ Select the Preprocessor tab, select 'All Configurations'.
+ Add '..\..\..\..\php5\regex' to the 'Additional include directories' list.
+ Add 'HAVE_MKTEMP' to the 'Preprocessor definitions' list.
+- Compile (you can compile both Debug and Release versions).
+
+
+- Launch Visual Studio with OpenLDAP\libraries\liblber\liblber.dsw
+- Enter Project->Settings.
+ Select the C/C++ tab, and select 'Code Generation' in the Category box.
+ For 'Win32 Debug', change the runtime library to 'Debug Multithreaded DLL'
+ For 'Win32 Release', change the runtime library to 'Multithreaded DLL'
+ Select the Preprocessor tab, select 'All Configurations'.
+ Add 'HAVE_MKTEMP' to the 'Preprocessor definitions' list.
+- Compile (you can compile both Debug and Release versions).
+
+
+Start Visual Studio, load php_modules.dsw, select the LDAP project, and build
+it.
diff --git a/ext/ldap/config.m4 b/ext/ldap/config.m4
new file mode 100644
index 0000000..58d994c
--- /dev/null
+++ b/ext/ldap/config.m4
@@ -0,0 +1,195 @@
+dnl
+dnl $Id$
+dnl
+
+AC_DEFUN([PHP_LDAP_CHECKS], [
+ if test -f $1/include/ldap.h; then
+ LDAP_DIR=$1
+ LDAP_INCDIR=$1/include
+ LDAP_LIBDIR=$1/$PHP_LIBDIR
+ elif test -f $1/include/umich-ldap/ldap.h; then
+ LDAP_DIR=$1
+ LDAP_INCDIR=$1/include/umich-ldap
+ LDAP_LIBDIR=$1/$PHP_LIBDIR
+ elif test -f $1/ldap/public/ldap.h; then
+ LDAP_DIR=$1
+ LDAP_INCDIR=$1/ldap/public
+ LDAP_LIBDIR=$1/$PHP_LIBDIR
+ fi
+])
+
+AC_DEFUN([PHP_LDAP_SASL_CHECKS], [
+ if test "$1" = "yes"; then
+ SEARCH_DIRS="/usr/local /usr"
+ else
+ SEARCH_DIRS=$1
+ fi
+
+ for i in $SEARCH_DIRS; do
+ if test -f $i/include/sasl/sasl.h; then
+ LDAP_SASL_DIR=$i
+ AC_DEFINE(HAVE_LDAP_SASL_SASL_H,1,[ ])
+ break
+ elif test -f $i/include/sasl.h; then
+ LDAP_SASL_DIR=$i
+ AC_DEFINE(HAVE_LDAP_SASL_H,1,[ ])
+ break
+ fi
+ done
+
+ if test "$LDAP_SASL_DIR"; then
+ LDAP_SASL_INCDIR=$LDAP_SASL_DIR/include
+ LDAP_SASL_LIBDIR=$LDAP_SASL_DIR/$PHP_LIBDIR
+ else
+ AC_MSG_ERROR([sasl.h not found!])
+ fi
+
+ if test "$PHP_LDAP_SASL" = "yes"; then
+ SASL_LIB="-lsasl2"
+ else
+ SASL_LIB="-L$LDAP_SASL_LIBDIR -lsasl2"
+ fi
+
+ PHP_CHECK_LIBRARY(sasl2, sasl_version,
+ [
+ PHP_ADD_INCLUDE($LDAP_SASL_INCDIR)
+ PHP_ADD_LIBRARY_WITH_PATH(sasl2, $LDAP_SASL_LIBDIR, LDAP_SHARED_LIBADD)
+ AC_DEFINE(HAVE_LDAP_SASL, 1, [LDAP SASL support])
+ ], [
+ AC_MSG_ERROR([LDAP SASL check failed. Please check config.log for more information.])
+ ], [
+ $LDAP_SHARED_LIBADD $SASL_LIB
+ ])
+])
+
+PHP_ARG_WITH(ldap,for LDAP support,
+[ --with-ldap[=DIR] Include LDAP support])
+
+PHP_ARG_WITH(ldap-sasl,for LDAP Cyrus SASL support,
+[ --with-ldap-sasl[=DIR] LDAP: Include Cyrus SASL support], no, no)
+
+if test "$PHP_LDAP" != "no"; then
+
+ PHP_NEW_EXTENSION(ldap, ldap.c, $ext_shared,,-DLDAP_DEPRECATED=1)
+
+ if test "$PHP_LDAP" = "yes"; then
+ for i in /usr/local /usr; do
+ PHP_LDAP_CHECKS($i)
+ done
+ else
+ PHP_LDAP_CHECKS($PHP_LDAP)
+ fi
+
+ if test -z "$LDAP_DIR"; then
+ AC_MSG_ERROR(Cannot find ldap.h)
+ fi
+
+ dnl The Linux version of the SDK need -lpthread
+ dnl I have tested Solaris, and it doesn't, but others may. Add
+ dnl these here if necessary. -RL
+ dnl Is this really necessary? -Troels Arvin
+
+ if test `uname` = "Linux"; then
+ LDAP_PTHREAD=pthread
+ else
+ LDAP_PTHREAD=
+ fi
+
+ if test -f $LDAP_LIBDIR/liblber.a || test -f $LDAP_LIBDIR/liblber.$SHLIB_SUFFIX_NAME; then
+ PHP_ADD_LIBRARY_WITH_PATH(lber, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
+ PHP_ADD_LIBRARY_WITH_PATH(ldap, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
+
+ elif test -f $LDAP_LIBDIR/libldap.$SHLIB_SUFFIX_NAME || test -f $LDAP_LIBDIR/libldap.$SHLIB_SUFFIX_NAME.3 || test -f $LDAP_LIBDIR/libldap.3.dylib; then
+ PHP_ADD_LIBRARY_WITH_PATH(ldap, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
+
+ elif test -f $LDAP_LIBDIR/libssldap50.$SHLIB_SUFFIX_NAME; then
+ if test -n "$LDAP_PTHREAD"; then
+ PHP_ADD_LIBRARY($LDAP_PTHREAD)
+ fi
+ PHP_ADD_LIBRARY_WITH_PATH(nspr4, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
+ PHP_ADD_LIBRARY_WITH_PATH(plc4, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
+ PHP_ADD_LIBRARY_WITH_PATH(plds4, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
+ PHP_ADD_LIBRARY_WITH_PATH(ssldap50, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
+ PHP_ADD_LIBRARY_WITH_PATH(ldap50, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
+ PHP_ADD_LIBRARY_WITH_PATH(prldap50, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
+ PHP_ADD_LIBRARY_WITH_PATH(ssl3, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
+ AC_DEFINE(HAVE_NSLDAP,1,[ ])
+
+ elif test -f $LDAP_LIBDIR/libldapssl41.$SHLIB_SUFFIX_NAME; then
+ if test -n "$LDAP_PTHREAD"; then
+ PHP_ADD_LIBRARY($LDAP_PTHREAD)
+ fi
+ PHP_ADD_LIBRARY_WITH_PATH(nspr3, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
+ PHP_ADD_LIBRARY_WITH_PATH(plc3, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
+ PHP_ADD_LIBRARY_WITH_PATH(plds3, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
+ PHP_ADD_LIBRARY_WITH_PATH(ldapssl41, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
+ AC_DEFINE(HAVE_NSLDAP,1,[ ])
+
+ elif test -f $LDAP_LIBDIR/libldapssl30.$SHLIB_SUFFIX_NAME; then
+ if test -n "$LDAP_PTHREAD"; then
+ PHP_ADD_LIBRARY($LDAP_PTHREAD)
+ fi
+ PHP_ADD_LIBRARY_WITH_PATH(ldapssl30, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
+ AC_DEFINE(HAVE_NSLDAP,1,[ ])
+
+ elif test -f $LDAP_LIBDIR/libldap30.$SHLIB_SUFFIX_NAME; then
+ if test -n "$LDAP_PTHREAD"; then
+ PHP_ADD_LIBRARY($LDAP_PTHREAD)
+ fi
+ PHP_ADD_LIBRARY_WITH_PATH(ldap30, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
+ AC_DEFINE(HAVE_NSLDAP,1,[ ])
+
+ elif test -f $LDAP_LIBDIR/libumich_ldap.$SHLIB_SUFFIX_NAME; then
+ PHP_ADD_LIBRARY_WITH_PATH(umich_lber, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
+ PHP_ADD_LIBRARY_WITH_PATH(umich_ldap, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
+
+ elif test -f $LDAP_LIBDIR/libclntsh.$SHLIB_SUFFIX_NAME; then
+ PHP_ADD_LIBRARY_WITH_PATH(clntsh, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
+ AC_DEFINE(HAVE_ORALDAP,1,[ ])
+ if test -f $LDAP_LIBDIR/libclntsh.$SHLIB_SUFFIX_NAME.10.1; then
+ AC_DEFINE(HAVE_ORALDAP_10,1,[ ])
+ fi
+ else
+ AC_MSG_ERROR(Cannot find ldap libraries in $LDAP_LIBDIR.)
+ fi
+
+ PHP_ADD_INCLUDE($LDAP_INCDIR)
+ PHP_SUBST(LDAP_SHARED_LIBADD)
+ AC_DEFINE(HAVE_LDAP,1,[ ])
+
+ dnl Save original values
+ _SAVE_CPPFLAGS=$CPPFLAGS
+ _SAVE_LIBS=$LIBS
+ CPPFLAGS="$CPPFLAGS -I$LDAP_INCDIR"
+ LIBS="$LIBS $LDAP_SHARED_LIBADD"
+
+ dnl Check for 3 arg ldap_set_rebind_proc
+ AC_CACHE_CHECK([for 3 arg ldap_set_rebind_proc], ac_cv_3arg_setrebindproc,
+ [AC_TRY_COMPILE([#include <ldap.h>], [ldap_set_rebind_proc(0,0,0)],
+ ac_cv_3arg_setrebindproc=yes, ac_cv_3arg_setrebindproc=no)])
+ if test "$ac_cv_3arg_setrebindproc" = yes; then
+ AC_DEFINE(HAVE_3ARG_SETREBINDPROC,1,[Whether 3 arg set_rebind_proc()])
+ fi
+
+ dnl Solaris 2.8 claims to be 2004 API, but doesn't have
+ dnl ldap_parse_reference() nor ldap_start_tls_s()
+ AC_CHECK_FUNCS([ldap_parse_result ldap_parse_reference ldap_start_tls_s])
+
+ dnl
+ dnl SASL check
+ dnl
+ if test "$PHP_LDAP_SASL" != "no"; then
+ PHP_LDAP_SASL_CHECKS([$PHP_LDAP_SASL])
+ fi
+
+ dnl
+ dnl Sanity check
+ dnl
+ AC_CHECK_FUNC(ldap_bind_s, [], [
+ AC_MSG_ERROR([LDAP build check failed. Please check config.log for more information.])
+ ])
+
+ dnl Restore original values
+ CPPFLAGS=$_SAVE_CPPFLAGS
+ LIBS=$_SAVE_LIBS
+fi
diff --git a/ext/ldap/config.w32 b/ext/ldap/config.w32
new file mode 100644
index 0000000..2fa05f4
--- /dev/null
+++ b/ext/ldap/config.w32
@@ -0,0 +1,30 @@
+// $Id$
+// vim:ft=javascript
+
+ARG_WITH("ldap", "LDAP support", "no");
+
+if (PHP_LDAP != "no") {
+
+ if (CHECK_HEADER_ADD_INCLUDE("ldap.h", "CFLAGS_LDAP", PHP_PHP_BUILD + "\\include\\openldap;" + PHP_PHP_BUILD + "\\openldap\\include;" + PHP_LDAP) &&
+ CHECK_HEADER_ADD_INCLUDE("lber.h", "CFLAGS_LDAP", PHP_PHP_BUILD + "\\include\\openldap;" + PHP_PHP_BUILD + "\\openldap\\include;" + PHP_LDAP)
+ &&
+ CHECK_LIB("ssleay32.lib", "ldap", PHP_LDAP) &&
+ CHECK_LIB("libeay32.lib", "ldap", PHP_LDAP) &&
+ CHECK_LIB("oldap32_a.lib", "ldap", PHP_LDAP) &&
+ CHECK_LIB("olber32_a.lib", "ldap", PHP_LDAP)&&
+ CHECK_LIB("libsasl.lib", "ldap", PHP_LDAP)) {
+ EXTENSION('ldap', 'ldap.c');
+
+ AC_DEFINE('HAVE_LDAP_PARSE_RESULT', 1);
+ AC_DEFINE('HAVE_LDAP_PARSE_REFERENCE', 1);
+ AC_DEFINE('HAVE_LDAP_START_TLS_S', 1);
+ AC_DEFINE('HAVE_LDAP', 1);
+ AC_DEFINE('HAVE_LDAP_SASL', 1);
+ AC_DEFINE('HAVE_LDAP_SASL_SASL_H', 1);
+ AC_DEFINE('LDAP_DEPRECATED', 1);
+
+ } else {
+ WARNING("ldap not enabled; libraries and headers not found");
+ }
+}
+
diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c
new file mode 100644
index 0000000..3cfa209
--- /dev/null
+++ b/ext/ldap/ldap.c
@@ -0,0 +1,2744 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2013 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Authors: Amitay Isaacs <amitay@w-o-i.com> |
+ | Eric Warnke <ericw@albany.edu> |
+ | Rasmus Lerdorf <rasmus@php.net> |
+ | Gerrit Thomson <334647@swin.edu.au> |
+ | Jani Taskinen <sniper@iki.fi> |
+ | Stig Venaas <venaas@uninett.no> |
+ | Doug Goldstein <cardoe@cardoe.com> |
+ | PHP 4.0 updates: Zeev Suraski <zeev@zend.com> |
+ +----------------------------------------------------------------------+
+ */
+
+/* $Id$ */
+#define IS_EXT_MODULE
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* Additional headers for NetWare */
+#if defined(NETWARE) && (NEW_LIBC)
+#include <sys/select.h>
+#include <sys/timeval.h>
+#endif
+
+#include "php.h"
+#include "php_ini.h"
+
+#include <stddef.h>
+
+#include "ext/standard/dl.h"
+#include "php_ldap.h"
+
+#ifdef PHP_WIN32
+#include <string.h>
+#include "config.w32.h"
+#if HAVE_NSLDAP
+#include <winsock2.h>
+#endif
+#define strdup _strdup
+#undef WINDOWS
+#undef strcasecmp
+#undef strncasecmp
+#define WINSOCK 1
+#define __STDC__ 1
+#endif
+
+#include "ext/standard/php_string.h"
+#include "ext/standard/info.h"
+
+#ifdef HAVE_LDAP_SASL_H
+#include <sasl.h>
+#elif defined(HAVE_LDAP_SASL_SASL_H)
+#include <sasl/sasl.h>
+#endif
+
+typedef struct {
+ LDAP *link;
+#if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
+ zval *rebindproc;
+#endif
+} ldap_linkdata;
+
+typedef struct {
+ LDAPMessage *data;
+ BerElement *ber;
+ int id;
+} ldap_resultentry;
+
+ZEND_DECLARE_MODULE_GLOBALS(ldap)
+static PHP_GINIT_FUNCTION(ldap);
+
+static int le_link, le_result, le_result_entry;
+
+#ifdef COMPILE_DL_LDAP
+ZEND_GET_MODULE(ldap)
+#endif
+
+static void _close_ldap_link(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
+{
+ ldap_linkdata *ld = (ldap_linkdata *)rsrc->ptr;
+
+ ldap_unbind_s(ld->link);
+#if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
+ if (ld->rebindproc != NULL) {
+ zval_dtor(ld->rebindproc);
+ FREE_ZVAL(ld->rebindproc);
+ }
+#endif
+ efree(ld);
+ LDAPG(num_links)--;
+}
+/* }}} */
+
+static void _free_ldap_result(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
+{
+ LDAPMessage *result = (LDAPMessage *)rsrc->ptr;
+ ldap_msgfree(result);
+}
+/* }}} */
+
+static void _free_ldap_result_entry(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
+{
+ ldap_resultentry *entry = (ldap_resultentry *)rsrc->ptr;
+
+ if (entry->ber != NULL) {
+ ber_free(entry->ber, 0);
+ entry->ber = NULL;
+ }
+ zend_list_delete(entry->id);
+ efree(entry);
+}
+/* }}} */
+
+/* {{{ PHP_INI_BEGIN
+ */
+PHP_INI_BEGIN()
+ STD_PHP_INI_ENTRY_EX("ldap.max_links", "-1", PHP_INI_SYSTEM, OnUpdateLong, max_links, zend_ldap_globals, ldap_globals, display_link_numbers)
+PHP_INI_END()
+/* }}} */
+
+/* {{{ PHP_GINIT_FUNCTION
+ */
+static PHP_GINIT_FUNCTION(ldap)
+{
+ ldap_globals->num_links = 0;
+}
+/* }}} */
+
+/* {{{ PHP_MINIT_FUNCTION
+ */
+PHP_MINIT_FUNCTION(ldap)
+{
+ REGISTER_INI_ENTRIES();
+
+ /* Constants to be used with deref-parameter in php_ldap_do_search() */
+ REGISTER_LONG_CONSTANT("LDAP_DEREF_NEVER", LDAP_DEREF_NEVER, CONST_PERSISTENT | CONST_CS);
+ REGISTER_LONG_CONSTANT("LDAP_DEREF_SEARCHING", LDAP_DEREF_SEARCHING, CONST_PERSISTENT | CONST_CS);
+ REGISTER_LONG_CONSTANT("LDAP_DEREF_FINDING", LDAP_DEREF_FINDING, CONST_PERSISTENT | CONST_CS);
+ REGISTER_LONG_CONSTANT("LDAP_DEREF_ALWAYS", LDAP_DEREF_ALWAYS, CONST_PERSISTENT | CONST_CS);
+
+#if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP_10
+ /* LDAP options */
+ REGISTER_LONG_CONSTANT("LDAP_OPT_DEREF", LDAP_OPT_DEREF, CONST_PERSISTENT | CONST_CS);
+ REGISTER_LONG_CONSTANT("LDAP_OPT_SIZELIMIT", LDAP_OPT_SIZELIMIT, CONST_PERSISTENT | CONST_CS);
+ REGISTER_LONG_CONSTANT("LDAP_OPT_TIMELIMIT", LDAP_OPT_TIMELIMIT, CONST_PERSISTENT | CONST_CS);
+#ifdef LDAP_OPT_NETWORK_TIMEOUT
+ REGISTER_LONG_CONSTANT("LDAP_OPT_NETWORK_TIMEOUT", LDAP_OPT_NETWORK_TIMEOUT, CONST_PERSISTENT | CONST_CS);
+#elif defined (LDAP_X_OPT_CONNECT_TIMEOUT)
+ REGISTER_LONG_CONSTANT("LDAP_OPT_NETWORK_TIMEOUT", LDAP_X_OPT_CONNECT_TIMEOUT, CONST_PERSISTENT | CONST_CS);
+#endif
+ REGISTER_LONG_CONSTANT("LDAP_OPT_PROTOCOL_VERSION", LDAP_OPT_PROTOCOL_VERSION, CONST_PERSISTENT | CONST_CS);
+ REGISTER_LONG_CONSTANT("LDAP_OPT_ERROR_NUMBER", LDAP_OPT_ERROR_NUMBER, CONST_PERSISTENT | CONST_CS);
+ REGISTER_LONG_CONSTANT("LDAP_OPT_REFERRALS", LDAP_OPT_REFERRALS, CONST_PERSISTENT | CONST_CS);
+#ifdef LDAP_OPT_RESTART
+ REGISTER_LONG_CONSTANT("LDAP_OPT_RESTART", LDAP_OPT_RESTART, CONST_PERSISTENT | CONST_CS);
+#endif
+#ifdef LDAP_OPT_HOST_NAME
+ REGISTER_LONG_CONSTANT("LDAP_OPT_HOST_NAME", LDAP_OPT_HOST_NAME, CONST_PERSISTENT | CONST_CS);
+#endif
+ REGISTER_LONG_CONSTANT("LDAP_OPT_ERROR_STRING", LDAP_OPT_ERROR_STRING, CONST_PERSISTENT | CONST_CS);
+#ifdef LDAP_OPT_MATCHED_DN
+ REGISTER_LONG_CONSTANT("LDAP_OPT_MATCHED_DN", LDAP_OPT_MATCHED_DN, CONST_PERSISTENT | CONST_CS);
+#endif
+ REGISTER_LONG_CONSTANT("LDAP_OPT_SERVER_CONTROLS", LDAP_OPT_SERVER_CONTROLS, CONST_PERSISTENT | CONST_CS);
+ REGISTER_LONG_CONSTANT("LDAP_OPT_CLIENT_CONTROLS", LDAP_OPT_CLIENT_CONTROLS, CONST_PERSISTENT | CONST_CS);
+#endif
+#ifdef LDAP_OPT_DEBUG_LEVEL
+ REGISTER_LONG_CONSTANT("LDAP_OPT_DEBUG_LEVEL", LDAP_OPT_DEBUG_LEVEL, CONST_PERSISTENT | CONST_CS);
+#endif
+
+#ifdef HAVE_LDAP_SASL
+ REGISTER_LONG_CONSTANT("LDAP_OPT_X_SASL_MECH", LDAP_OPT_X_SASL_MECH, CONST_PERSISTENT | CONST_CS);
+ REGISTER_LONG_CONSTANT("LDAP_OPT_X_SASL_REALM", LDAP_OPT_X_SASL_REALM, CONST_PERSISTENT | CONST_CS);
+ REGISTER_LONG_CONSTANT("LDAP_OPT_X_SASL_AUTHCID", LDAP_OPT_X_SASL_AUTHCID, CONST_PERSISTENT | CONST_CS);
+ REGISTER_LONG_CONSTANT("LDAP_OPT_X_SASL_AUTHZID", LDAP_OPT_X_SASL_AUTHZID, CONST_PERSISTENT | CONST_CS);
+#endif
+
+#ifdef ORALDAP
+ REGISTER_LONG_CONSTANT("GSLC_SSL_NO_AUTH", GSLC_SSL_NO_AUTH, CONST_PERSISTENT | CONST_CS);
+ REGISTER_LONG_CONSTANT("GSLC_SSL_ONEWAY_AUTH", GSLC_SSL_ONEWAY_AUTH, CONST_PERSISTENT | CONST_CS);
+ REGISTER_LONG_CONSTANT("GSLC_SSL_TWOWAY_AUTH", GSLC_SSL_TWOWAY_AUTH, CONST_PERSISTENT | CONST_CS);
+#endif
+
+ le_link = zend_register_list_destructors_ex(_close_ldap_link, NULL, "ldap link", module_number);
+ le_result = zend_register_list_destructors_ex(_free_ldap_result, NULL, "ldap result", module_number);
+ le_result_entry = zend_register_list_destructors_ex(_free_ldap_result_entry, NULL, "ldap result entry", module_number);
+
+ Z_TYPE(ldap_module_entry) = type;
+
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ PHP_MSHUTDOWN_FUNCTION
+ */
+PHP_MSHUTDOWN_FUNCTION(ldap)
+{
+ UNREGISTER_INI_ENTRIES();
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ PHP_MINFO_FUNCTION
+ */
+PHP_MINFO_FUNCTION(ldap)
+{
+ char tmp[32];
+#if HAVE_NSLDAP
+ LDAPVersion ver;
+ double SDKVersion;
+#endif
+
+ php_info_print_table_start();
+ php_info_print_table_row(2, "LDAP Support", "enabled");
+ php_info_print_table_row(2, "RCS Version", "$Id$");
+
+ if (LDAPG(max_links) == -1) {
+ snprintf(tmp, 31, "%ld/unlimited", LDAPG(num_links));
+ } else {
+ snprintf(tmp, 31, "%ld/%ld", LDAPG(num_links), LDAPG(max_links));
+ }
+ php_info_print_table_row(2, "Total Links", tmp);
+
+#ifdef LDAP_API_VERSION
+ snprintf(tmp, 31, "%d", LDAP_API_VERSION);
+ php_info_print_table_row(2, "API Version", tmp);
+#endif
+
+#ifdef LDAP_VENDOR_NAME
+ php_info_print_table_row(2, "Vendor Name", LDAP_VENDOR_NAME);
+#endif
+
+#ifdef LDAP_VENDOR_VERSION
+ snprintf(tmp, 31, "%d", LDAP_VENDOR_VERSION);
+ php_info_print_table_row(2, "Vendor Version", tmp);
+#endif
+
+#if HAVE_NSLDAP
+ SDKVersion = ldap_version(&ver);
+ snprintf(tmp, 31, "%F", SDKVersion/100.0);
+ php_info_print_table_row(2, "SDK Version", tmp);
+
+ snprintf(tmp, 31, "%F", ver.protocol_version/100.0);
+ php_info_print_table_row(2, "Highest LDAP Protocol Supported", tmp);
+
+ snprintf(tmp, 31, "%F", ver.SSL_version/100.0);
+ php_info_print_table_row(2, "SSL Level Supported", tmp);
+
+ if (ver.security_level != LDAP_SECURITY_NONE) {
+ snprintf(tmp, 31, "%d", ver.security_level);
+ } else {
+ strcpy(tmp, "SSL not enabled");
+ }
+ php_info_print_table_row(2, "Level of Encryption", tmp);
+#endif
+
+#ifdef HAVE_LDAP_SASL
+ php_info_print_table_row(2, "SASL Support", "Enabled");
+#endif
+
+ php_info_print_table_end();
+ DISPLAY_INI_ENTRIES();
+}
+/* }}} */
+
+/* {{{ proto resource ldap_connect([string host [, int port [, string wallet [, string wallet_passwd [, int authmode]]]]])
+ Connect to an LDAP server */
+PHP_FUNCTION(ldap_connect)
+{
+ char *host = NULL;
+ int hostlen;
+ long port = 389; /* Default port */
+#ifdef HAVE_ORALDAP
+ char *wallet = NULL, *walletpasswd = NULL;
+ int walletlen = 0, walletpasswdlen = 0;
+ long authmode = GSLC_SSL_NO_AUTH;
+ int ssl=0;
+#endif
+ ldap_linkdata *ld;
+ LDAP *ldap;
+
+#ifdef HAVE_ORALDAP
+ if (ZEND_NUM_ARGS() == 3 || ZEND_NUM_ARGS() == 4) {
+ WRONG_PARAM_COUNT;
+ }
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|slssl", &host, &hostlen, &port, &wallet, &walletlen, &walletpasswd, &walletpasswdlen, &authmode) != SUCCESS) {
+ RETURN_FALSE;
+ }
+
+ if (ZEND_NUM_ARGS() == 5) {
+ ssl = 1;
+ }
+#else
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sl", &host, &hostlen, &port) != SUCCESS) {
+ RETURN_FALSE;
+ }
+#endif
+
+ if (LDAPG(max_links) != -1 && LDAPG(num_links) >= LDAPG(max_links)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too many open links (%ld)", LDAPG(num_links));
+ RETURN_FALSE;
+ }
+
+ ld = ecalloc(1, sizeof(ldap_linkdata));
+
+#ifdef LDAP_API_FEATURE_X_OPENLDAP
+ if (host != NULL && strchr(host, '/')) {
+ int rc;
+
+ rc = ldap_initialize(&ldap, host);
+ if (rc != LDAP_SUCCESS) {
+ efree(ld);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not create session handle: %s", ldap_err2string(rc));
+ RETURN_FALSE;
+ }
+ } else {
+ ldap = ldap_init(host, port);
+ }
+#else
+ ldap = ldap_open(host, port);
+#endif
+
+ if (ldap == NULL) {
+ efree(ld);
+ RETURN_FALSE;
+ } else {
+#ifdef HAVE_ORALDAP
+ if (ssl) {
+ if (ldap_init_SSL(&ldap->ld_sb, wallet, walletpasswd, authmode)) {
+ efree(ld);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "SSL init failed");
+ RETURN_FALSE;
+ }
+ }
+#endif
+ LDAPG(num_links)++;
+ ld->link = ldap;
+ ZEND_REGISTER_RESOURCE(return_value, ld, le_link);
+ }
+
+}
+/* }}} */
+
+/* {{{ _get_lderrno
+ */
+static int _get_lderrno(LDAP *ldap)
+{
+#if !HAVE_NSLDAP
+#if LDAP_API_VERSION > 2000 || HAVE_ORALDAP_10
+ int lderr;
+
+ /* New versions of OpenLDAP do it this way */
+ ldap_get_option(ldap, LDAP_OPT_ERROR_NUMBER, &lderr);
+ return lderr;
+#else
+ return ldap->ld_errno;
+#endif
+#else
+ return ldap_get_lderrno(ldap, NULL, NULL);
+#endif
+}
+/* }}} */
+
+/* {{{ proto bool ldap_bind(resource link [, string dn [, string password]])
+ Bind to LDAP directory */
+PHP_FUNCTION(ldap_bind)
+{
+ zval *link;
+ char *ldap_bind_dn = NULL, *ldap_bind_pw = NULL;
+ int ldap_bind_dnlen, ldap_bind_pwlen;
+ 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) {
+ RETURN_FALSE;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+
+ if ((rc = ldap_bind_s(ld->link, ldap_bind_dn, ldap_bind_pw, LDAP_AUTH_SIMPLE)) != LDAP_SUCCESS) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to bind to server: %s", ldap_err2string(rc));
+ RETURN_FALSE;
+ } else {
+ RETURN_TRUE;
+ }
+}
+/* }}} */
+
+#ifdef HAVE_LDAP_SASL
+typedef struct {
+ char *mech;
+ char *realm;
+ char *authcid;
+ char *passwd;
+ char *authzid;
+} php_ldap_bictx;
+
+/* {{{ _php_sasl_setdefs
+ */
+static php_ldap_bictx *_php_sasl_setdefs(LDAP *ld, char *sasl_mech, char *sasl_realm, char *sasl_authc_id, char *passwd, char *sasl_authz_id)
+{
+ php_ldap_bictx *ctx;
+
+ ctx = ber_memalloc(sizeof(php_ldap_bictx));
+ ctx->mech = (sasl_mech) ? ber_strdup(sasl_mech) : NULL;
+ ctx->realm = (sasl_realm) ? ber_strdup(sasl_realm) : NULL;
+ ctx->authcid = (sasl_authc_id) ? ber_strdup(sasl_authc_id) : NULL;
+ ctx->passwd = (passwd) ? ber_strdup(passwd) : NULL;
+ ctx->authzid = (sasl_authz_id) ? ber_strdup(sasl_authz_id) : NULL;
+
+ if (ctx->mech == NULL) {
+ ldap_get_option(ld, LDAP_OPT_X_SASL_MECH, &ctx->mech);
+ }
+ if (ctx->realm == NULL) {
+ ldap_get_option(ld, LDAP_OPT_X_SASL_REALM, &ctx->realm);
+ }
+ if (ctx->authcid == NULL) {
+ ldap_get_option(ld, LDAP_OPT_X_SASL_AUTHCID, &ctx->authcid);
+ }
+ if (ctx->authzid == NULL) {
+ ldap_get_option(ld, LDAP_OPT_X_SASL_AUTHZID, &ctx->authzid);
+ }
+
+ return ctx;
+}
+/* }}} */
+
+/* {{{ _php_sasl_freedefs
+ */
+static void _php_sasl_freedefs(php_ldap_bictx *ctx)
+{
+ if (ctx->mech) ber_memfree(ctx->mech);
+ if (ctx->realm) ber_memfree(ctx->realm);
+ if (ctx->authcid) ber_memfree(ctx->authcid);
+ if (ctx->passwd) ber_memfree(ctx->passwd);
+ if (ctx->authzid) ber_memfree(ctx->authzid);
+ ber_memfree(ctx);
+}
+/* }}} */
+
+/* {{{ _php_sasl_interact
+ Internal interact function for SASL */
+static int _php_sasl_interact(LDAP *ld, unsigned flags, void *defaults, void *in)
+{
+ sasl_interact_t *interact = in;
+ const char *p;
+ php_ldap_bictx *ctx = defaults;
+
+ for (;interact->id != SASL_CB_LIST_END;interact++) {
+ p = NULL;
+ switch(interact->id) {
+ case SASL_CB_GETREALM:
+ p = ctx->realm;
+ break;
+ case SASL_CB_AUTHNAME:
+ p = ctx->authcid;
+ break;
+ case SASL_CB_USER:
+ p = ctx->authzid;
+ break;
+ case SASL_CB_PASS:
+ p = ctx->passwd;
+ break;
+ }
+ if (p) {
+ interact->result = p;
+ interact->len = strlen(interact->result);
+ }
+ }
+ return LDAP_SUCCESS;
+}
+/* }}} */
+
+/* {{{ 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]]]]]]])
+ Bind to LDAP directory using SASL */
+PHP_FUNCTION(ldap_sasl_bind)
+{
+ zval *link;
+ ldap_linkdata *ld;
+ char *binddn = NULL;
+ char *passwd = NULL;
+ char *sasl_mech = NULL;
+ char *sasl_realm = NULL;
+ char *sasl_authz_id = NULL;
+ char *sasl_authc_id = NULL;
+ char *props = NULL;
+ 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|sssssss", &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) {
+ RETURN_FALSE;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+
+ ctx = _php_sasl_setdefs(ld->link, sasl_mech, sasl_realm, sasl_authc_id, passwd, sasl_authz_id);
+
+ if (props) {
+ ldap_set_option(ld->link, LDAP_OPT_X_SASL_SECPROPS, props);
+ }
+
+ rc = ldap_sasl_interactive_bind_s(ld->link, binddn, ctx->mech, NULL, NULL, LDAP_SASL_QUIET, _php_sasl_interact, ctx);
+ if (rc != LDAP_SUCCESS) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to bind to server: %s", ldap_err2string(rc));
+ RETVAL_FALSE;
+ } else {
+ RETVAL_TRUE;
+ }
+ _php_sasl_freedefs(ctx);
+}
+/* }}} */
+#endif /* HAVE_LDAP_SASL */
+
+/* {{{ proto bool ldap_unbind(resource link)
+ Unbind from LDAP directory */
+PHP_FUNCTION(ldap_unbind)
+{
+ zval *link;
+ ldap_linkdata *ld;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &link) != SUCCESS) {
+ RETURN_FALSE;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+
+ zend_list_delete(Z_LVAL_P(link));
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ php_set_opts
+ */
+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
+ }
+
+ /* 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
+ }
+
+ /* 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
+ }
+}
+/* }}} */
+
+/* {{{ php_ldap_do_search
+ */
+static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
+{
+ zval *link, *base_dn, **filter, *attrs = NULL, **attr;
+ long attrsonly, sizelimit, timelimit, deref;
+ char *ldap_base_dn = NULL, *ldap_filter = NULL, **ldap_attrs = NULL;
+ ldap_linkdata *ld = NULL;
+ LDAPMessage *ldap_res;
+ int ldap_attrsonly = 0, ldap_sizelimit = -1, ldap_timelimit = -1, ldap_deref = -1;
+ int old_ldap_sizelimit = -1, old_ldap_timelimit = -1, old_ldap_deref = -1;
+ int num_attribs = 0, ret = 1, i, errno, argcount = ZEND_NUM_ARGS();
+
+ if (zend_parse_parameters(argcount TSRMLS_CC, "zzZ|allll", &link, &base_dn, &filter, &attrs, &attrsonly,
+ &sizelimit, &timelimit, &deref) == FAILURE) {
+ return;
+ }
+
+ /* Reverse -> fall through */
+ switch (argcount) {
+ case 8:
+ ldap_deref = deref;
+ case 7:
+ ldap_timelimit = timelimit;
+ case 6:
+ ldap_sizelimit = sizelimit;
+ case 5:
+ ldap_attrsonly = attrsonly;
+ case 4:
+ num_attribs = zend_hash_num_elements(Z_ARRVAL_P(attrs));
+ ldap_attrs = safe_emalloc((num_attribs+1), sizeof(char *), 0);
+
+ for (i = 0; i<num_attribs; i++) {
+ if (zend_hash_index_find(Z_ARRVAL_P(attrs), i, (void **) &attr) != SUCCESS) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array initialization wrong");
+ ret = 0;
+ goto cleanup;
+ }
+
+ SEPARATE_ZVAL(attr);
+ convert_to_string_ex(attr);
+ ldap_attrs[i] = Z_STRVAL_PP(attr);
+ }
+ ldap_attrs[num_attribs] = NULL;
+ default:
+ break;
+ }
+
+ /* parallel search? */
+ if (Z_TYPE_P(link) == IS_ARRAY) {
+ int i, nlinks, nbases, nfilters, *rcs;
+ ldap_linkdata **lds;
+ zval **entry, *resource;
+
+ nlinks = zend_hash_num_elements(Z_ARRVAL_P(link));
+ if (nlinks == 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "No links in link array");
+ ret = 0;
+ goto cleanup;
+ }
+
+ if (Z_TYPE_P(base_dn) == IS_ARRAY) {
+ nbases = zend_hash_num_elements(Z_ARRVAL_P(base_dn));
+ if (nbases != nlinks) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Base must either be a string, or an array with the same number of elements as the links array");
+ ret = 0;
+ goto cleanup;
+ }
+ zend_hash_internal_pointer_reset(Z_ARRVAL_P(base_dn));
+ } else {
+ nbases = 0; /* this means string, not array */
+ /* If anything else than string is passed, ldap_base_dn = NULL */
+ if (Z_TYPE_P(base_dn) == IS_STRING) {
+ ldap_base_dn = Z_STRVAL_P(base_dn);
+ } else {
+ ldap_base_dn = NULL;
+ }
+ }
+
+ if (Z_TYPE_PP(filter) == IS_ARRAY) {
+ nfilters = zend_hash_num_elements(Z_ARRVAL_PP(filter));
+ if (nfilters != nlinks) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Filter must either be a string, or an array with the same number of elements as the links array");
+ ret = 0;
+ goto cleanup;
+ }
+ zend_hash_internal_pointer_reset(Z_ARRVAL_PP(filter));
+ } else {
+ nfilters = 0; /* this means string, not array */
+ convert_to_string_ex(filter);
+ ldap_filter = Z_STRVAL_PP(filter);
+ }
+
+ lds = safe_emalloc(nlinks, sizeof(ldap_linkdata), 0);
+ rcs = safe_emalloc(nlinks, sizeof(*rcs), 0);
+
+ zend_hash_internal_pointer_reset(Z_ARRVAL_P(link));
+ for (i=0; i<nlinks; i++) {
+ zend_hash_get_current_data(Z_ARRVAL_P(link), (void **)&entry);
+
+ ld = (ldap_linkdata *) zend_fetch_resource(entry TSRMLS_CC, -1, "ldap link", NULL, 1, le_link);
+ if (ld == NULL) {
+ ret = 0;
+ goto cleanup_parallel;
+ }
+ if (nbases != 0) { /* base_dn an array? */
+ zend_hash_get_current_data(Z_ARRVAL_P(base_dn), (void **)&entry);
+ zend_hash_move_forward(Z_ARRVAL_P(base_dn));
+
+ /* If anything else than string is passed, ldap_base_dn = NULL */
+ if (Z_TYPE_PP(entry) == IS_STRING) {
+ ldap_base_dn = Z_STRVAL_PP(entry);
+ } else {
+ ldap_base_dn = NULL;
+ }
+ }
+ if (nfilters != 0) { /* filter an array? */
+ zend_hash_get_current_data(Z_ARRVAL_PP(filter), (void **)&entry);
+ zend_hash_move_forward(Z_ARRVAL_PP(filter));
+ convert_to_string_ex(entry);
+ ldap_filter = Z_STRVAL_PP(entry);
+ }
+
+ 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);
+ lds[i] = ld;
+ zend_hash_move_forward(Z_ARRVAL_P(link));
+ }
+
+ array_init(return_value);
+
+ /* Collect results from the searches */
+ for (i=0; i<nlinks; i++) {
+ MAKE_STD_ZVAL(resource);
+ if (rcs[i] != -1) {
+ rcs[i] = ldap_result(lds[i]->link, LDAP_RES_ANY, 1 /* LDAP_MSG_ALL */, NULL, &ldap_res);
+ }
+ if (rcs[i] != -1) {
+ ZEND_REGISTER_RESOURCE(resource, ldap_res, le_result);
+ add_next_index_zval(return_value, resource);
+ } else {
+ add_next_index_bool(return_value, 0);
+ }
+ }
+
+cleanup_parallel:
+ efree(lds);
+ efree(rcs);
+ } else {
+ convert_to_string_ex(filter);
+ ldap_filter = Z_STRVAL_PP(filter);
+
+ /* If anything else than string is passed, ldap_base_dn = NULL */
+ if (Z_TYPE_P(base_dn) == IS_STRING) {
+ ldap_base_dn = Z_STRVAL_P(base_dn);
+ }
+
+ ld = (ldap_linkdata *) zend_fetch_resource(&link TSRMLS_CC, -1, "ldap link", NULL, 1, le_link);
+ if (ld == NULL) {
+ ret = 0;
+ goto cleanup;
+ }
+
+ 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);
+
+ if (errno != LDAP_SUCCESS
+ && errno != LDAP_SIZELIMIT_EXCEEDED
+#ifdef LDAP_ADMINLIMIT_EXCEEDED
+ && errno != LDAP_ADMINLIMIT_EXCEEDED
+#endif
+#ifdef LDAP_REFERRAL
+ && errno != LDAP_REFERRAL
+#endif
+ ) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Search: %s", ldap_err2string(errno));
+ ret = 0;
+ } else {
+ if (errno == LDAP_SIZELIMIT_EXCEEDED) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Partial search results returned: Sizelimit exceeded");
+ }
+#ifdef LDAP_ADMINLIMIT_EXCEEDED
+ else if (errno == LDAP_ADMINLIMIT_EXCEEDED) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Partial search results returned: Adminlimit exceeded");
+ }
+#endif
+
+ ZEND_REGISTER_RESOURCE(return_value, ldap_res, le_result);
+ }
+ }
+
+cleanup:
+ if (ld) {
+ /* 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);
+ }
+ if (!ret) {
+ RETVAL_BOOL(ret);
+ }
+}
+/* }}} */
+
+/* {{{ proto resource ldap_read(resource|array link, string base_dn, string filter [, array attrs [, int attrsonly [, int sizelimit [, int timelimit [, int deref]]]]])
+ Read an entry */
+PHP_FUNCTION(ldap_read)
+{
+ php_ldap_do_search(INTERNAL_FUNCTION_PARAM_PASSTHRU, LDAP_SCOPE_BASE);
+}
+/* }}} */
+
+/* {{{ proto resource ldap_list(resource|array link, string base_dn, string filter [, array attrs [, int attrsonly [, int sizelimit [, int timelimit [, int deref]]]]])
+ Single-level search */
+PHP_FUNCTION(ldap_list)
+{
+ php_ldap_do_search(INTERNAL_FUNCTION_PARAM_PASSTHRU, LDAP_SCOPE_ONELEVEL);
+}
+/* }}} */
+
+/* {{{ proto resource ldap_search(resource|array link, string base_dn, string filter [, array attrs [, int attrsonly [, int sizelimit [, int timelimit [, int deref]]]]])
+ Search LDAP tree under base_dn */
+PHP_FUNCTION(ldap_search)
+{
+ php_ldap_do_search(INTERNAL_FUNCTION_PARAM_PASSTHRU, LDAP_SCOPE_SUBTREE);
+}
+/* }}} */
+
+/* {{{ proto bool ldap_free_result(resource result)
+ Free result memory */
+PHP_FUNCTION(ldap_free_result)
+{
+ zval *result;
+ LDAPMessage *ldap_result;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &result) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ldap_result, LDAPMessage *, &result, -1, "ldap result", le_result);
+
+ zend_list_delete(Z_LVAL_P(result)); /* Delete list entry */
+ RETVAL_TRUE;
+}
+/* }}} */
+
+/* {{{ proto int ldap_count_entries(resource link, resource result)
+ Count the number of entries in a search result */
+PHP_FUNCTION(ldap_count_entries)
+{
+ zval *link, *result;
+ ldap_linkdata *ld;
+ LDAPMessage *ldap_result;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &link, &result) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+ ZEND_FETCH_RESOURCE(ldap_result, LDAPMessage *, &result, -1, "ldap result", le_result);
+
+ RETURN_LONG(ldap_count_entries(ld->link, ldap_result));
+}
+/* }}} */
+
+/* {{{ proto resource ldap_first_entry(resource link, resource result)
+ Return first result id */
+PHP_FUNCTION(ldap_first_entry)
+{
+ zval *link, *result;
+ ldap_linkdata *ld;
+ ldap_resultentry *resultentry;
+ LDAPMessage *ldap_result, *entry;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &link, &result) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+ ZEND_FETCH_RESOURCE(ldap_result, LDAPMessage *, &result, -1, "ldap result", le_result);
+
+ if ((entry = ldap_first_entry(ld->link, ldap_result)) == NULL) {
+ RETVAL_FALSE;
+ } else {
+ resultentry = emalloc(sizeof(ldap_resultentry));
+ ZEND_REGISTER_RESOURCE(return_value, resultentry, le_result_entry);
+ resultentry->id = Z_LVAL_P(result);
+ zend_list_addref(resultentry->id);
+ resultentry->data = entry;
+ resultentry->ber = NULL;
+ }
+}
+/* }}} */
+
+/* {{{ proto resource ldap_next_entry(resource link, resource result_entry)
+ Get next result entry */
+PHP_FUNCTION(ldap_next_entry)
+{
+ zval *link, *result_entry;
+ ldap_linkdata *ld;
+ ldap_resultentry *resultentry, *resultentry_next;
+ LDAPMessage *entry_next;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &link, &result_entry) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+ ZEND_FETCH_RESOURCE(resultentry, ldap_resultentry *, &result_entry, -1, "ldap result entry", le_result_entry);
+
+ if ((entry_next = ldap_next_entry(ld->link, resultentry->data)) == NULL) {
+ RETVAL_FALSE;
+ } else {
+ resultentry_next = emalloc(sizeof(ldap_resultentry));
+ ZEND_REGISTER_RESOURCE(return_value, resultentry_next, le_result_entry);
+ resultentry_next->id = resultentry->id;
+ zend_list_addref(resultentry->id);
+ resultentry_next->data = entry_next;
+ resultentry_next->ber = NULL;
+ }
+}
+/* }}} */
+
+/* {{{ proto array ldap_get_entries(resource link, resource result)
+ Get all result entries */
+PHP_FUNCTION(ldap_get_entries)
+{
+ zval *link, *result;
+ LDAPMessage *ldap_result, *ldap_result_entry;
+ zval *tmp1, *tmp2;
+ ldap_linkdata *ld;
+ LDAP *ldap;
+ int num_entries, num_attrib, num_values, i;
+ BerElement *ber;
+ char *attribute;
+ size_t attr_len;
+ struct berval **ldap_value;
+ char *dn;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &link, &result) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+ ZEND_FETCH_RESOURCE(ldap_result, LDAPMessage *, &result, -1, "ldap result", le_result);
+
+ ldap = ld->link;
+ num_entries = ldap_count_entries(ldap, ldap_result);
+
+ array_init(return_value);
+ add_assoc_long(return_value, "count", num_entries);
+
+ if (num_entries == 0) {
+ return;
+ }
+
+ ldap_result_entry = ldap_first_entry(ldap, ldap_result);
+ if (ldap_result_entry == NULL) {
+ zval_dtor(return_value);
+ RETURN_FALSE;
+ }
+
+ num_entries = 0;
+ while (ldap_result_entry != NULL) {
+ MAKE_STD_ZVAL(tmp1);
+ array_init(tmp1);
+
+ num_attrib = 0;
+ attribute = ldap_first_attribute(ldap, ldap_result_entry, &ber);
+
+ while (attribute != NULL) {
+ ldap_value = ldap_get_values_len(ldap, ldap_result_entry, attribute);
+ num_values = ldap_count_values_len(ldap_value);
+
+ MAKE_STD_ZVAL(tmp2);
+ array_init(tmp2);
+ add_assoc_long(tmp2, "count", num_values);
+ for (i = 0; i < num_values; i++) {
+ add_index_stringl(tmp2, i, ldap_value[i]->bv_val, ldap_value[i]->bv_len, 1);
+ }
+ ldap_value_free_len(ldap_value);
+
+ attr_len = strlen(attribute);
+ zend_hash_update(Z_ARRVAL_P(tmp1), php_strtolower(attribute, attr_len), attr_len+1, (void *) &tmp2, sizeof(zval *), NULL);
+ add_index_string(tmp1, num_attrib, attribute, 1);
+
+ num_attrib++;
+#if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP_10 || WINDOWS
+ ldap_memfree(attribute);
+#endif
+ attribute = ldap_next_attribute(ldap, ldap_result_entry, ber);
+ }
+#if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP_10 || WINDOWS
+ if (ber != NULL) {
+ ber_free(ber, 0);
+ }
+#endif
+
+ add_assoc_long(tmp1, "count", num_attrib);
+ dn = ldap_get_dn(ldap, ldap_result_entry);
+ add_assoc_string(tmp1, "dn", dn, 1);
+#if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP_10 || WINDOWS
+ ldap_memfree(dn);
+#else
+ free(dn);
+#endif
+
+ zend_hash_index_update(Z_ARRVAL_P(return_value), num_entries, (void *) &tmp1, sizeof(zval *), NULL);
+
+ num_entries++;
+ ldap_result_entry = ldap_next_entry(ldap, ldap_result_entry);
+ }
+
+ add_assoc_long(return_value, "count", num_entries);
+
+}
+/* }}} */
+
+/* {{{ proto string ldap_first_attribute(resource link, resource result_entry)
+ Return first attribute */
+PHP_FUNCTION(ldap_first_attribute)
+{
+ zval *link, *result_entry;
+ ldap_linkdata *ld;
+ ldap_resultentry *resultentry;
+ char *attribute;
+ long dummy_ber;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|l", &link, &result_entry, &dummy_ber) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+ ZEND_FETCH_RESOURCE(resultentry, ldap_resultentry *, &result_entry, -1, "ldap result entry", le_result_entry);
+
+ if ((attribute = ldap_first_attribute(ld->link, resultentry->data, &resultentry->ber)) == NULL) {
+ RETURN_FALSE;
+ } else {
+ RETVAL_STRING(attribute, 1);
+#if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP_10 || WINDOWS
+ ldap_memfree(attribute);
+#endif
+ }
+}
+/* }}} */
+
+/* {{{ proto string ldap_next_attribute(resource link, resource result_entry)
+ Get the next attribute in result */
+PHP_FUNCTION(ldap_next_attribute)
+{
+ zval *link, *result_entry;
+ ldap_linkdata *ld;
+ ldap_resultentry *resultentry;
+ char *attribute;
+ long dummy_ber;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|l", &link, &result_entry, &dummy_ber) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+ ZEND_FETCH_RESOURCE(resultentry, ldap_resultentry *, &result_entry, -1, "ldap result entry", le_result_entry);
+
+ if (resultentry->ber == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "called before calling ldap_first_attribute() or no attributes found in result entry");
+ RETURN_FALSE;
+ }
+
+ if ((attribute = ldap_next_attribute(ld->link, resultentry->data, resultentry->ber)) == NULL) {
+#if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP_10 || WINDOWS
+ if (resultentry->ber != NULL) {
+ ber_free(resultentry->ber, 0);
+ resultentry->ber = NULL;
+ }
+#endif
+ RETURN_FALSE;
+ } else {
+ RETVAL_STRING(attribute, 1);
+#if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP_10 || WINDOWS
+ ldap_memfree(attribute);
+#endif
+ }
+}
+/* }}} */
+
+/* {{{ proto array ldap_get_attributes(resource link, resource result_entry)
+ Get attributes from a search result entry */
+PHP_FUNCTION(ldap_get_attributes)
+{
+ zval *link, *result_entry;
+ zval *tmp;
+ ldap_linkdata *ld;
+ ldap_resultentry *resultentry;
+ char *attribute;
+ struct berval **ldap_value;
+ int i, num_values, num_attrib;
+ BerElement *ber;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &link, &result_entry) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+ ZEND_FETCH_RESOURCE(resultentry, ldap_resultentry *, &result_entry, -1, "ldap result entry", le_result_entry);
+
+ array_init(return_value);
+ num_attrib = 0;
+
+ attribute = ldap_first_attribute(ld->link, resultentry->data, &ber);
+ while (attribute != NULL) {
+ ldap_value = ldap_get_values_len(ld->link, resultentry->data, attribute);
+ num_values = ldap_count_values_len(ldap_value);
+
+ MAKE_STD_ZVAL(tmp);
+ array_init(tmp);
+ add_assoc_long(tmp, "count", num_values);
+ for (i = 0; i < num_values; i++) {
+ add_index_stringl(tmp, i, ldap_value[i]->bv_val, ldap_value[i]->bv_len, 1);
+ }
+ ldap_value_free_len(ldap_value);
+
+ zend_hash_update(Z_ARRVAL_P(return_value), attribute, strlen(attribute)+1, (void *) &tmp, sizeof(zval *), NULL);
+ add_index_string(return_value, num_attrib, attribute, 1);
+
+ num_attrib++;
+#if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP_10 || WINDOWS
+ ldap_memfree(attribute);
+#endif
+ attribute = ldap_next_attribute(ld->link, resultentry->data, ber);
+ }
+#if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP_10 || WINDOWS
+ if (ber != NULL) {
+ ber_free(ber, 0);
+ }
+#endif
+
+ add_assoc_long(return_value, "count", num_attrib);
+}
+/* }}} */
+
+/* {{{ proto array ldap_get_values_len(resource link, resource result_entry, string attribute)
+ Get all values with lengths from a result entry */
+PHP_FUNCTION(ldap_get_values_len)
+{
+ zval *link, *result_entry;
+ ldap_linkdata *ld;
+ ldap_resultentry *resultentry;
+ char *attr;
+ struct berval **ldap_value_len;
+ int i, num_values, attr_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrs", &link, &result_entry, &attr, &attr_len) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+ ZEND_FETCH_RESOURCE(resultentry, ldap_resultentry *, &result_entry, -1, "ldap result entry", le_result_entry);
+
+ if ((ldap_value_len = ldap_get_values_len(ld->link, resultentry->data, attr)) == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot get the value(s) of attribute %s", ldap_err2string(_get_lderrno(ld->link)));
+ RETURN_FALSE;
+ }
+
+ num_values = ldap_count_values_len(ldap_value_len);
+ array_init(return_value);
+
+ for (i=0; i<num_values; i++) {
+ add_next_index_stringl(return_value, ldap_value_len[i]->bv_val, ldap_value_len[i]->bv_len, 1);
+ }
+
+ add_assoc_long(return_value, "count", num_values);
+ ldap_value_free_len(ldap_value_len);
+
+}
+/* }}} */
+
+/* {{{ proto string ldap_get_dn(resource link, resource result_entry)
+ Get the DN of a result entry */
+PHP_FUNCTION(ldap_get_dn)
+{
+ zval *link, *result_entry;
+ ldap_linkdata *ld;
+ ldap_resultentry *resultentry;
+ char *text;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &link, &result_entry) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+ ZEND_FETCH_RESOURCE(resultentry, ldap_resultentry *, &result_entry, -1, "ldap result entry", le_result_entry);
+
+ text = ldap_get_dn(ld->link, resultentry->data);
+ if (text != NULL) {
+ RETVAL_STRING(text, 1);
+#if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP_10 || WINDOWS
+ ldap_memfree(text);
+#else
+ free(text);
+#endif
+ } else {
+ RETURN_FALSE;
+ }
+}
+/* }}} */
+
+/* {{{ proto array ldap_explode_dn(string dn, int with_attrib)
+ Splits DN into its component parts */
+PHP_FUNCTION(ldap_explode_dn)
+{
+ long with_attrib;
+ char *dn, **ldap_value;
+ int i, count, dn_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &dn, &dn_len, &with_attrib) != SUCCESS) {
+ return;
+ }
+
+ if (!(ldap_value = ldap_explode_dn(dn, with_attrib))) {
+ /* Invalid parameters were passed to ldap_explode_dn */
+ RETURN_FALSE;
+ }
+
+ i=0;
+ while (ldap_value[i] != NULL) i++;
+ count = i;
+
+ array_init(return_value);
+
+ add_assoc_long(return_value, "count", count);
+ for (i = 0; i<count; i++) {
+ add_index_string(return_value, i, ldap_value[i], 1);
+ }
+
+ ldap_value_free(ldap_value);
+}
+/* }}} */
+
+/* {{{ proto string ldap_dn2ufn(string dn)
+ Convert DN to User Friendly Naming format */
+PHP_FUNCTION(ldap_dn2ufn)
+{
+ char *dn, *ufn;
+ int dn_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &dn, &dn_len) != SUCCESS) {
+ return;
+ }
+
+ ufn = ldap_dn2ufn(dn);
+
+ if (ufn != NULL) {
+ RETVAL_STRING(ufn, 1);
+#if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP_10 || WINDOWS
+ ldap_memfree(ufn);
+#endif
+ } else {
+ RETURN_FALSE;
+ }
+}
+/* }}} */
+
+
+/* added to fix use of ldap_modify_add for doing an ldap_add, gerrit thomson. */
+#define PHP_LD_FULL_ADD 0xff
+/* {{{ php_ldap_do_modify
+ */
+static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper)
+{
+ zval *link, *entry, **value, **ivalue;
+ ldap_linkdata *ld;
+ char *dn;
+ LDAPMod **ldap_mods;
+ int i, j, num_attribs, num_values, dn_len;
+ int *num_berval;
+ char *attribute;
+ ulong index;
+ int is_full_add=0; /* flag for full add operation so ldap_mod_add can be put back into oper, gerrit THomson */
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsa", &link, &dn, &dn_len, &entry) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+
+ num_attribs = zend_hash_num_elements(Z_ARRVAL_P(entry));
+ ldap_mods = safe_emalloc((num_attribs+1), sizeof(LDAPMod *), 0);
+ num_berval = safe_emalloc(num_attribs, sizeof(int), 0);
+ zend_hash_internal_pointer_reset(Z_ARRVAL_P(entry));
+
+ /* added by gerrit thomson to fix ldap_add using ldap_mod_add */
+ if (oper == PHP_LD_FULL_ADD) {
+ oper = LDAP_MOD_ADD;
+ is_full_add = 1;
+ }
+ /* end additional , gerrit thomson */
+
+ for (i = 0; i < num_attribs; i++) {
+ ldap_mods[i] = emalloc(sizeof(LDAPMod));
+ ldap_mods[i]->mod_op = oper | LDAP_MOD_BVALUES;
+ ldap_mods[i]->mod_type = NULL;
+
+ if (zend_hash_get_current_key(Z_ARRVAL_P(entry), &attribute, &index, 0) == HASH_KEY_IS_STRING) {
+ ldap_mods[i]->mod_type = estrdup(attribute);
+ } else {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown attribute in the data");
+ /* Free allocated memory */
+ while (i >= 0) {
+ if (ldap_mods[i]->mod_type) {
+ efree(ldap_mods[i]->mod_type);
+ }
+ efree(ldap_mods[i]);
+ i--;
+ }
+ efree(num_berval);
+ efree(ldap_mods);
+ RETURN_FALSE;
+ }
+
+ zend_hash_get_current_data(Z_ARRVAL_P(entry), (void **)&value);
+
+ if (Z_TYPE_PP(value) != IS_ARRAY) {
+ num_values = 1;
+ } else {
+ num_values = zend_hash_num_elements(Z_ARRVAL_PP(value));
+ }
+
+ num_berval[i] = num_values;
+ ldap_mods[i]->mod_bvalues = safe_emalloc((num_values + 1), sizeof(struct berval *), 0);
+
+/* allow for arrays with one element, no allowance for arrays with none but probably not required, gerrit thomson. */
+ if ((num_values == 1) && (Z_TYPE_PP(value) != IS_ARRAY)) {
+ convert_to_string_ex(value);
+ ldap_mods[i]->mod_bvalues[0] = (struct berval *) emalloc (sizeof(struct berval));
+ ldap_mods[i]->mod_bvalues[0]->bv_len = Z_STRLEN_PP(value);
+ ldap_mods[i]->mod_bvalues[0]->bv_val = Z_STRVAL_PP(value);
+ } else {
+ for (j = 0; j < num_values; j++) {
+ if (zend_hash_index_find(Z_ARRVAL_PP(value), j, (void **) &ivalue) != SUCCESS) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Value array must have consecutive indices 0, 1, ...");
+ num_berval[i] = j;
+ num_attribs = i + 1;
+ RETVAL_FALSE;
+ goto errexit;
+ }
+ convert_to_string_ex(ivalue);
+ ldap_mods[i]->mod_bvalues[j] = (struct berval *) emalloc (sizeof(struct berval));
+ ldap_mods[i]->mod_bvalues[j]->bv_len = Z_STRLEN_PP(ivalue);
+ ldap_mods[i]->mod_bvalues[j]->bv_val = Z_STRVAL_PP(ivalue);
+ }
+ }
+ ldap_mods[i]->mod_bvalues[num_values] = NULL;
+ zend_hash_move_forward(Z_ARRVAL_P(entry));
+ }
+ ldap_mods[num_attribs] = NULL;
+
+/* check flag to see if do_mod was called to perform full add , gerrit thomson */
+ if (is_full_add == 1) {
+ if ((i = ldap_add_s(ld->link, dn, ldap_mods)) != LDAP_SUCCESS) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Add: %s", ldap_err2string(i));
+ RETVAL_FALSE;
+ } else RETVAL_TRUE;
+ } else {
+ if ((i = ldap_modify_ext_s(ld->link, dn, ldap_mods, NULL, NULL)) != LDAP_SUCCESS) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Modify: %s", ldap_err2string(i));
+ RETVAL_FALSE;
+ } else RETVAL_TRUE;
+ }
+
+errexit:
+ for (i = 0; i < num_attribs; i++) {
+ efree(ldap_mods[i]->mod_type);
+ for (j = 0; j < num_berval[i]; j++) {
+ efree(ldap_mods[i]->mod_bvalues[j]);
+ }
+ efree(ldap_mods[i]->mod_bvalues);
+ efree(ldap_mods[i]);
+ }
+ efree(num_berval);
+ efree(ldap_mods);
+
+ return;
+}
+/* }}} */
+
+/* {{{ proto bool ldap_add(resource link, string dn, array entry)
+ Add entries to LDAP directory */
+PHP_FUNCTION(ldap_add)
+{
+ /* use a newly define parameter into the do_modify so ldap_mod_add can be used the way it is supposed to be used , Gerrit THomson */
+ php_ldap_do_modify(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_LD_FULL_ADD);
+}
+/* }}} */
+
+/* three functions for attribute base modifications, gerrit Thomson */
+
+/* {{{ proto bool ldap_mod_replace(resource link, string dn, array entry)
+ Replace attribute values with new ones */
+PHP_FUNCTION(ldap_mod_replace)
+{
+ php_ldap_do_modify(INTERNAL_FUNCTION_PARAM_PASSTHRU, LDAP_MOD_REPLACE);
+}
+/* }}} */
+
+/* {{{ proto bool ldap_mod_add(resource link, string dn, array entry)
+ Add attribute values to current */
+PHP_FUNCTION(ldap_mod_add)
+{
+ php_ldap_do_modify(INTERNAL_FUNCTION_PARAM_PASSTHRU, LDAP_MOD_ADD);
+}
+/* }}} */
+
+/* {{{ proto bool ldap_mod_del(resource link, string dn, array entry)
+ Delete attribute values */
+PHP_FUNCTION(ldap_mod_del)
+{
+ php_ldap_do_modify(INTERNAL_FUNCTION_PARAM_PASSTHRU, LDAP_MOD_DELETE);
+}
+/* }}} */
+
+/* {{{ proto bool ldap_delete(resource link, string dn)
+ Delete an entry from a directory */
+PHP_FUNCTION(ldap_delete)
+{
+ zval *link;
+ ldap_linkdata *ld;
+ char *dn;
+ int rc, dn_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &link, &dn, &dn_len) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+
+ if ((rc = ldap_delete_s(ld->link, dn)) != LDAP_SUCCESS) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Delete: %s", ldap_err2string(rc));
+ RETURN_FALSE;
+ }
+
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto int ldap_errno(resource link)
+ Get the current ldap error number */
+PHP_FUNCTION(ldap_errno)
+{
+ zval *link;
+ ldap_linkdata *ld;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &link) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+
+ RETURN_LONG(_get_lderrno(ld->link));
+}
+/* }}} */
+
+/* {{{ proto string ldap_err2str(int errno)
+ Convert error number to error string */
+PHP_FUNCTION(ldap_err2str)
+{
+ long perrno;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &perrno) != SUCCESS) {
+ return;
+ }
+
+ RETURN_STRING(ldap_err2string(perrno), 1);
+}
+/* }}} */
+
+/* {{{ proto string ldap_error(resource link)
+ Get the current ldap error string */
+PHP_FUNCTION(ldap_error)
+{
+ zval *link;
+ ldap_linkdata *ld;
+ int ld_errno;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &link) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+
+ ld_errno = _get_lderrno(ld->link);
+
+ RETURN_STRING(ldap_err2string(ld_errno), 1);
+}
+/* }}} */
+
+/* {{{ proto bool ldap_compare(resource link, string dn, string attr, string value)
+ Determine if an entry has a specific value for one of its attributes */
+PHP_FUNCTION(ldap_compare)
+{
+ zval *link;
+ char *dn, *attr, *value;
+ int dn_len, attr_len, value_len;
+ ldap_linkdata *ld;
+ int errno;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsss", &link, &dn, &dn_len, &attr, &attr_len, &value, &value_len) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+
+ errno = ldap_compare_s(ld->link, dn, attr, value);
+
+ switch (errno) {
+ case LDAP_COMPARE_TRUE:
+ RETURN_TRUE;
+ break;
+
+ case LDAP_COMPARE_FALSE:
+ RETURN_FALSE;
+ break;
+ }
+
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Compare: %s", ldap_err2string(errno));
+ RETURN_LONG(-1);
+}
+/* }}} */
+
+/* {{{ proto bool ldap_sort(resource link, resource result, string sortfilter)
+ Sort LDAP result entries */
+PHP_FUNCTION(ldap_sort)
+{
+ zval *link, *result;
+ ldap_linkdata *ld;
+ char *sortfilter;
+ int sflen;
+ zend_rsrc_list_entry *le;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrs", &link, &result, &sortfilter, &sflen) != SUCCESS) {
+ RETURN_FALSE;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+
+ if (zend_hash_index_find(&EG(regular_list), Z_LVAL_P(result), (void **) &le) != SUCCESS || le->type != le_result) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Supplied resource is not a valid ldap result resource");
+ RETURN_FALSE;
+ }
+
+ if (ldap_sort_entries(ld->link, (LDAPMessage **) &le->ptr, sflen ? sortfilter : NULL, strcmp) != LDAP_SUCCESS) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ldap_err2string(errno));
+ RETURN_FALSE;
+ }
+
+ RETURN_TRUE;
+}
+/* }}} */
+
+#if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP_10
+/* {{{ proto bool ldap_get_option(resource link, int option, mixed retval)
+ Get the current value of various session-wide parameters */
+PHP_FUNCTION(ldap_get_option)
+{
+ zval *link, *retval;
+ ldap_linkdata *ld;
+ long option;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlz", &link, &option, &retval) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+
+ switch (option) {
+ /* options with int value */
+ case LDAP_OPT_DEREF:
+ case LDAP_OPT_SIZELIMIT:
+ case LDAP_OPT_TIMELIMIT:
+ case LDAP_OPT_PROTOCOL_VERSION:
+ case LDAP_OPT_ERROR_NUMBER:
+ case LDAP_OPT_REFERRALS:
+#ifdef LDAP_OPT_RESTART
+ case LDAP_OPT_RESTART:
+#endif
+ {
+ int val;
+
+ if (ldap_get_option(ld->link, option, &val)) {
+ RETURN_FALSE;
+ }
+ zval_dtor(retval);
+ ZVAL_LONG(retval, val);
+ } break;
+#ifdef LDAP_OPT_NETWORK_TIMEOUT
+ case LDAP_OPT_NETWORK_TIMEOUT:
+ {
+ struct timeval *timeout = NULL;
+
+ if (ldap_get_option(ld->link, LDAP_OPT_NETWORK_TIMEOUT, (void *) &timeout)) {
+ if (timeout) {
+ ldap_memfree(timeout);
+ }
+ RETURN_FALSE;
+ }
+ if (!timeout) {
+ RETURN_FALSE;
+ }
+ zval_dtor(retval);
+ ZVAL_LONG(retval, timeout->tv_sec);
+ ldap_memfree(timeout);
+ } break;
+#elif defined(LDAP_X_OPT_CONNECT_TIMEOUT)
+ case LDAP_X_OPT_CONNECT_TIMEOUT:
+ {
+ int timeout;
+
+ if (ldap_get_option(ld->link, LDAP_X_OPT_CONNECT_TIMEOUT, &timeout)) {
+ RETURN_FALSE;
+ }
+ zval_dtor(retval);
+ ZVAL_LONG(retval, (timeout / 1000));
+ } break;
+#endif
+ /* options with string value */
+ case LDAP_OPT_ERROR_STRING:
+#ifdef LDAP_OPT_HOST_NAME
+ case LDAP_OPT_HOST_NAME:
+#endif
+#ifdef HAVE_LDAP_SASL
+ case LDAP_OPT_X_SASL_MECH:
+ case LDAP_OPT_X_SASL_REALM:
+ case LDAP_OPT_X_SASL_AUTHCID:
+ case LDAP_OPT_X_SASL_AUTHZID:
+#endif
+#ifdef LDAP_OPT_MATCHED_DN
+ case LDAP_OPT_MATCHED_DN:
+#endif
+ {
+ char *val = NULL;
+
+ if (ldap_get_option(ld->link, option, &val) || val == NULL || *val == '\0') {
+ if (val) {
+ ldap_memfree(val);
+ }
+ RETURN_FALSE;
+ }
+ zval_dtor(retval);
+ ZVAL_STRING(retval, val, 1);
+ ldap_memfree(val);
+ } break;
+/* options not implemented
+ case LDAP_OPT_SERVER_CONTROLS:
+ case LDAP_OPT_CLIENT_CONTROLS:
+ case LDAP_OPT_API_INFO:
+ case LDAP_OPT_API_FEATURE_INFO:
+*/
+ default:
+ RETURN_FALSE;
+ }
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto bool ldap_set_option(resource link, int option, mixed newval)
+ Set the value of various session-wide parameters */
+PHP_FUNCTION(ldap_set_option)
+{
+ zval *link, **newval;
+ ldap_linkdata *ld;
+ LDAP *ldap;
+ long option;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlZ", &link, &option, &newval) != SUCCESS) {
+ return;
+ }
+
+ if (Z_TYPE_P(link) == IS_NULL) {
+ ldap = NULL;
+ } else {
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+ ldap = ld->link;
+ }
+
+ switch (option) {
+ /* options with int value */
+ case LDAP_OPT_DEREF:
+ case LDAP_OPT_SIZELIMIT:
+ case LDAP_OPT_TIMELIMIT:
+ case LDAP_OPT_PROTOCOL_VERSION:
+ case LDAP_OPT_ERROR_NUMBER:
+#ifdef LDAP_OPT_DEBUG_LEVEL
+ case LDAP_OPT_DEBUG_LEVEL:
+#endif
+ {
+ int val;
+
+ convert_to_long_ex(newval);
+ val = Z_LVAL_PP(newval);
+ if (ldap_set_option(ldap, option, &val)) {
+ RETURN_FALSE;
+ }
+ } break;
+#ifdef LDAP_OPT_NETWORK_TIMEOUT
+ case LDAP_OPT_NETWORK_TIMEOUT:
+ {
+ struct timeval timeout;
+
+ convert_to_long_ex(newval);
+ timeout.tv_sec = Z_LVAL_PP(newval);
+ timeout.tv_usec = 0;
+ if (ldap_set_option(ldap, LDAP_OPT_NETWORK_TIMEOUT, (void *) &timeout)) {
+ RETURN_FALSE;
+ }
+ } break;
+#elif defined(LDAP_X_OPT_CONNECT_TIMEOUT)
+ case LDAP_X_OPT_CONNECT_TIMEOUT:
+ {
+ int timeout;
+
+ convert_to_long_ex(newval);
+ timeout = 1000 * Z_LVAL_PP(newval); /* Convert to milliseconds */
+ if (ldap_set_option(ldap, LDAP_X_OPT_CONNECT_TIMEOUT, &timeout)) {
+ RETURN_FALSE;
+ }
+ } break;
+#endif
+ /* options with string value */
+ case LDAP_OPT_ERROR_STRING:
+#ifdef LDAP_OPT_HOST_NAME
+ case LDAP_OPT_HOST_NAME:
+#endif
+#ifdef HAVE_LDAP_SASL
+ case LDAP_OPT_X_SASL_MECH:
+ case LDAP_OPT_X_SASL_REALM:
+ case LDAP_OPT_X_SASL_AUTHCID:
+ case LDAP_OPT_X_SASL_AUTHZID:
+#endif
+#ifdef LDAP_OPT_MATCHED_DN
+ case LDAP_OPT_MATCHED_DN:
+#endif
+ {
+ char *val;
+ convert_to_string_ex(newval);
+ val = Z_STRVAL_PP(newval);
+ if (ldap_set_option(ldap, option, val)) {
+ RETURN_FALSE;
+ }
+ } break;
+ /* options with boolean value */
+ case LDAP_OPT_REFERRALS:
+#ifdef LDAP_OPT_RESTART
+ case LDAP_OPT_RESTART:
+#endif
+ {
+ void *val;
+ convert_to_boolean_ex(newval);
+ val = Z_LVAL_PP(newval)
+ ? LDAP_OPT_ON : LDAP_OPT_OFF;
+ if (ldap_set_option(ldap, option, val)) {
+ RETURN_FALSE;
+ }
+ } break;
+ /* options with control list value */
+ case LDAP_OPT_SERVER_CONTROLS:
+ case LDAP_OPT_CLIENT_CONTROLS:
+ {
+ LDAPControl *ctrl, **ctrls, **ctrlp;
+ zval **ctrlval, **val;
+ int ncontrols;
+ char error=0;
+
+ if ((Z_TYPE_PP(newval) != IS_ARRAY) || !(ncontrols = zend_hash_num_elements(Z_ARRVAL_PP(newval)))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected non-empty array value for this option");
+ RETURN_FALSE;
+ }
+ ctrls = safe_emalloc((1 + ncontrols), sizeof(*ctrls), 0);
+ *ctrls = NULL;
+ ctrlp = ctrls;
+ zend_hash_internal_pointer_reset(Z_ARRVAL_PP(newval));
+ while (zend_hash_get_current_data(Z_ARRVAL_PP(newval), (void**)&ctrlval) == SUCCESS) {
+ if (Z_TYPE_PP(ctrlval) != IS_ARRAY) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "The array value must contain only arrays, where each array is a control");
+ error = 1;
+ break;
+ }
+ if (zend_hash_find(Z_ARRVAL_PP(ctrlval), "oid", sizeof("oid"), (void **) &val) != SUCCESS) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Control must have an oid key");
+ error = 1;
+ break;
+ }
+ ctrl = *ctrlp = emalloc(sizeof(**ctrlp));
+ convert_to_string_ex(val);
+ ctrl->ldctl_oid = Z_STRVAL_PP(val);
+ if (zend_hash_find(Z_ARRVAL_PP(ctrlval), "value", sizeof("value"), (void **) &val) == SUCCESS) {
+ convert_to_string_ex(val);
+ ctrl->ldctl_value.bv_val = Z_STRVAL_PP(val);
+ ctrl->ldctl_value.bv_len = Z_STRLEN_PP(val);
+ } else {
+ ctrl->ldctl_value.bv_val = NULL;
+ ctrl->ldctl_value.bv_len = 0;
+ }
+ if (zend_hash_find(Z_ARRVAL_PP(ctrlval), "iscritical", sizeof("iscritical"), (void **) &val) == SUCCESS) {
+ convert_to_boolean_ex(val);
+ ctrl->ldctl_iscritical = Z_BVAL_PP(val);
+ } else {
+ ctrl->ldctl_iscritical = 0;
+ }
+
+ ++ctrlp;
+ *ctrlp = NULL;
+ zend_hash_move_forward(Z_ARRVAL_PP(newval));
+ }
+ if (!error) {
+ error = ldap_set_option(ldap, option, ctrls);
+ }
+ ctrlp = ctrls;
+ while (*ctrlp) {
+ efree(*ctrlp);
+ ctrlp++;
+ }
+ efree(ctrls);
+ if (error) {
+ RETURN_FALSE;
+ }
+ } break;
+ default:
+ RETURN_FALSE;
+ }
+ RETURN_TRUE;
+}
+/* }}} */
+
+#ifdef HAVE_LDAP_PARSE_RESULT
+/* {{{ proto bool ldap_parse_result(resource link, resource result, int errcode, string matcheddn, string errmsg, array referrals)
+ Extract information from result */
+PHP_FUNCTION(ldap_parse_result)
+{
+ zval *link, *result, *errcode, *matcheddn, *errmsg, *referrals;
+ ldap_linkdata *ld;
+ LDAPMessage *ldap_result;
+ char **lreferrals, **refp;
+ char *lmatcheddn, *lerrmsg;
+ int rc, lerrcode, myargcount = ZEND_NUM_ARGS();
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrz|zzz", &link, &result, &errcode, &matcheddn, &errmsg, &referrals) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+ ZEND_FETCH_RESOURCE(ldap_result, LDAPMessage *, &result, -1, "ldap result", le_result);
+
+ rc = ldap_parse_result(ld->link, ldap_result, &lerrcode,
+ myargcount > 3 ? &lmatcheddn : NULL,
+ myargcount > 4 ? &lerrmsg : NULL,
+ myargcount > 5 ? &lreferrals : NULL,
+ NULL /* &serverctrls */,
+ 0);
+ if (rc != LDAP_SUCCESS) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to parse result: %s", ldap_err2string(rc));
+ RETURN_FALSE;
+ }
+
+ zval_dtor(errcode);
+ ZVAL_LONG(errcode, lerrcode);
+
+ /* Reverse -> fall through */
+ switch (myargcount) {
+ case 6:
+ zval_dtor(referrals);
+ array_init(referrals);
+ if (lreferrals != NULL) {
+ refp = lreferrals;
+ while (*refp) {
+ add_next_index_string(referrals, *refp, 1);
+ refp++;
+ }
+ ldap_value_free(lreferrals);
+ }
+ case 5:
+ zval_dtor(errmsg);
+ if (lerrmsg == NULL) {
+ ZVAL_EMPTY_STRING(errmsg);
+ } else {
+ ZVAL_STRING(errmsg, lerrmsg, 1);
+ ldap_memfree(lerrmsg);
+ }
+ case 4:
+ zval_dtor(matcheddn);
+ if (lmatcheddn == NULL) {
+ ZVAL_EMPTY_STRING(matcheddn);
+ } else {
+ ZVAL_STRING(matcheddn, lmatcheddn, 1);
+ ldap_memfree(lmatcheddn);
+ }
+ }
+ RETURN_TRUE;
+}
+/* }}} */
+#endif
+
+/* {{{ proto resource ldap_first_reference(resource link, resource result)
+ Return first reference */
+PHP_FUNCTION(ldap_first_reference)
+{
+ zval *link, *result;
+ ldap_linkdata *ld;
+ ldap_resultentry *resultentry;
+ LDAPMessage *ldap_result, *entry;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &link, &result) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+ ZEND_FETCH_RESOURCE(ldap_result, LDAPMessage *, &result, -1, "ldap result", le_result);
+
+ if ((entry = ldap_first_reference(ld->link, ldap_result)) == NULL) {
+ RETVAL_FALSE;
+ } else {
+ resultentry = emalloc(sizeof(ldap_resultentry));
+ ZEND_REGISTER_RESOURCE(return_value, resultentry, le_result_entry);
+ resultentry->id = Z_LVAL_P(result);
+ zend_list_addref(resultentry->id);
+ resultentry->data = entry;
+ resultentry->ber = NULL;
+ }
+}
+/* }}} */
+
+/* {{{ proto resource ldap_next_reference(resource link, resource reference_entry)
+ Get next reference */
+PHP_FUNCTION(ldap_next_reference)
+{
+ zval *link, *result_entry;
+ ldap_linkdata *ld;
+ ldap_resultentry *resultentry, *resultentry_next;
+ LDAPMessage *entry_next;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &link, &result_entry) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+ ZEND_FETCH_RESOURCE(resultentry, ldap_resultentry *, &result_entry, -1, "ldap result entry", le_result_entry);
+
+ if ((entry_next = ldap_next_reference(ld->link, resultentry->data)) == NULL) {
+ RETVAL_FALSE;
+ } else {
+ resultentry_next = emalloc(sizeof(ldap_resultentry));
+ ZEND_REGISTER_RESOURCE(return_value, resultentry_next, le_result_entry);
+ resultentry_next->id = resultentry->id;
+ zend_list_addref(resultentry->id);
+ resultentry_next->data = entry_next;
+ resultentry_next->ber = NULL;
+ }
+}
+/* }}} */
+
+#ifdef HAVE_LDAP_PARSE_REFERENCE
+/* {{{ proto bool ldap_parse_reference(resource link, resource reference_entry, array referrals)
+ Extract information from reference entry */
+PHP_FUNCTION(ldap_parse_reference)
+{
+ zval *link, *result_entry, *referrals;
+ ldap_linkdata *ld;
+ ldap_resultentry *resultentry;
+ char **lreferrals, **refp;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrz", &link, &result_entry, &referrals) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+ ZEND_FETCH_RESOURCE(resultentry, ldap_resultentry *, &result_entry, -1, "ldap result entry", le_result_entry);
+
+ if (ldap_parse_reference(ld->link, resultentry->data, &lreferrals, NULL /* &serverctrls */, 0) != LDAP_SUCCESS) {
+ RETURN_FALSE;
+ }
+
+ zval_dtor(referrals);
+ array_init(referrals);
+ if (lreferrals != NULL) {
+ refp = lreferrals;
+ while (*refp) {
+ add_next_index_string(referrals, *refp, 1);
+ refp++;
+ }
+ ldap_value_free(lreferrals);
+ }
+ RETURN_TRUE;
+}
+/* }}} */
+#endif
+
+/* {{{ proto bool ldap_rename(resource link, string dn, string newrdn, string newparent, bool deleteoldrdn);
+ Modify the name of an entry */
+PHP_FUNCTION(ldap_rename)
+{
+ zval *link;
+ ldap_linkdata *ld;
+ int rc;
+ char *dn, *newrdn, *newparent;
+ int dn_len, newrdn_len, newparent_len;
+ zend_bool deleteoldrdn;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsssb", &link, &dn, &dn_len, &newrdn, &newrdn_len, &newparent, &newparent_len, &deleteoldrdn) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+
+ if (newparent_len == 0) {
+ newparent = NULL;
+ }
+
+#if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP_10
+ rc = ldap_rename_s(ld->link, dn, newrdn, newparent, deleteoldrdn, NULL, NULL);
+#else
+ if (newparent_len != 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "You are using old LDAP API, newparent must be the empty string, can only modify RDN");
+ RETURN_FALSE;
+ }
+/* could support old APIs but need check for ldap_modrdn2()/ldap_modrdn() */
+ rc = ldap_modrdn2_s(ld->link, dn, newrdn, deleteoldrdn);
+#endif
+
+ if (rc == LDAP_SUCCESS) {
+ RETURN_TRUE;
+ }
+ RETURN_FALSE;
+}
+/* }}} */
+
+#ifdef HAVE_LDAP_START_TLS_S
+/* {{{ proto bool ldap_start_tls(resource link)
+ Start TLS */
+PHP_FUNCTION(ldap_start_tls)
+{
+ zval *link;
+ ldap_linkdata *ld;
+ int rc, protocol = LDAP_VERSION3;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &link) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+
+ if (((rc = ldap_set_option(ld->link, LDAP_OPT_PROTOCOL_VERSION, &protocol)) != LDAP_SUCCESS) ||
+ ((rc = ldap_start_tls_s(ld->link, NULL, NULL)) != LDAP_SUCCESS)
+ ) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING,"Unable to start TLS: %s", ldap_err2string(rc));
+ RETURN_FALSE;
+ } else {
+ RETURN_TRUE;
+ }
+}
+/* }}} */
+#endif
+#endif /* (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP_10 */
+
+#if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
+/* {{{ _ldap_rebind_proc()
+*/
+int _ldap_rebind_proc(LDAP *ldap, const char *url, ber_tag_t req, ber_int_t msgid, void *params)
+{
+ ldap_linkdata *ld;
+ int retval;
+ zval *cb_url;
+ zval **cb_args[2];
+ zval *cb_retval;
+ zval *cb_link = (zval *) params;
+ TSRMLS_FETCH();
+
+ ld = (ldap_linkdata *) zend_fetch_resource(&cb_link TSRMLS_CC, -1, "ldap link", NULL, 1, le_link);
+
+ /* link exists and callback set? */
+ if (ld == NULL || ld->rebindproc == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Link not found or no callback set");
+ return LDAP_OTHER;
+ }
+
+ /* callback */
+ MAKE_STD_ZVAL(cb_url);
+ ZVAL_STRING(cb_url, estrdup(url), 0);
+ cb_args[0] = &cb_link;
+ cb_args[1] = &cb_url;
+ if (call_user_function_ex(EG(function_table), NULL, ld->rebindproc, &cb_retval, 2, cb_args, 0, NULL TSRMLS_CC) == SUCCESS && cb_retval) {
+ convert_to_long_ex(&cb_retval);
+ retval = Z_LVAL_P(cb_retval);
+ zval_ptr_dtor(&cb_retval);
+ } else {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "rebind_proc PHP callback failed");
+ retval = LDAP_OTHER;
+ }
+ zval_dtor(cb_url);
+ FREE_ZVAL(cb_url);
+ return retval;
+}
+/* }}} */
+
+/* {{{ proto bool ldap_set_rebind_proc(resource link, string callback)
+ Set a callback function to do re-binds on referral chasing. */
+PHP_FUNCTION(ldap_set_rebind_proc)
+{
+ zval *link, *callback;
+ ldap_linkdata *ld;
+ char *callback_name;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz", &link, &callback) != SUCCESS) {
+ RETURN_FALSE;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+
+ if (Z_TYPE_P(callback) == IS_STRING && Z_STRLEN_P(callback) == 0) {
+ /* unregister rebind procedure */
+ if (ld->rebindproc != NULL) {
+ zval_dtor(ld->rebindproc);
+ ld->rebindproc = NULL;
+ ldap_set_rebind_proc(ld->link, NULL, NULL);
+ }
+ RETURN_TRUE;
+ }
+
+ /* callable? */
+ if (!zend_is_callable(callback, 0, &callback_name TSRMLS_CC)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Two arguments expected for '%s' to be a valid callback", callback_name);
+ efree(callback_name);
+ RETURN_FALSE;
+ }
+ efree(callback_name);
+
+ /* register rebind procedure */
+ if (ld->rebindproc == NULL) {
+ ldap_set_rebind_proc(ld->link, _ldap_rebind_proc, (void *) link);
+ } else {
+ zval_dtor(ld->rebindproc);
+ }
+
+ ALLOC_ZVAL(ld->rebindproc);
+ *ld->rebindproc = *callback;
+ zval_copy_ctor(ld->rebindproc);
+ RETURN_TRUE;
+}
+/* }}} */
+#endif
+
+#ifdef STR_TRANSLATION
+/* {{{ php_ldap_do_translate
+ */
+static void php_ldap_do_translate(INTERNAL_FUNCTION_PARAMETERS, int way)
+{
+ char *value;
+ int result, ldap_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &value, &value_len) != SUCCESS) {
+ return;
+ }
+
+ if (value_len == 0) {
+ RETURN_FALSE;
+ }
+
+ if (way == 1) {
+ result = ldap_8859_to_t61(&value, &value_len, 0);
+ } else {
+ result = ldap_t61_to_8859(&value, &value_len, 0);
+ }
+
+ if (result == LDAP_SUCCESS) {
+ RETVAL_STRINGL(value, value_len, 1);
+ free(value);
+ } else {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Conversion from iso-8859-1 to t61 failed: %s", ldap_err2string(result));
+ RETVAL_FALSE;
+ }
+}
+/* }}} */
+
+/* {{{ proto string ldap_t61_to_8859(string value)
+ Translate t61 characters to 8859 characters */
+PHP_FUNCTION(ldap_t61_to_8859)
+{
+ php_ldap_do_translate(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
+}
+/* }}} */
+
+/* {{{ proto string ldap_8859_to_t61(string value)
+ Translate 8859 characters to t61 characters */
+PHP_FUNCTION(ldap_8859_to_t61)
+{
+ php_ldap_do_translate(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
+}
+/* }}} */
+#endif
+
+#ifdef LDAP_CONTROL_PAGEDRESULTS
+/* {{{ proto mixed ldap_control_paged_result(resource link, int pagesize [, bool iscritical [, string cookie]])
+ Inject paged results control*/
+PHP_FUNCTION(ldap_control_paged_result)
+{
+ long pagesize;
+ zend_bool iscritical;
+ zval *link;
+ char *cookie = NULL;
+ int cookie_len = 0;
+ struct berval lcookie = { 0, NULL };
+ ldap_linkdata *ld;
+ LDAP *ldap;
+ BerElement *ber = NULL;
+ LDAPControl ctrl, *ctrlsp[2];
+ int rc, myargcount = ZEND_NUM_ARGS();
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|bs", &link, &pagesize, &iscritical, &cookie, &cookie_len) != SUCCESS) {
+ return;
+ }
+
+ if (Z_TYPE_P(link) == IS_NULL) {
+ ldap = NULL;
+ } else {
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+ ldap = ld->link;
+ }
+
+ ber = ber_alloc_t(LBER_USE_DER);
+ if (ber == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to alloc BER encoding resources for paged results control");
+ RETURN_FALSE;
+ }
+
+ ctrl.ldctl_iscritical = 0;
+
+ switch (myargcount) {
+ case 4:
+ lcookie.bv_val = cookie;
+ lcookie.bv_len = cookie_len;
+ /* fallthru */
+ case 3:
+ ctrl.ldctl_iscritical = (int)iscritical;
+ /* fallthru */
+ }
+
+ if (ber_printf(ber, "{iO}", (int)pagesize, &lcookie) == LBER_ERROR) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to BER printf paged results control");
+ RETVAL_FALSE;
+ goto lcpr_error_out;
+ }
+ rc = ber_flatten2(ber, &ctrl.ldctl_value, 0);
+ if (rc == LBER_ERROR) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to BER encode paged results control");
+ RETVAL_FALSE;
+ goto lcpr_error_out;
+ }
+
+ ctrl.ldctl_oid = LDAP_CONTROL_PAGEDRESULTS;
+
+ if (ldap) {
+ /* directly set the option */
+ ctrlsp[0] = &ctrl;
+ ctrlsp[1] = NULL;
+
+ rc = ldap_set_option(ldap, LDAP_OPT_SERVER_CONTROLS, ctrlsp);
+ if (rc != LDAP_SUCCESS) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to set paged results control: %s (%d)", ldap_err2string(rc), rc);
+ RETVAL_FALSE;
+ goto lcpr_error_out;
+ }
+ RETVAL_TRUE;
+ } else {
+ /* return a PHP control object */
+ array_init(return_value);
+
+ add_assoc_string(return_value, "oid", ctrl.ldctl_oid, 1);
+ if (ctrl.ldctl_value.bv_len) {
+ add_assoc_stringl(return_value, "value", ctrl.ldctl_value.bv_val, ctrl.ldctl_value.bv_len, 1);
+ }
+ if (ctrl.ldctl_iscritical) {
+ add_assoc_bool(return_value, "iscritical", ctrl.ldctl_iscritical);
+ }
+ }
+
+lcpr_error_out:
+ if (ber != NULL) {
+ ber_free(ber, 1);
+ }
+ return;
+}
+/* }}} */
+
+/* {{{ proto bool ldap_control_paged_result_response(resource link, resource result [, string &cookie [, int &estimated]])
+ Extract paged results control response */
+PHP_FUNCTION(ldap_control_paged_result_response)
+{
+ zval *link, *result, *cookie, *estimated;
+ struct berval lcookie;
+ int lestimated;
+ ldap_linkdata *ld;
+ LDAPMessage *ldap_result;
+ LDAPControl **lserverctrls, *lctrl;
+ BerElement *ber;
+ ber_tag_t tag;
+ int rc, lerrcode, myargcount = ZEND_NUM_ARGS();
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|zz", &link, &result, &cookie, &estimated) != SUCCESS) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+ ZEND_FETCH_RESOURCE(ldap_result, LDAPMessage *, &result, -1, "ldap result", le_result);
+
+ rc = ldap_parse_result(ld->link,
+ ldap_result,
+ &lerrcode,
+ NULL, /* matcheddn */
+ NULL, /* errmsg */
+ NULL, /* referrals */
+ &lserverctrls,
+ 0);
+
+ if (rc != LDAP_SUCCESS) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to parse result: %s (%d)", ldap_err2string(rc), rc);
+ RETURN_FALSE;
+ }
+
+ if (lerrcode != LDAP_SUCCESS) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Result is: %s (%d)", ldap_err2string(lerrcode), lerrcode);
+ RETURN_FALSE;
+ }
+
+ if (lserverctrls == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "No server controls in result");
+ RETURN_FALSE;
+ }
+
+ lctrl = ldap_find_control(LDAP_CONTROL_PAGEDRESULTS, lserverctrls);
+ if (lctrl == NULL) {
+ ldap_controls_free(lserverctrls);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "No paged results control response in result");
+ RETURN_FALSE;
+ }
+
+ ber = ber_init(&lctrl->ldctl_value);
+ if (ber == NULL) {
+ ldap_controls_free(lserverctrls);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to alloc BER decoding resources for paged results control response");
+ RETURN_FALSE;
+ }
+
+ tag = ber_scanf(ber, "{io}", &lestimated, &lcookie);
+ (void)ber_free(ber, 1);
+
+ if (tag == LBER_ERROR) {
+ ldap_controls_free(lserverctrls);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to decode paged results control response");
+ RETURN_FALSE;
+ }
+
+ if (lestimated < 0) {
+ ldap_controls_free(lserverctrls);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid paged results control response value");
+ RETURN_FALSE;
+ }
+
+ ldap_controls_free(lserverctrls);
+ if (myargcount == 4) {
+ zval_dtor(estimated);
+ ZVAL_LONG(estimated, lestimated);
+ }
+
+ zval_dtor(cookie);
+ if (lcookie.bv_len == 0) {
+ ZVAL_EMPTY_STRING(cookie);
+ } else {
+ ZVAL_STRINGL(cookie, lcookie.bv_val, lcookie.bv_len, 1);
+ }
+ ldap_memfree(lcookie.bv_val);
+
+ RETURN_TRUE;
+}
+/* }}} */
+#endif
+
+/* {{{ arginfo */
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_connect, 0, 0, 0)
+ ZEND_ARG_INFO(0, hostname)
+ ZEND_ARG_INFO(0, port)
+#ifdef HAVE_ORALDAP
+ ZEND_ARG_INFO(0, wallet)
+ ZEND_ARG_INFO(0, wallet_passwd)
+ ZEND_ARG_INFO(0, authmode)
+#endif
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_resource, 0, 0, 1)
+ ZEND_ARG_INFO(0, link_identifier)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_bind, 0, 0, 1)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, bind_rdn)
+ ZEND_ARG_INFO(0, bind_password)
+ZEND_END_ARG_INFO()
+
+#ifdef HAVE_LDAP_SASL
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_sasl_bind, 0, 0, 1)
+ ZEND_ARG_INFO(0, link)
+ ZEND_ARG_INFO(0, binddn)
+ ZEND_ARG_INFO(0, password)
+ ZEND_ARG_INFO(0, sasl_mech)
+ ZEND_ARG_INFO(0, sasl_realm)
+ ZEND_ARG_INFO(0, sasl_authz_id)
+ ZEND_ARG_INFO(0, props)
+ZEND_END_ARG_INFO()
+#endif
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_read, 0, 0, 3)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, base_dn)
+ ZEND_ARG_INFO(0, filter)
+ ZEND_ARG_INFO(0, attributes)
+ ZEND_ARG_INFO(0, attrsonly)
+ ZEND_ARG_INFO(0, sizelimit)
+ ZEND_ARG_INFO(0, timelimit)
+ ZEND_ARG_INFO(0, deref)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_list, 0, 0, 3)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, base_dn)
+ ZEND_ARG_INFO(0, filter)
+ ZEND_ARG_INFO(0, attributes)
+ ZEND_ARG_INFO(0, attrsonly)
+ ZEND_ARG_INFO(0, sizelimit)
+ ZEND_ARG_INFO(0, timelimit)
+ ZEND_ARG_INFO(0, deref)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_search, 0, 0, 3)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, base_dn)
+ ZEND_ARG_INFO(0, filter)
+ ZEND_ARG_INFO(0, attributes)
+ ZEND_ARG_INFO(0, attrsonly)
+ ZEND_ARG_INFO(0, sizelimit)
+ ZEND_ARG_INFO(0, timelimit)
+ ZEND_ARG_INFO(0, deref)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_count_entries, 0, 0, 2)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, result_identifier)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_first_entry, 0, 0, 2)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, result_identifier)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_next_entry, 0, 0, 2)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, result_identifier)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_get_entries, 0, 0, 2)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, result_identifier)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_first_attribute, 0, 0, 2)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, result_entry_identifier)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_next_attribute, 0, 0, 2)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, result_entry_identifier)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_get_attributes, 0, 0, 2)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, result_entry_identifier)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_get_values, 0, 0, 3)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, result_entry_identifier)
+ ZEND_ARG_INFO(0, attribute)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_get_values_len, 0, 0, 3)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, result_entry_identifier)
+ ZEND_ARG_INFO(0, attribute)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_get_dn, 0, 0, 2)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, result_entry_identifier)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_explode_dn, 0, 0, 2)
+ ZEND_ARG_INFO(0, dn)
+ ZEND_ARG_INFO(0, with_attrib)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_dn2ufn, 0, 0, 1)
+ ZEND_ARG_INFO(0, dn)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_add, 0, 0, 3)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, dn)
+ ZEND_ARG_INFO(0, entry)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_delete, 0, 0, 2)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, dn)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_modify, 0, 0, 3)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, dn)
+ ZEND_ARG_INFO(0, entry)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_mod_add, 0, 0, 3)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, dn)
+ ZEND_ARG_INFO(0, entry)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_mod_replace, 0, 0, 3)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, dn)
+ ZEND_ARG_INFO(0, entry)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_mod_del, 0, 0, 3)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, dn)
+ ZEND_ARG_INFO(0, entry)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_err2str, 0, 0, 1)
+ ZEND_ARG_INFO(0, errno)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_compare, 0, 0, 4)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, dn)
+ ZEND_ARG_INFO(0, attribute)
+ ZEND_ARG_INFO(0, value)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_sort, 0, 0, 3)
+ ZEND_ARG_INFO(0, link)
+ ZEND_ARG_INFO(0, result)
+ ZEND_ARG_INFO(0, sortfilter)
+ZEND_END_ARG_INFO()
+
+#ifdef LDAP_CONTROL_PAGEDRESULTS
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_control_paged_result, 0, 0, 2)
+ ZEND_ARG_INFO(0, link)
+ ZEND_ARG_INFO(0, pagesize)
+ ZEND_ARG_INFO(0, iscritical)
+ ZEND_ARG_INFO(0, cookie)
+ZEND_END_ARG_INFO();
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_control_paged_result_response, 0, 0, 2)
+ ZEND_ARG_INFO(0, link)
+ ZEND_ARG_INFO(0, result)
+ ZEND_ARG_INFO(1, cookie)
+ ZEND_ARG_INFO(1, estimated)
+ZEND_END_ARG_INFO();
+#endif
+
+#if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP_10
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_rename, 0, 0, 5)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, dn)
+ ZEND_ARG_INFO(0, newrdn)
+ ZEND_ARG_INFO(0, newparent)
+ ZEND_ARG_INFO(0, deleteoldrdn)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_get_option, 0, 0, 3)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, option)
+ ZEND_ARG_INFO(1, retval)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_set_option, 0, 0, 3)
+ ZEND_ARG_INFO(0, link_identifier)
+ ZEND_ARG_INFO(0, option)
+ ZEND_ARG_INFO(0, newval)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_first_reference, 0, 0, 2)
+ ZEND_ARG_INFO(0, link)
+ ZEND_ARG_INFO(0, result)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_next_reference, 0, 0, 2)
+ ZEND_ARG_INFO(0, link)
+ ZEND_ARG_INFO(0, entry)
+ZEND_END_ARG_INFO()
+
+#ifdef HAVE_LDAP_PARSE_REFERENCE
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_parse_reference, 0, 0, 3)
+ ZEND_ARG_INFO(0, link)
+ ZEND_ARG_INFO(0, entry)
+ ZEND_ARG_INFO(1, referrals)
+ZEND_END_ARG_INFO()
+#endif
+
+
+#ifdef HAVE_LDAP_PARSE_RESULT
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_parse_result, 0, 0, 3)
+ ZEND_ARG_INFO(0, link)
+ ZEND_ARG_INFO(0, result)
+ ZEND_ARG_INFO(1, errcode)
+ ZEND_ARG_INFO(1, matcheddn)
+ ZEND_ARG_INFO(1, errmsg)
+ ZEND_ARG_INFO(1, referrals)
+ZEND_END_ARG_INFO()
+#endif
+#endif
+
+#if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_set_rebind_proc, 0, 0, 2)
+ ZEND_ARG_INFO(0, link)
+ ZEND_ARG_INFO(0, callback)
+ZEND_END_ARG_INFO()
+#endif
+
+#ifdef STR_TRANSLATION
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_t61_to_8859, 0, 0, 1)
+ ZEND_ARG_INFO(0, value)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_8859_to_t61, 0, 0, 1)
+ ZEND_ARG_INFO(0, value)
+ZEND_END_ARG_INFO()
+#endif
+/* }}} */
+
+/*
+ This is just a small subset of the functionality provided by the LDAP library. All the
+ operations are synchronous. Referrals are not handled automatically.
+*/
+/* {{{ ldap_functions[]
+ */
+const zend_function_entry ldap_functions[] = {
+ PHP_FE(ldap_connect, arginfo_ldap_connect)
+ PHP_FALIAS(ldap_close, ldap_unbind, arginfo_ldap_resource)
+ PHP_FE(ldap_bind, arginfo_ldap_bind)
+#ifdef HAVE_LDAP_SASL
+ PHP_FE(ldap_sasl_bind, arginfo_ldap_sasl_bind)
+#endif
+ PHP_FE(ldap_unbind, arginfo_ldap_resource)
+ PHP_FE(ldap_read, arginfo_ldap_read)
+ PHP_FE(ldap_list, arginfo_ldap_list)
+ PHP_FE(ldap_search, arginfo_ldap_search)
+ PHP_FE(ldap_free_result, arginfo_ldap_resource)
+ PHP_FE(ldap_count_entries, arginfo_ldap_count_entries)
+ PHP_FE(ldap_first_entry, arginfo_ldap_first_entry)
+ PHP_FE(ldap_next_entry, arginfo_ldap_next_entry)
+ PHP_FE(ldap_get_entries, arginfo_ldap_get_entries)
+ PHP_FE(ldap_first_attribute, arginfo_ldap_first_attribute)
+ PHP_FE(ldap_next_attribute, arginfo_ldap_next_attribute)
+ PHP_FE(ldap_get_attributes, arginfo_ldap_get_attributes)
+ PHP_FALIAS(ldap_get_values, ldap_get_values_len, arginfo_ldap_get_values)
+ PHP_FE(ldap_get_values_len, arginfo_ldap_get_values_len)
+ PHP_FE(ldap_get_dn, arginfo_ldap_get_dn)
+ PHP_FE(ldap_explode_dn, arginfo_ldap_explode_dn)
+ PHP_FE(ldap_dn2ufn, arginfo_ldap_dn2ufn)
+ PHP_FE(ldap_add, arginfo_ldap_add)
+ PHP_FE(ldap_delete, arginfo_ldap_delete)
+ PHP_FALIAS(ldap_modify, ldap_mod_replace, arginfo_ldap_modify)
+
+/* additional functions for attribute based modifications, Gerrit Thomson */
+ PHP_FE(ldap_mod_add, arginfo_ldap_mod_add)
+ PHP_FE(ldap_mod_replace, arginfo_ldap_mod_replace)
+ PHP_FE(ldap_mod_del, arginfo_ldap_mod_del)
+/* end gjt mod */
+
+ PHP_FE(ldap_errno, arginfo_ldap_resource)
+ PHP_FE(ldap_err2str, arginfo_ldap_err2str)
+ PHP_FE(ldap_error, arginfo_ldap_resource)
+ PHP_FE(ldap_compare, arginfo_ldap_compare)
+ PHP_FE(ldap_sort, arginfo_ldap_sort)
+
+#if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP_10
+ PHP_FE(ldap_rename, arginfo_ldap_rename)
+ PHP_FE(ldap_get_option, arginfo_ldap_get_option)
+ PHP_FE(ldap_set_option, arginfo_ldap_set_option)
+ PHP_FE(ldap_first_reference, arginfo_ldap_first_reference)
+ PHP_FE(ldap_next_reference, arginfo_ldap_next_reference)
+#ifdef HAVE_LDAP_PARSE_REFERENCE
+ PHP_FE(ldap_parse_reference, arginfo_ldap_parse_reference)
+#endif
+#ifdef HAVE_LDAP_PARSE_RESULT
+ PHP_FE(ldap_parse_result, arginfo_ldap_parse_result)
+#endif
+#ifdef HAVE_LDAP_START_TLS_S
+ PHP_FE(ldap_start_tls, arginfo_ldap_resource)
+#endif
+#endif
+
+#if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
+ PHP_FE(ldap_set_rebind_proc, arginfo_ldap_set_rebind_proc)
+#endif
+
+#ifdef STR_TRANSLATION
+ PHP_FE(ldap_t61_to_8859, arginfo_ldap_t61_to_8859)
+ PHP_FE(ldap_8859_to_t61, arginfo_ldap_8859_to_t61)
+#endif
+
+#ifdef LDAP_CONTROL_PAGEDRESULTS
+ PHP_FE(ldap_control_paged_result, arginfo_ldap_control_paged_result)
+ PHP_FE(ldap_control_paged_result_response, arginfo_ldap_control_paged_result_response)
+#endif
+ PHP_FE_END
+};
+/* }}} */
+
+zend_module_entry ldap_module_entry = { /* {{{ */
+ STANDARD_MODULE_HEADER,
+ "ldap",
+ ldap_functions,
+ PHP_MINIT(ldap),
+ PHP_MSHUTDOWN(ldap),
+ NULL,
+ NULL,
+ PHP_MINFO(ldap),
+ NO_VERSION_YET,
+ PHP_MODULE_GLOBALS(ldap),
+ PHP_GINIT(ldap),
+ NULL,
+ NULL,
+ STANDARD_MODULE_PROPERTIES_EX
+};
+/* }}} */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */
diff --git a/ext/ldap/ldap.dsp b/ext/ldap/ldap.dsp
new file mode 100644
index 0000000..a97ebe4
--- /dev/null
+++ b/ext/ldap/ldap.dsp
@@ -0,0 +1,288 @@
+# Microsoft Developer Studio Project File - Name="ldap" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=ldap - Win32 Debug_TS_SSL
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "ldap.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "ldap.mak" CFG="ldap - Win32 Debug_TS_SSL"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "ldap - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "ldap - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "ldap - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "ldap - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "ldap - Win32 Release_TS SASL" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "ldap - Win32 Debug_TS SASL" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "ldap - Win32 Release_TS_SSL" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "ldap - Win32 Debug_TS_SSL" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "ldap - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LDAP_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "..\..\..\php_build\openldap\include" /D "NDEBUG" /D ZEND_DEBUG=0 /D "COMPILE_DL_LDAP_LDAP" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LDAP_EXPORTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_LDAP=1 /D "COMPILE_DL_LDAP" /D "HAVE_LDAP_START_TLS_S" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
+# ADD LINK32 oldap32.lib olber32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib php5nts.lib /nologo /dll /machine:I386 /out:"Release/php_ldap.dll" /libpath:"..\..\Release" /libpath:"..\..\..\php_build\openldap\libraries\Release"
+
+!ELSEIF "$(CFG)" == "ldap - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LDAP_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "..\..\..\php_build\openldap\include" /D "_DEBUG" /D ZEND_DEBUG=1 /D "COMPILE_DL_LDAP_LDAP" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LDAP_EXPORTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_LDAP=1 /D "COMPILE_DL_LDAP" /D "HAVE_LDAP_START_TLS_S" /FR /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 oldap32.lib olber32.lib php5nts_debug.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /dll /debug /machine:I386 /out:"Debug/php_ldap.dll" /pdbtype:sept /libpath:"..\..\Debug" /libpath:"..\..\..\php_build\openldap\libraries\Debug"
+
+!ELSEIF "$(CFG)" == "ldap - Win32 Debug_TS"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug_TS"
+# PROP BASE Intermediate_Dir "Debug_TS"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug_TS"
+# PROP Intermediate_Dir "Debug_TS"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "..\..\..\openldap\include" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LDAP_EXPORTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_LDAP=1 /D ZEND_DEBUG=1 /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "..\..\..\php_build\openldap\include" /D "_DEBUG" /D ZEND_DEBUG=1 /D "ZTS" /D "COMPILE_DL_LDAP" /D "HAVE_LDAP_START_TLS_S" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LDAP_EXPORTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_LDAP=1 /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 oldap32.lib olber32.lib php5nts_debug.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept /libpath:"..\..\..\openldap\libraries\Debug" /libpath:"..\..\Debug"
+# ADD LINK32 oldap32.lib olber32.lib php5ts_debug.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /dll /debug /machine:I386 /out:"..\..\Debug_TS/php_ldap.dll" /pdbtype:sept /libpath:"..\..\Debug_TS" /libpath:"..\..\..\php_build\openldap\libraries\Debug"
+
+!ELSEIF "$(CFG)" == "ldap - Win32 Release_TS"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release_TS"
+# PROP BASE Intermediate_Dir "Release_TS"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release_TS"
+# PROP Intermediate_Dir "Release_TS"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "..\..\..\openldap\include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LDAP_EXPORTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_LDAP=1 /D ZEND_DEBUG=0 /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "..\..\..\php_build\openldap\include" /D "NDEBUG" /D ZEND_DEBUG=0 /D "ZTS" /D "COMPILE_DL_LDAP" /D "HAVE_LDAP_START_TLS_S" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LDAP_EXPORTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_LDAP=1 /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 oldap32.lib olber32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib php5ts.lib /nologo /dll /machine:I386
+# ADD LINK32 oldap32.lib olber32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib php5ts.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_ldap.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\..\php_build\openldap\libraries\Release" /libpath:"..\..\Release_TS_Inline"
+
+!ELSEIF "$(CFG)" == "ldap - Win32 Release_TS SASL"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "ldap___Win32_Release_TS_SASL"
+# PROP BASE Intermediate_Dir "ldap___Win32_Release_TS_SASL"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release_TS_SASL"
+# PROP Intermediate_Dir "Release_TS_SASL"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "..\..\..\php_build\openldap\include" /D "NDEBUG" /D ZEND_DEBUG=0 /D "ZTS" /D "COMPILE_DL_LDAP" /D "HAVE_LDAP_START_TLS_S" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LDAP_EXPORTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_LDAP=1 /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "..\..\..\php_build\openldap\include" /D "NDEBUG" /D ZEND_DEBUG=0 /D "ZTS" /D "COMPILE_DL_LDAP" /D "HAVE_LDAP_START_TLS_S" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LDAP_EXPORTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_LDAP=1 /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 oldap32.lib olber32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib php5ts.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_ldap.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\..\php_build\openldap\libraries\Release" /libpath:"..\..\Release_TS_Inline"
+# ADD LINK32 oldap32.lib olber32.lib libsasl.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib php5ts.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_ldap.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\..\php_build\openldap\libraries\Release" /libpath:"..\..\Release_TS_Inline"
+
+!ELSEIF "$(CFG)" == "ldap - Win32 Debug_TS SASL"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "ldap___Win32_Debug_TS_SASL"
+# PROP BASE Intermediate_Dir "ldap___Win32_Debug_TS_SASL"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug_TS_SASL"
+# PROP Intermediate_Dir "Debug_TS_SASL"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "..\..\..\php_build\openldap\include" /D "_DEBUG" /D ZEND_DEBUG=1 /D "ZTS" /D "COMPILE_DL_LDAP" /D "HAVE_LDAP_START_TLS_S" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LDAP_EXPORTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_LDAP=1 /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "..\..\..\php_build\openldap\include" /D "_DEBUG" /D ZEND_DEBUG=1 /D "ZTS" /D "COMPILE_DL_LDAP" /D "HAVE_LDAP_START_TLS_S" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LDAP_EXPORTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_LDAP=1 /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 oldap32.lib olber32.lib php5ts_debug.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /dll /debug /machine:I386 /out:"Debug_TS/php_ldap.dll" /pdbtype:sept /libpath:"..\..\Debug_TS" /libpath:"..\..\..\php_build\openldap\libraries\Debug"
+# ADD LINK32 oldap32.lib olber32.lib libsasl.lib php5ts_debug.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /dll /debug /machine:I386 /out:"..\..\Debug_TS/php_ldap.dll" /pdbtype:sept /libpath:"..\..\Debug_TS" /libpath:"..\..\..\php_build\openldap\libraries\Debug"
+
+!ELSEIF "$(CFG)" == "ldap - Win32 Release_TS_SSL"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "ldap___Win32_Release_TS_SSL"
+# PROP BASE Intermediate_Dir "ldap___Win32_Release_TS_SSL"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release_TS_SSL"
+# PROP Intermediate_Dir "Release_TS_SSL"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "..\..\..\php_build\openldap\include" /D "NDEBUG" /D ZEND_DEBUG=0 /D "ZTS" /D "COMPILE_DL_LDAP" /D "HAVE_LDAP_START_TLS_S" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LDAP_EXPORTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_LDAP=1 /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "..\..\..\php_build\openldap\include" /D "NDEBUG" /D ZEND_DEBUG=0 /D "ZTS" /D "COMPILE_DL_LDAP" /D "HAVE_LDAP_START_TLS_S" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LDAP_EXPORTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_LDAP=1 /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 oldap32.lib olber32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib php5ts.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_ldap.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\..\php_build\openldap\libraries\Release" /libpath:"..\..\Release_TS_Inline"
+# ADD LINK32 php5ts.lib oldap32.lib olber32.lib ssleay32.lib libeay32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_ldap.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\..\php_build\openldap\libraries\Release" /libpath:"..\..\Release_TS_Inline"
+
+!ELSEIF "$(CFG)" == "ldap - Win32 Debug_TS_SSL"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "ldap___Win32_Debug_TS_SSL"
+# PROP BASE Intermediate_Dir "ldap___Win32_Debug_TS_SSL"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug_TS_SSL"
+# PROP Intermediate_Dir "Debug_TS_SSL"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "..\..\..\php_build\openldap\include" /D "_DEBUG" /D ZEND_DEBUG=1 /D "ZTS" /D "COMPILE_DL_LDAP" /D "HAVE_LDAP_START_TLS_S" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LDAP_EXPORTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_LDAP=1 /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "..\..\..\php_build\openldap\include" /D "_DEBUG" /D ZEND_DEBUG=1 /D "ZTS" /D "COMPILE_DL_LDAP" /D "HAVE_LDAP_START_TLS_S" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LDAP_EXPORTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_LDAP=1 /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 oldap32.lib olber32.lib php5ts_debug.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /dll /debug /machine:I386 /out:"..\..\Debug_TS/php_ldap.dll" /pdbtype:sept /libpath:"..\..\Debug_TS" /libpath:"..\..\..\php_build\openldap\libraries\Debug"
+# ADD LINK32 php5ts_debug.lib oldap32.lib olber32.lib ssleay32.lib libeay32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /dll /debug /machine:I386 /out:"..\..\Debug_TS/php_ldap.dll" /pdbtype:sept /libpath:"..\..\Debug_TS" /libpath:"..\..\..\php_build\openldap\libraries\Debug"
+
+!ENDIF
+
+# Begin Target
+
+# Name "ldap - Win32 Release"
+# Name "ldap - Win32 Debug"
+# Name "ldap - Win32 Debug_TS"
+# Name "ldap - Win32 Release_TS"
+# Name "ldap - Win32 Release_TS SASL"
+# Name "ldap - Win32 Debug_TS SASL"
+# Name "ldap - Win32 Release_TS_SSL"
+# Name "ldap - Win32 Debug_TS_SSL"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\ldap.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\php_ldap.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# Begin Source File
+
+SOURCE=.\LDAP_Win32_HOWTO.txt
+# End Source File
+# End Target
+# End Project
diff --git a/ext/ldap/ldap.mak b/ext/ldap/ldap.mak
new file mode 100644
index 0000000..959fe16
--- /dev/null
+++ b/ext/ldap/ldap.mak
@@ -0,0 +1,173 @@
+# Temporarily here -- later may go into some batch file
+# which will set this as an environment variable
+PROJECT_ROOT = ..\..
+
+# Module details
+MODULE_NAME = php_ldap
+MODULE_DESC = "PHP 5 - LDAP Extension"
+VMAJ = 3
+VMIN = 0
+VREV = 0
+
+#include the common settings
+include $(PROJECT_ROOT)/netware/common.mif
+
+# Extensions of all input and output files
+.SUFFIXES:
+.SUFFIXES: .nlm .lib .obj .cpp .c .msg .mlc .mdb .xdc .d
+
+# Source files
+C_SRC = ldap.c \
+ start.c
+
+CPP_SRC_NODIR = $(notdir $(CPP_SRC))
+C_SRC_NODIR = $(notdir $(C_SRC))
+SRC_DIR = $(dir $(CPP_SRC) $(C_SRC))
+
+# Library files
+LIBRARY =
+
+# Destination directories and files
+OBJ_DIR = $(BUILD)
+FINAL_DIR = $(BUILD)
+MAP_FILE = $(FINAL_DIR)\$(MODULE_NAME).map
+OBJECTS = $(addprefix $(OBJ_DIR)/,$(CPP_SRC_NODIR:.c=.obj) $(C_SRC_NODIR:.c=.obj))
+DEPDS = $(addprefix $(OBJ_DIR)/,$(CPP_SRC_NODIR:.c=.d) $(C_SRC_NODIR:.c=.d))
+
+# Binary file
+ifndef BINARY
+ BINARY=$(FINAL_DIR)\$(MODULE_NAME).nlm
+endif
+
+# Compile flags
+C_FLAGS += -c -maxerrors 25 -msgstyle gcc
+C_FLAGS += -wchar_t on -bool on
+C_FLAGS += -processor Pentium
+C_FLAGS += -nostdinc -nosyspath
+C_FLAGS += -relax_pointers # To remove type-casting errors
+C_FLAGS += -DNETWARE -DZTS
+C_FLAGS += -DNEW_LIBC
+C_FLAGS += -DCOMPILE_DL_LDAP
+C_FLAGS += -I. -I- -I$(PROJECT_ROOT) -I$(PROJECT_ROOT)/main
+C_FLAGS += -I$(PROJECT_ROOT)/ext/standard -I$(PROJECT_ROOT)/netware
+C_FLAGS += -I$(PROJECT_ROOT)/zend -I$(PROJECT_ROOT)/tsrm
+C_FLAGS += -I$(SDK_DIR)/include -I$(MWCIncludes)
+C_FLAGS += -I$(LDAP_DIR)/inc
+C_FLAGS += -I$(WINSOCK_DIR)/include/nlm -I$(WINSOCK_DIR)/include
+
+ifndef STACK_SIZE
+STACK_SIZE=8192
+endif
+
+# Extra stuff based on debug / release builds
+ifeq '$(BUILD)' 'debug'
+ SYM_FILE = $(FINAL_DIR)\$(MODULE_NAME).sym
+ C_FLAGS += -inline smart -sym on -sym codeview4 -opt off -opt intrinsics -sym internal -DDEBUGGING -DDKFBPON
+ C_FLAGS += -exc cw -DZEND_DEBUG=1
+ LD_FLAGS += -sym on -sym codeview4 -osym $(SYM_FILE)
+ export MWLibraryFiles=$(SDK_DIR)/imports/libcpre.o;mwcrtld.lib
+else
+ C_FLAGS += -opt speed -inline on -inline smart -inline auto -sym off
+ C_FLAGS += -opt intrinsics
+ C_FLAGS += -opt level=4 -DZEND_DEBUG=0
+ LD_FLAGS += -sym off
+ export MWLibraryFiles=$(SDK_DIR)/imports/libcpre.o;mwcrtl.lib
+endif
+
+# Dependencies
+MODULE = LibC \
+ ldapsdk \
+ phplib
+IMPORT = @$(SDK_DIR)/imports/libc.imp \
+ @$(SDK_DIR)/imports/ws2nlm.imp \
+ @$(MPK_DIR)/import/mpkOrg.imp \
+ @$(LDAP_DIR)/lib/nlm/Ldapsdk.imp \
+ @$(PROJECT_ROOT)/netware/phplib.imp
+EXPORT = ($(MODULE_NAME)) get_module
+API = OutputToScreen
+
+
+# Virtual paths
+vpath %.cpp .
+vpath %.c . ..\..\netware
+vpath %.obj $(OBJ_DIR)
+
+
+all: prebuild project
+
+.PHONY: all
+
+prebuild:
+ @if not exist $(OBJ_DIR) md $(OBJ_DIR)
+
+project: $(BINARY)
+ @echo Build complete.
+
+$(OBJ_DIR)/%.d: %.cpp
+ @echo Building Dependencies for $(<F)
+ @$(CC) -M $< $(C_FLAGS) -o $@
+
+$(OBJ_DIR)/%.d: %.c
+ @echo Building Dependencies for $(<F)
+ @$(CC) -M $< $(C_FLAGS) -o $@
+
+$(OBJ_DIR)/%.obj: %.cpp
+ @echo Compiling $?...
+ @$(CC) $< $(C_FLAGS) -o $@
+
+$(OBJ_DIR)/%.obj: %.c
+ @echo Compiling $?...
+ @$(CC) $< $(C_FLAGS) -o $@
+
+
+$(BINARY): $(OBJECTS)
+ @echo Import $(IMPORT) > $(basename $@).def
+ifdef API
+ @echo Import $(API) >> $(basename $@).def
+endif
+ @echo Module $(MODULE) >> $(basename $@).def
+ifdef EXPORT
+ @echo Export $(EXPORT) >> $(basename $@).def
+endif
+ @echo AutoUnload >> $(basename $@).def
+ifeq '$(BUILD)' 'debug'
+ @echo Debug >> $(basename $@).def
+endif
+ @echo Flag_On 0x00000008 >> $(basename $@).def
+ @echo Start _LibCPrelude >> $(basename $@).def
+ @echo Exit _LibCPostlude >> $(basename $@).def
+
+ $(MPKTOOL) $(XDCFLAGS) $(basename $@).xdc
+ @echo xdcdata $(basename $@).xdc >> $(basename $@).def
+
+ @echo Linking $@...
+ @echo $(LD_FLAGS) -commandfile $(basename $@).def > $(basename $@).link
+ @echo $(LIBRARY) $(OBJECTS) >> $(basename $@).link
+
+ @$(LINK) @$(basename $@).link
+
+
+.PHONY: clean
+clean: cleanobj cleanbin
+
+.PHONY: cleand
+cleand:
+ @echo Deleting all dependency files...
+ -@del "$(OBJ_DIR)\*.d"
+
+.PHONY: cleanobj
+cleanobj:
+ @echo Deleting all object files...
+ -@del "$(OBJ_DIR)\*.obj"
+
+.PHONY: cleanbin
+cleanbin:
+ @echo Deleting binary files...
+ -@del "$(FINAL_DIR)\$(MODULE_NAME).nlm"
+ @echo Deleting MAP, DEF files, etc....
+ -@del "$(FINAL_DIR)\$(MODULE_NAME).map"
+ -@del "$(FINAL_DIR)\$(MODULE_NAME).def"
+ -@del "$(FINAL_DIR)\$(MODULE_NAME).link"
+ifeq '$(BUILD)' 'debug'
+ -@del $(FINAL_DIR)\$(MODULE_NAME).sym
+endif
diff --git a/ext/ldap/php_ldap.h b/ext/ldap/php_ldap.h
new file mode 100644
index 0000000..2ed8fd8
--- /dev/null
+++ b/ext/ldap/php_ldap.h
@@ -0,0 +1,53 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2013 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Authors: Amitay Isaacs <amitay@w-o-i.com> |
+ | Eric Warnke <ericw@albany.edu> |
+ | Jani Taskinen <sniper@iki.fi> |
+ +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+#ifndef PHP_LDAP_H
+#define PHP_LDAP_H
+
+#ifndef HAVE_ORALDAP
+#include <lber.h>
+#endif
+
+#include <ldap.h>
+
+extern zend_module_entry ldap_module_entry;
+#define ldap_module_ptr &ldap_module_entry
+
+/* LDAP functions */
+PHP_MINIT_FUNCTION(ldap);
+PHP_MSHUTDOWN_FUNCTION(ldap);
+PHP_MINFO_FUNCTION(ldap);
+
+ZEND_BEGIN_MODULE_GLOBALS(ldap)
+ long num_links;
+ long max_links;
+ZEND_END_MODULE_GLOBALS(ldap)
+
+#ifdef ZTS
+# define LDAPG(v) TSRMG(ldap_globals_id, zend_ldap_globals *, v)
+#else
+# define LDAPG(v) (ldap_globals.v)
+#endif
+
+#define phpext_ldap_ptr ldap_module_ptr
+
+#endif /* PHP_LDAP_H */
diff --git a/ext/ldap/tests/README b/ext/ldap/tests/README
new file mode 100644
index 0000000..7dccd27
--- /dev/null
+++ b/ext/ldap/tests/README
@@ -0,0 +1,53 @@
+Most tests here relies on the availability of an LDAP server configured with TLS.
+
+Client/Server configuration:
+===========================================================
+OpenLDAP 2.3.43 has been used with the configuration below.
+
+Notes:
+1. A self signed certificate can be generated using:
+ $ openssl req -newkey rsa:1024 -x509 -nodes -out server.pem -keyout server.pem -days 3650
+ It is used for testing ldap_start_tls(), which also requires "TLS_REQCERT never" in client configuration
+2. An empty LDAP structure is required for the tests to be PASSed
+
+(/etc/openldap/)slapd.conf:
+-----------------------------------------------------------
+TLSCACertificateFile /etc/openldap/ssl/server.pem
+TLSCertificateFile /etc/openldap/ssl/server.pem
+TLSCertificateKeyFile /etc/openldap/ssl/server.pem
+TLSVerifyClient never
+
+# hdb is used instead of bdb as it enables the usage of referrals & aliases
+database hdb
+suffix "dc=my-domain,dc=com"
+checkpoint 32 30
+rootdn "cn=Manager,dc=my-domain,dc=com"
+rootpw secret
+directory /var/lib/openldap-data
+index objectClass eq
+
+authz-regexp
+ uid=Manager,cn=digest-md5,cn=auth
+ cn=Manager,dc=my-domain,dc=com
+
+
+(/etc/openldap/)ldap.conf:
+-----------------------------------------------------------
+TLS_REQCERT never
+
+Tests configuration:
+===========================================================
+The following environment variables may be defined:
+LDAP_TEST_HOST (default: localhost) Host to connect to
+LDAP_TEST_PORT (default: 389) Port to connect to
+LDAP_TEST_USER (default: cn=Manager,dc=my-domain,dc=com) DN used for binding
+LDAP_TEST_SASL_USER (default: Manager) SASL user used for SASL binding
+LDAP_TEST_PASSWD (default: secret) Password used for plain and SASL binding
+LDAP_TEST_OPT_PROTOCOL_VERSION (default: 3) Version of LDAP protocol to use
+LDAP_TEST_SKIP_BIND_FAILURE (default: true) Whether to fail the test or not in case binding fails
+
+Credits:
+===========================================================
+Davide Mendolia <idaf1er@gmail.com>
+Patrick Allaert <patrick.allaert@gmail.com>
+
diff --git a/ext/ldap/tests/bug48441.phpt b/ext/ldap/tests/bug48441.phpt
new file mode 100644
index 0000000..8725661
--- /dev/null
+++ b/ext/ldap/tests/bug48441.phpt
@@ -0,0 +1,169 @@
+--TEST--
+ldap_search() bug 48441 - options persists after specifying them in ldap_search
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$dn = "dc=my-domain,dc=com";
+$filter = "(objectclass=person)";
+
+var_dump(
+ $result = ldap_search($link, $dn, $filter, array('sn')),
+ ldap_get_entries($link, $result)
+);
+var_dump(
+ $result = ldap_search($link, $dn, $filter, array('sn'), 1, 1, 1, LDAP_DEREF_ALWAYS),
+ ldap_get_entries($link, $result)
+);
+var_dump(
+ $result = ldap_search($link, $dn, $filter, array('sn')),
+ ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+resource(%d) of type (ldap result)
+array(4) {
+ ["count"]=>
+ int(3)
+ [0]=>
+ array(4) {
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(7) "testSN1"
+ }
+ [0]=>
+ string(2) "sn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+ }
+ [1]=>
+ array(4) {
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(7) "testSN2"
+ }
+ [0]=>
+ string(2) "sn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(28) "cn=userB,dc=my-domain,dc=com"
+ }
+ [2]=>
+ array(4) {
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(7) "testSN3"
+ }
+ [0]=>
+ string(2) "sn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(37) "cn=userC,cn=userB,dc=my-domain,dc=com"
+ }
+}
+
+Warning: ldap_search(): Partial search results returned: Sizelimit exceeded in %s on line %d
+resource(%d) of type (ldap result)
+array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ array(4) {
+ ["sn"]=>
+ array(1) {
+ ["count"]=>
+ int(0)
+ }
+ [0]=>
+ string(2) "sn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+ }
+}
+resource(%d) of type (ldap result)
+array(4) {
+ ["count"]=>
+ int(3)
+ [0]=>
+ array(4) {
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(7) "testSN1"
+ }
+ [0]=>
+ string(2) "sn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+ }
+ [1]=>
+ array(4) {
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(7) "testSN2"
+ }
+ [0]=>
+ string(2) "sn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(28) "cn=userB,dc=my-domain,dc=com"
+ }
+ [2]=>
+ array(4) {
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(7) "testSN3"
+ }
+ [0]=>
+ string(2) "sn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(37) "cn=userC,cn=userB,dc=my-domain,dc=com"
+ }
+}
+===DONE===
diff --git a/ext/ldap/tests/bug48696.phpt b/ext/ldap/tests/bug48696.phpt
new file mode 100644
index 0000000..8d25b67
--- /dev/null
+++ b/ext/ldap/tests/bug48696.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Bug #48696 (ldap_read() segfaults with invalid parameters)
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+
+ldap_read(1,1,1);
+
+?>
+--EXPECTF--
+Warning: ldap_read(): supplied argument is not a valid ldap link resource in %s on line %d
diff --git a/ext/ldap/tests/connect.inc b/ext/ldap/tests/connect.inc
new file mode 100644
index 0000000..ddb5782
--- /dev/null
+++ b/ext/ldap/tests/connect.inc
@@ -0,0 +1,61 @@
+<?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") ? getenv("LDAP_TEST_PORT") : 389;
+$user = getenv("LDAP_TEST_USER") ? getenv("LDAP_TEST_USER") : "cn=Manager,dc=my-domain,dc=com";
+$sasl_user = getenv("LDAP_TEST_SASL_USER") ? getenv("LDAP_TEST_SASL_USER") : "Manager";
+$passwd = getenv("LDAP_TEST_PASSWD") ? getenv("LDAP_TEST_PASSWD") : "secret";
+$protocol_version = getenv("LDAP_TEST_OPT_PROTOCOL_VERSION") ? getenv("LDAP_TEST_OPT_PROTOCOL_VERSION") : 3;
+$skip_on_bind_failure = getenv("LDAP_TEST_SKIP_BIND_FAILURE") ? getenv("LDAP_TEST_SKIP_BIND_FAILURE") : true;
+
+function ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version) {
+ $link = ldap_connect($host, $port);
+ ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+ ldap_bind($link, $user, $passwd);
+ return $link;
+}
+
+function insert_dummy_data($link) {
+ ldap_add($link, "dc=my-domain,dc=com", array(
+ "objectClass" => array(
+ "top",
+ "dcObject",
+ "organization"),
+ "dc" => "my-domain",
+ "o" => "my-domain",
+ ));
+ ldap_add($link, "cn=userA,dc=my-domain,dc=com", array(
+ "objectclass" => "person",
+ "cn" => "userA",
+ "sn" => "testSN1",
+ "userPassword" => "oops",
+ "telephoneNumber" => "xx-xx-xx-xx-xx",
+ "description" => "user A",
+ ));
+ ldap_add($link, "cn=userB,dc=my-domain,dc=com", array(
+ "objectclass" => "person",
+ "cn" => "userB",
+ "sn" => "testSN2",
+ "userPassword" => "oopsIDitItAgain",
+ "description" => "user B",
+ ));
+ ldap_add($link, "cn=userC,cn=userB,dc=my-domain,dc=com", array(
+ "objectclass" => "person",
+ "cn" => "userC",
+ "sn" => "testSN3",
+ "userPassword" => "0r1g1na1 passw0rd",
+ ));
+}
+
+function remove_dummy_data($link) {
+ ldap_delete($link, "cn=userC,cn=userB,dc=my-domain,dc=com");
+ ldap_delete($link, "cn=userA,dc=my-domain,dc=com");
+ ldap_delete($link, "cn=userB,dc=my-domain,dc=com");
+ ldap_delete($link, "dc=my-domain,dc=com");
+}
+?>
diff --git a/ext/ldap/tests/ldap_add_basic.phpt b/ext/ldap/tests/ldap_add_basic.phpt
new file mode 100644
index 0000000..ca65e49
--- /dev/null
+++ b/ext/ldap/tests/ldap_add_basic.phpt
@@ -0,0 +1,83 @@
+--TEST--
+ldap_add() - Basic add operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+var_dump(
+ ldap_add($link, "dc=my-domain,dc=com", array(
+ "objectClass" => array(
+ "top",
+ "dcObject",
+ "organization"),
+ "dc" => "my-domain",
+ "o" => "my-domain",
+ )),
+ ldap_get_entries(
+ $link,
+ ldap_search($link, "dc=my-domain,dc=com", "(o=my-domain)")
+ )
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+ldap_delete($link, "dc=my-domain,dc=com");
+?>
+--EXPECT--
+bool(true)
+array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ array(8) {
+ ["objectclass"]=>
+ array(4) {
+ ["count"]=>
+ int(3)
+ [0]=>
+ string(3) "top"
+ [1]=>
+ string(8) "dcObject"
+ [2]=>
+ string(12) "organization"
+ }
+ [0]=>
+ string(11) "objectclass"
+ ["dc"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(9) "my-domain"
+ }
+ [1]=>
+ string(2) "dc"
+ ["o"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(9) "my-domain"
+ }
+ [2]=>
+ string(1) "o"
+ ["count"]=>
+ int(3)
+ ["dn"]=>
+ string(19) "dc=my-domain,dc=com"
+ }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_add_error.phpt b/ext/ldap/tests/ldap_add_error.phpt
new file mode 100644
index 0000000..d17db6b
--- /dev/null
+++ b/ext/ldap/tests/ldap_add_error.phpt
@@ -0,0 +1,136 @@
+--TEST--
+ldap_add() - Add operation that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+// Too few parameters
+var_dump(ldap_add());
+var_dump(ldap_add($link));
+var_dump(ldap_add($link, "dc=my-domain,dc=com"));
+
+// Too many parameters
+var_dump(ldap_add($link, "dc=my-domain,dc=com", array(), "Additional data"));
+
+var_dump(ldap_add($link, "dc=my-domain,dc=com", array()));
+
+// Invalid DN
+var_dump(
+ ldap_add($link, "weirdAttribute=val", array(
+ "weirdAttribute" => "val",
+ )),
+ ldap_error($link),
+ ldap_errno($link)
+);
+
+// Duplicate entry
+for ($i = 0; $i < 2; $i++)
+ var_dump(
+ ldap_add($link, "dc=my-domain,dc=com", array(
+ "objectClass" => array(
+ "top",
+ "dcObject",
+ "organization"),
+ "dc" => "my-domain",
+ "o" => "my-domain",
+ ))
+ );
+var_dump(ldap_error($link), ldap_errno($link));
+
+// Wrong array indexes
+var_dump(
+ ldap_add($link, "dc=my-domain2,dc=com", array(
+ "objectClass" => array(
+ 0 => "top",
+ 2 => "dcObject",
+ 5 => "organization"),
+ "dc" => "my-domain",
+ "o" => "my-domain",
+ ))
+ /* Is this correct behaviour to still have "Already exists" as error/errno?
+ ,
+ ldap_error($link),
+ ldap_errno($link)
+ */
+);
+
+// Invalid attribute
+var_dump(
+ ldap_add($link, "dc=my-domain,dc=com", array(
+ "objectClass" => array(
+ "top",
+ "dcObject",
+ "organization"),
+ "dc" => "my-domain",
+ "o" => "my-domain",
+ "weirdAttr" => "weirdVal",
+ )),
+ ldap_error($link),
+ ldap_errno($link)
+);
+
+var_dump(
+ ldap_add($link, "dc=my-domain,dc=com", array(array( "Oops"
+ )))
+ /* Is this correct behaviour to still have "Undefined attribute type" as error/errno?
+ ,
+ ldap_error($link),
+ ldap_errno($link)
+ */
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+ldap_delete($link, "dc=my-domain,dc=com");
+?>
+--EXPECTF--
+Warning: ldap_add() expects exactly 3 parameters, 0 given in %s on line %d
+NULL
+
+Warning: ldap_add() expects exactly 3 parameters, 1 given in %s on line %d
+NULL
+
+Warning: ldap_add() expects exactly 3 parameters, 2 given in %s on line %d
+NULL
+
+Warning: ldap_add() expects exactly 3 parameters, 4 given in %s on line %d
+NULL
+
+Warning: ldap_add(): Add: Protocol error in %s on line %d
+bool(false)
+
+Warning: ldap_add(): Add: Invalid DN syntax in %s on line %d
+bool(false)
+string(17) "Invalid DN syntax"
+int(34)
+bool(true)
+
+Warning: ldap_add(): Add: Already exists in %s on line %d
+bool(false)
+string(14) "Already exists"
+int(68)
+
+Warning: ldap_add(): Value array must have consecutive indices 0, 1, ... in %s on line %d
+bool(false)
+
+Warning: ldap_add(): Add: Undefined attribute type in %s on line %d
+bool(false)
+string(24) "Undefined attribute type"
+int(17)
+
+Warning: ldap_add(): Unknown attribute in the data in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_bind_basic.phpt b/ext/ldap/tests/ldap_bind_basic.phpt
new file mode 100644
index 0000000..b0babae
--- /dev/null
+++ b/ext/ldap/tests/ldap_bind_basic.phpt
@@ -0,0 +1,20 @@
+--TEST--
+ldap_bind() - Basic anonymous binding
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once dirname(__FILE__) .'/skipif.inc'; ?>
+<?php require_once dirname(__FILE__) .'/skipifbindfailure.inc'; ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+var_dump(ldap_bind($link));
+?>
+===DONE===
+--EXPECT--
+bool(true)
+===DONE===
diff --git a/ext/ldap/tests/ldap_bind_error.phpt b/ext/ldap/tests/ldap_bind_error.phpt
new file mode 100644
index 0000000..a569ce6
--- /dev/null
+++ b/ext/ldap/tests/ldap_bind_error.phpt
@@ -0,0 +1,35 @@
+--TEST--
+ldap_bind() - Binding that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+
+// Invalid parameter count
+var_dump(ldap_bind($link, $user, $passwd, null));
+
+// Invalid password
+var_dump(ldap_bind($link, $user, "ThisIsNotCorrect$passwd"));
+
+// Invalid DN syntax
+var_dump(ldap_bind($link, "unexistingProperty=weirdValue,$user", $passwd));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_bind() expects at most 3 parameters, 4 given in %s on line %d
+bool(false)
+
+Warning: ldap_bind(): Unable to bind to server: Invalid credentials in %s on line %d
+bool(false)
+
+Warning: ldap_bind(): Unable to bind to server: Invalid DN syntax in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_bind_variation.phpt b/ext/ldap/tests/ldap_bind_variation.phpt
new file mode 100644
index 0000000..24102f7
--- /dev/null
+++ b/ext/ldap/tests/ldap_bind_variation.phpt
@@ -0,0 +1,20 @@
+--TEST--
+ldap_bind() - Advanced binding
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once dirname(__FILE__) .'/skipif.inc'; ?>
+<?php require_once dirname(__FILE__) .'/skipifbindfailure.inc'; ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+var_dump(ldap_bind($link, $user, $passwd));
+?>
+===DONE===
+--EXPECT--
+bool(true)
+===DONE===
diff --git a/ext/ldap/tests/ldap_compare_basic.phpt b/ext/ldap/tests/ldap_compare_basic.phpt
new file mode 100644
index 0000000..b0c5e97
--- /dev/null
+++ b/ext/ldap/tests/ldap_compare_basic.phpt
@@ -0,0 +1,31 @@
+--TEST--
+ldap_compare() - Basic ldap_compare test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+var_dump(
+ ldap_compare($link, "cn=userA,dc=my-domain,dc=com", "sn", "testSN1"),
+ ldap_compare($link, "cn=userA,dc=my-domain,dc=com", "telephoneNumber", "yy-yy-yy-yy-yy")
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECT--
+bool(true)
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_compare_error.phpt b/ext/ldap/tests/ldap_compare_error.phpt
new file mode 100644
index 0000000..2812757
--- /dev/null
+++ b/ext/ldap/tests/ldap_compare_error.phpt
@@ -0,0 +1,55 @@
+--TEST--
+ldap_compare() - Testing ldap_compare() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+// Too few parameters
+var_dump(ldap_compare($link));
+var_dump(ldap_compare($link, $link));
+var_dump(ldap_compare($link, $link, $link));
+
+// Too many parameters
+var_dump(ldap_compare($link, $link, $link, $link, "Additional data"));
+
+var_dump(
+ ldap_compare($link, "cn=userNotAvailable,dc=my-domain,dc=com", "sn", "testSN1"),
+ ldap_error($link),
+ ldap_errno($link)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+Warning: ldap_compare() expects exactly 4 parameters, 1 given in %s on line %d
+NULL
+
+Warning: ldap_compare() expects exactly 4 parameters, 2 given in %s on line %d
+NULL
+
+Warning: ldap_compare() expects exactly 4 parameters, 3 given in %s on line %d
+NULL
+
+Warning: ldap_compare() expects exactly 4 parameters, 5 given in %s on line %d
+NULL
+
+Warning: ldap_compare(): Compare: No such object in %s on line %d
+int(-1)
+string(14) "No such object"
+int(32)
+===DONE===
diff --git a/ext/ldap/tests/ldap_connect_basic.phpt b/ext/ldap/tests/ldap_connect_basic.phpt
new file mode 100644
index 0000000..26133a6
--- /dev/null
+++ b/ext/ldap/tests/ldap_connect_basic.phpt
@@ -0,0 +1,18 @@
+--TEST--
+ldap_connect() - Basic connection
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump($link);
+?>
+===DONE===
+--EXPECTF--
+resource(%d) of type (ldap link)
+===DONE===
diff --git a/ext/ldap/tests/ldap_connect_error.phpt b/ext/ldap/tests/ldap_connect_error.phpt
new file mode 100644
index 0000000..fa28fcf
--- /dev/null
+++ b/ext/ldap/tests/ldap_connect_error.phpt
@@ -0,0 +1,31 @@
+--TEST--
+ldap_connect() - Connection errors
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--INI--
+ldap.max_links=1
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+// too many arguments
+var_dump(ldap_connect(null, null, null));
+var_dump(ldap_connect("ldap://$host:$port/dc=my-domain,dc=com"));
+
+$links = array();
+$links[0] = ldap_connect($host, $port);
+$links[1] = ldap_connect($host, $port);
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_connect() expects at most 2 parameters, 3 given in %s on line %d
+bool(false)
+
+Warning: ldap_connect(): Could not create session handle: %s in %s on line %d
+bool(false)
+
+Warning: ldap_connect(): Too many open links (1) in %s on line %d
+===DONE===
diff --git a/ext/ldap/tests/ldap_connect_variation.phpt b/ext/ldap/tests/ldap_connect_variation.phpt
new file mode 100644
index 0000000..09b07e7
--- /dev/null
+++ b/ext/ldap/tests/ldap_connect_variation.phpt
@@ -0,0 +1,39 @@
+--TEST--
+ldap_connect() - Variation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+// no hostname, no port
+$link = ldap_connect();
+var_dump($link);
+
+// no port
+$link = ldap_connect($host);
+var_dump($link);
+
+// URI
+$link = ldap_connect("ldap://$host:$port");
+var_dump($link);
+
+// URI no port
+$link = ldap_connect("ldap://$host");
+var_dump($link);
+
+// bad hostname (connect should work, not bind)
+$link = ldap_connect("nonexistent" . $host);
+var_dump($link);
+?>
+===DONE===
+--EXPECTF--
+resource(%d) of type (ldap link)
+resource(%d) of type (ldap link)
+resource(%d) of type (ldap link)
+resource(%d) of type (ldap link)
+resource(%d) of type (ldap link)
+===DONE===
diff --git a/ext/ldap/tests/ldap_control_paged_results_variation1.phpt b/ext/ldap/tests/ldap_control_paged_results_variation1.phpt
new file mode 100644
index 0000000..0e89446
--- /dev/null
+++ b/ext/ldap/tests/ldap_control_paged_results_variation1.phpt
@@ -0,0 +1,56 @@
+--TEST--
+ldap_ldap_control_paged_result() test (fetching the first page)
+--CREDITS--
+Jean-Sebastien Hedde <jeanseb@au-fil-du.net>
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$dn = "dc=my-domain,dc=com";
+$filter = "(cn=*)";
+var_dump(
+ ldap_control_paged_result($link, 1),
+ $result = ldap_search($link, $dn, $filter, array('cn')),
+ ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+bool(true)
+resource(6) of type (ldap result)
+array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ array(4) {
+ ["cn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(5) "userA"
+ }
+ [0]=>
+ string(2) "cn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+ }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_control_paged_results_variation2.phpt b/ext/ldap/tests/ldap_control_paged_results_variation2.phpt
new file mode 100644
index 0000000..fee43fc
--- /dev/null
+++ b/ext/ldap/tests/ldap_control_paged_results_variation2.phpt
@@ -0,0 +1,72 @@
+--TEST--
+ldap_ldap_control_paged_result() test (fetching the first page with a pagesize=2)
+--CREDITS--
+Jean-Sebastien Hedde <jeanseb@au-fil-du.net>
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$dn = "dc=my-domain,dc=com";
+$filter = "(cn=*)";
+var_dump(
+ ldap_control_paged_result($link, 2),
+ $result = ldap_search($link, $dn, $filter, array('cn')),
+ ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+bool(true)
+resource(6) of type (ldap result)
+array(3) {
+ ["count"]=>
+ int(2)
+ [0]=>
+ array(4) {
+ ["cn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(5) "userA"
+ }
+ [0]=>
+ string(2) "cn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+ }
+ [1]=>
+ array(4) {
+ ["cn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(5) "userB"
+ }
+ [0]=>
+ string(2) "cn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(28) "cn=userB,dc=my-domain,dc=com"
+ }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_control_paged_results_variation3.phpt b/ext/ldap/tests/ldap_control_paged_results_variation3.phpt
new file mode 100644
index 0000000..43a68ae
--- /dev/null
+++ b/ext/ldap/tests/ldap_control_paged_results_variation3.phpt
@@ -0,0 +1,100 @@
+--TEST--
+ldap_ldap_control_paged_result() test (fetching the first page then the next final page)
+--CREDITS--
+Jean-Sebastien Hedde <jeanseb@au-fil-du.net>
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$dn = "dc=my-domain,dc=com";
+$filter = "(cn=*)";
+$cookie = '';
+var_dump(
+ ldap_control_paged_result($link, 2, true, $cookie),
+ $result = ldap_search($link, $dn, $filter, array('cn')),
+ ldap_get_entries($link, $result),
+ ldap_control_paged_result_response($link, $result, $cookie),
+ ldap_control_paged_result($link, 20, true, $cookie),
+ $result = ldap_search($link, $dn, $filter, array('cn')),
+ ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+bool(true)
+resource(%d) of type (ldap result)
+array(3) {
+ ["count"]=>
+ int(2)
+ [0]=>
+ array(4) {
+ ["cn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(5) "userA"
+ }
+ [0]=>
+ string(2) "cn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+ }
+ [1]=>
+ array(4) {
+ ["cn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(5) "userB"
+ }
+ [0]=>
+ string(2) "cn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(28) "cn=userB,dc=my-domain,dc=com"
+ }
+}
+bool(true)
+bool(true)
+resource(%d) of type (ldap result)
+array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ array(4) {
+ ["cn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(5) "userC"
+ }
+ [0]=>
+ string(2) "cn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(37) "cn=userC,cn=userB,dc=my-domain,dc=com"
+ }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_count_entries_basic.phpt b/ext/ldap/tests/ldap_count_entries_basic.phpt
new file mode 100644
index 0000000..a03f059
--- /dev/null
+++ b/ext/ldap/tests/ldap_count_entries_basic.phpt
@@ -0,0 +1,28 @@
+--TEST--
+ldap_count_entries() - Basic counting LDAP entries
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=person)");
+var_dump(ldap_count_entries($link, $result));
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECT--
+int(3)
+===DONE===
diff --git a/ext/ldap/tests/ldap_count_entries_error.phpt b/ext/ldap/tests/ldap_count_entries_error.phpt
new file mode 100644
index 0000000..552625a
--- /dev/null
+++ b/ext/ldap/tests/ldap_count_entries_error.phpt
@@ -0,0 +1,23 @@
+--TEST--
+ldap_count_entries() - Testing counting LDAP entries that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_count_entries($link));
+var_dump(ldap_count_entries($link, $link));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_count_entries() expects exactly 2 parameters, 1 given in %s on line %d
+NULL
+
+Warning: ldap_count_entries(): supplied resource is not a valid ldap result resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_delete_basic.phpt b/ext/ldap/tests/ldap_delete_basic.phpt
new file mode 100644
index 0000000..1457384
--- /dev/null
+++ b/ext/ldap/tests/ldap_delete_basic.phpt
@@ -0,0 +1,40 @@
+--TEST--
+ldap_delete() - Basic delete operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+ldap_add($link, "dc=my-domain,dc=com", array(
+ "objectClass" => array(
+ "top",
+ "dcObject",
+ "organization"),
+ "dc" => "my-domain",
+ "o" => "my-domain",
+));
+
+var_dump(
+ ldap_delete($link, "dc=my-domain,dc=com"),
+ @ldap_search($link, "dc=my-domain,dc=com", "(o=my-domain)")
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+ldap_delete($link, "dc=my-domain,dc=com");
+?>
+--EXPECT--
+bool(true)
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_delete_error.phpt b/ext/ldap/tests/ldap_delete_error.phpt
new file mode 100644
index 0000000..6ef997b
--- /dev/null
+++ b/ext/ldap/tests/ldap_delete_error.phpt
@@ -0,0 +1,62 @@
+--TEST--
+ldap_delete() - Delete operation that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+// Too few parameters
+var_dump(ldap_delete());
+var_dump(ldap_delete($link));
+
+// Too many parameters
+var_dump(ldap_delete($link, "dc=my-domain,dc=com", "Additional data"));
+
+// Invalid DN
+var_dump(
+ ldap_delete($link, "weirdAttribute=val"),
+ ldap_error($link),
+ ldap_errno($link)
+);
+
+// Deleting unexisting data
+var_dump(
+ ldap_delete($link, "dc=my-domain,dc=com"),
+ ldap_error($link),
+ ldap_errno($link)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+?>
+--EXPECTF--
+Warning: ldap_delete() expects exactly 2 parameters, 0 given in %s on line %d
+NULL
+
+Warning: ldap_delete() expects exactly 2 parameters, 1 given in %s on line %d
+NULL
+
+Warning: ldap_delete() expects exactly 2 parameters, 3 given in %s on line %d
+NULL
+
+Warning: ldap_delete(): Delete: Invalid DN syntax in %s on line %d
+bool(false)
+string(17) "Invalid DN syntax"
+int(34)
+
+Warning: ldap_delete(): Delete: No such object in %s on line %d
+bool(false)
+string(14) "No such object"
+int(32)
+===DONE===
diff --git a/ext/ldap/tests/ldap_dn2ufn.phpt b/ext/ldap/tests/ldap_dn2ufn.phpt
new file mode 100644
index 0000000..8082e97
--- /dev/null
+++ b/ext/ldap/tests/ldap_dn2ufn.phpt
@@ -0,0 +1,33 @@
+--TEST--
+ldap_dn2ufn() test
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+
+/* Convert valid DN */
+var_dump(ldap_dn2ufn("cn=bob,dc=example,dc=com"));
+
+/* Convert valid DN */
+var_dump(ldap_dn2ufn("cn=bob,ou=users,dc=example,dc=com"));
+
+/* Convert DN with < > characters */
+var_dump(ldap_dn2ufn("cn=<bob>,dc=example,dc=com"));
+
+/* Too many parameters */
+ldap_dn2ufn("cn=bob,dc=example,dc=com", 1);
+
+/* Bad DN value */
+var_dump(ldap_dn2ufn("bob,dc=example,dc=com"));
+
+echo "Done\n";
+
+?>
+--EXPECTF--
+string(16) "bob, example.com"
+string(23) "bob, users, example.com"
+bool(false)
+
+Warning: ldap_dn2ufn() expects exactly 1 parameter, 2 given in %s on line %d
+bool(false)
+Done
diff --git a/ext/ldap/tests/ldap_err2str_basic.phpt b/ext/ldap/tests/ldap_err2str_basic.phpt
new file mode 100644
index 0000000..0ecad03
--- /dev/null
+++ b/ext/ldap/tests/ldap_err2str_basic.phpt
@@ -0,0 +1,15 @@
+--TEST--
+ldap_err2str() - Basic error number to string conversion
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+var_dump(ldap_err2str(2));
+?>
+===DONE===
+--EXPECT--
+string(14) "Protocol error"
+===DONE===
diff --git a/ext/ldap/tests/ldap_err2str_error.phpt b/ext/ldap/tests/ldap_err2str_error.phpt
new file mode 100644
index 0000000..0f768d2
--- /dev/null
+++ b/ext/ldap/tests/ldap_err2str_error.phpt
@@ -0,0 +1,28 @@
+--TEST--
+ldap_err2str() - Incorrect usage of number to string conversion
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+// Too few args
+var_dump(ldap_err2str());
+
+// Too many args
+var_dump(ldap_err2str(1, "Additional data"));
+
+var_dump(ldap_err2str("weird"));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_err2str() expects exactly 1 parameter, 0 given in %s on line %d
+NULL
+
+Warning: ldap_err2str() expects exactly 1 parameter, 2 given in %s on line %d
+NULL
+
+Warning: ldap_err2str() expects parameter 1 to be long, %unicode_string_optional% given in %s on line %d
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_errno_basic.phpt b/ext/ldap/tests/ldap_errno_basic.phpt
new file mode 100644
index 0000000..4b02ac6
--- /dev/null
+++ b/ext/ldap/tests/ldap_errno_basic.phpt
@@ -0,0 +1,30 @@
+--TEST--
+ldap_errno() - Basic ldap_errno() operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+@ldap_add($link, "badDN dc=my-domain,dc=com", array(
+ "objectClass" => array(
+ "top",
+ "dcObject",
+ "organization"),
+ "dc" => "my-domain",
+ "o" => "my-domain",
+));
+
+var_dump(
+ ldap_errno($link)
+);
+?>
+===DONE===
+--EXPECT--
+int(34)
+===DONE===
diff --git a/ext/ldap/tests/ldap_errno_error.phpt b/ext/ldap/tests/ldap_errno_error.phpt
new file mode 100644
index 0000000..a05876c
--- /dev/null
+++ b/ext/ldap/tests/ldap_errno_error.phpt
@@ -0,0 +1,23 @@
+--TEST--
+ldap_errno() - ldap_errno() operation that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+// Too few parameters
+var_dump(ldap_errno());
+
+// Too many parameters
+var_dump(ldap_errno(null, null));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_errno() expects exactly 1 parameter, 0 given in %s on line %d
+NULL
+
+Warning: ldap_errno() expects exactly 1 parameter, 2 given in %s on line %d
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_error_basic.phpt b/ext/ldap/tests/ldap_error_basic.phpt
new file mode 100644
index 0000000..64e4ef6
--- /dev/null
+++ b/ext/ldap/tests/ldap_error_basic.phpt
@@ -0,0 +1,30 @@
+--TEST--
+ldap_error() - Basic ldap_error() operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+@ldap_add($link, "badDN dc=my-domain,dc=com", array(
+ "objectClass" => array(
+ "top",
+ "dcObject",
+ "organization"),
+ "dc" => "my-domain",
+ "o" => "my-domain",
+));
+
+var_dump(
+ ldap_error($link)
+);
+?>
+===DONE===
+--EXPECT--
+string(17) "Invalid DN syntax"
+===DONE===
diff --git a/ext/ldap/tests/ldap_error_error.phpt b/ext/ldap/tests/ldap_error_error.phpt
new file mode 100644
index 0000000..e74eacf
--- /dev/null
+++ b/ext/ldap/tests/ldap_error_error.phpt
@@ -0,0 +1,23 @@
+--TEST--
+ldap_error() - ldap_error() operation that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+// Too few parameters
+var_dump(ldap_error());
+
+// Too many parameters
+var_dump(ldap_error(null, null));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_error() expects exactly 1 parameter, 0 given in %s on line %d
+NULL
+
+Warning: ldap_error() expects exactly 1 parameter, 2 given in %s on line %d
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_explode_dn.phpt b/ext/ldap/tests/ldap_explode_dn.phpt
new file mode 100644
index 0000000..2337ac9
--- /dev/null
+++ b/ext/ldap/tests/ldap_explode_dn.phpt
@@ -0,0 +1,94 @@
+--TEST--
+ldap_explode_dn() test
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+
+/* Explode with attributes */
+var_dump(ldap_explode_dn("cn=bob,dc=example,dc=com", 0));
+
+/* Explode with attributes */
+var_dump(ldap_explode_dn("cn=bob,ou=users,dc=example,dc=com", 0));
+
+/* Explode without attributes */
+var_dump(ldap_explode_dn("cn=bob,dc=example,dc=com", 1));
+
+/* Explode without attributes */
+var_dump(ldap_explode_dn("cn=bob,ou=users,dc=example,dc=com", 1));
+
+/* Explode with attributes and < > characters */
+var_dump(ldap_explode_dn("cn=<bob>,dc=example,dc=com", 0));
+
+/* Explode without attributes and < > characters */
+var_dump(ldap_explode_dn("cn=<bob>,dc=example,dc=com", 1));
+
+/* Too few parameters */
+ldap_explode_dn("cn=bob,dc=example,dc=com");
+
+/* Too many parameters */
+ldap_explode_dn("cn=bob,dc=example,dc=com", 1, 1);
+
+/* Bad DN value with attributes */
+var_dump(ldap_explode_dn("bob,dc=example,dc=com", 0));
+
+/* Bad DN value without attributes */
+var_dump(ldap_explode_dn("bob,dc=example,dc=com", 1));
+
+echo "Done\n";
+
+?>
+--EXPECTF--
+array(4) {
+ ["count"]=>
+ int(3)
+ [0]=>
+ string(6) "cn=bob"
+ [1]=>
+ string(10) "dc=example"
+ [2]=>
+ string(6) "dc=com"
+}
+array(5) {
+ ["count"]=>
+ int(4)
+ [0]=>
+ string(6) "cn=bob"
+ [1]=>
+ string(8) "ou=users"
+ [2]=>
+ string(10) "dc=example"
+ [3]=>
+ string(6) "dc=com"
+}
+array(4) {
+ ["count"]=>
+ int(3)
+ [0]=>
+ string(3) "bob"
+ [1]=>
+ string(7) "example"
+ [2]=>
+ string(3) "com"
+}
+array(5) {
+ ["count"]=>
+ int(4)
+ [0]=>
+ string(3) "bob"
+ [1]=>
+ string(5) "users"
+ [2]=>
+ string(7) "example"
+ [3]=>
+ string(3) "com"
+}
+bool(false)
+bool(false)
+
+Warning: ldap_explode_dn() expects exactly 2 parameters, 1 given in %s on line %d
+
+Warning: ldap_explode_dn() expects exactly 2 parameters, 3 given in %s on line %d
+bool(false)
+bool(false)
+Done
diff --git a/ext/ldap/tests/ldap_first_attribute_basic.phpt b/ext/ldap/tests/ldap_first_attribute_basic.phpt
new file mode 100644
index 0000000..8e506fa
--- /dev/null
+++ b/ext/ldap/tests/ldap_first_attribute_basic.phpt
@@ -0,0 +1,31 @@
+--TEST--
+ldap_first_attribute() - Basic ldap_first_attribute test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=organization)");
+$entry = ldap_first_entry($link, $result);
+var_dump(
+ ldap_first_attribute($link, $entry)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECT--
+string(11) "objectClass"
+===DONE===
diff --git a/ext/ldap/tests/ldap_first_attribute_error.phpt b/ext/ldap/tests/ldap_first_attribute_error.phpt
new file mode 100644
index 0000000..f7016c5
--- /dev/null
+++ b/ext/ldap/tests/ldap_first_attribute_error.phpt
@@ -0,0 +1,23 @@
+--TEST--
+ldap_first_attribute() - Testing ldap_first_attribute() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_first_attribute($link));
+var_dump(ldap_first_attribute($link, $link));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_first_attribute() expects %s 2 parameters, 1 given in %s on line %d
+NULL
+
+Warning: ldap_first_attribute(): supplied resource is not a valid ldap result entry resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_first_entry_basic.phpt b/ext/ldap/tests/ldap_first_entry_basic.phpt
new file mode 100644
index 0000000..9b65822
--- /dev/null
+++ b/ext/ldap/tests/ldap_first_entry_basic.phpt
@@ -0,0 +1,37 @@
+--TEST--
+ldap_first_entry() - Basic ldap_first_entry test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=person)");
+var_dump(
+ $entry = ldap_first_entry($link, $result),
+ ldap_get_values($link, $entry, 'sn')
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+resource(%d) of type (ldap result entry)
+array(2) {
+ [0]=>
+ string(7) "testSN%d"
+ ["count"]=>
+ int(1)
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_first_entry_error.phpt b/ext/ldap/tests/ldap_first_entry_error.phpt
new file mode 100644
index 0000000..9f232e0
--- /dev/null
+++ b/ext/ldap/tests/ldap_first_entry_error.phpt
@@ -0,0 +1,27 @@
+--TEST--
+ldap_first_entry() - Testing ldap_first_entry() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_first_entry($link));
+var_dump(ldap_first_entry($link, $link, "Additional data"));
+var_dump(ldap_first_entry($link, $link));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_first_entry() expects exactly 2 parameters, 1 given in %s on line %d
+NULL
+
+Warning: ldap_first_entry() expects exactly 2 parameters, 3 given in %s on line %d
+NULL
+
+Warning: ldap_first_entry(): supplied resource is not a valid ldap result resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_first_reference_basic.phpt b/ext/ldap/tests/ldap_first_reference_basic.phpt
new file mode 100644
index 0000000..d783489
--- /dev/null
+++ b/ext/ldap/tests/ldap_first_reference_basic.phpt
@@ -0,0 +1,43 @@
+--TEST--
+ldap_first_reference() - Basic ldap_first_reference test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+ldap_add($link, "cn=userref,dc=my-domain,dc=com", array(
+ "objectClass" => array("extensibleObject", "referral"),
+ "cn" => "userref",
+ "ref" => "cn=userA,dc=my-domain,dc=com",
+));
+ldap_set_option($link, LDAP_OPT_DEREF, LDAP_DEREF_NEVER);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(cn=*)");
+var_dump($ref = ldap_first_reference($link, $result));
+$refs = null;
+ldap_parse_reference($link, $ref, $refs);
+var_dump($refs);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+// Referral can only be removed with Manage DSA IT Control
+ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, array(array("oid" => "2.16.840.1.113730.3.4.2")));
+ldap_delete($link, "cn=userref,dc=my-domain,dc=com");
+remove_dummy_data($link);
+?>
+--EXPECTF--
+resource(%d) of type (ldap result entry)
+array(1) {
+ [0]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_first_reference_error.phpt b/ext/ldap/tests/ldap_first_reference_error.phpt
new file mode 100644
index 0000000..d5541e1
--- /dev/null
+++ b/ext/ldap/tests/ldap_first_reference_error.phpt
@@ -0,0 +1,27 @@
+--TEST--
+ldap_first_reference() - Testing ldap_first_reference() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_first_reference($link));
+var_dump(ldap_first_reference($link, $link, "Additional data"));
+var_dump(ldap_first_reference($link, $link));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_first_reference() expects exactly 2 parameters, 1 given in %s on line %d
+NULL
+
+Warning: ldap_first_reference() expects exactly 2 parameters, 3 given in %s on line %d
+NULL
+
+Warning: ldap_first_reference(): supplied resource is not a valid ldap result resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_free_result_basic.phpt b/ext/ldap/tests/ldap_free_result_basic.phpt
new file mode 100644
index 0000000..33e47d6
--- /dev/null
+++ b/ext/ldap/tests/ldap_free_result_basic.phpt
@@ -0,0 +1,28 @@
+--TEST--
+ldap_free_result() - Basic ldap_free_result tests
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=person)");
+var_dump(ldap_free_result($result));
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECT--
+bool(true)
+===DONE===
diff --git a/ext/ldap/tests/ldap_free_result_error.phpt b/ext/ldap/tests/ldap_free_result_error.phpt
new file mode 100644
index 0000000..05623d6
--- /dev/null
+++ b/ext/ldap/tests/ldap_free_result_error.phpt
@@ -0,0 +1,23 @@
+--TEST--
+ldap_free_result() - Testing ldap_free_result() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_free_result($link));
+var_dump(ldap_free_result($link, "Additional data"));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_free_result(): supplied resource is not a valid ldap result resource in %s on line %d
+bool(false)
+
+Warning: ldap_free_result() expects exactly 1 parameter, 2 given in %s on line %d
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_attributes_basic.phpt b/ext/ldap/tests/ldap_get_attributes_basic.phpt
new file mode 100644
index 0000000..82074c5
--- /dev/null
+++ b/ext/ldap/tests/ldap_get_attributes_basic.phpt
@@ -0,0 +1,65 @@
+--TEST--
+ldap_get_attributes() - Basic ldap_get_attributes test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=organization)");
+$entry = ldap_first_entry($link, $result);
+var_dump(
+ ldap_get_attributes($link, $entry)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECT--
+array(7) {
+ ["objectClass"]=>
+ array(4) {
+ ["count"]=>
+ int(3)
+ [0]=>
+ string(3) "top"
+ [1]=>
+ string(8) "dcObject"
+ [2]=>
+ string(12) "organization"
+ }
+ [0]=>
+ string(11) "objectClass"
+ ["dc"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(9) "my-domain"
+ }
+ [1]=>
+ string(2) "dc"
+ ["o"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(9) "my-domain"
+ }
+ [2]=>
+ string(1) "o"
+ ["count"]=>
+ int(3)
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_attributes_error.phpt b/ext/ldap/tests/ldap_get_attributes_error.phpt
new file mode 100644
index 0000000..465ba4f
--- /dev/null
+++ b/ext/ldap/tests/ldap_get_attributes_error.phpt
@@ -0,0 +1,23 @@
+--TEST--
+ldap_get_attributes() - Testing ldap_get_attributes() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_get_attributes($link));
+var_dump(ldap_get_attributes($link, $link));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_get_attributes() expects exactly 2 parameters, 1 given in %s on line %d
+NULL
+
+Warning: ldap_get_attributes(): supplied resource is not a valid ldap result entry resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_dn_basic.phpt b/ext/ldap/tests/ldap_get_dn_basic.phpt
new file mode 100644
index 0000000..e70e7bf
--- /dev/null
+++ b/ext/ldap/tests/ldap_get_dn_basic.phpt
@@ -0,0 +1,31 @@
+--TEST--
+ldap_get_dn() - Basic ldap_get_dn test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=organization)");
+$entry = ldap_first_entry($link, $result);
+var_dump(
+ ldap_get_dn($link, $entry)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECT--
+string(19) "dc=my-domain,dc=com"
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_dn_error.phpt b/ext/ldap/tests/ldap_get_dn_error.phpt
new file mode 100644
index 0000000..71df6a3
--- /dev/null
+++ b/ext/ldap/tests/ldap_get_dn_error.phpt
@@ -0,0 +1,23 @@
+--TEST--
+ldap_get_dn() - Testing ldap_get_dn() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_get_dn($link));
+var_dump(ldap_get_dn($link, $link));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_get_dn() expects exactly 2 parameters, 1 given in %s on line %d
+NULL
+
+Warning: ldap_get_dn(): supplied resource is not a valid ldap result entry resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_entries_basic.phpt b/ext/ldap/tests/ldap_get_entries_basic.phpt
new file mode 100644
index 0000000..90dbb26
--- /dev/null
+++ b/ext/ldap/tests/ldap_get_entries_basic.phpt
@@ -0,0 +1,74 @@
+--TEST--
+ldap_get_entries() - Basic modify operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+var_dump(
+ ldap_get_entries(
+ $link,
+ ldap_search($link, "dc=my-domain,dc=com", "(o=my-domain)")
+ )
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECT--
+array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ array(8) {
+ ["objectclass"]=>
+ array(4) {
+ ["count"]=>
+ int(3)
+ [0]=>
+ string(3) "top"
+ [1]=>
+ string(8) "dcObject"
+ [2]=>
+ string(12) "organization"
+ }
+ [0]=>
+ string(11) "objectclass"
+ ["dc"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(9) "my-domain"
+ }
+ [1]=>
+ string(2) "dc"
+ ["o"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(9) "my-domain"
+ }
+ [2]=>
+ string(1) "o"
+ ["count"]=>
+ int(3)
+ ["dn"]=>
+ string(19) "dc=my-domain,dc=com"
+ }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_entries_error.phpt b/ext/ldap/tests/ldap_get_entries_error.phpt
new file mode 100644
index 0000000..b728dd2
--- /dev/null
+++ b/ext/ldap/tests/ldap_get_entries_error.phpt
@@ -0,0 +1,33 @@
+--TEST--
+ldap_get_entries() - ldap_get_entries() operation that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+
+// Too few parameters
+var_dump(ldap_get_entries($link));
+
+// Too many parameters
+var_dump(ldap_get_entries($link, $link, "Additional data"));
+
+// Bad parameter
+var_dump(ldap_get_entries($link, "string"));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_get_entries() expects exactly 2 parameters, 1 given in %s on line %d
+NULL
+
+Warning: ldap_get_entries() expects exactly 2 parameters, 3 given in %s on line %d
+NULL
+
+Warning: ldap_get_entries() expects parameter 2 to be resource, %unicode_string_optional% given in %s on line %d
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_entries_variation.phpt b/ext/ldap/tests/ldap_get_entries_variation.phpt
new file mode 100644
index 0000000..cb0f306
--- /dev/null
+++ b/ext/ldap/tests/ldap_get_entries_variation.phpt
@@ -0,0 +1,36 @@
+--TEST--
+Test ldap_get_entries() function - variation: used on empty search
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+var_dump(
+ ldap_get_entries(
+ $link,
+ ldap_search($link, "dc=my-domain,dc=com", "(o=my-unexisting-domain)")
+ )
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECT--
+array(1) {
+ ["count"]=>
+ int(0)
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_option_basic.phpt b/ext/ldap/tests/ldap_get_option_basic.phpt
new file mode 100644
index 0000000..3136a5a
--- /dev/null
+++ b/ext/ldap/tests/ldap_get_option_basic.phpt
@@ -0,0 +1,25 @@
+--TEST--
+ldap_get_option() - Basic ldap_get_option() operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+$option = null;
+ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+
+var_dump(
+ ldap_get_option($link, LDAP_OPT_PROTOCOL_VERSION, $option),
+ $option
+);
+?>
+===DONE===
+--EXPECT--
+bool(true)
+int(3)
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_option_error.phpt b/ext/ldap/tests/ldap_get_option_error.phpt
new file mode 100644
index 0000000..cf7a0e5
--- /dev/null
+++ b/ext/ldap/tests/ldap_get_option_error.phpt
@@ -0,0 +1,40 @@
+--TEST--
+ldap_get_option() - ldap_get_option() operation that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+$option = null;
+
+// Too few parameters
+var_dump(ldap_get_option());
+var_dump(ldap_get_option($link));
+var_dump(ldap_get_option($link, LDAP_OPT_PROTOCOL_VERSION));
+
+// Too many parameters
+var_dump(
+ ldap_get_option($link, LDAP_OPT_PROTOCOL_VERSION, $option, "Additional data"),
+ $option
+);
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_get_option() expects exactly 3 parameters, 0 given in %s on line %d
+NULL
+
+Warning: ldap_get_option() expects exactly 3 parameters, 1 given in %s on line %d
+NULL
+
+Warning: ldap_get_option() expects exactly 3 parameters, 2 given in %s on line %d
+NULL
+
+Warning: ldap_get_option() expects exactly 3 parameters, 4 given in %s on line %d
+NULL
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_option_variation.phpt b/ext/ldap/tests/ldap_get_option_variation.phpt
new file mode 100644
index 0000000..da71d89
--- /dev/null
+++ b/ext/ldap/tests/ldap_get_option_variation.phpt
@@ -0,0 +1,66 @@
+--TEST--
+ldap_get_option() - More ldap_get_option() operations
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+$option = null;
+
+$controls = array(
+ array("oid" => "1.2.752.58.10.1", "iscritical" => true),
+ array("oid" => "1.2.752.58.1.10", "value" => "magic"),
+);
+
+ldap_set_option($link, LDAP_OPT_DEREF, LDAP_DEREF_NEVER);
+ldap_set_option($link, LDAP_OPT_SIZELIMIT, 123);
+ldap_set_option($link, LDAP_OPT_TIMELIMIT, 33);
+ldap_set_option($link, LDAP_OPT_NETWORK_TIMEOUT, 44);
+ldap_set_option($link, LDAP_OPT_REFERRALS, false);
+ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, $controls);
+ldap_set_option($link, LDAP_OPT_CLIENT_CONTROLS, $controls);
+ldap_set_option($link, LDAP_OPT_RESTART, false);
+
+var_dump(
+ ldap_get_option($link, LDAP_OPT_DEREF, $option),
+ $option,
+ ldap_get_option($link, LDAP_OPT_SIZELIMIT, $option),
+ $option,
+ ldap_get_option($link, LDAP_OPT_TIMELIMIT, $option),
+ $option,
+ ldap_get_option($link, LDAP_OPT_NETWORK_TIMEOUT, $option),
+ $option,
+ ldap_get_option($link, LDAP_OPT_REFERRALS, $option),
+ $option,
+ ldap_get_option($link, LDAP_OPT_RESTART, $option),
+ $option,
+ ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $option),
+ $option,
+ ldap_get_option($link, LDAP_OPT_CLIENT_CONTROLS, $option),
+ $option
+);
+?>
+===DONE===
+--EXPECT--
+bool(true)
+int(0)
+bool(true)
+int(123)
+bool(true)
+int(33)
+bool(true)
+int(44)
+bool(true)
+int(0)
+bool(true)
+int(0)
+bool(false)
+int(0)
+bool(false)
+int(0)
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_values_len_basic.phpt b/ext/ldap/tests/ldap_get_values_len_basic.phpt
new file mode 100644
index 0000000..ed84614
--- /dev/null
+++ b/ext/ldap/tests/ldap_get_values_len_basic.phpt
@@ -0,0 +1,36 @@
+--TEST--
+ldap_get_values_len() - Basic ldap_get_values_len test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=organization)");
+$entry = ldap_first_entry($link, $result);
+var_dump(
+ ldap_get_values_len($link, $entry, "o")
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ string(9) "my-domain"
+ ["count"]=>
+ int(1)
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_values_len_error.phpt b/ext/ldap/tests/ldap_get_values_len_error.phpt
new file mode 100644
index 0000000..8caea14
--- /dev/null
+++ b/ext/ldap/tests/ldap_get_values_len_error.phpt
@@ -0,0 +1,45 @@
+--TEST--
+ldap_get_values_len() - Testing ldap_get_values_len() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=organization)");
+$entry = ldap_first_entry($link, $result);
+
+// Too few parameters
+var_dump(ldap_get_values_len($link));
+var_dump(ldap_get_values_len($link, $entry));
+var_dump(ldap_get_values_len($link, $entry, "weirdAttribute", "Additional data"));
+
+var_dump(ldap_get_values_len($link, $entry, "inexistantAttribute"));
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+Warning: ldap_get_values_len() expects exactly 3 parameters, 1 given in %s on line %d
+NULL
+
+Warning: ldap_get_values_len() expects exactly 3 parameters, 2 given in %s on line %d
+NULL
+
+Warning: ldap_get_values_len() expects exactly 3 parameters, 4 given in %s on line %d
+NULL
+
+Warning: ldap_get_values_len(): Cannot get the value(s) of attribute %s in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_list_basic.phpt b/ext/ldap/tests/ldap_list_basic.phpt
new file mode 100644
index 0000000..1993f30
--- /dev/null
+++ b/ext/ldap/tests/ldap_list_basic.phpt
@@ -0,0 +1,150 @@
+--TEST--
+ldap_list() test
+--CREDITS--
+Davide Mendolia <idaf1er@gmail.com>
+Patrick Allaert <patrickallaert@php.net>
+Belgian PHP Testfest 2009
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+var_dump(
+ $result = ldap_list($link, "dc=my-domain,dc=com", "(objectClass=person)"),
+ ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+resource(%d) of type (ldap result)
+array(3) {
+ ["count"]=>
+ int(2)
+ [0]=>
+ array(14) {
+ ["objectclass"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(6) "person"
+ }
+ [0]=>
+ string(11) "objectclass"
+ ["cn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(5) "userA"
+ }
+ [1]=>
+ string(2) "cn"
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(7) "testSN1"
+ }
+ [2]=>
+ string(2) "sn"
+ ["userpassword"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(4) "oops"
+ }
+ [3]=>
+ string(12) "userpassword"
+ ["telephonenumber"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(14) "xx-xx-xx-xx-xx"
+ }
+ [4]=>
+ string(15) "telephonenumber"
+ ["description"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(6) "user A"
+ }
+ [5]=>
+ string(11) "description"
+ ["count"]=>
+ int(6)
+ ["dn"]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+ }
+ [1]=>
+ array(12) {
+ ["objectclass"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(6) "person"
+ }
+ [0]=>
+ string(11) "objectclass"
+ ["cn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(5) "userB"
+ }
+ [1]=>
+ string(2) "cn"
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(7) "testSN2"
+ }
+ [2]=>
+ string(2) "sn"
+ ["userpassword"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(15) "oopsIDitItAgain"
+ }
+ [3]=>
+ string(12) "userpassword"
+ ["description"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(6) "user B"
+ }
+ [4]=>
+ string(11) "description"
+ ["count"]=>
+ int(5)
+ ["dn"]=>
+ string(28) "cn=userB,dc=my-domain,dc=com"
+ }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_list_error.phpt b/ext/ldap/tests/ldap_list_error.phpt
new file mode 100644
index 0000000..d234d0a
--- /dev/null
+++ b/ext/ldap/tests/ldap_list_error.phpt
@@ -0,0 +1,35 @@
+--TEST--
+ldap_list() - operation that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect($host, $port);
+
+// Too few parameters
+var_dump(ldap_list());
+var_dump(ldap_list($link));
+var_dump(ldap_list($link, $link));
+
+// Too many parameters
+var_dump(ldap_list($link, "dc=my-domain,dc=com", "(objectClass=*)", array(), 0, 0, 0, 0 , "Additional data"));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_list() expects at least 3 parameters, 0 given in %s on line %d
+NULL
+
+Warning: ldap_list() expects at least 3 parameters, 1 given in %s on line %d
+NULL
+
+Warning: ldap_list() expects at least 3 parameters, 2 given in %s on line %d
+NULL
+
+Warning: ldap_list() expects at most 8 parameters, 9 given in %s on line %d
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_mod_add_basic.phpt b/ext/ldap/tests/ldap_mod_add_basic.phpt
new file mode 100644
index 0000000..8c8164c
--- /dev/null
+++ b/ext/ldap/tests/ldap_mod_add_basic.phpt
@@ -0,0 +1,90 @@
+--TEST--
+ldap_mod_add() - Basic modify operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$entry = array(
+ "description" => "Domain description",
+);
+
+var_dump(
+ ldap_mod_add($link, "dc=my-domain,dc=com", $entry),
+ ldap_get_entries(
+ $link,
+ ldap_search($link, "dc=my-domain,dc=com", "(Description=Domain description)")
+ )
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+remove_dummy_data($link);
+?>
+--EXPECT--
+bool(true)
+array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ array(10) {
+ ["objectclass"]=>
+ array(4) {
+ ["count"]=>
+ int(3)
+ [0]=>
+ string(3) "top"
+ [1]=>
+ string(8) "dcObject"
+ [2]=>
+ string(12) "organization"
+ }
+ [0]=>
+ string(11) "objectclass"
+ ["dc"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(9) "my-domain"
+ }
+ [1]=>
+ string(2) "dc"
+ ["o"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(9) "my-domain"
+ }
+ [2]=>
+ string(1) "o"
+ ["description"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(18) "Domain description"
+ }
+ [3]=>
+ string(11) "description"
+ ["count"]=>
+ int(4)
+ ["dn"]=>
+ string(19) "dc=my-domain,dc=com"
+ }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_mod_add_error.phpt b/ext/ldap/tests/ldap_mod_add_error.phpt
new file mode 100644
index 0000000..4ba1ef9
--- /dev/null
+++ b/ext/ldap/tests/ldap_mod_add_error.phpt
@@ -0,0 +1,83 @@
+--TEST--
+ldap_mod_add() - ldap_mod_add() operations that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+// Too few parameters
+var_dump(ldap_mod_add());
+var_dump(ldap_mod_add($link));
+var_dump(ldap_mod_add($link, "dc=my-domain,dc=com"));
+
+// Too many parameters
+var_dump(ldap_mod_add($link, "dc=my-domain,dc=com", array(), "Additional data"));
+
+// DN not found
+var_dump(ldap_mod_add($link, "dc=my-domain,dc=com", array()));
+
+// Invalid DN
+var_dump(ldap_mod_add($link, "weirdAttribute=val", array()));
+
+$entry = array(
+ "objectClass" => array(
+ "top",
+ "dcObject",
+ "organization"),
+ "dc" => "my-domain",
+ "o" => "my-domain",
+);
+
+ldap_add($link, "dc=my-domain,dc=com", $entry);
+
+$entry2 = $entry;
+$entry2["dc"] = "Wrong Domain";
+
+var_dump(ldap_mod_add($link, "dc=my-domain,dc=com", $entry2));
+
+$entry2 = $entry;
+$entry2["weirdAttribute"] = "weirdVal";
+
+var_dump(ldap_mod_add($link, "dc=my-domain,dc=com", $entry2));
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+ldap_delete($link, "dc=my-domain,dc=com");
+?>
+--EXPECTF--
+Warning: ldap_mod_add() expects exactly 3 parameters, 0 given in %s on line %d
+NULL
+
+Warning: ldap_mod_add() expects exactly 3 parameters, 1 given in %s on line %d
+NULL
+
+Warning: ldap_mod_add() expects exactly 3 parameters, 2 given in %s on line %d
+NULL
+
+Warning: ldap_mod_add() expects exactly 3 parameters, 4 given in %s on line %d
+NULL
+
+Warning: ldap_mod_add(): Modify: No such object in %s on line %d
+bool(false)
+
+Warning: ldap_mod_add(): Modify: Invalid DN syntax in %s on line %d
+bool(false)
+
+Warning: ldap_mod_add(): Modify: Type or value exists in %s on line %d
+bool(false)
+
+Warning: ldap_mod_add(): Modify: Undefined attribute type in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_mod_del_basic.phpt b/ext/ldap/tests/ldap_mod_del_basic.phpt
new file mode 100644
index 0000000..c7daba4
--- /dev/null
+++ b/ext/ldap/tests/ldap_mod_del_basic.phpt
@@ -0,0 +1,43 @@
+--TEST--
+ldap_mod_del() - Basic modify operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$entry = array(
+ "description" => "user A"
+);
+
+var_dump(
+ ldap_mod_del($link, "cn=userA,dc=my-domain,dc=com", $entry),
+ ldap_get_entries(
+ $link,
+ ldap_search($link, "dc=my-domain,dc=com", "(description=user A)")
+ )
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+remove_dummy_data($link);
+?>
+--EXPECT--
+bool(true)
+array(1) {
+ ["count"]=>
+ int(0)
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_mod_del_error.phpt b/ext/ldap/tests/ldap_mod_del_error.phpt
new file mode 100644
index 0000000..71bac9f
--- /dev/null
+++ b/ext/ldap/tests/ldap_mod_del_error.phpt
@@ -0,0 +1,62 @@
+--TEST--
+ldap_mod_del() - ldap_mod_del() operations that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+// Too few parameters
+var_dump(ldap_mod_del());
+var_dump(ldap_mod_del($link));
+var_dump(ldap_mod_del($link, "dc=my-domain,dc=com"));
+
+// Too many parameters
+var_dump(ldap_mod_del($link, "dc=my-domain,dc=com", array(), "Additional data"));
+
+// DN not found
+var_dump(ldap_mod_del($link, "dc=my-domain,dc=com", array()));
+
+// Invalid DN
+var_dump(ldap_mod_del($link, "weirdAttribute=val", array()));
+
+// Invalid attributes
+var_dump(ldap_mod_del($link, "dc=my-domain,dc=com", array('dc')));
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+ldap_delete($link, "dc=my-domain,dc=com");
+?>
+--EXPECTF--
+Warning: ldap_mod_del() expects exactly 3 parameters, 0 given in %s on line %d
+NULL
+
+Warning: ldap_mod_del() expects exactly 3 parameters, 1 given in %s on line %d
+NULL
+
+Warning: ldap_mod_del() expects exactly 3 parameters, 2 given in %s on line %d
+NULL
+
+Warning: ldap_mod_del() expects exactly 3 parameters, 4 given in %s on line %d
+NULL
+
+Warning: ldap_mod_del(): Modify: No such object in %s on line %d
+bool(false)
+
+Warning: ldap_mod_del(): Modify: Invalid DN syntax in %s on line %d
+bool(false)
+
+Warning: ldap_mod_del(): Unknown attribute in the data in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_mod_replace_basic.phpt b/ext/ldap/tests/ldap_mod_replace_basic.phpt
new file mode 100644
index 0000000..d1670ec
--- /dev/null
+++ b/ext/ldap/tests/ldap_mod_replace_basic.phpt
@@ -0,0 +1,59 @@
+--TEST--
+ldap_mod_replace() - Basic modify operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$entry = array(
+ "description" => "user X"
+);
+
+var_dump(
+ ldap_mod_replace($link, "cn=userA,dc=my-domain,dc=com", $entry),
+ ldap_get_entries(
+ $link,
+ ldap_search($link, "dc=my-domain,dc=com", "(description=user X)", array("description"))
+ )
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+remove_dummy_data($link);
+?>
+--EXPECT--
+bool(true)
+array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ array(4) {
+ ["description"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(6) "user X"
+ }
+ [0]=>
+ string(11) "description"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+ }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_mod_replace_error.phpt b/ext/ldap/tests/ldap_mod_replace_error.phpt
new file mode 100644
index 0000000..0409e3e
--- /dev/null
+++ b/ext/ldap/tests/ldap_mod_replace_error.phpt
@@ -0,0 +1,62 @@
+--TEST--
+ldap_mod_replace() - ldap_mod_replace() operations that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+// Too few parameters
+var_dump(ldap_mod_replace());
+var_dump(ldap_mod_replace($link));
+var_dump(ldap_mod_replace($link, "dc=my-domain,dc=com"));
+
+// Too many parameters
+var_dump(ldap_mod_replace($link, "dc=my-domain,dc=com", array(), "Additional data"));
+
+// DN not found
+var_dump(ldap_mod_replace($link, "dc=my-domain,dc=com", array()));
+
+// Invalid DN
+var_dump(ldap_mod_replace($link, "weirdAttribute=val", array()));
+
+// Invalid attributes
+var_dump(ldap_mod_replace($link, "dc=my-domain,dc=com", array('dc')));
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+ldap_delete($link, "dc=my-domain,dc=com");
+?>
+--EXPECTF--
+Warning: ldap_mod_replace() expects exactly 3 parameters, 0 given in %s on line %d
+NULL
+
+Warning: ldap_mod_replace() expects exactly 3 parameters, 1 given in %s on line %d
+NULL
+
+Warning: ldap_mod_replace() expects exactly 3 parameters, 2 given in %s on line %d
+NULL
+
+Warning: ldap_mod_replace() expects exactly 3 parameters, 4 given in %s on line %d
+NULL
+
+Warning: ldap_mod_replace(): Modify: No such object in %s on line %d
+bool(false)
+
+Warning: ldap_mod_replace(): Modify: Invalid DN syntax in %s on line %d
+bool(false)
+
+Warning: ldap_mod_replace(): Unknown attribute in the data in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_modify_basic.phpt b/ext/ldap/tests/ldap_modify_basic.phpt
new file mode 100644
index 0000000..74bd831
--- /dev/null
+++ b/ext/ldap/tests/ldap_modify_basic.phpt
@@ -0,0 +1,96 @@
+--TEST--
+ldap_modify() - Basic modify operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$entry = array(
+ "objectClass" => array(
+ "top",
+ "dcObject",
+ "organization"),
+ "dc" => "my-domain",
+ "o" => "my-domain",
+ "description" => "Domain description",
+);
+
+var_dump(
+ ldap_modify($link, "dc=my-domain,dc=com", $entry),
+ ldap_get_entries(
+ $link,
+ ldap_search($link, "dc=my-domain,dc=com", "(Description=Domain description)")
+ )
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+remove_dummy_data($link);
+?>
+--EXPECT--
+bool(true)
+array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ array(10) {
+ ["objectclass"]=>
+ array(4) {
+ ["count"]=>
+ int(3)
+ [0]=>
+ string(3) "top"
+ [1]=>
+ string(8) "dcObject"
+ [2]=>
+ string(12) "organization"
+ }
+ [0]=>
+ string(11) "objectclass"
+ ["dc"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(9) "my-domain"
+ }
+ [1]=>
+ string(2) "dc"
+ ["o"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(9) "my-domain"
+ }
+ [2]=>
+ string(1) "o"
+ ["description"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(18) "Domain description"
+ }
+ [3]=>
+ string(11) "description"
+ ["count"]=>
+ int(4)
+ ["dn"]=>
+ string(19) "dc=my-domain,dc=com"
+ }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_modify_error.phpt b/ext/ldap/tests/ldap_modify_error.phpt
new file mode 100644
index 0000000..78a7212
--- /dev/null
+++ b/ext/ldap/tests/ldap_modify_error.phpt
@@ -0,0 +1,83 @@
+--TEST--
+ldap_modify() - Modify operations that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+// Too few parameters
+var_dump(ldap_modify());
+var_dump(ldap_modify($link));
+var_dump(ldap_modify($link, "dc=my-domain,dc=com"));
+
+// Too many parameters
+var_dump(ldap_modify($link, "dc=my-domain,dc=com", array(), "Additional data"));
+
+// DN not found
+var_dump(ldap_modify($link, "dc=my-domain,dc=com", array()));
+
+// Invalid DN
+var_dump(ldap_modify($link, "weirdAttribute=val", array()));
+
+$entry = array(
+ "objectClass" => array(
+ "top",
+ "dcObject",
+ "organization"),
+ "dc" => "my-domain",
+ "o" => "my-domain",
+);
+
+ldap_add($link, "dc=my-domain,dc=com", $entry);
+
+$entry2 = $entry;
+$entry2["dc"] = "Wrong Domain";
+
+var_dump(ldap_modify($link, "dc=my-domain,dc=com", $entry2));
+
+$entry2 = $entry;
+$entry2["weirdAttribute"] = "weirdVal";
+
+var_dump(ldap_modify($link, "dc=my-domain,dc=com", $entry2));
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+ldap_delete($link, "dc=my-domain,dc=com");
+?>
+--EXPECTF--
+Warning: ldap_modify() expects exactly 3 parameters, 0 given in %s on line %d
+NULL
+
+Warning: ldap_modify() expects exactly 3 parameters, 1 given in %s on line %d
+NULL
+
+Warning: ldap_modify() expects exactly 3 parameters, 2 given in %s on line %d
+NULL
+
+Warning: ldap_modify() expects exactly 3 parameters, 4 given in %s on line %d
+NULL
+
+Warning: ldap_modify(): Modify: No such object in %s on line %d
+bool(false)
+
+Warning: ldap_modify(): Modify: Invalid DN syntax in %s on line %d
+bool(false)
+
+Warning: ldap_modify(): Modify: Naming violation in %s on line %d
+bool(false)
+
+Warning: ldap_modify(): Modify: Undefined attribute type in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_next_attribute_basic.phpt b/ext/ldap/tests/ldap_next_attribute_basic.phpt
new file mode 100644
index 0000000..0fab78a
--- /dev/null
+++ b/ext/ldap/tests/ldap_next_attribute_basic.phpt
@@ -0,0 +1,36 @@
+--TEST--
+ldap_next_attribute() - Basic ldap_next_attribute test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=organization)");
+$entry = ldap_first_entry($link, $result);
+$attribute = ldap_first_attribute($link, $entry);
+var_dump(
+ ldap_next_attribute($link, $entry),
+ ldap_next_attribute($link, $entry),
+ ldap_next_attribute($link, $entry)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+string(%d) "%s"
+string(%d) "%s"
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_next_attribute_error.phpt b/ext/ldap/tests/ldap_next_attribute_error.phpt
new file mode 100644
index 0000000..c58a560
--- /dev/null
+++ b/ext/ldap/tests/ldap_next_attribute_error.phpt
@@ -0,0 +1,40 @@
+--TEST--
+ldap_next_attribute() - Testing ldap_next_attribute() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=organization)");
+$entry = ldap_first_entry($link, $result);
+var_dump(
+ ldap_next_attribute($link),
+ ldap_next_attribute($link, $link),
+ ldap_next_attribute($link, $entry)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+Warning: ldap_next_attribute() expects %s 2 parameters, 1 given in %s on line %d
+
+Warning: ldap_next_attribute(): supplied resource is not a valid ldap result entry resource in %s on line %d
+
+Warning: ldap_next_attribute(): called before calling ldap_first_attribute() or no attributes found in result entry in %s on line %d
+NULL
+bool(false)
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_next_entry_basic.phpt b/ext/ldap/tests/ldap_next_entry_basic.phpt
new file mode 100644
index 0000000..3209df6
--- /dev/null
+++ b/ext/ldap/tests/ldap_next_entry_basic.phpt
@@ -0,0 +1,40 @@
+--TEST--
+ldap_next_entry() - Basic ldap_first_entry test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_list($link, "dc=my-domain,dc=com", "(objectClass=person)");
+$entry = ldap_first_entry($link, $result);
+var_dump(
+ $entry = ldap_next_entry($link, $entry),
+ ldap_get_values($link, $entry, 'sn'),
+ $entry = ldap_next_entry($link, $entry)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+resource(%d) of type (ldap result entry)
+array(2) {
+ [0]=>
+ string(7) "testSN%d"
+ ["count"]=>
+ int(1)
+}
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_next_entry_error.phpt b/ext/ldap/tests/ldap_next_entry_error.phpt
new file mode 100644
index 0000000..59e9cdc
--- /dev/null
+++ b/ext/ldap/tests/ldap_next_entry_error.phpt
@@ -0,0 +1,27 @@
+--TEST--
+ldap_next_entry() - Testing ldap_next_entry() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_next_entry($link));
+var_dump(ldap_next_entry($link, $link, "Additional data"));
+var_dump(ldap_next_entry($link, $link));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_next_entry() expects exactly 2 parameters, 1 given in %s on line %d
+NULL
+
+Warning: ldap_next_entry() expects exactly 2 parameters, 3 given in %s on line %d
+NULL
+
+Warning: ldap_next_entry(): supplied resource is not a valid ldap result entry resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_next_reference_basic.phpt b/ext/ldap/tests/ldap_next_reference_basic.phpt
new file mode 100644
index 0000000..d0fa31d
--- /dev/null
+++ b/ext/ldap/tests/ldap_next_reference_basic.phpt
@@ -0,0 +1,49 @@
+--TEST--
+ldap_next_reference() - Basic ldap_next_reference test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+ldap_add($link, "cn=userref,dc=my-domain,dc=com", array(
+ "objectClass" => array("extensibleObject", "referral"),
+ "cn" => "userref",
+ "ref" => "cn=userA,dc=my-domain,dc=com",
+));
+ldap_add($link, "cn=userref2,dc=my-domain,dc=com", array(
+ "objectClass" => array("extensibleObject", "referral"),
+ "cn" => "userref2",
+ "ref" => "cn=userB,dc=my-domain,dc=com",
+));
+ldap_set_option($link, LDAP_OPT_DEREF, LDAP_DEREF_NEVER);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(cn=*)");
+$ref = ldap_first_reference($link, $result);
+var_dump($ref2 = ldap_next_reference($link, $ref));
+ldap_parse_reference($link, $ref2, $refs);
+var_dump($refs);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+// Referral can only be removed with Manage DSA IT Control
+ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, array(array("oid" => "2.16.840.1.113730.3.4.2")));
+ldap_delete($link, "cn=userref,dc=my-domain,dc=com");
+ldap_delete($link, "cn=userref2,dc=my-domain,dc=com");
+remove_dummy_data($link);
+?>
+--EXPECTF--
+resource(%d) of type (ldap result entry)
+array(1) {
+ [0]=>
+ string(28) "cn=userB,dc=my-domain,dc=com"
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_next_reference_error.phpt b/ext/ldap/tests/ldap_next_reference_error.phpt
new file mode 100644
index 0000000..0e47c5e
--- /dev/null
+++ b/ext/ldap/tests/ldap_next_reference_error.phpt
@@ -0,0 +1,27 @@
+--TEST--
+ldap_next_reference() - Testing ldap_next_reference() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_next_reference($link));
+var_dump(ldap_next_reference($link, $link, "Additional data"));
+var_dump(ldap_next_reference($link, $link));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_next_reference() expects exactly 2 parameters, 1 given in %s on line %d
+NULL
+
+Warning: ldap_next_reference() expects exactly 2 parameters, 3 given in %s on line %d
+NULL
+
+Warning: ldap_next_reference(): supplied resource is not a valid ldap result entry resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_parse_reference_basic.phpt b/ext/ldap/tests/ldap_parse_reference_basic.phpt
new file mode 100644
index 0000000..2bacd42
--- /dev/null
+++ b/ext/ldap/tests/ldap_parse_reference_basic.phpt
@@ -0,0 +1,45 @@
+--TEST--
+ldap_parse_reference() - Basic ldap_parse_reference test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+ldap_add($link, "cn=userref,dc=my-domain,dc=com", array(
+ "objectClass" => array("extensibleObject", "referral"),
+ "cn" => "userref",
+ "ref" => "cn=userA,dc=my-domain,dc=com",
+));
+ldap_set_option($link, LDAP_OPT_DEREF, LDAP_DEREF_NEVER);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(cn=*)");
+$ref = ldap_first_reference($link, $result);
+$refs = null;
+var_dump(
+ ldap_parse_reference($link, $ref, $refs),
+ $refs
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+// Referral can only be removed with Manage DSA IT Control
+ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, array(array("oid" => "2.16.840.1.113730.3.4.2")));
+ldap_delete($link, "cn=userref,dc=my-domain,dc=com");
+remove_dummy_data($link);
+?>
+--EXPECTF--
+bool(true)
+array(1) {
+ [0]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_parse_reference_error.phpt b/ext/ldap/tests/ldap_parse_reference_error.phpt
new file mode 100644
index 0000000..9d180e7
--- /dev/null
+++ b/ext/ldap/tests/ldap_parse_reference_error.phpt
@@ -0,0 +1,31 @@
+--TEST--
+ldap_parse_reference() - ldap_parse_reference() operations that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+$link = ldap_connect($host, $port);
+$refs = null;
+var_dump(
+ ldap_parse_reference($link, $link),
+ ldap_parse_reference($link, $link, $refs),
+ ldap_parse_reference($link, $refs, $refs, "Additional data"),
+ $refs
+);
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_parse_reference() expects exactly 3 parameters, 2 given in %s on line %d
+
+Warning: ldap_parse_reference(): supplied resource is not a valid ldap result entry resource in %s on line %d
+
+Warning: ldap_parse_reference() expects exactly 3 parameters, 4 given in %s on line %d
+NULL
+bool(false)
+NULL
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_parse_result_basic.phpt b/ext/ldap/tests/ldap_parse_result_basic.phpt
new file mode 100644
index 0000000..1646d59
--- /dev/null
+++ b/ext/ldap/tests/ldap_parse_result_basic.phpt
@@ -0,0 +1,47 @@
+--TEST--
+ldap_parse_result() - Basic ldap_parse_result test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+ldap_add($link, "cn=userref,dc=my-domain,dc=com", array(
+ "objectClass" => array("extensibleObject", "referral"),
+ "cn" => "userref",
+ "ref" => "cn=userA,dc=my-domain,dc=com",
+));
+$result = ldap_search($link, "cn=userref,dc=my-domain,dc=com", "(cn=user*)");
+$errcode = $dn = $errmsg = $refs = null;
+var_dump(
+ ldap_parse_result($link, $result, $errcode, $dn, $errmsg, $refs),
+ $errcode, $dn, $errmsg, $refs
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+// Referral can only be removed with Manage DSA IT Control
+ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, array(array("oid" => "2.16.840.1.113730.3.4.2")));
+ldap_delete($link, "cn=userref,dc=my-domain,dc=com");
+remove_dummy_data($link);
+?>
+--EXPECT--
+bool(true)
+int(10)
+string(30) "cn=userref,dc=my-domain,dc=com"
+string(0) ""
+array(1) {
+ [0]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_parse_result_error.phpt b/ext/ldap/tests/ldap_parse_result_error.phpt
new file mode 100644
index 0000000..33f86f4
--- /dev/null
+++ b/ext/ldap/tests/ldap_parse_result_error.phpt
@@ -0,0 +1,17 @@
+--TEST--
+ldap_parse_result() - Testing ldap_parse_result() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+var_dump(ldap_parse_result(null, null));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_parse_result() expects at least 3 parameters, 2 given in %s on line %d
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_read_basic.phpt b/ext/ldap/tests/ldap_read_basic.phpt
new file mode 100644
index 0000000..04d03d9
--- /dev/null
+++ b/ext/ldap/tests/ldap_read_basic.phpt
@@ -0,0 +1,75 @@
+--TEST--
+ldap_read() test
+--CREDITS--
+Davide Mendolia <idaf1er@gmail.com>
+Patrick Allaert <patrickallaert@php.net>
+Belgian PHP Testfest 2009
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+var_dump(
+ $result = ldap_read($link, "dc=my-domain,dc=com", "(dc=*)"),
+ ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+resource(%d) of type (ldap result)
+array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ array(8) {
+ ["objectclass"]=>
+ array(4) {
+ ["count"]=>
+ int(3)
+ [0]=>
+ string(3) "top"
+ [1]=>
+ string(8) "dcObject"
+ [2]=>
+ string(12) "organization"
+ }
+ [0]=>
+ string(11) "objectclass"
+ ["dc"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(9) "my-domain"
+ }
+ [1]=>
+ string(2) "dc"
+ ["o"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(9) "my-domain"
+ }
+ [2]=>
+ string(1) "o"
+ ["count"]=>
+ int(3)
+ ["dn"]=>
+ string(19) "dc=my-domain,dc=com"
+ }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_read_error.phpt b/ext/ldap/tests/ldap_read_error.phpt
new file mode 100644
index 0000000..649658a
--- /dev/null
+++ b/ext/ldap/tests/ldap_read_error.phpt
@@ -0,0 +1,35 @@
+--TEST--
+ldap_read() - operation that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect($host, $port);
+
+// Too few parameters
+var_dump(ldap_read());
+var_dump(ldap_read($link));
+var_dump(ldap_read($link, $link));
+
+// Too many parameters
+var_dump(ldap_read($link, "dc=my-domain,dc=com", "(objectClass=*)", array(), 0, 0, 0, 0 , "Additional data"));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_read() expects at least 3 parameters, 0 given in %s on line %d
+NULL
+
+Warning: ldap_read() expects at least 3 parameters, 1 given in %s on line %d
+NULL
+
+Warning: ldap_read() expects at least 3 parameters, 2 given in %s on line %d
+NULL
+
+Warning: ldap_read() expects at most 8 parameters, 9 given in %s on line %d
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_rename_basic.phpt b/ext/ldap/tests/ldap_rename_basic.phpt
new file mode 100644
index 0000000..135769d
--- /dev/null
+++ b/ext/ldap/tests/ldap_rename_basic.phpt
@@ -0,0 +1,62 @@
+--TEST--
+ldap_rename() - Basic ldap_rename test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+var_dump(
+ ldap_rename($link, "cn=userA,dc=my-domain,dc=com", "cn=userZ", "dc=my-domain,dc=com", true)
+);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(cn=userA)", array("cn", "sn"));
+$result = ldap_search($link, "dc=my-domain,dc=com", "(cn=userZ)", array("cn", "sn"));
+var_dump(ldap_get_entries($link, $result));
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+ldap_rename($link, "cn=userZ,dc=my-domain,dc=com", "cn=userA", "dc=my-domain,dc=com", true);
+remove_dummy_data($link);
+?>
+--EXPECT--
+bool(true)
+array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ array(6) {
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(7) "testSN1"
+ }
+ [0]=>
+ string(2) "sn"
+ ["cn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(5) "userZ"
+ }
+ [1]=>
+ string(2) "cn"
+ ["count"]=>
+ int(2)
+ ["dn"]=>
+ string(28) "cn=userZ,dc=my-domain,dc=com"
+ }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_rename_error.phpt b/ext/ldap/tests/ldap_rename_error.phpt
new file mode 100644
index 0000000..57ca357
--- /dev/null
+++ b/ext/ldap/tests/ldap_rename_error.phpt
@@ -0,0 +1,21 @@
+--TEST--
+ldap_rename() - Testing ldap_rename() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_rename($link));
+var_dump(ldap_rename($link, "cn=userNotFound,dc=my-domain,dc=com", "cn=userZ", "dc=my-domain,dc=com", true));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_rename() expects exactly 5 parameters, 1 given in %s on line %d
+NULL
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_sasl_bind_basic.phpt b/ext/ldap/tests/ldap_sasl_bind_basic.phpt
new file mode 100644
index 0000000..efa1f82
--- /dev/null
+++ b/ext/ldap/tests/ldap_sasl_bind_basic.phpt
@@ -0,0 +1,27 @@
+--TEST--
+ldap_sasl_bind() - Basic anonymous binding
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php if (!function_exists("ldap_sasl_bind")) die("skip LDAP extension not compiled with SASL support"); ?>
+<?php
+ require "connect.inc";
+ $link = fsockopen($host, $port);
+ if (!$link) {
+ die("skip no server listening");
+ }
+?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+var_dump(ldap_sasl_bind($link, null, $passwd, 'DIGEST-MD5', 'realm', $sasl_user));
+?>
+===DONE===
+--EXPECT--
+bool(true)
+===DONE===
diff --git a/ext/ldap/tests/ldap_sasl_bind_error.phpt b/ext/ldap/tests/ldap_sasl_bind_error.phpt
new file mode 100644
index 0000000..180066b
--- /dev/null
+++ b/ext/ldap/tests/ldap_sasl_bind_error.phpt
@@ -0,0 +1,53 @@
+--TEST--
+ldap_sasl_bind() - Binding that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+<?php if (!function_exists("ldap_sasl_bind")) die("skip LDAP extension not compiled with SASL support"); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+
+// Invalid parameter count
+var_dump(ldap_sasl_bind());
+
+// Invalid DN
+var_dump(ldap_sasl_bind($link, "Invalid DN", $passwd, 'DIGEST-MD5', 'realm', $sasl_user));
+
+// Invalid user
+var_dump(ldap_sasl_bind($link, null, "ThisIsNotCorrect$passwd", 'DIGEST-MD5', "realm", "invalid$sasl_user"));
+
+// Invalid password
+var_dump(ldap_sasl_bind($link, null, "ThisIsNotCorrect$passwd", 'DIGEST-MD5', "realm", $sasl_user));
+
+var_dump(ldap_sasl_bind($link, null, $passwd, 'DIGEST-MD5', "realm", "Manager", "test"));
+
+// Invalid DN syntax
+var_dump(ldap_sasl_bind($link, "unexistingProperty=weirdValue,$user", $passwd));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_sasl_bind() expects at least 1 parameter, 0 given in %s on line %d
+bool(false)
+
+Warning: ldap_sasl_bind(): Unable to bind to server: Invalid DN syntax in %s on line %d
+bool(false)
+
+Warning: ldap_sasl_bind(): Unable to bind to server: Invalid credentials in %s on line %d
+bool(false)
+
+Warning: ldap_sasl_bind(): Unable to bind to server: Invalid credentials in %s on line %d
+bool(false)
+
+Warning: ldap_sasl_bind(): Unable to bind to server: Insufficient access in %s on line %d
+bool(false)
+
+Warning: ldap_sasl_bind(): Unable to bind to server: Invalid DN syntax in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_search_basic.phpt b/ext/ldap/tests/ldap_search_basic.phpt
new file mode 100644
index 0000000..e6cebf2
--- /dev/null
+++ b/ext/ldap/tests/ldap_search_basic.phpt
@@ -0,0 +1,194 @@
+--TEST--
+ldap_search() test
+--CREDITS--
+Davide Mendolia <idaf1er@gmail.com>
+Patrick Allaert <patrickallaert@php.net>
+Belgian PHP Testfest 2009
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+insert_dummy_data($link);
+var_dump(
+ $result = ldap_search($link, "dc=my-domain,dc=com", "(objectClass=person)"),
+ ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+resource(%d) of type (ldap result)
+array(4) {
+ ["count"]=>
+ int(3)
+ [0]=>
+ array(14) {
+ ["objectclass"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(6) "person"
+ }
+ [0]=>
+ string(11) "objectclass"
+ ["cn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(5) "userA"
+ }
+ [1]=>
+ string(2) "cn"
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(7) "testSN1"
+ }
+ [2]=>
+ string(2) "sn"
+ ["userpassword"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(4) "oops"
+ }
+ [3]=>
+ string(12) "userpassword"
+ ["telephonenumber"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(14) "xx-xx-xx-xx-xx"
+ }
+ [4]=>
+ string(15) "telephonenumber"
+ ["description"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(6) "user A"
+ }
+ [5]=>
+ string(11) "description"
+ ["count"]=>
+ int(6)
+ ["dn"]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+ }
+ [1]=>
+ array(12) {
+ ["objectclass"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(6) "person"
+ }
+ [0]=>
+ string(11) "objectclass"
+ ["cn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(5) "userB"
+ }
+ [1]=>
+ string(2) "cn"
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(7) "testSN2"
+ }
+ [2]=>
+ string(2) "sn"
+ ["userpassword"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(15) "oopsIDitItAgain"
+ }
+ [3]=>
+ string(12) "userpassword"
+ ["description"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(6) "user B"
+ }
+ [4]=>
+ string(11) "description"
+ ["count"]=>
+ int(5)
+ ["dn"]=>
+ string(28) "cn=userB,dc=my-domain,dc=com"
+ }
+ [2]=>
+ array(10) {
+ ["objectclass"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(6) "person"
+ }
+ [0]=>
+ string(11) "objectclass"
+ ["cn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(5) "userC"
+ }
+ [1]=>
+ string(2) "cn"
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(7) "testSN3"
+ }
+ [2]=>
+ string(2) "sn"
+ ["userpassword"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(17) "0r1g1na1 passw0rd"
+ }
+ [3]=>
+ string(12) "userpassword"
+ ["count"]=>
+ int(4)
+ ["dn"]=>
+ string(37) "cn=userC,cn=userB,dc=my-domain,dc=com"
+ }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_search_error.phpt b/ext/ldap/tests/ldap_search_error.phpt
new file mode 100644
index 0000000..7e94613
--- /dev/null
+++ b/ext/ldap/tests/ldap_search_error.phpt
@@ -0,0 +1,61 @@
+--TEST--
+ldap_search() - operation that should fail
+--CREDITS--
+Davide Mendolia <idaf1er@gmail.com>
+Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once dirname(__FILE__) .'/skipif.inc'; ?>
+<?php require_once dirname(__FILE__) .'/skipifbindfailure.inc'; ?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect($host, $port);
+
+$dn = "dc=my-domain,dc=com";
+$filter = "(dc=*)";
+
+$result = ldap_search();
+var_dump($result);
+
+$result = ldap_search($link, $dn, $filter);
+var_dump($result);
+
+$result = ldap_search($link, $dn, $filter, NULL);
+var_dump($result);
+
+$result = ldap_search($link, $dn, $filter, array(1 => 'top'));
+var_dump($result);
+
+$result = ldap_search(array(), $dn, $filter, array('top'));
+var_dump($result);
+
+$result = ldap_search(array($link, $link), array($dn), $filter, array('top'));
+var_dump($result);
+
+$result = ldap_search(array($link, $link), $dn, array($filter), array('top'));
+var_dump($result);
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_search() expects at least 3 parameters, 0 given in %s on line %d
+NULL
+
+Warning: ldap_search(): Search: No such object in %s on line %d
+bool(false)
+
+Warning: ldap_search() expects parameter 4 to be array, null given in %s on line %d
+NULL
+
+Warning: ldap_search(): Array initialization wrong in %s on line %d
+bool(false)
+
+Warning: ldap_search(): No links in link array in %s on line %d
+bool(false)
+
+Warning: ldap_search(): Base must either be a string, or an array with the same number of elements as the links array in %s on line %d
+bool(false)
+
+Warning: ldap_search(): Filter must either be a string, or an array with the same number of elements as the links array in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_search_variation1.phpt b/ext/ldap/tests/ldap_search_variation1.phpt
new file mode 100644
index 0000000..d56f5bd
--- /dev/null
+++ b/ext/ldap/tests/ldap_search_variation1.phpt
@@ -0,0 +1,56 @@
+--TEST--
+ldap_search() test
+--CREDITS--
+Davide Mendolia <idaf1er@gmail.com>
+Patrick Allaert <patrickallaert@php.net>
+Belgian PHP Testfest 2009
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$dn = "dc=my-domain,dc=com";
+$filter = "(dc=*)";
+var_dump(
+ $result = ldap_search($link, "dc=my-domain,dc=com", "(dc=*)", array('dc')),
+ ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+resource(%d) of type (ldap result)
+array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ array(4) {
+ ["dc"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(9) "my-domain"
+ }
+ [0]=>
+ string(2) "dc"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(19) "dc=my-domain,dc=com"
+ }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_search_variation2.phpt b/ext/ldap/tests/ldap_search_variation2.phpt
new file mode 100644
index 0000000..791c5e9
--- /dev/null
+++ b/ext/ldap/tests/ldap_search_variation2.phpt
@@ -0,0 +1,80 @@
+--TEST--
+ldap_search() test
+--CREDITS--
+Davide Mendolia <idaf1er@gmail.com>
+Patrick Allaert <patrickallaert@php.net>
+Belgian PHP Testfest 2009
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+var_dump(
+ $result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=person)", array('sn'), 1),
+ ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+resource(%d) of type (ldap result)
+array(4) {
+ ["count"]=>
+ int(3)
+ [0]=>
+ array(4) {
+ ["sn"]=>
+ array(1) {
+ ["count"]=>
+ int(0)
+ }
+ [0]=>
+ string(2) "sn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+ }
+ [1]=>
+ array(4) {
+ ["sn"]=>
+ array(1) {
+ ["count"]=>
+ int(0)
+ }
+ [0]=>
+ string(2) "sn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(28) "cn=userB,dc=my-domain,dc=com"
+ }
+ [2]=>
+ array(4) {
+ ["sn"]=>
+ array(1) {
+ ["count"]=>
+ int(0)
+ }
+ [0]=>
+ string(2) "sn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(37) "cn=userC,cn=userB,dc=my-domain,dc=com"
+ }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_search_variation3.phpt b/ext/ldap/tests/ldap_search_variation3.phpt
new file mode 100644
index 0000000..ab7b222
--- /dev/null
+++ b/ext/ldap/tests/ldap_search_variation3.phpt
@@ -0,0 +1,108 @@
+--TEST--
+ldap_search() test
+--CREDITS--
+Davide Mendolia <idaf1er@gmail.com>
+Patrick Allaert <patrickallaert@php.net>
+Belgian PHP Testfest 2009
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$dn = "dc=my-domain,dc=com";
+$filter = "(objectclass=person)";
+var_dump(
+ $result = ldap_search($link, $dn, $filter, array('sn'), 1, 3),
+ ldap_get_entries($link, $result)
+);
+
+var_dump(
+ $result = ldap_search($link, $dn, $filter, array('sn'), 1, 1),
+ ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+resource(%d) of type (ldap result)
+array(4) {
+ ["count"]=>
+ int(3)
+ [0]=>
+ array(4) {
+ ["sn"]=>
+ array(1) {
+ ["count"]=>
+ int(0)
+ }
+ [0]=>
+ string(2) "sn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+ }
+ [1]=>
+ array(4) {
+ ["sn"]=>
+ array(1) {
+ ["count"]=>
+ int(0)
+ }
+ [0]=>
+ string(2) "sn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(28) "cn=userB,dc=my-domain,dc=com"
+ }
+ [2]=>
+ array(4) {
+ ["sn"]=>
+ array(1) {
+ ["count"]=>
+ int(0)
+ }
+ [0]=>
+ string(2) "sn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(37) "cn=userC,cn=userB,dc=my-domain,dc=com"
+ }
+}
+
+Warning: ldap_search(): Partial search results returned: Sizelimit exceeded in %s on line %d
+resource(%d) of type (ldap result)
+array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ array(4) {
+ ["sn"]=>
+ array(1) {
+ ["count"]=>
+ int(0)
+ }
+ [0]=>
+ string(2) "sn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+ }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_search_variation4.phpt b/ext/ldap/tests/ldap_search_variation4.phpt
new file mode 100644
index 0000000..787468e
--- /dev/null
+++ b/ext/ldap/tests/ldap_search_variation4.phpt
@@ -0,0 +1,55 @@
+--TEST--
+ldap_search() test
+--CREDITS--
+Davide Mendolia <idaf1er@gmail.com>
+Patrick Allaert <patrickallaert@php.net>
+Belgian PHP Testfest 2009
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$dn = "dc=my-domain,dc=com";
+$filter = "(objectclass=person)";
+var_dump(
+ $result = ldap_search($link, $dn, $filter, array('sn'), 1, 1, 3),
+ ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+Warning: ldap_search(): Partial search results returned: Sizelimit exceeded in %s on line %d
+resource(%d) of type (ldap result)
+array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ array(4) {
+ ["sn"]=>
+ array(1) {
+ ["count"]=>
+ int(0)
+ }
+ [0]=>
+ string(2) "sn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+ }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_search_variation5.phpt b/ext/ldap/tests/ldap_search_variation5.phpt
new file mode 100644
index 0000000..d50854c
--- /dev/null
+++ b/ext/ldap/tests/ldap_search_variation5.phpt
@@ -0,0 +1,105 @@
+--TEST--
+ldap_search() test
+--CREDITS--
+Davide Mendolia <idaf1er@gmail.com>
+Patrick Allaert <patrickallaert@php.net>
+Belgian PHP Testfest 2009
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$dn = "dc=my-domain,dc=com";
+$filter = "(objectclass=person)";
+var_dump(
+ $result = ldap_search($link, $dn, $filter, array('sn'), 1, 1, 3, LDAP_DEREF_SEARCHING),
+ ldap_get_entries($link, $result)
+);
+var_dump(
+ $result = ldap_search($link, $dn, $filter, array('sn'), 1, 1, 3, LDAP_DEREF_FINDING),
+ ldap_get_entries($link, $result)
+);
+var_dump(
+ $result = ldap_search($link, $dn, $filter, array('sn'), 1, 1, 3, LDAP_DEREF_ALWAYS),
+ ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+Warning: ldap_search(): Partial search results returned: Sizelimit exceeded in %s on line %d
+resource(%d) of type (ldap result)
+array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ array(4) {
+ ["sn"]=>
+ array(1) {
+ ["count"]=>
+ int(0)
+ }
+ [0]=>
+ string(2) "sn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+ }
+}
+
+Warning: ldap_search(): Partial search results returned: Sizelimit exceeded in %s on line %d
+resource(%d) of type (ldap result)
+array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ array(4) {
+ ["sn"]=>
+ array(1) {
+ ["count"]=>
+ int(0)
+ }
+ [0]=>
+ string(2) "sn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+ }
+}
+
+Warning: ldap_search(): Partial search results returned: Sizelimit exceeded in %s on line %d
+resource(%d) of type (ldap result)
+array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ array(4) {
+ ["sn"]=>
+ array(1) {
+ ["count"]=>
+ int(0)
+ }
+ [0]=>
+ string(2) "sn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+ }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_search_variation6.phpt b/ext/ldap/tests/ldap_search_variation6.phpt
new file mode 100644
index 0000000..a29e452
--- /dev/null
+++ b/ext/ldap/tests/ldap_search_variation6.phpt
@@ -0,0 +1,230 @@
+--TEST--
+ldap_search() test
+--CREDITS--
+Davide Mendolia <idaf1er@gmail.com>
+Patrick Allaert <patrickallaert@php.net>
+Belgian PHP Testfest 2009
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$dn = "dc=my-domain,dc=com";
+$filter = "(objectclass=person)";
+
+var_dump(
+ $result = ldap_search(array($link, $link), $dn, $filter),
+ $result0 = ldap_get_entries($link, $result[0]),
+ ldap_get_entries($link, $result[1]) === $result0
+);
+var_dump(
+ $result = ldap_search(array($link, $link), null, $filter),
+ ldap_get_entries($link, $result[0]),
+ ldap_get_entries($link, $result[1])
+);
+var_dump(
+ $result = ldap_search(array($link, $link), null, array($filter, $filter)),
+ ldap_get_entries($link, $result[0]),
+ ldap_get_entries($link, $result[1])
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+array(2) {
+ [0]=>
+ resource(%d) of type (ldap result)
+ [1]=>
+ resource(%d) of type (ldap result)
+}
+array(4) {
+ ["count"]=>
+ int(3)
+ [0]=>
+ array(14) {
+ ["objectclass"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(6) "person"
+ }
+ [0]=>
+ string(11) "objectclass"
+ ["cn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(5) "userA"
+ }
+ [1]=>
+ string(2) "cn"
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(7) "testSN1"
+ }
+ [2]=>
+ string(2) "sn"
+ ["userpassword"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(4) "oops"
+ }
+ [3]=>
+ string(12) "userpassword"
+ ["telephonenumber"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(14) "xx-xx-xx-xx-xx"
+ }
+ [4]=>
+ string(15) "telephonenumber"
+ ["description"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(6) "user A"
+ }
+ [5]=>
+ string(11) "description"
+ ["count"]=>
+ int(6)
+ ["dn"]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+ }
+ [1]=>
+ array(12) {
+ ["objectclass"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(6) "person"
+ }
+ [0]=>
+ string(11) "objectclass"
+ ["cn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(5) "userB"
+ }
+ [1]=>
+ string(2) "cn"
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(7) "testSN2"
+ }
+ [2]=>
+ string(2) "sn"
+ ["userpassword"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(15) "oopsIDitItAgain"
+ }
+ [3]=>
+ string(12) "userpassword"
+ ["description"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(6) "user B"
+ }
+ [4]=>
+ string(11) "description"
+ ["count"]=>
+ int(5)
+ ["dn"]=>
+ string(28) "cn=userB,dc=my-domain,dc=com"
+ }
+ [2]=>
+ array(10) {
+ ["objectclass"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(6) "person"
+ }
+ [0]=>
+ string(11) "objectclass"
+ ["cn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(5) "userC"
+ }
+ [1]=>
+ string(2) "cn"
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(7) "testSN3"
+ }
+ [2]=>
+ string(2) "sn"
+ ["userpassword"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(17) "0r1g1na1 passw0rd"
+ }
+ [3]=>
+ string(12) "userpassword"
+ ["count"]=>
+ int(4)
+ ["dn"]=>
+ string(37) "cn=userC,cn=userB,dc=my-domain,dc=com"
+ }
+}
+bool(true)
+array(2) {
+ [0]=>
+ resource(%d) of type (ldap result)
+ [1]=>
+ resource(%d) of type (ldap result)
+}
+NULL
+NULL
+array(2) {
+ [0]=>
+ resource(%d) of type (ldap result)
+ [1]=>
+ resource(%d) of type (ldap result)
+}
+NULL
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_set_option_basic.phpt b/ext/ldap/tests/ldap_set_option_basic.phpt
new file mode 100644
index 0000000..de25e59
--- /dev/null
+++ b/ext/ldap/tests/ldap_set_option_basic.phpt
@@ -0,0 +1,23 @@
+--TEST--
+ldap_set_option() - Basic ldap_set_option() operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+$option = null;
+
+var_dump(ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version));
+ldap_get_option($link, LDAP_OPT_PROTOCOL_VERSION, $option);
+var_dump($option);
+?>
+===DONE===
+--EXPECT--
+bool(true)
+int(3)
+===DONE===
diff --git a/ext/ldap/tests/ldap_set_option_error.phpt b/ext/ldap/tests/ldap_set_option_error.phpt
new file mode 100644
index 0000000..f319c7e
--- /dev/null
+++ b/ext/ldap/tests/ldap_set_option_error.phpt
@@ -0,0 +1,66 @@
+--TEST--
+ldap_set_option() - ldap_set_option() operation that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+$controls = array(
+ array(
+ array("xid" => "1.2.752.58.10.1", "iscritical" => true),
+ array("xid" => "1.2.752.58.1.10", "value" => "magic"),
+ ),
+ array(
+ array("oid" => "1.2.752.58.10.1", "iscritical" => true),
+ array("oid" => "1.2.752.58.1.10", "value" => "magic"),
+ "weird"
+ ),
+ array(
+ ),
+);
+
+// Too few parameters
+var_dump(ldap_set_option());
+var_dump(ldap_set_option($link));
+var_dump(ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION));
+
+// Too many parameters
+var_dump(ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, 3, "Additional data"));
+
+var_dump(ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, 10));
+
+foreach ($controls as $control)
+ var_dump(ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, $control));
+
+var_dump(ldap_set_option($link, 999999, 999999));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_set_option() expects exactly 3 parameters, 0 given in %s on line %d
+NULL
+
+Warning: ldap_set_option() expects exactly 3 parameters, 1 given in %s on line %d
+NULL
+
+Warning: ldap_set_option() expects exactly 3 parameters, 2 given in %s on line %d
+NULL
+
+Warning: ldap_set_option() expects exactly 3 parameters, 4 given in %s on line %d
+NULL
+bool(false)
+
+Warning: ldap_set_option(): Control must have an oid key in %s on line %d
+bool(false)
+
+Warning: ldap_set_option(): The array value must contain only arrays, where each array is a control in %s on line %d
+bool(false)
+
+Warning: ldap_set_option(): Expected non-empty array value for this option in %s on line %d
+bool(false)
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_set_option_variation.phpt b/ext/ldap/tests/ldap_set_option_variation.phpt
new file mode 100644
index 0000000..6e082be
--- /dev/null
+++ b/ext/ldap/tests/ldap_set_option_variation.phpt
@@ -0,0 +1,84 @@
+--TEST--
+ldap_set_option() - More ldap_set_option() operations
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+$option = null;
+
+$controls = array(
+ array("oid" => "1.2.752.58.10.1", "iscritical" => true),
+ array("oid" => "1.2.752.58.1.10", "value" => "magic"),
+);
+
+var_dump(ldap_set_option($link, LDAP_OPT_DEREF, LDAP_DEREF_ALWAYS));
+ldap_get_option($link, LDAP_OPT_DEREF, $option);
+var_dump(
+ $option === LDAP_DEREF_ALWAYS,
+ ldap_set_option($link, LDAP_OPT_SIZELIMIT, 123)
+);
+ldap_get_option($link, LDAP_OPT_SIZELIMIT, $option);
+var_dump(
+ $option,
+ ldap_set_option($link, LDAP_OPT_TIMELIMIT, 33)
+);
+ldap_get_option($link, LDAP_OPT_TIMELIMIT, $option);
+var_dump(
+ $option,
+ ldap_set_option($link, LDAP_OPT_NETWORK_TIMEOUT, 44)
+);
+ldap_get_option($link, LDAP_OPT_NETWORK_TIMEOUT, $option);
+var_dump(
+ $option,
+ ldap_set_option($link, LDAP_OPT_REFERRALS, true)
+);
+ldap_get_option($link, LDAP_OPT_REFERRALS, $option);
+var_dump(
+ (bool) $option,
+ ldap_set_option($link, LDAP_OPT_RESTART, false)
+);
+ldap_get_option($link, LDAP_OPT_RESTART, $option);
+var_dump(
+ (bool) $option,
+ ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, $controls)
+);
+ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $option);
+var_dump(
+ $option,
+ ldap_set_option($link, LDAP_OPT_CLIENT_CONTROLS, $controls)
+);
+ldap_get_option($link, LDAP_OPT_CLIENT_CONTROLS, $option);
+var_dump(
+ $option,
+ ldap_set_option($link, LDAP_OPT_MATCHED_DN, "dc=test,dc=com")
+);
+ldap_get_option($link, LDAP_OPT_MATCHED_DN, $option);
+var_dump($option);
+?>
+===DONE===
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+int(123)
+bool(true)
+int(33)
+bool(true)
+int(44)
+bool(true)
+bool(true)
+bool(true)
+bool(false)
+bool(true)
+int(0)
+bool(true)
+int(0)
+bool(true)
+string(14) "dc=test,dc=com"
+===DONE===
diff --git a/ext/ldap/tests/ldap_set_rebind_proc_basic.phpt b/ext/ldap/tests/ldap_set_rebind_proc_basic.phpt
new file mode 100644
index 0000000..428b8d8
--- /dev/null
+++ b/ext/ldap/tests/ldap_set_rebind_proc_basic.phpt
@@ -0,0 +1,34 @@
+--TEST--
+ldap_set_rebind_proc() - Basic ldap_set_rebind_proc test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+function rebind_proc ($ds, $ldap_url) {
+ global $user;
+ global $passwd;
+ global $protocol_version;
+
+ // required by most modern LDAP servers, use LDAPv3
+ ldap_set_option($a, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+
+ if (!ldap_bind($a, $user, $passwd)) {
+ print "Cannot bind";
+ }
+}
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+var_dump(ldap_set_rebind_proc($link, "rebind_proc"));
+var_dump(ldap_set_rebind_proc($link, ""));
+?>
+===DONE===
+--EXPECT--
+bool(true)
+bool(true)
+===DONE===
diff --git a/ext/ldap/tests/ldap_set_rebind_proc_error.phpt b/ext/ldap/tests/ldap_set_rebind_proc_error.phpt
new file mode 100644
index 0000000..966612f
--- /dev/null
+++ b/ext/ldap/tests/ldap_set_rebind_proc_error.phpt
@@ -0,0 +1,50 @@
+--TEST--
+ldap_set_rebind_proc() - Testing ldap_set_rebind_proc() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php
+ if (!function_exists("ldap_set_rebind_proc")) {
+ die("skip ldap_set_rebind_proc() does not exist");
+ }
+ require "connect.inc";
+ $link = fsockopen($host, $port);
+ if (!$link) {
+ die("skip no server listening");
+ }
+?>
+--FILE--
+<?php
+require "connect.inc";
+
+function rebind_proc ($ds, $ldap_url) {
+ global $user;
+ global $passwd;
+ global $protocol_version;
+
+ // required by most modern LDAP servers, use LDAPv3
+ ldap_set_option($a, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+
+ if (!ldap_bind($a, $user, $passwd)) {
+ print "Cannot bind";
+ }
+}
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_set_rebind_proc($link));
+var_dump(ldap_set_rebind_proc($link, "rebind_proc", "Additional data"));
+var_dump(ldap_set_rebind_proc($link, "rebind_proc_inexistant"));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_set_rebind_proc() expects exactly 2 parameters, 1 given in %s on line %d
+bool(false)
+
+Warning: ldap_set_rebind_proc() expects exactly 2 parameters, 3 given in %s on line %d
+bool(false)
+
+Warning: ldap_set_rebind_proc(): Two arguments expected for 'rebind_proc_inexistant' to be a valid callback in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_sort_basic.phpt b/ext/ldap/tests/ldap_sort_basic.phpt
new file mode 100644
index 0000000..f6ee5d1
--- /dev/null
+++ b/ext/ldap/tests/ldap_sort_basic.phpt
@@ -0,0 +1,200 @@
+--TEST--
+ldap_sort() - Basic ldap_sort test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+ldap_add($link, "cn=userC,dc=my-domain,dc=com", array(
+ "objectclass" => "person",
+ "cn" => "userC",
+ "sn" => "zzz",
+ "userPassword" => "oops",
+ "description" => "a user",
+));
+ldap_add($link, "cn=userD,dc=my-domain,dc=com", array(
+ "objectclass" => "person",
+ "cn" => "userD",
+ "sn" => "aaa",
+ "userPassword" => "oops",
+ "description" => "another user",
+));
+ldap_add($link, "cn=userE,dc=my-domain,dc=com", array(
+ "objectclass" => "person",
+ "cn" => "userE",
+ "sn" => "a",
+ "userPassword" => "oops",
+ "description" => "yet another user",
+));
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=person)", array("sn", "description"));
+var_dump(
+ ldap_sort($link, $result, "sn"),
+ ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+ldap_delete($link, "cn=userC,dc=my-domain,dc=com");
+ldap_delete($link, "cn=userD,dc=my-domain,dc=com");
+ldap_delete($link, "cn=userE,dc=my-domain,dc=com");
+remove_dummy_data($link);
+?>
+--EXPECT--
+bool(true)
+array(7) {
+ ["count"]=>
+ int(6)
+ [0]=>
+ array(6) {
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(1) "a"
+ }
+ [0]=>
+ string(2) "sn"
+ ["description"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(16) "yet another user"
+ }
+ [1]=>
+ string(11) "description"
+ ["count"]=>
+ int(2)
+ ["dn"]=>
+ string(28) "cn=userE,dc=my-domain,dc=com"
+ }
+ [1]=>
+ array(6) {
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(3) "aaa"
+ }
+ [0]=>
+ string(2) "sn"
+ ["description"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(12) "another user"
+ }
+ [1]=>
+ string(11) "description"
+ ["count"]=>
+ int(2)
+ ["dn"]=>
+ string(28) "cn=userD,dc=my-domain,dc=com"
+ }
+ [2]=>
+ array(6) {
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(7) "testSN1"
+ }
+ [0]=>
+ string(2) "sn"
+ ["description"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(6) "user A"
+ }
+ [1]=>
+ string(11) "description"
+ ["count"]=>
+ int(2)
+ ["dn"]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+ }
+ [3]=>
+ array(6) {
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(7) "testSN2"
+ }
+ [0]=>
+ string(2) "sn"
+ ["description"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(6) "user B"
+ }
+ [1]=>
+ string(11) "description"
+ ["count"]=>
+ int(2)
+ ["dn"]=>
+ string(28) "cn=userB,dc=my-domain,dc=com"
+ }
+ [4]=>
+ array(4) {
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(7) "testSN3"
+ }
+ [0]=>
+ string(2) "sn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(37) "cn=userC,cn=userB,dc=my-domain,dc=com"
+ }
+ [5]=>
+ array(6) {
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(3) "zzz"
+ }
+ [0]=>
+ string(2) "sn"
+ ["description"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(6) "a user"
+ }
+ [1]=>
+ string(11) "description"
+ ["count"]=>
+ int(2)
+ ["dn"]=>
+ string(28) "cn=userC,dc=my-domain,dc=com"
+ }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_sort_error.phpt b/ext/ldap/tests/ldap_sort_error.phpt
new file mode 100644
index 0000000..6eb4090
--- /dev/null
+++ b/ext/ldap/tests/ldap_sort_error.phpt
@@ -0,0 +1,35 @@
+--TEST--
+ldap_sort() - Testing ldap_sort() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_sort($link));
+var_dump(ldap_sort($link, $link));
+var_dump(ldap_sort($link, $link, $link, $link));
+var_dump(ldap_sort($link, $link, $link));
+var_dump(ldap_sort($link, $link, "sn"));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_sort() expects exactly 3 parameters, 1 given in %s on line %d
+bool(false)
+
+Warning: ldap_sort() expects exactly 3 parameters, 2 given in %s on line %d
+bool(false)
+
+Warning: ldap_sort() expects exactly 3 parameters, 4 given in %s on line %d
+bool(false)
+
+Warning: ldap_sort() expects parameter 3 to be %binary_string_optional%, resource given in %s on line %d
+bool(false)
+
+Warning: ldap_sort(): Supplied resource is not a valid ldap result resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_sort_variation.phpt b/ext/ldap/tests/ldap_sort_variation.phpt
new file mode 100644
index 0000000..e1affe8
--- /dev/null
+++ b/ext/ldap/tests/ldap_sort_variation.phpt
@@ -0,0 +1,200 @@
+--TEST--
+ldap_sort() - Basic ldap_sort test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+ldap_add($link, "cn=userC,dc=my-domain,dc=com", array(
+ "objectclass" => "person",
+ "cn" => "userC",
+ "sn" => "zzz",
+ "userPassword" => "oops",
+ "description" => "a user",
+));
+ldap_add($link, "cn=userD,dc=my-domain,dc=com", array(
+ "objectclass" => "person",
+ "cn" => "userD",
+ "sn" => "aaa",
+ "userPassword" => "oops",
+ "description" => "another user",
+));
+ldap_add($link, "cn=userE,dc=my-domain,dc=com", array(
+ "objectclass" => "person",
+ "cn" => "userE",
+ "sn" => "a",
+ "userPassword" => "oops",
+ "description" => "yet another user",
+));
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=person)", array("sn", "description"));
+var_dump(
+ ldap_sort($link, $result, "description"),
+ ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+ldap_delete($link, "cn=userC,dc=my-domain,dc=com");
+ldap_delete($link, "cn=userD,dc=my-domain,dc=com");
+ldap_delete($link, "cn=userE,dc=my-domain,dc=com");
+remove_dummy_data($link);
+?>
+--EXPECT--
+bool(true)
+array(7) {
+ ["count"]=>
+ int(6)
+ [0]=>
+ array(4) {
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(7) "testSN3"
+ }
+ [0]=>
+ string(2) "sn"
+ ["count"]=>
+ int(1)
+ ["dn"]=>
+ string(37) "cn=userC,cn=userB,dc=my-domain,dc=com"
+ }
+ [1]=>
+ array(6) {
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(3) "zzz"
+ }
+ [0]=>
+ string(2) "sn"
+ ["description"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(6) "a user"
+ }
+ [1]=>
+ string(11) "description"
+ ["count"]=>
+ int(2)
+ ["dn"]=>
+ string(28) "cn=userC,dc=my-domain,dc=com"
+ }
+ [2]=>
+ array(6) {
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(3) "aaa"
+ }
+ [0]=>
+ string(2) "sn"
+ ["description"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(12) "another user"
+ }
+ [1]=>
+ string(11) "description"
+ ["count"]=>
+ int(2)
+ ["dn"]=>
+ string(28) "cn=userD,dc=my-domain,dc=com"
+ }
+ [3]=>
+ array(6) {
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(7) "testSN1"
+ }
+ [0]=>
+ string(2) "sn"
+ ["description"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(6) "user A"
+ }
+ [1]=>
+ string(11) "description"
+ ["count"]=>
+ int(2)
+ ["dn"]=>
+ string(28) "cn=userA,dc=my-domain,dc=com"
+ }
+ [4]=>
+ array(6) {
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(7) "testSN2"
+ }
+ [0]=>
+ string(2) "sn"
+ ["description"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(6) "user B"
+ }
+ [1]=>
+ string(11) "description"
+ ["count"]=>
+ int(2)
+ ["dn"]=>
+ string(28) "cn=userB,dc=my-domain,dc=com"
+ }
+ [5]=>
+ array(6) {
+ ["sn"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(1) "a"
+ }
+ [0]=>
+ string(2) "sn"
+ ["description"]=>
+ array(2) {
+ ["count"]=>
+ int(1)
+ [0]=>
+ string(16) "yet another user"
+ }
+ [1]=>
+ string(11) "description"
+ ["count"]=>
+ int(2)
+ ["dn"]=>
+ string(28) "cn=userE,dc=my-domain,dc=com"
+ }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_start_tls_basic.phpt b/ext/ldap/tests/ldap_start_tls_basic.phpt
new file mode 100644
index 0000000..efc4356
--- /dev/null
+++ b/ext/ldap/tests/ldap_start_tls_basic.phpt
@@ -0,0 +1,20 @@
+--TEST--
+ldap_start_tls() - Basic ldap_start_tls test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once dirname(__FILE__) .'/skipif.inc'; ?>
+<?php require_once dirname(__FILE__) .'/skipifbindfailure.inc'; ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+var_dump(ldap_start_tls($link));
+?>
+===DONE===
+--EXPECT--
+bool(true)
+===DONE===
diff --git a/ext/ldap/tests/ldap_start_tls_error.phpt b/ext/ldap/tests/ldap_start_tls_error.phpt
new file mode 100644
index 0000000..686f533
--- /dev/null
+++ b/ext/ldap/tests/ldap_start_tls_error.phpt
@@ -0,0 +1,27 @@
+--TEST--
+ldap_start_tls() - Binding that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+
+// Invalid parameter count
+var_dump(ldap_start_tls());
+var_dump(ldap_start_tls($link, $link));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_start_tls() expects exactly 1 parameter, 0 given in %s on line %d
+NULL
+
+Warning: ldap_start_tls() expects exactly 1 parameter, 2 given in %s on line %d
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_unbind_basic.phpt b/ext/ldap/tests/ldap_unbind_basic.phpt
new file mode 100644
index 0000000..addfac5
--- /dev/null
+++ b/ext/ldap/tests/ldap_unbind_basic.phpt
@@ -0,0 +1,20 @@
+--TEST--
+ldap_unbind() - Basic ldap_unbind() operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+var_dump(ldap_unbind($link));
+?>
+===DONE===
+--EXPECT--
+bool(true)
+===DONE===
diff --git a/ext/ldap/tests/ldap_unbind_error.phpt b/ext/ldap/tests/ldap_unbind_error.phpt
new file mode 100644
index 0000000..19b4ad5
--- /dev/null
+++ b/ext/ldap/tests/ldap_unbind_error.phpt
@@ -0,0 +1,42 @@
+--TEST--
+ldap_unbind() - ldap_unbind() operations that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+// Too few parameters
+var_dump(ldap_unbind());
+
+// Too many parameters
+var_dump(ldap_unbind($link, "Additional data"));
+
+// Bad parameter
+var_dump(ldap_unbind("string"));
+
+// unbind twice
+var_dump(ldap_unbind($link));
+var_dump(ldap_unbind($link));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_unbind() expects exactly 1 parameter, 0 given in %s on line %d
+bool(false)
+
+Warning: ldap_unbind() expects exactly 1 parameter, 2 given in %s on line %d
+bool(false)
+
+Warning: ldap_unbind() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d
+bool(false)
+bool(true)
+
+Warning: ldap_unbind(): %d is not a valid ldap link resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_unbind_variation.phpt b/ext/ldap/tests/ldap_unbind_variation.phpt
new file mode 100644
index 0000000..377018c
--- /dev/null
+++ b/ext/ldap/tests/ldap_unbind_variation.phpt
@@ -0,0 +1,34 @@
+--TEST--
+ldap_unbind() - Variation of ldap_unbind() function using ldap_set_rebind_proc()
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+function rebind_proc ($ds, $ldap_url) {
+ global $user;
+ global $passwd;
+ global $protocol_version;
+
+ // required by most modern LDAP servers, use LDAPv3
+ ldap_set_option($a, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+
+ if (!ldap_bind($a, $user, $passwd)) {
+ print "Cannot bind";
+ }
+}
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+ldap_set_rebind_proc($link, "rebind_proc");
+
+var_dump(ldap_unbind($link));
+?>
+===DONE===
+--EXPECT--
+bool(true)
+===DONE===
diff --git a/ext/ldap/tests/skipif.inc b/ext/ldap/tests/skipif.inc
new file mode 100644
index 0000000..d349428
--- /dev/null
+++ b/ext/ldap/tests/skipif.inc
@@ -0,0 +1,5 @@
+<?php
+if (!extension_loaded('ldap')){
+ die('skip ldap extension not available');
+}
+?>
diff --git a/ext/ldap/tests/skipifbindfailure.inc b/ext/ldap/tests/skipifbindfailure.inc
new file mode 100644
index 0000000..f79bb9d
--- /dev/null
+++ b/ext/ldap/tests/skipifbindfailure.inc
@@ -0,0 +1,13 @@
+<?php
+require_once 'connect.inc';
+
+if ($skip_on_bind_failure) {
+
+ $link = ldap_connect($host, $port);
+ ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+ if (!@ldap_bind($link, $user, $passwd))
+ die(sprintf("skip Can't bind to LDAP Server - [%d] %s", ldap_errno($link), ldap_error($link)));
+
+ ldap_unbind($link);
+}
+?>