ildapwrapper.php 6.7 KB

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