1999-04-22 08:45:14 +08:00
/*
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2014-09-20 00:33:14 +08:00
| PHP Version 7 |
1999-04-22 08:45:14 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2017-01-05 01:14:55 +08:00
| Copyright ( c ) 1997 - 2017 The PHP Group |
1999-04-22 08:45:14 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2006-01-01 20:51:34 +08:00
| This source file is subject to version 3.01 of the PHP license , |
1999-07-16 21:13:16 +08:00
| that is bundled with this package in the file LICENSE , and is |
2003-06-11 04:04:29 +08:00
| available through the world - wide - web at the following url : |
2006-01-01 20:51:34 +08:00
| http : //www.php.net/license/3_01.txt |
1999-07-16 21:13:16 +08:00
| 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 . |
1999-04-22 08:45:14 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| Authors : Amitay Isaacs < amitay @ w - o - i . com > |
| Eric Warnke < ericw @ albany . edu > |
2002-02-28 16:29:35 +08:00
| Rasmus Lerdorf < rasmus @ php . net > |
1999-05-21 18:06:25 +08:00
| Gerrit Thomson < 334647 @ swin . edu . au > |
2000-07-25 23:34:28 +08:00
| Jani Taskinen < sniper @ iki . fi > |
2000-08-27 00:20:37 +08:00
| Stig Venaas < venaas @ uninett . no > |
2007-03-23 05:50:34 +08:00
| Doug Goldstein < cardoe @ cardoe . com > |
2000-04-02 00:23:39 +08:00
| PHP 4.0 updates : Zeev Suraski < zeev @ zend . com > |
1999-04-22 08:45:14 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
*/
2015-01-03 17:22:58 +08:00
1999-04-22 08:45:14 +08:00
/* $Id$ */
# define IS_EXT_MODULE
2001-05-24 18:07:29 +08:00
# ifdef HAVE_CONFIG_H
# include "config.h"
# endif
2002-09-05 19:22:20 +08:00
/* Additional headers for NetWare */
# if defined(NETWARE) && (NEW_LIBC)
# include <sys/select.h>
# include <sys/timeval.h>
# endif
1999-04-22 08:45:14 +08:00
# include "php.h"
2000-04-02 00:23:39 +08:00
# include "php_ini.h"
2008-06-02 16:46:41 +08:00
2002-11-05 22:18:20 +08:00
# include <stddef.h>
1999-04-23 11:28:47 +08:00
# include "ext/standard/dl.h"
1999-12-05 03:19:57 +08:00
# include "php_ldap.h"
1999-04-22 08:45:14 +08:00
2000-02-16 17:33:19 +08:00
# ifdef PHP_WIN32
1999-04-22 08:45:14 +08:00
# include <string.h>
2010-05-18 04:09:42 +08:00
# include "config.w32.h"
1999-04-22 08:45:14 +08:00
# if HAVE_NSLDAP
2003-02-16 11:48:49 +08:00
# include <winsock2.h>
1999-04-22 08:45:14 +08:00
# endif
2008-06-02 16:46:41 +08:00
# define strdup _strdup
1999-04-22 08:45:14 +08:00
# undef WINDOWS
# undef strcasecmp
# undef strncasecmp
# define WINSOCK 1
# define __STDC__ 1
# endif
1999-12-05 03:19:57 +08:00
# include "ext/standard/php_string.h"
2000-04-07 00:57:33 +08:00
# include "ext/standard/info.h"
1999-04-22 08:45:14 +08:00
2003-06-13 21:30:46 +08:00
# ifdef HAVE_LDAP_SASL_H
# include <sasl.h>
# elif defined(HAVE_LDAP_SASL_SASL_H)
# include <sasl/sasl.h>
# endif
2013-09-17 23:34:30 +08:00
# define PHP_LDAP_ESCAPE_FILTER 0x01
# define PHP_LDAP_ESCAPE_DN 0x02
2015-08-18 22:52:44 +08:00
# if defined(LDAP_CONTROL_PAGEDRESULTS) && !defined(HAVE_LDAP_CONTROL_FIND)
2015-07-06 20:54:04 +08:00
LDAPControl * ldap_control_find ( const char * oid , LDAPControl * * ctrls , LDAPControl * * * nextctrlp )
{
2015-08-18 22:52:44 +08:00
assert ( nextctrlp = = NULL ) ;
return ldap_find_control ( oid , ctrls ) ;
}
# endif
# if !defined(LDAP_API_FEATURE_X_OPENLDAP)
void ldap_memvfree ( void * * v )
{
ldap_value_free ( ( char * * ) v ) ;
2015-07-06 20:54:04 +08:00
}
# endif
2001-11-30 04:17:17 +08:00
typedef struct {
LDAP * link ;
2015-08-18 22:52:44 +08:00
# if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
2014-05-20 11:26:26 +08:00
zval rebindproc ;
2001-11-30 04:26:20 +08:00
# endif
2001-11-30 04:17:17 +08:00
} ldap_linkdata ;
2002-05-04 22:27:48 +08:00
typedef struct {
LDAPMessage * data ;
2014-05-20 11:26:26 +08:00
BerElement * ber ;
zval res ;
2002-05-04 22:27:48 +08:00
} ldap_resultentry ;
2000-04-02 00:23:39 +08:00
ZEND_DECLARE_MODULE_GLOBALS ( ldap )
2006-06-16 02:33:09 +08:00
static PHP_GINIT_FUNCTION ( ldap ) ;
1999-04-22 08:45:14 +08:00
2007-07-13 09:24:16 +08:00
static int le_link , le_result , le_result_entry ;
1999-04-22 08:45:14 +08:00
2000-05-23 17:33:51 +08:00
# ifdef COMPILE_DL_LDAP
2000-05-02 08:30:36 +08:00
ZEND_GET_MODULE ( ldap )
1999-04-22 08:45:14 +08:00
# endif
2014-12-14 06:06:14 +08:00
static void _close_ldap_link ( zend_resource * rsrc ) /* { { { */
1999-04-22 08:45:14 +08:00
{
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld = ( ldap_linkdata * ) rsrc - > ptr ;
1999-04-22 08:45:14 +08:00
2015-04-16 23:11:38 +08:00
ldap_unbind_ext ( ld - > link , NULL , NULL ) ;
2015-08-18 22:52:44 +08:00
# if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
2014-05-20 11:26:26 +08:00
zval_ptr_dtor ( & ld - > rebindproc ) ;
2001-11-30 04:26:20 +08:00
# endif
2015-04-16 23:11:38 +08:00
2001-11-30 04:17:17 +08:00
efree ( ld ) ;
2000-04-02 00:23:39 +08:00
LDAPG ( num_links ) - - ;
1999-04-22 08:45:14 +08:00
}
2008-04-16 22:21:04 +08:00
/* }}} */
1999-04-22 08:45:14 +08:00
2014-12-14 06:06:14 +08:00
static void _free_ldap_result ( zend_resource * rsrc ) /* { { { */
1999-04-22 08:45:14 +08:00
{
2000-10-21 02:25:16 +08:00
LDAPMessage * result = ( LDAPMessage * ) rsrc - > ptr ;
2000-04-02 00:23:39 +08:00
ldap_msgfree ( result ) ;
1999-04-22 08:45:14 +08:00
}
2008-04-16 22:21:04 +08:00
/* }}} */
1999-04-22 08:45:14 +08:00
2014-12-14 06:06:14 +08:00
static void _free_ldap_result_entry ( zend_resource * rsrc ) /* { { { */
2002-05-04 22:27:48 +08:00
{
ldap_resultentry * entry = ( ldap_resultentry * ) rsrc - > ptr ;
2007-07-13 09:24:16 +08:00
if ( entry - > ber ! = NULL ) {
ber_free ( entry - > ber , 0 ) ;
2009-08-18 20:44:32 +08:00
entry - > ber = NULL ;
2007-07-13 09:24:16 +08:00
}
2014-05-20 11:26:26 +08:00
zval_ptr_dtor ( & entry - > res ) ;
2002-05-04 22:27:48 +08:00
efree ( entry ) ;
2015-01-03 17:22:58 +08:00
}
2008-04-16 22:21:04 +08:00
/* }}} */
2002-05-04 22:27:48 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ PHP_INI_BEGIN
*/
2000-04-02 00:23:39 +08:00
PHP_INI_BEGIN ( )
2003-06-09 07:34:51 +08:00
STD_PHP_INI_ENTRY_EX ( " ldap.max_links " , " -1 " , PHP_INI_SYSTEM , OnUpdateLong , max_links , zend_ldap_globals , ldap_globals , display_link_numbers )
2000-04-02 00:23:39 +08:00
PHP_INI_END ( )
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-22 08:45:14 +08:00
2006-06-16 02:33:09 +08:00
/* {{{ PHP_GINIT_FUNCTION
2001-06-05 21:12:10 +08:00
*/
2006-06-16 02:33:09 +08:00
static PHP_GINIT_FUNCTION ( ldap )
1999-04-22 08:45:14 +08:00
{
2000-04-02 00:23:39 +08:00
ldap_globals - > num_links = 0 ;
1999-04-22 08:45:14 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-22 08:45:14 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ PHP_MINIT_FUNCTION
*/
1999-08-02 23:02:52 +08:00
PHP_MINIT_FUNCTION ( ldap )
1999-04-22 08:45:14 +08:00
{
2000-04-02 00:23:39 +08:00
REGISTER_INI_ENTRIES ( ) ;
1999-04-22 08:45:14 +08:00
2000-07-24 05:32:02 +08:00
/* Constants to be used with deref-parameter in php_ldap_do_search() */
2014-08-26 01:24:55 +08:00
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 ) ;
2000-10-18 00:06:04 +08:00
2014-01-23 01:54:11 +08:00
/* Constants to be used with ldap_modify_batch() */
2014-08-26 01:24:55 +08:00
REGISTER_LONG_CONSTANT ( " LDAP_MODIFY_BATCH_ADD " , LDAP_MODIFY_BATCH_ADD , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " LDAP_MODIFY_BATCH_REMOVE " , LDAP_MODIFY_BATCH_REMOVE , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " LDAP_MODIFY_BATCH_REMOVE_ALL " , LDAP_MODIFY_BATCH_REMOVE_ALL , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " LDAP_MODIFY_BATCH_REPLACE " , LDAP_MODIFY_BATCH_REPLACE , CONST_PERSISTENT | CONST_CS ) ;
2014-01-23 01:54:11 +08:00
REGISTER_STRING_CONSTANT ( " LDAP_MODIFY_BATCH_ATTRIB " , LDAP_MODIFY_BATCH_ATTRIB , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_STRING_CONSTANT ( " LDAP_MODIFY_BATCH_MODTYPE " , LDAP_MODIFY_BATCH_MODTYPE , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_STRING_CONSTANT ( " LDAP_MODIFY_BATCH_VALUES " , LDAP_MODIFY_BATCH_VALUES , CONST_PERSISTENT | CONST_CS ) ;
2013-10-05 06:50:16 +08:00
# if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP
2000-10-18 00:06:04 +08:00
/* LDAP options */
2014-08-26 01:24:55 +08:00
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 ) ;
2007-10-06 09:43:26 +08:00
# ifdef LDAP_OPT_NETWORK_TIMEOUT
2014-08-26 01:24:55 +08:00
REGISTER_LONG_CONSTANT ( " LDAP_OPT_NETWORK_TIMEOUT " , LDAP_OPT_NETWORK_TIMEOUT , CONST_PERSISTENT | CONST_CS ) ;
2007-10-06 10:13:50 +08:00
# elif defined (LDAP_X_OPT_CONNECT_TIMEOUT)
2014-08-26 01:24:55 +08:00
REGISTER_LONG_CONSTANT ( " LDAP_OPT_NETWORK_TIMEOUT " , LDAP_X_OPT_CONNECT_TIMEOUT , CONST_PERSISTENT | CONST_CS ) ;
2015-09-10 00:02:10 +08:00
# endif
# ifdef LDAP_OPT_TIMEOUT
REGISTER_LONG_CONSTANT ( " LDAP_OPT_TIMEOUT " , LDAP_OPT_TIMEOUT , CONST_PERSISTENT | CONST_CS ) ;
2007-10-06 09:43:26 +08:00
# endif
2014-08-26 01:24:55 +08:00
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 ) ;
2002-07-10 04:54:49 +08:00
# ifdef LDAP_OPT_RESTART
2014-08-26 01:24:55 +08:00
REGISTER_LONG_CONSTANT ( " LDAP_OPT_RESTART " , LDAP_OPT_RESTART , CONST_PERSISTENT | CONST_CS ) ;
2002-07-10 04:54:49 +08:00
# endif
2005-05-08 23:43:22 +08:00
# ifdef LDAP_OPT_HOST_NAME
2014-08-26 01:24:55 +08:00
REGISTER_LONG_CONSTANT ( " LDAP_OPT_HOST_NAME " , LDAP_OPT_HOST_NAME , CONST_PERSISTENT | CONST_CS ) ;
2005-05-08 23:43:22 +08:00
# endif
2014-08-26 01:24:55 +08:00
REGISTER_LONG_CONSTANT ( " LDAP_OPT_ERROR_STRING " , LDAP_OPT_ERROR_STRING , CONST_PERSISTENT | CONST_CS ) ;
2001-01-08 05:18:02 +08:00
# ifdef LDAP_OPT_MATCHED_DN
2014-08-26 01:24:55 +08:00
REGISTER_LONG_CONSTANT ( " LDAP_OPT_MATCHED_DN " , LDAP_OPT_MATCHED_DN , CONST_PERSISTENT | CONST_CS ) ;
2000-10-18 00:06:04 +08:00
# endif
2014-08-26 01:24:55 +08:00
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 ) ;
2000-11-04 06:53:49 +08:00
# endif
2001-12-24 00:32:06 +08:00
# ifdef LDAP_OPT_DEBUG_LEVEL
2014-08-26 01:24:55 +08:00
REGISTER_LONG_CONSTANT ( " LDAP_OPT_DEBUG_LEVEL " , LDAP_OPT_DEBUG_LEVEL , CONST_PERSISTENT | CONST_CS ) ;
2001-12-24 00:32:06 +08:00
# endif
2000-10-18 00:06:04 +08:00
2015-05-06 03:30:29 +08:00
# ifdef LDAP_OPT_DIAGNOSTIC_MESSAGE
REGISTER_LONG_CONSTANT ( " LDAP_OPT_DIAGNOSTIC_MESSAGE " , LDAP_OPT_DIAGNOSTIC_MESSAGE , CONST_PERSISTENT | CONST_CS ) ;
# endif
2005-04-18 00:25:59 +08:00
# ifdef HAVE_LDAP_SASL
2014-08-26 01:24:55 +08:00
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 ) ;
2005-04-18 00:25:59 +08:00
# endif
2000-08-21 02:47:14 +08:00
# ifdef ORALDAP
2014-08-26 01:24:55 +08:00
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 ) ;
2000-08-21 02:47:14 +08:00
# endif
2000-07-22 08:34:22 +08:00
2016-02-16 16:39:58 +08:00
# if (LDAP_API_VERSION > 2000)
REGISTER_LONG_CONSTANT ( " LDAP_OPT_X_TLS_REQUIRE_CERT " , LDAP_OPT_X_TLS_REQUIRE_CERT , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " LDAP_OPT_X_TLS_NEVER " , LDAP_OPT_X_TLS_NEVER , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " LDAP_OPT_X_TLS_HARD " , LDAP_OPT_X_TLS_HARD , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " LDAP_OPT_X_TLS_DEMAND " , LDAP_OPT_X_TLS_DEMAND , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " LDAP_OPT_X_TLS_ALLOW " , LDAP_OPT_X_TLS_ALLOW , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " LDAP_OPT_X_TLS_TRY " , LDAP_OPT_X_TLS_TRY , CONST_PERSISTENT | CONST_CS ) ;
# endif
2014-08-26 01:24:55 +08:00
REGISTER_LONG_CONSTANT ( " LDAP_ESCAPE_FILTER " , PHP_LDAP_ESCAPE_FILTER , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " LDAP_ESCAPE_DN " , PHP_LDAP_ESCAPE_DN , CONST_PERSISTENT | CONST_CS ) ;
2013-09-17 23:34:30 +08:00
2000-10-26 01:44:02 +08:00
le_link = zend_register_list_destructors_ex ( _close_ldap_link , NULL , " ldap link " , module_number ) ;
2007-07-13 09:24:16 +08:00
le_result = zend_register_list_destructors_ex ( _free_ldap_result , NULL , " ldap result " , module_number ) ;
2002-05-04 22:27:48 +08:00
le_result_entry = zend_register_list_destructors_ex ( _free_ldap_result_entry , NULL , " ldap result entry " , module_number ) ;
1999-04-22 08:45:14 +08:00
2014-05-20 11:26:26 +08:00
ldap_module_entry . type = type ;
1999-04-22 08:45:14 +08:00
return SUCCESS ;
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-22 08:45:14 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ PHP_MSHUTDOWN_FUNCTION
*/
1999-08-02 23:02:52 +08:00
PHP_MSHUTDOWN_FUNCTION ( ldap )
{
2004-05-12 18:15:48 +08:00
UNREGISTER_INI_ENTRIES ( ) ;
1999-04-22 08:45:14 +08:00
return SUCCESS ;
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-22 08:45:14 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ PHP_MINFO_FUNCTION
*/
1999-08-02 23:02:52 +08:00
PHP_MINFO_FUNCTION ( ldap )
1999-04-22 08:45:14 +08:00
{
2000-06-05 23:17:25 +08:00
char tmp [ 32 ] ;
2001-12-25 22:36:06 +08:00
# if HAVE_NSLDAP
1999-04-22 08:45:14 +08:00
LDAPVersion ver ;
double SDKVersion ;
# endif
2000-04-04 06:00:18 +08:00
2001-12-25 22:36:06 +08:00
php_info_print_table_start ( ) ;
2003-06-09 07:34:51 +08:00
php_info_print_table_row ( 2 , " LDAP Support " , " enabled " ) ;
php_info_print_table_row ( 2 , " RCS Version " , " $Id$ " ) ;
2000-04-04 06:00:18 +08:00
2000-04-02 00:23:39 +08:00
if ( LDAPG ( max_links ) = = - 1 ) {
2014-08-26 02:22:49 +08:00
snprintf ( tmp , 31 , ZEND_LONG_FMT " /unlimited " , LDAPG ( num_links ) ) ;
1999-04-22 08:45:14 +08:00
} else {
2014-08-26 02:22:49 +08:00
snprintf ( tmp , 31 , ZEND_LONG_FMT " / " ZEND_LONG_FMT , LDAPG ( num_links ) , LDAPG ( max_links ) ) ;
1999-04-22 08:45:14 +08:00
}
2001-12-25 22:36:06 +08:00
php_info_print_table_row ( 2 , " Total Links " , tmp ) ;
2001-06-01 05:09:30 +08:00
2000-08-07 11:18:00 +08:00
# ifdef LDAP_API_VERSION
2001-12-25 22:36:06 +08:00
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
2008-06-02 19:23:16 +08:00
2001-12-25 22:36:06 +08:00
# ifdef LDAP_VENDOR_VERSION
snprintf ( tmp , 31 , " %d " , LDAP_VENDOR_VERSION ) ;
php_info_print_table_row ( 2 , " Vendor Version " , tmp ) ;
2000-08-07 11:18:00 +08:00
# endif
2000-04-07 05:17:50 +08:00
2001-06-01 05:09:30 +08:00
# if HAVE_NSLDAP
2003-06-09 07:34:51 +08:00
SDKVersion = ldap_version ( & ver ) ;
2007-01-05 23:06:55 +08:00
snprintf ( tmp , 31 , " %F " , SDKVersion / 100.0 ) ;
2003-06-09 07:34:51 +08:00
php_info_print_table_row ( 2 , " SDK Version " , tmp ) ;
2000-04-07 05:17:50 +08:00
2007-01-05 23:06:55 +08:00
snprintf ( tmp , 31 , " %F " , ver . protocol_version / 100.0 ) ;
2003-06-09 07:34:51 +08:00
php_info_print_table_row ( 2 , " Highest LDAP Protocol Supported " , tmp ) ;
2000-04-07 05:17:50 +08:00
2007-01-05 23:06:55 +08:00
snprintf ( tmp , 31 , " %F " , ver . SSL_version / 100.0 ) ;
2003-06-09 07:34:51 +08:00
php_info_print_table_row ( 2 , " SSL Level Supported " , tmp ) ;
2000-04-07 05:17:50 +08:00
2003-06-09 07:34:51 +08:00
if ( ver . security_level ! = LDAP_SECURITY_NONE ) {
snprintf ( tmp , 31 , " %d " , ver . security_level ) ;
1999-04-22 08:45:14 +08:00
} else {
2003-06-09 07:34:51 +08:00
strcpy ( tmp , " SSL not enabled " ) ;
1999-04-22 08:45:14 +08:00
}
2003-06-09 07:34:51 +08:00
php_info_print_table_row ( 2 , " Level of Encryption " , tmp ) ;
1999-04-22 08:45:14 +08:00
# endif
2000-04-07 05:17:50 +08:00
2003-06-13 21:30:46 +08:00
# ifdef HAVE_LDAP_SASL
php_info_print_table_row ( 2 , " SASL Support " , " Enabled " ) ;
# endif
2000-04-07 05:17:50 +08:00
php_info_print_table_end ( ) ;
2008-12-12 21:07:28 +08:00
DISPLAY_INI_ENTRIES ( ) ;
1999-04-22 08:45:14 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
2000-07-24 05:32:02 +08:00
2009-04-21 20:26:19 +08:00
/* {{{ proto resource ldap_connect([string host [, int port [, string wallet [, string wallet_passwd [, int authmode]]]]])
1999-04-22 08:45:14 +08:00
Connect to an LDAP server */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( ldap_connect )
1999-04-22 08:45:14 +08:00
{
2001-11-14 02:05:47 +08:00
char * host = NULL ;
2015-06-17 20:48:19 +08:00
size_t hostlen = 0 ;
2015-06-23 21:50:14 +08:00
zend_long port = LDAP_PORT ;
2000-08-21 02:47:14 +08:00
# ifdef HAVE_ORALDAP
2007-05-01 05:40:02 +08:00
char * wallet = NULL , * walletpasswd = NULL ;
2014-08-27 21:31:48 +08:00
size_t walletlen = 0 , walletpasswdlen = 0 ;
2014-08-26 01:24:55 +08:00
zend_long authmode = GSLC_SSL_NO_AUTH ;
2000-08-21 02:47:14 +08:00
int ssl = 0 ;
# endif
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2015-04-16 23:11:38 +08:00
LDAP * ldap = NULL ;
1999-04-22 08:45:14 +08:00
2000-08-21 02:47:14 +08:00
# ifdef HAVE_ORALDAP
2002-08-06 05:14:14 +08:00
if ( ZEND_NUM_ARGS ( ) = = 3 | | ZEND_NUM_ARGS ( ) = = 4 ) {
WRONG_PARAM_COUNT ;
}
2000-08-21 02:47:14 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " |slssl " , & host , & hostlen , & port , & wallet , & walletlen , & walletpasswd , & walletpasswdlen , & authmode ) ! = SUCCESS ) {
2002-08-06 05:14:14 +08:00
RETURN_FALSE ;
}
1999-04-22 08:45:14 +08:00
2003-06-09 07:34:51 +08:00
if ( ZEND_NUM_ARGS ( ) = = 5 ) {
2002-08-06 05:14:14 +08:00
ssl = 1 ;
1999-04-22 08:45:14 +08:00
}
2002-08-06 05:14:14 +08:00
# else
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " |sl " , & host , & hostlen , & port ) ! = SUCCESS ) {
2002-08-06 05:14:14 +08:00
RETURN_FALSE ;
}
# endif
1999-04-22 08:45:14 +08:00
2001-06-01 05:09:30 +08:00
if ( LDAPG ( max_links ) ! = - 1 & & LDAPG ( num_links ) > = LDAPG ( max_links ) ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Too many open links (%pd) " , LDAPG ( num_links ) ) ;
2000-04-02 00:23:39 +08:00
RETURN_FALSE ;
1999-04-22 08:45:14 +08:00
}
2001-11-30 04:17:17 +08:00
ld = ecalloc ( 1 , sizeof ( ldap_linkdata ) ) ;
2015-04-16 23:11:38 +08:00
{
2015-08-18 22:52:44 +08:00
int rc = LDAP_SUCCESS ;
2015-04-16 23:11:38 +08:00
char * url = host ;
if ( ! ldap_is_ldap_url ( url ) ) {
int urllen = hostlen + sizeof ( " ldap://:65535 " ) ;
if ( port < = 0 | | port > 65535 ) {
2016-08-30 00:01:21 +08:00
efree ( ld ) ;
2015-06-17 20:48:19 +08:00
php_error_docref ( NULL , E_WARNING , " invalid port number: %ld " , port ) ;
2015-04-16 23:11:38 +08:00
RETURN_FALSE ;
}
url = emalloc ( urllen ) ;
2015-11-23 10:08:25 +08:00
snprintf ( url , urllen , " ldap://%s:%ld " , host ? host : " " , port ) ;
2015-04-16 23:11:38 +08:00
}
2015-01-03 17:22:58 +08:00
2015-08-18 22:52:44 +08:00
# ifdef LDAP_API_FEATURE_X_OPENLDAP
/* ldap_init() is deprecated, use ldap_initialize() instead.
*/
2015-04-16 23:11:38 +08:00
rc = ldap_initialize ( & ldap , url ) ;
2015-08-18 22:52:44 +08:00
# else /* ! LDAP_API_FEATURE_X_OPENLDAP */
/* ldap_init does not support URLs.
* We must try the original host and port information .
*/
ldap = ldap_init ( host , port ) ;
if ( ldap = = NULL ) {
efree ( ld ) ;
2015-08-18 23:26:46 +08:00
php_error_docref ( NULL , E_WARNING , " Could not create session handle " ) ;
2015-08-18 22:52:44 +08:00
RETURN_FALSE ;
}
# endif /* ! LDAP_API_FEATURE_X_OPENLDAP */
2015-04-16 23:11:38 +08:00
if ( url ! = host ) {
efree ( url ) ;
}
2000-10-21 04:22:59 +08:00
if ( rc ! = LDAP_SUCCESS ) {
2002-10-31 02:12:34 +08:00
efree ( ld ) ;
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Could not create session handle: %s " , ldap_err2string ( rc ) ) ;
2000-10-21 04:22:59 +08:00
RETURN_FALSE ;
}
}
2015-01-03 17:22:58 +08:00
2003-06-09 07:34:51 +08:00
if ( ldap = = NULL ) {
2002-10-31 02:12:34 +08:00
efree ( ld ) ;
2000-04-02 00:23:39 +08:00
RETURN_FALSE ;
1999-04-22 08:45:14 +08:00
} else {
2000-08-21 02:47:14 +08:00
# ifdef HAVE_ORALDAP
if ( ssl ) {
2001-06-01 05:09:30 +08:00
if ( ldap_init_SSL ( & ldap - > ld_sb , wallet , walletpasswd , authmode ) ) {
2002-10-31 02:12:34 +08:00
efree ( ld ) ;
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " SSL init failed " ) ;
2000-08-21 02:47:14 +08:00
RETURN_FALSE ;
}
2015-01-03 17:22:58 +08:00
}
2000-08-21 02:47:14 +08:00
# endif
2001-06-01 05:09:30 +08:00
LDAPG ( num_links ) + + ;
2001-11-30 04:17:17 +08:00
ld - > link = ldap ;
2015-02-02 15:05:20 +08:00
RETURN_RES ( zend_register_resource ( ld , le_link ) ) ;
1999-04-22 08:45:14 +08:00
}
}
/* }}} */
2001-06-05 21:12:10 +08:00
/* {{{ _get_lderrno
*/
2000-08-27 00:20:37 +08:00
static int _get_lderrno ( LDAP * ldap )
{
# if !HAVE_NSLDAP
2013-10-05 06:50:16 +08:00
# if LDAP_API_VERSION > 2000 || HAVE_ORALDAP
2000-08-27 00:20:37 +08:00
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
2001-08-12 00:39:07 +08:00
return ldap_get_lderrno ( ldap , NULL , NULL ) ;
2000-08-27 00:20:37 +08:00
# endif
}
2001-06-05 21:12:10 +08:00
/* }}} */
2000-08-27 00:20:37 +08:00
2014-09-28 12:49:35 +08:00
/* {{{ _set_lderrno
*/
static void _set_lderrno ( LDAP * ldap , int lderr )
{
# if !HAVE_NSLDAP
# if LDAP_API_VERSION > 2000 || HAVE_ORALDAP
/* New versions of OpenLDAP do it this way */
ldap_set_option ( ldap , LDAP_OPT_ERROR_NUMBER , & lderr ) ;
# else
ldap - > ld_errno = lderr ;
# endif
# else
ldap_set_lderrno ( ldap , lderr , NULL , NULL ) ;
# endif
}
/* }}} */
2008-05-05 05:17:33 +08:00
/* {{{ proto bool ldap_bind(resource link [, string dn [, string password]])
1999-04-22 08:45:14 +08:00
Bind to LDAP directory */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( ldap_bind )
1999-04-22 08:45:14 +08:00
{
2002-08-06 05:14:14 +08:00
zval * link ;
char * ldap_bind_dn = NULL , * ldap_bind_pw = NULL ;
2014-08-27 21:31:48 +08:00
size_t ldap_bind_dnlen , ldap_bind_pwlen ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2002-06-26 14:49:25 +08:00
int rc ;
1999-04-22 08:45:14 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " r|ss " , & link , & ldap_bind_dn , & ldap_bind_dnlen , & ldap_bind_pw , & ldap_bind_pwlen ) ! = SUCCESS ) {
2002-08-06 05:14:14 +08:00
RETURN_FALSE ;
}
1999-04-22 08:45:14 +08:00
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
2014-09-28 12:49:35 +08:00
2014-04-14 11:43:46 +08:00
if ( ldap_bind_dn ! = NULL & & memchr ( ldap_bind_dn , ' \0 ' , ldap_bind_dnlen ) ! = NULL ) {
2014-09-28 12:49:35 +08:00
_set_lderrno ( ld - > link , LDAP_INVALID_CREDENTIALS ) ;
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " DN contains a null byte " ) ;
2014-04-14 11:43:46 +08:00
RETURN_FALSE ;
}
if ( ldap_bind_pw ! = NULL & & memchr ( ldap_bind_pw , ' \0 ' , ldap_bind_pwlen ) ! = NULL ) {
2014-09-28 12:49:35 +08:00
_set_lderrno ( ld - > link , LDAP_INVALID_CREDENTIALS ) ;
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Password contains a null byte " ) ;
2014-04-14 11:43:46 +08:00
RETURN_FALSE ;
}
2015-04-16 23:11:38 +08:00
{
2015-08-18 22:52:44 +08:00
# ifdef LDAP_API_FEATURE_X_OPENLDAP
/* ldap_simple_bind_s() is deprecated, use ldap_sasl_bind_s() instead.
*/
2015-04-16 23:11:38 +08:00
struct berval cred ;
cred . bv_val = ldap_bind_pw ;
cred . bv_len = ldap_bind_pw ? ldap_bind_pwlen : 0 ;
rc = ldap_sasl_bind_s ( ld - > link , ldap_bind_dn , LDAP_SASL_SIMPLE , & cred ,
NULL , NULL , /* no controls right now */
NULL ) ; /* we don't care about the server's credentials */
2015-08-18 22:52:44 +08:00
# else /* ! LDAP_API_FEATURE_X_OPENLDAP */
rc = ldap_simple_bind_s ( ld - > link , ldap_bind_dn , ldap_bind_pw ) ;
# endif /* ! LDAP_API_FEATURE_X_OPENLDAP */
2015-04-16 23:11:38 +08:00
}
if ( rc ! = LDAP_SUCCESS ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to bind to server: %s " , ldap_err2string ( rc ) ) ;
1999-04-22 08:45:14 +08:00
RETURN_FALSE ;
} else {
RETURN_TRUE ;
}
}
/* }}} */
2003-06-13 21:30:46 +08:00
# ifdef HAVE_LDAP_SASL
2005-04-18 00:25:59 +08:00
typedef struct {
char * mech ;
char * realm ;
char * authcid ;
char * passwd ;
char * authzid ;
} php_ldap_bictx ;
/* {{{ _php_sasl_setdefs
*/
2007-07-13 06:08:58 +08:00
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 )
2005-04-18 00:25:59 +08:00
{
php_ldap_bictx * ctx ;
2015-01-03 17:22:58 +08:00
ctx = ber_memalloc ( sizeof ( php_ldap_bictx ) ) ;
2005-04-18 00:25:59 +08:00
ctx - > mech = ( sasl_mech ) ? ber_strdup ( sasl_mech ) : NULL ;
ctx - > realm = ( sasl_realm ) ? ber_strdup ( sasl_realm ) : NULL ;
2007-07-13 06:08:58 +08:00
ctx - > authcid = ( sasl_authc_id ) ? ber_strdup ( sasl_authc_id ) : NULL ;
ctx - > passwd = ( passwd ) ? ber_strdup ( passwd ) : NULL ;
2005-04-18 00:25:59 +08:00
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 ;
}
2005-12-12 06:38:38 +08:00
/* }}} */
2005-04-18 00:25:59 +08:00
2005-12-12 06:38:38 +08:00
/* {{{ _php_sasl_freedefs
2005-04-18 00:25:59 +08:00
*/
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 ) ;
}
2005-12-12 06:38:38 +08:00
/* }}} */
2005-04-18 00:25:59 +08:00
2003-06-09 07:44:01 +08:00
/* {{{ _php_sasl_interact
2005-04-18 00:25:59 +08:00
Internal interact function for SASL */
2003-06-09 07:44:01 +08:00
static int _php_sasl_interact ( LDAP * ld , unsigned flags , void * defaults , void * in )
{
sasl_interact_t * interact = in ;
2005-04-18 00:25:59 +08:00
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 ) ;
}
}
2003-06-09 07:44:01 +08:00
return LDAP_SUCCESS ;
}
2005-12-12 06:38:38 +08:00
/* }}} */
2003-06-09 07:44:01 +08:00
2008-05-05 05:17:33 +08:00
/* {{{ 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]]]]]]])
2003-06-09 07:44:01 +08:00
Bind to LDAP directory using SASL */
PHP_FUNCTION ( ldap_sasl_bind )
{
zval * link ;
ldap_linkdata * ld ;
2005-04-18 00:25:59 +08:00
char * binddn = NULL ;
2007-07-13 06:08:58 +08:00
char * passwd = NULL ;
2005-04-18 00:25:59 +08:00
char * sasl_mech = NULL ;
char * sasl_realm = NULL ;
char * sasl_authz_id = NULL ;
2007-07-13 06:08:58 +08:00
char * sasl_authc_id = NULL ;
2005-04-18 00:25:59 +08:00
char * props = NULL ;
2014-08-28 15:43:14 +08:00
size_t rc , dn_len , passwd_len , mech_len , realm_len , authc_id_len , authz_id_len , props_len ;
2005-04-18 00:25:59 +08:00
php_ldap_bictx * ctx ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " 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 ) {
2003-06-09 07:44:01 +08:00
RETURN_FALSE ;
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
2003-06-09 07:44:01 +08:00
2007-07-13 06:08:58 +08:00
ctx = _php_sasl_setdefs ( ld - > link , sasl_mech , sasl_realm , sasl_authc_id , passwd , sasl_authz_id ) ;
2005-04-18 00:25:59 +08:00
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 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to bind to server: %s " , ldap_err2string ( rc ) ) ;
2005-04-18 00:25:59 +08:00
RETVAL_FALSE ;
2003-06-09 07:44:01 +08:00
} else {
2005-04-18 00:25:59 +08:00
RETVAL_TRUE ;
2003-06-09 07:44:01 +08:00
}
2005-04-18 00:25:59 +08:00
_php_sasl_freedefs ( ctx ) ;
2003-06-09 07:44:01 +08:00
}
/* }}} */
2003-06-13 21:30:46 +08:00
# endif /* HAVE_LDAP_SASL */
2003-06-09 07:44:01 +08:00
2002-02-11 10:48:49 +08:00
/* {{{ proto bool ldap_unbind(resource link)
1999-04-22 08:45:14 +08:00
Unbind from LDAP directory */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( ldap_unbind )
1999-04-22 08:45:14 +08:00
{
2002-08-06 05:14:14 +08:00
zval * link ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
1999-04-22 08:45:14 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " r " , & link ) ! = SUCCESS ) {
2002-08-06 05:14:14 +08:00
RETURN_FALSE ;
1999-04-22 08:45:14 +08:00
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-22 08:45:14 +08:00
2014-05-20 11:26:26 +08:00
zend_list_close ( Z_RES_P ( link ) ) ;
1999-04-22 08:45:14 +08:00
RETURN_TRUE ;
}
/* }}} */
2001-11-14 01:10:08 +08:00
/* {{{ php_set_opts
2001-06-05 21:12:10 +08:00
*/
2009-06-15 23:18:31 +08:00
static void php_set_opts ( LDAP * ldap , int sizelimit , int timelimit , int deref , int * old_sizelimit , int * old_timelimit , int * old_deref )
2001-01-13 06:08:26 +08:00
{
/* sizelimit */
if ( sizelimit > - 1 ) {
2013-10-05 06:50:16 +08:00
# if (LDAP_API_VERSION >= 2004) || HAVE_NSLDAP || HAVE_ORALDAP
2009-06-15 23:18:31 +08:00
ldap_get_option ( ldap , LDAP_OPT_SIZELIMIT , old_sizelimit ) ;
2001-01-13 06:08:26 +08:00
ldap_set_option ( ldap , LDAP_OPT_SIZELIMIT , & sizelimit ) ;
# else
2015-01-03 17:22:58 +08:00
* old_sizelimit = ldap - > ld_sizelimit ;
ldap - > ld_sizelimit = sizelimit ;
2001-01-13 06:08:26 +08:00
# endif
}
/* timelimit */
if ( timelimit > - 1 ) {
2013-10-05 06:50:16 +08:00
# if (LDAP_API_VERSION >= 2004) || HAVE_NSLDAP || HAVE_ORALDAP
2015-09-09 06:24:09 +08:00
ldap_get_option ( ldap , LDAP_OPT_TIMELIMIT , old_timelimit ) ;
2001-01-13 06:08:26 +08:00
ldap_set_option ( ldap , LDAP_OPT_TIMELIMIT , & timelimit ) ;
# else
2015-01-03 17:22:58 +08:00
* old_timelimit = ldap - > ld_timelimit ;
ldap - > ld_timelimit = timelimit ;
2001-01-13 06:08:26 +08:00
# endif
}
/* deref */
if ( deref > - 1 ) {
2013-10-05 06:50:16 +08:00
# if (LDAP_API_VERSION >= 2004) || HAVE_NSLDAP || HAVE_ORALDAP
2015-09-09 06:24:09 +08:00
ldap_get_option ( ldap , LDAP_OPT_DEREF , old_deref ) ;
2001-01-13 06:08:26 +08:00
ldap_set_option ( ldap , LDAP_OPT_DEREF , & deref ) ;
# else
2015-01-03 17:22:58 +08:00
* old_deref = ldap - > ld_deref ;
ldap - > ld_deref = deref ;
2001-01-13 06:08:26 +08:00
# endif
}
}
2001-06-05 21:12:10 +08:00
/* }}} */
2001-01-13 06:08:26 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ php_ldap_do_search
*/
1999-12-18 19:49:31 +08:00
static void php_ldap_do_search ( INTERNAL_FUNCTION_PARAMETERS , int scope )
1999-04-22 08:45:14 +08:00
{
2014-05-20 11:26:26 +08:00
zval * link , * base_dn , * filter , * attrs = NULL , * attr ;
2014-08-26 01:24:55 +08:00
zend_long attrsonly , sizelimit , timelimit , deref ;
2015-01-03 17:22:58 +08:00
char * ldap_base_dn = NULL , * ldap_filter = NULL , * * ldap_attrs = NULL ;
2009-06-25 23:19:29 +08:00
ldap_linkdata * ld = NULL ;
2001-06-01 05:09:30 +08:00
LDAPMessage * ldap_res ;
2015-01-03 17:22:58 +08:00
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 ;
2009-08-15 08:52:31 +08:00
int num_attribs = 0 , ret = 1 , i , errno , argcount = ZEND_NUM_ARGS ( ) ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( argcount , " zzz|allll " , & link , & base_dn , & filter , & attrs , & attrsonly ,
2008-06-29 22:29:09 +08:00
& sizelimit , & timelimit , & deref ) = = FAILURE ) {
return ;
2000-07-22 03:00:21 +08:00
}
1999-04-22 08:45:14 +08:00
2000-07-22 03:00:21 +08:00
/* Reverse -> fall through */
2009-08-15 08:52:31 +08:00
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 ) ) ;
2004-06-29 06:31:28 +08:00
ldap_attrs = safe_emalloc ( ( num_attribs + 1 ) , sizeof ( char * ) , 0 ) ;
1999-04-22 08:45:14 +08:00
2003-06-09 07:34:51 +08:00
for ( i = 0 ; i < num_attribs ; i + + ) {
2014-05-20 11:26:26 +08:00
if ( ( attr = zend_hash_index_find ( Z_ARRVAL_P ( attrs ) , i ) ) = = NULL ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Array initialization wrong " ) ;
2009-06-15 23:04:11 +08:00
ret = 0 ;
goto cleanup ;
1999-04-22 08:45:14 +08:00
}
2000-07-22 03:00:21 +08:00
1999-11-22 10:31:32 +08:00
convert_to_string_ex ( attr ) ;
2014-05-20 11:26:26 +08:00
ldap_attrs [ i ] = Z_STRVAL_P ( attr ) ;
1999-04-22 08:45:14 +08:00
}
ldap_attrs [ num_attribs ] = NULL ;
default :
2009-08-15 08:52:31 +08:00
break ;
1999-04-22 08:45:14 +08:00
}
2001-01-13 06:08:26 +08:00
/* parallel search? */
2009-08-15 08:52:31 +08:00
if ( Z_TYPE_P ( link ) = = IS_ARRAY ) {
2001-01-17 21:43:39 +08:00
int i , nlinks , nbases , nfilters , * rcs ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * * lds ;
2014-05-20 11:26:26 +08:00
zval * entry , resource ;
2015-01-03 17:22:58 +08:00
2009-08-15 08:52:31 +08:00
nlinks = zend_hash_num_elements ( Z_ARRVAL_P ( link ) ) ;
2001-01-13 06:08:26 +08:00
if ( nlinks = = 0 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " No links in link array " ) ;
2009-06-15 23:04:11 +08:00
ret = 0 ;
goto cleanup ;
2001-01-13 06:08:26 +08:00
}
2009-08-15 08:52:31 +08:00
if ( Z_TYPE_P ( base_dn ) = = IS_ARRAY ) {
nbases = zend_hash_num_elements ( Z_ARRVAL_P ( base_dn ) ) ;
2001-01-13 06:08:26 +08:00
if ( nbases ! = nlinks ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Base must either be a string, or an array with the same number of elements as the links array " ) ;
2009-06-15 23:04:11 +08:00
ret = 0 ;
goto cleanup ;
2001-01-13 06:08:26 +08:00
}
2009-08-15 08:52:31 +08:00
zend_hash_internal_pointer_reset ( Z_ARRVAL_P ( base_dn ) ) ;
2001-01-13 06:08:26 +08:00
} else {
nbases = 0 ; /* this means string, not array */
2005-07-09 08:46:45 +08:00
/* If anything else than string is passed, ldap_base_dn = NULL */
2009-08-15 08:52:31 +08:00
if ( Z_TYPE_P ( base_dn ) = = IS_STRING ) {
ldap_base_dn = Z_STRVAL_P ( base_dn ) ;
2005-07-09 08:46:45 +08:00
} else {
ldap_base_dn = NULL ;
}
2001-01-13 06:08:26 +08:00
}
2014-05-20 11:26:26 +08:00
if ( Z_TYPE_P ( filter ) = = IS_ARRAY ) {
nfilters = zend_hash_num_elements ( Z_ARRVAL_P ( filter ) ) ;
2001-01-17 21:43:39 +08:00
if ( nfilters ! = nlinks ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Filter must either be a string, or an array with the same number of elements as the links array " ) ;
2009-06-15 23:04:11 +08:00
ret = 0 ;
goto cleanup ;
2001-01-17 21:43:39 +08:00
}
2014-05-20 11:26:26 +08:00
zend_hash_internal_pointer_reset ( Z_ARRVAL_P ( filter ) ) ;
2001-01-17 21:43:39 +08:00
} else {
nfilters = 0 ; /* this means string, not array */
convert_to_string_ex ( filter ) ;
2014-05-20 11:26:26 +08:00
ldap_filter = Z_STRVAL_P ( filter ) ;
2001-01-17 21:43:39 +08:00
}
2003-05-01 05:53:53 +08:00
lds = safe_emalloc ( nlinks , sizeof ( ldap_linkdata ) , 0 ) ;
rcs = safe_emalloc ( nlinks , sizeof ( * rcs ) , 0 ) ;
2015-01-03 17:22:58 +08:00
2009-08-15 08:52:31 +08:00
zend_hash_internal_pointer_reset ( Z_ARRVAL_P ( link ) ) ;
2001-01-13 06:08:26 +08:00
for ( i = 0 ; i < nlinks ; i + + ) {
2014-05-20 11:26:26 +08:00
entry = zend_hash_get_current_data ( Z_ARRVAL_P ( link ) ) ;
2001-06-01 05:09:30 +08:00
2015-02-02 15:05:20 +08:00
ld = ( ldap_linkdata * ) zend_fetch_resource_ex ( entry , " ldap link " , le_link ) ;
2001-11-30 04:17:17 +08:00
if ( ld = = NULL ) {
2009-06-15 23:04:11 +08:00
ret = 0 ;
goto cleanup_parallel ;
2001-01-13 06:08:26 +08:00
}
if ( nbases ! = 0 ) { /* base_dn an array? */
2014-05-20 11:26:26 +08:00
entry = zend_hash_get_current_data ( Z_ARRVAL_P ( base_dn ) ) ;
2009-08-15 08:52:31 +08:00
zend_hash_move_forward ( Z_ARRVAL_P ( base_dn ) ) ;
2005-07-09 08:46:45 +08:00
/* If anything else than string is passed, ldap_base_dn = NULL */
2014-05-20 11:26:26 +08:00
if ( Z_TYPE_P ( entry ) = = IS_STRING ) {
ldap_base_dn = Z_STRVAL_P ( entry ) ;
2005-07-09 08:46:45 +08:00
} else {
ldap_base_dn = NULL ;
}
2001-01-13 06:08:26 +08:00
}
2001-01-17 21:43:39 +08:00
if ( nfilters ! = 0 ) { /* filter an array? */
2014-05-20 11:26:26 +08:00
entry = zend_hash_get_current_data ( Z_ARRVAL_P ( filter ) ) ;
zend_hash_move_forward ( Z_ARRVAL_P ( filter ) ) ;
2001-01-17 21:43:39 +08:00
convert_to_string_ex ( entry ) ;
2014-05-20 11:26:26 +08:00
ldap_filter = Z_STRVAL_P ( entry ) ;
2001-01-17 21:43:39 +08:00
}
2001-01-13 06:08:26 +08:00
2009-06-15 23:18:31 +08:00
php_set_opts ( ld - > link , ldap_sizelimit , ldap_timelimit , ldap_deref , & old_ldap_sizelimit , & old_ldap_timelimit , & old_ldap_deref ) ;
2001-01-13 06:08:26 +08:00
2015-01-03 17:22:58 +08:00
/* Run the actual search */
2015-06-23 22:44:48 +08:00
ldap_search_ext ( ld - > link , ldap_base_dn , scope , ldap_filter , ldap_attrs , ldap_attrsonly , NULL , NULL , NULL , ldap_sizelimit , & rcs [ i ] ) ;
2001-11-30 04:17:17 +08:00
lds [ i ] = ld ;
2009-08-15 08:52:31 +08:00
zend_hash_move_forward ( Z_ARRVAL_P ( link ) ) ;
2001-01-13 06:08:26 +08:00
}
2015-01-03 17:22:58 +08:00
2003-01-19 04:10:23 +08:00
array_init ( return_value ) ;
2001-01-13 06:08:26 +08:00
/* Collect results from the searches */
for ( i = 0 ; i < nlinks ; i + + ) {
if ( rcs [ i ] ! = - 1 ) {
2001-11-30 04:17:17 +08:00
rcs [ i ] = ldap_result ( lds [ i ] - > link , LDAP_RES_ANY , 1 /* LDAP_MSG_ALL */ , NULL , & ldap_res ) ;
2001-01-13 06:08:26 +08:00
}
if ( rcs [ i ] ! = - 1 ) {
2015-02-02 15:05:20 +08:00
ZVAL_RES ( & resource , zend_register_resource ( ldap_res , le_result ) ) ;
2014-05-20 11:26:26 +08:00
add_next_index_zval ( return_value , & resource ) ;
2001-01-13 06:08:26 +08:00
} else {
add_next_index_bool ( return_value , 0 ) ;
}
2001-12-27 02:40:57 +08:00
}
2009-06-15 23:04:11 +08:00
cleanup_parallel :
2001-11-30 04:17:17 +08:00
efree ( lds ) ;
2001-01-13 06:08:26 +08:00
efree ( rcs ) ;
2009-06-15 23:04:11 +08:00
} else {
convert_to_string_ex ( filter ) ;
2014-05-20 11:26:26 +08:00
ldap_filter = Z_STRVAL_P ( filter ) ;
2001-01-13 06:08:26 +08:00
2009-06-15 23:04:11 +08:00
/* If anything else than string is passed, ldap_base_dn = NULL */
2009-08-15 08:52:31 +08:00
if ( Z_TYPE_P ( base_dn ) = = IS_STRING ) {
ldap_base_dn = Z_STRVAL_P ( base_dn ) ;
2001-01-13 18:00:27 +08:00
}
2000-07-22 03:00:21 +08:00
2015-02-02 15:05:20 +08:00
ld = ( ldap_linkdata * ) zend_fetch_resource_ex ( link , " ldap link " , le_link ) ;
2009-06-15 23:04:11 +08:00
if ( ld = = NULL ) {
ret = 0 ;
goto cleanup ;
}
2000-07-22 03:00:21 +08:00
2009-06-15 23:18:31 +08:00
php_set_opts ( ld - > link , ldap_sizelimit , ldap_timelimit , ldap_deref , & old_ldap_sizelimit , & old_ldap_timelimit , & old_ldap_deref ) ;
2000-07-22 03:00:21 +08:00
2015-01-03 17:22:58 +08:00
/* Run the actual search */
2015-06-23 22:44:48 +08:00
errno = ldap_search_ext_s ( ld - > link , ldap_base_dn , scope , ldap_filter , ldap_attrs , ldap_attrsonly , NULL , NULL , NULL , ldap_sizelimit , & ldap_res ) ;
2015-01-03 17:22:58 +08:00
2009-06-15 23:04:11 +08:00
if ( errno ! = LDAP_SUCCESS
& & errno ! = LDAP_SIZELIMIT_EXCEEDED
2001-01-07 21:03:11 +08:00
# ifdef LDAP_ADMINLIMIT_EXCEEDED
2009-06-15 23:04:11 +08:00
& & errno ! = LDAP_ADMINLIMIT_EXCEEDED
2001-01-07 21:03:11 +08:00
# endif
# ifdef LDAP_REFERRAL
2009-06-15 23:04:11 +08:00
& & errno ! = LDAP_REFERRAL
2001-01-07 21:03:11 +08:00
# endif
2009-06-15 23:04:11 +08:00
) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Search: %s " , ldap_err2string ( errno ) ) ;
2009-06-15 23:04:11 +08:00
ret = 0 ;
} else {
if ( errno = = LDAP_SIZELIMIT_EXCEEDED ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Partial search results returned: Sizelimit exceeded " ) ;
2009-06-15 23:04:11 +08:00
}
2001-01-07 21:03:11 +08:00
# ifdef LDAP_ADMINLIMIT_EXCEEDED
2009-06-15 23:04:11 +08:00
else if ( errno = = LDAP_ADMINLIMIT_EXCEEDED ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Partial search results returned: Adminlimit exceeded " ) ;
2009-06-15 23:04:11 +08:00
}
2001-01-07 21:03:11 +08:00
# endif
2015-01-03 17:22:58 +08:00
2015-02-02 15:05:20 +08:00
RETVAL_RES ( zend_register_resource ( ldap_res , le_result ) ) ;
2009-06-15 23:04:11 +08:00
}
}
cleanup :
2009-06-25 23:19:29 +08:00
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 ) ;
}
2009-06-15 23:04:11 +08:00
if ( ldap_attrs ! = NULL ) {
efree ( ldap_attrs ) ;
}
if ( ! ret ) {
RETVAL_BOOL ( ret ) ;
1999-04-22 08:45:14 +08:00
}
}
2001-06-05 21:12:10 +08:00
/* }}} */
2000-07-22 03:00:21 +08:00
2009-08-15 08:52:31 +08:00
/* {{{ proto resource ldap_read(resource|array link, string base_dn, string filter [, array attrs [, int attrsonly [, int sizelimit [, int timelimit [, int deref]]]]])
1999-04-22 08:45:14 +08:00
Read an entry */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( ldap_read )
1999-04-22 08:45:14 +08:00
{
1999-12-18 19:49:31 +08:00
php_ldap_do_search ( INTERNAL_FUNCTION_PARAM_PASSTHRU , LDAP_SCOPE_BASE ) ;
1999-04-22 08:45:14 +08:00
}
/* }}} */
2009-08-15 08:52:31 +08:00
/* {{{ proto resource ldap_list(resource|array link, string base_dn, string filter [, array attrs [, int attrsonly [, int sizelimit [, int timelimit [, int deref]]]]])
1999-04-22 08:45:14 +08:00
Single - level search */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( ldap_list )
1999-04-22 08:45:14 +08:00
{
1999-12-18 19:49:31 +08:00
php_ldap_do_search ( INTERNAL_FUNCTION_PARAM_PASSTHRU , LDAP_SCOPE_ONELEVEL ) ;
1999-04-22 08:45:14 +08:00
}
/* }}} */
2009-08-15 08:52:31 +08:00
/* {{{ proto resource ldap_search(resource|array link, string base_dn, string filter [, array attrs [, int attrsonly [, int sizelimit [, int timelimit [, int deref]]]]])
1999-04-22 08:45:14 +08:00
Search LDAP tree under base_dn */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( ldap_search )
1999-04-22 08:45:14 +08:00
{
1999-12-18 19:49:31 +08:00
php_ldap_do_search ( INTERNAL_FUNCTION_PARAM_PASSTHRU , LDAP_SCOPE_SUBTREE ) ;
1999-04-22 08:45:14 +08:00
}
/* }}} */
2002-02-11 10:48:49 +08:00
/* {{{ proto bool ldap_free_result(resource result)
1999-04-22 08:45:14 +08:00
Free result memory */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( ldap_free_result )
1999-04-22 08:45:14 +08:00
{
2008-04-16 22:21:04 +08:00
zval * result ;
1999-07-17 02:01:55 +08:00
LDAPMessage * ldap_result ;
1999-04-22 08:45:14 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " r " , & result ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
1999-04-22 08:45:14 +08:00
}
2015-02-02 15:05:20 +08:00
if ( ( ldap_result = ( LDAPMessage * ) zend_fetch_resource ( Z_RES_P ( result ) , " ldap result " , le_result ) ) = = NULL ) {
RETURN_FALSE ;
}
2001-06-01 05:09:30 +08:00
2014-05-20 11:26:26 +08:00
zend_list_close ( Z_RES_P ( result ) ) ; /* Delete list entry */
2001-11-15 06:05:33 +08:00
RETVAL_TRUE ;
1999-04-22 08:45:14 +08:00
}
/* }}} */
2002-02-11 10:48:49 +08:00
/* {{{ proto int ldap_count_entries(resource link, resource result)
1999-04-22 08:45:14 +08:00
Count the number of entries in a search result */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( ldap_count_entries )
1999-04-22 08:45:14 +08:00
{
2008-04-16 22:21:04 +08:00
zval * link , * result ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
1999-07-17 02:01:55 +08:00
LDAPMessage * ldap_result ;
1999-04-22 08:45:14 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rr " , & link , & result ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
1999-04-22 08:45:14 +08:00
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( ldap_result = ( LDAPMessage * ) zend_fetch_resource ( Z_RES_P ( result ) , " ldap result " , le_result ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-22 08:45:14 +08:00
2014-08-26 01:24:55 +08:00
RETURN_LONG ( ldap_count_entries ( ld - > link , ldap_result ) ) ;
1999-04-22 08:45:14 +08:00
}
/* }}} */
2002-02-11 10:48:49 +08:00
/* {{{ proto resource ldap_first_entry(resource link, resource result)
1999-04-22 08:45:14 +08:00
Return first result id */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( ldap_first_entry )
1999-04-22 08:45:14 +08:00
{
2008-04-16 22:21:04 +08:00
zval * link , * result ;
2015-01-03 17:22:58 +08:00
ldap_linkdata * ld ;
2002-05-04 22:27:48 +08:00
ldap_resultentry * resultentry ;
LDAPMessage * ldap_result , * entry ;
1999-04-22 08:45:14 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rr " , & link , & result ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
1999-04-22 08:45:14 +08:00
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( ldap_result = ( LDAPMessage * ) zend_fetch_resource ( Z_RES_P ( result ) , " ldap result " , le_result ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-22 08:45:14 +08:00
2002-05-04 22:27:48 +08:00
if ( ( entry = ldap_first_entry ( ld - > link , ldap_result ) ) = = NULL ) {
2001-06-01 05:09:30 +08:00
RETVAL_FALSE ;
1999-04-22 08:45:14 +08:00
} else {
2002-05-04 22:27:48 +08:00
resultentry = emalloc ( sizeof ( ldap_resultentry ) ) ;
2015-02-02 15:05:20 +08:00
RETVAL_RES ( zend_register_resource ( resultentry , le_result_entry ) ) ;
2014-05-20 11:26:26 +08:00
ZVAL_COPY ( & resultentry - > res , result ) ;
2002-05-04 22:27:48 +08:00
resultentry - > data = entry ;
2007-07-13 09:24:16 +08:00
resultentry - > ber = NULL ;
1999-04-22 08:45:14 +08:00
}
}
/* }}} */
2002-05-04 22:27:48 +08:00
/* {{{ proto resource ldap_next_entry(resource link, resource result_entry)
1999-04-22 08:45:14 +08:00
Get next result entry */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( ldap_next_entry )
1999-04-22 08:45:14 +08:00
{
2008-04-16 22:21:04 +08:00
zval * link , * result_entry ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2002-05-04 22:27:48 +08:00
ldap_resultentry * resultentry , * resultentry_next ;
LDAPMessage * entry_next ;
1999-04-22 08:45:14 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rr " , & link , & result_entry ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
1999-04-22 08:45:14 +08:00
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( resultentry = ( ldap_resultentry * ) zend_fetch_resource ( Z_RES_P ( result_entry ) , " ldap result entry " , le_result_entry ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-22 08:45:14 +08:00
2002-05-04 22:27:48 +08:00
if ( ( entry_next = ldap_next_entry ( ld - > link , resultentry - > data ) ) = = NULL ) {
2001-06-01 05:09:30 +08:00
RETVAL_FALSE ;
1999-04-22 08:45:14 +08:00
} else {
2002-05-04 22:27:48 +08:00
resultentry_next = emalloc ( sizeof ( ldap_resultentry ) ) ;
2015-02-02 15:05:20 +08:00
RETVAL_RES ( zend_register_resource ( resultentry_next , le_result_entry ) ) ;
2014-05-20 11:26:26 +08:00
ZVAL_COPY ( & resultentry_next - > res , & resultentry - > res ) ;
2002-05-04 22:27:48 +08:00
resultentry_next - > data = entry_next ;
2007-07-13 09:24:16 +08:00
resultentry_next - > ber = NULL ;
1999-04-22 08:45:14 +08:00
}
}
/* }}} */
2002-02-11 10:48:49 +08:00
/* {{{ proto array ldap_get_entries(resource link, resource result)
1999-04-22 08:45:14 +08:00
Get all result entries */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( ldap_get_entries )
1999-04-22 08:45:14 +08:00
{
2008-04-16 22:21:04 +08:00
zval * link , * result ;
1999-07-17 02:01:55 +08:00
LDAPMessage * ldap_result , * ldap_result_entry ;
2014-05-20 11:26:26 +08:00
zval tmp1 , tmp2 ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
1999-07-17 02:01:55 +08:00
LDAP * ldap ;
int num_entries , num_attrib , num_values , i ;
BerElement * ber ;
char * attribute ;
1999-12-10 07:45:30 +08:00
size_t attr_len ;
2007-03-23 05:50:34 +08:00
struct berval * * ldap_value ;
1999-07-17 02:01:55 +08:00
char * dn ;
1999-04-22 08:45:14 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rr " , & link , & result ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
1999-04-22 08:45:14 +08:00
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( ldap_result = ( LDAPMessage * ) zend_fetch_resource ( Z_RES_P ( result ) , " ldap result " , le_result ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-22 08:45:14 +08:00
2001-11-30 04:17:17 +08:00
ldap = ld - > link ;
1999-04-22 08:45:14 +08:00
num_entries = ldap_count_entries ( ldap , ldap_result ) ;
2009-11-19 01:44:58 +08:00
array_init ( return_value ) ;
2014-08-26 01:24:55 +08:00
add_assoc_long ( return_value , " count " , num_entries ) ;
2009-11-19 01:44:58 +08:00
2008-04-16 22:21:04 +08:00
if ( num_entries = = 0 ) {
2009-11-19 01:44:58 +08:00
return ;
2008-04-16 22:21:04 +08:00
}
2015-01-03 17:22:58 +08:00
1999-04-22 08:45:14 +08:00
ldap_result_entry = ldap_first_entry ( ldap , ldap_result ) ;
2008-04-16 22:21:04 +08:00
if ( ldap_result_entry = = NULL ) {
2009-11-19 01:44:58 +08:00
zval_dtor ( return_value ) ;
2008-04-16 22:21:04 +08:00
RETURN_FALSE ;
}
1999-04-22 08:45:14 +08:00
2009-11-19 01:44:58 +08:00
num_entries = 0 ;
2003-06-09 07:34:51 +08:00
while ( ldap_result_entry ! = NULL ) {
2014-05-20 11:26:26 +08:00
array_init ( & tmp1 ) ;
1999-04-22 08:45:14 +08:00
2000-07-25 23:34:28 +08:00
num_attrib = 0 ;
1999-04-22 08:45:14 +08:00
attribute = ldap_first_attribute ( ldap , ldap_result_entry , & ber ) ;
2000-07-25 23:34:28 +08:00
1999-04-22 08:45:14 +08:00
while ( attribute ! = NULL ) {
2007-03-23 05:50:34 +08:00
ldap_value = ldap_get_values_len ( ldap , ldap_result_entry , attribute ) ;
num_values = ldap_count_values_len ( ldap_value ) ;
1999-04-22 08:45:14 +08:00
2014-05-20 11:26:26 +08:00
array_init ( & tmp2 ) ;
2014-08-26 01:24:55 +08:00
add_assoc_long ( & tmp2 , " count " , num_values ) ;
2003-06-09 07:34:51 +08:00
for ( i = 0 ; i < num_values ; i + + ) {
2014-05-20 11:26:26 +08:00
add_index_stringl ( & tmp2 , i , ldap_value [ i ] - > bv_val , ldap_value [ i ] - > bv_len ) ;
2015-01-03 17:22:58 +08:00
}
2007-03-23 05:50:34 +08:00
ldap_value_free_len ( ldap_value ) ;
1999-04-22 08:45:14 +08:00
1999-12-10 07:45:30 +08:00
attr_len = strlen ( attribute ) ;
2014-05-20 11:26:26 +08:00
zend_hash_str_update ( Z_ARRVAL ( tmp1 ) , php_strtolower ( attribute , attr_len ) , attr_len , & tmp2 ) ;
add_index_string ( & tmp1 , num_attrib , attribute ) ;
1999-04-22 08:45:14 +08:00
2000-07-25 23:34:28 +08:00
num_attrib + + ;
2013-10-05 06:50:16 +08:00
# if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP || WINDOWS
2001-06-21 05:12:55 +08:00
ldap_memfree ( attribute ) ;
# endif
1999-04-22 08:45:14 +08:00
attribute = ldap_next_attribute ( ldap , ldap_result_entry , ber ) ;
}
2013-10-05 06:50:16 +08:00
# if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP || WINDOWS
2007-07-13 09:24:16 +08:00
if ( ber ! = NULL ) {
2001-06-21 05:12:55 +08:00
ber_free ( ber , 0 ) ;
2007-07-13 09:24:16 +08:00
}
2001-06-21 05:12:55 +08:00
# endif
1999-04-22 08:45:14 +08:00
2014-08-26 01:24:55 +08:00
add_assoc_long ( & tmp1 , " count " , num_attrib ) ;
1999-04-22 08:45:14 +08:00
dn = ldap_get_dn ( ldap , ldap_result_entry ) ;
2014-05-20 11:26:26 +08:00
add_assoc_string ( & tmp1 , " dn " , dn ) ;
2013-10-05 06:50:16 +08:00
# if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP || WINDOWS
2001-06-21 05:12:55 +08:00
ldap_memfree ( dn ) ;
2001-07-15 19:12:28 +08:00
# else
free ( dn ) ;
2001-06-21 05:12:55 +08:00
# endif
1999-04-22 08:45:14 +08:00
2014-05-20 11:26:26 +08:00
zend_hash_index_update ( Z_ARRVAL_P ( return_value ) , num_entries , & tmp1 ) ;
2015-01-03 17:22:58 +08:00
2000-07-25 23:34:28 +08:00
num_entries + + ;
1999-04-22 08:45:14 +08:00
ldap_result_entry = ldap_next_entry ( ldap , ldap_result_entry ) ;
}
2014-08-26 01:24:55 +08:00
add_assoc_long ( return_value , " count " , num_entries ) ;
2000-07-25 23:34:28 +08:00
1999-04-22 08:45:14 +08:00
}
/* }}} */
2007-07-13 09:24:16 +08:00
/* {{{ proto string ldap_first_attribute(resource link, resource result_entry)
1999-04-22 08:45:14 +08:00
Return first attribute */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( ldap_first_attribute )
1999-04-22 08:45:14 +08:00
{
2008-04-16 22:21:04 +08:00
zval * link , * result_entry ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2002-05-04 22:27:48 +08:00
ldap_resultentry * resultentry ;
1999-04-22 08:45:14 +08:00
char * attribute ;
2014-08-26 01:24:55 +08:00
zend_long dummy_ber ;
1999-04-22 08:45:14 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rr|l " , & link , & result_entry , & dummy_ber ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
1999-04-22 08:45:14 +08:00
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( resultentry = ( ldap_resultentry * ) zend_fetch_resource ( Z_RES_P ( result_entry ) , " ldap result entry " , le_result_entry ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-22 08:45:14 +08:00
2007-07-13 09:24:16 +08:00
if ( ( attribute = ldap_first_attribute ( ld - > link , resultentry - > data , & resultentry - > ber ) ) = = NULL ) {
1999-04-22 08:45:14 +08:00
RETURN_FALSE ;
} else {
2014-05-20 11:26:26 +08:00
RETVAL_STRING ( attribute ) ;
2013-10-05 06:50:16 +08:00
# if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP || WINDOWS
1999-04-22 08:45:14 +08:00
ldap_memfree ( attribute ) ;
# endif
}
}
/* }}} */
2007-07-13 09:24:16 +08:00
/* {{{ proto string ldap_next_attribute(resource link, resource result_entry)
1999-04-22 08:45:14 +08:00
Get the next attribute in result */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( ldap_next_attribute )
1999-04-22 08:45:14 +08:00
{
2008-04-16 22:21:04 +08:00
zval * link , * result_entry ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2002-05-04 22:27:48 +08:00
ldap_resultentry * resultentry ;
1999-07-17 02:01:55 +08:00
char * attribute ;
2014-08-26 01:24:55 +08:00
zend_long dummy_ber ;
1999-04-22 08:45:14 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rr|l " , & link , & result_entry , & dummy_ber ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
1999-04-22 08:45:14 +08:00
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( resultentry = ( ldap_resultentry * ) zend_fetch_resource ( Z_RES_P ( result_entry ) , " ldap result entry " , le_result_entry ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-22 08:45:14 +08:00
2007-07-13 10:00:39 +08:00
if ( resultentry - > ber = = NULL ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " called before calling ldap_first_attribute() or no attributes found in result entry " ) ;
2007-07-13 10:00:39 +08:00
RETURN_FALSE ;
}
2007-07-13 09:24:16 +08:00
if ( ( attribute = ldap_next_attribute ( ld - > link , resultentry - > data , resultentry - > ber ) ) = = NULL ) {
2013-10-05 06:50:16 +08:00
# if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP || WINDOWS
2007-07-13 09:24:16 +08:00
if ( resultentry - > ber ! = NULL ) {
ber_free ( resultentry - > ber , 0 ) ;
resultentry - > ber = NULL ;
}
# endif
1999-04-22 08:45:14 +08:00
RETURN_FALSE ;
} else {
2014-05-20 11:26:26 +08:00
RETVAL_STRING ( attribute ) ;
2013-10-05 06:50:16 +08:00
# if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP || WINDOWS
1999-04-22 08:45:14 +08:00
ldap_memfree ( attribute ) ;
# endif
}
}
/* }}} */
2002-05-04 22:27:48 +08:00
/* {{{ proto array ldap_get_attributes(resource link, resource result_entry)
1999-04-22 08:45:14 +08:00
Get attributes from a search result entry */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( ldap_get_attributes )
1999-04-22 08:45:14 +08:00
{
2008-04-16 22:21:04 +08:00
zval * link , * result_entry ;
2014-05-20 11:26:26 +08:00
zval tmp ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2002-05-04 22:27:48 +08:00
ldap_resultentry * resultentry ;
1999-07-17 02:01:55 +08:00
char * attribute ;
2007-03-23 05:50:34 +08:00
struct berval * * ldap_value ;
2000-07-25 23:34:28 +08:00
int i , num_values , num_attrib ;
1999-07-17 02:01:55 +08:00
BerElement * ber ;
1999-04-22 08:45:14 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rr " , & link , & result_entry ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
1999-04-22 08:45:14 +08:00
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( resultentry = ( ldap_resultentry * ) zend_fetch_resource ( Z_RES_P ( result_entry ) , " ldap result entry " , le_result_entry ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-22 08:45:14 +08:00
2000-07-25 23:34:28 +08:00
array_init ( return_value ) ;
1999-04-22 08:45:14 +08:00
num_attrib = 0 ;
2015-01-03 17:22:58 +08:00
2002-05-04 22:27:48 +08:00
attribute = ldap_first_attribute ( ld - > link , resultentry - > data , & ber ) ;
1999-04-22 08:45:14 +08:00
while ( attribute ! = NULL ) {
2007-03-23 05:50:34 +08:00
ldap_value = ldap_get_values_len ( ld - > link , resultentry - > data , attribute ) ;
num_values = ldap_count_values_len ( ldap_value ) ;
1999-04-22 08:45:14 +08:00
2014-05-20 11:26:26 +08:00
array_init ( & tmp ) ;
2014-08-26 01:24:55 +08:00
add_assoc_long ( & tmp , " count " , num_values ) ;
2003-06-09 07:34:51 +08:00
for ( i = 0 ; i < num_values ; i + + ) {
2014-05-20 11:26:26 +08:00
add_index_stringl ( & tmp , i , ldap_value [ i ] - > bv_val , ldap_value [ i ] - > bv_len ) ;
1999-04-22 08:45:14 +08:00
}
2007-03-23 05:50:34 +08:00
ldap_value_free_len ( ldap_value ) ;
1999-04-22 08:45:14 +08:00
2014-05-20 11:26:26 +08:00
zend_hash_str_update ( Z_ARRVAL_P ( return_value ) , attribute , strlen ( attribute ) , & tmp ) ;
2014-04-15 19:40:40 +08:00
add_index_string ( return_value , num_attrib , attribute ) ;
1999-04-22 08:45:14 +08:00
2000-07-25 23:34:28 +08:00
num_attrib + + ;
2013-10-05 06:50:16 +08:00
# if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP || WINDOWS
2001-06-23 21:43:20 +08:00
ldap_memfree ( attribute ) ;
# endif
2002-05-04 22:27:48 +08:00
attribute = ldap_next_attribute ( ld - > link , resultentry - > data , ber ) ;
1999-04-22 08:45:14 +08:00
}
2013-10-05 06:50:16 +08:00
# if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP || WINDOWS
2007-07-13 09:24:16 +08:00
if ( ber ! = NULL ) {
ber_free ( ber , 0 ) ;
}
2001-06-23 21:43:20 +08:00
# endif
2015-01-03 17:22:58 +08:00
2014-08-26 01:24:55 +08:00
add_assoc_long ( return_value , " count " , num_attrib ) ;
1999-04-22 08:45:14 +08:00
}
/* }}} */
2002-05-04 22:27:48 +08:00
/* {{{ proto array ldap_get_values_len(resource link, resource result_entry, string attribute)
2000-07-28 08:09:33 +08:00
Get all values with lengths from a result entry */
2000-04-08 07:20:22 +08:00
PHP_FUNCTION ( ldap_get_values_len )
{
2008-04-16 22:21:04 +08:00
zval * link , * result_entry ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2002-05-04 22:27:48 +08:00
ldap_resultentry * resultentry ;
2008-04-16 22:21:04 +08:00
char * attr ;
2000-04-08 07:20:22 +08:00
struct berval * * ldap_value_len ;
2014-08-28 15:43:14 +08:00
int i , num_values ;
size_t attr_len ;
2015-01-03 17:22:58 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rrs " , & link , & result_entry , & attr , & attr_len ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
2000-04-08 07:20:22 +08:00
}
2015-01-03 17:22:58 +08:00
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( resultentry = ( ldap_resultentry * ) zend_fetch_resource ( Z_RES_P ( result_entry ) , " ldap result entry " , le_result_entry ) ) = = NULL ) {
RETURN_FALSE ;
}
2000-07-29 06:39:22 +08:00
2008-04-16 22:21:04 +08:00
if ( ( ldap_value_len = ldap_get_values_len ( ld - > link , resultentry - > data , attr ) ) = = NULL ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Cannot get the value(s) of attribute %s " , ldap_err2string ( _get_lderrno ( ld - > link ) ) ) ;
2000-04-08 07:20:22 +08:00
RETURN_FALSE ;
}
2015-01-03 17:22:58 +08:00
2000-04-08 07:20:22 +08:00
num_values = ldap_count_values_len ( ldap_value_len ) ;
2003-01-19 04:10:23 +08:00
array_init ( return_value ) ;
2015-01-03 17:22:58 +08:00
2000-04-08 07:20:22 +08:00
for ( i = 0 ; i < num_values ; i + + ) {
2014-04-15 19:40:40 +08:00
add_next_index_stringl ( return_value , ldap_value_len [ i ] - > bv_val , ldap_value_len [ i ] - > bv_len ) ;
2000-04-08 07:20:22 +08:00
}
2015-01-03 17:22:58 +08:00
2014-08-26 01:24:55 +08:00
add_assoc_long ( return_value , " count " , num_values ) ;
2000-07-28 08:09:33 +08:00
ldap_value_free_len ( ldap_value_len ) ;
2000-04-08 07:20:22 +08:00
}
/* }}} */
2002-05-04 22:27:48 +08:00
/* {{{ proto string ldap_get_dn(resource link, resource result_entry)
1999-04-22 08:45:14 +08:00
Get the DN of a result entry */
2015-01-03 17:22:58 +08:00
PHP_FUNCTION ( ldap_get_dn )
1999-04-22 08:45:14 +08:00
{
2008-04-16 22:21:04 +08:00
zval * link , * result_entry ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2002-05-04 22:27:48 +08:00
ldap_resultentry * resultentry ;
1999-04-22 08:45:14 +08:00
char * text ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rr " , & link , & result_entry ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
1999-04-22 08:45:14 +08:00
}
2015-01-03 17:22:58 +08:00
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( resultentry = ( ldap_resultentry * ) zend_fetch_resource ( Z_RES_P ( result_entry ) , " ldap result entry " , le_result_entry ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-22 08:45:14 +08:00
2002-05-04 22:27:48 +08:00
text = ldap_get_dn ( ld - > link , resultentry - > data ) ;
2003-06-09 07:34:51 +08:00
if ( text ! = NULL ) {
2014-05-20 11:26:26 +08:00
RETVAL_STRING ( text ) ;
2013-10-05 06:50:16 +08:00
# if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP || WINDOWS
1999-04-22 08:45:14 +08:00
ldap_memfree ( text ) ;
2001-07-15 19:12:28 +08:00
# else
free ( text ) ;
1999-04-22 08:45:14 +08:00
# endif
} else {
RETURN_FALSE ;
}
}
/* }}} */
/* {{{ proto array ldap_explode_dn(string dn, int with_attrib)
Splits DN into its component parts */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( ldap_explode_dn )
1999-04-22 08:45:14 +08:00
{
2014-08-26 01:24:55 +08:00
zend_long with_attrib ;
2008-04-16 22:21:04 +08:00
char * dn , * * ldap_value ;
2014-08-28 15:43:14 +08:00
int i , count ;
size_t dn_len ;
1999-04-22 08:45:14 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " sl " , & dn , & dn_len , & with_attrib ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
1999-04-22 08:45:14 +08:00
}
2008-04-16 22:21:04 +08:00
if ( ! ( ldap_value = ldap_explode_dn ( dn , with_attrib ) ) ) {
2003-09-14 01:31:07 +08:00
/* Invalid parameters were passed to ldap_explode_dn */
RETURN_FALSE ;
}
1999-04-22 08:45:14 +08:00
i = 0 ;
2003-06-09 07:34:51 +08:00
while ( ldap_value [ i ] ! = NULL ) i + + ;
1999-04-22 08:45:14 +08:00
count = i ;
2003-01-19 04:10:23 +08:00
array_init ( return_value ) ;
1999-04-22 08:45:14 +08:00
2014-08-26 01:24:55 +08:00
add_assoc_long ( return_value , " count " , count ) ;
2003-06-09 07:34:51 +08:00
for ( i = 0 ; i < count ; i + + ) {
2014-04-15 19:40:40 +08:00
add_index_string ( return_value , i , ldap_value [ i ] ) ;
1999-04-22 08:45:14 +08:00
}
2015-06-23 22:44:48 +08:00
ldap_memvfree ( ( void * * ) ldap_value ) ;
1999-04-22 08:45:14 +08:00
}
/* }}} */
/* {{{ proto string ldap_dn2ufn(string dn)
Convert DN to User Friendly Naming format */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( ldap_dn2ufn )
1999-04-22 08:45:14 +08:00
{
2008-04-16 22:21:04 +08:00
char * dn , * ufn ;
2014-08-27 21:31:48 +08:00
size_t dn_len ;
1999-04-22 08:45:14 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " s " , & dn , & dn_len ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
1999-04-22 08:45:14 +08:00
}
2015-01-03 17:22:58 +08:00
2008-04-16 22:21:04 +08:00
ufn = ldap_dn2ufn ( dn ) ;
2015-01-03 17:22:58 +08:00
2008-04-16 22:21:04 +08:00
if ( ufn ! = NULL ) {
2014-05-20 11:26:26 +08:00
RETVAL_STRING ( ufn ) ;
2013-10-05 06:50:16 +08:00
# if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP || WINDOWS
1999-04-22 08:45:14 +08:00
ldap_memfree ( ufn ) ;
# endif
} else {
RETURN_FALSE ;
}
}
/* }}} */
1999-05-21 18:06:25 +08:00
2000-07-24 05:32:02 +08:00
2003-06-09 07:34:51 +08:00
/* added to fix use of ldap_modify_add for doing an ldap_add, gerrit thomson. */
1999-05-21 18:06:25 +08:00
# define PHP_LD_FULL_ADD 0xff
2001-06-05 21:12:10 +08:00
/* {{{ php_ldap_do_modify
*/
1999-12-18 19:49:31 +08:00
static void php_ldap_do_modify ( INTERNAL_FUNCTION_PARAMETERS , int oper )
1999-04-22 08:45:14 +08:00
{
2014-05-20 11:26:26 +08:00
zval * link , * entry , * value , * ivalue ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2008-04-16 22:21:04 +08:00
char * dn ;
1999-07-17 02:01:55 +08:00
LDAPMod * * ldap_mods ;
2014-08-28 15:43:14 +08:00
int i , j , num_attribs , num_values ;
size_t dn_len ;
2000-07-29 05:31:02 +08:00
int * num_berval ;
2014-05-20 11:26:26 +08:00
zend_string * attribute ;
2014-08-26 01:24:55 +08:00
zend_ulong index ;
1999-07-17 02:01:55 +08:00
int is_full_add = 0 ; /* flag for full add operation so ldap_mod_add can be put back into oper, gerrit THomson */
1999-04-22 08:45:14 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rsa " , & link , & dn , & dn_len , & entry ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
2015-01-03 17:22:58 +08:00
}
1999-04-22 08:45:14 +08:00
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-22 08:45:14 +08:00
2008-04-16 22:21:04 +08:00
num_attribs = zend_hash_num_elements ( Z_ARRVAL_P ( entry ) ) ;
2003-05-01 05:53:53 +08:00
ldap_mods = safe_emalloc ( ( num_attribs + 1 ) , sizeof ( LDAPMod * ) , 0 ) ;
num_berval = safe_emalloc ( num_attribs , sizeof ( int ) , 0 ) ;
2008-04-16 22:21:04 +08:00
zend_hash_internal_pointer_reset ( Z_ARRVAL_P ( entry ) ) ;
2000-07-29 05:31:02 +08:00
/* added by gerrit thomson to fix ldap_add using ldap_mod_add */
2003-06-09 07:34:51 +08:00
if ( oper = = PHP_LD_FULL_ADD ) {
2000-07-29 05:31:02 +08:00
oper = LDAP_MOD_ADD ;
is_full_add = 1 ;
}
1999-05-21 18:06:25 +08:00
/* end additional , gerrit thomson */
1999-04-22 08:45:14 +08:00
2003-06-09 07:34:51 +08:00
for ( i = 0 ; i < num_attribs ; i + + ) {
1999-04-22 08:45:14 +08:00
ldap_mods [ i ] = emalloc ( sizeof ( LDAPMod ) ) ;
2000-07-29 05:31:02 +08:00
ldap_mods [ i ] - > mod_op = oper | LDAP_MOD_BVALUES ;
2008-04-16 21:20:59 +08:00
ldap_mods [ i ] - > mod_type = NULL ;
1999-04-22 08:45:14 +08:00
2014-12-24 05:00:18 +08:00
if ( zend_hash_get_current_key ( Z_ARRVAL_P ( entry ) , & attribute , & index ) = = HASH_KEY_IS_STRING ) {
2015-06-30 18:59:27 +08:00
ldap_mods [ i ] - > mod_type = estrndup ( ZSTR_VAL ( attribute ) , ZSTR_LEN ( attribute ) ) ;
1999-04-22 08:45:14 +08:00
} else {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unknown attribute in the data " ) ;
2001-01-13 18:00:27 +08:00
/* Free allocated memory */
while ( i > = 0 ) {
2008-04-16 21:20:59 +08:00
if ( ldap_mods [ i ] - > mod_type ) {
efree ( ldap_mods [ i ] - > mod_type ) ;
}
efree ( ldap_mods [ i ] ) ;
i - - ;
2001-01-13 18:00:27 +08:00
}
efree ( num_berval ) ;
2015-01-03 17:22:58 +08:00
efree ( ldap_mods ) ;
2000-11-13 10:02:40 +08:00
RETURN_FALSE ;
1999-04-22 08:45:14 +08:00
}
2014-05-20 11:26:26 +08:00
value = zend_hash_get_current_data ( Z_ARRVAL_P ( entry ) ) ;
1999-04-22 08:45:14 +08:00
2016-01-01 23:06:58 +08:00
ZVAL_DEREF ( value ) ;
2014-05-20 11:26:26 +08:00
if ( Z_TYPE_P ( value ) ! = IS_ARRAY ) {
1999-04-22 08:45:14 +08:00
num_values = 1 ;
} else {
2014-05-20 11:26:26 +08:00
num_values = zend_hash_num_elements ( Z_ARRVAL_P ( value ) ) ;
1999-04-22 08:45:14 +08:00
}
2015-01-03 17:22:58 +08:00
2000-07-29 05:31:02 +08:00
num_berval [ i ] = num_values ;
2003-05-01 05:53:53 +08:00
ldap_mods [ i ] - > mod_bvalues = safe_emalloc ( ( num_values + 1 ) , sizeof ( struct berval * ) , 0 ) ;
1999-05-21 18:06:25 +08:00
/* allow for arrays with one element, no allowance for arrays with none but probably not required, gerrit thomson. */
2014-05-20 11:26:26 +08:00
if ( ( num_values = = 1 ) & & ( Z_TYPE_P ( value ) ! = IS_ARRAY ) ) {
1999-11-22 10:31:32 +08:00
convert_to_string_ex ( value ) ;
2000-07-29 05:31:02 +08:00
ldap_mods [ i ] - > mod_bvalues [ 0 ] = ( struct berval * ) emalloc ( sizeof ( struct berval ) ) ;
2014-08-26 01:24:55 +08:00
ldap_mods [ i ] - > mod_bvalues [ 0 ] - > bv_len = Z_STRLEN_P ( value ) ;
2014-05-20 11:26:26 +08:00
ldap_mods [ i ] - > mod_bvalues [ 0 ] - > bv_val = Z_STRVAL_P ( value ) ;
2015-01-03 17:22:58 +08:00
} else {
2003-06-09 07:34:51 +08:00
for ( j = 0 ; j < num_values ; j + + ) {
2014-05-20 11:26:26 +08:00
if ( ( ivalue = zend_hash_index_find ( Z_ARRVAL_P ( value ) , j ) ) = = NULL ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Value array must have consecutive indices 0, 1, ... " ) ;
2001-11-05 19:50:52 +08:00
num_berval [ i ] = j ;
num_attribs = i + 1 ;
RETVAL_FALSE ;
goto errexit ;
}
1999-11-22 10:31:32 +08:00
convert_to_string_ex ( ivalue ) ;
2000-07-29 05:31:02 +08:00
ldap_mods [ i ] - > mod_bvalues [ j ] = ( struct berval * ) emalloc ( sizeof ( struct berval ) ) ;
2014-08-26 01:24:55 +08:00
ldap_mods [ i ] - > mod_bvalues [ j ] - > bv_len = Z_STRLEN_P ( ivalue ) ;
2014-05-20 11:26:26 +08:00
ldap_mods [ i ] - > mod_bvalues [ j ] - > bv_val = Z_STRVAL_P ( ivalue ) ;
1999-04-22 08:45:14 +08:00
}
}
2000-07-29 05:31:02 +08:00
ldap_mods [ i ] - > mod_bvalues [ num_values ] = NULL ;
2008-04-16 22:21:04 +08:00
zend_hash_move_forward ( Z_ARRVAL_P ( entry ) ) ;
1999-04-22 08:45:14 +08:00
}
ldap_mods [ num_attribs ] = NULL ;
1999-05-21 18:06:25 +08:00
/* check flag to see if do_mod was called to perform full add , gerrit thomson */
2001-11-14 01:10:08 +08:00
if ( is_full_add = = 1 ) {
2015-06-23 22:44:48 +08:00
if ( ( i = ldap_add_ext_s ( ld - > link , dn , ldap_mods , NULL , NULL ) ) ! = LDAP_SUCCESS ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Add: %s " , ldap_err2string ( i ) ) ;
1999-04-22 08:45:14 +08:00
RETVAL_FALSE ;
} else RETVAL_TRUE ;
} else {
2009-08-30 23:33:59 +08:00
if ( ( i = ldap_modify_ext_s ( ld - > link , dn , ldap_mods , NULL , NULL ) ) ! = LDAP_SUCCESS ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Modify: %s " , ldap_err2string ( i ) ) ;
1999-04-22 08:45:14 +08:00
RETVAL_FALSE ;
2015-01-03 17:22:58 +08:00
} else RETVAL_TRUE ;
1999-04-22 08:45:14 +08:00
}
2001-11-05 19:50:52 +08:00
errexit :
2003-06-09 07:34:51 +08:00
for ( i = 0 ; i < num_attribs ; i + + ) {
1999-04-22 08:45:14 +08:00
efree ( ldap_mods [ i ] - > mod_type ) ;
2003-06-09 07:34:51 +08:00
for ( j = 0 ; j < num_berval [ i ] ; j + + ) {
2000-07-29 05:31:02 +08:00
efree ( ldap_mods [ i ] - > mod_bvalues [ j ] ) ;
}
efree ( ldap_mods [ i ] - > mod_bvalues ) ;
1999-04-22 08:45:14 +08:00
efree ( ldap_mods [ i ] ) ;
}
2000-07-29 05:31:02 +08:00
efree ( num_berval ) ;
2015-01-03 17:22:58 +08:00
efree ( ldap_mods ) ;
1999-04-22 08:45:14 +08:00
return ;
}
2001-06-05 21:12:10 +08:00
/* }}} */
2000-07-24 05:32:02 +08:00
2002-02-11 10:48:49 +08:00
/* {{{ proto bool ldap_add(resource link, string dn, array entry)
1999-04-22 08:45:14 +08:00
Add entries to LDAP directory */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( ldap_add )
1999-04-22 08:45:14 +08:00
{
1999-05-21 18:06:25 +08:00
/* 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 */
1999-12-18 19:49:31 +08:00
php_ldap_do_modify ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_LD_FULL_ADD ) ;
1999-04-22 08:45:14 +08:00
}
/* }}} */
1999-05-21 18:06:25 +08:00
/* three functions for attribute base modifications, gerrit Thomson */
2002-02-11 10:48:49 +08:00
/* {{{ proto bool ldap_mod_replace(resource link, string dn, array entry)
1999-05-21 18:06:25 +08:00
Replace attribute values with new ones */
PHP_FUNCTION ( ldap_mod_replace )
{
2001-06-01 05:09:30 +08:00
php_ldap_do_modify ( INTERNAL_FUNCTION_PARAM_PASSTHRU , LDAP_MOD_REPLACE ) ;
}
1999-05-21 18:06:25 +08:00
/* }}} */
2002-02-11 10:48:49 +08:00
/* {{{ proto bool ldap_mod_add(resource link, string dn, array entry)
2000-02-23 23:04:36 +08:00
Add attribute values to current */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( ldap_mod_add )
{
2001-06-01 05:09:30 +08:00
php_ldap_do_modify ( INTERNAL_FUNCTION_PARAM_PASSTHRU , LDAP_MOD_ADD ) ;
1999-05-21 18:06:25 +08:00
}
/* }}} */
2002-02-11 10:48:49 +08:00
/* {{{ proto bool ldap_mod_del(resource link, string dn, array entry)
1999-05-21 18:06:25 +08:00
Delete attribute values */
PHP_FUNCTION ( ldap_mod_del )
{
2003-06-09 07:34:51 +08:00
php_ldap_do_modify ( INTERNAL_FUNCTION_PARAM_PASSTHRU , LDAP_MOD_DELETE ) ;
1999-05-21 18:06:25 +08:00
}
2000-07-24 05:32:02 +08:00
/* }}} */
1999-05-21 18:06:25 +08:00
2002-02-11 10:48:49 +08:00
/* {{{ proto bool ldap_delete(resource link, string dn)
1999-04-22 08:45:14 +08:00
Delete an entry from a directory */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( ldap_delete )
1999-04-22 08:45:14 +08:00
{
2008-04-16 22:21:04 +08:00
zval * link ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2008-04-16 22:21:04 +08:00
char * dn ;
2014-08-28 15:43:14 +08:00
int rc ;
size_t dn_len ;
1999-04-22 08:45:14 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rs " , & link , & dn , & dn_len ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
1999-04-22 08:45:14 +08:00
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-22 08:45:14 +08:00
2015-06-23 22:44:48 +08:00
if ( ( rc = ldap_delete_ext_s ( ld - > link , dn , NULL , NULL ) ) ! = LDAP_SUCCESS ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Delete: %s " , ldap_err2string ( rc ) ) ;
1999-04-22 08:45:14 +08:00
RETURN_FALSE ;
}
RETURN_TRUE ;
}
/* }}} */
2014-01-23 01:54:11 +08:00
/* {{{ _ldap_str_equal_to_const
*/
static int _ldap_str_equal_to_const ( const char * str , uint str_len , const char * cstr )
{
int i ;
if ( strlen ( cstr ) ! = str_len )
return 0 ;
for ( i = 0 ; i < str_len ; + + i ) {
if ( str [ i ] ! = cstr [ i ] ) {
return 0 ;
}
}
return 1 ;
}
/* }}} */
/* {{{ _ldap_strlen_max
*/
static int _ldap_strlen_max ( const char * str , uint max_len )
{
int i ;
for ( i = 0 ; i < max_len ; + + i ) {
if ( str [ i ] = = ' \0 ' ) {
return i ;
}
}
return max_len ;
}
/* }}} */
/* {{{ _ldap_hash_fetch
*/
static void _ldap_hash_fetch ( zval * hashTbl , const char * key , zval * * out )
{
2014-05-20 11:26:26 +08:00
* out = zend_hash_str_find ( Z_ARRVAL_P ( hashTbl ) , key , strlen ( key ) ) ;
2014-01-23 01:54:11 +08:00
}
/* }}} */
/* {{{ proto bool ldap_modify_batch(resource link, string dn, array modifs)
Perform multiple modifications as part of one operation */
PHP_FUNCTION ( ldap_modify_batch )
{
ldap_linkdata * ld ;
zval * link , * mods , * mod , * modinfo , * modval ;
zval * attrib , * modtype , * vals ;
2014-05-20 11:26:26 +08:00
zval * fetched ;
2014-01-23 01:54:11 +08:00
char * dn ;
2014-08-27 21:31:48 +08:00
size_t dn_len ;
2014-01-23 01:54:11 +08:00
int i , j , k ;
int num_mods , num_modprops , num_modvals ;
LDAPMod * * ldap_mods ;
uint oper ;
/*
$ mods = array (
array (
" attrib " = > " unicodePwd " ,
" modtype " = > LDAP_MODIFY_BATCH_REMOVE ,
" values " = > array ( $ oldpw )
) ,
array (
" attrib " = > " unicodePwd " ,
" modtype " = > LDAP_MODIFY_BATCH_ADD ,
" values " = > array ( $ newpw )
) ,
array (
" attrib " = > " userPrincipalName " ,
" modtype " = > LDAP_MODIFY_BATCH_REPLACE ,
" values " = > array ( " janitor@corp.contoso.com " )
) ,
array (
" attrib " = > " userCert " ,
" modtype " = > LDAP_MODIFY_BATCH_REMOVE_ALL
)
) ;
*/
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rsa " , & link , & dn , & dn_len , & mods ) ! = SUCCESS ) {
2014-01-23 01:54:11 +08:00
return ;
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
2014-01-23 01:54:11 +08:00
/* perform validation */
{
2014-05-20 11:26:26 +08:00
zend_string * modkey ;
2014-08-26 01:24:55 +08:00
zend_long modtype ;
2014-01-23 01:54:11 +08:00
/* to store the wrongly-typed keys */
2014-08-26 01:24:55 +08:00
zend_ulong tmpUlong ;
2014-01-23 01:54:11 +08:00
/* make sure the DN contains no NUL bytes */
if ( _ldap_strlen_max ( dn , dn_len ) ! = dn_len ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " DN must not contain NUL bytes " ) ;
2014-01-23 01:54:11 +08:00
RETURN_FALSE ;
}
/* make sure the top level is a normal array */
zend_hash_internal_pointer_reset ( Z_ARRVAL_P ( mods ) ) ;
2014-08-26 01:24:55 +08:00
if ( zend_hash_get_current_key_type ( Z_ARRVAL_P ( mods ) ) ! = HASH_KEY_IS_LONG ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Modifications array must not be string-indexed " ) ;
2014-01-23 01:54:11 +08:00
RETURN_FALSE ;
}
num_mods = zend_hash_num_elements ( Z_ARRVAL_P ( mods ) ) ;
for ( i = 0 ; i < num_mods ; i + + ) {
/* is the numbering consecutive? */
2014-05-20 11:26:26 +08:00
if ( ( fetched = zend_hash_index_find ( Z_ARRVAL_P ( mods ) , i ) ) = = NULL ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Modifications array must have consecutive indices 0, 1, ... " ) ;
2014-01-23 01:54:11 +08:00
RETURN_FALSE ;
}
2014-05-20 11:26:26 +08:00
mod = fetched ;
2014-01-23 01:54:11 +08:00
/* is it an array? */
if ( Z_TYPE_P ( mod ) ! = IS_ARRAY ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Each entry of modifications array must be an array itself " ) ;
2014-01-23 01:54:11 +08:00
RETURN_FALSE ;
}
/* for the modification hashtable... */
zend_hash_internal_pointer_reset ( Z_ARRVAL_P ( mod ) ) ;
num_modprops = zend_hash_num_elements ( Z_ARRVAL_P ( mod ) ) ;
for ( j = 0 ; j < num_modprops ; j + + ) {
/* are the keys strings? */
2014-12-24 05:00:18 +08:00
if ( zend_hash_get_current_key ( Z_ARRVAL_P ( mod ) , & modkey , & tmpUlong ) ! = HASH_KEY_IS_STRING ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Each entry of modifications array must be string-indexed " ) ;
2014-01-23 01:54:11 +08:00
RETURN_FALSE ;
}
/* is this a valid entry? */
if (
2015-06-30 18:59:27 +08:00
! _ldap_str_equal_to_const ( ZSTR_VAL ( modkey ) , ZSTR_LEN ( modkey ) , LDAP_MODIFY_BATCH_ATTRIB ) & &
! _ldap_str_equal_to_const ( ZSTR_VAL ( modkey ) , ZSTR_LEN ( modkey ) , LDAP_MODIFY_BATCH_MODTYPE ) & &
! _ldap_str_equal_to_const ( ZSTR_VAL ( modkey ) , ZSTR_LEN ( modkey ) , LDAP_MODIFY_BATCH_VALUES )
2014-01-23 01:54:11 +08:00
) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " The only allowed keys in entries of the modifications array are ' " LDAP_MODIFY_BATCH_ATTRIB " ', ' " LDAP_MODIFY_BATCH_MODTYPE " ' and ' " LDAP_MODIFY_BATCH_VALUES " ' " ) ;
2014-01-23 01:54:11 +08:00
RETURN_FALSE ;
}
2014-05-20 11:26:26 +08:00
fetched = zend_hash_get_current_data ( Z_ARRVAL_P ( mod ) ) ;
modinfo = fetched ;
2014-01-23 01:54:11 +08:00
/* does the value type match the key? */
2015-06-30 18:59:27 +08:00
if ( _ldap_str_equal_to_const ( ZSTR_VAL ( modkey ) , ZSTR_LEN ( modkey ) , LDAP_MODIFY_BATCH_ATTRIB ) ) {
2014-01-23 01:54:11 +08:00
if ( Z_TYPE_P ( modinfo ) ! = IS_STRING ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " A ' " LDAP_MODIFY_BATCH_ATTRIB " ' value must be a string " ) ;
2014-01-23 01:54:11 +08:00
RETURN_FALSE ;
}
2014-08-26 01:24:55 +08:00
if ( Z_STRLEN_P ( modinfo ) ! = _ldap_strlen_max ( Z_STRVAL_P ( modinfo ) , Z_STRLEN_P ( modinfo ) ) ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " A ' " LDAP_MODIFY_BATCH_ATTRIB " ' value must not contain NUL bytes " ) ;
2014-01-23 01:54:11 +08:00
RETURN_FALSE ;
}
}
2015-06-30 18:59:27 +08:00
else if ( _ldap_str_equal_to_const ( ZSTR_VAL ( modkey ) , ZSTR_LEN ( modkey ) , LDAP_MODIFY_BATCH_MODTYPE ) ) {
2014-08-26 01:24:55 +08:00
if ( Z_TYPE_P ( modinfo ) ! = IS_LONG ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " A ' " LDAP_MODIFY_BATCH_MODTYPE " ' value must be a long " ) ;
2014-01-23 01:54:11 +08:00
RETURN_FALSE ;
}
/* is the value in range? */
2014-08-26 01:24:55 +08:00
modtype = Z_LVAL_P ( modinfo ) ;
2014-01-23 01:54:11 +08:00
if (
modtype ! = LDAP_MODIFY_BATCH_ADD & &
modtype ! = LDAP_MODIFY_BATCH_REMOVE & &
modtype ! = LDAP_MODIFY_BATCH_REPLACE & &
modtype ! = LDAP_MODIFY_BATCH_REMOVE_ALL
) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " The ' " LDAP_MODIFY_BATCH_MODTYPE " ' value must match one of the LDAP_MODIFY_BATCH_* constants " ) ;
2014-01-23 01:54:11 +08:00
RETURN_FALSE ;
}
/* if it's REMOVE_ALL, there must not be a values array; otherwise, there must */
if ( modtype = = LDAP_MODIFY_BATCH_REMOVE_ALL ) {
2014-05-20 11:26:26 +08:00
if ( zend_hash_str_exists ( Z_ARRVAL_P ( mod ) , LDAP_MODIFY_BATCH_VALUES , strlen ( LDAP_MODIFY_BATCH_VALUES ) ) ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " If ' " LDAP_MODIFY_BATCH_MODTYPE " ' is LDAP_MODIFY_BATCH_REMOVE_ALL, a ' " LDAP_MODIFY_BATCH_VALUES " ' array must not be provided " ) ;
2014-01-23 01:54:11 +08:00
RETURN_FALSE ;
}
}
else {
2014-05-20 11:26:26 +08:00
if ( ! zend_hash_str_exists ( Z_ARRVAL_P ( mod ) , LDAP_MODIFY_BATCH_VALUES , strlen ( LDAP_MODIFY_BATCH_VALUES ) ) ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " If ' " LDAP_MODIFY_BATCH_MODTYPE " ' is not LDAP_MODIFY_BATCH_REMOVE_ALL, a ' " LDAP_MODIFY_BATCH_VALUES " ' array must be provided " ) ;
2014-01-23 01:54:11 +08:00
RETURN_FALSE ;
}
}
}
2015-06-30 18:59:27 +08:00
else if ( _ldap_str_equal_to_const ( ZSTR_VAL ( modkey ) , ZSTR_LEN ( modkey ) , LDAP_MODIFY_BATCH_VALUES ) ) {
2014-01-23 01:54:11 +08:00
if ( Z_TYPE_P ( modinfo ) ! = IS_ARRAY ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " A ' " LDAP_MODIFY_BATCH_VALUES " ' value must be an array " ) ;
2014-01-23 01:54:11 +08:00
RETURN_FALSE ;
}
/* is the array not empty? */
zend_hash_internal_pointer_reset ( Z_ARRVAL_P ( modinfo ) ) ;
num_modvals = zend_hash_num_elements ( Z_ARRVAL_P ( modinfo ) ) ;
if ( num_modvals = = 0 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " A ' " LDAP_MODIFY_BATCH_VALUES " ' array must have at least one element " ) ;
2014-01-23 01:54:11 +08:00
RETURN_FALSE ;
}
/* are its keys integers? */
2014-08-26 01:24:55 +08:00
if ( zend_hash_get_current_key_type ( Z_ARRVAL_P ( modinfo ) ) ! = HASH_KEY_IS_LONG ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " A ' " LDAP_MODIFY_BATCH_VALUES " ' array must not be string-indexed " ) ;
2014-01-23 01:54:11 +08:00
RETURN_FALSE ;
}
/* are the keys consecutive? */
for ( k = 0 ; k < num_modvals ; k + + ) {
2014-05-20 11:26:26 +08:00
if ( ( fetched = zend_hash_index_find ( Z_ARRVAL_P ( modinfo ) , k ) ) = = NULL ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " A ' " LDAP_MODIFY_BATCH_VALUES " ' array must have consecutive indices 0, 1, ... " ) ;
2014-01-23 01:54:11 +08:00
RETURN_FALSE ;
}
2014-05-20 11:26:26 +08:00
modval = fetched ;
2014-01-23 01:54:11 +08:00
/* is the data element a string? */
if ( Z_TYPE_P ( modval ) ! = IS_STRING ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Each element of a ' " LDAP_MODIFY_BATCH_VALUES " ' array must be a string " ) ;
2014-01-23 01:54:11 +08:00
RETURN_FALSE ;
}
}
}
zend_hash_move_forward ( Z_ARRVAL_P ( mod ) ) ;
}
}
}
/* validation was successful */
/* allocate array of modifications */
ldap_mods = safe_emalloc ( ( num_mods + 1 ) , sizeof ( LDAPMod * ) , 0 ) ;
/* for each modification */
for ( i = 0 ; i < num_mods ; i + + ) {
/* allocate the modification struct */
ldap_mods [ i ] = safe_emalloc ( 1 , sizeof ( LDAPMod ) , 0 ) ;
/* fetch the relevant data */
2014-05-20 11:26:26 +08:00
fetched = zend_hash_index_find ( Z_ARRVAL_P ( mods ) , i ) ;
mod = fetched ;
2014-01-23 01:54:11 +08:00
_ldap_hash_fetch ( mod , LDAP_MODIFY_BATCH_ATTRIB , & attrib ) ;
_ldap_hash_fetch ( mod , LDAP_MODIFY_BATCH_MODTYPE , & modtype ) ;
_ldap_hash_fetch ( mod , LDAP_MODIFY_BATCH_VALUES , & vals ) ;
/* map the modification type */
2014-08-26 01:24:55 +08:00
switch ( Z_LVAL_P ( modtype ) ) {
2014-01-23 01:54:11 +08:00
case LDAP_MODIFY_BATCH_ADD :
oper = LDAP_MOD_ADD ;
break ;
case LDAP_MODIFY_BATCH_REMOVE :
case LDAP_MODIFY_BATCH_REMOVE_ALL :
oper = LDAP_MOD_DELETE ;
break ;
case LDAP_MODIFY_BATCH_REPLACE :
oper = LDAP_MOD_REPLACE ;
break ;
default :
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_ERROR , " Unknown and uncaught modification type. " ) ;
2014-01-23 01:54:11 +08:00
RETURN_FALSE ;
}
/* fill in the basic info */
ldap_mods [ i ] - > mod_op = oper | LDAP_MOD_BVALUES ;
2014-08-26 01:24:55 +08:00
ldap_mods [ i ] - > mod_type = estrndup ( Z_STRVAL_P ( attrib ) , Z_STRLEN_P ( attrib ) ) ;
2014-01-23 01:54:11 +08:00
2014-08-26 01:24:55 +08:00
if ( Z_LVAL_P ( modtype ) = = LDAP_MODIFY_BATCH_REMOVE_ALL ) {
2014-01-23 01:54:11 +08:00
/* no values */
ldap_mods [ i ] - > mod_bvalues = NULL ;
}
else {
/* allocate space for the values as part of this modification */
num_modvals = zend_hash_num_elements ( Z_ARRVAL_P ( vals ) ) ;
ldap_mods [ i ] - > mod_bvalues = safe_emalloc ( ( num_modvals + 1 ) , sizeof ( struct berval * ) , 0 ) ;
/* for each value */
for ( j = 0 ; j < num_modvals ; j + + ) {
/* fetch it */
2014-05-20 11:26:26 +08:00
fetched = zend_hash_index_find ( Z_ARRVAL_P ( vals ) , j ) ;
modval = fetched ;
2014-01-23 01:54:11 +08:00
/* allocate the data struct */
ldap_mods [ i ] - > mod_bvalues [ j ] = safe_emalloc ( 1 , sizeof ( struct berval ) , 0 ) ;
/* fill it */
2014-08-26 01:24:55 +08:00
ldap_mods [ i ] - > mod_bvalues [ j ] - > bv_len = Z_STRLEN_P ( modval ) ;
ldap_mods [ i ] - > mod_bvalues [ j ] - > bv_val = estrndup ( Z_STRVAL_P ( modval ) , Z_STRLEN_P ( modval ) ) ;
2014-01-23 01:54:11 +08:00
}
/* NULL-terminate values */
ldap_mods [ i ] - > mod_bvalues [ num_modvals ] = NULL ;
}
}
/* NULL-terminate modifications */
ldap_mods [ num_mods ] = NULL ;
/* perform (finally) */
if ( ( i = ldap_modify_ext_s ( ld - > link , dn , ldap_mods , NULL , NULL ) ) ! = LDAP_SUCCESS ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Batch Modify: %s " , ldap_err2string ( i ) ) ;
2014-01-23 01:54:11 +08:00
RETVAL_FALSE ;
} else RETVAL_TRUE ;
/* clean up */
{
for ( i = 0 ; i < num_mods ; i + + ) {
/* attribute */
efree ( ldap_mods [ i ] - > mod_type ) ;
if ( ldap_mods [ i ] - > mod_bvalues ! = NULL ) {
/* each BER value */
for ( j = 0 ; ldap_mods [ i ] - > mod_bvalues [ j ] ! = NULL ; j + + ) {
/* free the data bytes */
efree ( ldap_mods [ i ] - > mod_bvalues [ j ] - > bv_val ) ;
/* free the bvalue struct */
efree ( ldap_mods [ i ] - > mod_bvalues [ j ] ) ;
}
/* the BER value array */
efree ( ldap_mods [ i ] - > mod_bvalues ) ;
}
/* the modification */
efree ( ldap_mods [ i ] ) ;
}
/* the modifications array */
efree ( ldap_mods ) ;
}
}
/* }}} */
2002-02-11 10:48:49 +08:00
/* {{{ proto int ldap_errno(resource link)
2000-04-06 20:36:47 +08:00
Get the current ldap error number */
2001-06-01 05:09:30 +08:00
PHP_FUNCTION ( ldap_errno )
{
2008-04-16 22:21:04 +08:00
zval * link ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2000-04-06 20:36:47 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " r " , & link ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
2000-04-06 20:36:47 +08:00
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
2001-06-01 05:09:30 +08:00
2014-08-26 01:24:55 +08:00
RETURN_LONG ( _get_lderrno ( ld - > link ) ) ;
2000-04-06 20:36:47 +08:00
}
/* }}} */
/* {{{ proto string ldap_err2str(int errno)
Convert error number to error string */
2001-06-01 05:09:30 +08:00
PHP_FUNCTION ( ldap_err2str )
{
2014-08-26 01:24:55 +08:00
zend_long perrno ;
2000-04-06 20:36:47 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " l " , & perrno ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
2000-04-06 20:36:47 +08:00
}
2001-06-01 05:09:30 +08:00
2014-05-20 11:26:26 +08:00
RETURN_STRING ( ldap_err2string ( perrno ) ) ;
2000-04-06 20:36:47 +08:00
}
/* }}} */
2002-02-11 10:48:49 +08:00
/* {{{ proto string ldap_error(resource link)
2000-04-06 20:36:47 +08:00
Get the current ldap error string */
2015-01-03 17:22:58 +08:00
PHP_FUNCTION ( ldap_error )
2001-06-01 05:09:30 +08:00
{
2008-04-16 22:21:04 +08:00
zval * link ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2000-04-06 20:36:47 +08:00
int ld_errno ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " r " , & link ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
2000-04-06 20:36:47 +08:00
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
2000-04-06 20:36:47 +08:00
2001-11-30 04:17:17 +08:00
ld_errno = _get_lderrno ( ld - > link ) ;
2000-04-06 20:36:47 +08:00
2014-05-20 11:26:26 +08:00
RETURN_STRING ( ldap_err2string ( ld_errno ) ) ;
2000-04-06 20:36:47 +08:00
}
2000-04-07 00:57:33 +08:00
/* }}} */
2000-07-26 19:01:44 +08:00
2002-02-11 10:48:49 +08:00
/* {{{ proto bool ldap_compare(resource link, string dn, string attr, string value)
2000-07-26 19:28:14 +08:00
Determine if an entry has a specific value for one of its attributes */
2015-01-03 17:22:58 +08:00
PHP_FUNCTION ( ldap_compare )
2001-06-01 05:09:30 +08:00
{
2008-04-16 22:21:04 +08:00
zval * link ;
char * dn , * attr , * value ;
2014-08-28 15:43:14 +08:00
size_t dn_len , attr_len , value_len ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2000-07-26 19:01:44 +08:00
int errno ;
2015-06-29 23:14:14 +08:00
struct berval lvalue ;
2000-07-26 19:01:44 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rsss " , & link , & dn , & dn_len , & attr , & attr_len , & value , & value_len ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
2000-07-26 19:01:44 +08:00
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
2000-07-26 19:01:44 +08:00
2015-06-23 22:44:48 +08:00
lvalue . bv_val = value ;
lvalue . bv_len = value_len ;
errno = ldap_compare_ext_s ( ld - > link , dn , attr , & lvalue , NULL , NULL ) ;
2000-07-26 19:01:44 +08:00
2003-06-09 07:34:51 +08:00
switch ( errno ) {
case LDAP_COMPARE_TRUE :
2000-07-26 19:01:44 +08:00
RETURN_TRUE ;
2003-06-09 07:34:51 +08:00
break ;
2000-07-26 19:01:44 +08:00
2003-06-09 07:34:51 +08:00
case LDAP_COMPARE_FALSE :
2000-07-26 19:01:44 +08:00
RETURN_FALSE ;
2003-06-09 07:34:51 +08:00
break ;
2000-07-26 19:01:44 +08:00
}
2015-01-03 17:22:58 +08:00
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Compare: %s " , ldap_err2string ( errno ) ) ;
2014-08-26 01:24:55 +08:00
RETURN_LONG ( - 1 ) ;
2000-07-26 19:01:44 +08:00
}
/* }}} */
2000-10-17 23:51:04 +08:00
2002-02-11 10:48:49 +08:00
/* {{{ proto bool ldap_sort(resource link, resource result, string sortfilter)
2001-11-22 04:14:17 +08:00
Sort LDAP result entries */
PHP_FUNCTION ( ldap_sort )
{
zval * link , * result ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2001-11-22 04:14:17 +08:00
char * sortfilter ;
2014-08-27 21:31:48 +08:00
size_t sflen ;
2014-05-20 11:26:26 +08:00
zend_resource * le ;
2001-11-22 04:14:17 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rrs " , & link , & result , & sortfilter , & sflen ) ! = SUCCESS ) {
2001-11-22 04:14:17 +08:00
RETURN_FALSE ;
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
2001-11-22 04:14:17 +08:00
2015-04-07 19:19:12 +08:00
le = Z_RES_P ( result ) ;
if ( le - > type ! = le_result ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Supplied resource is not a valid ldap result resource " ) ;
2001-11-22 04:14:17 +08:00
RETURN_FALSE ;
}
2001-11-30 04:17:17 +08:00
if ( ldap_sort_entries ( ld - > link , ( LDAPMessage * * ) & le - > ptr , sflen ? sortfilter : NULL , strcmp ) ! = LDAP_SUCCESS ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " %s " , ldap_err2string ( errno ) ) ;
2001-11-22 04:14:17 +08:00
RETURN_FALSE ;
}
RETURN_TRUE ;
}
/* }}} */
2013-10-05 06:50:16 +08:00
# if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP
2002-02-11 10:48:49 +08:00
/* {{{ proto bool ldap_get_option(resource link, int option, mixed retval)
2000-10-18 00:06:04 +08:00
Get the current value of various session - wide parameters */
2015-01-03 17:22:58 +08:00
PHP_FUNCTION ( ldap_get_option )
2001-06-01 05:09:30 +08:00
{
2008-04-16 22:21:04 +08:00
zval * link , * retval ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2014-08-26 01:24:55 +08:00
zend_long option ;
2015-01-03 17:22:58 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rlz/ " , & link , & option , & retval ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
2000-10-18 00:06:04 +08:00
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
2000-10-18 00:06:04 +08:00
2008-04-16 22:21:04 +08:00
switch ( option ) {
2003-06-09 07:34:51 +08:00
/* options with int value */
2000-10-18 00:06:04 +08:00
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 :
2002-07-10 04:54:49 +08:00
# ifdef LDAP_OPT_RESTART
2000-10-18 00:06:04 +08:00
case LDAP_OPT_RESTART :
2016-02-16 16:39:58 +08:00
# endif
# ifdef LDAP_OPT_X_TLS_REQUIRE_CERT
case LDAP_OPT_X_TLS_REQUIRE_CERT :
2002-07-10 04:54:49 +08:00
# endif
2000-10-18 00:06:04 +08:00
{
int val ;
2007-10-06 09:43:26 +08:00
2008-04-16 22:21:04 +08:00
if ( ldap_get_option ( ld - > link , option , & val ) ) {
2000-10-18 00:06:04 +08:00
RETURN_FALSE ;
}
2014-05-20 11:26:26 +08:00
zval_ptr_dtor ( retval ) ;
2014-08-26 01:24:55 +08:00
ZVAL_LONG ( retval , val ) ;
2000-10-18 00:06:04 +08:00
} break ;
2008-02-10 05:59:17 +08:00
# ifdef LDAP_OPT_NETWORK_TIMEOUT
2007-10-06 09:43:26 +08:00
case LDAP_OPT_NETWORK_TIMEOUT :
{
2009-11-18 21:37:45 +08:00
struct timeval * timeout = NULL ;
2007-10-06 10:13:50 +08:00
if ( ldap_get_option ( ld - > link , LDAP_OPT_NETWORK_TIMEOUT , ( void * ) & timeout ) ) {
2007-10-06 09:43:26 +08:00
if ( timeout ) {
ldap_memfree ( timeout ) ;
}
RETURN_FALSE ;
2015-01-03 17:22:58 +08:00
}
2009-11-18 21:37:45 +08:00
if ( ! timeout ) {
RETURN_FALSE ;
}
2014-05-20 11:26:26 +08:00
zval_ptr_dtor ( retval ) ;
2014-08-26 01:24:55 +08:00
ZVAL_LONG ( retval , timeout - > tv_sec ) ;
2007-10-06 09:43:26 +08:00
ldap_memfree ( timeout ) ;
2008-02-10 05:59:17 +08:00
} break ;
# elif defined(LDAP_X_OPT_CONNECT_TIMEOUT)
case LDAP_X_OPT_CONNECT_TIMEOUT :
{
2007-10-06 10:13:50 +08:00
int timeout ;
if ( ldap_get_option ( ld - > link , LDAP_X_OPT_CONNECT_TIMEOUT , & timeout ) ) {
RETURN_FALSE ;
2015-01-03 17:22:58 +08:00
}
2014-05-20 11:26:26 +08:00
zval_ptr_dtor ( retval ) ;
2014-08-26 01:24:55 +08:00
ZVAL_LONG ( retval , ( timeout / 1000 ) ) ;
2007-10-06 09:43:26 +08:00
} break ;
2015-09-10 00:02:10 +08:00
# endif
# ifdef LDAP_OPT_TIMEOUT
case LDAP_OPT_TIMEOUT :
{
struct timeval * timeout = NULL ;
if ( ldap_get_option ( ld - > link , LDAP_OPT_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 ;
2007-10-06 09:43:26 +08:00
# endif
2003-06-09 07:34:51 +08:00
/* options with string value */
2000-10-18 00:06:04 +08:00
case LDAP_OPT_ERROR_STRING :
2005-05-08 23:43:22 +08:00
# ifdef LDAP_OPT_HOST_NAME
case LDAP_OPT_HOST_NAME :
# endif
2005-04-18 00:25:59 +08:00
# ifdef HAVE_LDAP_SASL
2015-01-03 17:22:58 +08:00
case LDAP_OPT_X_SASL_MECH :
2005-04-18 00:25:59 +08:00
case LDAP_OPT_X_SASL_REALM :
case LDAP_OPT_X_SASL_AUTHCID :
case LDAP_OPT_X_SASL_AUTHZID :
# endif
2001-01-08 05:18:02 +08:00
# ifdef LDAP_OPT_MATCHED_DN
2000-10-18 00:06:04 +08:00
case LDAP_OPT_MATCHED_DN :
2000-11-04 06:53:49 +08:00
# endif
2003-06-09 07:34:51 +08:00
{
2003-10-07 07:33:00 +08:00
char * val = NULL ;
2008-04-16 22:21:04 +08:00
if ( ldap_get_option ( ld - > link , option , & val ) | | val = = NULL | | * val = = ' \0 ' ) {
2003-10-07 08:36:31 +08:00
if ( val ) {
ldap_memfree ( val ) ;
2003-10-07 07:33:00 +08:00
}
RETURN_FALSE ;
}
2014-05-20 11:26:26 +08:00
zval_ptr_dtor ( retval ) ;
ZVAL_STRING ( retval , val ) ;
2003-10-07 08:36:31 +08:00
ldap_memfree ( val ) ;
2000-10-18 00:06:04 +08:00
} break ;
2000-10-29 03:22:46 +08:00
/* options not implemented
2000-10-18 00:06:04 +08:00
case LDAP_OPT_SERVER_CONTROLS :
case LDAP_OPT_CLIENT_CONTROLS :
case LDAP_OPT_API_INFO :
case LDAP_OPT_API_FEATURE_INFO :
2000-10-29 03:22:46 +08:00
*/
2000-10-18 00:06:04 +08:00
default :
RETURN_FALSE ;
}
RETURN_TRUE ;
}
/* }}} */
2002-02-11 10:48:49 +08:00
/* {{{ proto bool ldap_set_option(resource link, int option, mixed newval)
2000-10-18 00:06:04 +08:00
Set the value of various session - wide parameters */
2015-01-03 17:22:58 +08:00
PHP_FUNCTION ( ldap_set_option )
2001-06-01 05:09:30 +08:00
{
2014-05-20 11:26:26 +08:00
zval * link , * newval ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2001-12-24 00:32:06 +08:00
LDAP * ldap ;
2014-08-26 01:24:55 +08:00
zend_long option ;
2015-01-03 17:22:58 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " zlz " , & link , & option , & newval ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
2000-10-18 00:06:04 +08:00
}
2008-04-16 22:21:04 +08:00
if ( Z_TYPE_P ( link ) = = IS_NULL ) {
2001-12-24 00:32:06 +08:00
ldap = NULL ;
} else {
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource_ex ( link , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
2001-12-24 00:32:06 +08:00
ldap = ld - > link ;
}
2001-06-01 05:09:30 +08:00
2008-04-16 22:21:04 +08:00
switch ( option ) {
2005-04-18 00:25:59 +08:00
/* options with int value */
2000-10-18 00:06:04 +08:00
case LDAP_OPT_DEREF :
case LDAP_OPT_SIZELIMIT :
case LDAP_OPT_TIMELIMIT :
case LDAP_OPT_PROTOCOL_VERSION :
case LDAP_OPT_ERROR_NUMBER :
2001-12-24 00:32:06 +08:00
# ifdef LDAP_OPT_DEBUG_LEVEL
case LDAP_OPT_DEBUG_LEVEL :
2016-02-16 16:39:58 +08:00
# endif
# ifdef LDAP_OPT_X_TLS_REQUIRE_CERT
case LDAP_OPT_X_TLS_REQUIRE_CERT :
2001-12-24 00:32:06 +08:00
# endif
2000-10-18 00:06:04 +08:00
{
int val ;
2007-10-06 09:43:26 +08:00
2014-08-26 03:51:49 +08:00
convert_to_long_ex ( newval ) ;
2014-08-26 01:24:55 +08:00
val = Z_LVAL_P ( newval ) ;
2008-04-16 22:21:04 +08:00
if ( ldap_set_option ( ldap , option , & val ) ) {
2000-10-18 00:06:04 +08:00
RETURN_FALSE ;
}
} break ;
2008-02-10 05:59:17 +08:00
# ifdef LDAP_OPT_NETWORK_TIMEOUT
2007-10-06 09:43:26 +08:00
case LDAP_OPT_NETWORK_TIMEOUT :
{
struct timeval timeout ;
2007-10-06 10:13:50 +08:00
2014-08-26 03:51:49 +08:00
convert_to_long_ex ( newval ) ;
2014-08-26 01:24:55 +08:00
timeout . tv_sec = Z_LVAL_P ( newval ) ;
2007-10-06 09:43:26 +08:00
timeout . tv_usec = 0 ;
2007-10-06 10:13:50 +08:00
if ( ldap_set_option ( ldap , LDAP_OPT_NETWORK_TIMEOUT , ( void * ) & timeout ) ) {
2007-10-06 09:43:26 +08:00
RETURN_FALSE ;
2015-01-03 17:22:58 +08:00
}
2008-02-10 05:59:17 +08:00
} break ;
# elif defined(LDAP_X_OPT_CONNECT_TIMEOUT)
case LDAP_X_OPT_CONNECT_TIMEOUT :
{
2007-10-06 10:13:50 +08:00
int timeout ;
2014-08-26 03:51:49 +08:00
convert_to_long_ex ( newval ) ;
2014-08-26 01:24:55 +08:00
timeout = 1000 * Z_LVAL_P ( newval ) ; /* Convert to milliseconds */
2007-10-06 10:13:50 +08:00
if ( ldap_set_option ( ldap , LDAP_X_OPT_CONNECT_TIMEOUT , & timeout ) ) {
RETURN_FALSE ;
2015-01-03 17:22:58 +08:00
}
2007-10-06 09:43:26 +08:00
} break ;
2015-09-10 00:02:10 +08:00
# endif
# ifdef LDAP_OPT_TIMEOUT
case LDAP_OPT_TIMEOUT :
{
struct timeval timeout ;
convert_to_long_ex ( newval ) ;
2015-09-11 01:24:11 +08:00
timeout . tv_sec = Z_LVAL_P ( newval ) ;
2015-09-10 00:02:10 +08:00
timeout . tv_usec = 0 ;
if ( ldap_set_option ( ldap , LDAP_OPT_TIMEOUT , ( void * ) & timeout ) ) {
RETURN_FALSE ;
}
} break ;
2007-10-06 09:43:26 +08:00
# endif
2000-10-18 00:06:04 +08:00
/* options with string value */
case LDAP_OPT_ERROR_STRING :
2005-05-08 23:43:22 +08:00
# ifdef LDAP_OPT_HOST_NAME
case LDAP_OPT_HOST_NAME :
# endif
2005-04-18 00:25:59 +08:00
# ifdef HAVE_LDAP_SASL
2015-01-03 17:22:58 +08:00
case LDAP_OPT_X_SASL_MECH :
2005-04-18 00:25:59 +08:00
case LDAP_OPT_X_SASL_REALM :
case LDAP_OPT_X_SASL_AUTHCID :
case LDAP_OPT_X_SASL_AUTHZID :
# endif
2001-01-09 02:13:08 +08:00
# ifdef LDAP_OPT_MATCHED_DN
2000-10-18 00:06:04 +08:00
case LDAP_OPT_MATCHED_DN :
2000-11-04 06:53:49 +08:00
# endif
2000-10-18 00:06:04 +08:00
{
char * val ;
convert_to_string_ex ( newval ) ;
2014-05-20 11:26:26 +08:00
val = Z_STRVAL_P ( newval ) ;
2008-04-16 22:21:04 +08:00
if ( ldap_set_option ( ldap , option , val ) ) {
2000-10-18 00:06:04 +08:00
RETURN_FALSE ;
}
} break ;
/* options with boolean value */
case LDAP_OPT_REFERRALS :
2002-07-10 04:54:49 +08:00
# ifdef LDAP_OPT_RESTART
2000-10-18 00:06:04 +08:00
case LDAP_OPT_RESTART :
2002-07-10 04:54:49 +08:00
# endif
2000-10-18 00:06:04 +08:00
{
void * val ;
convert_to_boolean_ex ( newval ) ;
2014-05-20 11:26:26 +08:00
val = Z_TYPE_P ( newval ) = = IS_TRUE
2000-10-18 00:06:04 +08:00
? LDAP_OPT_ON : LDAP_OPT_OFF ;
2008-04-16 22:21:04 +08:00
if ( ldap_set_option ( ldap , option , val ) ) {
2000-10-18 00:06:04 +08:00
RETURN_FALSE ;
}
} break ;
2001-01-08 05:18:02 +08:00
/* options with control list value */
2000-10-18 00:06:04 +08:00
case LDAP_OPT_SERVER_CONTROLS :
case LDAP_OPT_CLIENT_CONTROLS :
2001-01-08 05:18:02 +08:00
{
LDAPControl * ctrl , * * ctrls , * * ctrlp ;
2014-05-20 11:26:26 +08:00
zval * ctrlval , * val ;
2001-01-08 05:18:02 +08:00
int ncontrols ;
char error = 0 ;
2014-05-20 11:26:26 +08:00
if ( ( Z_TYPE_P ( newval ) ! = IS_ARRAY ) | | ! ( ncontrols = zend_hash_num_elements ( Z_ARRVAL_P ( newval ) ) ) ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Expected non-empty array value for this option " ) ;
2003-06-09 07:34:51 +08:00
RETURN_FALSE ;
}
2003-05-01 05:53:53 +08:00
ctrls = safe_emalloc ( ( 1 + ncontrols ) , sizeof ( * ctrls ) , 0 ) ;
2001-01-08 05:18:02 +08:00
* ctrls = NULL ;
ctrlp = ctrls ;
2014-05-28 21:49:31 +08:00
ZEND_HASH_FOREACH_VAL ( Z_ARRVAL_P ( newval ) , ctrlval ) {
2014-05-20 11:26:26 +08:00
if ( Z_TYPE_P ( ctrlval ) ! = IS_ARRAY ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " The array value must contain only arrays, where each array is a control " ) ;
2001-01-08 05:18:02 +08:00
error = 1 ;
break ;
}
2014-05-20 11:26:26 +08:00
if ( ( val = zend_hash_str_find ( Z_ARRVAL_P ( ctrlval ) , " oid " , sizeof ( " oid " ) - 1 ) ) = = NULL ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Control must have an oid key " ) ;
2001-01-08 05:18:02 +08:00
error = 1 ;
break ;
}
ctrl = * ctrlp = emalloc ( sizeof ( * * ctrlp ) ) ;
convert_to_string_ex ( val ) ;
2014-05-20 11:26:26 +08:00
ctrl - > ldctl_oid = Z_STRVAL_P ( val ) ;
if ( ( val = zend_hash_str_find ( Z_ARRVAL_P ( ctrlval ) , " value " , sizeof ( " value " ) - 1 ) ) ! = NULL ) {
2001-01-08 05:18:02 +08:00
convert_to_string_ex ( val ) ;
2014-05-20 11:26:26 +08:00
ctrl - > ldctl_value . bv_val = Z_STRVAL_P ( val ) ;
2014-08-26 01:24:55 +08:00
ctrl - > ldctl_value . bv_len = Z_STRLEN_P ( val ) ;
2001-01-08 05:18:02 +08:00
} else {
ctrl - > ldctl_value . bv_val = NULL ;
ctrl - > ldctl_value . bv_len = 0 ;
}
2014-05-20 11:26:26 +08:00
if ( ( val = zend_hash_str_find ( Z_ARRVAL_P ( ctrlval ) , " iscritical " , sizeof ( " iscritical " ) - 1 ) ) ! = NULL ) {
2001-01-08 05:18:02 +08:00
convert_to_boolean_ex ( val ) ;
2014-05-20 11:26:26 +08:00
ctrl - > ldctl_iscritical = Z_TYPE_P ( val ) = = IS_TRUE ;
2001-01-08 05:18:02 +08:00
} else {
ctrl - > ldctl_iscritical = 0 ;
}
2015-01-03 17:22:58 +08:00
2001-01-08 05:18:02 +08:00
+ + ctrlp ;
* ctrlp = NULL ;
2014-05-28 21:49:31 +08:00
} ZEND_HASH_FOREACH_END ( ) ;
2001-01-08 05:18:02 +08:00
if ( ! error ) {
2008-04-16 22:21:04 +08:00
error = ldap_set_option ( ldap , option , ctrls ) ;
2001-01-08 05:18:02 +08:00
}
ctrlp = ctrls ;
2003-06-09 07:34:51 +08:00
while ( * ctrlp ) {
2001-01-08 05:18:02 +08:00
efree ( * ctrlp ) ;
ctrlp + + ;
}
efree ( ctrls ) ;
if ( error ) {
RETURN_FALSE ;
}
} break ;
2000-10-18 00:06:04 +08:00
default :
RETURN_FALSE ;
}
RETURN_TRUE ;
}
/* }}} */
2001-01-07 21:03:11 +08:00
2005-05-08 23:43:22 +08:00
# ifdef HAVE_LDAP_PARSE_RESULT
2002-02-11 10:48:49 +08:00
/* {{{ proto bool ldap_parse_result(resource link, resource result, int errcode, string matcheddn, string errmsg, array referrals)
2001-01-07 21:03:11 +08:00
Extract information from result */
2015-01-03 17:22:58 +08:00
PHP_FUNCTION ( ldap_parse_result )
2001-06-01 05:09:30 +08:00
{
2008-04-16 22:21:04 +08:00
zval * link , * result , * errcode , * matcheddn , * errmsg , * referrals ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2001-01-07 21:03:11 +08:00
LDAPMessage * ldap_result ;
char * * lreferrals , * * refp ;
char * lmatcheddn , * lerrmsg ;
2001-06-01 05:09:30 +08:00
int rc , lerrcode , myargcount = ZEND_NUM_ARGS ( ) ;
2003-06-09 07:34:51 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rrz/|z/z/z/ " , & link , & result , & errcode , & matcheddn , & errmsg , & referrals ) ! = SUCCESS ) {
2015-01-03 17:22:58 +08:00
return ;
2001-01-07 21:03:11 +08:00
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( ldap_result = ( LDAPMessage * ) zend_fetch_resource ( Z_RES_P ( result ) , " ldap result " , le_result ) ) = = NULL ) {
RETURN_FALSE ;
}
2001-01-07 21:03:11 +08:00
2003-06-09 07:34:51 +08:00
rc = ldap_parse_result ( ld - > link , ldap_result , & lerrcode ,
2001-01-07 21:03:11 +08:00
myargcount > 3 ? & lmatcheddn : NULL ,
myargcount > 4 ? & lerrmsg : NULL ,
myargcount > 5 ? & lreferrals : NULL ,
NULL /* &serverctrls */ ,
2003-06-09 07:34:51 +08:00
0 ) ;
if ( rc ! = LDAP_SUCCESS ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to parse result: %s " , ldap_err2string ( rc ) ) ;
2001-01-07 21:03:11 +08:00
RETURN_FALSE ;
}
2014-05-20 11:26:26 +08:00
zval_ptr_dtor ( errcode ) ;
2014-08-26 01:24:55 +08:00
ZVAL_LONG ( errcode , lerrcode ) ;
2001-01-07 21:03:11 +08:00
/* Reverse -> fall through */
2003-06-09 07:34:51 +08:00
switch ( myargcount ) {
case 6 :
2014-05-20 11:26:26 +08:00
zval_ptr_dtor ( referrals ) ;
2008-04-16 22:21:04 +08:00
array_init ( referrals ) ;
2001-01-07 21:03:11 +08:00
if ( lreferrals ! = NULL ) {
refp = lreferrals ;
while ( * refp ) {
2014-04-15 19:40:40 +08:00
add_next_index_string ( referrals , * refp ) ;
2001-01-07 21:03:11 +08:00
refp + + ;
}
2015-06-23 22:44:48 +08:00
ldap_memvfree ( ( void * * ) lreferrals ) ;
2001-01-07 21:03:11 +08:00
}
2003-06-09 07:34:51 +08:00
case 5 :
2014-05-20 11:26:26 +08:00
zval_ptr_dtor ( errmsg ) ;
2001-01-07 21:03:11 +08:00
if ( lerrmsg = = NULL ) {
2008-04-16 22:21:04 +08:00
ZVAL_EMPTY_STRING ( errmsg ) ;
2001-01-07 21:03:11 +08:00
} else {
2014-05-20 11:26:26 +08:00
ZVAL_STRING ( errmsg , lerrmsg ) ;
2001-01-07 21:03:11 +08:00
ldap_memfree ( lerrmsg ) ;
}
2015-01-03 17:22:58 +08:00
case 4 :
2014-05-20 11:26:26 +08:00
zval_ptr_dtor ( matcheddn ) ;
2001-01-07 21:03:11 +08:00
if ( lmatcheddn = = NULL ) {
2008-04-16 22:21:04 +08:00
ZVAL_EMPTY_STRING ( matcheddn ) ;
2001-01-07 21:03:11 +08:00
} else {
2014-05-20 11:26:26 +08:00
ZVAL_STRING ( matcheddn , lmatcheddn ) ;
2001-01-07 21:03:11 +08:00
ldap_memfree ( lmatcheddn ) ;
}
}
RETURN_TRUE ;
}
/* }}} */
2005-05-08 23:43:22 +08:00
# endif
2001-01-07 21:03:11 +08:00
2002-02-11 10:48:49 +08:00
/* {{{ proto resource ldap_first_reference(resource link, resource result)
2001-01-07 21:03:11 +08:00
Return first reference */
PHP_FUNCTION ( ldap_first_reference )
{
2008-04-16 22:21:04 +08:00
zval * link , * result ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2002-05-04 22:27:48 +08:00
ldap_resultentry * resultentry ;
LDAPMessage * ldap_result , * entry ;
2001-01-07 21:03:11 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rr " , & link , & result ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
2001-01-07 21:03:11 +08:00
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( ldap_result = ( LDAPMessage * ) zend_fetch_resource ( Z_RES_P ( result ) , " ldap result " , le_result ) ) = = NULL ) {
RETURN_FALSE ;
}
2001-01-07 21:03:11 +08:00
2002-05-04 22:27:48 +08:00
if ( ( entry = ldap_first_reference ( ld - > link , ldap_result ) ) = = NULL ) {
2001-06-01 05:09:30 +08:00
RETVAL_FALSE ;
2001-01-07 21:03:11 +08:00
} else {
2002-05-04 22:27:48 +08:00
resultentry = emalloc ( sizeof ( ldap_resultentry ) ) ;
2015-02-02 15:05:20 +08:00
RETVAL_RES ( zend_register_resource ( resultentry , le_result_entry ) ) ;
2014-05-20 11:26:26 +08:00
ZVAL_COPY ( & resultentry - > res , result ) ;
2002-05-04 22:27:48 +08:00
resultentry - > data = entry ;
2009-12-22 04:39:48 +08:00
resultentry - > ber = NULL ;
2001-01-07 21:03:11 +08:00
}
}
/* }}} */
2002-05-04 22:27:48 +08:00
/* {{{ proto resource ldap_next_reference(resource link, resource reference_entry)
2001-01-07 21:03:11 +08:00
Get next reference */
PHP_FUNCTION ( ldap_next_reference )
{
2008-04-16 22:21:04 +08:00
zval * link , * result_entry ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2002-05-04 22:27:48 +08:00
ldap_resultentry * resultentry , * resultentry_next ;
LDAPMessage * entry_next ;
2001-01-07 21:03:11 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rr " , & link , & result_entry ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
2001-01-07 21:03:11 +08:00
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( resultentry = ( ldap_resultentry * ) zend_fetch_resource ( Z_RES_P ( result_entry ) , " ldap result entry " , le_result_entry ) ) = = NULL ) {
RETURN_FALSE ;
}
2001-01-07 21:03:11 +08:00
2002-05-04 22:27:48 +08:00
if ( ( entry_next = ldap_next_reference ( ld - > link , resultentry - > data ) ) = = NULL ) {
2001-06-01 05:09:30 +08:00
RETVAL_FALSE ;
2001-01-07 21:03:11 +08:00
} else {
2002-05-04 22:27:48 +08:00
resultentry_next = emalloc ( sizeof ( ldap_resultentry ) ) ;
2015-02-02 15:05:20 +08:00
RETVAL_RES ( zend_register_resource ( resultentry_next , le_result_entry ) ) ;
2014-05-20 11:26:26 +08:00
ZVAL_COPY ( & resultentry_next - > res , & resultentry - > res ) ;
2002-05-04 22:27:48 +08:00
resultentry_next - > data = entry_next ;
2009-12-22 04:39:48 +08:00
resultentry_next - > ber = NULL ;
2001-01-07 21:03:11 +08:00
}
}
/* }}} */
2002-06-22 23:41:39 +08:00
# ifdef HAVE_LDAP_PARSE_REFERENCE
2002-05-04 22:27:48 +08:00
/* {{{ proto bool ldap_parse_reference(resource link, resource reference_entry, array referrals)
2001-01-07 21:03:11 +08:00
Extract information from reference entry */
PHP_FUNCTION ( ldap_parse_reference )
{
2008-04-16 22:21:04 +08:00
zval * link , * result_entry , * referrals ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2002-05-04 22:27:48 +08:00
ldap_resultentry * resultentry ;
2001-01-07 21:03:11 +08:00
char * * lreferrals , * * refp ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rrz/ " , & link , & result_entry , & referrals ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
2001-01-07 21:03:11 +08:00
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( resultentry = ( ldap_resultentry * ) zend_fetch_resource ( Z_RES_P ( result_entry ) , " ldap result entry " , le_result_entry ) ) = = NULL ) {
RETURN_FALSE ;
}
2001-01-07 21:03:11 +08:00
2002-05-04 22:27:48 +08:00
if ( ldap_parse_reference ( ld - > link , resultentry - > data , & lreferrals , NULL /* &serverctrls */ , 0 ) ! = LDAP_SUCCESS ) {
2001-01-07 21:03:11 +08:00
RETURN_FALSE ;
}
2014-05-20 11:26:26 +08:00
zval_ptr_dtor ( referrals ) ;
2008-04-16 22:21:04 +08:00
array_init ( referrals ) ;
2001-01-07 21:03:11 +08:00
if ( lreferrals ! = NULL ) {
refp = lreferrals ;
while ( * refp ) {
2014-04-15 19:40:40 +08:00
add_next_index_string ( referrals , * refp ) ;
2001-01-07 21:03:11 +08:00
refp + + ;
}
2015-06-23 22:44:48 +08:00
ldap_memvfree ( ( void * * ) lreferrals ) ;
2001-01-07 21:03:11 +08:00
}
RETURN_TRUE ;
}
/* }}} */
2002-06-22 23:41:39 +08:00
# endif
2001-01-09 02:13:08 +08:00
2015-06-24 03:47:07 +08:00
/* {{{ proto bool ldap_rename(resource link, string dn, string newrdn, string newparent, bool deleteoldrdn)
2001-01-09 02:13:08 +08:00
Modify the name of an entry */
PHP_FUNCTION ( ldap_rename )
{
2008-04-16 22:21:04 +08:00
zval * link ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2001-01-09 02:13:08 +08:00
int rc ;
2008-04-16 22:21:04 +08:00
char * dn , * newrdn , * newparent ;
2014-08-28 15:43:14 +08:00
size_t dn_len , newrdn_len , newparent_len ;
2008-04-16 22:21:04 +08:00
zend_bool deleteoldrdn ;
2015-01-03 17:22:58 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rsssb " , & link , & dn , & dn_len , & newrdn , & newrdn_len , & newparent , & newparent_len , & deleteoldrdn ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
2001-01-09 02:13:08 +08:00
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
2001-01-09 02:13:08 +08:00
2008-04-16 22:21:04 +08:00
if ( newparent_len = = 0 ) {
newparent = NULL ;
}
2007-07-17 16:40:24 +08:00
2013-10-05 06:50:16 +08:00
# if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP
2008-04-16 22:21:04 +08:00
rc = ldap_rename_s ( ld - > link , dn , newrdn , newparent , deleteoldrdn , NULL , NULL ) ;
2001-01-09 02:13:08 +08:00
# else
2008-04-16 22:21:04 +08:00
if ( newparent_len ! = 0 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " You are using old LDAP API, newparent must be the empty string, can only modify RDN " ) ;
2001-01-09 02:13:08 +08:00
RETURN_FALSE ;
}
/* could support old APIs but need check for ldap_modrdn2()/ldap_modrdn() */
2008-04-16 22:21:04 +08:00
rc = ldap_modrdn2_s ( ld - > link , dn , newrdn , deleteoldrdn ) ;
2001-01-09 02:13:08 +08:00
# endif
if ( rc = = LDAP_SUCCESS ) {
RETURN_TRUE ;
}
RETURN_FALSE ;
}
/* }}} */
2000-10-18 00:06:04 +08:00
2002-06-22 23:41:39 +08:00
# ifdef HAVE_LDAP_START_TLS_S
2002-02-11 10:48:49 +08:00
/* {{{ proto bool ldap_start_tls(resource link)
2001-10-10 05:14:14 +08:00
Start TLS */
PHP_FUNCTION ( ldap_start_tls )
{
2008-04-16 22:21:04 +08:00
zval * link ;
2001-11-30 04:17:17 +08:00
ldap_linkdata * ld ;
2005-01-19 08:27:21 +08:00
int rc , protocol = LDAP_VERSION3 ;
2001-10-10 05:14:14 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " r " , & link ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
2001-10-10 05:14:14 +08:00
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
2001-10-10 05:14:14 +08:00
2005-01-19 08:27:21 +08:00
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 )
) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to start TLS: %s " , ldap_err2string ( rc ) ) ;
2001-10-10 05:14:14 +08:00
RETURN_FALSE ;
} else {
RETURN_TRUE ;
}
}
/* }}} */
# endif
2013-10-05 06:50:16 +08:00
# endif /* (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP */
2001-10-10 05:14:14 +08:00
2015-08-18 22:52:44 +08:00
# if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
2005-04-06 04:31:10 +08:00
/* {{{ _ldap_rebind_proc()
2003-06-09 07:34:51 +08:00
*/
int _ldap_rebind_proc ( LDAP * ldap , const char * url , ber_tag_t req , ber_int_t msgid , void * params )
{
2001-11-30 04:26:20 +08:00
ldap_linkdata * ld ;
int retval ;
2014-05-20 11:26:26 +08:00
zval cb_args [ 2 ] ;
zval cb_retval ;
2001-11-30 04:26:20 +08:00
zval * cb_link = ( zval * ) params ;
2015-02-02 15:05:20 +08:00
ld = ( ldap_linkdata * ) zend_fetch_resource_ex ( cb_link , " ldap link " , le_link ) ;
2001-11-30 04:26:20 +08:00
/* link exists and callback set? */
2014-05-20 11:26:26 +08:00
if ( ld = = NULL | | Z_ISUNDEF ( ld - > rebindproc ) ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Link not found or no callback set " ) ;
2001-11-30 04:26:20 +08:00
return LDAP_OTHER ;
}
/* callback */
2014-05-20 11:26:26 +08:00
ZVAL_COPY_VALUE ( & cb_args [ 0 ] , cb_link ) ;
ZVAL_STRING ( & cb_args [ 1 ] , url ) ;
2014-12-14 06:06:14 +08:00
if ( call_user_function_ex ( EG ( function_table ) , NULL , & ld - > rebindproc , & cb_retval , 2 , cb_args , 0 , NULL ) = = SUCCESS & & ! Z_ISUNDEF ( cb_retval ) ) {
2014-08-26 03:51:49 +08:00
convert_to_long_ex ( & cb_retval ) ;
2014-08-26 01:24:55 +08:00
retval = Z_LVAL ( cb_retval ) ;
2001-11-30 04:26:20 +08:00
zval_ptr_dtor ( & cb_retval ) ;
} else {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " rebind_proc PHP callback failed " ) ;
2001-11-30 04:26:20 +08:00
retval = LDAP_OTHER ;
}
2014-05-20 11:26:26 +08:00
zval_ptr_dtor ( & cb_args [ 1 ] ) ;
2001-11-30 04:26:20 +08:00
return retval ;
}
2003-06-09 07:34:51 +08:00
/* }}} */
2001-11-30 04:26:20 +08:00
2002-02-11 10:48:49 +08:00
/* {{{ proto bool ldap_set_rebind_proc(resource link, string callback)
2001-11-30 04:26:20 +08:00
Set a callback function to do re - binds on referral chasing . */
PHP_FUNCTION ( ldap_set_rebind_proc )
{
zval * link , * callback ;
ldap_linkdata * ld ;
2014-05-20 11:26:26 +08:00
zend_string * callback_name ;
2001-11-30 04:26:20 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rz " , & link , & callback ) ! = SUCCESS ) {
2001-11-30 04:26:20 +08:00
RETURN_FALSE ;
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
2001-11-30 04:26:20 +08:00
2014-08-26 01:24:55 +08:00
if ( Z_TYPE_P ( callback ) = = IS_STRING & & Z_STRLEN_P ( callback ) = = 0 ) {
2001-11-30 04:26:20 +08:00
/* unregister rebind procedure */
2014-05-20 11:26:26 +08:00
if ( ! Z_ISUNDEF ( ld - > rebindproc ) ) {
zval_ptr_dtor ( & ld - > rebindproc ) ;
ZVAL_UNDEF ( & ld - > rebindproc ) ;
2001-11-30 04:26:20 +08:00
ldap_set_rebind_proc ( ld - > link , NULL , NULL ) ;
}
RETURN_TRUE ;
}
/* callable? */
2014-12-14 06:06:14 +08:00
if ( ! zend_is_callable ( callback , 0 , & callback_name ) ) {
2015-06-30 18:59:27 +08:00
php_error_docref ( NULL , E_WARNING , " Two arguments expected for '%s' to be a valid callback " , ZSTR_VAL ( callback_name ) ) ;
2014-08-26 01:24:55 +08:00
zend_string_release ( callback_name ) ;
2001-11-30 04:26:20 +08:00
RETURN_FALSE ;
}
2014-08-26 01:24:55 +08:00
zend_string_release ( callback_name ) ;
2001-11-30 04:26:20 +08:00
/* register rebind procedure */
2014-05-20 11:26:26 +08:00
if ( Z_ISUNDEF ( ld - > rebindproc ) ) {
2001-11-30 04:26:20 +08:00
ldap_set_rebind_proc ( ld - > link , _ldap_rebind_proc , ( void * ) link ) ;
} else {
2014-05-20 11:26:26 +08:00
zval_ptr_dtor ( & ld - > rebindproc ) ;
2001-11-30 04:26:20 +08:00
}
2014-05-20 11:26:26 +08:00
ZVAL_COPY ( & ld - > rebindproc , callback ) ;
2001-11-30 04:26:20 +08:00
RETURN_TRUE ;
}
2003-06-09 07:34:51 +08:00
/* }}} */
2001-11-30 04:26:20 +08:00
# endif
2015-07-01 18:49:57 +08:00
static zend_string * php_ldap_do_escape ( const zend_bool * map , const char * value , size_t valuelen )
2013-09-17 23:34:30 +08:00
{
char hex [ ] = " 0123456789abcdef " ;
int i , p = 0 ;
size_t len = 0 ;
2015-07-01 18:49:57 +08:00
zend_string * ret ;
2013-09-17 23:34:30 +08:00
for ( i = 0 ; i < valuelen ; i + + ) {
2013-10-18 17:34:24 +08:00
len + = ( map [ ( unsigned char ) value [ i ] ] ) ? 3 : 1 ;
2013-09-17 23:34:30 +08:00
}
2015-07-01 18:49:57 +08:00
ret = zend_string_alloc ( len , 0 ) ;
2013-09-17 23:34:30 +08:00
for ( i = 0 ; i < valuelen ; i + + ) {
2013-10-18 17:34:24 +08:00
unsigned char v = ( unsigned char ) value [ i ] ;
if ( map [ v ] ) {
2015-07-01 18:49:57 +08:00
ZSTR_VAL ( ret ) [ p + + ] = ' \\ ' ;
ZSTR_VAL ( ret ) [ p + + ] = hex [ v > > 4 ] ;
ZSTR_VAL ( ret ) [ p + + ] = hex [ v & 0x0f ] ;
2013-09-17 23:34:30 +08:00
} else {
2015-07-01 18:49:57 +08:00
ZSTR_VAL ( ret ) [ p + + ] = v ;
2013-09-17 23:34:30 +08:00
}
}
2015-07-01 18:49:57 +08:00
ZSTR_VAL ( ret ) [ p ] = ' \0 ' ;
ZSTR_LEN ( ret ) = p ;
2015-07-06 16:25:19 +08:00
return ret ;
2013-09-17 23:34:30 +08:00
}
2013-10-18 17:34:24 +08:00
static void php_ldap_escape_map_set_chars ( zend_bool * map , const char * chars , const int charslen , char escape )
2013-09-17 23:34:30 +08:00
{
int i = 0 ;
while ( i < charslen ) {
2013-10-18 17:34:24 +08:00
map [ ( unsigned char ) chars [ i + + ] ] = escape ;
2013-09-17 23:34:30 +08:00
}
}
PHP_FUNCTION ( ldap_escape )
{
2015-07-01 18:49:57 +08:00
char * value , * ignores ;
2014-08-27 21:31:48 +08:00
size_t valuelen = 0 , ignoreslen = 0 ;
int i ;
2014-08-26 01:24:55 +08:00
zend_long flags = 0 ;
2013-09-17 23:34:30 +08:00
zend_bool map [ 256 ] = { 0 } , havecharlist = 0 ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " s|sl " , & value , & valuelen , & ignores , & ignoreslen , & flags ) ! = SUCCESS ) {
2013-09-17 23:34:30 +08:00
return ;
}
if ( ! valuelen ) {
RETURN_EMPTY_STRING ( ) ;
}
if ( flags & PHP_LDAP_ESCAPE_FILTER ) {
havecharlist = 1 ;
php_ldap_escape_map_set_chars ( map , " \\ *() \0 " , sizeof ( " \\ *() \0 " ) - 1 , 1 ) ;
}
if ( flags & PHP_LDAP_ESCAPE_DN ) {
havecharlist = 1 ;
php_ldap_escape_map_set_chars ( map , " \\ ,=+<>; \" # " , sizeof ( " \\ ,=+<>; \" # " ) - 1 , 1 ) ;
}
if ( ! havecharlist ) {
for ( i = 0 ; i < 256 ; i + + ) {
map [ i ] = 1 ;
}
}
if ( ignoreslen ) {
php_ldap_escape_map_set_chars ( map , ignores , ignoreslen , 0 ) ;
}
2015-07-01 18:49:57 +08:00
RETURN_NEW_STR ( php_ldap_do_escape ( map , value , valuelen ) ) ;
2013-09-17 23:34:30 +08:00
}
2000-08-02 21:11:46 +08:00
# ifdef STR_TRANSLATION
2001-06-05 21:12:10 +08:00
/* {{{ php_ldap_do_translate
*/
2015-01-03 17:22:58 +08:00
static void php_ldap_do_translate ( INTERNAL_FUNCTION_PARAMETERS , int way )
2001-06-01 05:09:30 +08:00
{
2008-04-16 22:21:04 +08:00
char * value ;
2015-01-21 15:00:40 +08:00
size_t value_len ;
int result ;
2015-01-03 17:22:58 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " s " , & value , & value_len ) ! = SUCCESS ) {
2008-04-16 22:21:04 +08:00
return ;
2000-08-02 21:11:46 +08:00
}
2008-04-16 22:21:04 +08:00
if ( value_len = = 0 ) {
2000-08-02 21:11:46 +08:00
RETURN_FALSE ;
}
2003-06-09 07:34:51 +08:00
if ( way = = 1 ) {
2008-04-16 22:21:04 +08:00
result = ldap_8859_to_t61 ( & value , & value_len , 0 ) ;
2000-08-02 21:11:46 +08:00
} else {
2008-04-16 22:21:04 +08:00
result = ldap_t61_to_8859 ( & value , & value_len , 0 ) ;
2000-08-02 21:11:46 +08:00
}
if ( result = = LDAP_SUCCESS ) {
2014-05-20 11:26:26 +08:00
RETVAL_STRINGL ( value , value_len ) ;
2008-04-16 22:21:04 +08:00
free ( value ) ;
2000-08-02 21:11:46 +08:00
} else {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Conversion from iso-8859-1 to t61 failed: %s " , ldap_err2string ( result ) ) ;
2000-08-02 21:11:46 +08:00
RETVAL_FALSE ;
}
}
2001-06-05 21:12:10 +08:00
/* }}} */
2000-08-02 21:11:46 +08:00
/* {{{ proto string ldap_t61_to_8859(string value)
Translate t61 characters to 8859 characters */
2001-08-05 09:43:02 +08:00
PHP_FUNCTION ( ldap_t61_to_8859 )
{
2000-08-02 21:11:46 +08:00
php_ldap_do_translate ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 ) ;
}
/* }}} */
/* {{{ proto string ldap_8859_to_t61(string value)
Translate 8859 characters to t61 characters */
2001-08-05 09:43:02 +08:00
PHP_FUNCTION ( ldap_8859_to_t61 )
{
2000-08-02 21:11:46 +08:00
php_ldap_do_translate ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 ) ;
}
/* }}} */
# endif
2001-06-05 21:12:10 +08:00
2010-06-16 03:47:28 +08:00
# ifdef LDAP_CONTROL_PAGEDRESULTS
2011-07-15 02:49:12 +08:00
/* {{{ proto mixed ldap_control_paged_result(resource link, int pagesize [, bool iscritical [, string cookie]])
2010-06-16 03:47:28 +08:00
Inject paged results control */
2015-01-03 17:22:58 +08:00
PHP_FUNCTION ( ldap_control_paged_result )
2010-06-16 03:47:28 +08:00
{
2014-08-26 01:24:55 +08:00
zend_long pagesize ;
2010-09-08 09:46:23 +08:00
zend_bool iscritical ;
2011-05-20 01:41:21 +08:00
zval * link ;
char * cookie = NULL ;
2014-08-27 21:31:48 +08:00
size_t cookie_len = 0 ;
2010-06-16 03:47:28 +08:00
struct berval lcookie = { 0 , NULL } ;
ldap_linkdata * ld ;
LDAP * ldap ;
BerElement * ber = NULL ;
LDAPControl ctrl , * ctrlsp [ 2 ] ;
int rc , myargcount = ZEND_NUM_ARGS ( ) ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rl|bs " , & link , & pagesize , & iscritical , & cookie , & cookie_len ) ! = SUCCESS ) {
2010-06-16 03:47:28 +08:00
return ;
}
2011-05-20 01:41:21 +08:00
if ( Z_TYPE_P ( link ) = = IS_NULL ) {
2010-06-16 03:47:28 +08:00
ldap = NULL ;
} else {
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource_ex ( link , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
2010-06-16 03:47:28 +08:00
ldap = ld - > link ;
}
ber = ber_alloc_t ( LBER_USE_DER ) ;
if ( ber = = NULL ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to alloc BER encoding resources for paged results control " ) ;
2010-06-16 03:47:28 +08:00
RETURN_FALSE ;
}
ctrl . ldctl_iscritical = 0 ;
switch ( myargcount ) {
case 4 :
2011-05-20 01:41:21 +08:00
lcookie . bv_val = cookie ;
lcookie . bv_len = cookie_len ;
2010-06-16 03:47:28 +08:00
/* fallthru */
case 3 :
2010-09-08 09:46:23 +08:00
ctrl . ldctl_iscritical = ( int ) iscritical ;
2010-06-16 03:47:28 +08:00
/* fallthru */
}
2010-09-08 09:46:23 +08:00
if ( ber_printf ( ber , " {iO} " , ( int ) pagesize , & lcookie ) = = LBER_ERROR ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to BER printf paged results control " ) ;
2011-05-20 01:41:21 +08:00
RETVAL_FALSE ;
2010-06-16 03:47:28 +08:00
goto lcpr_error_out ;
}
rc = ber_flatten2 ( ber , & ctrl . ldctl_value , 0 ) ;
if ( rc = = LBER_ERROR ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to BER encode paged results control " ) ;
2011-05-20 01:41:21 +08:00
RETVAL_FALSE ;
2010-06-16 03:47:28 +08:00
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 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to set paged results control: %s (%d) " , ldap_err2string ( rc ) , rc ) ;
2011-05-20 01:41:21 +08:00
RETVAL_FALSE ;
2010-06-16 03:47:28 +08:00
goto lcpr_error_out ;
}
2011-05-20 01:41:21 +08:00
RETVAL_TRUE ;
2010-06-16 03:47:28 +08:00
} else {
/* return a PHP control object */
array_init ( return_value ) ;
2014-04-15 19:40:40 +08:00
add_assoc_string ( return_value , " oid " , ctrl . ldctl_oid ) ;
2011-05-20 01:41:21 +08:00
if ( ctrl . ldctl_value . bv_len ) {
2014-04-15 19:40:40 +08:00
add_assoc_stringl ( return_value , " value " , ctrl . ldctl_value . bv_val , ctrl . ldctl_value . bv_len ) ;
2010-06-16 03:47:28 +08:00
}
if ( ctrl . ldctl_iscritical ) {
add_assoc_bool ( return_value , " iscritical " , ctrl . ldctl_iscritical ) ;
}
}
lcpr_error_out :
2011-05-20 01:41:21 +08:00
if ( ber ! = NULL ) {
2010-06-16 03:47:28 +08:00
ber_free ( ber , 1 ) ;
}
return ;
}
/* }}} */
2011-07-15 02:49:12 +08:00
/* {{{ proto bool ldap_control_paged_result_response(resource link, resource result [, string &cookie [, int &estimated]])
2010-06-16 03:47:28 +08:00
Extract paged results control response */
2015-01-03 17:22:58 +08:00
PHP_FUNCTION ( ldap_control_paged_result_response )
2010-06-16 03:47:28 +08:00
{
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 ( ) ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rr|z/z/ " , & link , & result , & cookie , & estimated ) ! = SUCCESS ) {
2010-06-16 03:47:28 +08:00
return ;
}
2015-02-02 15:05:20 +08:00
if ( ( ld = ( ldap_linkdata * ) zend_fetch_resource ( Z_RES_P ( link ) , " ldap link " , le_link ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( ldap_result = ( LDAPMessage * ) zend_fetch_resource ( Z_RES_P ( result ) , " ldap result " , le_result ) ) = = NULL ) {
RETURN_FALSE ;
}
2010-06-16 03:47:28 +08:00
rc = ldap_parse_result ( ld - > link ,
ldap_result ,
& lerrcode ,
NULL , /* matcheddn */
NULL , /* errmsg */
NULL , /* referrals */
& lserverctrls ,
0 ) ;
if ( rc ! = LDAP_SUCCESS ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to parse result: %s (%d) " , ldap_err2string ( rc ) , rc ) ;
2010-06-16 03:47:28 +08:00
RETURN_FALSE ;
}
if ( lerrcode ! = LDAP_SUCCESS ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Result is: %s (%d) " , ldap_err2string ( lerrcode ) , lerrcode ) ;
2010-06-16 03:47:28 +08:00
RETURN_FALSE ;
}
if ( lserverctrls = = NULL ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " No server controls in result " ) ;
2010-06-16 03:47:28 +08:00
RETURN_FALSE ;
}
2015-06-23 21:50:14 +08:00
lctrl = ldap_control_find ( LDAP_CONTROL_PAGEDRESULTS , lserverctrls , NULL ) ;
2010-06-16 03:47:28 +08:00
if ( lctrl = = NULL ) {
ldap_controls_free ( lserverctrls ) ;
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " No paged results control response in result " ) ;
2010-06-16 03:47:28 +08:00
RETURN_FALSE ;
}
ber = ber_init ( & lctrl - > ldctl_value ) ;
if ( ber = = NULL ) {
ldap_controls_free ( lserverctrls ) ;
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to alloc BER decoding resources for paged results control response " ) ;
2010-06-16 03:47:28 +08:00
RETURN_FALSE ;
}
tag = ber_scanf ( ber , " {io} " , & lestimated , & lcookie ) ;
( void ) ber_free ( ber , 1 ) ;
if ( tag = = LBER_ERROR ) {
ldap_controls_free ( lserverctrls ) ;
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to decode paged results control response " ) ;
2010-06-16 03:47:28 +08:00
RETURN_FALSE ;
}
if ( lestimated < 0 ) {
ldap_controls_free ( lserverctrls ) ;
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Invalid paged results control response value " ) ;
2010-06-16 03:47:28 +08:00
RETURN_FALSE ;
}
ldap_controls_free ( lserverctrls ) ;
if ( myargcount = = 4 ) {
zval_dtor ( estimated ) ;
2014-08-26 01:24:55 +08:00
ZVAL_LONG ( estimated , lestimated ) ;
2010-06-16 03:47:28 +08:00
}
2011-05-20 01:41:21 +08:00
2014-05-20 11:26:26 +08:00
zval_ptr_dtor ( cookie ) ;
2010-06-16 03:47:28 +08:00
if ( lcookie . bv_len = = 0 ) {
ZVAL_EMPTY_STRING ( cookie ) ;
} else {
2014-05-20 11:26:26 +08:00
ZVAL_STRINGL ( cookie , lcookie . bv_val , lcookie . bv_len ) ;
2010-06-16 03:47:28 +08:00
}
ldap_memfree ( lcookie . bv_val ) ;
RETURN_TRUE ;
}
/* }}} */
# endif
2008-06-29 22:29:09 +08:00
/* {{{ arginfo */
ZEND_BEGIN_ARG_INFO_EX ( arginfo_ldap_connect , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , hostname )
ZEND_ARG_INFO ( 0 , port )
2009-04-22 02:08:34 +08:00
# ifdef HAVE_ORALDAP
ZEND_ARG_INFO ( 0 , wallet )
ZEND_ARG_INFO ( 0 , wallet_passwd )
ZEND_ARG_INFO ( 0 , authmode )
# endif
2008-06-29 22:29:09 +08:00
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 ( )
2014-01-23 01:54:11 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_ldap_modify_batch , 0 , 0 , 3 )
ZEND_ARG_INFO ( 0 , link_identifier )
ZEND_ARG_INFO ( 0 , dn )
ZEND_ARG_ARRAY_INFO ( 0 , modifications_info , 0 )
ZEND_END_ARG_INFO ( )
2008-06-29 22:29:09 +08:00
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 ( )
2010-06-16 03:47:28 +08:00
# ifdef LDAP_CONTROL_PAGEDRESULTS
2011-05-20 01:41:21 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_ldap_control_paged_result , 0 , 0 , 2 )
2010-06-16 03:47:28 +08:00
ZEND_ARG_INFO ( 0 , link )
ZEND_ARG_INFO ( 0 , pagesize )
ZEND_ARG_INFO ( 0 , iscritical )
ZEND_ARG_INFO ( 0 , cookie )
ZEND_END_ARG_INFO ( ) ;
2011-05-20 01:41:21 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_ldap_control_paged_result_response , 0 , 0 , 2 )
2010-06-16 03:47:28 +08:00
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
2013-10-05 06:50:16 +08:00
# if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP
2008-06-29 22:29:09 +08:00
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 )
2008-07-16 21:41:35 +08:00
ZEND_ARG_INFO ( 0 , newval )
2008-06-29 22:29:09 +08:00
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
2015-08-18 22:52:44 +08:00
# if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
2008-06-29 22:29:09 +08:00
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
2013-09-17 23:34:30 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_ldap_escape , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , value )
ZEND_ARG_INFO ( 0 , ignore )
ZEND_ARG_INFO ( 0 , flags )
ZEND_END_ARG_INFO ( )
2008-06-29 22:29:09 +08:00
# 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
/* }}} */
2015-01-03 17:22:58 +08:00
2008-04-16 22:21:04 +08:00
/*
2015-01-03 17:22:58 +08:00
This is just a small subset of the functionality provided by the LDAP library . All the
2008-04-16 22:21:04 +08:00
operations are synchronous . Referrals are not handled automatically .
*/
/* {{{ ldap_functions[]
*/
const zend_function_entry ldap_functions [ ] = {
2008-06-29 22:29:09 +08:00
PHP_FE ( ldap_connect , arginfo_ldap_connect )
PHP_FALIAS ( ldap_close , ldap_unbind , arginfo_ldap_resource )
PHP_FE ( ldap_bind , arginfo_ldap_bind )
2008-04-16 22:21:04 +08:00
# ifdef HAVE_LDAP_SASL
2008-06-29 22:29:09 +08:00
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 )
2014-01-23 01:54:11 +08:00
PHP_FE ( ldap_modify_batch , arginfo_ldap_modify_batch )
2008-06-29 22:29:09 +08:00
PHP_FALIAS ( ldap_modify , ldap_mod_replace , arginfo_ldap_modify )
2008-04-16 22:21:04 +08:00
/* additional functions for attribute based modifications, Gerrit Thomson */
2008-06-29 22:29:09 +08:00
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 )
2008-04-16 22:21:04 +08:00
/* end gjt mod */
2008-06-29 22:29:09 +08:00
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 )
2015-06-29 20:31:20 +08:00
PHP_DEP_FE ( ldap_sort , arginfo_ldap_sort )
2008-04-16 22:21:04 +08:00
2013-10-05 06:50:16 +08:00
# if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP
2008-06-29 22:29:09 +08:00
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 )
2008-04-16 22:21:04 +08:00
# ifdef HAVE_LDAP_PARSE_REFERENCE
2008-06-29 22:29:09 +08:00
PHP_FE ( ldap_parse_reference , arginfo_ldap_parse_reference )
2008-04-16 22:21:04 +08:00
# endif
# ifdef HAVE_LDAP_PARSE_RESULT
2008-06-29 22:29:09 +08:00
PHP_FE ( ldap_parse_result , arginfo_ldap_parse_result )
2008-04-16 22:21:04 +08:00
# endif
# ifdef HAVE_LDAP_START_TLS_S
2008-06-29 22:29:09 +08:00
PHP_FE ( ldap_start_tls , arginfo_ldap_resource )
2008-04-16 22:21:04 +08:00
# endif
# endif
2015-08-18 22:52:44 +08:00
# if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
2008-06-29 22:29:09 +08:00
PHP_FE ( ldap_set_rebind_proc , arginfo_ldap_set_rebind_proc )
2008-04-16 22:21:04 +08:00
# endif
2013-09-17 23:34:30 +08:00
PHP_FE ( ldap_escape , arginfo_ldap_escape )
2008-04-16 22:21:04 +08:00
# ifdef STR_TRANSLATION
2008-06-29 22:29:09 +08:00
PHP_FE ( ldap_t61_to_8859 , arginfo_ldap_t61_to_8859 )
PHP_FE ( ldap_8859_to_t61 , arginfo_ldap_8859_to_t61 )
2008-04-16 22:21:04 +08:00
# endif
2010-06-16 03:47:28 +08:00
# ifdef LDAP_CONTROL_PAGEDRESULTS
2011-05-20 01:41:21 +08:00
PHP_FE ( ldap_control_paged_result , arginfo_ldap_control_paged_result )
PHP_FE ( ldap_control_paged_result_response , arginfo_ldap_control_paged_result_response )
2010-06-16 03:47:28 +08:00
# endif
2011-07-25 19:35:02 +08:00
PHP_FE_END
2008-04-16 22:21:04 +08:00
} ;
/* }}} */
zend_module_entry ldap_module_entry = { /* {{{ */
STANDARD_MODULE_HEADER ,
2015-01-03 17:22:58 +08:00
" ldap " ,
ldap_functions ,
PHP_MINIT ( ldap ) ,
PHP_MSHUTDOWN ( ldap ) ,
NULL ,
2008-04-16 22:21:04 +08:00
NULL ,
2015-01-03 17:22:58 +08:00
PHP_MINFO ( ldap ) ,
2015-03-24 03:33:54 +08:00
PHP_LDAP_VERSION ,
2008-04-16 22:21:04 +08:00
PHP_MODULE_GLOBALS ( ldap ) ,
PHP_GINIT ( ldap ) ,
NULL ,
NULL ,
STANDARD_MODULE_PROPERTIES_EX
} ;
/* }}} */
2001-06-05 21:12:10 +08:00
/*
* Local variables :
* tab - width : 4
* c - basic - offset : 4
* End :
2001-09-09 21:29:31 +08:00
* vim600 : sw = 4 ts = 4 fdm = marker
* vim < 600 : sw = 4 ts = 4
2001-06-05 21:12:10 +08:00
*/