Skip to content

Commit 495837b

Browse files
committed
ext/ldap: Add API parsing zval to LDAP value
1 parent 9709887 commit 495837b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

ext/ldap/ldap.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,26 @@ static void ldap_result_entry_free_obj(zend_object *obj)
234234
} \
235235
}
236236

237+
/* An LDAP value must be a string, however it defines a format for integer and
238+
* booleans, thus we parse zvals to the corresponding string if possible
239+
* See RFC 4517: https://datatracker.ietf.org/doc/html/rfc4517 */
240+
static zend_string* php_ldap_try_get_ldap_value_from_zval(zval *zv) {
241+
switch (Z_TYPE_P(zv)) {
242+
case IS_STRING:
243+
case IS_LONG:
244+
/* Object might be stringable */
245+
case IS_OBJECT:
246+
return zval_try_get_string(zv);
247+
case IS_TRUE:
248+
return ZSTR_INIT_LITERAL("TRUE", false);
249+
case IS_FALSE:
250+
return ZSTR_INIT_LITERAL("FALSE", false);
251+
default:
252+
zend_type_error("LDAP value must be of type string|int|bool, %s given", zend_zval_value_name(zv));
253+
return NULL;
254+
}
255+
}
256+
237257
/* {{{ Parse controls from and to arrays */
238258
static void _php_ldap_control_to_array(LDAP *ld, LDAPControl* ctrl, zval* array, int request)
239259
{

0 commit comments

Comments
 (0)