diff --git a/nur_src/ldap/LdapException.php b/nur_src/ldap/LdapException.php index d8c7800..3f67220 100644 --- a/nur_src/ldap/LdapException.php +++ b/nur_src/ldap/LdapException.php @@ -5,10 +5,12 @@ use nur\b\UserException; class LdapException extends UserException { /** @param $r ?resource */ - static function check(string $message, $r, $value) { + static function check(string $message, $r, $value, ?int $allow_errno=null) { if ($value !== false) return $value; if ($r !== null) { - throw new self($message, ldap_errno($r), null, ldap_error($r)); + $errno = ldap_errno($r); + if ($allow_errno !== null && $errno === $allow_errno) return $value; + throw new self($message, $errno, null, ldap_error($r)); } else { throw new self($message); } diff --git a/nur_src/ldap/LdapSearch.php b/nur_src/ldap/LdapSearch.php index 33d8805..956ed10 100644 --- a/nur_src/ldap/LdapSearch.php +++ b/nur_src/ldap/LdapSearch.php @@ -157,17 +157,16 @@ class LdapSearch extends Parametrable implements IteratorAggregate { elseif ($scope == self::SCOPE_BASE) $rr = @ldap_read(...$args); else throw ValueException::invalid_value($scope, "scope"); - // pas trouvé - if ($rr === false && ldap_errno($conn) == 32) return; - $rr = LdapException::check("search", $conn, $rr); + $rr = LdapException::check("search", $conn, $rr, 32); + if ($rr === false) return; // pas trouvé try { - $er = LdapException::check("first_entry", $conn, ldap_first_entry($conn, $rr)); + $er = LdapException::check("first_entry", $conn, ldap_first_entry($conn, $rr), 32); while ($er !== false) { $dn = ldap_get_dn($conn, $er); $entry = ldap_get_attributes($conn, $er); yield $dn => $entry; - $er = LdapException::check("next_entry", $conn, ldap_next_entry($conn, $er)); + $er = LdapException::check("next_entry", $conn, ldap_next_entry($conn, $er), 32); } } catch (StopException $e) { } finally {