ILDAPWrapper.php 6.7 KB

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