$result[$key] = $ldapval;
}
}
- @ldap_close($ldapconnection);
+ $this->ldap_close($ldapconnection);
return $result;
}
/**
* @return connection result
*/
function ldap_connect($binddn='',$bindpwd='') {
+ // Cache ldap connections (they are expensive to set up
+ // and can drain the TCP/IP ressources on the server if we
+ // are syncing a lot of users (as we try to open a new connection
+ // to get the user details). This is the least invasive way
+ // to reuse existing connections without greater code surgery.
+ if(!empty($this->ldapconnection)) {
+ $this->ldapconns++;
+ return $this->ldapconnection;
+ }
+
//Select bind password, With empty values use
//ldap_bind_* variables or anonymous bind if ldap_bind_* are empty
if ($binddn == '' and $bindpwd == '') {
ldap_set_option($connresult, LDAP_OPT_DEREF, $this->config->opt_deref);
}
if ($bindresult) {
+ // Set the connection counter so we can call PHP's ldap_close()
+ // when we call $this->ldap_close() for the last 'open' connection.
+ $this->ldapconns = 1;
+ $this->ldapconnection = $connresult;
return $connresult;
}
$debuginfo .= "<br/>Server: '$server' <br/> Connection: '$connresult'<br/> Bind result: '$bindresult'</br>";
print_error('auth_ldap_noconnect_all','auth',$this->config->user_type);
return false;
}
+ /**
+ * disconnects from a ldap server
+ *
+ */
+ function ldap_close() {
+ $this->ldapconns--;
+ if($this->ldapconns == 0) {
+ @ldap_close($this->ldapconnection);
+ unset($this->ldapconnection);
+ }
+ }
+
/**
* retuns user attribute mappings between moodle and ldap
*
$ldapconnection = $this->ldap_connect();
if (!$ldapconnection) {
- @ldap_close($ldapconnection);
+ $this->ldap_close($ldapconnection);
print get_string('auth_ldap_noconnect','auth',$this->config->host_url);
exit;
}
}
$dbman->drop_temp_table($table);
+ $this->ldap_close();
return true;
}
}
}
}
+ $this->ldap_close();
return $result;
}
/**
array_push($fresult, ($users[$i][$this->config->user_attribute][0]) );
}
}
+ $this->ldap_close();
return $fresult;
}
/**
if ($this->ldap_find_userdn($ldapconnection, $extusername)) {
$validuser = true;
}
- ldap_close($ldapconnection);
+ $this->ldap_close();
}
// Shortcut here - SSO confirmed
//if ldap_user_dn is empty, user does not exist
if (!$ldap_user_dn) {
- ldap_close($ldapconnection);
+ $this->ldap_close();
return false;
}
// Try to bind with current username and password
$ldap_login = @ldap_bind($ldapconnection, $ldap_user_dn, $extpassword);
- ldap_close($ldapconnection);
+ $this->ldap_close();
if ($ldap_login) {
return true;
}
}
else {
- @ldap_close($ldapconnection);
+ $this->ldap_close();
print_error('auth_ldap_noconnect','auth','',$this->config->host_url);
}
return false;
}
}
- @ldap_close($ldapconnection);
+ $this->ldap_close();
return $result;
}
default:
print_error('auth_ldap_unsupportedusertype','auth','',$this->config->user_type);
}
- ldap_close($ldapconnection);
+ $this->ldap_close();
return $uadd;
}
$ldapconnection = $this->ldap_connect();
if (!$ldapconnection) {
- @ldap_close($ldapconnection);
+ $this->ldap_close();
print get_string('auth_ldap_noconnect','auth',$this->config->host_url);
exit;
}
}
$dbman->drop_temp_table($table);
+ $this->ldap_close();
return true;
}
print_error('user_activatenotsupportusertype', 'auth', '', $this->config->user_type);
}
$result = ldap_modify($ldapconnection, $userdn, $newinfo);
- ldap_close($ldapconnection);
+ $this->ldap_close();
return $result;
}
print_error('user_disablenotsupportusertype', 'auth');
}
$result = ldap_modify($ldapconnection, $userdn, $newinfo);
- ldap_close($ldapconnection);
+ $this->ldap_close();
return $result;
}*/
}
} else {
error_log("ERROR:No user found in LDAP");
- @ldap_close($ldapconnection);
+ $this->ldap_close();
return false;
}
- @ldap_close($ldapconnection);
+ $this->ldap_close();
return true;
}
- @ldap_close($ldapconnection);
+ $this->ldap_close();
return $result;
}
* @return connection result
*/
function ldap_connect($binddn='',$bindpwd='') {
+ // Cache ldap connections (they are expensive to set up
+ // and can drain the TCP/IP ressources on the server if we
+ // are syncing a lot of users (as we try to open a new connection
+ // to get the user details). This is the least invasive way
+ // to reuse existing connections without greater code surgery.
+ if(!empty($this->ldapconnection)) {
+ $this->ldapconns++;
+ return $this->ldapconnection;
+ }
+
//Select bind password, With empty values use
//ldap_bind_* variables or anonymous bind if ldap_bind_* are empty
if ($binddn == '' and $bindpwd == '') {
}
if ($bindresult) {
+ // Set the connection counter so we can call PHP's ldap_close()
+ // when we call $this->ldap_close() for the last 'open' connection.
+ $this->ldapconns = 1;
+ $this->ldapconnection = $connresult;
return $connresult;
}
return false;
}
+ /**
+ * disconnects from a ldap server
+ *
+ */
+ function ldap_close() {
+ $this->ldapconns--;
+ if($this->ldapconns == 0) {
+ @ldap_close($this->ldapconnection);
+ unset($this->ldapconnection);
+ }
+ }
+
/**
* retuns dn of username
*