function ldap_pear_escape_filter_value in Lightweight Directory Access Protocol (LDAP) 7.2
Same name and namespace in other branches
- 8.2 ldap_servers/ldap_servers.functions.inc \ldap_pear_escape_filter_value()
- 7 ldap_servers/ldap_servers.functions.inc \ldap_pear_escape_filter_value()
From pear net_ldap2-2.0.11.
Escapes the given VALUES according to RFC 2254 so that they can be safely used in LDAP filters.
Any control characters with an ACII code < 32 as well as the characters with special meaning in LDAP filters "*", "(", ")", and "\" (the backslash) are converted into the representation of a backslash followed by two hex digits representing the hexadecimal value of the character.
@static
Parameters
array $values: Array of values to escape.
Return value
array Array $values, but escaped
5 calls to ldap_pear_escape_filter_value()
- LdapServer::groupMembershipsFromEntryRecursive in ldap_servers/
LdapServer.class.php - Recurse through all groups, adding parent groups to $all_group_dns array.
- LdapServer::groupMembersResursive in ldap_servers/
LdapServer.class.php - NOT IMPLEMENTED recurse through all child groups and add members.
- LdapServer::groupUserMembershipsFromEntry in ldap_servers/
LdapServer.class.php - Get list of all groups that a user is a member of by querying groups.
- LdapServer::groupUserMembershipsFromUserAttr in ldap_servers/
LdapServer.class.php - Get list of all groups that a user is a member of by using memberOf attribute first, then if nesting is true, using group entries to find parent groups.
- ldap_server_massage_text in ldap_servers/
ldap_servers.functions.inc - Function to massage (change case, escape, unescape) ldap attribute names and values. The primary purpose of this is to articulate and ensure consistency across ldap modules.
File
- ldap_servers/
ldap_servers.functions.inc, line 251 - Collection of functions that don't belong in server object.
Code
function ldap_pear_escape_filter_value($values = []) {
// Parameter validation.
$is_scalar = is_scalar($values);
if ($is_scalar) {
$values = [
$values,
];
}
if ($values === NULL) {
return NULL;
}
foreach ($values as $key => $val) {
// Escaping of filter meta characters.
$val = str_replace('\\', '\\5c', $val);
$val = str_replace('*', '\\2a', $val);
$val = str_replace('(', '\\28', $val);
$val = str_replace(')', '\\29', $val);
// ASCII < 32 escaping.
$val = ldap_pear_asc2hex32($val);
if (NULL === $val) {
$val = '\\0';
}
// apply escaped "null" if string is empty
$values[$key] = $val;
}
return $is_scalar ? $values[0] : $values;
}