Skip to content
Snippets Groups Projects
Commit ad986597 authored by Olav Morken's avatar Olav Morken
Browse files

Cleaned up ldap loop.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@93 44740490-163a-0410-bde0-09ae8108e29a
parent 6e71d6e2
No related branches found
No related tags found
No related merge requests found
...@@ -56,22 +56,49 @@ if (isset($_POST['username'])) { ...@@ -56,22 +56,49 @@ if (isset($_POST['username'])) {
} else { } else {
$sr = ldap_read($ds, $dn, $config->getValue('auth.ldap.attributes')); $sr = ldap_read($ds, $dn, $config->getValue('auth.ldap.attributes'));
$ldapentries = ldap_get_entries($ds, $sr); $ldapentries = ldap_get_entries($ds, $sr);
/* Check if we have any entries in the search result.
*/
if($ldapentries['count'] == 0) {
throw new Exception('LDAP: No entries in the' .
' search result.');
}
/* Currently we only care about the first entry. We
* write a message to the error log if we have more.
*/
if($ldapentries['count'] > 1) {
error_log('LDAP: we have more than one entry' .
' in the search result.');
}
/* Iterate over all the attributes in the first
* result. $ldapentries[0]['count'] contains the
* attribute count, while $ldapentries[0][$i]
* contains the name of the $i'th attribute.
*/
for ($i = 0; $i < $ldapentries[0]['count']; $i++) { for ($i = 0; $i < $ldapentries[0]['count']; $i++) {
$name = $ldapentries[0][$i];
/* We currently ignore the 'jpegphoto'
* attribute since it is relatively big.
*/
if ($name === 'jpegphoto') {
continue;
}
$attribute = $ldapentries[0][$name];
$values = array(); $values = array();
if ($ldapentries[0][$i] == 'jpegphoto') continue;
for ($j = 0; $j < $ldapentries[0][$ldapentries[0][$i]]['count']; $j++) { for ($j = 0; $j < $attribute['count']; $j++) {
$values[] = $ldapentries[0][$ldapentries[0][$i]][$j]; $values[] = $attribute[$j];
} }
$attributes[$ldapentries[0][$i]] = $values; assert(!array_key_exists($name, $attributes));
$attributes[$name] = $values;
} }
// generelt ldap_next_entry for flere, men bare ett her
//print_r($ldapentries);
//print_r($attributes);
$session->setAuthenticated(true); $session->setAuthenticated(true);
$session->setAttributes($attributes); $session->setAttributes($attributes);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment