Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix PHP 8.1 support for user_ldap application
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Dec 16, 2021
commit f3dcbfe146782d2c7dec8760651e79605ddc96e7
8 changes: 4 additions & 4 deletions apps/user_ldap/lib/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public function readAttribute($dn, $attr, $filter = 'objectClass=*') {
/**
* Runs an read operation against LDAP
*
* @param resource $cr the LDAP connection
* @param resource|\LDAP\Connection $cr the LDAP connection
* @param string $dn
* @param string $attribute
* @param string $filter
Expand Down Expand Up @@ -926,7 +926,7 @@ public function fetchListOfUsers(string $filter, array $attr, int $limit = null,
* @throws \Exception
*/
public function batchApplyUserAttributes(array $ldapRecords) {
$displayNameAttribute = strtolower($this->connection->ldapUserDisplayName);
$displayNameAttribute = strtolower((string)$this->connection->ldapUserDisplayName);
foreach ($ldapRecords as $userRecord) {
if (!isset($userRecord[$displayNameAttribute])) {
// displayName is obligatory
Expand Down Expand Up @@ -1186,7 +1186,7 @@ private function executeSearch(
/**
* processes an LDAP paged search operation
*
* @param resource $sr the array containing the LDAP search resources
* @param resource|\LDAP\Result|resource[]|\LDAP\Result[] $sr the array containing the LDAP search resources
* @param int $foundItems number of results in the single search operation
* @param int $limit maximum results to be counted
* @param bool $pagedSearchOK whether a paged search has been executed
Expand Down Expand Up @@ -1303,7 +1303,7 @@ private function count(
}

/**
* @param resource $sr
* @param resource|\LDAP\Result|resource[]|\LDAP\Result[] $sr
* @return int
* @throws ServerNotAvailableException
*/
Expand Down
9 changes: 6 additions & 3 deletions apps/user_ldap/lib/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
* @property string ldapMatchingRuleInChainState
*/
class Connection extends LDAPUtility {
/**
* @var resource|\LDAP\Connection|null
*/
private $ldapConnectionRes = null;
private $configPrefix;
private $configID;
Expand Down Expand Up @@ -202,7 +205,7 @@ public function init($force = false) {
}

/**
* Returns the LDAP handler
* @return resource|\LDAP\Connection The LDAP resource
*/
public function getConnectionResource() {
if (!$this->ldapConnectionRes) {
Expand Down Expand Up @@ -408,7 +411,7 @@ private function doSoftValidation() {
}
}

if ((stripos($this->configuration->ldapHost, 'ldaps://') === 0)
if ((stripos((string)$this->configuration->ldapHost, 'ldaps://') === 0)
&& $this->configuration->ldapTLS) {
$this->configuration->ldapTLS = false;
$this->logger->info(
Expand Down Expand Up @@ -487,7 +490,7 @@ private function doCriticalValidation() {
$configurationOK = false;
}

if (mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8')
if (mb_strpos((string)$this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8')
=== false) {
$this->logger->warning(
$errorStr.'login filter does not contain %uid place holder.',
Expand Down
6 changes: 3 additions & 3 deletions apps/user_ldap/lib/Group_LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function __construct(Access $access, GroupPluginManager $groupPluginManag
$this->cachedNestedGroups = new CappedMemoryCache();
$this->groupPluginManager = $groupPluginManager;
$this->logger = OC::$server->get(LoggerInterface::class);
$this->ldapGroupMemberAssocAttr = strtolower($gAssoc);
$this->ldapGroupMemberAssocAttr = strtolower((string)$gAssoc);
}

/**
Expand Down Expand Up @@ -202,7 +202,7 @@ public function inGroup($uid, $gid) {
* @throws ServerNotAvailableException
*/
public function getDynamicGroupMembers(string $dnGroup): array {
$dynamicGroupMemberURL = strtolower($this->access->connection->ldapDynamicGroupMemberURL);
$dynamicGroupMemberURL = strtolower((string)$this->access->connection->ldapDynamicGroupMemberURL);

if (empty($dynamicGroupMemberURL)) {
return [];
Expand Down Expand Up @@ -1312,7 +1312,7 @@ public function getGroupDetails($gid) {
* of the current access.
*
* @param string $gid
* @return resource of the LDAP connection
* @return resource|\LDAP\Connection The LDAP connection
* @throws ServerNotAvailableException
*/
public function getNewLDAPConnection($gid) {
Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/Group_Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public function getLDAPAccess($gid) {
* The connection needs to be closed manually.
*
* @param string $gid
* @return resource of the LDAP connection
* @return resource|\LDAP\Connection The LDAP connection
*/
public function getNewLDAPConnection($gid) {
return $this->handleRequest($gid, 'getNewLDAPConnection', [$gid]);
Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/IGroupLDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getLDAPAccess($gid);
/**
* Return a new LDAP connection for the specified group.
* @param string $gid
* @return resource of the LDAP connection
* @return resource|\LDAP\Connection The LDAP connection
*/
public function getNewLDAPConnection($gid);
}
60 changes: 30 additions & 30 deletions apps/user_ldap/lib/ILDAPWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface ILDAPWrapper {

/**
* Bind to LDAP directory
* @param resource $link LDAP link resource
* @param resource|\LDAP\Connection $link LDAP link resource
* @param string $dn an RDN to log in with
* @param string $password the password
* @return bool true on success, false otherwise
Expand All @@ -54,7 +54,7 @@ public function connect($host, $port);

/**
* Send LDAP pagination control
* @param resource $link LDAP link resource
* @param resource|\LDAP\Connection $link LDAP link resource
* @param int $pageSize number of results per page
* @param bool $isCritical Indicates whether the pagination is critical of not.
* @param string $cookie structure sent by LDAP server
Expand All @@ -64,8 +64,8 @@ public function controlPagedResult($link, $pageSize, $isCritical);

/**
* Retrieve the LDAP pagination cookie
* @param resource $link LDAP link resource
* @param resource $result LDAP result resource
* @param resource|\LDAP\Connection $link LDAP link resource
* @param resource|\LDAP\Result $result LDAP result resource
* @param string $cookie structure sent by LDAP server
* @return bool true on success, false otherwise
*
Expand All @@ -75,22 +75,22 @@ public function controlPagedResultResponse($link, $result, &$cookie);

/**
* Count the number of entries in a search
* @param resource $link LDAP link resource
* @param resource $result LDAP result resource
* @param resource|\LDAP\Connection $link LDAP link resource
* @param resource|\LDAP\Result $result LDAP result resource
* @return int|false number of results on success, false otherwise
*/
public function countEntries($link, $result);

/**
* Return the LDAP error number of the last LDAP command
* @param resource $link LDAP link resource
* @param resource|\LDAP\Connection $link LDAP link resource
* @return int error code
*/
public function errno($link);

/**
* Return the LDAP error message of the last LDAP command
* @param resource $link LDAP link resource
* @param resource|\LDAP\Connection $link LDAP link resource
* @return string error message
*/
public function error($link);
Expand All @@ -106,69 +106,69 @@ public function explodeDN($dn, $withAttrib);

/**
* Return first result id
* @param resource $link LDAP link resource
* @param resource $result LDAP result resource
* @return Resource an LDAP search result resource
* @param resource|\LDAP\Connection $link LDAP link resource
* @param resource|\LDAP\Result $result LDAP result resource
* @return resource|\LDAP\ResultEntry an LDAP entry resource
* */
public function firstEntry($link, $result);

/**
* Get attributes from a search result entry
* @param resource $link LDAP link resource
* @param resource $result LDAP result resource
* @param resource|\LDAP\Connection $link LDAP link resource
* @param resource|\LDAP\ResultEntry $result LDAP result resource
* @return array containing the results, false on error
* */
public function getAttributes($link, $result);

/**
* Get the DN of a result entry
* @param resource $link LDAP link resource
* @param resource $result LDAP result resource
* @param resource|\LDAP\Connection $link LDAP link resource
* @param resource|\LDAP\ResultEntry $result LDAP result resource
* @return string containing the DN, false on error
*/
public function getDN($link, $result);

/**
* Get all result entries
* @param resource $link LDAP link resource
* @param resource $result LDAP result resource
* @param resource|\LDAP\Connection $link LDAP link resource
* @param resource|\LDAP\Result $result LDAP result resource
* @return array containing the results, false on error
*/
public function getEntries($link, $result);

/**
* Return next result id
* @param resource $link LDAP link resource
* @param resource $result LDAP entry result resource
* @return resource an LDAP search result resource
* @param resource|\LDAP\Connection $link LDAP link resource
* @param resource|\LDAP\ResultEntry $result LDAP result resource
* @return resource|\LDAP\ResultEntry an LDAP entry resource
* */
public function nextEntry($link, $result);

/**
* Read an entry
* @param resource $link LDAP link resource
* @param resource|\LDAP\Connection $link LDAP link resource
* @param array $baseDN The DN of the entry to read from
* @param string $filter An LDAP filter
* @param array $attr array of the attributes to read
* @return resource an LDAP search result resource
* @return resource|\LDAP\Result an LDAP search result resource
*/
public function read($link, $baseDN, $filter, $attr);

/**
* Search LDAP tree
* @param resource $link LDAP link resource
* @param resource|\LDAP\Connection $link LDAP link resource
* @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
* @return resource|false an LDAP search result resource, false on error
* @return resource|\LDAP\Result|false an LDAP search result resource, false on error
*/
public function search($link, $baseDN, $filter, $attr, $attrsOnly = 0, $limit = 0);

/**
* Replace the value of a userPassword by $password
* @param resource $link LDAP link resource
* @param resource|\LDAP\Connection $link LDAP link resource
* @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
Expand All @@ -177,7 +177,7 @@ public function modReplace($link, $userDN, $password);

/**
* Sets the value of the specified option to be $value
* @param resource $link LDAP link resource
* @param resource|\LDAP\Connection $link LDAP link resource
* @param string $option a defined LDAP Server option
* @param int $value the new value for the option
* @return bool true on success, false otherwise
Expand All @@ -186,14 +186,14 @@ public function setOption($link, $option, $value);

/**
* establish Start TLS
* @param resource $link LDAP link resource
* @param resource|\LDAP\Connection $link LDAP link resource
* @return bool true on success, false otherwise
*/
public function startTls($link);

/**
* Unbind from LDAP directory
* @param resource $link LDAP link resource
* @param resource|\LDAP\Connection $link LDAP link resource
* @return bool true on success, false otherwise
*/
public function unbind($link);
Expand All @@ -208,8 +208,8 @@ public function areLDAPFunctionsAvailable();

/**
* Checks whether the submitted parameter is a resource
* @param resource $resource the resource variable to check
* @return bool true if it is a resource, false otherwise
* @param mixed $resource the resource variable to check
* @return bool true if it is a resource or LDAP object, false otherwise
*/
public function isResource($resource);
}
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/IUserLDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getLDAPAccess($uid);
/**
* Return a new LDAP connection for the specified user.
* @param string $uid
* @return resource of the LDAP connection
* @return resource|\LDAP\Connection of the LDAP connection
*/
public function getNewLDAPConnection($uid);

Expand Down
Loading