Changeset 602

Show
Ignore:
Timestamp:
09/29/06 13:33:02 (2 years ago)
Author:
misja
Message:

LDAP authentication, work in progress: added the ability to set the search filter and search attributes.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • devel/auth/ldap/lib.php

    r555 r602  
    1313     * Configuration parameters in config.php: 
    1414     * 
     15     * // LDAP host 
    1516     * $CFG->ldap_host = 'localhost'; 
     17     * // LDAP port 
    1618     * $CFG->ldap_port = 389; 
     19     * // Base DN 
    1720     * $CFG->ldap_basedn = 'dc=curverider,dc=co,dc=uk'; 
     21     * // Bind as 
    1822     * $CFG->ldap_bind_dn = 'cn=admin,dc=curverider,dc=co,dc=uk'; 
     23     * // Password for non anonymous bind 
    1924     * $CFG->ldap_bind_pwd = 'secret'; 
     25     * // Protocol version 
    2026     * $CFG->ldap_protocol_version = 3; 
     27     * // Filter for username, common are cn or uid 
     28     * $CFG->ldap_filter_attr = 'uid'; 
     29     * // Search attibutes 
     30     * $CFG->ldap_search_attr = array('dn', 'ou', 'mail'); 
     31     * 
    2132     */ 
    2233 
    2334    function ldap_authenticate_user_login($username, $password) { 
    24  
    2535        global $CFG, $messages; 
    2636 
     
    3040        } 
    3141 
     42        // LDAP host 
    3243        if (!$CFG->ldap_host) { 
    3344            // No host defined, switch to plain login 
     
    3647        } 
    3748 
     49        // LDAP port 
    3850        if (!$CFG->ldap_port) { 
    3951            $CFG->ldap_port = 389; 
     52        } 
     53 
     54        // Which filter to apply for the username, e.g. cn or uid 
     55        if (!$CFG->ldap_filter_attr) { 
     56            $CFG->ldap_filter_attr = 'uid'; 
     57        } 
     58 
     59        // Which search attributes to return 
     60        if (!$CFG->ldap_search_attr) { 
     61            $CFG->ldap_search_attr = array('dn'); 
    4062        } 
    4163 
     
    4668        $version = 3; 
    4769 
     70        // LDAP protocol version 
    4871        if ($CFG->ldap_protocol_version) { 
    4972            $version = $CFG->ldap_protocol_version; 
     
    7093        if ($ldapbind) { 
    7194            // Perform LDAP search 
    72             $sr = @ldap_search($ds, $CFG->ldap_basedn, "cn=" . $username); 
     95            $sr = @ldap_search($ds, $CFG->ldap_basedn, $CFG->ldap_filter_attr ."=". $username, $CFG->ldap_search_attr); 
    7396 
    7497            if ($sr) {