From ea759d53644fc3063420dd64998511305a592529 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Wed, 19 Jan 2011 11:53:04 +0000
Subject: [PATCH] ldap:AttributeAddFromLDAP: Extract attributes from multiple
 hits.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

If there are several entries that matches the search, we should
extract the values from all of them.

Thanks to Stéphane Gully for providing this patch!

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2719 44740490-163a-0410-bde0-09ae8108e29a
---
 modules/ldap/lib/Auth/Process/AttributeAddFromLDAP.php | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/modules/ldap/lib/Auth/Process/AttributeAddFromLDAP.php b/modules/ldap/lib/Auth/Process/AttributeAddFromLDAP.php
index ed0cd81ae..fc08fb3c7 100644
--- a/modules/ldap/lib/Auth/Process/AttributeAddFromLDAP.php
+++ b/modules/ldap/lib/Auth/Process/AttributeAddFromLDAP.php
@@ -218,10 +218,12 @@ class sspmod_ldap_Auth_Process_AttributeAddFromLDAP extends SimpleSAML_Auth_Proc
 
 		// handle [multiple] values
 		if(is_array($entries) && is_array($entries[0])){
-			$entry = $entries[0][strtolower($this->config['ldap_search_attribute'])];
 			$results = array();
-			for($i = 0; $i < $entry['count']; $i++){
-				$results[] = $entry[$i];
+			foreach($entries as $entry){
+				$entry = $entry[strtolower($this->config['ldap_search_attribute'])];
+				for($i = 0; $i < $entry['count']; $i++){
+					$results[] = $entry[$i];
+				}
 			}
 			$attributes[$this->config['new_attribute_name']] = array_values($results);
 		}
-- 
GitLab