| | |
| | | $host = rcube_utils::idn_to_ascii(rcube_utils::parse_host($host)); |
| | | $hostname = $host . ($this->config['port'] ? ':'.$this->config['port'] : ''); |
| | | |
| | | $this->_debug("C: Connect [$hostname] [{$this->config['name']}]"); |
| | | $this->_debug("C: Connect to $hostname [{$this->config['name']}]"); |
| | | |
| | | if ($lc = @ldap_connect($host, $this->config['port'])) { |
| | | if ($this->config['use_tls'] === true) |
| | |
| | | $method = 'DIGEST-MD5'; |
| | | } |
| | | |
| | | $this->_debug("C: Bind [mech: $method, authc: $authc, authz: $authz] [pass: $pass]"); |
| | | $this->_debug("C: SASL Bind [mech: $method, authc: $authc, authz: $authz, pass: $pass]"); |
| | | |
| | | if (ldap_sasl_bind($this->conn, NULL, $pass, $method, NULL, $authc, $authz)) { |
| | | $this->_debug("S: OK"); |
| | |
| | | return false; |
| | | } |
| | | |
| | | $this->_debug("C: Bind [dn: $dn] [pass: $pass]"); |
| | | $this->_debug("C: Bind $dn [pass: $pass]"); |
| | | |
| | | if (@ldap_bind($this->conn, $dn, $pass)) { |
| | | $this->_debug("S: OK"); |
| | |
| | | $rec = null; |
| | | |
| | | if ($this->conn && $dn) { |
| | | $this->_debug("C: Read [dn: $dn] [(objectclass=*)]"); |
| | | $this->_debug("C: Read $dn [(objectclass=*)]"); |
| | | |
| | | if ($ldap_result = @ldap_read($this->conn, $dn, '(objectclass=*)', $this->attributes)) { |
| | | $this->_debug("S: OK"); |
| | |
| | | if (empty($filter)) |
| | | $filter = $filter = '(objectclass=*)'; |
| | | |
| | | $this->_debug("C: Search [$filter][dn: $base_dn]"); |
| | | $this->_debug("C: Search $base_dn for $filter"); |
| | | |
| | | $function = self::scope2func($scope, $ns_function); |
| | | |
| | |
| | | */ |
| | | public function add($dn, $entry) |
| | | { |
| | | $this->_debug("C: Add [dn: $dn]: ".print_r($entry, true)); |
| | | $this->_debug("C: Add $dn: ".print_r($entry, true)); |
| | | |
| | | $res = ldap_add($this->conn, $dn, $entry); |
| | | if ($res === false) { |
| | |
| | | */ |
| | | public function delete($dn) |
| | | { |
| | | $this->_debug("C: Delete [dn: $dn]"); |
| | | $this->_debug("C: Delete $dn"); |
| | | |
| | | $res = ldap_delete($this->conn, $dn); |
| | | if ($res === false) { |
| | |
| | | */ |
| | | public function mod_replace($dn, $entry) |
| | | { |
| | | $this->_debug("C: Replace [dn: $dn]: ".print_r($entry, true)); |
| | | $this->_debug("C: Replace $dn: ".print_r($entry, true)); |
| | | |
| | | if (!ldap_mod_replace($this->conn, $dn, $entry)) { |
| | | $this->_debug("S: ".ldap_error($this->conn)); |
| | |
| | | */ |
| | | public function mod_add($dn, $entry) |
| | | { |
| | | $this->_debug("C: Add [dn: $dn]: ".print_r($entry, true)); |
| | | $this->_debug("C: Add $dn: ".print_r($entry, true)); |
| | | |
| | | if (!ldap_mod_add($this->conn, $dn, $entry)) { |
| | | $this->_debug("S: ".ldap_error($this->conn)); |
| | |
| | | */ |
| | | public function mod_del($dn, $entry) |
| | | { |
| | | $this->_debug("C: Delete [dn: $dn]: ".print_r($entry, true)); |
| | | $this->_debug("C: Delete $dn: ".print_r($entry, true)); |
| | | |
| | | if (!ldap_mod_del($this->conn, $dn, $entry)) { |
| | | $this->_debug("S: ".ldap_error($this->conn)); |
| | |
| | | */ |
| | | public function rename($dn, $newrdn, $newparent = null, $deleteoldrdn = true) |
| | | { |
| | | $this->_debug("C: Rename [dn: $dn] [dn: $newrdn]"); |
| | | $this->_debug("C: Rename $dn to $newrdn"); |
| | | |
| | | if (!ldap_rename($this->conn, $dn, $newrdn, $newparent, $deleteoldrdn)) { |
| | | $this->_debug("S: ".ldap_error($this->conn)); |
| | |
| | | public function list_entries($dn, $filter, $attributes = array('dn')) |
| | | { |
| | | $list = array(); |
| | | $this->_debug("C: List [dn: $dn] [{$filter}]"); |
| | | $this->_debug("C: List $dn [{$filter}]"); |
| | | |
| | | if ($result = ldap_list($this->conn, $dn, $filter, $attributes)) { |
| | | $list = ldap_get_entries($this->conn, $result); |
| | |
| | | */ |
| | | public function read_entries($dn, $filter, $attributes = null) |
| | | { |
| | | $this->_debug("C: Read [dn: $dn] [{$filter}]"); |
| | | $this->_debug("C: Read $dn [{$filter}]"); |
| | | |
| | | if ($this->conn && $dn) { |
| | | if (!$attributes) |
| | |
| | | $sort_ctrl = array('oid' => "1.2.840.113556.1.4.473", 'value' => self::_sort_ber_encode((array)$sort)); |
| | | $vlv_ctrl = array('oid' => "2.16.840.1.113730.3.4.9", 'value' => self::_vlv_ber_encode(($offset = ($list_page-1) * $page_size + 1), $page_size, $search), 'iscritical' => true); |
| | | |
| | | $this->_debug("C: set controls sort=" . join(' ', unpack('H'.(strlen($sort_ctrl['value'])*2), $sort_ctrl['value'])) . " ($sort[0]);" |
| | | $this->_debug("C: Set controls sort=" . join(' ', unpack('H'.(strlen($sort_ctrl['value'])*2), $sort_ctrl['value'])) . " ($sort[0]);" |
| | | . " vlv=" . join(' ', (unpack('H'.(strlen($vlv_ctrl['value'])*2), $vlv_ctrl['value']))) . " ($offset/$page_size; $search)"); |
| | | |
| | | if (!ldap_set_option($this->conn, LDAP_OPT_SERVER_CONTROLS, array($sort_ctrl, $vlv_ctrl))) { |
| | |
| | | $vlv_config = $this->_read_vlv_config(); |
| | | |
| | | if ($vlv = $vlv_config[$base_dn]) { |
| | | $this->_debug("D: Found a VLV for base_dn: " . $base_dn); |
| | | $this->_debug("D: Found a VLV for $base_dn"); |
| | | |
| | | if ($vlv['filter'] == strtolower($filter) || stripos($filter, '(&'.$vlv['filter'].'(') === 0) { |
| | | $this->_debug("D: Filter matches"); |
| | |
| | | } |
| | | } |
| | | else { |
| | | $this->_debug("D: No VLV for base dn " . $base_dn); |
| | | $this->_debug("D: No VLV for $base_dn"); |
| | | } |
| | | |
| | | return false; |
| | |
| | | if (is_array($this->vlv_config)) { |
| | | return $this->vlv_config; |
| | | } |
| | | |
| | | |
| | | if ($this->cache && ($cached_config = $this->cache->get('vlvconfig'))) { |
| | | $this->vlv_config = $cached_config; |
| | | return $this->vlv_config; |