From ce84536664bde5801ec480eeff050df2ba90a045 Mon Sep 17 00:00:00 2001 From: cajus Date: Mon, 30 Jan 2006 13:06:02 +0000 Subject: [PATCH] Added support for f*cking colons in the dn git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2598 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/class_config.inc | 3 + include/class_ldap.inc | 81 +++++++++++++------ include/functions.inc | 52 ++---------- include/smarty/Smarty_Compiler.class.php | 4 +- .../class_applicationManagement.inc | 2 +- .../departments/class_departmentGeneric.inc | 2 +- .../class_departmentManagement.inc | 2 +- plugins/admin/departments/tabs_department.inc | 4 +- plugins/admin/fai/class_faiManagement.inc | 2 +- .../admin/groups/class_groupManagement.inc | 2 +- .../admin/ogroups/class_ogroupManagement.inc | 2 +- .../admin/systems/class_systemManagement.inc | 2 +- plugins/admin/users/class_userManagement.inc | 2 +- 13 files changed, 80 insertions(+), 80 deletions(-) diff --git a/include/class_config.inc b/include/class_config.inc index f91dd2a54..b2125dbe5 100644 --- a/include/class_config.inc +++ b/include/class_config.inc @@ -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))." ..."; diff --git a/include/class_ldap.inc b/include/class_ldap.inc index 20ff04037..8d4d06aef 100644 --- a/include/class_ldap.inc +++ b/include/class_ldap.inc @@ -11,11 +11,8 @@ 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'
"; + #} + 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'
"; + #} + 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")); } diff --git a/include/functions.inc b/include/functions.inc index 339a3ef72..57ded91d4 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -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('/\\\\,/', '', $dn); - $tmp_dn= preg_replace('/[ ]*,[ ]*/', ",", $tmp_dn); - $tmp_dn= preg_replace('/\/', '\\,', $tmp_dn); - return ($tmp_dn); -} - // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/include/smarty/Smarty_Compiler.class.php b/include/smarty/Smarty_Compiler.class.php index b9cb808c1..b444b7245 100644 --- a/include/smarty/Smarty_Compiler.class.php +++ b/include/smarty/Smarty_Compiler.class.php @@ -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__); diff --git a/plugins/admin/applications/class_applicationManagement.inc b/plugins/admin/applications/class_applicationManagement.inc index d67167bef..261b19617 100644 --- a/plugins/admin/applications/class_applicationManagement.inc +++ b/plugins/admin/applications/class_applicationManagement.inc @@ -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 { diff --git a/plugins/admin/departments/class_departmentGeneric.inc b/plugins/admin/departments/class_departmentGeneric.inc index afa6e2744..5dbb830c8 100644 --- a/plugins/admin/departments/class_departmentGeneric.inc +++ b/plugins/admin/departments/class_departmentGeneric.inc @@ -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)){ diff --git a/plugins/admin/departments/class_departmentManagement.inc b/plugins/admin/departments/class_departmentManagement.inc index 6e2fe7950..39c5eb93c 100644 --- a/plugins/admin/departments/class_departmentManagement.inc +++ b/plugins/admin/departments/class_departmentManagement.inc @@ -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); } diff --git a/plugins/admin/departments/tabs_department.inc b/plugins/admin/departments/tabs_department.inc index 25cb791eb..1bcb78641 100644 --- a/plugins/admin/departments/tabs_department.inc +++ b/plugins/admin/departments/tabs_department.inc @@ -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."
"; + echo $baseobject->ou; if ($this->dn != $new_dn && $this->dn != "new"){ diff --git a/plugins/admin/fai/class_faiManagement.inc b/plugins/admin/fai/class_faiManagement.inc index d540e03c2..a55ebc356 100644 --- a/plugins/admin/fai/class_faiManagement.inc +++ b/plugins/admin/fai/class_faiManagement.inc @@ -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 { diff --git a/plugins/admin/groups/class_groupManagement.inc b/plugins/admin/groups/class_groupManagement.inc index 003cb10ac..5ce272b32 100644 --- a/plugins/admin/groups/class_groupManagement.inc +++ b/plugins/admin/groups/class_groupManagement.inc @@ -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 { diff --git a/plugins/admin/ogroups/class_ogroupManagement.inc b/plugins/admin/ogroups/class_ogroupManagement.inc index f13a3108f..d848dd856 100644 --- a/plugins/admin/ogroups/class_ogroupManagement.inc +++ b/plugins/admin/ogroups/class_ogroupManagement.inc @@ -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 { diff --git a/plugins/admin/systems/class_systemManagement.inc b/plugins/admin/systems/class_systemManagement.inc index 782a3ed7e..dd5a89608 100644 --- a/plugins/admin/systems/class_systemManagement.inc +++ b/plugins/admin/systems/class_systemManagement.inc @@ -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 { diff --git a/plugins/admin/users/class_userManagement.inc b/plugins/admin/users/class_userManagement.inc index 857488dc6..88936bd50 100644 --- a/plugins/admin/users/class_userManagement.inc +++ b/plugins/admin/users/class_userManagement.inc @@ -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 { -- 2.30.2