Changeset 0102742 in github


Ignore:
Timestamp:
Sep 21, 2009 7:50:53 AM (4 years ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
3e2bc6a
Parents:
104a14d
Message:
  • Added 'ldap_debug' option + small change to not rely on rcube_config inside rcube_ldap class
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    r587444f r0102742  
    22=========================== 
    33 
     4- Added 'ldap_debug' option 
    45- Fix "Empty startup greeting" bug (#1486085) 
    56- Fix setting user name in 'new_user_identity' plugin (#1486137) 
  • config/main.inc.php.dist

    r4d97074 r0102742  
    130130// Log IMAP conversation to <log_dir>/imap or to syslog 
    131131$rcmail_config['imap_debug'] = false; 
     132 
     133// Log LDAP conversation to <log_dir>/ldap or to syslog 
     134$rcmail_config['ldap_debug'] = false; 
    132135 
    133136// Log SMTP conversation to <log_dir>/smtp or to syslog 
  • program/include/rcmail.php

    rbdab2c5 r0102742  
    267267    } 
    268268    else if ($id && $ldap_config[$id]) { 
    269       $contacts = new rcube_ldap($ldap_config[$id]); 
     269      $contacts = new rcube_ldap($ldap_config[$id], $this->config->get('ldap_debug'), $this->config->mail_domain($_SESSION['imap_host'])); 
    270270    } 
    271271    else if ($id === '0') { 
     
    276276      foreach ($ldap_config as $id => $prop) { 
    277277        if (!$writeable || $prop['writable']) { 
    278           $contacts = new rcube_ldap($prop); 
     278          $contacts = new rcube_ldap($prop, $this->config->get('ldap_debug'), $this->config->mail_domain($_SESSION['imap_host'])); 
    279279          break; 
    280280        } 
  • program/include/rcube_ldap.php

    r2b82072 r0102742  
    3535  var $ldap_result = null; 
    3636  var $sort_col = ''; 
     37  var $mail_domain = ''; 
     38  var $debug = false; 
    3739   
    3840  /** public properties */ 
     
    4749   * Object constructor 
    4850   * 
    49    * @param array LDAP connection properties 
     51   * @param array       LDAP connection properties 
     52   * @param boolean     Enables debug mode 
     53   * @param string      Current user mail domain name 
    5054   * @param integer User-ID 
    5155   */ 
    52   function __construct($p) 
     56  function __construct($p, $debug=false, $mail_domain=NULL) 
    5357  { 
    5458    $this->prop = $p; 
     
    6670 
    6771    $this->sort_col = $p['sort']; 
     72    $this->debug = $debug; 
     73    $this->mail_domain = $mail_domain; 
    6874 
    6975    $this->connect(); 
     
    9298    foreach ($this->prop['hosts'] as $host) 
    9399    { 
     100      $this->_debug("C: Connect [$host".($this->prop['port'] ? ':'.$this->prop['port'] : '')."]"); 
     101 
    94102      if ($lc = @ldap_connect($host, $this->prop['port'])) 
    95103      { 
     
    98106            continue; 
    99107 
     108        $this->_debug("S: OK"); 
     109 
    100110        ldap_set_option($lc, LDAP_OPT_PROTOCOL_VERSION, $this->prop['ldap_version']); 
    101111        $this->prop['host'] = $host; 
     
    103113        break; 
    104114      } 
     115      $this->_debug("S: NOT OK"); 
    105116    } 
    106117     
     
    153164    } 
    154165     
     166    $this->_debug("C: Bind [dn: $dn] [pass: $pass]"); 
     167     
    155168    if (@ldap_bind($this->conn, $dn, $pass)) { 
     169      $this->_debug("S: OK"); 
    156170      return true; 
    157171    } 
     172 
     173    $this->_debug("S: ".ldap_error($this->conn)); 
    158174 
    159175    raise_error(array( 
     
    174190    if ($this->conn) 
    175191    { 
     192      $this->_debug("C: Close"); 
    176193      ldap_unbind($this->conn); 
    177194      $this->conn = null; 
     
    389406    if ($this->conn && $dn) 
    390407    { 
     408      $this->_debug("C: Read [dn: ".base64_decode($dn)."] [(objectclass=*)]"); 
     409     
    391410      if ($this->ldap_result = @ldap_read($this->conn, base64_decode($dn), '(objectclass=*)', array_values($this->fieldmap))) 
    392411        $entry = ldap_first_entry($this->conn, $this->ldap_result); 
     412      else 
     413        $this->_debug("S: ".ldap_error($this->conn)); 
    393414 
    394415      if ($entry && ($rec = ldap_get_attributes($this->conn, $entry))) 
    395416      { 
     417        $this->_debug("S: OK"); 
     418 
    396419        $rec = array_change_key_case($rec, CASE_LOWER); 
    397420 
     
    438461    // Build the new entries DN. 
    439462    $dn = $this->prop['LDAP_rdn'].'='.$newentry[$this->prop['LDAP_rdn']].','.$this->prop['base_dn']; 
     463 
     464    $this->_debug("C: Add [dn: $dn]: ".print_r($newentry, true)); 
     465 
    440466    $res = ldap_add($this->conn, $dn, $newentry); 
    441467    if ($res === FALSE) { 
     468      $this->_debug("S: ".ldap_error($this->conn)); 
    442469      return false; 
    443470    } // end if 
     471 
     472    $this->_debug("S: OK"); 
    444473 
    445474    return base64_encode($dn); 
     
    493522    if (!empty($deletedata)) { 
    494523      // Delete the fields. 
    495       if (!ldap_mod_del($this->conn, $dn, $deletedata)) 
     524      $this->_debug("C: Delete [dn: $dn]: ".print_r($deletedata, true)); 
     525      if (!ldap_mod_del($this->conn, $dn, $deletedata)) { 
     526        $this->_debug("S: ".ldap_error($this->conn)); 
    496527        return false; 
     528      } 
     529      $this->_debug("S: OK"); 
    497530    } // end if 
    498531 
     
    508541      // Replace the fields. 
    509542      if (!empty($replacedata)) { 
    510         if (!ldap_mod_replace($this->conn, $dn, $replacedata)) 
     543        $this->_debug("C: Replace [dn: $dn]: ".print_r($replacedata, true)); 
     544        if (!ldap_mod_replace($this->conn, $dn, $replacedata)) { 
     545          $this->_debug("S: ".ldap_error($this->conn)); 
    511546          return false; 
     547        } 
     548        $this->_debug("S: OK"); 
    512549      } // end if 
    513550    } // end if 
     
    515552    if (!empty($newdata)) { 
    516553      // Add the fields. 
    517       if (!ldap_mod_add($this->conn, $dn, $newdata)) 
     554      $this->_debug("C: Add [dn: $dn]: ".print_r($newdata, true)); 
     555      if (!ldap_mod_add($this->conn, $dn, $newdata)) { 
     556        $this->_debug("S: ".ldap_error($this->conn)); 
    518557        return false; 
     558      } 
     559      $this->_debug("S: OK"); 
    519560    } // end if 
    520561 
    521562    // Handle RDN change 
    522563    if (!empty($newrdn)) { 
    523       if (@ldap_rename($this->conn, $dn, $newrdn, NULL, TRUE)) 
     564      $this->_debug("C: Rename [dn: $dn] [dn: $newrdn]"); 
     565      if (@ldap_rename($this->conn, $dn, $newrdn, NULL, TRUE)) { 
     566        $this->_debug("S: ".ldap_error($this->conn)); 
    524567        return base64_encode($newdn); 
     568      } 
     569      $this->_debug("S: OK"); 
    525570    } 
    526571 
     
    544589    foreach ($dns as $id) { 
    545590      $dn = base64_decode($id); 
     591      $this->_debug("C: Delete [dn: $dn]"); 
    546592      // Delete the record. 
    547593      $res = ldap_delete($this->conn, $dn); 
    548594      if ($res === FALSE) { 
     595        $this->_debug("S: ".ldap_error($this->conn)); 
    549596        return false; 
    550597      } // end if 
     598      $this->_debug("S: OK"); 
    551599    } // end foreach 
    552600 
     
    567615      $function = $this->prop['scope'] == 'sub' ? 'ldap_search' : ($this->prop['scope'] == 'base' ? 'ldap_read' : 'ldap_list'); 
    568616 
    569       if ($this->ldap_result = @$function($this->conn, $this->prop['base_dn'], $filter, array_values($this->fieldmap), 0, 0)) 
     617      $this->_debug("C: Search [".$filter."]"); 
     618 
     619      if ($this->ldap_result = @$function($this->conn, $this->prop['base_dn'], $filter, array_values($this->fieldmap), 0, 0)) { 
     620        $this->_debug("S: ".ldap_count_entries($this->conn, $this->ldap_result)." record(s)"); 
    570621        return true; 
     622      } else 
     623        $this->_debug("S: ".ldap_error($this->conn)); 
    571624    } 
    572625     
     
    590643    { 
    591644      if ($rec[$lf]['count']) { 
    592         if ($rf == 'email' && !strpos($rec[$lf][0], '@')) 
    593           $out[$rf] = sprintf('%s@%s', $rec[$lf][0] , $RCMAIL->config->mail_domain($_SESSION['imap_host'])); 
     645        if ($rf == 'email' && $mail_domain && !strpos($rec[$lf][0], '@')) 
     646          $out[$rf] = sprintf('%s@%s', $rec[$lf][0], $this->mail_domain); 
    594647        else 
    595648          $out[$rf] = $rec[$lf][0]; 
     
    628681 
    629682  /** 
     683   * @access private 
     684   */ 
     685  private function _debug($str) 
     686  { 
     687    if ($this->debug) 
     688      write_log('ldap', $str); 
     689  } 
     690   
     691 
     692  /** 
    630693   * @static 
    631694   */ 
Note: See TracChangeset for help on using the changeset viewer.