From afbe8f0fcb1dd021cfc7ac2f8a455a48781876c4 Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Tue, 17 Dec 2013 14:28:56 +0100 Subject: [PATCH] Implement move on LDAP Connection refs #5202 Conflicts: library/Icinga/Protocol/Ldap/Connection.php --- library/Icinga/Protocol/Ldap/Connection.php | 47 +++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/library/Icinga/Protocol/Ldap/Connection.php b/library/Icinga/Protocol/Ldap/Connection.php index 4b5476840..9f3581e23 100644 --- a/library/Icinga/Protocol/Ldap/Connection.php +++ b/library/Icinga/Protocol/Ldap/Connection.php @@ -486,6 +486,53 @@ class Connection } } + /** + * Create an ldap entry + * + * @param string $dn DN to add + * @param array $entry Entry description + * + * @return bool True on success + */ + public function addEntry($dn, array $entry) + { + return ldap_add($this->ds, $dn, $entry); + } + + /** + * Modify a ldap entry + * + * @param string $dn DN of the entry to change + * @param array $entry Change values + * + * @return bool True on success + */ + public function modifyEntry($dn, array $entry) + { + return ldap_modify($this->ds, $dn, $entry); + } + + /** + * Move entry to a new DN + * + * @param string $dn DN of the object + * @param string $newRdn Relative DN identifier + * @param string $newParentDn Parent or superior entry + * @throws \Exception Thrown then rename failed + * + * @return bool True on success + */ + public function moveEntry($dn, $newRdn, $newParentDn) + { + $returnValue = ldap_rename($this->ds, $dn, $newRdn, $newParentDn, false); + + if ($returnValue === false) { + throw new \Exception('Could not move entry: ' . ldap_error($this->ds)); + } + + return $returnValue; + } + public function __destruct() { putenv('LDAPRC');