blob: c74fe4e891211d16036d080dfa0e101405aaba87 [file] [log] [blame]
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001<?php
2
3namespace LdapRecord;
4
5interface LdapInterface
6{
7 /**
8 * The SSL LDAP protocol string.
9 *
10 * @var string
11 */
12 const PROTOCOL_SSL = 'ldaps://';
13
14 /**
15 * The standard LDAP protocol string.
16 *
17 * @var string
18 */
19 const PROTOCOL = 'ldap://';
20
21 /**
22 * The LDAP SSL port number.
23 *
24 * @var string
25 */
26 const PORT_SSL = 636;
27
28 /**
29 * The standard LDAP port number.
30 *
31 * @var string
32 */
33 const PORT = 389;
34
35 /**
36 * Various useful server control OID's.
37 *
38 * @see https://ldap.com/ldap-oid-reference-guide/
39 * @see http://msdn.microsoft.com/en-us/library/cc223359.aspx
40 */
41 const OID_SERVER_START_TLS = '1.3.6.1.4.1.1466.20037';
42 const OID_SERVER_PAGED_RESULTS = '1.2.840.113556.1.4.319';
43 const OID_SERVER_SHOW_DELETED = '1.2.840.113556.1.4.417';
44 const OID_SERVER_SORT = '1.2.840.113556.1.4.473';
45 const OID_SERVER_CROSSDOM_MOVE_TARGET = '1.2.840.113556.1.4.521';
46 const OID_SERVER_NOTIFICATION = '1.2.840.113556.1.4.528';
47 const OID_SERVER_EXTENDED_DN = '1.2.840.113556.1.4.529';
48 const OID_SERVER_LAZY_COMMIT = '1.2.840.113556.1.4.619';
49 const OID_SERVER_SD_FLAGS = '1.2.840.113556.1.4.801';
50 const OID_SERVER_TREE_DELETE = '1.2.840.113556.1.4.805';
51 const OID_SERVER_DIRSYNC = '1.2.840.113556.1.4.841';
52 const OID_SERVER_VERIFY_NAME = '1.2.840.113556.1.4.1338';
53 const OID_SERVER_DOMAIN_SCOPE = '1.2.840.113556.1.4.1339';
54 const OID_SERVER_SEARCH_OPTIONS = '1.2.840.113556.1.4.1340';
55 const OID_SERVER_PERMISSIVE_MODIFY = '1.2.840.113556.1.4.1413';
56 const OID_SERVER_ASQ = '1.2.840.113556.1.4.1504';
57 const OID_SERVER_FAST_BIND = '1.2.840.113556.1.4.1781';
58 const OID_SERVER_CONTROL_VLVREQUEST = '2.16.840.1.113730.3.4.9';
59
60 /**
61 * Query OID's.
62 *
63 * @see https://ldapwiki.com/wiki/LDAP_MATCHING_RULE_IN_CHAIN
64 */
65 const OID_MATCHING_RULE_IN_CHAIN = '1.2.840.113556.1.4.1941';
66
67 /**
68 * Set the current connection to use SSL.
69 *
70 * @param bool $enabled
71 *
72 * @return $this
73 */
74 public function ssl();
75
76 /**
77 * Determine if the current connection instance is using SSL.
78 *
79 * @return bool
80 */
81 public function isUsingSSL();
82
83 /**
84 * Set the current connection to use TLS.
85 *
86 * @param bool $enabled
87 *
88 * @return $this
89 */
90 public function tls();
91
92 /**
93 * Determine if the current connection instance is using TLS.
94 *
95 * @return bool
96 */
97 public function isUsingTLS();
98
99 /**
100 * Determine if the connection is bound.
101 *
102 * @return bool
103 */
104 public function isBound();
105
106 /**
107 * Determine if the connection has been created.
108 *
109 * @return bool
110 */
111 public function isConnected();
112
113 /**
114 * Determine the connection is able to modify passwords.
115 *
116 * @return bool
117 */
118 public function canChangePasswords();
119
120 /**
121 * Returns the full LDAP host URL.
122 *
123 * Ex: ldap://192.168.1.1:386
124 *
125 * @return string|null
126 */
127 public function getHost();
128
129 /**
130 * Get the underlying connection resource.
131 *
132 * @return resource|null
133 */
134 public function getConnection();
135
136 /**
137 * Retrieve the entries from a search result.
138 *
139 * @see http://php.net/manual/en/function.ldap-get-entries.php
140 *
141 * @param resource $searchResults
142 *
143 * @return array
144 */
145 public function getEntries($searchResults);
146
147 /**
148 * Retrieve the last error on the current connection.
149 *
150 * @see http://php.net/manual/en/function.ldap-error.php
151 *
152 * @return string|null
153 */
154 public function getLastError();
155
156 /**
157 * Return detailed information about an error.
158 *
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100159 * Returns null when there was a successful last request.
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200160 *
161 * Returns DetailedError when there was an error.
162 *
163 * @return DetailedError|null
164 */
165 public function getDetailedError();
166
167 /**
168 * Set an option on the current connection.
169 *
170 * @see http://php.net/manual/en/function.ldap-set-option.php
171 *
172 * @param int $option
173 * @param mixed $value
174 *
175 * @return bool
176 */
177 public function setOption($option, $value);
178
179 /**
180 * Set options on the current connection.
181 *
182 * @param array $options
183 *
184 * @return void
185 */
186 public function setOptions(array $options = []);
187
188 /**
189 * Get the value for the LDAP option.
190 *
191 * @see https://www.php.net/manual/en/function.ldap-get-option.php
192 *
193 * @param int $option
194 * @param mixed $value
195 *
196 * @return mixed
197 */
198 public function getOption($option, &$value = null);
199
200 /**
201 * Starts a connection using TLS.
202 *
203 * @see http://php.net/manual/en/function.ldap-start-tls.php
204 *
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200205 * @return bool
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100206 *
207 * @throws LdapRecordException
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200208 */
209 public function startTLS();
210
211 /**
212 * Connects to the specified hostname using the specified port.
213 *
214 * @see http://php.net/manual/en/function.ldap-start-tls.php
215 *
216 * @param string|array $hosts
217 * @param int $port
218 *
219 * @return resource|false
220 */
221 public function connect($hosts = [], $port = 389);
222
223 /**
224 * Closes the current connection.
225 *
226 * Returns false if no connection is present.
227 *
228 * @see http://php.net/manual/en/function.ldap-close.php
229 *
230 * @return bool
231 */
232 public function close();
233
234 /**
235 * Performs a search on the current connection.
236 *
237 * @see http://php.net/manual/en/function.ldap-search.php
238 *
239 * @param string $dn
240 * @param string $filter
241 * @param array $fields
242 * @param bool $onlyAttributes
243 * @param int $size
244 * @param int $time
245 * @param int $deref
246 * @param array $serverControls
247 *
248 * @return resource
249 */
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100250 public function search($dn, $filter, array $fields, $onlyAttributes = false, $size = 0, $time = 0, $deref = LDAP_DEREF_NEVER, $serverControls = []);
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200251
252 /**
253 * Performs a single level search on the current connection.
254 *
255 * @see http://php.net/manual/en/function.ldap-list.php
256 *
257 * @param string $dn
258 * @param string $filter
259 * @param array $fields
260 * @param bool $onlyAttributes
261 * @param int $size
262 * @param int $time
263 * @param int $deref
264 * @param array $serverControls
265 *
266 * @return resource
267 */
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100268 public function listing($dn, $filter, array $fields, $onlyAttributes = false, $size = 0, $time = 0, $deref = LDAP_DEREF_NEVER, $serverControls = []);
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200269
270 /**
271 * Reads an entry on the current connection.
272 *
273 * @see http://php.net/manual/en/function.ldap-read.php
274 *
275 * @param string $dn
276 * @param string $filter
277 * @param array $fields
278 * @param bool $onlyAttributes
279 * @param int $size
280 * @param int $time
281 * @param int $deref
282 * @param array $serverControls
283 *
284 * @return resource
285 */
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100286 public function read($dn, $filter, array $fields, $onlyAttributes = false, $size = 0, $time = 0, $deref = LDAP_DEREF_NEVER, $serverControls = []);
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200287
288 /**
289 * Extract information from an LDAP result.
290 *
291 * @see https://www.php.net/manual/en/function.ldap-parse-result.php
292 *
293 * @param resource $result
294 * @param int $errorCode
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100295 * @param ?string $dn
296 * @param ?string $errorMessage
297 * @param ?array $referrals
298 * @param ?array $serverControls
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200299 *
300 * @return bool
301 */
302 public function parseResult($result, &$errorCode, &$dn, &$errorMessage, &$referrals, &$serverControls = []);
303
304 /**
305 * Binds to the current connection using the specified username and password.
306 * If sasl is true, the current connection is bound using SASL.
307 *
308 * @see http://php.net/manual/en/function.ldap-bind.php
309 *
310 * @param string $username
311 * @param string $password
312 *
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200313 * @return bool
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100314 *
315 * @throws LdapRecordException
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200316 */
317 public function bind($username, $password);
318
319 /**
320 * Adds an entry to the current connection.
321 *
322 * @see http://php.net/manual/en/function.ldap-add.php
323 *
324 * @param string $dn
325 * @param array $entry
326 *
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200327 * @return bool
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100328 *
329 * @throws LdapRecordException
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200330 */
331 public function add($dn, array $entry);
332
333 /**
334 * Deletes an entry on the current connection.
335 *
336 * @see http://php.net/manual/en/function.ldap-delete.php
337 *
338 * @param string $dn
339 *
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200340 * @return bool
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100341 *
342 * @throws LdapRecordException
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200343 */
344 public function delete($dn);
345
346 /**
347 * Modify the name of an entry on the current connection.
348 *
349 * @see http://php.net/manual/en/function.ldap-rename.php
350 *
351 * @param string $dn
352 * @param string $newRdn
353 * @param string $newParent
354 * @param bool $deleteOldRdn
355 *
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200356 * @return bool
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100357 *
358 * @throws LdapRecordException
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200359 */
360 public function rename($dn, $newRdn, $newParent, $deleteOldRdn = false);
361
362 /**
363 * Modifies an existing entry on the current connection.
364 *
365 * @see http://php.net/manual/en/function.ldap-modify.php
366 *
367 * @param string $dn
368 * @param array $entry
369 *
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200370 * @return bool
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100371 *
372 * @throws LdapRecordException
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200373 */
374 public function modify($dn, array $entry);
375
376 /**
377 * Batch modifies an existing entry on the current connection.
378 *
379 * @see http://php.net/manual/en/function.ldap-modify-batch.php
380 *
381 * @param string $dn
382 * @param array $values
383 *
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200384 * @return bool
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100385 *
386 * @throws LdapRecordException
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200387 */
388 public function modifyBatch($dn, array $values);
389
390 /**
391 * Add attribute values to current attributes.
392 *
393 * @see http://php.net/manual/en/function.ldap-mod-add.php
394 *
395 * @param string $dn
396 * @param array $entry
397 *
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200398 * @return bool
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100399 *
400 * @throws LdapRecordException
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200401 */
402 public function modAdd($dn, array $entry);
403
404 /**
405 * Replaces attribute values with new ones.
406 *
407 * @see http://php.net/manual/en/function.ldap-mod-replace.php
408 *
409 * @param string $dn
410 * @param array $entry
411 *
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200412 * @return bool
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100413 *
414 * @throws LdapRecordException
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200415 */
416 public function modReplace($dn, array $entry);
417
418 /**
419 * Delete attribute values from current attributes.
420 *
421 * @see http://php.net/manual/en/function.ldap-mod-del.php
422 *
423 * @param string $dn
424 * @param array $entry
425 *
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200426 * @return bool
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100427 *
428 * @throws LdapRecordException
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200429 */
430 public function modDelete($dn, array $entry);
431
432 /**
433 * Send LDAP pagination control.
434 *
435 * @see http://php.net/manual/en/function.ldap-control-paged-result.php
436 *
437 * @param int $pageSize
438 * @param bool $isCritical
439 * @param string $cookie
440 *
441 * @return bool
442 */
443 public function controlPagedResult($pageSize = 1000, $isCritical = false, $cookie = '');
444
445 /**
446 * Retrieve the LDAP pagination cookie.
447 *
448 * @see http://php.net/manual/en/function.ldap-control-paged-result-response.php
449 *
450 * @param resource $result
451 * @param string $cookie
452 *
453 * @return bool
454 */
455 public function controlPagedResultResponse($result, &$cookie);
456
457 /**
458 * Frees up the memory allocated internally to store the result.
459 *
460 * @see https://www.php.net/manual/en/function.ldap-free-result.php
461 *
462 * @param resource $result
463 *
464 * @return bool
465 */
466 public function freeResult($result);
467
468 /**
469 * Returns the error number of the last command executed.
470 *
471 * @see http://php.net/manual/en/function.ldap-errno.php
472 *
473 * @return int|null
474 */
475 public function errNo();
476
477 /**
478 * Returns the error string of the specified error number.
479 *
480 * @see http://php.net/manual/en/function.ldap-err2str.php
481 *
482 * @param int $number
483 *
484 * @return string
485 */
486 public function err2Str($number);
487
488 /**
489 * Returns the LDAP protocol to utilize for the current connection.
490 *
491 * @return string
492 */
493 public function getProtocol();
494
495 /**
496 * Returns the extended error code of the last command.
497 *
498 * @return string
499 */
500 public function getExtendedError();
501
502 /**
503 * Return the diagnostic Message.
504 *
505 * @return string
506 */
507 public function getDiagnosticMessage();
508
509 /**
510 * Determine if the current PHP version supports server controls.
511 *
512 * @deprecated since v2.5.0
513 *
514 * @return bool
515 */
516 public function supportsServerControlsInMethods();
517}