Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MDL-12323 MDL-4061 Don't connect to the LDAP server if update externa…
…l is not set for any field.
  • Loading branch information
iarenaza committed Dec 28, 2007
1 parent 90dc0f3 commit 8a60457
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions auth/ldap/auth.php
Expand Up @@ -835,14 +835,28 @@ function user_update($olduser, $newuser) {
return true; // just change auth and skip update return true; // just change auth and skip update
} }


$attrmap = $this->ldap_attributes();

// Before doing anything else, make sure really need to update anything
// in the external LDAP server.
$update_external = false;
foreach ($attrmap as $key => $ldapkeys) {
if (!empty($this->config->{'field_updateremote_'.$key})) {
$update_external = true;
break;
}
}
if (!$update_external) {
return true;
}

$textlib = textlib_get_instance(); $textlib = textlib_get_instance();
$extoldusername = $textlib->convert($olduser->username, 'utf-8', $this->config->ldapencoding); $extoldusername = $textlib->convert($olduser->username, 'utf-8', $this->config->ldapencoding);


$ldapconnection = $this->ldap_connect(); $ldapconnection = $this->ldap_connect();


$search_attribs = array(); $search_attribs = array();


$attrmap = $this->ldap_attributes();
foreach ($attrmap as $key => $values) { foreach ($attrmap as $key => $values) {
if (!is_array($values)) { if (!is_array($values)) {
$values = array($values); $values = array($values);
Expand All @@ -863,9 +877,16 @@ function user_update($olduser, $newuser) {


$user_entry = $this->ldap_get_entries($ldapconnection, $user_info_result); $user_entry = $this->ldap_get_entries($ldapconnection, $user_info_result);
if (empty($user_entry)) { if (empty($user_entry)) {
$error = 'ldap: Could not find user while updating externally. '.
'Details follow: search base: \''.$user_dn.'\'; search filter: \''.
$this->config->objectclass.'\'; search attributes: ';
foreach ($search_attribs as $attrib) {
$error .= $attrib.' ';
}
error_log($error);
return false; // old user not found! return false; // old user not found!
} else if (count($user_entry) > 1) { } else if (count($user_entry) > 1) {
trigger_error("ldap: Strange! More than one user record found in ldap. Only using the first one."); error_log('ldap: Strange! More than one user record found in ldap. Only using the first one.');
return false; return false;
} }
$user_entry = $user_entry[0]; $user_entry = $user_entry[0];
Expand Down

0 comments on commit 8a60457

Please sign in to comment.