diff --git a/LibreNMS/Authentication/ActiveDirectoryCommon.php b/LibreNMS/Authentication/ActiveDirectoryCommon.php index 47d2925259..2fd436d48b 100644 --- a/LibreNMS/Authentication/ActiveDirectoryCommon.php +++ b/LibreNMS/Authentication/ActiveDirectoryCommon.php @@ -196,7 +196,7 @@ trait ActiveDirectoryCommon ]; } - public function getUser($user_id) + public function getUser($user_id): array { $connection = $this->getConnection(); $domain_sid = $this->getDomainSid(); @@ -204,16 +204,19 @@ trait ActiveDirectoryCommon $search_filter = "(&(objectcategory=person)(objectclass=user)(objectsid=$domain_sid-$user_id))"; $attributes = ['samaccountname', 'displayname', 'objectsid', 'mail']; $search = ldap_search($connection, Config::get('auth_ad_base_dn'), $search_filter, $attributes); - $entry = ldap_get_entries($connection, $search); - if (isset($entry[0]['samaccountname'][0])) { - return $this->userFromAd($entry[0]); + if ($search !== false) { + $entry = ldap_get_entries($connection, $search); + + if (isset($entry[0]['samaccountname'][0])) { + return $this->userFromAd($entry[0]); + } } return []; } - protected function getDomainSid() + protected function getDomainSid(): string { $connection = $this->getConnection(); @@ -226,6 +229,13 @@ trait ActiveDirectoryCommon '(objectClass=*)', ['objectsid'] ); + + if ($search === false) { + \Log::debug('AD Auth: Could not determine domain SID'); + + return ''; + } + $entry = ldap_get_entries($connection, $search); return substr($this->sidFromLdap($entry[0]['objectsid'][0]), 0, 41); diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index cb04009028..aa2d4cb308 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1005,11 +1005,6 @@ parameters: count: 1 path: LibreNMS/Authentication/ADAuthorizationAuthorizer.php - - - message: "#^Method LibreNMS\\\\Authentication\\\\ADAuthorizationAuthorizer\\:\\:getDomainSid\\(\\) has no return type specified\\.$#" - count: 1 - path: LibreNMS/Authentication/ADAuthorizationAuthorizer.php - - message: "#^Method LibreNMS\\\\Authentication\\\\ADAuthorizationAuthorizer\\:\\:getFullname\\(\\) has no return type specified\\.$#" count: 1 @@ -1125,11 +1120,6 @@ parameters: count: 1 path: LibreNMS/Authentication/ActiveDirectoryAuthorizer.php - - - message: "#^Method LibreNMS\\\\Authentication\\\\ActiveDirectoryAuthorizer\\:\\:getDomainSid\\(\\) has no return type specified\\.$#" - count: 1 - path: LibreNMS/Authentication/ActiveDirectoryAuthorizer.php - - message: "#^Method LibreNMS\\\\Authentication\\\\ActiveDirectoryAuthorizer\\:\\:getFullname\\(\\) has no return type specified\\.$#" count: 1