From 4a5cecd6fa64b33a63c39d289565837e6d8ac340 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 7 Oct 2015 18:57:49 +0200 Subject: [PATCH] allow an attribute to return more than one value --- apps/user_ldap/lib/access.php | 41 +++++++++++------------------------ apps/user_ldap/lib/wizard.php | 2 +- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/apps/user_ldap/lib/access.php b/apps/user_ldap/lib/access.php index a2fdd88a24..c7ec06f356 100644 --- a/apps/user_ldap/lib/access.php +++ b/apps/user_ldap/lib/access.php @@ -710,6 +710,9 @@ class Access extends LDAPUtility implements user\IUserTools { if($manyAttributes) { return $list; } else { + $list = array_reduce($list, function($carry, $item) { + $carry[] = $item[0]; + }, array()); return array_unique($list, SORT_LOCALE_STRING); } } @@ -982,44 +985,26 @@ class Access extends LDAPUtility implements user\IUserTools { 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($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; } diff --git a/apps/user_ldap/lib/wizard.php b/apps/user_ldap/lib/wizard.php index 18a0412a63..a8fcae6314 100644 --- a/apps/user_ldap/lib/wizard.php +++ b/apps/user_ldap/lib/wizard.php @@ -435,7 +435,7 @@ class Wizard extends LDAPUtility { // detection will fail later $result = $this->access->searchGroups($filter, array('cn', 'dn'), $limit, $offset); foreach($result as $item) { - $groupNames[] = $item['cn']; + $groupNames[] = $item['cn'][0]; $groupEntries[] = $item; } $offset += $limit;