ILDAPWrapper.php 6.8 KB

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