]> granicus.if.org Git - php/commitdiff
Added ldap_exop_refresh helper for EXOP REFRESH operation on dds overlay
authorCôme Chilliet <mcmic@php.net>
Thu, 20 Jul 2017 14:14:47 +0000 (16:14 +0200)
committerCôme Chilliet <mcmic@php.net>
Thu, 20 Jul 2017 14:16:59 +0000 (16:16 +0200)
ldap_exop_refresh(resource link, string dn, int ttl)
Returns FALSE on failure, newttl on success

NEWS
ext/ldap/config.m4
ext/ldap/config.w32
ext/ldap/ldap.c
ext/ldap/tests/ldap_exop_refresh.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 06ebc476d78191dbd0ad418b4f38fcfbc0063f65..fd284f3317ba9f5beaa9983a5e428bc04a03651d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,9 @@ PHP                                                                        NEWS
   . Fixed bug #74941 (session fails to start after having headers sent). 
     (morozov)
 
+- LDAP:
+  . Added ldap_exop_refresh helper for EXOP REFRESH operation with dds overlay
+
 - ODBC:
   . Removed support for Birdstep. (Kalle)
 
index 7ea238f5a59eba073d21d6eec7c5f4c06dd88713..f77ff5a4c55a6eec7a043050fae96c95d0bba19c 100644 (file)
@@ -204,7 +204,7 @@ if test "$PHP_LDAP" != "no"; then
 
   dnl Solaris 2.8 claims to be 2004 API, but doesn't have
   dnl ldap_parse_reference() nor ldap_start_tls_s()
-  AC_CHECK_FUNCS([ldap_parse_result ldap_parse_reference ldap_start_tls_s ldap_control_find ldap_parse_extended_result ldap_extended_operation ldap_extended_operation_s ldap_passwd_s ldap_whoami_s])
+  AC_CHECK_FUNCS([ldap_parse_result ldap_parse_reference ldap_start_tls_s ldap_control_find ldap_parse_extended_result ldap_extended_operation ldap_extended_operation_s ldap_passwd_s ldap_whoami_s ldap_refresh_s])
 
   dnl
   dnl SASL check
index 7713bdc42bbc9b2939826d6864614537a59e84e7..626375502ea90968c8765666929e6f66787a9e4c 100644 (file)
@@ -25,6 +25,7 @@ if (PHP_LDAP != "no") {
                AC_DEFINE('HAVE_LDAP_EXTENDED_OPERATION_S', 1);
                AC_DEFINE('HAVE_LDAP_PASSWD_S', 1);
                AC_DEFINE('HAVE_LDAP_WHOAMI_S', 1);
+               AC_DEFINE('HAVE_LDAP_REFRESH_S', 1);
                AC_DEFINE('HAVE_LDAP_EXTENDED_OPERATION', 1);
 
        } else {
index a710025af09b24c9d06c4e7addbb401c23779f60..3232414de78f8d91bbbf02075a909e404cd9b3dc 100644 (file)
@@ -3513,7 +3513,44 @@ PHP_FUNCTION(ldap_exop_whoami)
 }
 /* }}} */
 #endif
+
+#ifdef HAVE_LDAP_REFRESH_S
+/* {{{ proto bool|int ldap_exop_refresh(resource link , string dn , int ttl)
+   DDS refresh extended operation */
+PHP_FUNCTION(ldap_exop_refresh)
+{
+       zval *link, *dn, *ttl;
+       struct berval ldn;
+       ber_int_t lttl;
+       ber_int_t newttl;
+       ldap_linkdata *ld;
+       int rc;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "rzz", &link, &dn, &ttl) != SUCCESS) {
+               WRONG_PARAM_COUNT;
+       }
+
+       if ((ld = (ldap_linkdata *)zend_fetch_resource(Z_RES_P(link), "ldap link", le_link)) == NULL) {
+               RETURN_FALSE;
+       }
+
+       convert_to_string_ex(dn);
+       ldn.bv_val = Z_STRVAL_P(dn);
+       ldn.bv_len = Z_STRLEN_P(dn);
+
+       convert_to_long_ex(ttl);
+       lttl = (ber_int_t)Z_LVAL_P(ttl);
+
+       rc = ldap_refresh_s(ld->link, &ldn, lttl, &newttl, NULL, NULL);
+       if (rc != LDAP_SUCCESS ) {
+               php_error_docref(NULL, E_WARNING, "Refresh extended operation failed: %s (%d)", ldap_err2string(rc), rc);
+               RETURN_FALSE;
+       }
+
+       RETURN_LONG(newttl);
+}
 /* }}} */
+#endif
 
 /* }}} */
 
@@ -3818,6 +3855,14 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_exop_whoami, 0, 0, 1)
 ZEND_END_ARG_INFO()
 #endif
 
+#ifdef HAVE_LDAP_REFRESH_S
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_exop_refresh, 0, 0, 3)
+       ZEND_ARG_INFO(0, link)
+       ZEND_ARG_INFO(0, dn)
+       ZEND_ARG_INFO(0, ttl)
+ZEND_END_ARG_INFO()
+#endif
+
 #ifdef HAVE_LDAP_PARSE_EXTENDED_RESULT
 ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_parse_exop, 0, 0, 4)
        ZEND_ARG_INFO(0, link)
@@ -3899,6 +3944,9 @@ const zend_function_entry ldap_functions[] = {
 #ifdef HAVE_LDAP_WHOAMI_S
        PHP_FE(ldap_exop_whoami,                                                        arginfo_ldap_exop_whoami)
 #endif
+#ifdef HAVE_LDAP_REFRESH_S
+       PHP_FE(ldap_exop_refresh,                                                       arginfo_ldap_exop_refresh)
+#endif
 #ifdef HAVE_LDAP_PARSE_EXTENDED_RESULT
        PHP_FE(ldap_parse_exop,                                                         arginfo_ldap_parse_exop)
 #endif
diff --git a/ext/ldap/tests/ldap_exop_refresh.phpt b/ext/ldap/tests/ldap_exop_refresh.phpt
new file mode 100644 (file)
index 0000000..170f013
--- /dev/null
@@ -0,0 +1,43 @@
+--TEST--
+ldap_exop_refresh() - Test LDAP refresh extended operation
+--CREDITS--
+Emmanuel Dreyfus <manu@netbsd.org>
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+<?php
+       $link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+       $r = ldap_read($link, '', 'objectClass=*', array('dynamicsubtrees')),
+       $info = ldap_get_entries($link, $r)[0];
+       if (!isset($info['dynamicsubtrees'])) {
+               die("Overlay DDS not available");
+       }
+?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+insert_dummy_data($link, $base);
+ldap_add($link, "cn=tmp,$base", array(
+       "objectclass" => array("person", "dynamicObject"),
+       "cn" => "tmp",
+       "sn" => "tmp"
+));
+var_dump(
+       ldap_exop_refresh($link, "cn=tmp,$base", 1234)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+ldap_delete($link, "cn=tmp,$base");
+remove_dummy_data($link, $base);
+?>
+--EXPECTF--
+int(1234)
+===DONE===