Changeset 29135


Ignore:
Timestamp:
Aug 1, 2014, 12:56:27 PM (10 years ago)
Author:
22decembre
Message:

modif of function ldap_bind_as with password strtr

modif of ldapd_search_dn to correspond to the function send by "Bleylevens I (UB)" <i.bleylevens@…>
new function supposed to work better with AD.

the lang file contains a small modif already updated in english

Location:
extensions/Ldap_Login
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/Ldap_Login/class.ldap.php

    r28534 r29135  
    4141        }
    4242       
    43         public function load_default_config()
    44         {
     43        public function load_default_config(){
    4544                $this->config['host'] = 'localhost';
    4645                $this->config['basedn'] = 'dc=example,dc=com'; // racine !
     
    6564        }
    6665       
    67         function load_config() {
     66        function load_config(){
    6867                $this->load_default_config();
    6968               
     
    7372                {
    7473                        $this->config = unserialize($conf_file);
    75                         $this->config['full_usersbranch'] = $this->config['usersbranch'].','.$this->config['basedn'];
    76                         $this->config['full_groupbranch'] = $this->config['groupbranch'].','.$this->config['basedn'];
    77                 }
    78         }
    79 
    80         function save_config()
    81         {
     74//                      $this->config['full_usersbranch'] = $this->config['usersbranch'].','.$this->config['basedn'];
     75//                      $this->config['full_groupbranch'] = $this->config['groupbranch'].','.$this->config['basedn'];
     76                        // I don't place it in config['..'] because it will save it in the config file, and I don't want that !
     77                        $this->full_usersbranch = $this->config['usersbranch'].','.$this->config['basedn'];
     78                        $this->full_groupbranch = $this->config['groupbranch'].','.$this->config['basedn'];
     79                }
     80        }
     81
     82        function save_config(){
    8283                $file = fopen( LDAP_LOGIN_PATH.'/data.dat', 'w' );
    8384                fwrite($file, serialize($this->config) );
     
    8586        }
    8687
    87         function ldap_admin_menu($menu)
    88         {
     88        function ldap_admin_menu($menu){
    8989                array_push($menu,
    9090                array(
     
    121121                        // then we authenticate if anonymous search is forbidden
    122122                        if (!empty($obj->config['ld_binddn']) && !empty($obj->config['ld_bindpw'])){
    123                                 if (@ldap_bind($this->cnx,$this->config['ld_binddn'],$this->config['ld_bindpw'])){
     123                                $password = strtr($obj->config['ld_bindpw'], array("\'"=>"'"));
     124                       
     125                                if (@ldap_bind($this->cnx,$this->config['ld_binddn'],$password)){
    124126                                        return true;
    125127                                }
     
    147149                        return $this->ldap_search_dn($name);
    148150                }
    149                 else { return $this->config['ld_attr'].'='.$name.','.$this->config['full_usersbranch']; }
     151                else { return $this->config['ld_attr'].'='.$name.','.$this->full_usersbranch; }
    150152        }
    151153       
     
    156158                }
    157159                else {
    158                 $result[] = $this->config['ld_group'].'='.$groupname.','.$this->config['full_groupbranch'];
     160                $result[] = $this->config['ld_group'].'='.$groupname.','.$this->full_groupbranch;
    159161                return $result;
    160162                }
     
    163165        // authentication
    164166        public function ldap_bind_as($user,$user_passwd){
     167                $user_passwd = strtr($user_passwd, array("\'"=>"'"));
     168               
    165169                if (@ldap_bind($this->cnx,$this->ldap_name($user),$user_passwd)){
    166170                        return true;
     
    182186                $ld_group = $this->config['ld_group'];
    183187               
    184                 $sr=@ldap_search($this->cnx, $this->config['full_groupbranch'], "($ld_group=$to_search)", array('dn'),0,0);
     188                $sr=@ldap_search($this->cnx, $this->full_groupbranch, "($ld_group=$to_search)", array('dn'),0,0);
    185189                $groups = @ldap_get_entries($this->cnx, $sr);
    186190                $result = array();
     
    191195        }
    192196       
     197/*      $filter="(sAMAccountName=".$user.")";
     198
     199                if(($results=ldap_search($this->cnx,$this->config['basedn'],$filter,array('dn',$this->config['ld_attr'])))!==false)
     200                {       $firstEntry=ldap_first_entry($this->cnx,$results);
     201                       
     202                        if($firstEntry==null)
     203                        {       return false;
     204                        }
     205                        else
     206                        {       if(($userDn=ldap_get_dn($this->cnx,$firstEntry))!==false)
     207                                {       if(($isBound=wpDirAuth_bindTest($this->cnx,$userDn,$user_passwd,$this->config['basedn']))===true)
     208                                        {       return true;
     209                                        }
     210                                        else
     211                                        {       return false;
     212                                        }
     213                                }
     214                        }
     215                } */
     216       
     217       
     218       
    193219        public function ldap_search_dn($to_search){
    194220                $ld_attr = $this->config['ld_attr'];
    195221               
    196                 $sr=@ldap_search($this->cnx, $this->config['full_usersbranch'], "($ld_attr=$to_search)", array('dn','mail'),0,0);
    197                 $entry = @ldap_get_entries($this->cnx, $sr);
    198                
    199                 if (!empty($entry[0]['dn'])) {
    200                         return $entry[0]['dn'];
    201                         }
    202                 else { return False; }
     222                if(($results=@ldap_search($this->cnx,$this->config['basedn'],"($ld_attr=$to_search)",array('dn','mail',$ld_attr)))!==false)
     223                //$sr=          @ldap_search($this->cnx, $this->full_usersbranch, "($ld_attr=$to_search)", array('dn','mail'),0,0);
     224                $entry = @ldap_first_entry($this->cnx, $results);
     225               
     226                if($entry==null)
     227                {
     228                return false;
     229                }
     230               
     231                else
     232                {       if(($userDn=ldap_get_dn($this->cnx,$entry))!==false)
     233                        {
     234                                return $userDN;
     235                        }
     236                        else
     237                        {
     238                                return null;
     239                        }
     240                }
     241//              if (!empty($entry[0]['dn'])) {
     242//                      return $entry[0]['dn'];
     243//                      }
     244//              else { return False; }
    203245        }
    204246       
  • extensions/Ldap_Login/language/fr_FR/plugin.lang.php

    r28535 r29135  
    3030
    3131$lang['Ldap attributes'] = 'Attributs ldap';
    32 $lang['Base DN'] = 'Arbre ldap à explorer où rechercher les utilisateurs (ex : ou=users,dc=exemple,dc=com)';
     32$lang['Base DN'] = 'Arbre ldap à explorer où rechercher les utilisateurs et les groupes (ex : dc=exemple,dc=com)';
    3333$lang['Attribute corresponding to the user name'] = 'Attribut correspondant au nom d\'utilisateur';
    3434
Note: See TracChangeset for help on using the changeset viewer.