diff --git a/include/class_ldap.inc b/include/class_ldap.inc index a86fe3825da80229aaadc289b5800e5f2aed83f9..09ba93cb2bbba16b364c97b281583220e6b10387 100755 --- a/include/class_ldap.inc +++ b/include/class_ldap.inc @@ -430,6 +430,9 @@ class LDAP */ function cat ($srp, $dn, $attrs = ["*"], $filter = "(objectclass=*)") { + // Set the default error hanlder of PHP allowins @ suppression of PHP Warnings in case of DN not found. (ldap_read). + restore_error_handler(); + if ($this->hascon) { if ($this->reconnect) { $this->connect(); @@ -449,6 +452,7 @@ class LDAP } } + /*! * \brief Search object from a filter * @@ -463,8 +467,15 @@ class LDAP $this->connect(); } $res = @ldap_read($this->cid, $dn, $filter, ["objectClass"]); - logging::debug(DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $this->error, 'object_match_filter(dn="'.$dn.'",filter="'.$filter.'")'); - return @ldap_count_entries($this->cid, $res); + // Method ldap_read can return array of ldap\result (multiple ldap instances) or FALSE. We escape both. + // This is cleary a quick fix for php8.2 adaptation ... + if (is_bool($res) || is_array($res)) { + logging::debug(DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $this->error, 'object_match_filter(dn="'.$dn.'",filter="'.$filter.'")'); + return FALSE; + } else { + logging::debug(DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $this->error, 'object_match_filter(dn="'.$dn.'",filter="'.$filter.'")'); + return @ldap_count_entries($this->cid, $res); + } } else { $this->error = "Could not connect to LDAP server"; logging::debug(DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $this->error, 'object_match_filter(dn="'.$dn.'",filter="'.$filter.'")'); @@ -597,6 +608,12 @@ class LDAP { if ($this->hascon) { if ($this->hasres[$srp]) { + // Method ldap_read can return array of ldap\result (multiple ldap instances) or FALSE. We escape both. + // This is cleary a quick fix for php8.2 adaptation ... + if (is_bool($this->hasres[$srp]) || is_array($this->hasres[$srp])) { + logging::debug(DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $this->error, 'count()'); + return FALSE; + } $rv = @ldap_count_entries($this->cid, $this->sr[$srp]); $this->error = @ldap_error($this->cid); logging::debug(DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $this->error, 'count()');