Skip to content

Commit 915abeb

Browse files
ptomulikCôme Chilliet
authored and
Côme Chilliet
committed
Add ldap_count_references()
Closes phpGH-5784
1 parent 3190282 commit 915abeb

File tree

5 files changed

+84
-1
lines changed

5 files changed

+84
-1
lines changed

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,10 @@ PHP 8.0 UPGRADE NOTES
711711
. Added get_resource_id($resource) function, which returns the same value as
712712
(int) $resource. It provides the same functionality under a clearer API.
713713

714+
- LDAP:
715+
. Added ldap_count_references(), which returns the number of reference
716+
messages in a search result.
717+
714718
- OpenSSL:
715719
. Added openssl_cms_encrypt() encrypts the message in the file with the
716720
certificates and outputs the result to the supplied file.

ext/ldap/ldap.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3464,6 +3464,30 @@ PHP_FUNCTION(ldap_parse_exop)
34643464
#endif
34653465
/* }}} */
34663466

3467+
/* {{{ proto int ldap_count_references(resource link, resource result)
3468+
Count the number of references in a search result */
3469+
PHP_FUNCTION(ldap_count_references)
3470+
{
3471+
zval *link, *result;
3472+
ldap_linkdata *ld;
3473+
LDAPMessage *ldap_result;
3474+
3475+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rr", &link, &result) != SUCCESS) {
3476+
RETURN_THROWS();
3477+
}
3478+
3479+
if ((ld = (ldap_linkdata *)zend_fetch_resource(Z_RES_P(link), "ldap link", le_link)) == NULL) {
3480+
RETURN_THROWS();
3481+
}
3482+
3483+
if ((ldap_result = (LDAPMessage *)zend_fetch_resource(Z_RES_P(result), "ldap result", le_result)) == NULL) {
3484+
RETURN_THROWS();
3485+
}
3486+
3487+
RETURN_LONG(ldap_count_references(ld->link, ldap_result));
3488+
}
3489+
/* }}} */
3490+
34673491
/* {{{ proto resource ldap_first_reference(resource link, resource result)
34683492
Return first reference */
34693493
PHP_FUNCTION(ldap_first_reference)

ext/ldap/ldap.stub.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ function ldap_get_option($link_identifier, int $option, &$retval = null): bool {
226226
/** @param resource|null $link_identifier */
227227
function ldap_set_option($link_identifier, int $option, $newval): bool {}
228228

229+
/**
230+
* @param resource $link_identifier
231+
* @param resource $result_identifier
232+
*/
233+
function ldap_count_references($link_identifier, $result_identifier): int {}
234+
229235
/**
230236
* @param resource $link
231237
* @param resource $result

ext/ldap/ldap_arginfo.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: c9ce0e98ab386130b6332ae017808bec67b1cd07 */
2+
* Stub hash: 63d7fc9e11bd2821a77f6ee709ceaf1fdcbf190e */
33

44
#if defined(HAVE_ORALDAP)
55
ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_connect, 0, 0, 0)
@@ -243,6 +243,13 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ldap_set_option, 0, 3, _IS_BOOL,
243243
ZEND_END_ARG_INFO()
244244
#endif
245245

246+
#if (LDAP_API_VERSION > 2000) || defined(HAVE_ORALDAP)
247+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ldap_count_references, 0, 2, IS_LONG, 0)
248+
ZEND_ARG_INFO(0, link_identifier)
249+
ZEND_ARG_INFO(0, result_identifier)
250+
ZEND_END_ARG_INFO()
251+
#endif
252+
246253
#if (LDAP_API_VERSION > 2000) || defined(HAVE_ORALDAP)
247254
ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_first_reference, 0, 0, 2)
248255
ZEND_ARG_INFO(0, link)
@@ -412,6 +419,9 @@ ZEND_FUNCTION(ldap_get_option);
412419
ZEND_FUNCTION(ldap_set_option);
413420
#endif
414421
#if (LDAP_API_VERSION > 2000) || defined(HAVE_ORALDAP)
422+
ZEND_FUNCTION(ldap_count_references);
423+
#endif
424+
#if (LDAP_API_VERSION > 2000) || defined(HAVE_ORALDAP)
415425
ZEND_FUNCTION(ldap_first_reference);
416426
#endif
417427
#if (LDAP_API_VERSION > 2000) || defined(HAVE_ORALDAP)
@@ -517,6 +527,9 @@ static const zend_function_entry ext_functions[] = {
517527
#if (LDAP_API_VERSION > 2000) || defined(HAVE_ORALDAP)
518528
ZEND_FE(ldap_set_option, arginfo_ldap_set_option)
519529
#endif
530+
#if (LDAP_API_VERSION > 2000) || defined(HAVE_ORALDAP)
531+
ZEND_FE(ldap_count_references, arginfo_ldap_count_references)
532+
#endif
520533
#if (LDAP_API_VERSION > 2000) || defined(HAVE_ORALDAP)
521534
ZEND_FE(ldap_first_reference, arginfo_ldap_first_reference)
522535
#endif
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
ldap_count_references() - Basic ldap_count_references test
3+
--SKIPIF--
4+
<?php require_once('skipif.inc'); ?>
5+
<?php require_once('skipifbindfailure.inc'); ?>
6+
--FILE--
7+
<?php
8+
require "connect.inc";
9+
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
10+
insert_dummy_data($link, $base);
11+
ldap_add($link, "cn=userref,$base", array(
12+
"objectClass" => array("extensibleObject", "referral"),
13+
"cn" => "userref",
14+
"ref" => "cn=userA,$base",
15+
));
16+
ldap_add($link, "cn=userref2,$base", array(
17+
"objectClass" => array("extensibleObject", "referral"),
18+
"cn" => "userref2",
19+
"ref" => "cn=userB,$base",
20+
));
21+
ldap_set_option($link, LDAP_OPT_DEREF, LDAP_DEREF_NEVER);
22+
$result = ldap_search($link, "$base", "(cn=*)");
23+
var_dump(ldap_count_references($link, $result));
24+
?>
25+
--CLEAN--
26+
<?php
27+
include "connect.inc";
28+
29+
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
30+
// Referral can only be removed with Manage DSA IT Control
31+
ldap_delete($link, "cn=userref,$base", [['oid' => LDAP_CONTROL_MANAGEDSAIT, 'iscritical' => TRUE]]);
32+
ldap_delete($link, "cn=userref2,$base", [['oid' => LDAP_CONTROL_MANAGEDSAIT, 'iscritical' => TRUE]]);
33+
remove_dummy_data($link, $base);
34+
?>
35+
--EXPECTF--
36+
int(2)

0 commit comments

Comments
 (0)