From e2b4b86dd84c941e591f0560dc20a947854312c5 Mon Sep 17 00:00:00 2001 From: hickert Date: Thu, 15 May 2008 13:43:01 +0000 Subject: [PATCH] Updated rename_dn function. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10919 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/include/class_ldap.inc | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/gosa-core/include/class_ldap.inc b/gosa-core/include/class_ldap.inc index 67921e0ba..2bbb1d875 100644 --- a/gosa-core/include/class_ldap.inc +++ b/gosa-core/include/class_ldap.inc @@ -451,18 +451,34 @@ class LDAP{ */ function rename_dn($source,$dest) { + /* Check if source and destination are the same entry */ + if(strtolower($source) == strtolower($dest)){ + trigger_error("Source and destination can't be the same entry."); + return(FALSE); + } + + /* Check if destination entry exists */ + if($this->dn_exists($dest)){ + trigger_error("Destination '$dest' already exists."); + return(FALSE); + } + /* Extract the name and the parent part out ouf source dn. e.g. cn=herbert,ou=department,dc=... - parent => ou=department,dc=... - dest => cn=herbert + parent => ou=department,dc=... + dest_rdn => cn=herbert */ - $parent = preg_replace("/^[^,]+,/","",$dest); - $dest = preg_replace("/,.*$/","",$dest); + $parent = preg_replace("/^[^,]+,/","",$dest); + $dest_rdn = preg_replace("/,.*$/","",$dest); if($this->hascon){ if ($this->reconnect) $this->connect(); - $r= @ldap_rename($this->cid,$source,$dest,$parent,TRUE); + $r= @ldap_rename($this->cid,$source,$dest_rdn,$parent,TRUE); $this->error = @ldap_error($this->cid); + + /* Check if destination dn exists, if not the + server may not support this operation */ + $r &= $this->dn_exists($dest); return(!$r ? $r : TRUE); }else{ $this->error = "Could not connect to LDAP server"; -- 2.30.2