You are here

function ldap_baddn in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_servers/ldap_servers.functions.inc \ldap_baddn()
  2. 7 ldap_servers/ldap_servers.functions.inc \ldap_baddn()

This attempts to find bad dns, but should only be used as warnings 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 80
Collection of functions that don't belong in server object.

Code

function ldap_baddn($dn, $dn_name) {
  $result = [];
  $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 = [
      '%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;
}