Skip to content
Snippets Groups Projects
Commit c4aa63b1 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

Merge branch 'ldap_multi_server' of git://github.com/DvaSlona/dokuwiki into pull-request-104

* 'ldap_multi_server' of git://github.com/DvaSlona/dokuwiki:
  Config method changed from array to comma separated string.
  Allow multiple LDAP servers.
parents a655c878 2bd8dcab
No related branches found
No related tags found
No related merge requests found
...@@ -387,49 +387,75 @@ class auth_ldap extends auth_basic { ...@@ -387,49 +387,75 @@ class auth_ldap extends auth_basic {
$this->bound = 0; $this->bound = 0;
$port = ($this->cnf['port']) ? $this->cnf['port'] : 389; $port = ($this->cnf['port']) ? $this->cnf['port'] : 389;
$this->con = @ldap_connect($this->cnf['server'],$port); $bound = false;
if(!$this->con){ $servers = explode(',', $this->cnf['server']);
msg("LDAP: couldn't connect to LDAP server",-1); foreach ($servers as $server) {
return false; $server = trim($server);
} $this->con = @ldap_connect($server, $port);
if (!$this->con) {
continue;
}
//set protocol version and dependend options /*
if($this->cnf['version']){ * When OpenLDAP 2.x.x is used, ldap_connect() will always return a resource as it does
if(!@ldap_set_option($this->con, LDAP_OPT_PROTOCOL_VERSION, * not actually connect but just initializes the connecting parameters. The actual
$this->cnf['version'])){ * connect happens with the next calls to ldap_* funcs, usually with ldap_bind().
msg('Setting LDAP Protocol version '.$this->cnf['version'].' failed',-1); *
if($this->cnf['debug']) * So we should try to bind to server in order to check its availability.
msg('LDAP version set: '.htmlspecialchars(ldap_error($this->con)),0,__LINE__,__FILE__); */
}else{
//use TLS (needs version 3) //set protocol version and dependend options
if($this->cnf['starttls']) { if($this->cnf['version']){
if (!@ldap_start_tls($this->con)){ if(!@ldap_set_option($this->con, LDAP_OPT_PROTOCOL_VERSION,
msg('Starting TLS failed',-1); $this->cnf['version'])){
if($this->cnf['debug']) msg('Setting LDAP Protocol version '.$this->cnf['version'].' failed',-1);
msg('LDAP TLS set: '.htmlspecialchars(ldap_error($this->con)),0,__LINE__,__FILE__); if($this->cnf['debug'])
msg('LDAP version set: '.htmlspecialchars(ldap_error($this->con)),0,__LINE__,__FILE__);
}else{
//use TLS (needs version 3)
if($this->cnf['starttls']) {
if (!@ldap_start_tls($this->con)){
msg('Starting TLS failed',-1);
if($this->cnf['debug'])
msg('LDAP TLS set: '.htmlspecialchars(ldap_error($this->con)),0,__LINE__,__FILE__);
}
} }
} // needs version 3
// needs version 3 if(isset($this->cnf['referrals'])) {
if(isset($this->cnf['referrals'])) { if(!@ldap_set_option($this->con, LDAP_OPT_REFERRALS,
if(!@ldap_set_option($this->con, LDAP_OPT_REFERRALS, $this->cnf['referrals'])){
$this->cnf['referrals'])){ msg('Setting LDAP referrals to off failed',-1);
msg('Setting LDAP referrals to off failed',-1); if($this->cnf['debug'])
if($this->cnf['debug']) msg('LDAP referal set: '.htmlspecialchars(ldap_error($this->con)),0,__LINE__,__FILE__);
msg('LDAP referal set: '.htmlspecialchars(ldap_error($this->con)),0,__LINE__,__FILE__); }
} }
} }
} }
}
//set deref mode //set deref mode
if($this->cnf['deref']){ if($this->cnf['deref']){
if(!@ldap_set_option($this->con, LDAP_OPT_DEREF, $this->cnf['deref'])){ if(!@ldap_set_option($this->con, LDAP_OPT_DEREF, $this->cnf['deref'])){
msg('Setting LDAP Deref mode '.$this->cnf['deref'].' failed',-1); msg('Setting LDAP Deref mode '.$this->cnf['deref'].' failed',-1);
if($this->cnf['debug']) if($this->cnf['debug'])
msg('LDAP deref set: '.htmlspecialchars(ldap_error($this->con)),0,__LINE__,__FILE__); msg('LDAP deref set: '.htmlspecialchars(ldap_error($this->con)),0,__LINE__,__FILE__);
}
}
/* As of PHP 5.3.0 we can set timeout to speedup skipping of invalid servers */
if (defined('LDAP_OPT_NETWORK_TIMEOUT')) {
ldap_set_option($this->con, LDAP_OPT_NETWORK_TIMEOUT, 1);
}
$bound = ldap_bind($this->con);
if ($bound) {
break;
} }
} }
if(!$bound) {
msg("LDAP: couldn't connect to LDAP server",-1);
return false;
}
$this->canDo['getUsers'] = true; $this->canDo['getUsers'] = true;
return true; return true;
} }
......
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