From 38547ff4eda0640b95cbc1429d6b403b8c59deca Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Mon, 22 Sep 2008 05:57:43 +0000
Subject: [PATCH] login-radius: Handle multivalued attributes

This commit makes login-radius properly handle multiple attributes with
the same name.

Original patch from Stefan Winter.


git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@884 44740490-163a-0410-bde0-09ae8108e29a
---
 www/auth/login-radius.php | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/www/auth/login-radius.php b/www/auth/login-radius.php
index 2047a0e79..af9d9686a 100644
--- a/www/auth/login-radius.php
+++ b/www/auth/login-radius.php
@@ -70,12 +70,20 @@ if (isset($_POST['username'])) {
 							/**
 							 * Uncomment this to debug vendor attributes.
 							 */
-							// printf("Got Vendor Attr:%d %d Bytes %s\n", $attrv, strlen($datav), bin2hex($datav));
+							// printf("Got Vendor Attr:%d %d Bytes %s<br/>", $attrv, strlen($datav), bin2hex($datav));
 							
-							if ($vendor == $config->getValue('auth.radius.vendor') && $attrv == $config->getValue('auth.radius.vendor-attr'))
-							   $attrib_name  = strtok ($datav,'=');
-							   $attrib_value = strtok ('=');
-							   $attributes = $attributes + array($attrib_name => array($attrib_value));
+							if ($vendor == $config->getValue('auth.radius.vendor') && $attrv == $config->getValue('auth.radius.vendor-attr')) {
+
+								$attrib_name  = strtok ($datav,'=');
+								$attrib_value = strtok ('=');
+
+								// if the attribute name is already in result set, add another value
+								if (array_key_exists($attrib_name, $attributes)) {
+									$attributes[$attrib_name][] = $attrib_value;
+								} else {
+									$attributes[$attrib_name] = array($attrib_value);
+								}
+							}
 						}
 					}
 				}
-- 
GitLab