390
387
$this->bound = 0;
392
389
$port = ($this->cnf['port']) ? $this->cnf['port'] : 389;
393
$this->con = @ldap_connect($this->cnf['server'],$port);
391
$servers = explode(',', $this->cnf['server']);
392
foreach ($servers as $server) {
393
$server = trim($server);
394
$this->con = @ldap_connect($server, $port);
400
* When OpenLDAP 2.x.x is used, ldap_connect() will always return a resource as it does
401
* not actually connect but just initializes the connecting parameters. The actual
402
* connect happens with the next calls to ldap_* funcs, usually with ldap_bind().
404
* So we should try to bind to server in order to check its availability.
407
//set protocol version and dependend options
408
if($this->cnf['version']){
409
if(!@ldap_set_option($this->con, LDAP_OPT_PROTOCOL_VERSION,
410
$this->cnf['version'])){
411
msg('Setting LDAP Protocol version '.$this->cnf['version'].' failed',-1);
412
if($this->cnf['debug'])
413
msg('LDAP version set: '.htmlspecialchars(ldap_error($this->con)),0,__LINE__,__FILE__);
415
//use TLS (needs version 3)
416
if($this->cnf['starttls']) {
417
if (!@ldap_start_tls($this->con)){
418
msg('Starting TLS failed',-1);
419
if($this->cnf['debug'])
420
msg('LDAP TLS set: '.htmlspecialchars(ldap_error($this->con)),0,__LINE__,__FILE__);
424
if(isset($this->cnf['referrals'])) {
425
if(!@ldap_set_option($this->con, LDAP_OPT_REFERRALS,
426
$this->cnf['referrals'])){
427
msg('Setting LDAP referrals to off failed',-1);
428
if($this->cnf['debug'])
429
msg('LDAP referal set: '.htmlspecialchars(ldap_error($this->con)),0,__LINE__,__FILE__);
436
if($this->cnf['deref']){
437
if(!@ldap_set_option($this->con, LDAP_OPT_DEREF, $this->cnf['deref'])){
438
msg('Setting LDAP Deref mode '.$this->cnf['deref'].' failed',-1);
439
if($this->cnf['debug'])
440
msg('LDAP deref set: '.htmlspecialchars(ldap_error($this->con)),0,__LINE__,__FILE__);
443
/* As of PHP 5.3.0 we can set timeout to speedup skipping of invalid servers */
444
if (defined('LDAP_OPT_NETWORK_TIMEOUT')) {
445
ldap_set_option($this->con, LDAP_OPT_NETWORK_TIMEOUT, 1);
447
$bound = @ldap_bind($this->con);
395
454
msg("LDAP: couldn't connect to LDAP server",-1);
399
//set protocol version and dependend options
400
if($this->cnf['version']){
401
if(!@ldap_set_option($this->con, LDAP_OPT_PROTOCOL_VERSION,
402
$this->cnf['version'])){
403
msg('Setting LDAP Protocol version '.$this->cnf['version'].' failed',-1);
404
if($this->cnf['debug'])
405
msg('LDAP version set: '.htmlspecialchars(ldap_error($this->con)),0,__LINE__,__FILE__);
407
//use TLS (needs version 3)
408
if($this->cnf['starttls']) {
409
if (!@ldap_start_tls($this->con)){
410
msg('Starting TLS failed',-1);
411
if($this->cnf['debug'])
412
msg('LDAP TLS set: '.htmlspecialchars(ldap_error($this->con)),0,__LINE__,__FILE__);
416
if(isset($this->cnf['referrals'])) {
417
if(!@ldap_set_option($this->con, LDAP_OPT_REFERRALS,
418
$this->cnf['referrals'])){
419
msg('Setting LDAP referrals to off failed',-1);
420
if($this->cnf['debug'])
421
msg('LDAP referal set: '.htmlspecialchars(ldap_error($this->con)),0,__LINE__,__FILE__);
428
if($this->cnf['deref']){
429
if(!@ldap_set_option($this->con, LDAP_OPT_DEREF, $this->cnf['deref'])){
430
msg('Setting LDAP Deref mode '.$this->cnf['deref'].' failed',-1);
431
if($this->cnf['debug'])
432
msg('LDAP deref set: '.htmlspecialchars(ldap_error($this->con)),0,__LINE__,__FILE__);
436
459
$this->canDo['getUsers'] = true;