/** * Attach node to an LDAP connection * * This is an offline method. * * @uses Zend_Ldap_Dn::isChildOf() * @param Zend_Ldap $ldap * @return Zend_Ldap_Node Provides a fluid interface * @throws Zend_Ldap_Exception */ public function attachLdap(Zend_Ldap $ldap) { if (!Zend_Ldap_Dn::isChildOf($this->_getDn(), $ldap->getBaseDn())) { /** * @see Zend_Ldap_Exception */ require_once PHP_LIBRARY_PATH . 'Zend/Ldap/Exception.php'; throw new Zend_Ldap_Exception(null, 'LDAP connection is not responsible for given node.', Zend_Ldap_Exception::LDAP_OTHER); } if ($ldap !== $this->_ldap) { $this->_ldap = $ldap; if (is_array($this->_children)) { foreach ($this->_children as $child) { $child->attachLdap($ldap); } } } return $this; }
/** * Attach node to an LDAP connection * * This is an offline method. * * @uses Zend_Ldap_Dn::isChildOf() * @param Zend_Ldap $ldap * @return Zend_Ldap_Node Provides a fluent interface * @throws Zend_Ldap_Exception */ public function attachLdap(Zend_Ldap $ldap) { if (!Zend_Ldap_Dn::isChildOf($this->_getDn(), $ldap->getBaseDn())) { /** * @see Zend_Ldap_Exception */ throw new Zend_Ldap_Exception(null, 'LDAP connection is not responsible for given node.', Zend_Ldap_Exception::LDAP_OTHER); } if ($ldap !== $this->_ldap) { $this->_ldap = $ldap; if (is_array($this->_children)) { foreach ($this->_children as $child) { /* @var Zend_Ldap_Node $child */ $child->attachLdap($ldap); } } } return $this; }
public function testIsChildOfParentDnLonger() { $dn1 = 'dc=example,dc=de'; $dn2 = 'cb=name1,cn=name2,dc=example,dc=org'; $this->assertFalse(Zend_Ldap_Dn::isChildOf($dn1, $dn2)); }
/** * (non-PHPdoc) */ protected function _getSpecialResultDataFromLdap() { $filter = "&"; foreach ($this->_simpleMailConfig['skeleton'] as $attr => $val) { if (is_array($val)) { foreach ($val as $val_array) { $filter .= '(' . $attr . '=' . $val_array . ')'; } } else { $filter .= '(' . $attr . '=' . $val . ')'; } } $ldap = $this->_ldap->searchEntries(Zend_Ldap_Filter::string($filter), $this->_simpleMailConfig['base'], $this->_simpleMailConfig['scope'], array()); /* Make sure, the managed rdn is last in array and properties are * ultimately read from this rdn (if entries are doubled) * * Order of array matters: * - all entries anywhere * - entries within the storage path * - the exact managed dn */ $this->_ldapRawData = array(); $managedPath = Zend_Ldap_Dn::fromString($this->_simpleMailConfig['storage_base'], Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER); $managedDn = Zend_Ldap_Dn::fromString($this->_simpleMailConfig['storage_rdn'] . ',' . $this->_simpleMailConfig['storage_base'], Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER); $managedDnExisting = false; foreach ($ldap as $dn) { $dnArr = Zend_Ldap_Dn::fromString($dn['dn'], Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER); if ($dnArr->toString() == $managedDn->toString()) { array_push($this->_ldapRawData, $dn); $managedDnExisting = true; } elseif (Zend_Ldap_Dn::isChildOf($dnArr, $managedPath)) { $managedDnExisting === true ? array_splice($this->_ldapRawData, -1, 0, array($dn)) : array_push($this->_ldapRawData, $dn); } else { $dn['simplemail_readonly'] = true; array_unshift($this->_ldapRawData, $dn); } } if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' simpleMail - Tinebase_EmailUser combined with ldap: ' . print_r($this->_ldapRawData, true)); } }