You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ILDAPWrapper.php 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 $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 mixed a link resource on success, otherwise false
  48. */
  49. public function connect($host, $port);
  50. /**
  51. * Send LDAP pagination control
  52. * @param resource $link LDAP link resource
  53. * @param int $pageSize number of results per page
  54. * @param bool $isCritical Indicates whether the pagination is critical of not.
  55. * @param string $cookie structure sent by LDAP server
  56. * @return bool true on success, false otherwise
  57. */
  58. public function controlPagedResult($link, $pageSize, $isCritical);
  59. /**
  60. * Retrieve the LDAP pagination cookie
  61. * @param resource $link LDAP link resource
  62. * @param resource $result LDAP result resource
  63. * @param string $cookie structure sent by LDAP server
  64. * @return bool true on success, false otherwise
  65. *
  66. * Corresponds to ldap_control_paged_result_response
  67. */
  68. public function controlPagedResultResponse($link, $result, &$cookie);
  69. /**
  70. * Count the number of entries in a search
  71. * @param resource $link LDAP link resource
  72. * @param resource $result LDAP result resource
  73. * @return int|false number of results on success, false otherwise
  74. */
  75. public function countEntries($link, $result);
  76. /**
  77. * Return the LDAP error number of the last LDAP command
  78. * @param resource $link LDAP link resource
  79. * @return int error code
  80. */
  81. public function errno($link);
  82. /**
  83. * Return the LDAP error message of the last LDAP command
  84. * @param resource $link LDAP link resource
  85. * @return string error message
  86. */
  87. public function error($link);
  88. /**
  89. * Splits DN into its component parts
  90. * @param string $dn
  91. * @param int @withAttrib
  92. * @return array|false
  93. * @link https://www.php.net/manual/en/function.ldap-explode-dn.php
  94. */
  95. public function explodeDN($dn, $withAttrib);
  96. /**
  97. * Return first result id
  98. * @param resource $link LDAP link resource
  99. * @param resource $result LDAP result resource
  100. * @return Resource an LDAP search result resource
  101. * */
  102. public function firstEntry($link, $result);
  103. /**
  104. * Get attributes from a search result entry
  105. * @param resource $link LDAP link resource
  106. * @param resource $result LDAP result resource
  107. * @return array containing the results, false on error
  108. * */
  109. public function getAttributes($link, $result);
  110. /**
  111. * Get the DN of a result entry
  112. * @param resource $link LDAP link resource
  113. * @param resource $result LDAP result resource
  114. * @return string containing the DN, false on error
  115. */
  116. public function getDN($link, $result);
  117. /**
  118. * Get all result entries
  119. * @param resource $link LDAP link resource
  120. * @param resource $result LDAP result resource
  121. * @return array containing the results, false on error
  122. */
  123. public function getEntries($link, $result);
  124. /**
  125. * Return next result id
  126. * @param resource $link LDAP link resource
  127. * @param resource $result LDAP entry result resource
  128. * @return resource an LDAP search result resource
  129. * */
  130. public function nextEntry($link, $result);
  131. /**
  132. * Read an entry
  133. * @param resource $link LDAP link resource
  134. * @param array $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. * @return resource an LDAP search result resource
  138. */
  139. public function read($link, $baseDN, $filter, $attr);
  140. /**
  141. * Search LDAP tree
  142. * @param resource $link LDAP link resource
  143. * @param string $baseDN The DN of the entry to read from
  144. * @param string $filter An LDAP filter
  145. * @param array $attr array of the attributes to read
  146. * @param int $attrsOnly optional, 1 if only attribute types shall be returned
  147. * @param int $limit optional, limits the result entries
  148. * @return resource|false an LDAP search result resource, false on error
  149. */
  150. public function search($link, $baseDN, $filter, $attr, $attrsOnly = 0, $limit = 0);
  151. /**
  152. * Replace the value of a userPassword by $password
  153. * @param resource $link LDAP link resource
  154. * @param string $userDN the DN of the user whose password is to be replaced
  155. * @param string $password the new value for the userPassword
  156. * @return bool true on success, false otherwise
  157. */
  158. public function modReplace($link, $userDN, $password);
  159. /**
  160. * Sets the value of the specified option to be $value
  161. * @param resource $link LDAP link resource
  162. * @param string $option a defined LDAP Server option
  163. * @param int $value the new value for the option
  164. * @return bool true on success, false otherwise
  165. */
  166. public function setOption($link, $option, $value);
  167. /**
  168. * establish Start TLS
  169. * @param resource $link LDAP link resource
  170. * @return bool true on success, false otherwise
  171. */
  172. public function startTls($link);
  173. /**
  174. * Unbind from LDAP directory
  175. * @param resource $link LDAP link resource
  176. * @return bool true on success, false otherwise
  177. */
  178. public function unbind($link);
  179. //additional required methods in Nextcloud
  180. /**
  181. * Checks whether the server supports LDAP
  182. * @return bool true if it the case, false otherwise
  183. * */
  184. public function areLDAPFunctionsAvailable();
  185. /**
  186. * Checks whether the submitted parameter is a resource
  187. * @param resource $resource the resource variable to check
  188. * @return bool true if it is a resource, false otherwise
  189. */
  190. public function isResource($resource);
  191. }