~yoboy-leguesh/ubuntu-fr-doc/maj20150810a

« back to all changes in this revision

Viewing changes to inc/auth/ldap.class.php

  • Committer: YoBoY
  • Date: 2012-10-24 19:05:18 UTC
  • mfrom: (114.1.3 maj-AdoraBelle)
  • Revision ID: yoboy.leguesh@gmail.com-20121024190518-bgtic5m3dt8gnzfn
Mise à jour de Dokuwiki 2012-10-13 "Adora Belle"
Application des patch ubuntu-fr d'optimisation
Ajout des thèmes ubuntu-fr
Ajout des plugins
Mise à jour des plugins box, orphanswanted, pageredirect, tag, cloud, forcepreview, pagelist
Désactivation de la nouvelle option d'envoie de notifications mail en html
Application des derniers patchs correctifs de Dokuwiki.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
    /**
16
16
     * Constructor
17
17
     */
18
 
    function auth_ldap(){
 
18
    function __construct(){
19
19
        global $conf;
20
20
        $this->cnf = $conf['auth']['ldap'];
21
21
 
307
307
            }
308
308
        }
309
309
        return $result;
310
 
 
311
 
 
312
310
    }
313
311
 
314
312
    /**
360
358
    function _constructPattern($filter) {
361
359
        $this->_pattern = array();
362
360
        foreach ($filter as $item => $pattern) {
363
 
//          $this->_pattern[$item] = '/'.preg_quote($pattern,"/").'/i';          // don't allow regex characters
364
361
            $this->_pattern[$item] = '/'.str_replace('/','\/',$pattern).'/i';    // allow regex characters
365
362
        }
366
363
    }
390
387
        $this->bound = 0;
391
388
 
392
389
        $port = ($this->cnf['port']) ? $this->cnf['port'] : 389;
393
 
        $this->con = @ldap_connect($this->cnf['server'],$port);
394
 
        if(!$this->con){
 
390
        $bound = false;
 
391
        $servers = explode(',', $this->cnf['server']);
 
392
        foreach ($servers as $server) {
 
393
            $server = trim($server);
 
394
            $this->con = @ldap_connect($server, $port);
 
395
            if (!$this->con) {
 
396
                continue;
 
397
            }
 
398
 
 
399
            /*
 
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().
 
403
             *
 
404
             * So we should try to bind to server in order to check its availability.
 
405
             */
 
406
 
 
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__);
 
414
                }else{
 
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__);
 
421
                        }
 
422
                    }
 
423
                    // needs version 3
 
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__);
 
430
                        }
 
431
                    }
 
432
                }
 
433
            }
 
434
 
 
435
            //set deref mode
 
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__);
 
441
                }
 
442
            }
 
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);
 
446
            }
 
447
            $bound = @ldap_bind($this->con);
 
448
            if ($bound) {
 
449
                break;
 
450
            }
 
451
        }
 
452
 
 
453
        if(!$bound) {
395
454
            msg("LDAP: couldn't connect to LDAP server",-1);
396
455
            return false;
397
456
        }
398
457
 
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__);
406
 
            }else{
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__);
413
 
                    }
414
 
                }
415
 
                // needs version 3
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__);
422
 
                    }
423
 
                }
424
 
            }
425
 
        }
426
 
 
427
 
        //set deref mode
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__);
433
 
            }
434
 
        }
435
458
 
436
459
        $this->canDo['getUsers'] = true;
437
460
        return true;