X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-core%2Finclude%2Fclass_ldap.inc;h=7ff9cb8ac683143b11af81e96b243da7c28c44be;hb=cd5f4de8cfe3b506e563f61dca7f9dae0cccd19f;hp=560f809cfe44c98ba0bb6bbc6338fef1619a5119;hpb=7d94653c63f1fdf372d4a225060d9652c62e11b9;p=gosa.git diff --git a/gosa-core/include/class_ldap.inc b/gosa-core/include/class_ldap.inc index 560f809cf..7ff9cb8ac 100644 --- a/gosa-core/include/class_ldap.inc +++ b/gosa-core/include/class_ldap.inc @@ -36,6 +36,7 @@ class LDAP{ var $cid; var $hasres = array(); var $sr = array(); + var $re = array(); var $basedn =""; var $start = array(); // 0 if we are fetching the first entry, otherwise 1 var $error = ""; // Any error messages to be returned can be put here @@ -48,8 +49,6 @@ class LDAP{ var $referrals= array(); var $max_ldap_query_time = 0; // 0, empty or negative values will disable this check - var $re = NULL; - function LDAP($binddn,$bindpw, $hostname, $follow_referral= FALSE, $tls= FALSE) { global $config; @@ -316,17 +315,17 @@ class LDAP{ { if ($this->sr[$srp]){ $this->start[$srp] = 1; - $this->re= @ldap_first_entry($this->cid, $this->sr[$srp]); + $this->re[$srp]= @ldap_first_entry($this->cid, $this->sr[$srp]); } else { return array(); } } else { - $this->re= @ldap_next_entry($this->cid, $this->re); + $this->re[$srp]= @ldap_next_entry($this->cid, $this->re[$srp]); } - if ($this->re) + if ($this->re[$srp]) { - $att= @ldap_get_attributes($this->cid, $this->re); - $att['dn']= trim(LDAP::convert(@ldap_get_dn($this->cid, $this->re))); + $att= @ldap_get_attributes($this->cid, $this->re[$srp]); + $att['dn']= trim(LDAP::convert(@ldap_get_dn($this->cid, $this->re[$srp]))); } $this->error = @ldap_error($this->cid); if (!isset($att)){ @@ -361,13 +360,13 @@ class LDAP{ if($this->hascon){ if($this->hasres[$srp]){ - if(!$this->re) + if(!$this->re[$srp]) { $this->error = "Perform a Fetch with no valid Result"; } else { - $rv = @ldap_get_dn($this->cid, $this->re); + $rv = @ldap_get_dn($this->cid, $this->re[$srp]); $this->error = @ldap_error($this->cid); return(trim(LDAP::convert($rv))); @@ -444,6 +443,52 @@ class LDAP{ } } + + /*! \brief Move the given Ldap entry from $source to $dest + @param String $source The source dn. + @param String $dest The destination dn. + @return Boolean TRUE on success else FALSE. + */ + 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."); + $this->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."); + $this->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_rdn => cn=herbert + */ + $parent = preg_replace("/^[^,]+,/","",$dest); + $dest_rdn = preg_replace("/,.*$/","",$dest); + + if($this->hascon){ + if ($this->reconnect) $this->connect(); + $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 &= is_resource($this->dn_exists($dest)); + return($r); + }else{ + $this->error = "Could not connect to LDAP server"; + return(FALSE); + } + } + + /** * Function rmdir_recursive * @@ -452,7 +497,6 @@ class LDAP{ * GiveBack: True on sucessfull , 0 in error, and "" when we don't get a ldap conection * */ - function rmdir_recursive($srp, $deletedn) { if($this->hascon){ @@ -589,7 +633,7 @@ class LDAP{ /* Bail out, if we've nothing to do... */ if ($ocname == ""){ - msg_dialog::display(_("Internal error"), sprintf(_("Cannot automatically create subtrees with RDN '%s': no object class found"),$type), FATAL_ERROR_DIALOG); + msg_dialog::display(_("Internal error"), sprintf(_("Cannot automatically create subtrees with RDN '%s': no object class found!"),$type), FATAL_ERROR_DIALOG); exit(); } @@ -862,7 +906,7 @@ class LDAP{ if JustMofify id false the destination dn will be overwritten by the new ldif. */ - function import_complete_ldif($srp, $str_attr,&$error,$JustModify,$DeleteOldEntries) + function import_complete_ldif($srp, $str_attr,$error,$JustModify,$DeleteOldEntries) { if($this->reconnect) $this->connect(); @@ -1160,11 +1204,7 @@ class LDAP{ } # Get base to look for schema - $sr = @ldap_read ($this->cid, NULL, "objectClass=*", array("subschemaSubentry")); - if(!$sr){ - $sr = @ldap_read ($this->cid, "", "objectClass=*", array("subschemaSubentry")); - } - + $sr = @ldap_read ($this->cid, "", "objectClass=*", array("subschemaSubentry")); $attr = @ldap_get_entries($this->cid,$sr); if (!isset($attr[0]['subschemasubentry'][0])){ return array(); @@ -1224,6 +1264,7 @@ class LDAP{ if(class_available("session")){ session::set("LDAP_CACHE::get_objectclasses",$objectclasses); } + return $objectclasses; }