ILDAPWrapper.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\User_LDAP;
  8. interface ILDAPWrapper {
  9. //LDAP functions in use
  10. /**
  11. * Bind to LDAP directory
  12. * @param \LDAP\Connection $link LDAP link resource
  13. * @param string $dn an RDN to log in with
  14. * @param string $password the password
  15. * @return bool true on success, false otherwise
  16. *
  17. * with $dn and $password as null a anonymous bind is attempted.
  18. */
  19. public function bind($link, $dn, $password);
  20. /**
  21. * connect to an LDAP server
  22. * @param string $host The host to connect to
  23. * @param string $port The port to connect to
  24. * @return \LDAP\Connection|false a link resource on success, otherwise false
  25. */
  26. public function connect($host, $port);
  27. /**
  28. * Retrieve the LDAP pagination cookie
  29. * @param \LDAP\Connection $link LDAP link resource
  30. * @param \LDAP\Result $result LDAP result resource
  31. * @param string &$cookie structure sent by LDAP server
  32. * @return bool true on success, false otherwise
  33. *
  34. * Corresponds to ldap_control_paged_result_response
  35. */
  36. public function controlPagedResultResponse($link, $result, &$cookie);
  37. /**
  38. * Count the number of entries in a search
  39. * @param \LDAP\Connection $link LDAP link resource
  40. * @param \LDAP\Result $result LDAP result resource
  41. * @return int|false number of results on success, false otherwise
  42. */
  43. public function countEntries($link, $result);
  44. /**
  45. * Return the LDAP error number of the last LDAP command
  46. * @param \LDAP\Connection $link LDAP link resource
  47. * @return int error code
  48. */
  49. public function errno($link);
  50. /**
  51. * Return the LDAP error message of the last LDAP command
  52. * @param \LDAP\Connection $link LDAP link resource
  53. * @return string error message
  54. */
  55. public function error($link);
  56. /**
  57. * Splits DN into its component parts
  58. * @param string $dn
  59. * @param int @withAttrib
  60. * @return array|false
  61. * @link https://www.php.net/manual/en/function.ldap-explode-dn.php
  62. */
  63. public function explodeDN($dn, $withAttrib);
  64. /**
  65. * Return first result id
  66. * @param \LDAP\Connection $link LDAP link resource
  67. * @param \LDAP\Result $result LDAP result resource
  68. * @return \LDAP\ResultEntry an LDAP entry resource
  69. * */
  70. public function firstEntry($link, $result);
  71. /**
  72. * Get attributes from a search result entry
  73. * @param \LDAP\Connection $link LDAP link resource
  74. * @param \LDAP\ResultEntry $result LDAP result resource
  75. * @return array|false containing the results, false on error
  76. * */
  77. public function getAttributes($link, $result);
  78. /**
  79. * Get the DN of a result entry
  80. * @param \LDAP\Connection $link LDAP link resource
  81. * @param \LDAP\ResultEntry $result LDAP result resource
  82. * @return string|false containing the DN, false on error
  83. */
  84. public function getDN($link, $result);
  85. /**
  86. * Get all result entries
  87. * @param \LDAP\Connection $link LDAP link resource
  88. * @param \LDAP\Result $result LDAP result resource
  89. * @return array|false containing the results, false on error
  90. */
  91. public function getEntries($link, $result);
  92. /**
  93. * Return next result id
  94. * @param \LDAP\Connection $link LDAP link resource
  95. * @param \LDAP\ResultEntry $result LDAP result resource
  96. * @return \LDAP\ResultEntry an LDAP entry resource
  97. * */
  98. public function nextEntry($link, $result);
  99. /**
  100. * Read an entry
  101. * @param \LDAP\Connection $link LDAP link resource
  102. * @param string $baseDN The DN of the entry to read from
  103. * @param string $filter An LDAP filter
  104. * @param array $attr array of the attributes to read
  105. * @return \LDAP\Result an LDAP search result resource
  106. */
  107. public function read($link, $baseDN, $filter, $attr);
  108. /**
  109. * Search LDAP tree
  110. * @param \LDAP\Connection $link LDAP link resource
  111. * @param string $baseDN The DN of the entry to read from
  112. * @param string $filter An LDAP filter
  113. * @param array $attr array of the attributes to read
  114. * @param int $attrsOnly optional, 1 if only attribute types shall be returned
  115. * @param int $limit optional, limits the result entries
  116. * @return \LDAP\Result|false an LDAP search result resource, false on error
  117. */
  118. public function search($link, string $baseDN, string $filter, array $attr, int $attrsOnly = 0, int $limit = 0, int $pageSize = 0, string $cookie = '');
  119. /**
  120. * Replace the value of a userPassword by $password
  121. * @param \LDAP\Connection $link LDAP link resource
  122. * @param string $userDN the DN of the user whose password is to be replaced
  123. * @param string $password the new value for the userPassword
  124. * @return bool true on success, false otherwise
  125. */
  126. public function modReplace($link, $userDN, $password);
  127. /**
  128. * Performs a PASSWD extended operation.
  129. * @param \LDAP\Connection $link LDAP link resource
  130. * @return bool|string The generated password if new_password is empty or omitted. Otherwise true on success and false on failure.
  131. */
  132. public function exopPasswd($link, string $userDN, string $oldPassword, string $password);
  133. /**
  134. * Sets the value of the specified option to be $value
  135. * @param \LDAP\Connection $link LDAP link resource
  136. * @param int $option a defined LDAP Server option
  137. * @param mixed $value the new value for the option
  138. * @return bool true on success, false otherwise
  139. */
  140. public function setOption($link, $option, $value);
  141. /**
  142. * establish Start TLS
  143. * @param \LDAP\Connection $link LDAP link resource
  144. * @return bool true on success, false otherwise
  145. */
  146. public function startTls($link);
  147. /**
  148. * Unbind from LDAP directory
  149. * @param \LDAP\Connection $link LDAP link resource
  150. * @return bool true on success, false otherwise
  151. */
  152. public function unbind($link);
  153. //additional required methods in Nextcloud
  154. /**
  155. * Checks whether the server supports LDAP
  156. * @return bool true if it the case, false otherwise
  157. * */
  158. public function areLDAPFunctionsAvailable();
  159. /**
  160. * Checks whether the submitted parameter is a resource
  161. * @param mixed $resource the resource variable to check
  162. * @psalm-assert-if-true object $resource
  163. * @return bool true if it is a resource or LDAP object, false otherwise
  164. */
  165. public function isResource($resource);
  166. }