Code

Added property class to get_cfg_requests
[gosa.git] / gosa-core / include / class_userinfo.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class userinfo
24 {
25   var $dn;
26   var $ip;
27   var $username;
28   var $cn;
29   var $uid;
30   var $restrictions= array();
31   var $gidNumber= -1;
32   var $language= "";
33   var $config;
34   var $gosaUnitTag= "";
35   var $subtreeACL= array();
36   var $ACL= array();
37   var $ocMapping= array();
38   var $groups= array();
39   var $result_cache =array();
40   var $ignoreACL = FALSE;
41   var $ACLperPath = array();
42   var $ACLperPath_usesFilter = array();
44   /* get acl's an put them into the userinfo object
45      attr subtreeACL (userdn:components, userdn:component1#sub1#sub2,component2,...) */
46   function userinfo(&$config, $userdn){
47     $this->config= &$config;
48     $ldap= $this->config->get_ldap_link();
49     $ldap->cat($userdn,array('sn', 'givenName', 'uid', 'gidNumber', 'preferredLanguage', 'gosaUnitTag', 'gosaLoginRestriction'));
50     $attrs= $ldap->fetch();
52     if (isset($attrs['givenName'][0]) && isset($attrs['sn'][0])){
53       $this->cn= $attrs['givenName'][0]." ".$attrs['sn'][0];
54     } else {
55       $this->cn= $attrs['uid'][0];
56     }
57     if (isset($attrs['gidNumber'][0])){
58       $this->gidNumber= $attrs['gidNumber'][0];
59     }
61     /* Restrictions? */
62     if (isset($attrs['gosaLoginRestriction'])){
63       $this->restrictions= $attrs['gosaLoginRestriction'];
64       unset($this->restrictions['count']);
65     }
67     /* Assign user language */
68     if (isset($attrs['preferredLanguage'][0])){
69       $this->language= $attrs['preferredLanguage'][0];
70     }
72     if (isset($attrs['gosaUnitTag'][0])){
73       $this->gosaUnitTag= $attrs['gosaUnitTag'][0];
74     }
76     $this->dn= $userdn;
77     $this->uid= $attrs['uid'][0];
78     $this->ip= $_SERVER['REMOTE_ADDR'];
80     $this->ignoreACL = ($this->config->get_cfg_value("core","ignoreAcl") == $this->dn);
82     /* Initialize ACL_CACHE */
83     $this->reset_acl_cache();
84   }
87   public function reset_acl_cache()
88   {
89     /* Initialize ACL_CACHE */
90     session::global_set('ACL_CACHE',array());
91   }
93   function loadACL()
94   {
95     $this->ACL= array();    
96     $this->allACLs= array();    
97     $this->groups= array();    
98     $this->result_cache =array();
99     $this->reset_acl_cache();
100     $ldap= $this->config->get_ldap_link();
101     $ldap->cd($this->config->current['BASE']);
103     /* Get member groups... */
104     $ldap->search("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array('dn'));
105     while ($attrs= $ldap->fetch()){
106       $this->groups[$attrs['dn']]= $attrs['dn'];
107     }
109     /* Crawl through ACLs and move relevant to the tree */
110     $ldap->search("(objectClass=gosaACL)", array('dn', 'gosaAclEntry'));
111     $aclp= array();
112     $aclc= array();
113     while ($attrs= $ldap->fetch()){
115       /* Insert links in ACL array */
116       $aclp[$attrs['dn']]= substr_count($attrs['dn'], ',');
117       $aclc[$attrs['dn']]= array();
118       $ol= array();
119       for($i= 0; $i<$attrs['gosaAclEntry']['count']; $i++){
120         $ol= array_merge($ol, @acl::explodeAcl($attrs['gosaAclEntry'][$i]));
121       }
122       $aclc[$attrs['dn']]= $ol;
123     }
125     /* Resolve roles here. 
126      */
127     foreach($aclc as $dn => $data){
128       foreach($data as $prio => $aclc_value)  {
129         if($aclc_value['type'] == "role"){
131           unset($aclc[$dn][$prio]);
133           $ldap->cat($aclc_value['acl'],array("gosaAclTemplate"));
134           $attrs = $ldap->fetch();
136           if(isset($attrs['gosaAclTemplate'])){
137             for($i= 0; $i<$attrs['gosaAclTemplate']['count']; $i++){
138               $tmp = @acl::explodeAcl($attrs['gosaAclTemplate'][$i]);  
140               foreach($tmp as $new_acl){
142                 /* Keep non role attributes here! */
143                 $new_acl['filter'] = $aclc_value['filter'];
144                 $new_acl['members'] = $aclc_value['members'];
145                 $aclc[$dn][] =$new_acl;
146               }
147             }      
148           }
149         }
150       }
151     }
153     /* ACL's read, sort for tree depth */
154     asort($aclp);
156     /* Sort in tree order */
157     foreach ($aclp as $dn => $acl){
158       /* Check if we need to keep this ACL */
159       foreach($aclc[$dn] as $idx => $type){
160         $interresting= FALSE;
161         
162         /* No members? This ACL rule is deactivated ... */
163         if (!count($type['members'])){
164           $interresting= FALSE; 
165         } else {
167           /* Inspect members... */
168           foreach ($type['members'] as $grp => $grpdsc){
170             /* Some group inside the members that is relevant for us? */
171             if (in_array_ics(@LDAP::convert(preg_replace('/^G:/', '', $grp)), $this->groups)){
172               $interresting= TRUE;
173             }
175             /* User inside the members? */
176             if (preg_replace('/^U:/', '', $grp) == $this->dn){
177               $interresting= TRUE;
178             }
180             /* Wildcard? */
181             if (preg_match('/^G:\*/',  $grp)){
182               $interresting= TRUE;
183             }
184             $this->allACLs[$dn][$idx]= $type;
185           }
186         }
188         if ($interresting){
189           if (!isset($this->ACL[$dn])){
190             $this->ACL[$dn]= array();
191           }
192           $this->ACL[$dn][$idx]= $type;
193         }
194       }
195     }
197     /* Create an array which represenet all relevant permissions settings 
198         per dn.
200       The array will look like this:
201       
202       .     ['ou=base']        ['ou=base']          = array(ACLs);
203       .     
204       .     ['ou=dep1,ou=base']['ou=dep1,ou=base']  = array(ACLs);
205       .                        ['ou=base']          = array(ACLs);
208       For object located in 'ou=dep1,ou=base' we have to both ACLs,
209        for objects in 'ou=base' we only have to apply on ACL.
210      */
211     $without_self_acl = $all_acl = array();
212     foreach($this->ACL as $dn => $acl){
213       $sdn =$dn;
214       $first= TRUE; // Run at least once 
215       while(strpos($dn,",") !== FALSE || $first){
216         $first = FALSE;
217         if(isset($this->ACL[$dn])){
218           $all_acl[$sdn][$dn] = $this->ACL[$dn];
219           $without_self_acl[$sdn][$dn] = $this->ACL[$dn]; 
220           foreach($without_self_acl[$sdn][$dn] as $acl_id => $acl_set){
221   
222             /* Remember which ACL set has speicial user filter 
223              */
224             if(isset($acl_set['filter']{1})){
225               $this->ACLperPath_usesFilter[$sdn] = TRUE;
226             }
227           
228             /* Remove all acl entries which are especially for the current user (self acl)
229              */
230             if(isset($acl_set['acl'])){ 
231                 foreach($acl_set['acl'] as $object => $object_acls){
232                     if(isset($object_acls[0]) && strpos($object_acls[0],"s")){
233                         unset($without_self_acl[$sdn][$dn][$acl_id]['acl'][$object]);
234                     }
235                 }
236             }
237           }
238         }
239         $dn = preg_replace("/^[^,]*+,/","",$dn);
240       }
241     } 
242     $this->ACLperPath =$without_self_acl;
244     /* Append Self entry */
245     $dn = $this->dn;
246     while(strpos($dn,",") && !isset($all_acl[$dn])){
247       $dn = preg_replace("/^[^,]*+,/","",$dn);
248     }
249     if(isset($all_acl[$dn])){
250       $this->ACLperPath[$this->dn] = $all_acl[$dn];
251     }
252   }
255   /* Returns an array containing all target objects we've permssions on.
256    */
257   function get_acl_target_objects()
258   {
259     return(array_keys($this->ACLperPath));
260   }
261   
263   function get_category_permissions($dn, $category, $any_acl = FALSE)
264   {
265     return($this->get_permissions($dn,$category.'/0',""));
266   }
268   
269   /*! \brief Check if the given object (dn) is copyable
270       @param  String The object dn 
271       @param  String The acl  category (e.g. users) 
272       @param  String The acl  class (e.g. user) 
273       @return Boolean   TRUE if the given object is copyable else FALSE 
274   */
275   function is_copyable($dn, $object, $class)
276   {
277     return(preg_match("/r/",$this->has_complete_category_acls($dn, $object)));
278   }
281   /*! \brief Check if the given object (dn) is cutable
282       @param  String The object dn 
283       @param  String The acl  category (e.g. users) 
284       @param  String The acl  class (e.g. user) 
285       @return Boolean   TRUE if the given object is cutable else FALSE 
286   */
287   function is_cutable($dn, $object, $class)
288   {
289     $remove = preg_match("/d/",$this->get_permissions($dn,$object."/".$class));
290     $read   = preg_match("/r/",$this->has_complete_category_acls($dn, $object));
291     return($remove && $read);
292   }
295   /*! \brief  Checks if we are allowed to paste an object to the given destination ($dn)
296       @param  String The destination dn 
297       @param  String The acl  category (e.g. users) 
298       @param  String The acl  class (e.g. user) 
299       @return Boolean   TRUE if we are allowed to paste an object.
300   */
301   function is_pasteable($dn, $object)
302   {
303     return(preg_match("/w/",$this->has_complete_category_acls($dn, $object)));
304   }
307   /*! \brief  Checks if we are allowed to restore a snapshot for the given dn.
308       @param  String The destination dn 
309       @param  String The acl  category (e.g. users) 
310       @return Boolean   TRUE if we are allowed to restore a snapshot.
311   */
312   function allow_snapshot_restore($dn, $object)
313   {
314     if(!is_array($object)){
315       $object = array($object);
316     }
317     $r = $w = TRUE;
318     foreach($object as $category){
319       $w &= preg_match("/w/",$this->has_complete_category_acls($dn, $category));
320       $r &= preg_match("/r/",$this->has_complete_category_acls($dn, $category));
321     }
322     return($r && $w ); 
323   }  
326   /*! \brief  Checks if we are allowed to create a snapshot of the given dn.
327       @param  String The source dn 
328       @param  String The acl category (e.g. users) 
329       @return Boolean   TRUE if we are allowed to restore a snapshot.
330   */
331   function allow_snapshot_create($dn, $object)
332   {
333     if(!is_array($object)){
334       $object = array($object);
335     }
336     $r = TRUE;
337     foreach($object as $category){
338       $r &= preg_match("/r/",$this->has_complete_category_acls($dn, $category));
339     }
340     return($r) ; 
341   }  
344   function get_permissions($dn, $object, $attribute= "", $skip_write= FALSE)
345   {
346     /* If we are forced to skip ACLs checks for the current user 
347         then return all permissions.
348      */
349     if($this->ignore_acl_for_current_user()){
350       if($skip_write){
351         return("rcdm");
352       }
353       return("rwcdm");
354     }
356     /* Push cache answer? */
357     $ACL_CACHE = &session::global_get('ACL_CACHE');
358     if (isset($ACL_CACHE["$dn+$object+$attribute"])){
359       $ret = $ACL_CACHE["$dn+$object+$attribute"];
360       if($skip_write){
361         $ret = str_replace(array('w','c','d','m'), '',$ret);
362       }
363       return($ret);
364     }
366     /* Check for correct category and class values... */
367     if(strpos($object,'/') !== FALSE){
368       list($aclCategory, $aclClass) = preg_split("!/!", $object);
369     }else{
370       $aclCategory = $object;
371     }
373     if($this->config->get_cfg_value("core","displayErrors") == "true"){
374         if(!isset($this->ocMapping[$aclCategory])){
375             trigger_error("Invalid ACL category '".$aclCategory."'! ({$object})");
376             return("");
377         }elseif(isset($aclClass) && !in_array($aclClass, $this->ocMapping[$aclCategory])){
378             trigger_error("Invalid ACL class '".$aclClass."'! ({$object})");
379             return("");
380         }
381         if(isset($aclClass) &&class_available($aclClass)){
382             $plInfo = call_user_func(array($aclClass, 'plInfo'));
383             if(!empty($attribute) && !isset($plInfo['plProvidedAcls'][$attribute])){
384                 trigger_error("Invalid ACL attribute '".$attribute."'! ({$object})");
385                 return("");
386             }
387         }
388     }
390     /* Detect the set of ACLs we have to check for this object 
391      */
392     $adn = $dn;
393     while(!isset($this->ACLperPath[$adn]) && strpos($adn,",") !== FALSE){
394       $adn = preg_replace("/^[^,]*+,/","",$adn);
395     }
396     if(isset($this->ACLperPath[$adn])){
397       $ACL = $this->ACLperPath[$adn];
398     }else{
399       $ACL_CACHE["$dn+$object+$attribute"] = "";
400       return("");
401     }
402  
403     /* If we do not need to respect any user-filter settings 
404         we can skip the per object ACL checks.
405      */
406     $orig_dn= $dn;
407     if(!isset($this->ACLperPath_usesFilter[$adn])){
408       $dn = $adn;
409       if (isset($ACL_CACHE["$dn+$object+$attribute"])){
410         $ret = $ACL_CACHE["$dn+$object+$attribute"];
411         if(!isset($ACL_CACHE["$orig_dn+$object+$attribute"])){
412           $ACL_CACHE["$orig_dn+$object+$attribute"] = $ACL_CACHE["$dn+$object+$attribute"];
413         }
414         if($skip_write){
415           $ret = str_replace('w','',$ret);
416         }
417         return($ret);
418       }
419     }
420  
421     /* Get ldap object, for later filter checks 
422      */
423     $ldap = $this->config->get_ldap_link();
425     $acl= array("r" => "", "w" => "", "c" => "", "d" => "", "m" => "", "a" => "");
427     /* Build dn array */
428     $path= explode(',', $dn);
429     $path= array_reverse($path);
431     /* Walk along the path to evaluate the acl */
432     $cpath= "";
433     foreach ($path as $element){
435       /* Clean potential ACLs for each level */
436                         if(isset($this->config->idepartments[$cpath])){
437         $acl= $this->cleanACL($acl);
438       }
440       if ($cpath == ""){
441         $cpath= $element;
442       } else {
443         $cpath= $element.','.$cpath;
444       }
446       if (isset($ACL[$cpath])){
448         /* Inspect this ACL, place the result into ACL */
449         foreach ($ACL[$cpath] as $subacl){
451           if($subacl['type'] == "role") {
452             echo "role skipped";
453             continue;
454           }
456           /* With user filter */
457           if (isset($subacl['filter']) && !empty($subacl['filter'])){
458             $id = $dn."-".$subacl['filter'];
459             if(!isset($ACL_CACHE['FILTER'][$id])){
460               $ACL_CACHE['FILTER'][$id] = $ldap->object_match_filter($dn,$subacl['filter']);
461             }
462             if(!$ACL_CACHE['FILTER'][$id]){
463               continue;
464             }
465           }
467           /* Reset? Just clean the ACL and turn over to the next one... */
468           if ($subacl['type'] == 'reset'){
469             $acl= $this->cleanACL($acl, TRUE);
470             continue;
471           }
473           /* Self ACLs? 
474            */
475           if($dn != $this->dn && isset($subacl['acl'][$object][0]) && (strpos($subacl['acl'][$object][0],"s") !== FALSE)){
476             continue;
477           }
479           /* If attribute is "", we want to know, if we've *any* permissions here... 
480               Merge global class ACLs [0] with attributes specific ACLs [attribute].
481            */
482           if ($attribute == "" && isset($subacl['acl'][$object])){
483             foreach($subacl['acl'][$object] as $attr => $dummy){
484               $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$object][$attr]);
485             }
486             continue;
487           }
489           /* Per attribute ACL? */
490           if (isset($subacl['acl'][$object][$attribute])){
491             $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$object][$attribute]);
492             continue;
493           }
495           /* Per object ACL? */
496           if (isset($subacl['acl'][$object][0])){
497             $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$object][0]);
498             continue;
499           }
501           /* Global ACL? */
502           if (isset($subacl['acl']['all/all'][0])){
503             $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl']['all/all'][0]);
504             continue;
505           }
507           /* Global ACL? - Old style global ACL - Was removed since class_core.inc was created */
508           if (isset($subacl['acl']['all'][0])){
509             $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl']['all'][0]);
510             continue;
511           }
513           /* Category ACLs    (e.g. $object = "user/0")
514            */
515           if(strstr($object,"/0")){
516             $ocs = preg_replace("/\/0$/","",$object);
517             if(isset($this->ocMapping[$ocs])){
519               /* if $attribute is "", then check every single attribute for this object.
520                  if it is 0, then just check the object category ACL.
521                */
522               if($attribute == ""){    
523                 foreach($this->ocMapping[$ocs] as $oc){
524                   if (isset($subacl['acl'][$ocs.'/'.$oc])){
526                       // Skip ACLs wich are defined for ourselfs only - if not checking against ($ui->dn)
527                       if(isset($subacl['acl'][$ocs.'/'.$oc][0]) && 
528                               $dn != $this->dn && 
529                               strpos($subacl['acl'][$ocs.'/'.$oc][0],"s") !== FALSE) continue;
531                     foreach($subacl['acl'][$ocs.'/'.$oc] as $attr => $dummy){
532                       $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$ocs.'/'.$oc][$attr]);
533                     }
534                     continue;
535                   }
536                 }
537               }else{
538                 if(isset($subacl['acl'][$ocs.'/'.$oc][0])){
539                   if($dn != $this->dn && strpos($subacl['acl'][$ocs.'/'.$oc][0],"s") !== FALSE) continue;
540                   $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$ocs.'/'.$oc][0]);
541                 }
542               }
543             }
544             continue;
545           }
546         }
547       }
548     }
550     /* If the requested ACL is for a container object, then alter 
551         ACLs by applying cleanACL a last time.
552      */
553     if(isset($this->config->idepartments[$dn])){
554       $acl = $this->cleanACL($acl);
555     }
557     /* Assemble string */
558     $ret= "";
559     foreach ($acl as $key => $value){
560       if ($value !== ""){
561         $ret.= $key;
562       }
563     }
565     $ACL_CACHE["$dn+$object+$attribute"]= $ret;
566     $ACL_CACHE["$orig_dn+$object+$attribute"]= $ret;
568     /* Remove write if needed */
569     if ($skip_write){
570       $ret = str_replace(array('w','c','d','m'), '',$ret);
571     }
572     return ($ret);
573   }
576   /* Extract all departments that are accessible (direct or 'on the way' to an
577      accessible department) */
578   function get_module_departments($module, $skip_self_acls = FALSE )
579   {
580     /* If we are forced to skip ACLs checks for the current user 
581         then return all departments as valid.
582      */
583     if($this->ignore_acl_for_current_user()){
584       return(array_keys($this->config->idepartments));
585     }
587     /* Use cached results if possilbe */
588     $ACL_CACHE = &session::global_get('ACL_CACHE');
590     if(!is_array($module)){
591       $module = array($module);
592     }
594     global $plist;
595     $res = array();
596     foreach($module as $mod){
597       if(isset($ACL_CACHE['MODULE_DEPARTMENTS'][$mod])){
598         $res = array_merge($res,$ACL_CACHE['MODULE_DEPARTMENTS'][$mod]);
599         continue;
600       }
602       $deps = array();
604       /* Search for per object ACLs */
605       foreach($this->ACL as $dn => $infos){
606         foreach($infos as $info){
607           $found = FALSE;
608           if(isset($info['acl'])){
609               foreach($info['acl'] as $cat => $data){
611                   /* Skip self acls? */
612                   if($skip_self_acls && isset($data['0']) && (strpos($data['0'], "s") !== FALSE)) continue;
613                   if(preg_match("/^".preg_quote($mod, '/')."/",$cat)){
614                       $found =TRUE;
615                       break;
616                   }
617               } 
618         } 
620           if($found && !isset($this->config->idepartments[$dn])){
621             while(!isset($this->config->idepartments[$dn]) && strpos($dn, ",")){
622               $dn = preg_replace("/^[^,]+,/","",$dn);
623             }
624             if(isset($this->config->idepartments[$dn])){
625               $deps[$dn] = $dn;
626             }
627           }
628         }
629       }
631       /* For all gosaDepartments */
632       foreach ($this->config->departments as $dn){
633         if(isset($deps[$dn])) continue;
634         $acl = "";
635         if(strpos($mod, '/')){
636           $acl.=  $this->get_permissions($dn,$mod);
637         }else{
638           $acl.=  $this->get_category_permissions($dn,$mod,TRUE);
639         }
640         if(!empty($acl)) {
641           $deps[$dn] = $dn;
642         }
643       }
645       $ACL_CACHE['MODULE_DEPARTMENTS'][$mod] = $deps;
646       $res = array_merge($res,$deps);
647     }
649     return (array_values($res));
650   }
653   function mergeACL($acl, $type, $newACL)
654   {
655                 $at= array("psub" => "p", "sub" => "s", "one" => "1");
657     if (strpos($newACL, 'w') !== FALSE && strpos($newACL, 'r') === FALSE){
658       $newACL .= "r";
659     }
661                 /* Ignore invalid characters */
662                 $newACL= preg_replace('/[^rwcdm]/', '', $newACL);
664     foreach(str_split($newACL) as $char){
666       /* Skip "self" ACLs without combination of rwcdm, they have no effect.
667          -self flag without read/write/create/...
668        */
669       if(empty($char)) continue;
671       /* Skip permanent and subtree entries */
672       if (preg_match('/[sp]/', $acl[$char])){
673         continue;
674       }
676                         if ($type == "base" && $acl[$char] != 1) {
677                                 $acl[$char]= 0;
678                         } else {
679         $acl[$char]= $at[$type];
680                         }
681     }
683     return ($acl);
684   }
687   function cleanACL($acl, $reset= FALSE)
688   {
689     foreach ($acl as $key => $value){
691       /* Continue, if value is empty or permanent */
692       if ($value == "" || $value == "p") {
693             continue;
694       }
696       /* Reset removes everything but 'p' */
697       if ($reset && $value != 'p'){
698         $acl[$key]= "";
699         continue;
700       }
702       /* Decrease tree level */
703       if (is_int($value)){
704         if ($value){
705           $acl[$key]--;
706         } else {
707           $acl[$key]= "";
708         }
709       }
710     }
712     return ($acl);
713   }
716   /* #FIXME This could be logical wrong or could be optimized in the future
717      Return combined acls for a given category. 
718      All acls will be combined like boolean AND 
719       As example ('rwcdm' + 'rcd' + 'wrm'= 'r') 
720     
721      Results will be cached in $this->result_cache.
722       $this->result_cache will be resetted if load_acls is called.
723   */
724   function has_complete_category_acls($dn,$category)
725   {
726     $acl    = "rwcdm";
727     $types  = "rwcdm";
729     if(!is_string($category)){
730       trigger_error("category must be string");   
731       $acl = "";
732     }else{
733       if(!isset($this->result_cache['has_complete_category_acls'][$dn][$category]))   {
734         if (isset($this->ocMapping[$category])){
735           foreach($this->ocMapping[$category] as $oc){
737             /* Skip objectClass '0' (e.g. users/0) get_permissions will ever return '' ??  */
738             if($oc == "0") continue;
739             $tmp =  $this->get_permissions($dn, $category."/".$oc);
740             for($i = 0, $l= strlen($types); $i < $l; $i++) {
741               if(!preg_match("/".$types[$i]."/",$tmp)){ 
742                 $acl = preg_replace("/".$types[$i]."/","",$acl);
743               }
744             }
745           }
746         }else{
747             if($this->config->get_cfg_value("core","displayErrors") == "true"){
748                 trigger_error("Invalid type of category ".$category);
749             }
750           $acl = "";
751         }
752         $this->result_cache['has_complete_category_acls'][$dn][$category] = $acl;
753       }else{
754         $acl = $this->result_cache['has_complete_category_acls'][$dn][$category];
755       }
756     }
757     return($acl);
758   }
760  
761   /*! \brief  Returns TRUE if the current user is configured in IGNORE_ACL=".." in your gosa.conf 
762       @param  Return Boolean TRUE if we have to skip ACL checks else FALSE.
763    */ 
764   function ignore_acl_for_current_user()
765   {
766     return($this->ignoreACL);
767   }
770   function loginAllowed()
771   {
772     // Need to check restrictions?
773     if (count($this->restrictions)){
775       // We have restrictions but cannot check them
776       if (!isset($_SERVER['REMOTE_ADDR'])){
777         return false;
778       }
780       // Move to binary...
781       $source= $_SERVER['REMOTE_ADDR'];
782       foreach ($this->restrictions as $restriction) {
784         // Single IP
785         if (preg_match('/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/', $restriction)) {
786            if ($source == $restriction){
787              return true;
788            }
789         }
791         // Match with short netmask
792         if (preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\/([0-9]+)$/', $restriction, $matches)) {
793           if (isIpInNet($source, $matches[1], long2ip(~(pow(2, (32-$matches[2]))-1)))) {
794             return true;
795           }
796         }
798         // Match with long netmask
799         if (preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/', $restriction, $matches)) {
800           if (isIpInNet($source, $matches[1], $matches[2])) {
801             return true;
802           }
803         }
805       }
807       return false;
808     }
810     return true;
811   }
816 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
817 ?>