From d32ec43e5063a5a8ea19054ed07a2331ccf99008 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no>
Date: Sun, 11 Jan 2009 14:08:11 +0000
Subject: [PATCH] LDAP class may limit size on allowed attributes

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1139 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Auth/LDAP.php | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/lib/SimpleSAML/Auth/LDAP.php b/lib/SimpleSAML/Auth/LDAP.php
index b9e3043e7..c2bc9ebd7 100644
--- a/lib/SimpleSAML/Auth/LDAP.php
+++ b/lib/SimpleSAML/Auth/LDAP.php
@@ -126,7 +126,7 @@ class SimpleSAML_Auth_LDAP {
 	/**
 	 * Search DN for attributes, and return associative array.
 	 */
-	public function getAttributes($dn, $attributes = null) {
+	public function getAttributes($dn, $attributes = NULL, $maxsize = NULL) {
 	
 		$searchtxt = (is_array($attributes) ? join(',', $attributes) : 'all attributes');
 		SimpleSAML_Logger::debug('Library - LDAP: Get attributes from ' . $dn . ' (' . $searchtxt . ')');
@@ -156,6 +156,7 @@ class SimpleSAML_Auth_LDAP {
 			$attributeName = $ldapAttributes[$i];
 
 			$base64encode = FALSE;
+			$include = FALSE;
 			
 			if (strtolower($attributeName) === 'jpegphoto') {
 				$base64encode = TRUE;
@@ -166,10 +167,17 @@ class SimpleSAML_Auth_LDAP {
 
 			$values = array();
 			for ($j = 0; $j < $valueCount; $j++) {
-				$values[] = ($base64encode ? base64_encode($attribute[$j]) : $attribute[$j] );
-			}
+				/*
+				SimpleSAML_Logger::debug('Library - attribute size of [' . $attributeName . '] (' . strlen($attribute[$j]) . ' of ' . 
+					(is_null($maxsize) ? 'NA'  : $maxsize) . ')');
+				*/
+				if (is_null($maxsize) or strlen($attribute[$j]) < $maxsize) {
+					$include = TRUE;
+					$values[] = ($base64encode ? base64_encode($attribute[$j]) : $attribute[$j] );
+				}
 
-			$attributes[$attributeName] = $values;
+			}
+			if ($include) $attributes[$attributeName] = $values;
 		}
 		
 		SimpleSAML_Logger::debug('Library - LDAP: Found attributes (' . join(',', array_keys($attributes)) . ')');
-- 
GitLab