Code

Added support for f*cking colons in the dn
authorcajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 30 Jan 2006 13:06:02 +0000 (13:06 +0000)
committercajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 30 Jan 2006 13:06:02 +0000 (13:06 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2598 594d385d-05f5-0310-b6e9-bd551577e9d8

13 files changed:
include/class_config.inc
include/class_ldap.inc
include/functions.inc
include/smarty/Smarty_Compiler.class.php
plugins/admin/applications/class_applicationManagement.inc
plugins/admin/departments/class_departmentGeneric.inc
plugins/admin/departments/class_departmentManagement.inc
plugins/admin/departments/tabs_department.inc
plugins/admin/fai/class_faiManagement.inc
plugins/admin/groups/class_groupManagement.inc
plugins/admin/ogroups/class_ogroupManagement.inc
plugins/admin/systems/class_systemManagement.inc
plugins/admin/users/class_userManagement.inc

index f91dd2a549e7ecf31a22af9fd813e515f9bd6e0a..b2125dbe51c974904bfa8a2ebfe839a0da7daf13 100644 (file)
@@ -526,6 +526,9 @@ class config  {
                                unset($entries['SUB']);
                        }
 
+                       /* Fix name, if it contains a replace tag */
+                        $name= preg_replace('/###GOSAREPLACED###/', ',', $name);
+
                        /* Check if current name is too long, then cut it */
                        if(strlen($name)> $max_size){
                                $name = substr($name,0,($max_size-3))." ...";
index 20ff04037656c808190024ed349790aedc04d7b2..8d4d06aef576e62556a9818eb963a9dfb0db83dc 100644 (file)
 define("ALREADY_EXISTING_ENTRY",-10001);
 define("UNKNOWN_TOKEN_IN_LDIF_FILE",-10002);
 define("NO_FILE_UPLOADED",10003);
-
-
 define("INSERT_OK",10000);
-
-
+define("COLON_OVERRIDE", TRUE);
 
 class LDAP{
 
@@ -38,12 +35,43 @@ class LDAP{
   {
     $this->follow_referral= $follow_referral;
     $this->tls=$tls;
-    $this->binddn=$binddn;
+    $this->binddn=$this->convert($binddn);
+
     $this->bindpw=$bindpw;
     $this->hostname=$hostname;
     $this->connect();
   }
 
+
+  function convert($dn)
+  {
+    if (COLON_OVERRIDE == TRUE){
+      $res= preg_replace("/\\\\,/", '###GOSAREPLACED###', $dn);
+      $res= preg_replace("/\\\\2C/", '###GOSAREPLACED###', $res);
+      #if ($dn != $res){
+      #  echo "Conversation from '$dn' to '$res'<br>";
+      #}
+      return ($res);
+    } else {
+      return ($dn);
+    }
+  }
+
+
+  function fix($dn)
+  {
+    if (COLON_OVERRIDE == TRUE){
+      $res= preg_replace("/###GOSAREPLACED###/", '\,', $dn);
+      #if ($dn != $res){
+      #  echo "Fix from '$dn' to '$res'<br>";
+      #}
+      return ($res);
+    } else {
+      return ($dn);
+    }
+  }
+
+
   function connect()
   {
     $this->hascon=false;
@@ -59,7 +87,7 @@ class LDAP{
       }
 
       $this->error = "No Error";
-      if ($bid = @ldap_bind($this->cid, $this->binddn, $this->bindpw)) {
+      if ($bid = @ldap_bind($this->cid, $this->fix($this->binddn), $this->bindpw)) {
         $this->error = "Success";
         $this->hascon=true;
       } else {
@@ -79,7 +107,7 @@ class LDAP{
   function rebind($ldap, $referral)
   {
     $credentials= $this->get_credentials($referral);
-    if (@ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
+    if (@ldap_bind($ldap, $this->fix($credentials['ADMIN']), $credentials['PASSWORD'])) {
       $this->error = "Success";
       $this->hascon=true;
       $this->reconnect= true;
@@ -117,13 +145,15 @@ class LDAP{
     if ($dir == "..")
       $this->basedn = $this->getParentDir();
     else
-      $this->basedn = $dir;
+      $this->basedn = $this->convert($dir);
   }
 
   function getParentDir($basedn = "")
   {
     if ($basedn=="")
       $basedn = $this->basedn;
+    else
+      $basedn = $this-convert($this->basedn);
     return(ereg_replace("[^,]*[,]*[ ]*(.*)", "\\1", $basedn));
   }
 
@@ -134,7 +164,7 @@ class LDAP{
     if($this->hascon){
       if ($this->reconnect) $this->connect();
       $this->clearResult();
-      $this->sr = @ldap_search($this->cid, $this->basedn, $filter, $attrs);
+      $this->sr = @ldap_search($this->cid, $this->fix($this->basedn), $filter, $attrs);
       $this->error = @ldap_error($this->cid);
       $this->resetResult();
       $this->hasres=true;
@@ -177,7 +207,9 @@ class LDAP{
       $this->clearResult();
       if ($basedn == "")
         $basedn = $this->basedn;
-      $this->sr = @ldap_list($this->cid, $basedn, $filter,$attrs);
+      else
+        $basedn= $this->convert($basedn);
+      $this->sr = @ldap_list($this->cid, $this->fix($basedn), $filter,$attrs);
       $this->error = @ldap_error($this->cid);
       $this->resetResult();
       $this->hasres=true;
@@ -194,7 +226,7 @@ class LDAP{
       if ($this->reconnect) $this->connect();
       $this->clearResult();
       $filter = "(objectclass=*)";
-      $this->sr = @ldap_read($this->cid, $dn, $filter);
+      $this->sr = @ldap_read($this->cid, $this->fix($dn), $filter);
       $this->error = @ldap_error($this->cid);
       $this->resetResult();
       $this->hasres=true;
@@ -232,7 +264,7 @@ class LDAP{
         if ($this->re)
         {
           $att= @ldap_get_attributes($this->cid, $this->re);
-          $att['dn']= @ldap_get_dn($this->cid, $this->re);
+          $att['dn']= $this->convert(@ldap_get_dn($this->cid, $this->re));
         }
         $this->error = @ldap_error($this->cid);
         if (!isset($att)){
@@ -276,8 +308,7 @@ class LDAP{
           $rv = @ldap_get_dn($this->cid, $this->re);
         
           $this->error = @ldap_error($this->cid);
-          $rv= clean_dn($rv);
-          return($rv);
+          return($this->convert($rv));
            }
       }else{
         $this->error = "Perform a Fetch with no Search";
@@ -313,7 +344,7 @@ class LDAP{
       if ($dn == "")
         $dn = $this->basedn;
 
-      $r = @ldap_mod_del($this->cid, $dn, $attrs);
+      $r = @ldap_mod_del($this->cid, $this->fix($dn), $attrs);
       $this->error = @ldap_error($this->cid);
       return($r);
     }else{
@@ -329,7 +360,7 @@ class LDAP{
       if ($dn == "")
         $dn = $this->basedn;
 
-      $r = @ldap_mod_replace($this->cid, $dn, $attrs);
+      $r = @ldap_mod_replace($this->cid, $this->fix($dn), $attrs);
       $this->error = @ldap_error($this->cid);
       return($r);
     }else{
@@ -342,7 +373,7 @@ class LDAP{
   {
     if($this->hascon){
       if ($this->reconnect) $this->connect();
-      $r = @ldap_delete($this->cid, $deletedn);
+      $r = @ldap_delete($this->cid, $this->fix($deletedn));
       $this->error = @ldap_error($this->cid);
       return($r ? $r : 0);
     }else{
@@ -381,7 +412,7 @@ class LDAP{
       }
       
       /* Finally Delete own Node */
-      $r = @ldap_delete($this->cid, $deletedn);
+      $r = @ldap_delete($this->cid, $this->fix($deletedn));
       $this->error = @ldap_error($this->cid);
       return($r ? $r : 0);
     }else{
@@ -414,7 +445,7 @@ class LDAP{
 
         /* check if this is a department */
         if(in_array("organizationalUnit",$attr['objectClass'])){
-          $attr['dn'] = $destinationdn;
+          $attr['dn'] = $this->convert($destinationdn);
           $this->cd($basedn);
           $this->create_missing_trees($destinationdn);
           $this->cd($destinationdn);
@@ -517,7 +548,7 @@ class LDAP{
   {
     if($this->hascon){
       if ($this->reconnect) $this->connect();
-      $r = @ldap_modify($this->cid, $this->basedn, $attrs);
+      $r = @ldap_modify($this->cid, $this->fix($this->basedn), $attrs);
       $this->error = @ldap_error($this->cid);
       return($r ? $r : 0);
     }else{
@@ -530,7 +561,7 @@ class LDAP{
   {
     if($this->hascon){
       if ($this->reconnect) $this->connect();
-      $r = @ldap_add($this->cid, $this->basedn, $attrs);
+      $r = @ldap_add($this->cid, $this->fix($this->basedn), $attrs);
       $this->error = @ldap_error($this->cid);
       return($r ? $r : 0);
     }else{
@@ -615,7 +646,7 @@ class LDAP{
   {
     $data= "";
     if ($this->reconnect) $this->connect();
-    $sr= @ldap_read($this->cid, $dn, "objectClass=*", array("$name"));
+    $sr= @ldap_read($this->cid, $this->fix($dn), "objectClass=*", array("$name"));
 
     /* fill data from LDAP */
     if ($sr) {
@@ -667,7 +698,7 @@ class LDAP{
     if (isset($referrals[$server])){
       return ($referrals[$server]);
     } else {
-      $ret['ADMIN']= $this->binddn;
+      $ret['ADMIN']= $this->fix($this->binddn);
       $ret['PASSWORD']= $this->bindpw;
     }
 
@@ -725,7 +756,7 @@ function gen_xls ($dn, $filter= "(objectClass=*)", $attributes= array('*'), $rec
     }
 
     /* Searching Ldap Tree */
-    $sr= @ldap_read($this->cid, $dn, $filter, $name);
+    $sr= @ldap_read($this->cid, $this->fix($dn), $filter, $name);
 
     /* Get the first entry */   
     $entry= @ldap_first_entry($this->cid, $sr);
@@ -769,7 +800,7 @@ function gen_xls ($dn, $filter= "(objectClass=*)", $attributes= array('*'), $rec
 
   function dn_exists($dn)
   {
-    return @ldap_list($this->cid, $dn, "(objectClass=*)", array("objectClass"));
+    return @ldap_list($this->cid, $this->fix($dn), "(objectClass=*)", array("objectClass"));
   }
   
 
index 339a3ef72d94cfcdcd6371783f59fd09aeac1fd9..57ded91d438c11c7c317763fa8eb4c68d15f5df6 100644 (file)
@@ -509,7 +509,7 @@ function get_list2($subtreeACL, $filter, $subsearch= TRUE, $base="", $attrs= arr
   /* Crawl through reslut entries and perform the migration to the
      result array */
   while($attrs = $ldap->fetch()) {
-    $dn= clean_dn($ldap->getDN());
+    $dn= $ldap->getDN();
     foreach ($subtreeACL as $key => $value){
       if (preg_match("/$key/", $dn)){
         $attrs["dn"]= convert_department_dn($dn);
@@ -554,7 +554,7 @@ function get_list($subtreeACL, $filter, $subsearch= TRUE, $base="", $attrs= arra
      result array */
   $result= array();
   while($attrs = $ldap->fetch()) {
-    $dn= clean_dn($ldap->getDN());
+    $dn= $ldap->getDN();
     foreach ($subtreeACL as $key => $value){
       if (preg_match("/$key/", $dn)){
         $attrs["dn"]= $dn;
@@ -745,7 +745,7 @@ function convert_department_dn($dn)
 
   /* Build a sub-directory style list of the tree level
      specified in $dn */
-  foreach (dn_split ($dn) as $val){
+  foreach (split (',', $dn) as $val){
 
     /* We're only interested in organizational units... */
     if (preg_match ("/ou=/", $val)){
@@ -758,6 +758,9 @@ function convert_department_dn($dn)
     }
   }
 
+  /* Fix name, if it contains a replace tag */
+  $dep= preg_replace('/###GOSAREPLACED###/', ',', $dep);
+
   /* Return and remove accidently trailing slashes */
   return rtrim($dep, "/");
 }
@@ -772,11 +775,9 @@ function convert_department_dn2($dn)
 
   if(isset($deps[$dn])){
     $dn= $deps[$dn];
-    $tmp = dn_split ($dn);
-    $dep = preg_replace("/^.*=/","",$tmp[0]);
+    $dep = preg_replace("/^.*=/","",$dn);
   }else{
-    $tmp = dn_split ($dn);
-    $dep= preg_replace("%^.*/([^/]+)$%", "\\1", $tmp[0]);
+    $dep= preg_replace("%^.*/([^/]+)$%", "\\1", $dn);
   }
 
   /* Return and remove accidently trailing slashes */
@@ -1828,42 +1829,5 @@ function search_config($arr, $name, $return)
   return ("");
 }
 
-
-function dn_split($dn)
-{
-  $ret= array();
-  $tmp_dn= preg_replace('/\\\\,/', '##', $dn);
-  if (!preg_match('/,/', $tmp_dn)){
-    $ret[]= $dn;
-    return $ret;
-  }
-
-  while (1){
-
-    # Get next position of comma, exit if there
-    # are none left
-    $pos= strpos($tmp_dn, ',');
-    if ($pos === false){
-      break;
-    }
-
-    # Assign element
-    $ret[]= substr($dn, 0, $pos);
-    $tmp_dn= substr($tmp_dn, $pos + 1);
-    $dn= substr($dn, $pos + 1);
-  }
-  
-  return ($ret);
-}
-
-
-function clean_dn($dn)
-{
-  $tmp_dn= preg_replace('/\\\\,/', '<GOSA#REPLACED#KOMMA>', $dn);
-  $tmp_dn= preg_replace('/[ ]*,[ ]*/', ",", $tmp_dn);
-  $tmp_dn= preg_replace('/\<GOSA#REPLACED#KOMMA\>/', '\\,', $tmp_dn);
-  return ($tmp_dn);
-}
-
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>
index b9cb808c190d3f1a028874dd5c0eb4f6e6275d00..b444b72454528ae06bd9e4809c748373191f406c 100644 (file)
@@ -572,9 +572,9 @@ class Smarty_Compiler extends Smarty {
             default:
                 if ($this->_compile_compiler_tag($tag_command, $tag_args, $output)) {
                     return $output;
-                } else if ($this->_compile_block_tag($tag_command, $tag_args, $tag_modifier, $output)) {
+                } else if (@$this->_compile_block_tag($tag_command, $tag_args, $tag_modifier, $output)) {
                     return $output;
-                } else if ($this->_compile_custom_tag($tag_command, $tag_args, $tag_modifier, $output)) {
+                } else if (@$this->_compile_custom_tag($tag_command, $tag_args, $tag_modifier, $output)) {
                     return $output;                    
                 } else {
                     $this->_syntax_error("unrecognized tag '$tag_command'", E_USER_ERROR, __FILE__, __LINE__);
index d67167befdc16ea8e49fcc1fc6aaddc96e0e5026..261b19617f614da68115c5b7f14f0cf29721c093 100644 (file)
@@ -247,7 +247,7 @@ class applicationManagement extends plugin
                        /* Lock the current entry, so nobody will edit it during deletion */
                        add_lock ($this->dn, $this->ui->dn);
                        $smarty= get_smarty();
-                       $smarty->assign("intro", sprintf(_("You're about to delete the application '%s'."), $this->dn));
+                       $smarty->assign("intro", sprintf(_("You're about to delete the application '%s'."), LDAP::fix($this->dn)));
                        return($smarty->fetch (get_template_path('remove.tpl', TRUE)));
                } else {
 
index afa6e2744fa614fa12cdeccee17141b40c69b41e..5dbb830c8b0424ba3145a5ecf900b36e959a9174 100644 (file)
@@ -172,7 +172,7 @@ class department extends plugin
                $message[]= _("The field 'Name' contains the reserved word 'incoming'.".
                                " Please choose another name.");
        }
-       if (preg_match ('/[,#+:=>\\\\\/]/', $this->ou)){
+       if (preg_match ('/[#+:=>\\\\\/]/', $this->ou)){
                $message[]= _("The field 'Name' contains invalid characters.");
        }
        if (!is_phone_nr($this->telephoneNumber)){
index 6e2fe7950c1b3124fbbaf307894c2daf7797d2de..39c5eb93c860eeb24bc7028727470367a3d1484d 100644 (file)
@@ -182,7 +182,7 @@ class departmentManagement extends plugin
                                return(gen_locked_message($user, $this->dn));
                        } else {
                                add_lock ($this->dn, $this->ui->dn);
-                               $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), $this->dn));
+                               $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), LDAP::fix($this->dn)));
                                $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
                                return ($display);
                        }
index 25cb791ebcb05dc544eeb42e6bd21315a573fa98..1bcb786411c13aace1def936ae14a9119b0b653d 100644 (file)
@@ -19,7 +19,9 @@ class deptabs extends tabs
   function save()
   {
        $baseobject= $this->by_object['department'];
-       $new_dn= 'ou='.$baseobject->ou.','.$baseobject->base;
+       $new_dn= 'ou='.preg_replace('/,/', '\\\\2C', $baseobject->ou).','.$baseobject->base;
+       echo $new_dn."<br>";
+       echo $baseobject->ou;
 
        if ($this->dn != $new_dn && $this->dn != "new"){
                
index d540e03c27b30e0fb2ecc4f49ba777c589bf8470..a55ebc356efe257c0b1a6a9f58a2b4fdda9ab6d2 100644 (file)
@@ -223,7 +223,7 @@ class faiManagement extends plugin
 
                                /* Lock the current entry, so nobody will edit it during deletion */
                                add_lock ($this->dn, $this->ui->dn);
-                               $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), $this->dn));
+                               $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), LDAP::fix($this->dn)));
                                return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
                        } else {
 
index 003cb10acda1df598414151f615a10dee715b9c8..5ce272b32f181f4eca2f30a1241109dff2fe294d 100644 (file)
@@ -278,7 +278,7 @@ class groupManagement extends plugin
 
         /* Lock the current entry, so nobody will edit it during deletion */
         add_lock ($this->dn, $this->ui->dn);
-        $smarty->assign("info", sprintf(_("You're about to delete the group '%s'."), $this->dn));
+        $smarty->assign("info", sprintf(_("You're about to delete the group '%s'."), LDAP::fix($this->dn)));
         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
       } else {
 
index f13a3108f5a40d949059027d62f0caf7cc26ea60..d848dd856069dc554ec9a0cf7dba60fe7588f8e4 100644 (file)
@@ -214,7 +214,7 @@ class ogroupManagement extends plugin
 
         /* Lock the current entry, so nobody will edit it during deletion */
         add_lock ($this->dn, $this->ui->dn);
-        $smarty->assign("info", sprintf(_("You're about to delete the object group '%s'."), $this->dn));
+        $smarty->assign("info", sprintf(_("You're about to delete the object group '%s'."), LDAP::fix($this->dn)));
         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
       } else {
 
index 782a3ed7e05f16ceb58dac03844b3000093173aa..dd5a89608449e52a3d650058de7d515987908b3f 100644 (file)
@@ -404,7 +404,7 @@ class systems extends plugin
 
         /* Lock the current entry, so nobody will edit it during deletion */
         add_lock ($this->dn, $this->ui->dn);
-        $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), $this->dn));
+        $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), LDAP::fix($this->dn)));
         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
       } else {
 
index 857488dc67dedb344d27199fddfd73ff8ec2f482..88936bd503a44fca137274790f3a877074bdd5c7 100644 (file)
@@ -350,7 +350,7 @@ class userManagement extends plugin
 
         /* Lock the current entry, so nobody will edit it during deletion */
         add_lock ($this->dn, $this->ui->dn);
-        $smarty->assign("info", sprintf(_("You're about to delete the user %s."), $this->dn));
+        $smarty->assign("info", sprintf(_("You're about to delete the user %s."), LDAP::fix($this->dn)));
         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
       } else {