Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions apps/user_ldap/group_ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public function primaryGroupID2Name($gid, $dn) {
if(empty($result)) {
return false;
}
$dn = $result[0];
$dn = $result[0]['dn'][0];

//and now the group name
//NOTE once we have separate ownCloud group IDs and group names we can
Expand Down Expand Up @@ -491,7 +491,7 @@ private function getGroupsByMember($dn, &$seen = null) {
array($this->access->connection->ldapGroupDisplayName, 'dn'));
if (is_array($groups)) {
foreach ($groups as $groupobj) {
$groupDN = $groupobj['dn'];
$groupDN = $groupobj['dn'][0];
$allGroups[$groupDN] = $groupobj;
$nestedGroups = $this->access->connection->ldapNestedGroups;
if (!empty($nestedGroups)) {
Expand Down Expand Up @@ -653,7 +653,7 @@ public function countUsersInGroup($gid, $search = '') {
str_replace('%uid', $member, $this->access->connection->ldapLoginFilter),
$this->access->getFilterPartForUserSearch($search)
));
$ldap_users = $this->access->fetchListOfUsers($filter, 'dn');
$ldap_users = $this->access->fetchListOfUsers($filter, 'dn', 1);
if(count($ldap_users) < 1) {
continue;
}
Expand Down
70 changes: 35 additions & 35 deletions apps/user_ldap/lib/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ public function dn2ocname($fdn, $ldapName = null, $isUser = true) {

/**
* gives back the user names as they are used ownClod internally
* @param array $ldapUsers an array with the ldap Users result in style of array ( array ('dn' => foo, 'uid' => bar), ... )
* @param array $ldapUsers as returned by fetchList()
* @return array an array with the user names to use in ownCloud
*
* gives back the user names as they are used ownClod internally
Expand All @@ -500,7 +500,7 @@ public function ownCloudUserNames($ldapUsers) {

/**
* gives back the group names as they are used ownClod internally
* @param array $ldapGroups an array with the ldap Groups result in style of array ( array ('dn' => foo, 'cn' => bar), ... )
* @param array $ldapGroups as returned by fetchList()
* @return array an array with the group names to use in ownCloud
*
* gives back the group names as they are used ownClod internally
Expand All @@ -510,7 +510,7 @@ public function ownCloudGroupNames($ldapGroups) {
}

/**
* @param array $ldapObjects
* @param array $ldapObjects as returned by fetchList()
* @param bool $isUsers
* @return array
*/
Expand All @@ -523,15 +523,25 @@ private function ldap2ownCloudNames($ldapObjects, $isUsers) {
$ownCloudNames = array();

foreach($ldapObjects as $ldapObject) {
$nameByLDAP = isset($ldapObject[$nameAttribute]) ? $ldapObject[$nameAttribute] : null;
$ocName = $this->dn2ocname($ldapObject['dn'], $nameByLDAP, $isUsers);
$nameByLDAP = null;
if( isset($ldapObject[$nameAttribute])
&& is_array($ldapObject[$nameAttribute])
&& isset($ldapObject[$nameAttribute][0])
) {
// might be set, but not necessarily. if so, we use it.
$nameByLDAP = $ldapObject[$nameAttribute][0];
}

$ocName = $this->dn2ocname($ldapObject['dn'][0], $nameByLDAP, $isUsers);
if($ocName) {
$ownCloudNames[] = $ocName;
if($isUsers) {
//cache the user names so it does not need to be retrieved
//again later (e.g. sharing dialogue).
$this->cacheUserExists($ocName);
$this->cacheUserDisplayName($ocName, $nameByLDAP);
if(!is_null($nameByLDAP)) {
$this->cacheUserDisplayName($ocName, $nameByLDAP);
}
}
}
continue;
Expand Down Expand Up @@ -682,7 +692,7 @@ public function fetchListOfUsers($filter, $attr, $limit = null, $offset = null)
*/
public function batchApplyUserAttributes(array $ldapRecords){
foreach($ldapRecords as $userRecord) {
$ocName = $this->dn2ocname($userRecord['dn'], $userRecord[$this->connection->ldapUserDisplayName]);
$ocName = $this->dn2ocname($userRecord['dn'][0], $userRecord[$this->connection->ldapUserDisplayName]);
$this->cacheUserExists($ocName);
$user = $this->userManager->get($ocName);
$user->processAttributes($userRecord);
Expand Down Expand Up @@ -710,6 +720,11 @@ private function fetchList($list, $manyAttributes) {
if($manyAttributes) {
return $list;
} else {
$list = array_reduce($list, function($carry, $item) {
$attribute = array_keys($item)[0];
$carry[] = $item[$attribute][0];
return $carry;
}, array());
return array_unique($list, SORT_LOCALE_STRING);
}
}
Expand Down Expand Up @@ -982,44 +997,29 @@ private function search($filter, $base, $attr = null, $limit = null, $offset = n

if(!is_null($attr)) {
$selection = array();
$multiArray = false;
if(count($attr) > 1) {
$multiArray = true;
$i = 0;
}
$i = 0;
foreach($findings as $item) {
if(!is_array($item)) {
continue;
}
$item = \OCP\Util::mb_array_change_key_case($item, MB_CASE_LOWER, 'UTF-8');

if($multiArray) {
foreach($attr as $key) {
$key = mb_strtolower($key, 'UTF-8');
if(isset($item[$key])) {
if($key !== 'dn') {
$selection[$i][$key] = $this->resemblesDN($key) ?
$this->sanitizeDN($item[$key][0])
: $item[$key][0];
} else {
$selection[$i][$key] = $this->sanitizeDN($item[$key]);
}
}

}
$i++;
} else {
//tribute to case insensitivity
$key = mb_strtolower($attr[0], 'UTF-8');

foreach($attr as $key) {
$key = mb_strtolower($key, 'UTF-8');
if(isset($item[$key])) {
if($this->resemblesDN($key)) {
$selection[] = $this->sanitizeDN($item[$key]);
if(is_array($item[$key]) && isset($item[$key]['count'])) {
unset($item[$key]['count']);
}
if($key !== 'dn') {
$selection[$i][$key] = $this->resemblesDN($key) ?
$this->sanitizeDN($item[$key])
: $item[$key];
} else {
$selection[] = $item[$key];
$selection[$i][$key] = [$this->sanitizeDN($item[$key])];
}
}

}
$i++;
}
$findings = $selection;
}
Expand Down
17 changes: 10 additions & 7 deletions apps/user_ldap/lib/user/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,21 @@ public function processAttributes($ldapEntry) {
//Quota
$attr = strtolower($this->connection->ldapQuotaAttribute);
if(isset($ldapEntry[$attr])) {
$this->updateQuota($ldapEntry[$attr]);
$this->updateQuota($ldapEntry[$attr][0]);
}
unset($attr);

//Email
$attr = strtolower($this->connection->ldapEmailAttribute);
if(isset($ldapEntry[$attr])) {
$this->updateEmail($ldapEntry[$attr]);
$this->updateEmail($ldapEntry[$attr][0]);
}
unset($attr);

//displayName
$attr = strtolower($this->connection->ldapUserDisplayName);
if(isset($ldapEntry[$attr])) {
$displayName = $ldapEntry[$attr];
$displayName = $ldapEntry[$attr][0];
if(!empty($displayName)) {
$this->storeDisplayName($displayName);
$this->access->cacheUserDisplayName($this->getUsername(), $displayName);
Expand All @@ -171,30 +171,33 @@ public function processAttributes($ldapEntry) {

// LDAP Username, needed for s2s sharing
if(isset($ldapEntry['uid'])) {
$this->storeLDAPUserName($ldapEntry['uid']);
$this->storeLDAPUserName($ldapEntry['uid'][0]);
} else if(isset($ldapEntry['samaccountname'])) {
$this->storeLDAPUserName($ldapEntry['samaccountname']);
$this->storeLDAPUserName($ldapEntry['samaccountname'][0]);
}

//homePath
if(strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
$attr = strtolower(substr($this->connection->homeFolderNamingRule, strlen('attr:')));
if(isset($ldapEntry[$attr])) {
$this->access->cacheUserHome(
$this->getUsername(), $this->getHomePath($ldapEntry[$attr]));
$this->getUsername(), $this->getHomePath($ldapEntry[$attr][0]));
}
}

//memberOf groups
$cacheKey = 'getMemberOf'.$this->getUsername();
$groups = false;
if(isset($ldapEntry['memberof'])) {
$groups = $ldapEntry['memberof'];
}
$this->connection->writeToCache($cacheKey, $groups);

//Avatar
$attrs = array('jpegphoto', 'thumbnailphoto');
foreach ($attrs as $attr) {
if(isset($ldapEntry[$attr])) {
$this->avatarImage = $ldapEntry[$attr];
$this->avatarImage = $ldapEntry[$attr][0];
$this->updateAvatar();
break;
}
Expand Down
6 changes: 5 additions & 1 deletion apps/user_ldap/lib/wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,11 @@ public function fetchGroups($dbKey, $confKey) {
// detection will fail later
$result = $this->access->searchGroups($filter, array('cn', 'dn'), $limit, $offset);
foreach($result as $item) {
$groupNames[] = $item['cn'];
if(!isset($item['cn']) && !is_array($item['cn']) && !isset($item['cn'][0])) {
// just in case - no issue known
continue;
}
$groupNames[] = $item['cn'][0];
$groupEntries[] = $item;
}
$offset += $limit;
Expand Down
4 changes: 2 additions & 2 deletions apps/user_ldap/tests/group_ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function testPrimaryGroupID2NameSuccess() {

$access->expects($this->once())
->method('searchGroups')
->will($this->returnValue(array('cn=foo,dc=barfoo,dc=bar')));
->will($this->returnValue([['dn' => ['cn=foo,dc=barfoo,dc=bar']]]));

$access->expects($this->once())
->method('dn2groupname')
Expand Down Expand Up @@ -221,7 +221,7 @@ public function testPrimaryGroupID2NameNoName() {

$access->expects($this->once())
->method('searchGroups')
->will($this->returnValue(array('cn=foo,dc=barfoo,dc=bar')));
->will($this->returnValue([['dn' => ['cn=foo,dc=barfoo,dc=bar']]]));

$access->expects($this->once())
->method('dn2groupname')
Expand Down
4 changes: 2 additions & 2 deletions apps/user_ldap/tests/user_ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private function prepareAccessForCheckPassword(&$access, $noDisplayName = false)
->method('fetchListOfUsers')
->will($this->returnCallback(function($filter) {
if($filter === 'roland') {
return array(array('dn' => 'dnOfRoland,dc=test'));
return array(array('dn' => ['dnOfRoland,dc=test']));
}
return array();
}));
Expand All @@ -133,7 +133,7 @@ private function prepareAccessForCheckPassword(&$access, $noDisplayName = false)
->method('fetchUsersByLoginName')
->will($this->returnCallback(function($uid) {
if($uid === 'roland') {
return array(array('dn' => 'dnOfRoland,dc=test'));
return array(array('dn' => ['dnOfRoland,dc=test']));
}
return array();
}));
Expand Down
4 changes: 2 additions & 2 deletions apps/user_ldap/user_ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function canChangeAvatar($uid) {
public function loginName2UserName($loginName) {
try {
$ldapRecord = $this->getLDAPUserByLoginName($loginName);
$user = $this->access->userManager->get($ldapRecord['dn']);
$user = $this->access->userManager->get($ldapRecord['dn'][0]);
if($user instanceof OfflineUser) {
return false;
}
Expand Down Expand Up @@ -119,7 +119,7 @@ public function checkPassword($uid, $password) {
} catch(\Exception $e) {
return false;
}
$dn = $ldapRecord['dn'];
$dn = $ldapRecord['dn'][0];
$user = $this->access->userManager->get($dn);

if(!$user instanceof User) {
Expand Down