Subversion Repositories Applications.papyrus

Rev

Rev 1173 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1173 Rev 1713
Line 12... Line 12...
12
 * the PHP License and are unable to obtain it through the web, please
12
 * the PHP License and are unable to obtain it through the web, please
13
 * send a note to license@php.net so we can mail you a copy immediately.
13
 * send a note to license@php.net so we can mail you a copy immediately.
14
 *
14
 *
15
 * @category   Authentication
15
 * @category   Authentication
16
 * @package    Auth
16
 * @package    Auth
17
 * @author     Jan Wagner <wagner@netsols.de> 
17
 * @author     Jan Wagner <wagner@netsols.de>
18
 * @author     Adam Ashley <aashley@php.net>
18
 * @author     Adam Ashley <aashley@php.net>
19
 * @author     Hugues Peeters <hugues.peeters@claroline.net>
19
 * @author     Hugues Peeters <hugues.peeters@claroline.net>
20
 * @copyright  2001-2006 The PHP Group
20
 * @copyright  2001-2006 The PHP Group
21
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
21
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
22
 * @version    CVS: $Id: LDAP.php,v 1.2 2006-12-14 15:04:28 jp_milcent Exp $
22
 * @version    CVS: $Id: LDAP.php,v 1.3 2007-11-19 15:11:00 jp_milcent Exp $
23
 * @link       http://pear.php.net/package/Auth
23
 * @link       http://pear.php.net/package/Auth
24
 */
24
 */
Line 25... Line 25...
25
 
25
 
26
/**
26
/**
Line 101... Line 101...
101
 *              may be found (default: uniqueMember)
101
 *              may be found (default: uniqueMember)
102
 * memberisdn:  whether the memberattr is the dn of the user (default)
102
 * memberisdn:  whether the memberattr is the dn of the user (default)
103
 *              or the value of userattr (usually uid)
103
 *              or the value of userattr (usually uid)
104
 * group:       the name of group to search for
104
 * group:       the name of group to search for
105
 * groupscope:  Scope for group searching: one, sub (default), or base
105
 * groupscope:  Scope for group searching: one, sub (default), or base
106
 * start_tls:   enable/disable the use of START_TLS encrypted connection 
106
 * start_tls:   enable/disable the use of START_TLS encrypted connection
107
 *              (default: false)
107
 *              (default: false)
108
 * debug:       Enable/Disable debugging output (default: false)
108
 * debug:       Enable/Disable debugging output (default: false)
109
 * try_all:     Whether to try all user accounts returned from the search
109
 * try_all:     Whether to try all user accounts returned from the search
110
 *              or just the first one. (default: false)
110
 *              or just the first one. (default: false)
111
 *
111
 *
Line 175... Line 175...
175
 *   "OU=Accounts, OU=Custom, DC=win2000, DC=example, DC=org'
175
 *   "OU=Accounts, OU=Custom, DC=win2000, DC=example, DC=org'
176
 *
176
 *
177
 * It seems that binding anonymously to an Active Directory
177
 * It seems that binding anonymously to an Active Directory
178
 * is not allowed, so you have to set binddn and bindpw for
178
 * is not allowed, so you have to set binddn and bindpw for
179
 * user searching.
179
 * user searching.
180
 * 
180
 *
181
 * LDAP Referrals need to be set to false for AD to work sometimes.
181
 * LDAP Referrals need to be set to false for AD to work sometimes.
182
 *
182
 *
183
 * Example a3 shows a full blown and tested example for connection to 
183
 * Example a3 shows a full blown and tested example for connection to
184
 * Windows 2000 Active Directory with group mebership checking
184
 * Windows 2000 Active Directory with group mebership checking
185
 *
185
 *
186
 * Note also that if you want an encrypted connection to an MS LDAP 
186
 * Note also that if you want an encrypted connection to an MS LDAP
187
 * server, then, on your webserver, you must specify 
187
 * server, then, on your webserver, you must specify
188
 *        TLS_REQCERT never
188
 *        TLS_REQCERT never
189
 * in /etc/ldap/ldap.conf or in the webserver user's ~/.ldaprc (which
189
 * in /etc/ldap/ldap.conf or in the webserver user's ~/.ldaprc (which
190
 * may or may not be read depending on your configuration).
190
 * may or may not be read depending on your configuration).
191
 *
191
 *
192
 *
192
 *
Line 195... Line 195...
195
 * @author     Jan Wagner <wagner@netsols.de>
195
 * @author     Jan Wagner <wagner@netsols.de>
196
 * @author     Adam Ashley <aashley@php.net>
196
 * @author     Adam Ashley <aashley@php.net>
197
 * @author     Hugues Peeters <hugues.peeters@claroline.net>
197
 * @author     Hugues Peeters <hugues.peeters@claroline.net>
198
 * @copyright  2001-2006 The PHP Group
198
 * @copyright  2001-2006 The PHP Group
199
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
199
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
200
 * @version    Release: 1.4.3  File: $Revision: 1.2 $
200
 * @version    Release: 1.5.4  File: $Revision: 1.3 $
201
 * @link       http://pear.php.net/package/Auth
201
 * @link       http://pear.php.net/package/Auth
202
 */
202
 */
203
class Auth_Container_LDAP extends Auth_Container
203
class Auth_Container_LDAP extends Auth_Container
204
{
204
{
Line 273... Line 273...
273
     * @access private
273
     * @access private
274
     * @return object  Returns a PEAR error object if an error occurs.
274
     * @return object  Returns a PEAR error object if an error occurs.
275
     */
275
     */
276
    function _connect()
276
    function _connect()
277
    {
277
    {
-
 
278
        $this->log('Auth_Container_LDAP::_connect() called.', AUTH_LOG_DEBUG);
278
        // connect
279
        // connect
279
        if (isset($this->options['url']) && $this->options['url'] != '') {
280
        if (isset($this->options['url']) && $this->options['url'] != '') {
280
            $this->_debug('Connecting with URL', __LINE__);
281
            $this->log('Connecting with URL', AUTH_LOG_DEBUG);
281
            $conn_params = array($this->options['url']);
282
            $conn_params = array($this->options['url']);
282
        } else {
283
        } else {
283
            $this->_debug('Connecting with host:port', __LINE__);
284
            $this->log('Connecting with host:port', AUTH_LOG_DEBUG);
284
            $conn_params = array($this->options['host'], $this->options['port']);
285
            $conn_params = array($this->options['host'], $this->options['port']);
285
        }
286
        }
Line 286... Line 287...
286
 
287
 
-
 
288
        if (($this->conn_id = @call_user_func_array('ldap_connect', $conn_params)) === false) {
-
 
289
            $this->log('Connection to server failed.', AUTH_LOG_DEBUG);
287
        if (($this->conn_id = @call_user_func_array('ldap_connect', $conn_params)) === false) {
290
            $this->log('LDAP ERROR: '.ldap_errno($this->conn_id).': '.ldap_error($this->conn_id), AUTH_LOG_DEBUG);
288
            return PEAR::raiseError('Auth_Container_LDAP: Could not connect to server.', 41);
291
            return PEAR::raiseError('Auth_Container_LDAP: Could not connect to server.', 41);
289
        }
292
        }
Line 290... Line 293...
290
        $this->_debug('Successfully connected to server', __LINE__);
293
        $this->log('Successfully connected to server', AUTH_LOG_DEBUG);
291
 
294
 
292
        // switch LDAP version
295
        // switch LDAP version
293
        if (is_numeric($this->options['version']) && $this->options['version'] > 2) {
296
        if (is_numeric($this->options['version']) && $this->options['version'] > 2) {
294
            $this->_debug("Switching to LDAP version {$this->options['version']}", __LINE__);
297
            $this->log("Switching to LDAP version {$this->options['version']}", AUTH_LOG_DEBUG);
295
            @ldap_set_option($this->conn_id, LDAP_OPT_PROTOCOL_VERSION, $this->options['version']);
298
            @ldap_set_option($this->conn_id, LDAP_OPT_PROTOCOL_VERSION, $this->options['version']);
296
        
299
 
297
            // start TLS if available
300
            // start TLS if available
298
            if (isset($this->options['start_tls']) && $this->options['start_tls']) {           
301
            if (isset($this->options['start_tls']) && $this->options['start_tls']) {
-
 
302
                $this->log("Starting TLS session", AUTH_LOG_DEBUG);
-
 
303
                if (@ldap_start_tls($this->conn_id) === false) {
299
                $this->_debug("Starting TLS session", __LINE__);
304
                    $this->log('Could not start TLS session', AUTH_LOG_DEBUG);
300
                if (@ldap_start_tls($this->conn_id) === false) {
305
                    $this->log('LDAP ERROR: '.ldap_errno($this->conn_id).': '.ldap_error($this->conn_id), AUTH_LOG_DEBUG);
301
                    return PEAR::raiseError('Auth_Container_LDAP: Could not start tls.', 41);
306
                    return PEAR::raiseError('Auth_Container_LDAP: Could not start tls.', 41);
302
                }
307
                }
Line 303... Line 308...
303
            }
308
            }
304
        }
309
        }
305
 
310
 
306
        // switch LDAP referrals
311
        // switch LDAP referrals
-
 
312
        if (is_bool($this->options['referrals'])) {
-
 
313
            $this->log("Switching LDAP referrals to " . (($this->options['referrals']) ? 'true' : 'false'), AUTH_LOG_DEBUG);
-
 
314
            if (@ldap_set_option($this->conn_id, LDAP_OPT_REFERRALS, $this->options['referrals']) === false) {
307
        if (is_bool($this->options['referrals'])) {
315
                $this->log('Could not change LDAP referrals options', AUTH_LOG_DEBUG);
Line 308... Line 316...
308
          $this->_debug("Switching LDAP referrals to " . (($this->options['referrals']) ? 'true' : 'false'), __LINE__);
316
                $this->log('LDAP ERROR: '.ldap_errno($this->conn_id).': '.ldap_error($this->conn_id), AUTH_LOG_DEBUG);
309
          @ldap_set_option($this->conn_id, LDAP_OPT_REFERRALS, $this->options['referrals']);
317
            }
310
        }
318
        }
311
 
319
 
312
        // bind with credentials or anonymously
320
        // bind with credentials or anonymously
313
        if (strlen($this->options['binddn']) && strlen($this->options['bindpw'])) {
321
        if (strlen($this->options['binddn']) && strlen($this->options['bindpw'])) {
314
            $this->_debug('Binding with credentials', __LINE__);
322
            $this->log('Binding with credentials', AUTH_LOG_DEBUG);
315
            $bind_params = array($this->conn_id, $this->options['binddn'], $this->options['bindpw']);
323
            $bind_params = array($this->conn_id, $this->options['binddn'], $this->options['bindpw']);
Line 316... Line 324...
316
        } else {
324
        } else {
317
            $this->_debug('Binding anonymously', __LINE__);
325
            $this->log('Binding anonymously', AUTH_LOG_DEBUG);
318
            $bind_params = array($this->conn_id);
326
            $bind_params = array($this->conn_id);
-
 
327
        }
319
        }
328
 
320
 
329
        // bind for searching
321
        // bind for searching
330
        if ((@call_user_func_array('ldap_bind', $bind_params)) === false) {
322
        if ((@call_user_func_array('ldap_bind', $bind_params)) === false) {
331
            $this->log('Bind failed', AUTH_LOG_DEBUG);
Line 323... Line 332...
323
            $this->_debug();
332
            $this->log('LDAP ERROR: '.ldap_errno($this->conn_id).': '.ldap_error($this->conn_id), AUTH_LOG_DEBUG);
324
            $this->_disconnect();
333
            $this->_disconnect();
Line 325... Line 334...
325
            return PEAR::raiseError("Auth_Container_LDAP: Could not bind to LDAP server.", 41);
334
            return PEAR::raiseError("Auth_Container_LDAP: Could not bind to LDAP server.", 41);
Line 337... Line 346...
337
     *
346
     *
338
     * @access private
347
     * @access private
339
     */
348
     */
340
    function _disconnect()
349
    function _disconnect()
341
    {
350
    {
-
 
351
        $this->log('Auth_Container_LDAP::_disconnect() called.', AUTH_LOG_DEBUG);
342
        if ($this->_isValidLink()) {
352
        if ($this->_isValidLink()) {
343
            $this->_debug('disconnecting from server');
353
            $this->log('disconnecting from server');
344
            @ldap_unbind($this->conn_id);
354
            @ldap_unbind($this->conn_id);
345
        }
355
        }
346
    }
356
    }
Line 347... Line 357...
347
 
357
 
Line 353... Line 363...
353
     *
363
     *
354
     * @access private
364
     * @access private
355
     */
365
     */
356
    function _getBaseDN()
366
    function _getBaseDN()
357
    {
367
    {
-
 
368
        $this->log('Auth_Container_LDAP::_getBaseDN() called.', AUTH_LOG_DEBUG);
358
        $err = $this->_prepare();
369
        $err = $this->_prepare();
359
        if ($err !== true) {
370
        if ($err !== true) {
360
            return PEAR::raiseError($err->getMessage(), $err->getCode());
371
            return PEAR::raiseError($err->getMessage(), $err->getCode());
361
        }
372
        }
Line 362... Line 373...
362
 
373
 
363
        if ($this->options['basedn'] == "" && $this->_isValidLink()) {
374
        if ($this->options['basedn'] == "" && $this->_isValidLink()) {
Line 364... Line 375...
364
            $this->_debug("basedn not set, searching via namingContexts.", __LINE__);
375
            $this->log("basedn not set, searching via namingContexts.", AUTH_LOG_DEBUG);
Line 365... Line 376...
365
 
376
 
Line 366... Line 377...
366
            $result_id = @ldap_read($this->conn_id, "", "(objectclass=*)", array("namingContexts"));
377
            $result_id = @ldap_read($this->conn_id, "", "(objectclass=*)", array("namingContexts"));
Line 367... Line 378...
367
 
378
 
368
            if (@ldap_count_entries($this->conn_id, $result_id) == 1) {
379
            if (@ldap_count_entries($this->conn_id, $result_id) == 1) {
369
 
380
 
Line 370... Line 381...
370
                $this->_debug("got result for namingContexts", __LINE__);
381
                $this->log("got result for namingContexts", AUTH_LOG_DEBUG);
371
 
382
 
372
                $entry_id = @ldap_first_entry($this->conn_id, $result_id);
383
                $entry_id = @ldap_first_entry($this->conn_id, $result_id);
373
                $attrs = @ldap_get_attributes($this->conn_id, $entry_id);
384
                $attrs = @ldap_get_attributes($this->conn_id, $entry_id);
374
                $basedn = $attrs['namingContexts'][0];
385
                $basedn = $attrs['namingContexts'][0];
375
 
386
 
376
                if ($basedn != "") {
387
                if ($basedn != "") {
Line 428... Line 439...
428
        $this->options['userdn']      = '';
439
        $this->options['userdn']      = '';
429
        $this->options['userscope']   = 'sub';
440
        $this->options['userscope']   = 'sub';
430
        $this->options['userattr']    = 'uid';
441
        $this->options['userattr']    = 'uid';
431
        $this->options['userfilter']  = '(objectClass=posixAccount)';
442
        $this->options['userfilter']  = '(objectClass=posixAccount)';
432
        $this->options['attributes']  = array(''); // no attributes
443
        $this->options['attributes']  = array(''); // no attributes
433
     // $this->options['attrformat']  = 'LDAP'; // returns attribute array as PHP LDAP functions return it
-
 
434
        $this->options['attrformat']  = 'AUTH'; // returns attribute like other Auth containers
444
        $this->options['attrformat']  = 'AUTH'; // returns attribute like other Auth containers
435
        $this->options['group']       = '';
445
        $this->options['group']       = '';
436
        $this->options['groupdn']     = '';
446
        $this->options['groupdn']     = '';
437
        $this->options['groupscope']  = 'sub';
447
        $this->options['groupscope']  = 'sub';
438
        $this->options['groupattr']   = 'cn';
448
        $this->options['groupattr']   = 'cn';
Line 475... Line 485...
475
    // }}}
485
    // }}}
476
    // {{{ _setV12OptionsToV13()
486
    // {{{ _setV12OptionsToV13()
Line 477... Line 487...
477
 
487
 
478
    /**
488
    /**
479
     * Adapt deprecated options from Auth 1.2 LDAP to Auth 1.3 LDAP
489
     * Adapt deprecated options from Auth 1.2 LDAP to Auth 1.3 LDAP
480
     * 
490
     *
481
     * @author Hugues Peeters <hugues.peeters@claroline.net>
491
     * @author Hugues Peeters <hugues.peeters@claroline.net>
482
     * @access private
492
     * @access private
483
     * @param array
493
     * @param array
484
     * @return array
494
     * @return array
Line 534... Line 544...
534
     * @param  string Password
544
     * @param  string Password
535
     * @return boolean
545
     * @return boolean
536
     */
546
     */
537
    function fetchData($username, $password)
547
    function fetchData($username, $password)
538
    {
548
    {
-
 
549
        $this->log('Auth_Container_LDAP::fetchData() called.', AUTH_LOG_DEBUG);
539
        $err = $this->_prepare();
550
        $err = $this->_prepare();
540
        if ($err !== true) {
551
        if ($err !== true) {
541
            return PEAR::raiseError($err->getMessage(), $err->getCode());
552
            return PEAR::raiseError($err->getMessage(), $err->getCode());
542
        }
553
        }
Line 546... Line 557...
546
            return PEAR::raiseError($err->getMessage(), $err->getCode());
557
            return PEAR::raiseError($err->getMessage(), $err->getCode());
547
        }
558
        }
Line 548... Line 559...
548
 
559
 
549
        // UTF8 Encode username for LDAPv3
560
        // UTF8 Encode username for LDAPv3
550
        if (@ldap_get_option($this->conn_id, LDAP_OPT_PROTOCOL_VERSION, $ver) && $ver == 3) {
561
        if (@ldap_get_option($this->conn_id, LDAP_OPT_PROTOCOL_VERSION, $ver) && $ver == 3) {
551
            $this->_debug('UTF8 encoding username for LDAPv3', __LINE__);
562
            $this->log('UTF8 encoding username for LDAPv3', AUTH_LOG_DEBUG);
552
            $username = utf8_encode($username);
563
            $username = utf8_encode($username);
Line 553... Line 564...
553
        }
564
        }
554
 
565
 
Line 564... Line 575...
564
            $search_basedn .= ',';
575
            $search_basedn .= ',';
565
        }
576
        }
566
        $search_basedn .= $this->options['basedn'];
577
        $search_basedn .= $this->options['basedn'];
Line 567... Line 578...
567
 
578
 
568
        // attributes
579
        // attributes
Line 569... Line 580...
569
        $attributes = $this->options['attributes'];
580
        $searchAttributes = $this->options['attributes'];
570
 
581
 
Line 571... Line 582...
571
        // make functions params array
582
        // make functions params array
572
        $func_params = array($this->conn_id, $search_basedn, $filter, $attributes);
583
        $func_params = array($this->conn_id, $search_basedn, $filter, $searchAttributes);
Line 573... Line 584...
573
 
584
 
Line 574... Line 585...
574
        // search function to use
585
        // search function to use
575
        $func_name = $this->_scope2function($this->options['userscope']);
586
        $func_name = $this->_scope2function($this->options['userscope']);
576
 
587
 
577
        $this->_debug("Searching with $func_name and filter $filter in $search_basedn", __LINE__);
588
        $this->log("Searching with $func_name and filter $filter in $search_basedn", AUTH_LOG_DEBUG);
Line 578... Line 589...
578
 
589
 
Line 579... Line 590...
579
        // search
590
        // search
580
        if (($result_id = @call_user_func_array($func_name, $func_params)) === false) {
591
        if (($result_id = @call_user_func_array($func_name, $func_params)) === false) {
Line 581... Line 592...
581
            $this->_debug('User not found', __LINE__);
592
            $this->log('User not found', AUTH_LOG_DEBUG);
582
        } elseif (@ldap_count_entries($this->conn_id, $result_id) >= 1) { // did we get some possible results?
593
        } elseif (@ldap_count_entries($this->conn_id, $result_id) >= 1) { // did we get some possible results?
583
 
594
 
584
            $this->_debug('User(s) found', __LINE__);
595
            $this->log('User(s) found', AUTH_LOG_DEBUG);
585
 
596
 
586
            $first = true;
597
            $first = true;
587
            $entry_id = null;
598
            $entry_id = null;
Line 598... Line 609...
598
                        break;
609
                        break;
599
                }
610
                }
600
                $user_dn  = @ldap_get_dn($this->conn_id, $entry_id);
611
                $user_dn  = @ldap_get_dn($this->conn_id, $entry_id);
Line 601... Line 612...
601
 
612
 
602
                // as the dn is not fetched as an attribute, we save it anyway
613
                // as the dn is not fetched as an attribute, we save it anyway
603
                if (is_array($attributes) && in_array('dn', $attributes)) {
614
                if (is_array($searchAttributes) && in_array('dn', $searchAttributes)) {
604
                    $this->_debug('Saving DN to AuthData', __LINE__);
615
                    $this->log('Saving DN to AuthData', AUTH_LOG_DEBUG);
605
                    $this->_auth_obj->setAuthData('dn', $user_dn);
616
                    $this->_auth_obj->setAuthData('dn', $user_dn);
606
                }
617
                }
607
            
618
 
608
                // fetch attributes
619
                // fetch attributes
Line 609... Line 620...
609
                if ($attributes = @ldap_get_attributes($this->conn_id, $entry_id)) {
620
                if ($attributes = @ldap_get_attributes($this->conn_id, $entry_id)) {
610
 
621
 
Line 623... Line 634...
623
                        // enabled by setting 'attrformat' to
634
                        // enabled by setting 'attrformat' to
624
                        // 'AUTH' in the 'options' array.
635
                        // 'AUTH' in the 'options' array.
625
                        // eg. $this->options['attrformat'] = 'AUTH'
636
                        // eg. $this->options['attrformat'] = 'AUTH'
Line 626... Line 637...
626
 
637
 
627
                        if ( strtoupper($this->options['attrformat']) == 'AUTH' ) {
638
                        if ( strtoupper($this->options['attrformat']) == 'AUTH' ) {
628
                            $this->_debug('Saving attributes to Auth data in AUTH format', __LINE__);
639
                            $this->log('Saving attributes to Auth data in AUTH format', AUTH_LOG_DEBUG);
629
                            unset ($attributes['count']);
640
                            unset ($attributes['count']);
630
                            foreach ($attributes as $attributeName => $attributeValue ) {
641
                            foreach ($attributes as $attributeName => $attributeValue ) {
631
                                if (is_int($attributeName)) continue;
642
                                if (is_int($attributeName)) continue;
632
                                if (is_array($attributeValue) && isset($attributeValue['count'])) {
643
                                if (is_array($attributeValue) && isset($attributeValue['count'])) {
633
                                    unset ($attributeValue['count']);
644
                                    unset ($attributeValue['count']);
634
                                }
645
                                }
-
 
646
                                if (count($attributeValue)<=1) $attributeValue = $attributeValue[0];
635
                                if (count($attributeValue)<=1) $attributeValue = $attributeValue[0];
647
                                $this->log('Storing additional field: '.$attributeName, AUTH_LOG_DEBUG);
636
                                $this->_auth_obj->setAuthData($attributeName, $attributeValue);
648
                                $this->_auth_obj->setAuthData($attributeName, $attributeValue);
637
                            }
649
                            }
638
                        }
650
                        }
639
                        else
651
                        else
640
                        {
652
                        {
641
                            $this->_debug('Saving attributes to Auth data in LDAP format', __LINE__);
653
                            $this->log('Saving attributes to Auth data in LDAP format', AUTH_LOG_DEBUG);
642
                            $this->_auth_obj->setAuthData('attributes', $attributes);
654
                            $this->_auth_obj->setAuthData('attributes', $attributes);
643
                        }
655
                        }
644
                    }
656
                    }
645
                }
657
                }
Line 646... Line 658...
646
                @ldap_free_result($result_id);
658
                @ldap_free_result($result_id);
647
 
659
 
648
                // need to catch an empty password as openldap seems to return TRUE
660
                // need to catch an empty password as openldap seems to return TRUE
649
                // if anonymous binding is allowed
661
                // if anonymous binding is allowed
Line 650... Line 662...
650
                if ($password != "") {
662
                if ($password != "") {
651
                    $this->_debug("Bind as $user_dn", __LINE__);
663
                    $this->log("Bind as $user_dn", AUTH_LOG_DEBUG);
652
 
664
 
Line 653... Line 665...
653
                    // try binding as this user with the supplied password
665
                    // try binding as this user with the supplied password
654
                    if (@ldap_bind($this->conn_id, $user_dn, $password)) {
666
                    if (@ldap_bind($this->conn_id, $user_dn, $password)) {
655
                        $this->_debug('Bind successful', __LINE__);
667
                        $this->log('Bind successful', AUTH_LOG_DEBUG);
656
 
668
 
657
                        // check group if appropiate
669
                        // check group if appropiate
658
                        if (strlen($this->options['group'])) {
670
                        if (strlen($this->options['group'])) {
659
                            // decide whether memberattr value is a dn or the username
671
                            // decide whether memberattr value is a dn or the username
660
                            $this->_debug('Checking group membership', __LINE__);
672
                            $this->log('Checking group membership', AUTH_LOG_DEBUG);
661
                            $return = $this->checkGroup(($this->options['memberisdn']) ? $user_dn : $username);
673
                            $return = $this->checkGroup(($this->options['memberisdn']) ? $user_dn : $username);
662
                            $this->_disconnect();
674
                            $this->_disconnect();
663
                            return $return;
675
                            return $return;
664
                        } else {
676
                        } else {
665
                            $this->_debug('Authenticated', __LINE__);
677
                            $this->log('Authenticated', AUTH_LOG_DEBUG);
666
                            $this->_disconnect();
678
                            $this->_disconnect();
667
                            return true; // user authenticated
679
                            return true; // user authenticated
668
                        } // checkGroup
680
                        } // checkGroup
669
                    } // bind
681
                    } // bind
670
                } // non-empty password
682
                } // non-empty password
671
            } while ($this->options['try_all'] == true); // interate through entries
683
            } while ($this->options['try_all'] == true); // interate through entries
672
        } // get results
684
        } // get results
673
        // default
685
        // default
Line 674... Line 686...
674
        $this->_debug('NOT authenticated!', __LINE__);
686
        $this->log('NOT authenticated!', AUTH_LOG_DEBUG);
Line 689... Line 701...
689
     * @param  string Distinguished Name of the authenticated User
701
     * @param  string Distinguished Name of the authenticated User
690
     * @return boolean
702
     * @return boolean
691
     */
703
     */
692
    function checkGroup($user)
704
    function checkGroup($user)
693
    {
705
    {
-
 
706
        $this->log('Auth_Container_LDAP::checkGroup() called.', AUTH_LOG_DEBUG);
694
        $err = $this->_prepare();
707
        $err = $this->_prepare();
695
        if ($err !== true) {
708
        if ($err !== true) {
696
            return PEAR::raiseError($err->getMessage(), $err->getCode());
709
            return PEAR::raiseError($err->getMessage(), $err->getCode());
697
        }
710
        }
Line 713... Line 726...
713
 
726
 
714
        $func_params = array($this->conn_id, $search_basedn, $filter,
727
        $func_params = array($this->conn_id, $search_basedn, $filter,
715
                             array($this->options['memberattr']));
728
                             array($this->options['memberattr']));
Line 716... Line 729...
716
        $func_name = $this->_scope2function($this->options['groupscope']);
729
        $func_name = $this->_scope2function($this->options['groupscope']);
Line 717... Line 730...
717
 
730
 
718
        $this->_debug("Searching with $func_name and filter $filter in $search_basedn", __LINE__);
731
        $this->log("Searching with $func_name and filter $filter in $search_basedn", AUTH_LOG_DEBUG);
719
 
732
 
720
        // search
733
        // search
721
        if (($result_id = @call_user_func_array($func_name, $func_params)) != false) {
734
        if (($result_id = @call_user_func_array($func_name, $func_params)) != false) {
722
            if (@ldap_count_entries($this->conn_id, $result_id) == 1) {
735
            if (@ldap_count_entries($this->conn_id, $result_id) == 1) {
723
                @ldap_free_result($result_id);
736
                @ldap_free_result($result_id);
724
                $this->_debug('User is member of group', __LINE__);
737
                $this->log('User is member of group', AUTH_LOG_DEBUG);
725
                return true;
738
                return true;
726
            }
739
            }
727
        }
740
        }
728
        // default
741
        // default
Line 729... Line 742...
729
        $this->_debug('User is NOT member of group', __LINE__);
742
        $this->log('User is NOT member of group', AUTH_LOG_DEBUG);
730
        return false;
-
 
731
    }
-
 
732
 
-
 
733
    // }}}
-
 
734
    // {{{ _debug()
-
 
735
 
-
 
736
    /**
-
 
737
     * Outputs debugging messages
-
 
738
     *
-
 
739
     * @access private
-
 
740
     * @param string Debugging Message
-
 
741
     * @param integer Line number
-
 
742
     */
-
 
743
    function _debug($msg = '', $line = 0)
-
 
744
    {
-
 
745
        if ($this->options['debug'] == true) {
-
 
746
            if ($msg == '' && $this->_isValidLink()) {
-
 
747
                $msg = 'LDAP_Error: ' . @ldap_err2str(@ldap_errno($this->_conn_id));
-
 
748
            }
-
 
749
            print("$line: $msg <br />");
-
 
750
        }
743
        return false;
Line 751... Line 744...
751
    }
744
    }
752
 
745
 
753
    // }}}
746
    // }}}