| | |
| | | <?php |
| | | |
| | | /* |
| | | +-----------------------------------------------------------------------+ |
| | | | program/include/rcube_ldap.inc | |
| | |
| | | if (preg_match('/^(.+)_field$/', $prop, $matches)) |
| | | $this->fieldmap[$matches[1]] = $value; |
| | | |
| | | // $this->filter = "(dn=*)"; |
| | | $this->connect(); |
| | | } |
| | | |
| | |
| | | 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; |
| | |
| | | */ |
| | | 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; |
| | | } |
| | | |
| | |
| | | function close() |
| | | { |
| | | if ($this->conn) |
| | | { |
| | | @ldap_unbind($this->conn); |
| | | $this->conn = null; |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | 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(); |
| | |
| | | } |
| | | $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); |
| | |
| | | |
| | | } |
| | | |
| | | ?> |
| | | ?> |