thomascube
2008-04-05 e70d6ea64e711096af36b1234f8545b870ea5f45
program/include/rcube_ldap.inc
@@ -1,5 +1,4 @@
<?php
/*
 +-----------------------------------------------------------------------+
 | program/include/rcube_ldap.inc                                        |
@@ -58,7 +57,6 @@
      if (preg_match('/^(.+)_field$/', $prop, $matches))
        $this->fieldmap[$matches[1]] = $value;
    
    // $this->filter = "(dn=*)";
    $this->connect();
  }
@@ -87,11 +85,14 @@
    if (!is_array($this->prop['hosts']))
      $this->prop['hosts'] = array($this->prop['hosts']);
    if (empty($this->prop['ldap_version']))
      $this->prop['ldap_version'] = 3;
    foreach ($this->prop['hosts'] as $host)
    {
      if ($lc = @ldap_connect($host, $this->prop['port']))
      {
        ldap_set_option($lc, LDAP_OPT_PROTOCOL_VERSION, $this->prop['port']);
        ldap_set_option($lc, LDAP_OPT_PROTOCOL_VERSION, $this->prop['ldap_version']);
        $this->prop['host'] = $host;
        $this->conn = $lc;
        break;
@@ -118,20 +119,20 @@
   */
  function bind($dn, $pass)
  {
    if (!$this->conn)
    if (!$this->conn) {
      return false;
    }
    
    if (@ldap_bind($this->conn, $dn, $pass))
    if (ldap_bind($this->conn, $dn, $pass)) {
      return true;
    else
    {
      raise_error(array(
    }
    raise_error(array(
        'code' => ldap_errno($this->conn),
        'type' => 'ldap',
        'message' => "Bind failed for dn=$dn: ".ldap_error($this->conn)),
      true);
    }
        true);
    return false;
  }
@@ -142,7 +143,10 @@
  function close()
  {
    if ($this->conn)
    {
      @ldap_unbind($this->conn);
      $this->conn = null;
    }
  }
@@ -212,6 +216,13 @@
   */
  function list_records($cols=null, $subset=0)
  {
    // add general filter to query
    if (!empty($this->prop['filter']))
    {
      $filter = $this->prop['filter'];
      $this->set_search_set($filter);
    }
    // exec LDAP search if no result resource is stored
    if ($this->conn && !$this->ldap_result)
      $this->_exec_search();
@@ -274,9 +285,12 @@
    }
    $filter .= ')';
    
    // avoid double-wildcard if $value is empty
    $filter = preg_replace('/\*+/', '*', $filter);
    // add general filter to query
    if (!empty($this->prop['filter']))
      $filter = '(&'.$this->prop['filter'] . $filter . ')';
      $filter = '(&(' . preg_replace('/^\(|\)$/', '', $this->prop['filter']) . ')' . $filter . ')';
    // set filter string and execute search
    $this->set_search_set($filter);
@@ -442,4 +456,4 @@
}
?>
?>