Support ldap connections via URI to handle ldaps and redundant ldap servers

This commit is contained in:
Scott Savarese 2023-04-27 11:00:50 +00:00
parent effc004741
commit 0059d0dcdb
2 changed files with 13 additions and 2 deletions

View File

@ -657,6 +657,9 @@ $c->admin_email = 'calendar-admin@example.com';
// $c->authenticate_hook['call'] = 'LDAP_check';
// $c->authenticate_hook['config'] = array(
// /* Use URI to set one or more LDAP servers to connect to for redundancy. Also supports ldaps.
// * If no URI string is set, host and port can be used */
// 'uri' => 'ldaps://hostname:port ldap://hostname2:port2'
// 'host' => 'www.tennaxia.net', //host name of your LDAP Server
// 'port' => '389', //port

View File

@ -54,13 +54,21 @@ class ldapDriver
if (isset($config['networkTimeout']))
ldap_set_option($this->connect, LDAP_OPT_NETWORK_TIMEOUT, $config['networkTimeout']);
if ($port)
// If we are given a URI (or multiple) to connect to, use them. This allows support for LDAPS connections
// as well as redundant ldap servers to connect to
// Otherwise default to host and port
if (isset($config['uri']))
$this->connect=ldap_connect($config['uri']);
elseif ($port)
$this->connect=ldap_connect($host, $port);
else
$this->connect=ldap_connect($host);
if (! $this->connect){
$c->messages[] = sprintf(translate( 'drivers_ldap : Unable to connect to LDAP with port %s on host %s'), $port, $host );
if (isset($config['uri']))
$c->messages[] = sprintf(translate( 'drivers_ldap : Unable to connect to LDAP with URI: %s'), $config['uri'] );
else
$c->messages[] = sprintf(translate( 'drivers_ldap : Unable to connect to LDAP with port %s on host %s'), $port, $host );
$this->valid=false;
return ;
}