2013-08-20 08:23:49 -04:00
|
|
|
<?php
|
2024-05-29 05:32:54 -04:00
|
|
|
|
2013-08-20 08:23:49 -04:00
|
|
|
/**
|
2024-05-29 05:32:54 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2013-08-20 08:23:49 -04:00
|
|
|
*/
|
2016-05-12 10:25:14 -04:00
|
|
|
namespace OCA\User_LDAP;
|
2013-08-20 08:23:49 -04:00
|
|
|
|
|
|
|
|
interface ILDAPWrapper {
|
|
|
|
|
//LDAP functions in use
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-19 11:50:53 -04:00
|
|
|
* Bind to LDAP directory
|
2024-04-04 10:14:06 -04:00
|
|
|
* @param \LDAP\Connection $link LDAP link resource
|
2014-05-11 09:17:27 -04:00
|
|
|
* @param string $dn an RDN to log in with
|
|
|
|
|
* @param string $password the password
|
|
|
|
|
* @return bool true on success, false otherwise
|
2013-08-20 08:23:49 -04:00
|
|
|
*
|
|
|
|
|
* with $dn and $password as null a anonymous bind is attempted.
|
|
|
|
|
*/
|
|
|
|
|
public function bind($link, $dn, $password);
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-19 11:50:53 -04:00
|
|
|
* connect to an LDAP server
|
2014-05-11 09:17:27 -04:00
|
|
|
* @param string $host The host to connect to
|
|
|
|
|
* @param string $port The port to connect to
|
2024-04-04 10:14:06 -04:00
|
|
|
* @return \LDAP\Connection|false a link resource on success, otherwise false
|
2013-08-20 08:23:49 -04:00
|
|
|
*/
|
|
|
|
|
public function connect($host, $port);
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-19 11:50:53 -04:00
|
|
|
* Retrieve the LDAP pagination cookie
|
2024-04-04 10:14:06 -04:00
|
|
|
* @param \LDAP\Connection $link LDAP link resource
|
|
|
|
|
* @param \LDAP\Result $result LDAP result resource
|
2022-03-03 05:12:09 -05:00
|
|
|
* @param string &$cookie structure sent by LDAP server
|
2014-05-11 09:17:27 -04:00
|
|
|
* @return bool true on success, false otherwise
|
2013-08-20 08:23:49 -04:00
|
|
|
*
|
|
|
|
|
* Corresponds to ldap_control_paged_result_response
|
|
|
|
|
*/
|
|
|
|
|
public function controlPagedResultResponse($link, $result, &$cookie);
|
|
|
|
|
|
2013-09-29 17:53:14 -04:00
|
|
|
/**
|
2014-05-19 11:50:53 -04:00
|
|
|
* Count the number of entries in a search
|
2024-04-04 10:14:06 -04:00
|
|
|
* @param \LDAP\Connection $link LDAP link resource
|
|
|
|
|
* @param \LDAP\Result $result LDAP result resource
|
2014-05-11 09:17:27 -04:00
|
|
|
* @return int|false number of results on success, false otherwise
|
2013-09-29 17:53:14 -04:00
|
|
|
*/
|
|
|
|
|
public function countEntries($link, $result);
|
|
|
|
|
|
2013-08-20 08:23:49 -04:00
|
|
|
/**
|
2014-05-19 11:50:53 -04:00
|
|
|
* Return the LDAP error number of the last LDAP command
|
2024-04-04 10:14:06 -04:00
|
|
|
* @param \LDAP\Connection $link LDAP link resource
|
2017-07-05 16:06:36 -04:00
|
|
|
* @return int error code
|
2013-08-20 08:23:49 -04:00
|
|
|
*/
|
|
|
|
|
public function errno($link);
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-19 11:50:53 -04:00
|
|
|
* Return the LDAP error message of the last LDAP command
|
2024-04-04 10:14:06 -04:00
|
|
|
* @param \LDAP\Connection $link LDAP link resource
|
2017-07-05 16:06:36 -04:00
|
|
|
* @return string error message
|
2013-08-20 08:23:49 -04:00
|
|
|
*/
|
|
|
|
|
public function error($link);
|
|
|
|
|
|
2014-07-01 16:02:41 -04:00
|
|
|
/**
|
|
|
|
|
* Splits DN into its component parts
|
|
|
|
|
* @param string $dn
|
|
|
|
|
* @param int @withAttrib
|
|
|
|
|
* @return array|false
|
2020-09-17 11:23:07 -04:00
|
|
|
* @link https://www.php.net/manual/en/function.ldap-explode-dn.php
|
2014-07-01 16:02:41 -04:00
|
|
|
*/
|
|
|
|
|
public function explodeDN($dn, $withAttrib);
|
|
|
|
|
|
2013-08-20 08:23:49 -04:00
|
|
|
/**
|
2014-05-19 11:50:53 -04:00
|
|
|
* Return first result id
|
2024-04-04 10:14:06 -04:00
|
|
|
* @param \LDAP\Connection $link LDAP link resource
|
|
|
|
|
* @param \LDAP\Result $result LDAP result resource
|
|
|
|
|
* @return \LDAP\ResultEntry an LDAP entry resource
|
2013-08-20 08:23:49 -04:00
|
|
|
* */
|
|
|
|
|
public function firstEntry($link, $result);
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-19 11:50:53 -04:00
|
|
|
* Get attributes from a search result entry
|
2024-04-04 10:14:06 -04:00
|
|
|
* @param \LDAP\Connection $link LDAP link resource
|
|
|
|
|
* @param \LDAP\ResultEntry $result LDAP result resource
|
2022-10-20 10:45:43 -04:00
|
|
|
* @return array|false containing the results, false on error
|
2013-08-20 08:23:49 -04:00
|
|
|
* */
|
|
|
|
|
public function getAttributes($link, $result);
|
|
|
|
|
|
2013-10-04 10:33:37 -04:00
|
|
|
/**
|
2014-05-19 11:50:53 -04:00
|
|
|
* Get the DN of a result entry
|
2024-04-04 10:14:06 -04:00
|
|
|
* @param \LDAP\Connection $link LDAP link resource
|
|
|
|
|
* @param \LDAP\ResultEntry $result LDAP result resource
|
2022-10-20 10:45:43 -04:00
|
|
|
* @return string|false containing the DN, false on error
|
2013-10-04 10:33:37 -04:00
|
|
|
*/
|
|
|
|
|
public function getDN($link, $result);
|
|
|
|
|
|
2013-08-20 08:23:49 -04:00
|
|
|
/**
|
2014-05-19 11:50:53 -04:00
|
|
|
* Get all result entries
|
2024-04-04 10:14:06 -04:00
|
|
|
* @param \LDAP\Connection $link LDAP link resource
|
|
|
|
|
* @param \LDAP\Result $result LDAP result resource
|
2022-10-20 10:45:43 -04:00
|
|
|
* @return array|false containing the results, false on error
|
2013-08-20 08:23:49 -04:00
|
|
|
*/
|
|
|
|
|
public function getEntries($link, $result);
|
|
|
|
|
|
2013-10-04 10:33:37 -04:00
|
|
|
/**
|
2014-05-19 11:50:53 -04:00
|
|
|
* Return next result id
|
2024-04-04 10:14:06 -04:00
|
|
|
* @param \LDAP\Connection $link LDAP link resource
|
|
|
|
|
* @param \LDAP\ResultEntry $result LDAP result resource
|
|
|
|
|
* @return \LDAP\ResultEntry an LDAP entry resource
|
2013-10-04 10:33:37 -04:00
|
|
|
* */
|
|
|
|
|
public function nextEntry($link, $result);
|
|
|
|
|
|
2013-08-20 08:23:49 -04:00
|
|
|
/**
|
2014-05-19 11:50:53 -04:00
|
|
|
* Read an entry
|
2024-04-04 10:14:06 -04:00
|
|
|
* @param \LDAP\Connection $link LDAP link resource
|
2021-11-29 05:42:27 -05:00
|
|
|
* @param string $baseDN The DN of the entry to read from
|
2014-05-11 09:17:27 -04:00
|
|
|
* @param string $filter An LDAP filter
|
|
|
|
|
* @param array $attr array of the attributes to read
|
2024-04-04 10:14:06 -04:00
|
|
|
* @return \LDAP\Result an LDAP search result resource
|
2013-08-20 08:23:49 -04:00
|
|
|
*/
|
|
|
|
|
public function read($link, $baseDN, $filter, $attr);
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-19 11:50:53 -04:00
|
|
|
* Search LDAP tree
|
2024-04-04 10:14:06 -04:00
|
|
|
* @param \LDAP\Connection $link LDAP link resource
|
2014-05-11 09:17:27 -04:00
|
|
|
* @param string $baseDN The DN of the entry to read from
|
|
|
|
|
* @param string $filter An LDAP filter
|
|
|
|
|
* @param array $attr array of the attributes to read
|
|
|
|
|
* @param int $attrsOnly optional, 1 if only attribute types shall be returned
|
|
|
|
|
* @param int $limit optional, limits the result entries
|
2024-04-04 10:14:06 -04:00
|
|
|
* @return \LDAP\Result|false an LDAP search result resource, false on error
|
2013-08-20 08:23:49 -04:00
|
|
|
*/
|
2022-09-08 08:47:50 -04:00
|
|
|
public function search($link, string $baseDN, string $filter, array $attr, int $attrsOnly = 0, int $limit = 0, int $pageSize = 0, string $cookie = '');
|
2017-11-02 08:40:38 -04:00
|
|
|
|
2016-08-30 05:43:29 -04:00
|
|
|
/**
|
|
|
|
|
* Replace the value of a userPassword by $password
|
2024-04-04 10:14:06 -04:00
|
|
|
* @param \LDAP\Connection $link LDAP link resource
|
2016-08-30 05:43:29 -04:00
|
|
|
* @param string $userDN the DN of the user whose password is to be replaced
|
|
|
|
|
* @param string $password the new value for the userPassword
|
|
|
|
|
* @return bool true on success, false otherwise
|
|
|
|
|
*/
|
|
|
|
|
public function modReplace($link, $userDN, $password);
|
2013-08-20 08:23:49 -04:00
|
|
|
|
2022-09-28 09:27:04 -04:00
|
|
|
/**
|
|
|
|
|
* Performs a PASSWD extended operation.
|
2024-04-04 10:14:06 -04:00
|
|
|
* @param \LDAP\Connection $link LDAP link resource
|
2022-09-28 09:27:04 -04:00
|
|
|
* @return bool|string The generated password if new_password is empty or omitted. Otherwise true on success and false on failure.
|
|
|
|
|
*/
|
|
|
|
|
public function exopPasswd($link, string $userDN, string $oldPassword, string $password);
|
|
|
|
|
|
2013-08-20 08:23:49 -04:00
|
|
|
/**
|
2014-05-19 11:50:53 -04:00
|
|
|
* Sets the value of the specified option to be $value
|
2024-04-04 10:14:06 -04:00
|
|
|
* @param \LDAP\Connection $link LDAP link resource
|
2022-03-03 10:35:06 -05:00
|
|
|
* @param int $option a defined LDAP Server option
|
|
|
|
|
* @param mixed $value the new value for the option
|
2014-05-11 09:17:27 -04:00
|
|
|
* @return bool true on success, false otherwise
|
2013-08-20 08:23:49 -04:00
|
|
|
*/
|
|
|
|
|
public function setOption($link, $option, $value);
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-19 11:50:53 -04:00
|
|
|
* establish Start TLS
|
2024-04-04 10:14:06 -04:00
|
|
|
* @param \LDAP\Connection $link LDAP link resource
|
2014-05-11 09:17:27 -04:00
|
|
|
* @return bool true on success, false otherwise
|
2013-08-20 08:23:49 -04:00
|
|
|
*/
|
|
|
|
|
public function startTls($link);
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-19 11:50:53 -04:00
|
|
|
* Unbind from LDAP directory
|
2024-04-04 10:14:06 -04:00
|
|
|
* @param \LDAP\Connection $link LDAP link resource
|
2014-05-11 09:17:27 -04:00
|
|
|
* @return bool true on success, false otherwise
|
2013-08-20 08:23:49 -04:00
|
|
|
*/
|
|
|
|
|
public function unbind($link);
|
|
|
|
|
|
2017-04-12 00:16:27 -04:00
|
|
|
//additional required methods in Nextcloud
|
2013-08-20 08:23:49 -04:00
|
|
|
|
|
|
|
|
/**
|
2014-05-19 11:50:53 -04:00
|
|
|
* Checks whether the server supports LDAP
|
2014-05-11 09:17:27 -04:00
|
|
|
* @return bool true if it the case, false otherwise
|
2013-08-20 08:23:49 -04:00
|
|
|
* */
|
|
|
|
|
public function areLDAPFunctionsAvailable();
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-19 11:50:53 -04:00
|
|
|
* Checks whether the submitted parameter is a resource
|
2021-10-26 10:43:39 -04:00
|
|
|
* @param mixed $resource the resource variable to check
|
2024-04-09 03:59:23 -04:00
|
|
|
* @psalm-assert-if-true object $resource
|
2021-10-26 10:43:39 -04:00
|
|
|
* @return bool true if it is a resource or LDAP object, false otherwise
|
2013-08-20 08:23:49 -04:00
|
|
|
*/
|
|
|
|
|
public function isResource($resource);
|
2013-09-11 13:42:08 -04:00
|
|
|
}
|