1 | <?php |
||
2 | /** |
||
3 | * EGroupware API - LDAP server information |
||
4 | * |
||
5 | * @link http://www.egroupware.org |
||
6 | * @author Lars Kneschke <[email protected]> |
||
7 | * |
||
8 | * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License |
||
9 | * @package api |
||
10 | * @subpackage ldap |
||
11 | */ |
||
12 | |||
13 | namespace EGroupware\Api\Ldap; |
||
14 | |||
15 | /** |
||
16 | * Class to store and retrieve information (eg. supported object classes) of a connected ldap server |
||
17 | */ |
||
18 | class ServerInfo |
||
19 | { |
||
20 | /** |
||
21 | * Unknown LDAP server |
||
22 | */ |
||
23 | const UNKNOWN = 0; |
||
24 | /** |
||
25 | * OpenLDAP server |
||
26 | */ |
||
27 | const OPENLDAP = 1; |
||
28 | /** |
||
29 | * Samba4 LDAP server |
||
30 | */ |
||
31 | const SAMBA4 = 2; |
||
32 | |||
33 | /** |
||
34 | * @var array $namingContext holds the supported namingcontexts |
||
35 | */ |
||
36 | var $namingContext = array(); |
||
37 | |||
38 | /** |
||
39 | * @var string $version holds the LDAP server version |
||
40 | */ |
||
41 | var $version = 2; |
||
42 | |||
43 | /** |
||
44 | * @var integer $serverType holds the type of LDAP server(OpenLDAP, ADS, NDS, ...) |
||
45 | */ |
||
46 | var $serverType = 0; |
||
47 | |||
48 | /** |
||
49 | * @var string $_subSchemaEntry the subschema entry DN |
||
50 | */ |
||
51 | var $subSchemaEntry = ''; |
||
52 | |||
53 | /** |
||
54 | * @var array $supportedObjectClasses the supported objectclasses |
||
55 | */ |
||
56 | var $supportedObjectClasses = array(); |
||
57 | |||
58 | /** |
||
59 | * @var array $supportedOIDs the supported OIDs |
||
60 | */ |
||
61 | var $supportedOIDs = array(); |
||
62 | |||
63 | /** |
||
64 | * Name of host |
||
65 | * |
||
66 | * @var string |
||
67 | */ |
||
68 | var $host; |
||
69 | |||
70 | /** |
||
71 | * Constructor |
||
72 | * |
||
73 | * @param string $host |
||
74 | */ |
||
75 | function __construct($host) |
||
76 | { |
||
77 | $this->host = $host; |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * gets the version |
||
82 | * |
||
83 | * @return integer the supported ldap version |
||
84 | */ |
||
85 | function getVersion() |
||
86 | { |
||
87 | return $this->version; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * sets the namingcontexts |
||
92 | * |
||
93 | * @param array $_namingContext the supported namingcontexts |
||
94 | */ |
||
95 | function setNamingContexts($_namingContext) |
||
96 | { |
||
97 | $this->namingContext = $_namingContext; |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * sets the type of the ldap server(OpenLDAP, ADS, NDS, ...) |
||
102 | * |
||
103 | * @param integer $_serverType the type of ldap server |
||
104 | */ |
||
105 | function setServerType($_serverType) |
||
106 | { |
||
107 | $this->serverType = $_serverType; |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * sets the DN for the subschema entry |
||
112 | * |
||
113 | * @param string $_subSchemaEntry the subschema entry DN |
||
114 | */ |
||
115 | function setSubSchemaEntry($_subSchemaEntry) |
||
116 | { |
||
117 | $this->subSchemaEntry = $_subSchemaEntry; |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * sets the supported objectclasses |
||
122 | * |
||
123 | * @param array $_supportedObjectClasses the supported objectclasses |
||
124 | */ |
||
125 | function setSupportedObjectClasses($_supportedObjectClasses) |
||
126 | { |
||
127 | $this->supportedOIDs = $_supportedObjectClasses; |
||
128 | $this->supportedObjectClasses = array_flip($_supportedObjectClasses); |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * sets the version |
||
133 | * |
||
134 | * @param integer $_version the supported ldap version |
||
135 | */ |
||
136 | function setVersion($_version) |
||
137 | { |
||
138 | $this->version = $_version; |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * checks for supported objectclasses |
||
143 | * |
||
144 | * @return bool returns true if the ldap server supports this objectclass |
||
145 | */ |
||
146 | function supportsObjectClass($_objectClass) |
||
147 | { |
||
148 | if($this->supportedObjectClasses[strtolower($_objectClass)]) |
||
149 | { |
||
150 | return true; |
||
151 | } |
||
152 | return false; |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * Query given ldap connection for available information |
||
157 | * |
||
158 | * @param resource $ds |
||
159 | * @param string $host |
||
160 | * @param int $version 2 or 3 |
||
161 | * @return ldapserverinfo |
||
0 ignored issues
–
show
|
|||
162 | */ |
||
163 | public static function get($ds, $host, $version=3) |
||
164 | { |
||
165 | $filter='(objectclass=*)'; |
||
166 | $justthese = array('structuralObjectClass','namingContexts','supportedLDAPVersion','subschemaSubentry','vendorname'); |
||
167 | if(($sr = @ldap_read($ds, '', $filter, $justthese))) |
||
168 | { |
||
169 | if(($info = ldap_get_entries($ds, $sr))) |
||
170 | { |
||
171 | $ldapServerInfo = new ServerInfo($host); |
||
172 | $ldapServerInfo->setVersion($version); |
||
173 | |||
174 | // check for naming contexts |
||
175 | if($info[0]['namingcontexts']) |
||
176 | { |
||
177 | for($i=0; $i<$info[0]['namingcontexts']['count']; $i++) |
||
178 | { |
||
179 | $namingcontexts[] = $info[0]['namingcontexts'][$i]; |
||
180 | } |
||
181 | $ldapServerInfo->setNamingContexts($namingcontexts); |
||
182 | } |
||
183 | |||
184 | // check for ldap server type |
||
185 | if($info[0]['structuralobjectclass']) |
||
186 | { |
||
187 | switch($info[0]['structuralobjectclass'][0]) |
||
188 | { |
||
189 | case 'OpenLDAProotDSE': |
||
190 | $ldapServerType = self::OPENLDAP; |
||
191 | break; |
||
192 | default: |
||
193 | $ldapServerType = self::UNKNOWN; |
||
194 | break; |
||
195 | } |
||
196 | $ldapServerInfo->setServerType($ldapServerType); |
||
197 | } |
||
198 | if ($info[0]['vendorname'] && stripos($info[0]['vendorname'][0], 'samba') !== false) |
||
199 | { |
||
200 | $ldapServerInfo->setServerType(self::SAMBA4); |
||
201 | } |
||
202 | |||
203 | // check for subschema entry dn |
||
204 | if($info[0]['subschemasubentry']) |
||
205 | { |
||
206 | $subschemasubentry = $info[0]['subschemasubentry'][0]; |
||
207 | $ldapServerInfo->setSubSchemaEntry($subschemasubentry); |
||
208 | } |
||
209 | |||
210 | // create list of supported objetclasses |
||
211 | if(!empty($subschemasubentry)) |
||
212 | { |
||
213 | $filter='(objectclass=*)'; |
||
214 | $justthese = array('objectClasses'); |
||
215 | |||
216 | if(($sr = ldap_read($ds, $subschemasubentry, $filter, $justthese))) |
||
217 | { |
||
218 | if(($info = ldap_get_entries($ds, $sr))) |
||
219 | { |
||
220 | if($info[0]['objectclasses']) { |
||
221 | for($i=0; $i<$info[0]['objectclasses']['count']; $i++) |
||
222 | { |
||
223 | $matches = null; |
||
224 | if(preg_match('/^\( (.*) NAME \'(\w*)\' /', $info[0]['objectclasses'][$i], $matches)) |
||
225 | { |
||
226 | #_debug_array($matches); |
||
227 | if(count($matches) == 3) |
||
228 | { |
||
229 | $supportedObjectClasses[$matches[1]] = strtolower($matches[2]); |
||
230 | } |
||
231 | } |
||
232 | } |
||
233 | $ldapServerInfo->setSupportedObjectClasses($supportedObjectClasses); |
||
234 | } |
||
235 | } |
||
236 | } |
||
237 | } |
||
238 | } |
||
239 | } |
||
240 | return $ldapServerInfo; |
||
241 | } |
||
242 | } |
||
243 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths