ildapwrapper.php 6.5 KB

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