1
0

ILDAPWrapper.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author J0WI <J0WI@users.noreply.github.com>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Robin McCorkell <robin@mccorkell.me.uk>
  12. * @author Roger Szabo <roger.szabo@web.de>
  13. * @author Vinicius Cubas Brand <vinicius@eita.org.br>
  14. *
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. namespace OCA\User_LDAP;
  31. interface ILDAPWrapper {
  32. //LDAP functions in use
  33. /**
  34. * Bind to LDAP directory
  35. * @param resource|\LDAP\Connection $link LDAP link resource
  36. * @param string $dn an RDN to log in with
  37. * @param string $password the password
  38. * @return bool true on success, false otherwise
  39. *
  40. * with $dn and $password as null a anonymous bind is attempted.
  41. */
  42. public function bind($link, $dn, $password);
  43. /**
  44. * connect to an LDAP server
  45. * @param string $host The host to connect to
  46. * @param string $port The port to connect to
  47. * @return resource|\LDAP\Connection|false a link resource on success, otherwise false
  48. */
  49. public function connect($host, $port);
  50. /**
  51. * Retrieve the LDAP pagination cookie
  52. * @param resource|\LDAP\Connection $link LDAP link resource
  53. * @param resource|\LDAP\Result $result LDAP result resource
  54. * @param string &$cookie structure sent by LDAP server
  55. * @return bool true on success, false otherwise
  56. *
  57. * Corresponds to ldap_control_paged_result_response
  58. */
  59. public function controlPagedResultResponse($link, $result, &$cookie);
  60. /**
  61. * Count the number of entries in a search
  62. * @param resource|\LDAP\Connection $link LDAP link resource
  63. * @param resource|\LDAP\Result $result LDAP result resource
  64. * @return int|false number of results on success, false otherwise
  65. */
  66. public function countEntries($link, $result);
  67. /**
  68. * Return the LDAP error number of the last LDAP command
  69. * @param resource|\LDAP\Connection $link LDAP link resource
  70. * @return int error code
  71. */
  72. public function errno($link);
  73. /**
  74. * Return the LDAP error message of the last LDAP command
  75. * @param resource|\LDAP\Connection $link LDAP link resource
  76. * @return string error message
  77. */
  78. public function error($link);
  79. /**
  80. * Splits DN into its component parts
  81. * @param string $dn
  82. * @param int @withAttrib
  83. * @return array|false
  84. * @link https://www.php.net/manual/en/function.ldap-explode-dn.php
  85. */
  86. public function explodeDN($dn, $withAttrib);
  87. /**
  88. * Return first result id
  89. * @param resource|\LDAP\Connection $link LDAP link resource
  90. * @param resource|\LDAP\Result $result LDAP result resource
  91. * @return resource|\LDAP\ResultEntry an LDAP entry resource
  92. * */
  93. public function firstEntry($link, $result);
  94. /**
  95. * Get attributes from a search result entry
  96. * @param resource|\LDAP\Connection $link LDAP link resource
  97. * @param resource|\LDAP\ResultEntry $result LDAP result resource
  98. * @return array|false containing the results, false on error
  99. * */
  100. public function getAttributes($link, $result);
  101. /**
  102. * Get the DN of a result entry
  103. * @param resource|\LDAP\Connection $link LDAP link resource
  104. * @param resource|\LDAP\ResultEntry $result LDAP result resource
  105. * @return string|false containing the DN, false on error
  106. */
  107. public function getDN($link, $result);
  108. /**
  109. * Get all result entries
  110. * @param resource|\LDAP\Connection $link LDAP link resource
  111. * @param resource|\LDAP\Result $result LDAP result resource
  112. * @return array|false containing the results, false on error
  113. */
  114. public function getEntries($link, $result);
  115. /**
  116. * Return next result id
  117. * @param resource|\LDAP\Connection $link LDAP link resource
  118. * @param resource|\LDAP\ResultEntry $result LDAP result resource
  119. * @return resource|\LDAP\ResultEntry an LDAP entry resource
  120. * */
  121. public function nextEntry($link, $result);
  122. /**
  123. * Read an entry
  124. * @param resource|\LDAP\Connection $link LDAP link resource
  125. * @param string $baseDN The DN of the entry to read from
  126. * @param string $filter An LDAP filter
  127. * @param array $attr array of the attributes to read
  128. * @return resource|\LDAP\Result an LDAP search result resource
  129. */
  130. public function read($link, $baseDN, $filter, $attr);
  131. /**
  132. * Search LDAP tree
  133. * @param resource|\LDAP\Connection $link LDAP link resource
  134. * @param string $baseDN The DN of the entry to read from
  135. * @param string $filter An LDAP filter
  136. * @param array $attr array of the attributes to read
  137. * @param int $attrsOnly optional, 1 if only attribute types shall be returned
  138. * @param int $limit optional, limits the result entries
  139. * @return resource|\LDAP\Result|false an LDAP search result resource, false on error
  140. */
  141. public function search($link, string $baseDN, string $filter, array $attr, int $attrsOnly = 0, int $limit = 0, int $pageSize = 0, string $cookie = '');
  142. /**
  143. * Replace the value of a userPassword by $password
  144. * @param resource|\LDAP\Connection $link LDAP link resource
  145. * @param string $userDN the DN of the user whose password is to be replaced
  146. * @param string $password the new value for the userPassword
  147. * @return bool true on success, false otherwise
  148. */
  149. public function modReplace($link, $userDN, $password);
  150. /**
  151. * Performs a PASSWD extended operation.
  152. * @param resource|\LDAP\Connection $link LDAP link resource
  153. * @return bool|string The generated password if new_password is empty or omitted. Otherwise true on success and false on failure.
  154. */
  155. public function exopPasswd($link, string $userDN, string $oldPassword, string $password);
  156. /**
  157. * Sets the value of the specified option to be $value
  158. * @param resource|\LDAP\Connection $link LDAP link resource
  159. * @param int $option a defined LDAP Server option
  160. * @param mixed $value the new value for the option
  161. * @return bool true on success, false otherwise
  162. */
  163. public function setOption($link, $option, $value);
  164. /**
  165. * establish Start TLS
  166. * @param resource|\LDAP\Connection $link LDAP link resource
  167. * @return bool true on success, false otherwise
  168. */
  169. public function startTls($link);
  170. /**
  171. * Unbind from LDAP directory
  172. * @param resource|\LDAP\Connection $link LDAP link resource
  173. * @return bool true on success, false otherwise
  174. */
  175. public function unbind($link);
  176. //additional required methods in Nextcloud
  177. /**
  178. * Checks whether the server supports LDAP
  179. * @return bool true if it the case, false otherwise
  180. * */
  181. public function areLDAPFunctionsAvailable();
  182. /**
  183. * Checks whether the submitted parameter is a resource
  184. * @param mixed $resource the resource variable to check
  185. * @return bool true if it is a resource or LDAP object, false otherwise
  186. */
  187. public function isResource($resource);
  188. }