From: cajus Date: Thu, 19 Jan 2006 11:19:11 +0000 (+0000) Subject: Added first fixes for use with existing DN's with an escaped comma inside X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=72ee99076df258ea8c038f0706c656558d88ea84;p=gosa.git Added first fixes for use with existing DN's with an escaped comma inside git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2527 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/include/class_ldap.inc b/include/class_ldap.inc index 73dc11253..6319ee80f 100644 --- a/include/class_ldap.inc +++ b/include/class_ldap.inc @@ -250,7 +250,7 @@ class LDAP{ $rv = @ldap_get_dn($this->cid, $this->re); $this->error = @ldap_error($this->cid); - $rv= preg_replace("/[ ]*,[ ]*/", ",", $rv); + $rv= clean_dn($rv); return($rv); } }else{ diff --git a/include/functions.inc b/include/functions.inc index f0afc98b3..11a949f9c 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -372,7 +372,7 @@ function add_lock ($object, $user) /* Check for existing entries in lock area */ $ldap= $config->get_ldap_link(); $ldap->cd ($config->current['CONFIG']); - $ldap->search("(&(objectClass=gosaLockEntry)(gosaUser=$user)(gosaObject=$object))", + $ldap->search("(&(objectClass=gosaLockEntry)(gosaUser=$user)(gosaObject=".base64encode($object)."))", array("gosaUser")); if (!preg_match("/Success/i", $ldap->error)){ print_red (sprintf(_("Can't set locking information in LDAP database. Please check the 'config' entry in gosa.conf! LDAP server says '%s'."), $ldap->get_error())); @@ -386,7 +386,7 @@ function add_lock ($object, $user) $ldap->cd("cn=$name,".$config->current['CONFIG']); $attrs["objectClass"] = "gosaLockEntry"; $attrs["gosaUser"] = $user; - $attrs["gosaObject"] = $object; + $attrs["gosaObject"] = base64_encode($object); $attrs["cn"] = "$name"; $ldap->add($attrs); if (!preg_match("/Success/i", $ldap->error)){ @@ -410,7 +410,7 @@ function del_lock ($object) /* Check for existance and remove the entry */ $ldap= $config->get_ldap_link(); $ldap->cd ($config->current['CONFIG']); - $ldap->search ("(&(objectClass=gosaLockEntry)(gosaObject=$object))", array("gosaObject")); + $ldap->search ("(&(objectClass=gosaLockEntry)(gosaObject=".base64_encode($object)."))", array("gosaObject")); $attrs= $ldap->fetch(); if ($ldap->getDN() != "" && preg_match("/Success/i", $ldap->error)){ $ldap->rmdir ($ldap->getDN()); @@ -454,7 +454,7 @@ function get_lock ($object) $user= ""; $ldap= $config->get_ldap_link(); $ldap->cd ($config->current['CONFIG']); - $ldap->search("(&(objectClass=gosaLockEntry)(gosaObject=$object))", array("gosaUser")); + $ldap->search("(&(objectClass=gosaLockEntry)(gosaObject=".base64_encode($object)."))", array("gosaUser")); if (!preg_match("/Success/i", $ldap->error)){ print_red (_("Can't get locking information in LDAP database. Please check the 'config' entry in gosa.conf!")); return(""); @@ -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= preg_replace("/[ ]*,[ ]*/", ",", $ldap->getDN()); + $dn= clean_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= preg_replace("/[ ]*,[ ]*/", ",", $ldap->getDN()); + $dn= clean_dn($ldap->getDN()); foreach ($subtreeACL as $key => $value){ if (preg_match("/$key/", $dn)){ $attrs["dn"]= $dn; @@ -652,8 +652,10 @@ function get_permissions ($dn, $subtreeACL) /* Successively remove leading parts of the dn's until it doesn't contain commas anymore */ - while (preg_match('/,/', $tmp)){ - $tmp= ltrim(strstr($tmp, ","), ","); + $tmp_dn= preg_replace('/\\\\,/', '', $tmp); + while (preg_match('/,/', $tmp_dn)){ + $tmp_dn= ltrim(strstr($tmp_dn, ","), ","); + $tmp= preg_replace('/\/', '\\,', $tmp); /* Check for acl that may apply */ foreach ($sacl as $key => $value){ @@ -743,16 +745,16 @@ function convert_department_dn($dn) /* Build a sub-directory style list of the tree level specified in $dn */ - foreach (split (",", $dn) as $val){ + foreach (dn_split ($dn) as $val){ /* We're only interested in organizational units... */ if (preg_match ("/ou=/", $val)){ - $dep= preg_replace("/ou=([^,]+)/", "\\1", $val)."/$dep"; + $dep= substr($val,3)."/$dep"; } /* ... and location objects */ if (preg_match ("/l=/", $val)){ - $dep= preg_replace("/l=([^,]+)/", "\\1", $val)."/$dep"; + $dep= substr($val,2)."/$dep"; } } @@ -770,10 +772,10 @@ function convert_department_dn2($dn) if(isset($deps[$dn])){ $dn= $deps[$dn]; - $tmp = split (",", $dn); + $tmp = dn_split ($dn); $dep = preg_replace("/^.*=/","",$tmp[0]); }else{ - $tmp = split (",", $dn); + $tmp = dn_split ($dn); $dep= preg_replace("%^.*/([^/]+)$%", "\\1", $tmp[0]); } @@ -1827,5 +1829,41 @@ function search_config($arr, $name, $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/plugins/admin/groups/class_groupManagement.inc b/plugins/admin/groups/class_groupManagement.inc index df4f76f29..05befca60 100644 --- a/plugins/admin/groups/class_groupManagement.inc +++ b/plugins/admin/groups/class_groupManagement.inc @@ -56,8 +56,8 @@ class groupManagement extends plugin function execute() { - /* Call parent execute */ -// plugin::execute(); + /* Call parent execute */ + plugin::execute(); /* Save data */ $groupfilter= get_global("groupfilter");