Code

Backport from trunk
[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 = NULL;
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     /* Initialize ACL_CACHE */
81     $this->reset_acl_cache();
82   }
85   public function reset_acl_cache()
86   {
87     /* Initialize ACL_CACHE */
88     session::global_set('ACL_CACHE',array());
89   }
91   function loadACL()
92   {
93     $this->ACL= array();    
94     $this->allACLs= array();    
95     $this->groups= array();    
96     $this->result_cache =array();
97     $this->reset_acl_cache();
98     $ldap= $this->config->get_ldap_link();
99     $ldap->cd($this->config->current['BASE']);
101     /* Get member groups... */
102     $ldap->search("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array('dn'));
103     while ($attrs= $ldap->fetch()){
104       $this->groups[$attrs['dn']]= $attrs['dn'];
105     }
107     /* Crawl through ACLs and move relevant to the tree */
108     $ldap->search("(objectClass=gosaACL)", array('dn', 'gosaAclEntry'));
109     $aclp= array();
110     $aclc= array();
111     while ($attrs= $ldap->fetch()){
113       /* Insert links in ACL array */
114       $aclp[$attrs['dn']]= substr_count($attrs['dn'], ',');
115       $aclc[$attrs['dn']]= array();
116       $ol= array();
117       for($i= 0; $i<$attrs['gosaAclEntry']['count']; $i++){
118         $ol= array_merge($ol, @acl::explodeAcl($attrs['gosaAclEntry'][$i]));
119       }
120       $aclc[$attrs['dn']]= $ol;
121     }
123     /* Resolve roles here. 
124      */
125     foreach($aclc as $dn => $data){
126       foreach($data as $prio => $aclc_value)  {
127         if($aclc_value['type'] == "role"){
129           unset($aclc[$dn][$prio]);
131           $ldap->cat($aclc_value['acl'],array("gosaAclTemplate"));
132           $attrs = $ldap->fetch();
134           if(isset($attrs['gosaAclTemplate'])){
135             for($i= 0; $i<$attrs['gosaAclTemplate']['count']; $i++){
136               $tmp = @acl::explodeAcl($attrs['gosaAclTemplate'][$i]);  
138               foreach($tmp as $new_acl){
140                 /* Keep non role attributes here! */
141                 $new_acl['filter'] = $aclc_value['filter'];
142                 $new_acl['members'] = $aclc_value['members'];
143                 $aclc[$dn][] =$new_acl;
144               }
145             }      
146           }
147         }
148       }
149     }
151     /* ACL's read, sort for tree depth */
152     asort($aclp);
154     /* Sort in tree order */
155     foreach ($aclp as $dn => $acl){
156       /* Check if we need to keep this ACL */
157       foreach($aclc[$dn] as $idx => $type){
158         $interresting= FALSE;
159         
160         /* No members? This ACL rule is deactivated ... */
161         if (!count($type['members'])){
162           $interresting= FALSE; 
163         } else {
165           /* Inspect members... */
166           foreach ($type['members'] as $grp => $grpdsc){
168             /* Some group inside the members that is relevant for us? */
169             if (in_array_ics(@LDAP::convert(preg_replace('/^G:/', '', $grp)), $this->groups)){
170               $interresting= TRUE;
171             }
173             /* User inside the members? */
174             if (mb_strtoupper(preg_replace('/^U:/', '', $grp)) == mb_strtoupper($this->dn)){
175               $interresting= TRUE;
176             }
178             /* Wildcard? */
179             if (preg_match('/^G:\*/',  $grp)){
180               $interresting= TRUE;
181             }
182             $this->allACLs[$dn][$idx]= $type;
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       }
193     }
195     /* Create an array which represenet all relevant permissions settings 
196         per dn.
198       The array will look like this:
199       
200       .     ['ou=base']        ['ou=base']          = array(ACLs);
201       .     
202       .     ['ou=dep1,ou=base']['ou=dep1,ou=base']  = array(ACLs);
203       .                        ['ou=base']          = array(ACLs);
206       For object located in 'ou=dep1,ou=base' we have to both ACLs,
207        for objects in 'ou=base' we only have to apply on ACL.
208      */
209     $without_self_acl = $all_acl = array();
210     foreach($this->ACL as $dn => $acl){
211       $sdn =$dn;
212       $first= TRUE; // Run at least once 
213       while(strpos($dn,",") !== FALSE || $first){
214         $first = FALSE;
215         if(isset($this->ACL[$dn])){
216           $all_acl[$sdn][$dn] = $this->ACL[$dn];
217           $without_self_acl[$sdn][$dn] = $this->ACL[$dn]; 
218           foreach($without_self_acl[$sdn][$dn] as $acl_id => $acl_set){
219   
220             /* Remember which ACL set has speicial user filter 
221              */
222             if(isset($acl_set['filter']{1})){
223               $this->ACLperPath_usesFilter[$sdn] = TRUE;
224             }
225           
226             /* Remove all acl entries which are especially for the current user (self acl)
227              */
228             if(isset($acl_set['acl'])){ 
229                 foreach($acl_set['acl'] as $object => $object_acls){
230                     if(isset($object_acls[0]) && strpos($object_acls[0],"s") !== FALSE){
231                         unset($without_self_acl[$sdn][$dn][$acl_id]['acl'][$object]);
232                     }
233                 }
234             }
235           }
236         }
237         $dn = preg_replace("/^[^,]*+,/","",$dn);
238       }
239     } 
240     $this->ACLperPath =$without_self_acl;
242     /* Append Self entry */
243     $dn = $this->dn;
244     while(strpos($dn,",") && !isset($all_acl[$dn])){
245       $dn = preg_replace("/^[^,]*+,/","",$dn);
246     }
247     if(isset($all_acl[$dn])){
248       $this->ACLperPath[$this->dn] = $all_acl[$dn];
249     }
250   }
253   /* Returns an array containing all target objects we've permssions on.
254    */
255   function get_acl_target_objects()
256   {
257     return(array_keys($this->ACLperPath));
258   }
259   
261   function get_category_permissions($dn, $category, $any_acl = FALSE)
262   {
263     return($this->get_permissions($dn,$category.'/0',""));
264   }
266   
267   /*! \brief Check if the given object (dn) is copyable
268       @param  String The object dn 
269       @param  String The acl  category (e.g. users) 
270       @param  String The acl  class (e.g. user) 
271       @return Boolean   TRUE if the given object is copyable else FALSE 
272   */
273   function is_copyable($dn, $object, $class)
274   {
275     return(preg_match("/r/",$this->has_complete_category_acls($dn, $object)));
276   }
279   /*! \brief Check if the given object (dn) is cutable
280       @param  String The object dn 
281       @param  String The acl  category (e.g. users) 
282       @param  String The acl  class (e.g. user) 
283       @return Boolean   TRUE if the given object is cutable else FALSE 
284   */
285   function is_cutable($dn, $object, $class)
286   {
287     $remove = preg_match("/d/",$this->get_permissions($dn,$object."/".$class));
288     $read   = preg_match("/r/",$this->has_complete_category_acls($dn, $object));
289     return($remove && $read);
290   }
293   /*! \brief  Checks if we are allowed to paste an object to the given destination ($dn)
294       @param  String The destination dn 
295       @param  String The acl  category (e.g. users) 
296       @param  String The acl  class (e.g. user) 
297       @return Boolean   TRUE if we are allowed to paste an object.
298   */
299   function is_pasteable($dn, $object)
300   {
301     return(preg_match("/w/",$this->has_complete_category_acls($dn, $object)));
302   }
305   /*! \brief  Checks if we are allowed to restore a snapshot for the given dn.
306       @param  String The destination dn 
307       @param  String The acl  category (e.g. users) 
308       @return Boolean   TRUE if we are allowed to restore a snapshot.
309   */
310   function allow_snapshot_restore($dn, $object)
311   {
312     if(!is_array($object)){
313       $object = array($object);
314     }
315     $r = $w = TRUE;
316     foreach($object as $category){
317       $w &= preg_match("/w/",$this->has_complete_category_acls($dn, $category));
318       $r &= preg_match("/r/",$this->has_complete_category_acls($dn, $category));
319     }
320     return($r && $w ); 
321   }  
324   /*! \brief  Checks if we are allowed to create a snapshot of the given dn.
325       @param  String The source dn 
326       @param  String The acl category (e.g. users) 
327       @return Boolean   TRUE if we are allowed to restore a snapshot.
328   */
329   function allow_snapshot_create($dn, $object)
330   {
331     if(!is_array($object)){
332       $object = array($object);
333     }
334     $r = TRUE;
335     foreach($object as $category){
336       $r &= preg_match("/r/",$this->has_complete_category_acls($dn, $category));
337     }
338     return($r) ; 
339   }  
342   function get_permissions($dn, $object, $attribute= "", $skip_write= FALSE)
343   {
344     /* If we are forced to skip ACLs checks for the current user 
345         then return all permissions.
346      */
347     if($this->ignore_acl_for_current_user()){
348       if($skip_write){
349         return("rcdm");
350       }
351       return("rwcdm");
352     }
354     /* Push cache answer? */
355     $ACL_CACHE = &session::global_get('ACL_CACHE');
356     if (isset($ACL_CACHE["$dn+$object+$attribute"])){
357       $ret = $ACL_CACHE["$dn+$object+$attribute"];
358       if($skip_write){
359         $ret = str_replace(array('w','c','d','m'), '',$ret);
360       }
361       return($ret);
362     }
364     /* Check for correct category and class values... */
365     if(strpos($object,'/') !== FALSE){
366       list($aclCategory, $aclClass) = preg_split("!/!", $object);
367     }else{
368       $aclCategory = $object;
369     }
371     if($this->config->boolValueIsTrue("core","developmentMode")){
373         if(!isset($this->ocMapping[$aclCategory])){
374             trigger_error("Invalid ACL category '".$aclCategory."'! ({$object})");
375             return("");
376         }elseif(isset($aclClass) && !in_array_strict($aclClass, $this->ocMapping[$aclCategory])){
377             trigger_error("Invalid ACL class '".$aclClass."'! ({$object})");
378             return("");
379         }
380         if(isset($aclClass) && $aclClass != '0' && 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           if($subacl['type'] == "role") {
451             echo "role skipped";
452             continue;
453           }
455           /* With user filter */
456           if (isset($subacl['filter']) && !empty($subacl['filter'])){
457             $id = $dn."-".$subacl['filter'];
458             if(!isset($ACL_CACHE['FILTER'][$id])){
459               $ACL_CACHE['FILTER'][$id] = $ldap->object_match_filter($dn,$subacl['filter']);
460             }
461             if(!$ACL_CACHE['FILTER'][$id]){
462               continue;
463             }
464           }
466           /* Reset? Just clean the ACL and turn over to the next one... */
467           if ($subacl['type'] == 'reset'){
468             $acl= $this->cleanACL($acl, TRUE);
469             continue;
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/all'][0])){
502             $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl']['all/all'][0]);
503             continue;
504           }
506           /* Global ACL? - Old style global ACL - Was removed since class_core.inc was created */
507           if (isset($subacl['acl']['all'][0])){
508             $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl']['all'][0]);
509             continue;
510           }
512           /* Category ACLs    (e.g. $object = "user/0")
513            */
514           if(strstr($object,"/0")){
515             $ocs = preg_replace("/\/0$/","",$object);
516             if(isset($this->ocMapping[$ocs])){
518               /* if $attribute is "", then check every single attribute for this object.
519                  if it is 0, then just check the object category ACL.
520                */
521               if($attribute == ""){    
522                 foreach($this->ocMapping[$ocs] as $oc){
523                   if (isset($subacl['acl'][$ocs.'/'.$oc])){
525                       // Skip ACLs wich are defined for ourselfs only - if not checking against ($ui->dn)
526                       if(isset($subacl['acl'][$ocs.'/'.$oc][0]) && 
527                               $dn != $this->dn && 
528                               strpos($subacl['acl'][$ocs.'/'.$oc][0],"s") !== FALSE) continue;
530                     foreach($subacl['acl'][$ocs.'/'.$oc] as $attr => $dummy){
531                       $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$ocs.'/'.$oc][$attr]);
532                     }
533                     continue;
534                   }
535                 }
536               }else{
537                 if(isset($subacl['acl'][$ocs.'/'.$oc][0])){
538                   if($dn != $this->dn && strpos($subacl['acl'][$ocs.'/'.$oc][0],"s") !== FALSE) continue;
539                   $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$ocs.'/'.$oc][0]);
540                 }
541               }
542             }
543             continue;
544           }
545         }
546       }
547     }
549     /* If the requested ACL is for a container object, then alter 
550         ACLs by applying cleanACL a last time.
551      */
552     if(isset($this->config->idepartments[$dn])){
553       $acl = $this->cleanACL($acl);
554     }
556     /* Assemble string */
557     $ret= "";
558     foreach ($acl as $key => $value){
559       if ($value !== ""){
560         $ret.= $key;
561       }
562     }
564     $ACL_CACHE["$dn+$object+$attribute"]= $ret;
565     $ACL_CACHE["$orig_dn+$object+$attribute"]= $ret;
567     /* Remove write if needed */
568     if ($skip_write){
569       $ret = str_replace(array('w','c','d','m'), '',$ret);
570     }
571     return ($ret);
572   }
575   /* Extract all departments that are accessible (direct or 'on the way' to an
576      accessible department) */
577   function get_module_departments($module, $skip_self_acls = FALSE )
578   {
579     /* If we are forced to skip ACLs checks for the current user 
580         then return all departments as valid.
581      */
582     if($this->ignore_acl_for_current_user()){
583       return(array_keys($this->config->idepartments));
584     }
586     /* Use cached results if possilbe */
587     $ACL_CACHE = &session::global_get('ACL_CACHE');
589     if(!is_array($module)){
590       $module = array($module);
591     }
593     global $plist;
594     $res = array();
595     foreach($module as $mod){
596       if(isset($ACL_CACHE['MODULE_DEPARTMENTS'][$mod])){
597         $res = array_merge($res,$ACL_CACHE['MODULE_DEPARTMENTS'][$mod]);
598         continue;
599       }
601       $deps = array();
603       /* Search for per object ACLs */
604       foreach($this->ACL as $dn => $infos){
605         foreach($infos as $info){
606           $found = FALSE;
607           if(isset($info['acl'])){
608               foreach($info['acl'] as $cat => $data){
610                   /* Skip self acls? */
611                   if($skip_self_acls && isset($data['0']) && (strpos($data['0'], "s") !== FALSE)) continue;
612                   if(preg_match("/^".preg_quote($mod, '/')."/",$cat)){
613                       $found =TRUE;
614                       break;
615                   }
616               } 
617         } 
619           if($found && !isset($this->config->idepartments[$dn])){
620             while(!isset($this->config->idepartments[$dn]) && strpos($dn, ",")){
621               $dn = preg_replace("/^[^,]+,/","",$dn);
622             }
623             if(isset($this->config->idepartments[$dn])){
624               $deps[$dn] = $dn;
625             }
626           }
627         }
628       }
630       /* For all gosaDepartments */
631       foreach ($this->config->departments as $dn){
632         if(isset($deps[$dn])) continue;
633         $acl = "";
634         if(strpos($mod, '/')){
635           $acl.=  $this->get_permissions($dn,$mod);
636         }else{
637           $acl.=  $this->get_category_permissions($dn,$mod,TRUE);
638         }
639         if(!empty($acl)) {
640           $deps[$dn] = $dn;
641         }
642       }
644       $ACL_CACHE['MODULE_DEPARTMENTS'][$mod] = $deps;
645       $res = array_merge($res,$deps);
646     }
648     return (array_values($res));
649   }
652   function mergeACL($acl, $type, $newACL)
653   {
654                 $at= array("psub" => "p", "sub" => "s", "one" => "1");
656     if (strpos($newACL, 'w') !== FALSE && strpos($newACL, 'r') === FALSE){
657       $newACL .= "r";
658     }
660                 /* Ignore invalid characters */
661                 $newACL= preg_replace('/[^rwcdm]/', '', $newACL);
663     foreach(str_split($newACL) as $char){
665       /* Skip "self" ACLs without combination of rwcdm, they have no effect.
666          -self flag without read/write/create/...
667        */
668       if(empty($char)) continue;
670       /* Skip permanent and subtree entries */
671       if (preg_match('/[sp]/', $acl[$char])){
672         continue;
673       }
675                         if ($type == "base" && $acl[$char] != 1) {
676                                 $acl[$char]= 0;
677                         } else {
678         $acl[$char]= $at[$type];
679                         }
680     }
682     return ($acl);
683   }
686   function cleanACL($acl, $reset= FALSE)
687   {
688     foreach ($acl as $key => $value){
690       /* Continue, if value is empty or permanent */
691       if ($value == "" || $value == "p") {
692             continue;
693       }
695       /* Reset removes everything but 'p' */
696       if ($reset && $value != 'p'){
697         $acl[$key]= "";
698         continue;
699       }
701       /* Decrease tree level */
702       if (is_int($value)){
703         if ($value){
704           $acl[$key]--;
705         } else {
706           $acl[$key]= "";
707         }
708       }
709     }
711     return ($acl);
712   }
715   /* #FIXME This could be logical wrong or could be optimized in the future
716      Return combined acls for a given category. 
717      All acls will be combined like boolean AND 
718       As example ('rwcdm' + 'rcd' + 'wrm'= 'r') 
719     
720      Results will be cached in $this->result_cache.
721       $this->result_cache will be resetted if load_acls is called.
722   */
723   function has_complete_category_acls($dn,$category)
724   {
725     $acl    = "rwcdm";
726     $types  = "rwcdm";
728     if(!is_string($category)){
729       trigger_error("category must be string");   
730       $acl = "";
731     }else{
732       if(!isset($this->result_cache['has_complete_category_acls'][$dn][$category]))   {
733         if (isset($this->ocMapping[$category])){
734           foreach($this->ocMapping[$category] as $oc){
736             /* Skip objectClass '0' (e.g. users/0) get_permissions will ever return '' ??  */
737             if($oc == "0") continue;
738             $tmp =  $this->get_permissions($dn, $category."/".$oc);
739             for($i = 0, $l= strlen($types); $i < $l; $i++) {
740               if(!preg_match("/".$types[$i]."/",$tmp)){ 
741                 $acl = preg_replace("/".$types[$i]."/","",$acl);
742               }
743             }
744           }
745         }else{
746             if($this->config->boolValueIsTrue("core","developmentMode")){
747                 trigger_error("Invalid type of category ".$category);
748             }
749           $acl = "";
750         }
751         $this->result_cache['has_complete_category_acls'][$dn][$category] = $acl;
752       }else{
753         $acl = $this->result_cache['has_complete_category_acls'][$dn][$category];
754       }
755     }
756     return($acl);
757   }
759  
760   /*! \brief  Returns TRUE if the current user is configured in IGNORE_ACL=".." in your gosa.conf 
761       @param  Return Boolean TRUE if we have to skip ACL checks else FALSE.
762    */ 
763   function ignore_acl_for_current_user()
764   {
765     if($this->ignoreACL === NULL){
766         $this->ignoreACL = ($this->config->get_cfg_value("core","ignoreAcl") == $this->dn);
767     }
768     return($this->ignoreACL);
769   }
772   function loginAllowed()
773   {
774     // Need to check restrictions?
775     if (count($this->restrictions)){
777       // We have restrictions but cannot check them
778       if (!isset($_SERVER['REMOTE_ADDR'])){
779         return false;
780       }
782       // Move to binary...
783       $source= $_SERVER['REMOTE_ADDR'];
784       foreach ($this->restrictions as $restriction) {
786         // Single IP
787         if (preg_match('/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/', $restriction)) {
788            if ($source == $restriction){
789              return true;
790            }
791         }
793         // Match with short netmask
794         if (preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\/([0-9]+)$/', $restriction, $matches)) {
795           if (isIpInNet($source, $matches[1], long2ip(~(pow(2, (32-$matches[2]))-1)))) {
796             return true;
797           }
798         }
800         // Match with long netmask
801         if (preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/', $restriction, $matches)) {
802           if (isIpInNet($source, $matches[1], $matches[2])) {
803             return true;
804           }
805         }
807       }
809       return false;
810     }
812     return true;
813   }
818 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
819 ?>