index 53cdac8204bdf4eba8b344938b8362111c98ea70..93686b6e63476d594db051f1edf22eb8e005d9ac 100644 (file)
<?php
-/*****************************************************************************
- newldap.inc - version 1.0
- Copyright (C) 2003 Alejandro Escanero Blanco <aescanero@chaosdimension.org>
- Copyright (C) 2004-2006 Cajus Pollmeier <pollmeier@gonicus.de>
-
- Based in code of ldap.inc of
- Copyright (C) 1998 Eric Kilfoil <eric@ipass.net>
- *****************************************************************************/
+/*
+ * This code is part of GOsa (http://www.gosa-project.org)
+ * Copyright (C) 2003-2008 GONICUS GmbH
+ * Copyright (C) 2003 Alejandro Escanero Blanco <aescanero@chaosdimension.org>
+ * Copyright (C) 1998 Eric Kilfoil <eric@ipass.net>
+ *
+ * ID: $$Id$$
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
define("ALREADY_EXISTING_ENTRY",-10001);
define("UNKNOWN_TOKEN_IN_LDIF_FILE",-10002);
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;
}
+ /* Function to fix problematic characters in DN's that are used for search
+ requests. I.e. member=.... */
+ static function prepare4filter($dn)
+ {
+ return normalizeLdap(preg_replace('/\\\\/', '\\\\\\', LDAP::fix($dn)));
+ }
+
+
function connect()
{
$this->hascon=false;
return(ereg_replace("[^,]*[,]*[ ]*(.*)", "\\1", $basedn));
}
+
+# /* Checks if there is still unfetched data
+# */
+# function checkResult()
+# {
+# /* Check if we have started a search before */
+# if($this->start != 0 && $this->re){
+#
+# /* Check if there are still unfetched elements */
+# if(is_resource(@ldap_next_entry($this->cid, $this->re))){
+# new log("debug","LDAP:: CAT/SEARCH/FETCH","A new search was initiated while an older search wasn't fetched completely.");
+# msg_dialog::display(_("Debug"),"A new search was initiated while an older search wasn't fetched completely.",ERROR_DIALOG);
+# trigger_error("A new search was initiated while an older search wasn't fetched completely.");
+# }
+# }
+# }
+#
function search($filter, $attrs= array())
{
if($this->hascon){
if ($this->reconnect) $this->connect();
+# /* Check if there are still unfetched objects from last search
+# */
+# $this->checkResult();
+
$start = microtime();
-
$this->clearResult();
$this->sr = @ldap_search($this->cid, LDAP::fix($this->basedn), $filter, $attrs);
$this->error = @ldap_error($this->cid);
{
if($this->hascon){
if ($this->reconnect) $this->connect();
+
+# /* Check if there are still unfetched objects from last search
+# */
+# $this->checkResult();
+
$this->clearResult();
if ($basedn == "")
$basedn = $this->basedn;
{
if($this->hascon){
if ($this->reconnect) $this->connect();
+
+# /* Check if there are still unfetched objects from last search
+# */
+# $this->checkResult();
+
$this->clearResult();
$filter = "(objectclass=*)";
$this->sr = @ldap_read($this->cid, LDAP::fix($dn), $filter,$attrs);
/* 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), ERROR_DIALOG);
- display_error_page();
+ msg_dialog::display(_("Internal error"), sprintf(_("Cannot automatically create subtrees with RDN '%s': no object class found"),$type), FATAL_ERROR_DIALOG);
+ exit();
}
/* Assemble_entry */
$na["dc"]= $param;
break;
default:
- msg_dialog::display(_("Internal error"), sprintf(_("Cannot automatically create subtrees with RDN '%s': not supported"),$type), ERROR_DIALOG);
- display_error_page();
+ msg_dialog::display(_("Internal error"), sprintf(_("Cannot automatically create subtrees with RDN '%s': not supported"),$type), FATAL_ERROR_DIALOG);
+ exit();
}
}
return($objectclasses);
}
}
+
+ /* Return the cached results. */
+ if(class_available('session') && session::is_set("LDAP_CACHE::get_objectclasses")){
+ $objectclasses = session::get("LDAP_CACHE::get_objectclasses");
+ return($objectclasses);
+ }
# Get base to look for schema
$sr = @ldap_read ($this->cid, NULL, "objectClass=*", array("subschemaSubentry"));
}
}
+ if(class_available("session")){
+ session::set("LDAP_CACHE::get_objectclasses",$objectclasses);
+ }
return $objectclasses;
}
return ($result);
}
-
-
}
-
-
-/*! \brief Create a new FAI branch.
- * @param $sourcedn String The source release dn
- * @param $destinationdn String The destination dn
- * @param $destinationName String The name of the new release
- * @param $type String The release type (freeze/branch)
- * @param $is_first Boolean Use to identify the first func. call when recursivly called.
- * @param $depth Integer Current depth of recursion.
- */
-function copy_FAI_resource_recursive($sourcedn,$destinationdn,$destinationName,$type="branch",$is_first = true,$depth=0)
-{
- global $config;
- error_reporting(E_ALL | E_STRICT);
- $ldap = $config->get_ldap_link();
- $basedn = $config->current['BASE'];
- $delarray = array();
-
- /* The following code will output a status string
- * for each handled object, in a seperate iframe.
- */
-
-
- /* Display current action information.
- */
- if($is_first){
- echo "<h2>".sprintf(_("Creating copy of %s"),"<i>".LDAP::fix($sourcedn)."</i>")."</h2>";
- }else{
- if(preg_match("/^ou=/",$sourcedn)){
- echo "<h3>"._("Processing")." <i>".LDAP::fix($destinationdn)."</i></h3>";
- }else{
- $tmp = split(",",$sourcedn);
- echo " <b>"._("Object").":</b> ";
- $deststr = LDAP::fix($destinationdn);
- if(strlen($deststr) > 96){
- $deststr = substr($deststr,0,96)."...";
- }
- echo $deststr."<br>";
- }
- }
- /* .. immediately display infos */
- flush();
-
-
-
- /* Check if destination entry already exists
- */
- $ldap->cat($destinationdn);
- if($ldap->count()){
- echo _("Could not create new release, the destination dn is already in use.");
- return;
- }else{
-
- $ldap->clearResult();
-
- /* Get source entry
- * if it does not exist, abort here.
- */
- $ldap->cd($basedn);
- $ldap->cat($sourcedn);
- $attr = $ldap->fetch();
- if((!$attr) || (count($attr)) ==0) {
- echo _("Error while fetching source dn - aborted!");
- return;
- }
-
- /* The current object we want to create is an department.
- * Create the department and add the FAIbranch tag.
- */
- if(in_array("organizationalUnit",$attr['objectClass'])){
- $attr['dn'] = LDAP::convert($destinationdn);
- $ldap->cd($basedn);
- $ldap->create_missing_trees($destinationdn);
- $ldap->cd($destinationdn);
-
- /* If is first entry, append FAIbranch to department entry */
- if($is_first){
- $ldap->cat($destinationdn);
- $attr= $ldap->fetch();
-
- /* Filter unneeded informations */
- foreach($attr as $key => $value){
- if(is_numeric($key)) unset($attr[$key]);
- if(isset($attr[$key]['count'])){
- if(is_array($attr[$key])){
- unset($attr[$key]['count']);
- }
- }
- }
-
- unset($attr['count']);
- unset($attr['dn']);
-
- /* Add marking attribute */
- $attr['objectClass'][] = "FAIbranch";
-
- /* Add this entry */
- $ldap->modify($attr);
- }
- }else{
-
- /* Replicate all relevant FAI objects here.
- * FAI objects, Apps and Mimetypes.
- * Get all attributes as binary value, to ensure that Icon, File template aso
- * are created correctly.
- */
- foreach($attr as $key => $value){
- if(in_array($key ,array("FAItemplateFile","FAIscript", "gotoLogonScript", "gosaApplicationIcon","gotoMimeIcon"))){
- $sr= ldap_read($ldap->cid, LDAP::fix($sourcedn), "$key=*", array($key));
- $ei= ldap_first_entry($ldap->cid, $sr);
- if ($tmp= @ldap_get_values_len($ldap->cid, $ei,$key)){
- $attr[$key] = $tmp;
- }
- }
-
- if(is_numeric($key)) unset($attr[$key]);
- if(isset($attr[$key]['count'])){
- if(is_array($attr[$key])){
- unset($attr[$key]['count']);
- }
- }
- }
- unset($attr['count']);
- unset($attr['dn']);
-
- /* Add FAIstate attribute to all FAI objects.
- */
- if((!in_array("gosaApplication" , $attr['objectClass'])) && (!in_array("gotoMimeType", $attr['objectClass']))){
- $attr['FAIdebianRelease'] = $destinationName;
- if($type=="branch"){
- $attr['FAIstate'] ="branch";
- }elseif($type=="freeze"){
- $attr['FAIstate'] ="freeze";
- }else{
- msg_dialog::display(_("Internal error"), sprintf(_("FAIstate '%s' is unknown!"),$type), ERROR_DIALOG);
- }
- }
-
- /* Replace FAIdebianRelease with new release name.
- */
- if(in_array("FAIpackageList" , $attr['objectClass'])){
- $attr['FAIdebianRelease'] = $destinationName;
- }
-
- /* Add entry
- */
- $ldap->cd($destinationdn);
- $ldap->cat($destinationdn);
- $a = $ldap->fetch();
- if(!count($a)){
- $ldap->add($attr);
- }
-
- if($ldap->error != "Success"){
-
- /* Some error occurred */
- print "---------------------------------------------";
- print $ldap->get_error()."<br>";
- print $sourcedn."<br>";
- print $destinationdn."<br>";
- print_a( $attr);
- exit();
- }
- }
- }
-
- echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
-
- /* Prepare for recursive copy.
- * Get all object within the source dn and
- * call the recursive copy for each.
- */
- $ldap->ls ("(objectClass=*)",$sourcedn);
- while ($ldap->fetch()){
- $deldn= $ldap->getDN();
- $delarray[$deldn]= strlen($deldn);
- }
- asort ($delarray);
- reset ($delarray);
- $depth ++;
- foreach($delarray as $dn => $bla){
- if($dn != $destinationdn){
- $ldap->cd($basedn);
- $item = $ldap->fetch($ldap->cat($dn));
- if(!in_array("FAIbranch",$item['objectClass'])){
- copy_FAI_resource_recursive($dn,str_replace($sourcedn,$destinationdn,$dn),$destinationName,$type,false,$depth);
- }
- }
- }
- if($is_first){
- echo "<p class='seperator'> </p>";
- }
-}
-
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>