function ldap_baddn in Lightweight Directory Access Protocol (LDAP) 8.2
Same name and namespace in other branches
- 7.2 ldap_servers/ldap_servers.functions.inc \ldap_baddn()
- 7 ldap_servers/ldap_servers.functions.inc \ldap_baddn()
this attempts to find bad dns, but should only be used as warningswe as the ldap spec allows for any old character to be escaped and ldap implementations may not follow the spec.
http://www.ietf.org/rfc/rfc2253.txt
File
- ldap_servers/
ldap_servers.functions.inc, line 59 - collection of functions that don't belong in server object
Code
function ldap_baddn($dn, $dn_name) {
$result = array();
$valid_attr_name = '[_a-zA-Z\\d\\s]';
$valid_attr_values = '[_\\-a-zA-Z\\d\\s]';
$regex = '/^(' . $valid_attr_name . '*\\=' . $valid_attr_values . '*[,]{1})*(' . $valid_attr_name . '*\\=' . $valid_attr_values . '*){1}$/';
$match = preg_match($regex, $dn) ? TRUE : FALSE;
$result['boolean'] = $match;
if (!$match) {
$tokens = array(
'%dn' => htmlspecialchars($dn),
'%dn_name' => $dn_name,
);
$result['text'] = t('Possible invalid format for:', $tokens) . '<em>' . $tokens['%dn'] . '</em>.<br/> ' . t('The format may be correct for your ldap, but please double check.', $tokens);
}
return $result;
}