|
|
@@ -28,8 +28,8 @@
|
|
|
*/
|
|
|
class Zend_Ldap
|
|
|
{
|
|
|
- const SEARCH_SCOPE_SUB = 1;
|
|
|
- const SEARCH_SCOPE_ONE = 2;
|
|
|
+ const SEARCH_SCOPE_SUB = 1;
|
|
|
+ const SEARCH_SCOPE_ONE = 2;
|
|
|
const SEARCH_SCOPE_BASE = 3;
|
|
|
|
|
|
const ACCTNAME_FORM_DN = 1;
|
|
|
@@ -72,18 +72,18 @@ class Zend_Ldap
|
|
|
*/
|
|
|
protected $_schema = null;
|
|
|
|
|
|
- /**
|
|
|
+ /**
|
|
|
* @deprecated will be removed, use {@see Zend_Ldap_Filter_Abstract::escapeValue()}
|
|
|
* @param string $str The string to escape.
|
|
|
* @return string The escaped string
|
|
|
*/
|
|
|
public static function filterEscape($str)
|
|
|
{
|
|
|
- /**
|
|
|
- * @see Zend_Ldap_Filter_Abstract
|
|
|
- */
|
|
|
- require_once 'Zend/Ldap/Filter/Abstract.php';
|
|
|
- return Zend_Ldap_Filter_Abstract::escapeValue($str);
|
|
|
+ /**
|
|
|
+ * @see Zend_Ldap_Filter_Abstract
|
|
|
+ */
|
|
|
+ require_once 'Zend/Ldap/Filter/Abstract.php';
|
|
|
+ return Zend_Ldap_Filter_Abstract::escapeValue($str);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -96,15 +96,15 @@ class Zend_Ldap
|
|
|
*/
|
|
|
public static function explodeDn($dn, array &$keys = null, array &$vals = null)
|
|
|
{
|
|
|
- /**
|
|
|
- * @see Zend_Ldap_Dn
|
|
|
+ /**
|
|
|
+ * @see Zend_Ldap_Dn
|
|
|
*/
|
|
|
- require_once 'Zend/Ldap/Dn.php';
|
|
|
+ require_once 'Zend/Ldap/Dn.php';
|
|
|
return Zend_Ldap_Dn::checkDn($dn, $keys, $vals);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Constructor.
|
|
|
+ * Constructor.
|
|
|
*
|
|
|
* @param array|Zend_Config $options Options used in connecting, binding, etc.
|
|
|
* @return void
|
|
|
@@ -115,13 +115,13 @@ class Zend_Ldap
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Destructor.
|
|
|
- *
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function __destruct()
|
|
|
- {
|
|
|
- $this->disconnect();
|
|
|
+ * Destructor.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function __destruct()
|
|
|
+ {
|
|
|
+ $this->disconnect();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -225,9 +225,9 @@ class Zend_Ldap
|
|
|
*/
|
|
|
public function setOptions($options)
|
|
|
{
|
|
|
- if ($options instanceof Zend_Config) {
|
|
|
- $options = $options->toArray();
|
|
|
- }
|
|
|
+ if ($options instanceof Zend_Config) {
|
|
|
+ $options = $options->toArray();
|
|
|
+ }
|
|
|
|
|
|
$permittedOptions = array(
|
|
|
'host' => null,
|
|
|
@@ -279,7 +279,7 @@ class Zend_Ldap
|
|
|
require_once 'Zend/Ldap/Exception.php';
|
|
|
throw new Zend_Ldap_Exception(null, "Unknown Zend_Ldap option: $key");
|
|
|
}
|
|
|
- $this->_options = $permittedOptions;
|
|
|
+ $this->_options = $permittedOptions;
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
@@ -439,9 +439,9 @@ class Zend_Ldap
|
|
|
*/
|
|
|
protected function _getAccountFilter($acctname)
|
|
|
{
|
|
|
- /**
|
|
|
- * @see Zend_Ldap_Filter_Abstract
|
|
|
- */
|
|
|
+ /**
|
|
|
+ * @see Zend_Ldap_Filter_Abstract
|
|
|
+ */
|
|
|
require_once 'Zend/Ldap/Filter/Abstract.php';
|
|
|
$this->_splitName($acctname, $dname, $aname);
|
|
|
$accountFilterFormat = $this->_getAccountFilterFormat();
|
|
|
@@ -493,7 +493,7 @@ class Zend_Ldap
|
|
|
/**
|
|
|
* @see Zend_Ldap_Dn
|
|
|
*/
|
|
|
- require_once 'Zend/Ldap/Dn.php';
|
|
|
+ require_once 'Zend/Ldap/Dn.php';
|
|
|
if (Zend_Ldap_Dn::checkDn($acctname)) return $acctname;
|
|
|
$acctname = $this->getCanonicalAccountName($acctname, Zend_Ldap::ACCTNAME_FORM_USERNAME);
|
|
|
$acct = $this->_getAccount($acctname, array('dn'));
|
|
|
@@ -507,18 +507,18 @@ class Zend_Ldap
|
|
|
protected function _isPossibleAuthority($dname)
|
|
|
{
|
|
|
if ($dname === null) {
|
|
|
- return true;
|
|
|
+ return true;
|
|
|
}
|
|
|
$accountDomainName = $this->_getAccountDomainName();
|
|
|
$accountDomainNameShort = $this->_getAccountDomainNameShort();
|
|
|
if ($accountDomainName === null && $accountDomainNameShort === null) {
|
|
|
- return true;
|
|
|
+ return true;
|
|
|
}
|
|
|
if (strcasecmp($dname, $accountDomainName) == 0) {
|
|
|
- return true;
|
|
|
+ return true;
|
|
|
}
|
|
|
if (strcasecmp($dname, $accountDomainNameShort) == 0) {
|
|
|
- return true;
|
|
|
+ return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
@@ -624,28 +624,28 @@ class Zend_Ldap
|
|
|
$this->bind();
|
|
|
}
|
|
|
|
|
|
- $accounts = $this->search($accountFilter, $baseDn, self::SEARCH_SCOPE_SUB, $attrs);
|
|
|
- $count = $accounts->count();
|
|
|
- if ($count === 1) {
|
|
|
- $acct = $accounts->getFirst();
|
|
|
- $accounts->close();
|
|
|
- return $acct;
|
|
|
- } else if ($count === 0) {
|
|
|
- /**
|
|
|
- * @see Zend_Ldap_Exception
|
|
|
- */
|
|
|
- require_once 'Zend/Ldap/Exception.php';
|
|
|
+ $accounts = $this->search($accountFilter, $baseDn, self::SEARCH_SCOPE_SUB, $attrs);
|
|
|
+ $count = $accounts->count();
|
|
|
+ if ($count === 1) {
|
|
|
+ $acct = $accounts->getFirst();
|
|
|
+ $accounts->close();
|
|
|
+ return $acct;
|
|
|
+ } else if ($count === 0) {
|
|
|
+ /**
|
|
|
+ * @see Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ require_once 'Zend/Ldap/Exception.php';
|
|
|
$code = Zend_Ldap_Exception::LDAP_NO_SUCH_OBJECT;
|
|
|
- $str = "No object found for: $accountFilter";
|
|
|
- } else {
|
|
|
- /**
|
|
|
- * @see Zend_Ldap_Exception
|
|
|
- */
|
|
|
- require_once 'Zend/Ldap/Exception.php';
|
|
|
+ $str = "No object found for: $accountFilter";
|
|
|
+ } else {
|
|
|
+ /**
|
|
|
+ * @see Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ require_once 'Zend/Ldap/Exception.php';
|
|
|
$code = Zend_Ldap_Exception::LDAP_OPERATIONS_ERROR;
|
|
|
- $str = "Unexpected result count ($count) for: $accountFilter";
|
|
|
- }
|
|
|
- $accounts->close();
|
|
|
+ $str = "Unexpected result count ($count) for: $accountFilter";
|
|
|
+ }
|
|
|
+ $accounts->close();
|
|
|
/**
|
|
|
* @see Zend_Ldap_Exception
|
|
|
*/
|
|
|
@@ -864,62 +864,62 @@ class Zend_Ldap
|
|
|
$this->disconnect();
|
|
|
throw $zle;
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * A global LDAP search routine for finding information.
|
|
|
- *
|
|
|
- * @param string|Zend_Ldap_Filter_Abstract $filter
|
|
|
- * @param string|Zend_Ldap_Dn $basedn
|
|
|
- * @param integer $scope
|
|
|
- * @param array $attributes
|
|
|
+
|
|
|
+ /**
|
|
|
+ * A global LDAP search routine for finding information.
|
|
|
+ *
|
|
|
+ * @param string|Zend_Ldap_Filter_Abstract $filter
|
|
|
+ * @param string|Zend_Ldap_Dn $basedn
|
|
|
+ * @param integer $scope
|
|
|
+ * @param array $attributes
|
|
|
* @param string $sort
|
|
|
- * @param string $collectionClass
|
|
|
- * @return Zend_Ldap_Collection
|
|
|
- * @throws Zend_Ldap_Exception
|
|
|
- */
|
|
|
- public function search($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB,
|
|
|
- array $attributes = array(), $sort = null, $collectionClass = null)
|
|
|
- {
|
|
|
- if ($basedn === null) {
|
|
|
- $basedn = $this->getBaseDn();
|
|
|
- }
|
|
|
- else if ($basedn instanceof Zend_Ldap_Dn) {
|
|
|
- $basedn = $basedn->toString();
|
|
|
- }
|
|
|
-
|
|
|
- if ($filter instanceof Zend_Ldap_Filter_Abstract) {
|
|
|
- $filter = $filter->toString();
|
|
|
- }
|
|
|
-
|
|
|
- switch ($scope) {
|
|
|
- case self::SEARCH_SCOPE_ONE:
|
|
|
- $search = @ldap_list($this->getResource(), $basedn, $filter, $attributes);
|
|
|
- break;
|
|
|
- case self::SEARCH_SCOPE_BASE:
|
|
|
- $search = @ldap_read($this->getResource(), $basedn, $filter, $attributes);
|
|
|
- break;
|
|
|
- case self::SEARCH_SCOPE_SUB:
|
|
|
- default:
|
|
|
- $search = @ldap_search($this->getResource(), $basedn, $filter, $attributes);
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- if($search === false) {
|
|
|
- /**
|
|
|
- * @see Zend_Ldap_Exception
|
|
|
- */
|
|
|
- require_once 'Zend/Ldap/Exception.php';
|
|
|
- throw new Zend_Ldap_Exception($this, 'searching: ' . $filter);
|
|
|
- }
|
|
|
- if (!is_null($sort) && is_string($sort)) {
|
|
|
- $isSorted = @ldap_sort($this->getResource(), $search, $sort);
|
|
|
- if($search === false) {
|
|
|
- /**
|
|
|
- * @see Zend_Ldap_Exception
|
|
|
- */
|
|
|
- require_once 'Zend/Ldap/Exception.php';
|
|
|
- throw new Zend_Ldap_Exception($this, 'sorting: ' . $sort);
|
|
|
- }
|
|
|
+ * @param string $collectionClass
|
|
|
+ * @return Zend_Ldap_Collection
|
|
|
+ * @throws Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ public function search($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB,
|
|
|
+ array $attributes = array(), $sort = null, $collectionClass = null)
|
|
|
+ {
|
|
|
+ if ($basedn === null) {
|
|
|
+ $basedn = $this->getBaseDn();
|
|
|
+ }
|
|
|
+ else if ($basedn instanceof Zend_Ldap_Dn) {
|
|
|
+ $basedn = $basedn->toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($filter instanceof Zend_Ldap_Filter_Abstract) {
|
|
|
+ $filter = $filter->toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ switch ($scope) {
|
|
|
+ case self::SEARCH_SCOPE_ONE:
|
|
|
+ $search = @ldap_list($this->getResource(), $basedn, $filter, $attributes);
|
|
|
+ break;
|
|
|
+ case self::SEARCH_SCOPE_BASE:
|
|
|
+ $search = @ldap_read($this->getResource(), $basedn, $filter, $attributes);
|
|
|
+ break;
|
|
|
+ case self::SEARCH_SCOPE_SUB:
|
|
|
+ default:
|
|
|
+ $search = @ldap_search($this->getResource(), $basedn, $filter, $attributes);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($search === false) {
|
|
|
+ /**
|
|
|
+ * @see Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ require_once 'Zend/Ldap/Exception.php';
|
|
|
+ throw new Zend_Ldap_Exception($this, 'searching: ' . $filter);
|
|
|
+ }
|
|
|
+ if (!is_null($sort) && is_string($sort)) {
|
|
|
+ $isSorted = @ldap_sort($this->getResource(), $search, $sort);
|
|
|
+ if($search === false) {
|
|
|
+ /**
|
|
|
+ * @see Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ require_once 'Zend/Ldap/Exception.php';
|
|
|
+ throw new Zend_Ldap_Exception($this, 'sorting: ' . $sort);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -939,148 +939,148 @@ class Zend_Ldap
|
|
|
*/
|
|
|
return new $collectionClass($iterator);
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Count items found by given filter.
|
|
|
- *
|
|
|
- * @param string|Zend_Ldap_Filter_Abstract $filter
|
|
|
- * @param string|Zend_Ldap_Dn $basedn
|
|
|
- * @param integer $scope
|
|
|
- * @return integer
|
|
|
- * @throws Zend_Ldap_Exception
|
|
|
- */
|
|
|
- public function count($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB)
|
|
|
- {
|
|
|
- try {
|
|
|
- $result = $this->search($filter, $basedn, $scope, array('dn'), null);
|
|
|
- } catch (Zend_Ldap_Exception $e) {
|
|
|
- if ($e->getCode() === Zend_Ldap_Exception::LDAP_NO_SUCH_OBJECT) return 0;
|
|
|
- else throw $e;
|
|
|
- }
|
|
|
- return $result->count();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Count children for a given DN.
|
|
|
- *
|
|
|
- * @param string|Zend_Ldap_Dn $dn
|
|
|
- * @return integer
|
|
|
- * @throws Zend_Ldap_Exception
|
|
|
- */
|
|
|
- public function countChildren($dn)
|
|
|
- {
|
|
|
- return $this->count('(objectClass=*)', $dn, self::SEARCH_SCOPE_ONE);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Check if a given DN exists.
|
|
|
- *
|
|
|
- * @param string|Zend_Ldap_Dn $dn
|
|
|
- * @return boolean
|
|
|
- * @throws Zend_Ldap_Exception
|
|
|
- */
|
|
|
- public function exists($dn)
|
|
|
- {
|
|
|
- return ($this->count('(objectClass=*)', $dn, self::SEARCH_SCOPE_BASE) == 1);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Search LDAP registry for entries matching filter and optional attributes
|
|
|
- *
|
|
|
- * @param string|Zend_Ldap_Filter_Abstract $filter
|
|
|
- * @param string|Zend_Ldap_Dn $basedn
|
|
|
- * @param integer $scope
|
|
|
- * @param array $attributes
|
|
|
- * @param string $sort
|
|
|
- * @return array
|
|
|
- * @throws Zend_Ldap_Exception
|
|
|
- */
|
|
|
- public function searchEntries($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB,
|
|
|
- array $attributes = array(), $sort = null)
|
|
|
- {
|
|
|
- $result = $this->search($filter, $basedn, $scope, $attributes, $sort);
|
|
|
- return $result->toArray();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Get LDAP entry by DN
|
|
|
- *
|
|
|
- * @param string|Zend_Ldap_Dn $dn
|
|
|
- * @param array $attributes
|
|
|
- * @param boolean $throwOnNotFound
|
|
|
- * @return array
|
|
|
- * @throws Zend_Ldap_Exception
|
|
|
- */
|
|
|
- public function getEntry($dn, array $attributes = array(), $throwOnNotFound = false)
|
|
|
- {
|
|
|
- try {
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Count items found by given filter.
|
|
|
+ *
|
|
|
+ * @param string|Zend_Ldap_Filter_Abstract $filter
|
|
|
+ * @param string|Zend_Ldap_Dn $basedn
|
|
|
+ * @param integer $scope
|
|
|
+ * @return integer
|
|
|
+ * @throws Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ public function count($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $result = $this->search($filter, $basedn, $scope, array('dn'), null);
|
|
|
+ } catch (Zend_Ldap_Exception $e) {
|
|
|
+ if ($e->getCode() === Zend_Ldap_Exception::LDAP_NO_SUCH_OBJECT) return 0;
|
|
|
+ else throw $e;
|
|
|
+ }
|
|
|
+ return $result->count();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Count children for a given DN.
|
|
|
+ *
|
|
|
+ * @param string|Zend_Ldap_Dn $dn
|
|
|
+ * @return integer
|
|
|
+ * @throws Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ public function countChildren($dn)
|
|
|
+ {
|
|
|
+ return $this->count('(objectClass=*)', $dn, self::SEARCH_SCOPE_ONE);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Check if a given DN exists.
|
|
|
+ *
|
|
|
+ * @param string|Zend_Ldap_Dn $dn
|
|
|
+ * @return boolean
|
|
|
+ * @throws Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ public function exists($dn)
|
|
|
+ {
|
|
|
+ return ($this->count('(objectClass=*)', $dn, self::SEARCH_SCOPE_BASE) == 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Search LDAP registry for entries matching filter and optional attributes
|
|
|
+ *
|
|
|
+ * @param string|Zend_Ldap_Filter_Abstract $filter
|
|
|
+ * @param string|Zend_Ldap_Dn $basedn
|
|
|
+ * @param integer $scope
|
|
|
+ * @param array $attributes
|
|
|
+ * @param string $sort
|
|
|
+ * @return array
|
|
|
+ * @throws Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ public function searchEntries($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB,
|
|
|
+ array $attributes = array(), $sort = null)
|
|
|
+ {
|
|
|
+ $result = $this->search($filter, $basedn, $scope, $attributes, $sort);
|
|
|
+ return $result->toArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Get LDAP entry by DN
|
|
|
+ *
|
|
|
+ * @param string|Zend_Ldap_Dn $dn
|
|
|
+ * @param array $attributes
|
|
|
+ * @param boolean $throwOnNotFound
|
|
|
+ * @return array
|
|
|
+ * @throws Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ public function getEntry($dn, array $attributes = array(), $throwOnNotFound = false)
|
|
|
+ {
|
|
|
+ try {
|
|
|
$result = $this->search("(objectClass=*)", $dn, self::SEARCH_SCOPE_BASE,
|
|
|
- $attributes, null);
|
|
|
- return $result->getFirst();
|
|
|
- } catch (Zend_Ldap_Exception $e){
|
|
|
- if ($throwOnNotFound !== false) throw $e;
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Prepares an ldap data entry array for insert/update operation
|
|
|
- *
|
|
|
- * @param array $entry
|
|
|
- * @return void
|
|
|
- * @throws InvalidArgumentException
|
|
|
- */
|
|
|
- public static function prepareLdapEntryArray(array &$entry)
|
|
|
- {
|
|
|
- if (array_key_exists('dn', $entry)) unset($entry['dn']);
|
|
|
- foreach ($entry as $key => $value) {
|
|
|
- if (is_array($value)) {
|
|
|
- foreach ($value as $i => $v) {
|
|
|
- if (is_null($v)) unset($value[$i]);
|
|
|
- else if (empty($v)) unset($value[$i]);
|
|
|
- else if (!is_scalar($v)) {
|
|
|
- throw new InvalidArgumentException('Only scalar values allowed in LDAP data');
|
|
|
- }
|
|
|
- }
|
|
|
- $entry[$key] = array_values($value);
|
|
|
- } else {
|
|
|
- if (is_null($value)) $entry[$key] = array();
|
|
|
- else if (empty($value)) $entry[$key] = array();
|
|
|
- else $entry[$key] = array($value);
|
|
|
- }
|
|
|
- }
|
|
|
- $entry = array_change_key_case($entry, CASE_LOWER);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Add new information to the LDAP repository
|
|
|
- *
|
|
|
- * @param string|Zend_Ldap_Dn $dn
|
|
|
- * @param array $entry
|
|
|
- * @return Zend_Ldap *Provides a fluid interface*
|
|
|
- * @throws Zend_Ldap_Exception
|
|
|
- */
|
|
|
- public function add($dn, array $entry)
|
|
|
+ $attributes, null);
|
|
|
+ return $result->getFirst();
|
|
|
+ } catch (Zend_Ldap_Exception $e){
|
|
|
+ if ($throwOnNotFound !== false) throw $e;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Prepares an ldap data entry array for insert/update operation
|
|
|
+ *
|
|
|
+ * @param array $entry
|
|
|
+ * @return void
|
|
|
+ * @throws InvalidArgumentException
|
|
|
+ */
|
|
|
+ public static function prepareLdapEntryArray(array &$entry)
|
|
|
+ {
|
|
|
+ if (array_key_exists('dn', $entry)) unset($entry['dn']);
|
|
|
+ foreach ($entry as $key => $value) {
|
|
|
+ if (is_array($value)) {
|
|
|
+ foreach ($value as $i => $v) {
|
|
|
+ if (is_null($v)) unset($value[$i]);
|
|
|
+ else if (empty($v)) unset($value[$i]);
|
|
|
+ else if (!is_scalar($v)) {
|
|
|
+ throw new InvalidArgumentException('Only scalar values allowed in LDAP data');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $entry[$key] = array_values($value);
|
|
|
+ } else {
|
|
|
+ if (is_null($value)) $entry[$key] = array();
|
|
|
+ else if (empty($value)) $entry[$key] = array();
|
|
|
+ else $entry[$key] = array($value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $entry = array_change_key_case($entry, CASE_LOWER);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Add new information to the LDAP repository
|
|
|
+ *
|
|
|
+ * @param string|Zend_Ldap_Dn $dn
|
|
|
+ * @param array $entry
|
|
|
+ * @return Zend_Ldap *Provides a fluid interface*
|
|
|
+ * @throws Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ public function add($dn, array $entry)
|
|
|
{
|
|
|
if (!($dn instanceof Zend_Ldap_Dn)) {
|
|
|
$dn = Zend_Ldap_Dn::factory($dn, null);
|
|
|
- }
|
|
|
+ }
|
|
|
self::prepareLdapEntryArray($entry);
|
|
|
- foreach ($entry as $key => $value) {
|
|
|
- if (is_array($value) && count($value) === 0) {
|
|
|
- unset($entry[$key]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ foreach ($entry as $key => $value) {
|
|
|
+ if (is_array($value) && count($value) === 0) {
|
|
|
+ unset($entry[$key]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
$rdnParts = $dn->getRdn(Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER);
|
|
|
- foreach ($rdnParts as $key => $value) {
|
|
|
- $value = Zend_Ldap_Dn::unescapeValue($value);
|
|
|
+ foreach ($rdnParts as $key => $value) {
|
|
|
+ $value = Zend_Ldap_Dn::unescapeValue($value);
|
|
|
if (!array_key_exists($key, $entry) ||
|
|
|
!in_array($value, $entry[$key]) ||
|
|
|
- count($entry[$key]) !== 1) {
|
|
|
- $entry[$key] = array($value);
|
|
|
- }
|
|
|
+ count($entry[$key]) !== 1) {
|
|
|
+ $entry[$key] = array($value);
|
|
|
+ }
|
|
|
}
|
|
|
$adAttributes = array('distinguishedname', 'instancetype', 'name', 'objectcategory',
|
|
|
'objectguid', 'usnchanged', 'usncreated', 'whenchanged', 'whencreated');
|
|
|
@@ -1088,32 +1088,32 @@ class Zend_Ldap
|
|
|
if (array_key_exists($attr, $entry)) {
|
|
|
unset($entry[$attr]);
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- $isAdded = @ldap_add($this->getResource(), $dn->toString(), $entry);
|
|
|
- if($isAdded === false) {
|
|
|
- /**
|
|
|
- * @see Zend_Ldap_Exception
|
|
|
- */
|
|
|
- require_once 'Zend/Ldap/Exception.php';
|
|
|
- throw new Zend_Ldap_Exception($this, 'adding: ' . $dn->toString());
|
|
|
- }
|
|
|
- return $this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Update LDAP registry
|
|
|
- *
|
|
|
- * @param string|Zend_Ldap_Dn $dn
|
|
|
- * @param array $entry
|
|
|
- * @return Zend_Ldap *Provides a fluid interface*
|
|
|
- * @throws Zend_Ldap_Exception
|
|
|
- */
|
|
|
- public function update($dn, array $entry)
|
|
|
- {
|
|
|
- if (!($dn instanceof Zend_Ldap_Dn)) {
|
|
|
- $dn = Zend_Ldap_Dn::factory($dn, null);
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ $isAdded = @ldap_add($this->getResource(), $dn->toString(), $entry);
|
|
|
+ if($isAdded === false) {
|
|
|
+ /**
|
|
|
+ * @see Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ require_once 'Zend/Ldap/Exception.php';
|
|
|
+ throw new Zend_Ldap_Exception($this, 'adding: ' . $dn->toString());
|
|
|
+ }
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Update LDAP registry
|
|
|
+ *
|
|
|
+ * @param string|Zend_Ldap_Dn $dn
|
|
|
+ * @param array $entry
|
|
|
+ * @return Zend_Ldap *Provides a fluid interface*
|
|
|
+ * @throws Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ public function update($dn, array $entry)
|
|
|
+ {
|
|
|
+ if (!($dn instanceof Zend_Ldap_Dn)) {
|
|
|
+ $dn = Zend_Ldap_Dn::factory($dn, null);
|
|
|
+ }
|
|
|
self::prepareLdapEntryArray($entry);
|
|
|
|
|
|
$rdnParts = $dn->getRdn(Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER);
|
|
|
@@ -1127,69 +1127,69 @@ class Zend_Ldap
|
|
|
}
|
|
|
|
|
|
if (count($entry) > 0) {
|
|
|
- $isModified = @ldap_modify($this->getResource(), $dn->toString(), $entry);
|
|
|
- if($isModified === false) {
|
|
|
- /**
|
|
|
- * @see Zend_Ldap_Exception
|
|
|
- */
|
|
|
- require_once 'Zend/Ldap/Exception.php';
|
|
|
- throw new Zend_Ldap_Exception($this, 'updating: ' . $dn->toString());
|
|
|
+ $isModified = @ldap_modify($this->getResource(), $dn->toString(), $entry);
|
|
|
+ if($isModified === false) {
|
|
|
+ /**
|
|
|
+ * @see Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ require_once 'Zend/Ldap/Exception.php';
|
|
|
+ throw new Zend_Ldap_Exception($this, 'updating: ' . $dn->toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Save entry to LDAP registry.
|
|
|
+ *
|
|
|
+ * Internally decides if entry will be updated to added by calling
|
|
|
+ * {@link exists()}.
|
|
|
+ *
|
|
|
+ * @param string|Zend_Ldap_Dn $dn
|
|
|
+ * @param array $entry
|
|
|
+ * @return Zend_Ldap *Provides a fluid interface*
|
|
|
+ * @throws Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ public function save($dn, array $entry)
|
|
|
+ {
|
|
|
+ if ($dn instanceof Zend_Ldap_Dn) {
|
|
|
+ $dn = $dn->toString();
|
|
|
+ }
|
|
|
+ if ($this->exists($dn)) $this->update($dn, $entry);
|
|
|
+ else $this->add($dn, $entry);
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Delete an LDAP entry
|
|
|
+ *
|
|
|
+ * @param string|Zend_Ldap_Dn $dn
|
|
|
+ * @param boolean $recursively
|
|
|
+ * @return Zend_Ldap *Provides a fluid interface*
|
|
|
+ * @throws Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ public function delete($dn, $recursively = false)
|
|
|
+ {
|
|
|
+ if ($dn instanceof Zend_Ldap_Dn) {
|
|
|
+ $dn = $dn->toString();
|
|
|
+ }
|
|
|
+ if ($recursively === true) {
|
|
|
+ if ($this->countChildren($dn)>0) {
|
|
|
+ $children = $this->_getChildrenDns($dn);
|
|
|
+ foreach ($children as $c) {
|
|
|
+ $this->delete($c, true);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- return $this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Save entry to LDAP registry.
|
|
|
- *
|
|
|
- * Internally decides if entry will be updated to added by calling
|
|
|
- * {@link exists()}.
|
|
|
- *
|
|
|
- * @param string|Zend_Ldap_Dn $dn
|
|
|
- * @param array $entry
|
|
|
- * @return Zend_Ldap *Provides a fluid interface*
|
|
|
- * @throws Zend_Ldap_Exception
|
|
|
- */
|
|
|
- public function save($dn, array $entry)
|
|
|
- {
|
|
|
- if ($dn instanceof Zend_Ldap_Dn) {
|
|
|
- $dn = $dn->toString();
|
|
|
- }
|
|
|
- if ($this->exists($dn)) $this->update($dn, $entry);
|
|
|
- else $this->add($dn, $entry);
|
|
|
- return $this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Delete an LDAP entry
|
|
|
- *
|
|
|
- * @param string|Zend_Ldap_Dn $dn
|
|
|
- * @param boolean $recursively
|
|
|
- * @return Zend_Ldap *Provides a fluid interface*
|
|
|
- * @throws Zend_Ldap_Exception
|
|
|
- */
|
|
|
- public function delete($dn, $recursively = false)
|
|
|
- {
|
|
|
- if ($dn instanceof Zend_Ldap_Dn) {
|
|
|
- $dn = $dn->toString();
|
|
|
- }
|
|
|
- if ($recursively === true) {
|
|
|
- if ($this->countChildren($dn)>0) {
|
|
|
- $children = $this->_getChildrenDns($dn);
|
|
|
- foreach ($children as $c) {
|
|
|
- $this->delete($c, true);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- $isDeleted = @ldap_delete($this->getResource(), $dn);
|
|
|
- if($isDeleted === false) {
|
|
|
- /**
|
|
|
- * @see Zend_Ldap_Exception
|
|
|
- */
|
|
|
- require_once 'Zend/Ldap/Exception.php';
|
|
|
- throw new Zend_Ldap_Exception($this, 'deleting: ' . $dn);
|
|
|
- }
|
|
|
- return $this;
|
|
|
+ }
|
|
|
+ $isDeleted = @ldap_delete($this->getResource(), $dn);
|
|
|
+ if($isDeleted === false) {
|
|
|
+ /**
|
|
|
+ * @see Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ require_once 'Zend/Ldap/Exception.php';
|
|
|
+ throw new Zend_Ldap_Exception($this, 'deleting: ' . $dn);
|
|
|
+ }
|
|
|
+ return $this;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1223,187 +1223,187 @@ class Zend_Ldap
|
|
|
}
|
|
|
@ldap_free_result($search);
|
|
|
return $children;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Moves a LDAP entry from one DN to another subtree.
|
|
|
- *
|
|
|
- * @param string|Zend_Ldap_Dn $from
|
|
|
- * @param string|Zend_Ldap_Dn $to
|
|
|
- * @param boolean $recursively
|
|
|
- * @param boolean $alwaysEmulate
|
|
|
- * @return Zend_Ldap *Provides a fluid interface*
|
|
|
- * @throws Zend_Ldap_Exception
|
|
|
- */
|
|
|
- public function moveToSubtree($from, $to, $recursively = false, $alwaysEmulate = false)
|
|
|
- {
|
|
|
- if ($from instanceof Zend_Ldap_Dn) {
|
|
|
- $orgDnParts = $from->toArray();
|
|
|
- } else {
|
|
|
- $orgDnParts = Zend_Ldap_Dn::explodeDn($from);
|
|
|
- }
|
|
|
-
|
|
|
- if ($to instanceof Zend_Ldap_Dn) {
|
|
|
- $newParentDnParts = $to->toArray();
|
|
|
- } else {
|
|
|
- $newParentDnParts = Zend_Ldap_Dn::explodeDn($to);
|
|
|
- }
|
|
|
-
|
|
|
- $newDnParts = array_merge(array(array_shift($orgDnParts)), $newParentDnParts);
|
|
|
- $newDn = Zend_Ldap_Dn::fromArray($newDnParts);
|
|
|
- return $this->rename($from, $newDn, $recursively, $alwaysEmulate);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Moves a LDAP entry from one DN to another DN.
|
|
|
- *
|
|
|
- * This is an alias for {@link rename()}
|
|
|
- *
|
|
|
- * @param string|Zend_Ldap_Dn $from
|
|
|
- * @param string|Zend_Ldap_Dn $to
|
|
|
- * @param boolean $recursively
|
|
|
- * @param boolean $alwaysEmulate
|
|
|
- * @return Zend_Ldap *Provides a fluid interface*
|
|
|
- * @throws Zend_Ldap_Exception
|
|
|
- */
|
|
|
- public function move($from, $to, $recursively = false, $alwaysEmulate = false)
|
|
|
- {
|
|
|
- return $this->rename($from, $to, $recursively, $alwaysEmulate);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Renames a LDAP entry from one DN to another DN.
|
|
|
- *
|
|
|
- * This method implicitely moves the entry to another location within the tree.
|
|
|
- *
|
|
|
- * @param string|Zend_Ldap_Dn $from
|
|
|
- * @param string|Zend_Ldap_Dn $to
|
|
|
- * @param boolean $recursively
|
|
|
- * @param boolean $alwaysEmulate
|
|
|
- * @return Zend_Ldap *Provides a fluid interface*
|
|
|
- * @throws Zend_Ldap_Exception
|
|
|
- */
|
|
|
- public function rename($from, $to, $recursively = false, $alwaysEmulate = false)
|
|
|
- {
|
|
|
- $emulate = (bool)$alwaysEmulate;
|
|
|
- if (!function_exists('ldap_rename')) $emulate = true;
|
|
|
- else if ($recursively) $emulate = true;
|
|
|
-
|
|
|
- if ($emulate === false) {
|
|
|
- if ($from instanceof Zend_Ldap_Dn) {
|
|
|
- $from = $from->toString();
|
|
|
- }
|
|
|
-
|
|
|
- if ($to instanceof Zend_Ldap_Dn) {
|
|
|
- $newDnParts = $to->toArray();
|
|
|
- } else {
|
|
|
- $newDnParts = Zend_Ldap_Dn::explodeDn($to);
|
|
|
- }
|
|
|
-
|
|
|
- $newRdn = Zend_Ldap_Dn::implodeRdn(array_shift($newDnParts));
|
|
|
- $newParent = Zend_Ldap_Dn::implodeDn($newDnParts);
|
|
|
- $isOK = @ldap_rename($this->getResource(), $from, $newRdn, $newParent, true);
|
|
|
- if($isOK === false) {
|
|
|
- /**
|
|
|
- * @see Zend_Ldap_Exception
|
|
|
- */
|
|
|
- require_once 'Zend/Ldap/Exception.php';
|
|
|
- throw new Zend_Ldap_Exception($this, 'renaming ' . $from . ' to ' . $to);
|
|
|
- }
|
|
|
- else if (!$this->exists($to)) $emulate = true;
|
|
|
- }
|
|
|
- if ($emulate) {
|
|
|
- $this->copy($from, $to, $recursively);
|
|
|
- $this->delete($from, $recursively);
|
|
|
- }
|
|
|
- return $this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Copies a LDAP entry from one DN to another subtree.
|
|
|
- *
|
|
|
- * @param string|Zend_Ldap_Dn $from
|
|
|
- * @param string|Zend_Ldap_Dn $to
|
|
|
- * @param boolean $recursively
|
|
|
- * @return Zend_Ldap *Provides a fluid interface*
|
|
|
- * @throws Zend_Ldap_Exception
|
|
|
- */
|
|
|
- public function copyToSubtree($from, $to, $recursively = false)
|
|
|
- {
|
|
|
- if ($from instanceof Zend_Ldap_Dn) {
|
|
|
- $orgDnParts = $from->toArray();
|
|
|
- } else {
|
|
|
- $orgDnParts = Zend_Ldap_Dn::explodeDn($from);
|
|
|
- }
|
|
|
-
|
|
|
- if ($to instanceof Zend_Ldap_Dn) {
|
|
|
- $newParentDnParts = $to->toArray();
|
|
|
- } else {
|
|
|
- $newParentDnParts = Zend_Ldap_Dn::explodeDn($to);
|
|
|
- }
|
|
|
-
|
|
|
- $newDnParts = array_merge(array(array_shift($orgDnParts)), $newParentDnParts);
|
|
|
- $newDn = Zend_Ldap_Dn::fromArray($newDnParts);
|
|
|
- return $this->copy($from, $newDn, $recursively);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Copies a LDAP entry from one DN to another DN.
|
|
|
- *
|
|
|
- * @param string|Zend_Ldap_Dn $from
|
|
|
- * @param string|Zend_Ldap_Dn $to
|
|
|
- * @param boolean $recursively
|
|
|
- * @return Zend_Ldap *Provides a fluid interface*
|
|
|
- * @throws Zend_Ldap_Exception
|
|
|
- */
|
|
|
- public function copy($from, $to, $recursively = false)
|
|
|
- {
|
|
|
- $entry = $this->getEntry($from, array(), true);
|
|
|
-
|
|
|
- if ($to instanceof Zend_Ldap_Dn) {
|
|
|
- $toDnParts = $to->toArray();
|
|
|
- } else {
|
|
|
- $toDnParts = Zend_Ldap_Dn::explodeDn($to);
|
|
|
- }
|
|
|
- $this->add($to, $entry);
|
|
|
-
|
|
|
- if ($recursively === true && $this->countChildren($from)>0) {
|
|
|
- $children = $this->_getChildrenDns($from);
|
|
|
- foreach ($children as $c) {
|
|
|
- $cDnParts = Zend_Ldap_Dn::explodeDn($c);
|
|
|
- $newChildParts = array_merge(array(array_shift($cDnParts)), $toDnParts);
|
|
|
- $newChild = Zend_Ldap_Dn::implodeDn($newChildParts);
|
|
|
- $this->copy($c, $newChild, true);
|
|
|
- }
|
|
|
- }
|
|
|
- return $this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Returns the specified DN as a Zend_Ldap_Node
|
|
|
- *
|
|
|
- * @param string|Zend_Ldap_Dn $dn
|
|
|
- * @return Zend_Ldap_Node
|
|
|
- * @throws Zend_Ldap_Exception
|
|
|
- */
|
|
|
- public function getNode($dn)
|
|
|
- {
|
|
|
- /**
|
|
|
- * Zend_Ldap_Node
|
|
|
- */
|
|
|
- require_once 'Zend/Ldap/Node.php';
|
|
|
- return Zend_Ldap_Node::fromLdap($dn, $this);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Returns the base node as a Zend_Ldap_Node
|
|
|
- *
|
|
|
- * @return Zend_Ldap_Node
|
|
|
- * @throws Zend_Ldap_Exception
|
|
|
- */
|
|
|
- public function getBaseNode()
|
|
|
- {
|
|
|
- return $this->getNode($this->getBaseDn(), $this);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Moves a LDAP entry from one DN to another subtree.
|
|
|
+ *
|
|
|
+ * @param string|Zend_Ldap_Dn $from
|
|
|
+ * @param string|Zend_Ldap_Dn $to
|
|
|
+ * @param boolean $recursively
|
|
|
+ * @param boolean $alwaysEmulate
|
|
|
+ * @return Zend_Ldap *Provides a fluid interface*
|
|
|
+ * @throws Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ public function moveToSubtree($from, $to, $recursively = false, $alwaysEmulate = false)
|
|
|
+ {
|
|
|
+ if ($from instanceof Zend_Ldap_Dn) {
|
|
|
+ $orgDnParts = $from->toArray();
|
|
|
+ } else {
|
|
|
+ $orgDnParts = Zend_Ldap_Dn::explodeDn($from);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($to instanceof Zend_Ldap_Dn) {
|
|
|
+ $newParentDnParts = $to->toArray();
|
|
|
+ } else {
|
|
|
+ $newParentDnParts = Zend_Ldap_Dn::explodeDn($to);
|
|
|
+ }
|
|
|
+
|
|
|
+ $newDnParts = array_merge(array(array_shift($orgDnParts)), $newParentDnParts);
|
|
|
+ $newDn = Zend_Ldap_Dn::fromArray($newDnParts);
|
|
|
+ return $this->rename($from, $newDn, $recursively, $alwaysEmulate);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Moves a LDAP entry from one DN to another DN.
|
|
|
+ *
|
|
|
+ * This is an alias for {@link rename()}
|
|
|
+ *
|
|
|
+ * @param string|Zend_Ldap_Dn $from
|
|
|
+ * @param string|Zend_Ldap_Dn $to
|
|
|
+ * @param boolean $recursively
|
|
|
+ * @param boolean $alwaysEmulate
|
|
|
+ * @return Zend_Ldap *Provides a fluid interface*
|
|
|
+ * @throws Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ public function move($from, $to, $recursively = false, $alwaysEmulate = false)
|
|
|
+ {
|
|
|
+ return $this->rename($from, $to, $recursively, $alwaysEmulate);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Renames a LDAP entry from one DN to another DN.
|
|
|
+ *
|
|
|
+ * This method implicitely moves the entry to another location within the tree.
|
|
|
+ *
|
|
|
+ * @param string|Zend_Ldap_Dn $from
|
|
|
+ * @param string|Zend_Ldap_Dn $to
|
|
|
+ * @param boolean $recursively
|
|
|
+ * @param boolean $alwaysEmulate
|
|
|
+ * @return Zend_Ldap *Provides a fluid interface*
|
|
|
+ * @throws Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ public function rename($from, $to, $recursively = false, $alwaysEmulate = false)
|
|
|
+ {
|
|
|
+ $emulate = (bool)$alwaysEmulate;
|
|
|
+ if (!function_exists('ldap_rename')) $emulate = true;
|
|
|
+ else if ($recursively) $emulate = true;
|
|
|
+
|
|
|
+ if ($emulate === false) {
|
|
|
+ if ($from instanceof Zend_Ldap_Dn) {
|
|
|
+ $from = $from->toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($to instanceof Zend_Ldap_Dn) {
|
|
|
+ $newDnParts = $to->toArray();
|
|
|
+ } else {
|
|
|
+ $newDnParts = Zend_Ldap_Dn::explodeDn($to);
|
|
|
+ }
|
|
|
+
|
|
|
+ $newRdn = Zend_Ldap_Dn::implodeRdn(array_shift($newDnParts));
|
|
|
+ $newParent = Zend_Ldap_Dn::implodeDn($newDnParts);
|
|
|
+ $isOK = @ldap_rename($this->getResource(), $from, $newRdn, $newParent, true);
|
|
|
+ if($isOK === false) {
|
|
|
+ /**
|
|
|
+ * @see Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ require_once 'Zend/Ldap/Exception.php';
|
|
|
+ throw new Zend_Ldap_Exception($this, 'renaming ' . $from . ' to ' . $to);
|
|
|
+ }
|
|
|
+ else if (!$this->exists($to)) $emulate = true;
|
|
|
+ }
|
|
|
+ if ($emulate) {
|
|
|
+ $this->copy($from, $to, $recursively);
|
|
|
+ $this->delete($from, $recursively);
|
|
|
+ }
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Copies a LDAP entry from one DN to another subtree.
|
|
|
+ *
|
|
|
+ * @param string|Zend_Ldap_Dn $from
|
|
|
+ * @param string|Zend_Ldap_Dn $to
|
|
|
+ * @param boolean $recursively
|
|
|
+ * @return Zend_Ldap *Provides a fluid interface*
|
|
|
+ * @throws Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ public function copyToSubtree($from, $to, $recursively = false)
|
|
|
+ {
|
|
|
+ if ($from instanceof Zend_Ldap_Dn) {
|
|
|
+ $orgDnParts = $from->toArray();
|
|
|
+ } else {
|
|
|
+ $orgDnParts = Zend_Ldap_Dn::explodeDn($from);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($to instanceof Zend_Ldap_Dn) {
|
|
|
+ $newParentDnParts = $to->toArray();
|
|
|
+ } else {
|
|
|
+ $newParentDnParts = Zend_Ldap_Dn::explodeDn($to);
|
|
|
+ }
|
|
|
+
|
|
|
+ $newDnParts = array_merge(array(array_shift($orgDnParts)), $newParentDnParts);
|
|
|
+ $newDn = Zend_Ldap_Dn::fromArray($newDnParts);
|
|
|
+ return $this->copy($from, $newDn, $recursively);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Copies a LDAP entry from one DN to another DN.
|
|
|
+ *
|
|
|
+ * @param string|Zend_Ldap_Dn $from
|
|
|
+ * @param string|Zend_Ldap_Dn $to
|
|
|
+ * @param boolean $recursively
|
|
|
+ * @return Zend_Ldap *Provides a fluid interface*
|
|
|
+ * @throws Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ public function copy($from, $to, $recursively = false)
|
|
|
+ {
|
|
|
+ $entry = $this->getEntry($from, array(), true);
|
|
|
+
|
|
|
+ if ($to instanceof Zend_Ldap_Dn) {
|
|
|
+ $toDnParts = $to->toArray();
|
|
|
+ } else {
|
|
|
+ $toDnParts = Zend_Ldap_Dn::explodeDn($to);
|
|
|
+ }
|
|
|
+ $this->add($to, $entry);
|
|
|
+
|
|
|
+ if ($recursively === true && $this->countChildren($from)>0) {
|
|
|
+ $children = $this->_getChildrenDns($from);
|
|
|
+ foreach ($children as $c) {
|
|
|
+ $cDnParts = Zend_Ldap_Dn::explodeDn($c);
|
|
|
+ $newChildParts = array_merge(array(array_shift($cDnParts)), $toDnParts);
|
|
|
+ $newChild = Zend_Ldap_Dn::implodeDn($newChildParts);
|
|
|
+ $this->copy($c, $newChild, true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Returns the specified DN as a Zend_Ldap_Node
|
|
|
+ *
|
|
|
+ * @param string|Zend_Ldap_Dn $dn
|
|
|
+ * @return Zend_Ldap_Node
|
|
|
+ * @throws Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ public function getNode($dn)
|
|
|
+ {
|
|
|
+ /**
|
|
|
+ * Zend_Ldap_Node
|
|
|
+ */
|
|
|
+ require_once 'Zend/Ldap/Node.php';
|
|
|
+ return Zend_Ldap_Node::fromLdap($dn, $this);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Returns the base node as a Zend_Ldap_Node
|
|
|
+ *
|
|
|
+ * @return Zend_Ldap_Node
|
|
|
+ * @throws Zend_Ldap_Exception
|
|
|
+ */
|
|
|
+ public function getBaseNode()
|
|
|
+ {
|
|
|
+ return $this->getNode($this->getBaseDn(), $this);
|
|
|
}
|
|
|
|
|
|
/**
|