Skip to content

Commit 3a09c12

Browse files
author
Côme Chilliet
committed
Added support for controls to ldap_get_option
1 parent 6164ec9 commit 3a09c12

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

ext/ldap/ldap.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2129,6 +2129,8 @@ PHP_FUNCTION(ldap_sort)
21292129
PHP_FUNCTION(ldap_get_option)
21302130
{
21312131
zval *link, *retval;
2132+
zval tmp1;
2133+
int num_entries;
21322134
ldap_linkdata *ld;
21332135
zend_long option;
21342136

@@ -2273,9 +2275,37 @@ PHP_FUNCTION(ldap_get_option)
22732275
ZVAL_STRING(retval, val);
22742276
ldap_memfree(val);
22752277
} break;
2276-
/* options not implemented
22772278
case LDAP_OPT_SERVER_CONTROLS:
22782279
case LDAP_OPT_CLIENT_CONTROLS:
2280+
{
2281+
LDAPControl **ctrls = NULL, **ctrlp;
2282+
2283+
if (ldap_get_option(ld->link, option, &ctrls) || ctrls == NULL) {
2284+
if (ctrls) {
2285+
ldap_memfree(ctrls);
2286+
}
2287+
RETURN_FALSE;
2288+
}
2289+
2290+
zval_ptr_dtor(retval);
2291+
array_init(retval);
2292+
num_entries = 0;
2293+
ctrlp = ctrls;
2294+
while (*ctrlp != NULL)
2295+
{
2296+
array_init(&tmp1);
2297+
add_assoc_string(&tmp1, "oid", (*ctrlp)->ldctl_oid);
2298+
add_assoc_bool(&tmp1, "iscritical", ((*ctrlp)->ldctl_iscritical != 0));
2299+
if ((*ctrlp)->ldctl_value.bv_len) {
2300+
add_assoc_stringl(&tmp1, "value", (*ctrlp)->ldctl_value.bv_val, (*ctrlp)->ldctl_value.bv_len);
2301+
}
2302+
zend_hash_index_update(Z_ARRVAL_P(retval), num_entries, &tmp1);
2303+
num_entries++;
2304+
ctrlp++;
2305+
}
2306+
ldap_controls_free(ctrls);
2307+
} break;
2308+
/* options not implemented
22792309
case LDAP_OPT_API_INFO:
22802310
case LDAP_OPT_API_FEATURE_INFO:
22812311
*/

0 commit comments

Comments
 (0)