Code

Replaced config->search with get_cfg_value
[gosa.git] / gosa-core / include / class_ldap.inc
index 75901c78001dc6228dc35e445ec4c348f4acb683..21fc089307554f4e25d9449088097a3e13ed8ec9 100644 (file)
@@ -60,8 +60,8 @@ class LDAP{
     $this->hostname=$hostname;
 
     /* Check if MAX_LDAP_QUERY_TIME is defined */ 
-    if(is_object($config) && $config->get_cfg_value("ldapMaxQueryTime") != ""){
-      $str = $config->get_cfg_value("ldapMaxQueryTime");
+    if(is_object($config) && $config->get_cfg_value("core","ldapMaxQueryTime") != ""){
+      $str = $config->get_cfg_value("core","ldapMaxQueryTime");
       $this->max_ldap_query_time = (float)($str);
     }
 
@@ -857,27 +857,29 @@ class LDAP{
   }
 
 
-  function gen_ldif ($srp, $dn, $filter= "(objectClass=*)", $attributes= array('*'), $recursive= TRUE)
+  /*! \brief  Generates an ldif for all entries matching the filter settings, scope and limit.
+   *  @param  $dn           The entry to export.
+   *  @param  $filter       Limit the exported object to those maching this filter.
+   *  @param  $attributes   Specify the attributes to export here, empty means all.
+   *  @param  $scope        'base', 'sub' .. see manpage for 'ldapmodify' for details.
+   *  @param  $limit        Limits the result.
+   */
+  function generateLdif ($dn, $filter= "(objectClass=*)", $attributes= array(), $scope = 'sub', $limit=0)
   {
-    $display= "";
-
-    if ($recursive){
-      $this->cd($dn);
-      $this->ls($srp, $filter,$dn, array('dn','objectClass'));
-      $deps = array();
-
-      $display .= $this->gen_one_entry($dn)."\n";
-
-      while ($attrs= $this->fetch($srp)){
-        $deps[] = $attrs['dn'];
-      }
-      foreach($deps as $dn){
-        $display .= $this->gen_ldif($srp, $dn, $filter,$attributes,$recursive);
-      }
-    } else {
-      $display.= $this->gen_one_entry($dn);
-    }
-    return ($display);
+      $attrs  = (count($attributes))?implode($attributes,' '):'';
+      $scope = (!empty($scope))?' -s '.$scope: '';
+      $limit = (!$limit)?'':' -z '.$limit;
+      $dn = escapeshellarg($dn);
+      $admin = escapeshellarg($this->binddn);
+      $pwd = escapeshellarg($this->bindpw);
+      $filter = escapeshellarg($filter);
+      $host = escapeshellarg($this->hostname);
+      $cmd = "ldapsearch -x -LLLL -D {$admin} -w {$pwd} {$filter} {$limit} {$scope} -H {$host} -b {$dn} $attrs ";
+      ob_start();
+      passthru($cmd);
+      $res=ob_get_contents();
+      ob_end_clean();
+      return($res);
   }
 
 
@@ -904,57 +906,6 @@ class LDAP{
   }
 
 
-  function gen_one_entry($dn, $filter= "(objectClass=*)" , $name= array("*"))
-  {
-    $ret = "";
-    $data = "";
-    if($this->reconnect){
-      $this->connect();
-    }
-
-    /* Searching Ldap Tree */
-    $sr= @ldap_read($this->cid, LDAP::fix($dn), $filter, $name);
-
-    /* Get the first entry */   
-    $entry= @ldap_first_entry($this->cid, $sr);
-
-    /* Get all attributes related to that Objekt */
-    $atts = array();
-    
-    /* Assemble dn */
-    $atts[0]['name']  = "dn";
-    $atts[0]['value'] = array('count' => 1, 0 => $dn);
-
-    /* Reset index */
-    $i = 1 ; 
-  $identifier = array();
-    $attribute= @ldap_first_attribute($this->cid,$entry,$identifier);
-    while ($attribute) {
-      $i++;
-      $atts[$i]['name']  = $attribute;
-      $atts[$i]['value'] = @ldap_get_values_len($this->cid, $entry, "$attribute");
-
-      /* Next one */
-      $attribute= @ldap_next_attribute($this->cid,$entry,$identifier);
-    }
-
-    foreach($atts as $at)
-    {
-      for ($i= 0; $i<$at['value']['count']; $i++){
-
-        /* Check if we must encode the data */
-        if(!preg_match('/^[a-z0-9+@#.=, \/ -]+$/i', $at['value'][$i])) {
-          $ret .= $at['name'].":: ".base64_encode($at['value'][$i])."\n";
-        } else {
-          $ret .= $at['name'].": ".$at['value'][$i]."\n";
-        }
-      }
-    }
-
-    return($ret);
-  }
-
-
   function dn_exists($dn)
   {
     return @ldap_list($this->cid, LDAP::fix($dn), "(objectClass=*)", array("objectClass"));
@@ -1255,7 +1206,7 @@ class LDAP{
 
     /* Only read schema if it is allowed */
     if(isset($config) && preg_match("/config/i",get_class($config))){
-      if ($config->get_cfg_value("schemaCheck") != "true"){
+      if ($config->get_cfg_value("core","schemaCheck") != "true"){
         return($objectclasses);
       } 
     }