| | |
| | | /** private properties */ |
| | | protected $cache = null; |
| | | protected $attributes = array('dn'); |
| | | protected $error; |
| | | |
| | | function __construct($config = null) |
| | | { |
| | |
| | | |
| | | case LOG_ERR: |
| | | case LOG_WARNING: |
| | | $this->error = $msg; |
| | | rcube::raise_error($msg, true, false); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Returns the last LDAP error occurred |
| | | * |
| | | * @return mixed Error message string or null if no error occured |
| | | */ |
| | | function get_error() |
| | | { |
| | | return $this->error; |
| | | } |
| | | |
| | | /** |
| | |
| | | $this->_debug("C: Replace $dn: ".print_r($entry, true)); |
| | | |
| | | if (!ldap_mod_replace($this->conn, $dn, $entry)) { |
| | | $this->_debug("S: ".ldap_error($this->conn)); |
| | | $this->_error("ldap_mod_replace() failed with " . ldap_error($this->conn)); |
| | | return false; |
| | | } |
| | | |
| | |
| | | $this->_debug("C: Add $dn: ".print_r($entry, true)); |
| | | |
| | | if (!ldap_mod_add($this->conn, $dn, $entry)) { |
| | | $this->_debug("S: ".ldap_error($this->conn)); |
| | | $this->_error("ldap_mod_add() failed with " . ldap_error($this->conn)); |
| | | return false; |
| | | } |
| | | |
| | |
| | | $this->_debug("C: Delete $dn: ".print_r($entry, true)); |
| | | |
| | | if (!ldap_mod_del($this->conn, $dn, $entry)) { |
| | | $this->_debug("S: ".ldap_error($this->conn)); |
| | | $this->_error("ldap_mod_del() failed with " . ldap_error($this->conn)); |
| | | return false; |
| | | } |
| | | |
| | |
| | | $this->_debug("C: Rename $dn to $newrdn"); |
| | | |
| | | if (!ldap_rename($this->conn, $dn, $newrdn, $newparent, $deleteoldrdn)) { |
| | | $this->_debug("S: ".ldap_error($this->conn)); |
| | | $this->_error("ldap_rename() failed with " . ldap_error($this->conn)); |
| | | return false; |
| | | } |
| | | |
| | |
| | | $list = ldap_get_entries($this->conn, $result); |
| | | |
| | | if ($list === false) { |
| | | $this->_debug("S: ".ldap_error($this->conn)); |
| | | $this->_error("ldap_get_entries() failed with " . ldap_error($this->conn)); |
| | | return array(); |
| | | } |
| | | |
| | |
| | | $this->_debug("S: $count record(s)"); |
| | | } |
| | | else { |
| | | $this->_debug("S: ".ldap_error($this->conn)); |
| | | $this->_error("ldap_list() failed with " . ldap_error($this->conn)); |
| | | } |
| | | |
| | | return $list; |
| | |
| | | if ($this->conn && $dn) { |
| | | $result = @ldap_read($this->conn, $dn, $filter, $attributes, 0, (int)$this->config['sizelimit'], (int)$this->config['timelimit']); |
| | | if ($result === false) { |
| | | $this->_debug("S: ".ldap_error($this->conn)); |
| | | $this->_error("ldap_read() failed with " . ldap_error($this->conn)); |
| | | return false; |
| | | } |
| | | |
| | |
| | | |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * Turn an LDAP entry into a regular PHP array with attributes as keys. |
| | | * |
| | | * @param array $entry Attributes array as retrieved from ldap_get_attributes() or ldap_get_entries() |
| | | * |
| | | * @return array Hash array with attributes as keys |
| | | */ |
| | | public static function normalize_entry($entry) |
| | | { |
| | | if (!isset($entry['count'])) { |
| | | return $entry; |
| | | } |
| | | |
| | | $rec = array(); |
| | | |
| | | for ($i=0; $i < $entry['count']; $i++) { |
| | | $attr = $entry[$i]; |
| | | if ($entry[$attr]['count'] == 1) { |
| | | switch ($attr) { |
| | | case 'objectclass': |
| | | $rec[$attr] = array(strtolower($entry[$attr][0])); |
| | | break; |
| | | default: |
| | | $rec[$attr] = $entry[$attr][0]; |
| | | break; |
| | | } |
| | | } |
| | | else { |
| | | for ($j=0; $j < $entry[$attr]['count']; $j++) { |
| | | $rec[$attr][$j] = $entry[$attr][$j]; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return $rec; |
| | | } |
| | | } |
| | | |
| | | // for backward compat. |