Code

Updated styles
[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("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->groups= array();    
97     $this->result_cache =array();
98     $this->reset_acl_cache();
99     $ldap= $this->config->get_ldap_link();
100     $ldap->cd($this->config->current['BASE']);
102     /* Get member groups... */
103     $ldap->search("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array('dn'));
104     while ($attrs= $ldap->fetch()){
105       $this->groups[$attrs['dn']]= $attrs['dn'];
106     }
108     /* Crawl through ACLs and move relevant to the tree */
109     $ldap->search("(objectClass=gosaACL)", array('dn', 'gosaAclEntry'));
110     $aclp= array();
111     $aclc= array();
112     while ($attrs= $ldap->fetch()){
114       /* Insert links in ACL array */
115       $aclp[$attrs['dn']]= substr_count($attrs['dn'], ',');
116       $aclc[$attrs['dn']]= array();
117       $ol= array();
118       for($i= 0; $i<$attrs['gosaAclEntry']['count']; $i++){
119         $ol= array_merge($ol, @acl::explodeAcl($attrs['gosaAclEntry'][$i]));
120       }
121       $aclc[$attrs['dn']]= $ol;
122     }
124     /* Resolve roles here. 
125      */
126     foreach($aclc as $dn => $data){
127       foreach($data as $prio => $aclc_value)  {
128         if($aclc_value['type'] == "role"){
130           unset($aclc[$dn][$prio]);
132           $ldap->cat($aclc_value['acl'],array("gosaAclTemplate"));
133           $attrs = $ldap->fetch();
135           if(isset($attrs['gosaAclTemplate'])){
136             for($i= 0; $i<$attrs['gosaAclTemplate']['count']; $i++){
137               $tmp = @acl::explodeAcl($attrs['gosaAclTemplate'][$i]);  
139               foreach($tmp as $new_acl){
141                 /* Keep non role attributes here! */
142                 $new_acl['filter'] = $aclc_value['filter'];
143                 $new_acl['members'] = $aclc_value['members'];
144                 $aclc[$dn][] =$new_acl;
145               }
146             }      
147           }
148         }
149       }
150     }
152     /* ACL's read, sort for tree depth */
153     asort($aclp);
155     /* Sort in tree order */
156     foreach ($aclp as $dn => $acl){
157       /* Check if we need to keep this ACL */
158       foreach($aclc[$dn] as $idx => $type){
159         $interresting= FALSE;
160         
161         /* No members? This ACL rule is deactivated ... */
162         if (!count($type['members'])){
163           $interresting= FALSE; 
164         } else {
166           /* Inspect members... */
167           foreach ($type['members'] as $grp => $grpdsc){
169             /* Some group inside the members that is relevant for us? */
170             if (in_array_ics(@LDAP::convert(preg_replace('/^G:/', '', $grp)), $this->groups)){
171               $interresting= TRUE;
172             }
174             /* User inside the members? */
175             if (preg_replace('/^U:/', '', $grp) == $this->dn){
176               $interresting= TRUE;
177             }
179             /* Wildcard? */
180             if (preg_match('/^G:\*/',  $grp)){
181               $interresting= TRUE;
182             }
183           }
184         }
186         if ($interresting){
187           if (!isset($this->ACL[$dn])){
188             $this->ACL[$dn]= array();
189           }
190           $this->ACL[$dn][$idx]= $type;
191         }
192         $this->allACLs[$dn][$idx]= $type;
193       }
194     }
196     /* Create an array which represenet all relevant permissions settings 
197         per dn.
199       The array will look like this:
200       
201       .     ['ou=base']        ['ou=base']          = array(ACLs);
202       .     
203       .     ['ou=dep1,ou=base']['ou=dep1,ou=base']  = array(ACLs);
204       .                        ['ou=base']          = array(ACLs);
207       For object located in 'ou=dep1,ou=base' we have to both ACLs,
208        for objects in 'ou=base' we only have to apply on ACL.
209      */
210     $without_self_acl = $all_acl = array();
211     foreach($this->ACL as $dn => $acl){
212       $sdn =$dn;
213       $first= TRUE; // Run at least once 
214       while(strpos($dn,",") !== FALSE || $first){
215         $first = FALSE;
216         if(isset($this->ACL[$dn])){
217           $all_acl[$sdn][$dn] = $this->ACL[$dn];
218           $without_self_acl[$sdn][$dn] = $this->ACL[$dn]; 
219           foreach($without_self_acl[$sdn][$dn] as $acl_id => $acl_set){
220   
221             /* Remember which ACL set has speicial user filter 
222              */
223             if(isset($acl_set['filter']{1})){
224               $this->ACLperPath_usesFilter[$sdn] = TRUE;
225             }
226           
227             /* Remove all acl entries which are especially for the current user (self acl)
228              */
229             if(isset($acl_set['acl'])){ 
230                 foreach($acl_set['acl'] as $object => $object_acls){
231                     if(isset($object_acls[0]) && strpos($object_acls[0],"s")){
232                         unset($without_self_acl[$sdn][$dn][$acl_id]['acl'][$object]);
233                     }
234                 }
235             }
236           }
237         }
238         $dn = preg_replace("/^[^,]*+,/","",$dn);
239       }
240     } 
241     $this->ACLperPath =$without_self_acl;
243     /* Append Self entry */
244     $dn = $this->dn;
245     while(strpos($dn,",") && !isset($all_acl[$dn])){
246       $dn = preg_replace("/^[^,]*+,/","",$dn);
247     }
248     if(isset($all_acl[$dn])){
249       $this->ACLperPath[$this->dn] = $all_acl[$dn];
250     }
251   }
254   /* Returns an array containing all target objects we've permssions on.
255    */
256   function get_acl_target_objects()
257   {
258     return(array_keys($this->ACLperPath));
259   }
260   
262   function get_category_permissions($dn, $category, $any_acl = FALSE)
263   {
264     return($this->get_permissions($dn,$category.'/0',""));
265   }
267   
268   /*! \brief Check if the given object (dn) is copyable
269       @param  String The object dn 
270       @param  String The acl  category (e.g. users) 
271       @param  String The acl  class (e.g. user) 
272       @return Boolean   TRUE if the given object is copyable else FALSE 
273   */
274   function is_copyable($dn, $object, $class)
275   {
276     return(preg_match("/r/",$this->has_complete_category_acls($dn, $object)));
277   }
280   /*! \brief Check if the given object (dn) is cutable
281       @param  String The object dn 
282       @param  String The acl  category (e.g. users) 
283       @param  String The acl  class (e.g. user) 
284       @return Boolean   TRUE if the given object is cutable else FALSE 
285   */
286   function is_cutable($dn, $object, $class)
287   {
288     $remove = preg_match("/d/",$this->get_permissions($dn,$object."/".$class));
289     $read   = preg_match("/r/",$this->has_complete_category_acls($dn, $object));
290     return($remove && $read);
291   }
294   /*! \brief  Checks if we are allowed to paste an object to the given destination ($dn)
295       @param  String The destination dn 
296       @param  String The acl  category (e.g. users) 
297       @param  String The acl  class (e.g. user) 
298       @return Boolean   TRUE if we are allowed to paste an object.
299   */
300   function is_pasteable($dn, $object)
301   {
302     return(preg_match("/w/",$this->has_complete_category_acls($dn, $object)));
303   }
306   /*! \brief  Checks if we are allowed to restore a snapshot for the given dn.
307       @param  String The destination dn 
308       @param  String The acl  category (e.g. users) 
309       @return Boolean   TRUE if we are allowed to restore a snapshot.
310   */
311   function allow_snapshot_restore($dn, $object)
312   {
313     if(!is_array($object)){
314       $object = array($object);
315     }
316     $r = $w = TRUE;
317     foreach($object as $category){
318       $w &= preg_match("/w/",$this->has_complete_category_acls($dn, $category));
319       $r &= preg_match("/r/",$this->has_complete_category_acls($dn, $category));
320     }
321     return($r && $w ); 
322   }  
325   /*! \brief  Checks if we are allowed to create a snapshot of the given dn.
326       @param  String The source dn 
327       @param  String The acl category (e.g. users) 
328       @return Boolean   TRUE if we are allowed to restore a snapshot.
329   */
330   function allow_snapshot_create($dn, $object)
331   {
332     if(!is_array($object)){
333       $object = array($object);
334     }
335     $r = TRUE;
336     foreach($object as $category){
337       $r &= preg_match("/r/",$this->has_complete_category_acls($dn, $category));
338     }
339     return($r) ; 
340   }  
343   function get_permissions($dn, $object, $attribute= "", $skip_write= FALSE)
344   {
345     /* If we are forced to skip ACLs checks for the current user 
346         then return all permissions.
347      */
348     if($this->ignore_acl_for_current_user()){
349       if($skip_write){
350         return("rcdm");
351       }
352       return("rwcdm");
353     }
355     /* Push cache answer? */
356     $ACL_CACHE = &session::global_get('ACL_CACHE');
357     if (isset($ACL_CACHE["$dn+$object+$attribute"])){
358       $ret = $ACL_CACHE["$dn+$object+$attribute"];
359       if($skip_write){
360         $ret = str_replace(array('w','c','d','m'), '',$ret);
361       }
362       return($ret);
363     }
365     /* Check for correct category and class values... */
366     if(strpos($object,'/') !== FALSE){
367       list($aclCategory, $aclClass) = split("/", $object);
368     }else{
369       $aclCategory = $object;
370     }
372     if($this->config->get_cfg_value("displayerrors") == "true"){
373         if(!isset($this->ocMapping[$aclCategory])){
374             trigger_error("Invalid ACL category '".$aclCategory."'! ({$object})");
375             return("");
376         }elseif(isset($aclClass) && !in_array($aclClass, $this->ocMapping[$aclCategory])){
377             trigger_error("Invalid ACL class '".$aclClass."'! ({$object})");
378             return("");
379         }
380         if(isset($aclClass) &&class_available($aclClass)){
381             $plInfo = call_user_func(array($aclClass, 'plInfo'));
382             if(!empty($attribute) && !isset($plInfo['plProvidedAcls'][$attribute])){
383                 trigger_error("Invalid ACL attribute '".$attribute."'! ({$object})");
384                 return("");
385             }
386         }
387     }
389     /* Detect the set of ACLs we have to check for this object 
390      */
391     $adn = $dn;
392     while(!isset($this->ACLperPath[$adn]) && strpos($adn,",") !== FALSE){
393       $adn = preg_replace("/^[^,]*+,/","",$adn);
394     }
395     if(isset($this->ACLperPath[$adn])){
396       $ACL = $this->ACLperPath[$adn];
397     }else{
398       $ACL_CACHE["$dn+$object+$attribute"] = "";
399       return("");
400     }
401  
402     /* If we do not need to respect any user-filter settings 
403         we can skip the per object ACL checks.
404      */
405     $orig_dn= $dn;
406     if(!isset($this->ACLperPath_usesFilter[$adn])){
407       $dn = $adn;
408       if (isset($ACL_CACHE["$dn+$object+$attribute"])){
409         $ret = $ACL_CACHE["$dn+$object+$attribute"];
410         if(!isset($ACL_CACHE["$orig_dn+$object+$attribute"])){
411           $ACL_CACHE["$orig_dn+$object+$attribute"] = $ACL_CACHE["$dn+$object+$attribute"];
412         }
413         if($skip_write){
414           $ret = str_replace('w','',$ret);
415         }
416         return($ret);
417       }
418     }
419  
420     /* Get ldap object, for later filter checks 
421      */
422     $ldap = $this->config->get_ldap_link();
424     $acl= array("r" => "", "w" => "", "c" => "", "d" => "", "m" => "", "a" => "");
426     /* Build dn array */
427     $path= explode(',', $dn);
428     $path= array_reverse($path);
430     /* Walk along the path to evaluate the acl */
431     $cpath= "";
432     foreach ($path as $element){
434       /* Clean potential ACLs for each level */
435                         if(isset($this->config->idepartments[$cpath])){
436         $acl= $this->cleanACL($acl);
437       }
439       if ($cpath == ""){
440         $cpath= $element;
441       } else {
442         $cpath= $element.','.$cpath;
443       }
445       if (isset($ACL[$cpath])){
447         /* Inspect this ACL, place the result into ACL */
448         foreach ($ACL[$cpath] as $subacl){
450           /* Reset? Just clean the ACL and turn over to the next one... */
451           if ($subacl['type'] == 'reset'){
452             $acl= $this->cleanACL($acl, TRUE);
453             continue;
454           }
456           if($subacl['type'] == "role") {
457             echo "role skipped";
458             continue;
459           }
461           /* With user filter */
462           if (isset($subacl['filter']) && !empty($subacl['filter'])){
463             $id = $dn."-".$subacl['filter'];
464             if(!isset($ACL_CACHE['FILTER'][$id])){
465               $ACL_CACHE['FILTER'][$id] = $ldap->object_match_filter($dn,$subacl['filter']);
466             }
467             if(!$ACL_CACHE['FILTER'][$id]){
468               continue;
469             }
470           }
472           /* Self ACLs? 
473            */
474           if($dn != $this->dn && isset($subacl['acl'][$object][0]) && (strpos($subacl['acl'][$object][0],"s") !== FALSE)){
475             continue;
476           }
478           /* If attribute is "", we want to know, if we've *any* permissions here... 
479               Merge global class ACLs [0] with attributes specific ACLs [attribute].
480            */
481           if ($attribute == "" && isset($subacl['acl'][$object])){
482             foreach($subacl['acl'][$object] as $attr => $dummy){
483               $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$object][$attr]);
484             }
485             continue;
486           }
488           /* Per attribute ACL? */
489           if (isset($subacl['acl'][$object][$attribute])){
490             $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$object][$attribute]);
491             continue;
492           }
494           /* Per object ACL? */
495           if (isset($subacl['acl'][$object][0])){
496             $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$object][0]);
497             continue;
498           }
500           /* Global ACL? */
501           if (isset($subacl['acl']['all'][0])){
502             $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl']['all'][0]);
503             continue;
504           }
506           /* Category ACLs    (e.g. $object = "user/0")
507            */
508           if(strstr($object,"/0")){
509             $ocs = preg_replace("/\/0$/","",$object);
510             if(isset($this->ocMapping[$ocs])){
512               /* if $attribute is "", then check every single attribute for this object.
513                  if it is 0, then just check the object category ACL.
514                */
515               if($attribute == ""){    
516                 foreach($this->ocMapping[$ocs] as $oc){
517                   if (isset($subacl['acl'][$ocs.'/'.$oc])){
519                     if($dn != $this->dn && strpos($subacl['acl'][$ocs.'/'.$oc][0],"s") !== FALSE) continue;
521                     foreach($subacl['acl'][$ocs.'/'.$oc] as $attr => $dummy){
522                       $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$ocs.'/'.$oc][$attr]);
523                     }
524                     continue;
525                   }
526                 }
527               }else{
528                 if(isset($subacl['acl'][$ocs.'/'.$oc][0])){
529                   if($dn != $this->dn && strpos($subacl['acl'][$ocs.'/'.$oc][0],"s") !== FALSE) continue;
530                   $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$ocs.'/'.$oc][0]);
531                 }
532               }
533             }
534             continue;
535           }
536         }
537       }
538     }
540     /* If the requested ACL is for a container object, then alter 
541         ACLs by applying cleanACL a last time.
542      */
543     if(isset($this->config->idepartments[$dn])){
544       $acl = $this->cleanACL($acl);
545     }
547     /* Assemble string */
548     $ret= "";
549     foreach ($acl as $key => $value){
550       if ($value !== ""){
551         $ret.= $key;
552       }
553     }
555     $ACL_CACHE["$dn+$object+$attribute"]= $ret;
556     $ACL_CACHE["$orig_dn+$object+$attribute"]= $ret;
558     /* Remove write if needed */
559     if ($skip_write){
560       $ret = str_replace(array('w','c','d','m'), '',$ret);
561     }
562     return ($ret);
563   }
566   /* Extract all departments that are accessible (direct or 'on the way' to an
567      accessible department) */
568   function get_module_departments($module, $skip_self_acls = FALSE )
569   {
570     /* If we are forced to skip ACLs checks for the current user 
571         then return all departments as valid.
572      */
573     if($this->ignore_acl_for_current_user()){
574       return(array_keys($this->config->idepartments));
575     }
577     /* Use cached results if possilbe */
578     $ACL_CACHE = &session::global_get('ACL_CACHE');
580     if(!is_array($module)){
581       $module = array($module);
582     }
584     global $plist;
585     $res = array();
586     foreach($module as $mod){
587       if(isset($ACL_CACHE['MODULE_DEPARTMENTS'][$mod])){
588         $res = array_merge($res,$ACL_CACHE['MODULE_DEPARTMENTS'][$mod]);
589         continue;
590       }
592       $deps = array();
594       /* Search for per object ACLs */
595       foreach($this->ACL as $dn => $infos){
596         foreach($infos as $info){
597           $found = FALSE;
598           if(isset($info['acl'])){
599               foreach($info['acl'] as $cat => $data){
601                   /* Skip self acls? */
602                   if($skip_self_acls && isset($data['0']) && (strpos($data['0'], "s") !== FALSE)) continue;
603                   if(preg_match("/^".preg_quote($mod, '/')."/",$cat)){
604                       $found =TRUE;
605                       break;
606                   }
607               } 
608         } 
610           if($found && !isset($this->config->idepartments[$dn])){
611             while(!isset($this->config->idepartments[$dn]) && strpos($dn, ",")){
612               $dn = preg_replace("/^[^,]+,/","",$dn);
613             }
614             if(isset($this->config->idepartments[$dn])){
615               $deps[$dn] = $dn;
616             }
617           }
618         }
619       }
621       /* For all gosaDepartments */
622       foreach ($this->config->departments as $dn){
623         if(isset($deps[$dn])) continue;
624         $acl = "";
625         if(strpos($mod, '/')){
626           $acl.=  $this->get_permissions($dn,$mod);
627         }else{
628           $acl.=  $this->get_category_permissions($dn,$mod,TRUE);
629         }
630         if(!empty($acl)) {
631           $deps[$dn] = $dn;
632         }
633       }
635       $ACL_CACHE['MODULE_DEPARTMENTS'][$mod] = $deps;
636       $res = array_merge($res,$deps);
637     }
639     return (array_values($res));
640   }
643   function mergeACL($acl, $type, $newACL)
644   {
645                 $at= array("psub" => "p", "sub" => "s", "one" => "1");
647     if (strpos($newACL, 'w') !== FALSE && strpos($newACL, 'r') === FALSE){
648       $newACL .= "r";
649     }
651                 /* Ignore invalid characters */
652                 $newACL= preg_replace('/[^rwcdm]/', '', $newACL);
654     foreach(str_split($newACL) as $char){
656       /* Skip "self" ACLs without combination of rwcdm, they have no effect.
657          -self flag without read/write/create/...
658        */
659       if(empty($char)) continue;
661       /* Skip permanent and subtree entries */
662       if (preg_match('/[sp]/', $acl[$char])){
663         continue;
664       }
666                         if ($type == "base" && $acl[$char] != 1) {
667                                 $acl[$char]= 0;
668                         } else {
669         $acl[$char]= $at[$type];
670                         }
671     }
673     return ($acl);
674   }
677   function cleanACL($acl, $reset= FALSE)
678   {
679     foreach ($acl as $key => $value){
681       /* Continue, if value is empty or permanent */
682       if ($value == "" || $value == "p") {
683             continue;
684       }
686       /* Reset removes everything but 'p' */
687       if ($reset && $value != 'p'){
688         $acl[$key]= "";
689         continue;
690       }
692       /* Decrease tree level */
693       if (is_int($value)){
694         if ($value){
695           $acl[$key]--;
696         } else {
697           $acl[$key]= "";
698         }
699       }
700     }
702     return ($acl);
703   }
706   /* #FIXME This could be logical wrong or could be optimized in the future
707      Return combined acls for a given category. 
708      All acls will be combined like boolean AND 
709       As example ('rwcdm' + 'rcd' + 'wrm'= 'r') 
710     
711      Results will be cached in $this->result_cache.
712       $this->result_cache will be resetted if load_acls is called.
713   */
714   function has_complete_category_acls($dn,$category)
715   {
716     $acl    = "rwcdm";
717     $types  = "rwcdm";
719     if(!is_string($category)){
720       trigger_error("category must be string");   
721       $acl = "";
722     }else{
723       if(!isset($this->result_cache['has_complete_category_acls'][$dn][$category]))   {
724         if (isset($this->ocMapping[$category])){
725           foreach($this->ocMapping[$category] as $oc){
727             /* Skip objectClass '0' (e.g. users/0) get_permissions will ever return '' ??  */
728             if($oc == "0") continue;
729             $tmp =  $this->get_permissions($dn, $category."/".$oc);
730             for($i = 0, $l= strlen($types); $i < $l; $i++) {
731               if(!preg_match("/".$types[$i]."/",$tmp)){ 
732                 $acl = preg_replace("/".$types[$i]."/","",$acl);
733               }
734             }
735           }
736         }else{
737             if($this->config->get_cfg_value("displayerrors") == "true"){
738                 trigger_error("Invalid type of category ".$category);
739             }
740           $acl = "";
741         }
742         $this->result_cache['has_complete_category_acls'][$dn][$category] = $acl;
743       }else{
744         $acl = $this->result_cache['has_complete_category_acls'][$dn][$category];
745       }
746     }
747     return($acl);
748   }
750  
751   /*! \brief  Returns TRUE if the current user is configured in IGNORE_ACL=".." in your gosa.conf 
752       @param  Return Boolean TRUE if we have to skip ACL checks else FALSE.
753    */ 
754   function ignore_acl_for_current_user()
755   {
756     return($this->ignoreACL);
757   }
760   function loginAllowed()
761   {
762     // Need to check restrictions?
763     if (count($this->restrictions)){
765       // We have restrictions but cannot check them
766       if (!isset($_SERVER['REMOTE_ADDR'])){
767         return false;
768       }
770       // Move to binary...
771       $source= $_SERVER['REMOTE_ADDR'];
772       foreach ($this->restrictions as $restriction) {
774         // Single IP
775         if (preg_match('/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/', $restriction)) {
776            if ($source == $restriction){
777              return true;
778            }
779         }
781         // Match with short netmask
782         if (preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\/([0-9]+)$/', $restriction, $matches)) {
783           if (isIpInNet($source, $matches[1], long2ip(~(pow(2, (32-$matches[2]))-1)))) {
784             return true;
785           }
786         }
788         // Match with long netmask
789         if (preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/', $restriction, $matches)) {
790           if (isIpInNet($source, $matches[1], $matches[2])) {
791             return true;
792           }
793         }
795       }
797       return false;
798     }
800     return true;
801   }
806 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
807 ?>