X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=include%2Ffunctions.inc;h=6eda98aa4bc95f3afb0029a6819c388369b4a30e;hb=41b3851a98576e3cd9b843a63353a9e669c4f501;hp=06b898405718ebaf18ea2124aa3094ede31a112b;hpb=3844e0ef56a91ba4b0c3f9723eeba83f147a5ee4;p=gosa.git diff --git a/include/functions.inc b/include/functions.inc index 06b898405..6eda98aa4 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -2176,6 +2176,65 @@ function obj_is_writable($dn, $object, $attribute) } +function gosa_ldap_explode_dn($dn,$config = NULL,$verify_in_ldap=false) +{ + /* Initialize variables */ + $ret = array("count" => 0); // Set count to 0 + $next = true; // if false, then skip next loops and return + $cnt = 0; // Current number of loops + $max = 100; // Just for security, prevent looops + $ldap = NULL; // To check if created result a valid + $keep = ""; // save last failed parse string + + /* Check each parsed dn in ldap ? */ + if($config!=NULL && $verify_in_ldap){ + $ldap = $config->get_ldap_link(); + } + + $Diff = ldap_explode_dn($dn,0); + + /* Lets start */ + $called = false; + while(preg_match("/,/",$dn) && $next && $cnt < $max){ + + $cnt ++; + if(!preg_match("/,/",$dn)){ + $next = false; + } + $object = preg_replace("/[,].*$/","",$dn); + $dn = preg_replace("/^[^,]+,/","",$dn); + + $called = true; + + /* Check if current dn is valid */ + if($ldap!=NULL){ + $ldap->cd($dn); + $ldap->cat($dn,array("dn")); + if($ldap->count()){ + $ret[] = $keep.$object; + $keep = ""; + }else{ + $keep .= $object.","; + } + }else{ + $ret[] = $keep.$object; + $keep = ""; + } + } + + /* Append the rest */ + $test = $keep.$dn; + if($called && !empty($test)){ + $ret[] = $keep.$dn; + } + $ret['count'] = count($ret) - 1; + + $diff = array_diff($ret,$Diff); + if($diff){ + print_a(array("Diff" => $diff,"OLD" => $Diff,"NEW"=> $ret,"DEBUG"=> debug_backtrace())); + } + return($ret); +} // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?>