Rev 24 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 24 | Rev 77 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * VtsLDAPUtils - Simple LDAP helper functions |
4 | * VtsLDAPUtils - Simple LDAP helper functions |
5 | * Copyright 2021 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2021 - 2023 Daniel Marschall, ViaThinkSoft |
6 | * Revision: 2021-06-11 |
6 | * Revision: 2023-04-09 |
7 | * |
7 | * |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
9 | * you may not use this file except in compliance with the License. |
9 | * you may not use this file except in compliance with the License. |
10 | * You may obtain a copy of the License at |
10 | * You may obtain a copy of the License at |
11 | * |
11 | * |
Line 20... | Line 20... | ||
20 | 20 | ||
21 | class VtsLDAPUtils { |
21 | class VtsLDAPUtils { |
22 | 22 | ||
23 | protected $conn = null; |
23 | protected $conn = null; |
24 | 24 | ||
25 | private static function _L($str, ...$sprintfArgs) { |
25 | private static function _L(string $str, ...$sprintfArgs): string { |
26 | if (function_exists('_L')) { |
26 | if (function_exists('_L')) { |
27 | return _L($str, $sprintfArgs); |
27 | return _L($str, $sprintfArgs); |
28 | } else if (function_exists('my_vsprintf')) { |
28 | } else if (function_exists('my_vsprintf')) { |
29 | return my_vsprintf($str, $sprintfArgs); |
29 | return my_vsprintf($str, $sprintfArgs); |
30 | } else { |
30 | } else { |
Line 111... | Line 111... | ||
111 | 111 | ||
112 | if (!($result = @ldap_search($this->conn,$cfg_ldap_base_dn, $cfg_ldap_user_filter))) throw new Exception(self::_L('Error in search query: %1', ldap_error($this->conn))); |
112 | if (!($result = @ldap_search($this->conn,$cfg_ldap_base_dn, $cfg_ldap_user_filter))) throw new Exception(self::_L('Error in search query: %1', ldap_error($this->conn))); |
113 | $data = ldap_get_entries($this->conn, $result); |
113 | $data = ldap_get_entries($this->conn, $result); |
114 | $ldap_userinfo = array(); |
114 | $ldap_userinfo = array(); |
115 | 115 | ||
116 | if ($data['count'] == 0) return false; |
116 | if ($data['count'] == 0) return false; /* @phpstan-ignore-line */ |
117 | $ldap_userinfo = $data[0]; |
117 | $ldap_userinfo = $data[0]; |
118 | 118 | ||
119 | // empty($ldap_userinfo) can happen if the user did not log-in using their correct userPrincipalName (e.g. "username@domainname" instead of "username@domainname.local") |
119 | // empty($ldap_userinfo) can happen if the user did not log-in using their correct userPrincipalName (e.g. "username@domainname" instead of "username@domainname.local") |
120 | return empty($ldap_userinfo) ? false : $ldap_userinfo; |
120 | return empty($ldap_userinfo) ? false : $ldap_userinfo; |
121 | } |
121 | } |