public function exists($dn)
{
if ($dn instanceof Horde_Ldap_Entry) {
$dn = $dn->dn();
}
if (!is_string($dn)) {
throw new Horde_Ldap_Exception('Parameter $dn is not a string nor an entry object!');
}
/* Make dn relative to parent. */
$options = array('casefold' => 'none');
$base = Horde_Ldap_Util::explodeDN($dn, $options);
$entry_rdn = '(&(' . Horde_Ldap_Util::canonicalDN(array_shift($base), array_merge($options, array('separator' => ')('))) . '))';
$base = Horde_Ldap_Util::canonicalDN($base, $options);
$result = @ldap_list($this->_link, $base, $entry_rdn, array('dn'), 1, 1);
if ($result && @ldap_count_entries($this->_link, $result)) {
return true;
}
if ($this->errorName(@ldap_errno($this->_link)) == 'LDAP_NO_SUCH_OBJECT') {
return false;
}
if (@ldap_errno($this->_link)) {
throw new Horde_Ldap_Exception(@ldap_error($this->_link), @ldap_errno($this->_link));
}
return false;
}