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;
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:
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){
222 /* Remember which ACL set has speicial user filter
223 */
224 if(isset($acl_set['filter']{1})){
225 $this->ACLperPath_usesFilter[$sdn] = TRUE;
226 }
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 }
263 function get_category_permissions($dn, $category, $any_acl = FALSE)
264 {
265 return($this->get_permissions($dn,$category.'/0',""));
266 }
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->boolValueIsTrue("core","developmentMode")){
375 if(!isset($this->ocMapping[$aclCategory])){
376 trigger_error("Invalid ACL category '".$aclCategory."'! ({$object})");
377 return("");
378 }elseif(isset($aclClass) && !in_array($aclClass, $this->ocMapping[$aclCategory])){
379 trigger_error("Invalid ACL class '".$aclClass."'! ({$object})");
380 return("");
381 }
382 if(isset($aclClass) && $aclClass != '0' && class_available($aclClass)){
383 $plInfo = call_user_func(array($aclClass, 'plInfo'));
384 if(!empty($attribute) && !isset($plInfo['plProvidedAcls'][$attribute])){
385 trigger_error("Invalid ACL attribute '".$attribute."'! ({$object})");
386 return("");
387 }
388 }
389 }
391 /* Detect the set of ACLs we have to check for this object
392 */
393 $adn = $dn;
394 while(!isset($this->ACLperPath[$adn]) && strpos($adn,",") !== FALSE){
395 $adn = preg_replace("/^[^,]*+,/","",$adn);
396 }
397 if(isset($this->ACLperPath[$adn])){
398 $ACL = $this->ACLperPath[$adn];
399 }else{
400 $ACL_CACHE["$dn+$object+$attribute"] = "";
401 return("");
402 }
404 /* If we do not need to respect any user-filter settings
405 we can skip the per object ACL checks.
406 */
407 $orig_dn= $dn;
408 if(!isset($this->ACLperPath_usesFilter[$adn])){
409 $dn = $adn;
410 if (isset($ACL_CACHE["$dn+$object+$attribute"])){
411 $ret = $ACL_CACHE["$dn+$object+$attribute"];
412 if(!isset($ACL_CACHE["$orig_dn+$object+$attribute"])){
413 $ACL_CACHE["$orig_dn+$object+$attribute"] = $ACL_CACHE["$dn+$object+$attribute"];
414 }
415 if($skip_write){
416 $ret = str_replace('w','',$ret);
417 }
418 return($ret);
419 }
420 }
422 /* Get ldap object, for later filter checks
423 */
424 $ldap = $this->config->get_ldap_link();
426 $acl= array("r" => "", "w" => "", "c" => "", "d" => "", "m" => "", "a" => "");
428 /* Build dn array */
429 $path= explode(',', $dn);
430 $path= array_reverse($path);
432 /* Walk along the path to evaluate the acl */
433 $cpath= "";
434 foreach ($path as $element){
436 /* Clean potential ACLs for each level */
437 if(isset($this->config->idepartments[$cpath])){
438 $acl= $this->cleanACL($acl);
439 }
441 if ($cpath == ""){
442 $cpath= $element;
443 } else {
444 $cpath= $element.','.$cpath;
445 }
447 if (isset($ACL[$cpath])){
449 /* Inspect this ACL, place the result into ACL */
450 foreach ($ACL[$cpath] as $subacl){
452 if($subacl['type'] == "role") {
453 echo "role skipped";
454 continue;
455 }
457 /* With user filter */
458 if (isset($subacl['filter']) && !empty($subacl['filter'])){
459 $id = $dn."-".$subacl['filter'];
460 if(!isset($ACL_CACHE['FILTER'][$id])){
461 $ACL_CACHE['FILTER'][$id] = $ldap->object_match_filter($dn,$subacl['filter']);
462 }
463 if(!$ACL_CACHE['FILTER'][$id]){
464 continue;
465 }
466 }
468 /* Reset? Just clean the ACL and turn over to the next one... */
469 if ($subacl['type'] == 'reset'){
470 $acl= $this->cleanACL($acl, TRUE);
471 continue;
472 }
474 /* Self ACLs?
475 */
476 if($dn != $this->dn && isset($subacl['acl'][$object][0]) && (strpos($subacl['acl'][$object][0],"s") !== FALSE)){
477 continue;
478 }
480 /* If attribute is "", we want to know, if we've *any* permissions here...
481 Merge global class ACLs [0] with attributes specific ACLs [attribute].
482 */
483 if ($attribute == "" && isset($subacl['acl'][$object])){
484 foreach($subacl['acl'][$object] as $attr => $dummy){
485 $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$object][$attr]);
486 }
487 continue;
488 }
490 /* Per attribute ACL? */
491 if (isset($subacl['acl'][$object][$attribute])){
492 $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$object][$attribute]);
493 continue;
494 }
496 /* Per object ACL? */
497 if (isset($subacl['acl'][$object][0])){
498 $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$object][0]);
499 continue;
500 }
502 /* Global ACL? */
503 if (isset($subacl['acl']['all/all'][0])){
504 $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl']['all/all'][0]);
505 continue;
506 }
508 /* Global ACL? - Old style global ACL - Was removed since class_core.inc was created */
509 if (isset($subacl['acl']['all'][0])){
510 $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl']['all'][0]);
511 continue;
512 }
514 /* Category ACLs (e.g. $object = "user/0")
515 */
516 if(strstr($object,"/0")){
517 $ocs = preg_replace("/\/0$/","",$object);
518 if(isset($this->ocMapping[$ocs])){
520 /* if $attribute is "", then check every single attribute for this object.
521 if it is 0, then just check the object category ACL.
522 */
523 if($attribute == ""){
524 foreach($this->ocMapping[$ocs] as $oc){
525 if (isset($subacl['acl'][$ocs.'/'.$oc])){
527 // Skip ACLs wich are defined for ourselfs only - if not checking against ($ui->dn)
528 if(isset($subacl['acl'][$ocs.'/'.$oc][0]) &&
529 $dn != $this->dn &&
530 strpos($subacl['acl'][$ocs.'/'.$oc][0],"s") !== FALSE) continue;
532 foreach($subacl['acl'][$ocs.'/'.$oc] as $attr => $dummy){
533 $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$ocs.'/'.$oc][$attr]);
534 }
535 continue;
536 }
537 }
538 }else{
539 if(isset($subacl['acl'][$ocs.'/'.$oc][0])){
540 if($dn != $this->dn && strpos($subacl['acl'][$ocs.'/'.$oc][0],"s") !== FALSE) continue;
541 $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$ocs.'/'.$oc][0]);
542 }
543 }
544 }
545 continue;
546 }
547 }
548 }
549 }
551 /* If the requested ACL is for a container object, then alter
552 ACLs by applying cleanACL a last time.
553 */
554 if(isset($this->config->idepartments[$dn])){
555 $acl = $this->cleanACL($acl);
556 }
558 /* Assemble string */
559 $ret= "";
560 foreach ($acl as $key => $value){
561 if ($value !== ""){
562 $ret.= $key;
563 }
564 }
566 $ACL_CACHE["$dn+$object+$attribute"]= $ret;
567 $ACL_CACHE["$orig_dn+$object+$attribute"]= $ret;
569 /* Remove write if needed */
570 if ($skip_write){
571 $ret = str_replace(array('w','c','d','m'), '',$ret);
572 }
573 return ($ret);
574 }
577 /* Extract all departments that are accessible (direct or 'on the way' to an
578 accessible department) */
579 function get_module_departments($module, $skip_self_acls = FALSE )
580 {
581 /* If we are forced to skip ACLs checks for the current user
582 then return all departments as valid.
583 */
584 if($this->ignore_acl_for_current_user()){
585 return(array_keys($this->config->idepartments));
586 }
588 /* Use cached results if possilbe */
589 $ACL_CACHE = &session::global_get('ACL_CACHE');
591 if(!is_array($module)){
592 $module = array($module);
593 }
595 global $plist;
596 $res = array();
597 foreach($module as $mod){
598 if(isset($ACL_CACHE['MODULE_DEPARTMENTS'][$mod])){
599 $res = array_merge($res,$ACL_CACHE['MODULE_DEPARTMENTS'][$mod]);
600 continue;
601 }
603 $deps = array();
605 /* Search for per object ACLs */
606 foreach($this->ACL as $dn => $infos){
607 foreach($infos as $info){
608 $found = FALSE;
609 if(isset($info['acl'])){
610 foreach($info['acl'] as $cat => $data){
612 /* Skip self acls? */
613 if($skip_self_acls && isset($data['0']) && (strpos($data['0'], "s") !== FALSE)) continue;
614 if(preg_match("/^".preg_quote($mod, '/')."/",$cat)){
615 $found =TRUE;
616 break;
617 }
618 }
619 }
621 if($found && !isset($this->config->idepartments[$dn])){
622 while(!isset($this->config->idepartments[$dn]) && strpos($dn, ",")){
623 $dn = preg_replace("/^[^,]+,/","",$dn);
624 }
625 if(isset($this->config->idepartments[$dn])){
626 $deps[$dn] = $dn;
627 }
628 }
629 }
630 }
632 /* For all gosaDepartments */
633 foreach ($this->config->departments as $dn){
634 if(isset($deps[$dn])) continue;
635 $acl = "";
636 if(strpos($mod, '/')){
637 $acl.= $this->get_permissions($dn,$mod);
638 }else{
639 $acl.= $this->get_category_permissions($dn,$mod,TRUE);
640 }
641 if(!empty($acl)) {
642 $deps[$dn] = $dn;
643 }
644 }
646 $ACL_CACHE['MODULE_DEPARTMENTS'][$mod] = $deps;
647 $res = array_merge($res,$deps);
648 }
650 return (array_values($res));
651 }
654 function mergeACL($acl, $type, $newACL)
655 {
656 $at= array("psub" => "p", "sub" => "s", "one" => "1");
658 if (strpos($newACL, 'w') !== FALSE && strpos($newACL, 'r') === FALSE){
659 $newACL .= "r";
660 }
662 /* Ignore invalid characters */
663 $newACL= preg_replace('/[^rwcdm]/', '', $newACL);
665 foreach(str_split($newACL) as $char){
667 /* Skip "self" ACLs without combination of rwcdm, they have no effect.
668 -self flag without read/write/create/...
669 */
670 if(empty($char)) continue;
672 /* Skip permanent and subtree entries */
673 if (preg_match('/[sp]/', $acl[$char])){
674 continue;
675 }
677 if ($type == "base" && $acl[$char] != 1) {
678 $acl[$char]= 0;
679 } else {
680 $acl[$char]= $at[$type];
681 }
682 }
684 return ($acl);
685 }
688 function cleanACL($acl, $reset= FALSE)
689 {
690 foreach ($acl as $key => $value){
692 /* Continue, if value is empty or permanent */
693 if ($value == "" || $value == "p") {
694 continue;
695 }
697 /* Reset removes everything but 'p' */
698 if ($reset && $value != 'p'){
699 $acl[$key]= "";
700 continue;
701 }
703 /* Decrease tree level */
704 if (is_int($value)){
705 if ($value){
706 $acl[$key]--;
707 } else {
708 $acl[$key]= "";
709 }
710 }
711 }
713 return ($acl);
714 }
717 /* #FIXME This could be logical wrong or could be optimized in the future
718 Return combined acls for a given category.
719 All acls will be combined like boolean AND
720 As example ('rwcdm' + 'rcd' + 'wrm'= 'r')
722 Results will be cached in $this->result_cache.
723 $this->result_cache will be resetted if load_acls is called.
724 */
725 function has_complete_category_acls($dn,$category)
726 {
727 $acl = "rwcdm";
728 $types = "rwcdm";
730 if(!is_string($category)){
731 trigger_error("category must be string");
732 $acl = "";
733 }else{
734 if(!isset($this->result_cache['has_complete_category_acls'][$dn][$category])) {
735 if (isset($this->ocMapping[$category])){
736 foreach($this->ocMapping[$category] as $oc){
738 /* Skip objectClass '0' (e.g. users/0) get_permissions will ever return '' ?? */
739 if($oc == "0") continue;
740 $tmp = $this->get_permissions($dn, $category."/".$oc);
741 for($i = 0, $l= strlen($types); $i < $l; $i++) {
742 if(!preg_match("/".$types[$i]."/",$tmp)){
743 $acl = preg_replace("/".$types[$i]."/","",$acl);
744 }
745 }
746 }
747 }else{
748 if($this->config->boolValueIsTrue("core","developmentMode")){
749 trigger_error("Invalid type of category ".$category);
750 }
751 $acl = "";
752 }
753 $this->result_cache['has_complete_category_acls'][$dn][$category] = $acl;
754 }else{
755 $acl = $this->result_cache['has_complete_category_acls'][$dn][$category];
756 }
757 }
758 return($acl);
759 }
762 /*! \brief Returns TRUE if the current user is configured in IGNORE_ACL=".." in your gosa.conf
763 @param Return Boolean TRUE if we have to skip ACL checks else FALSE.
764 */
765 function ignore_acl_for_current_user()
766 {
767 return($this->ignoreACL);
768 }
771 function loginAllowed()
772 {
773 // Need to check restrictions?
774 if (count($this->restrictions)){
776 // We have restrictions but cannot check them
777 if (!isset($_SERVER['REMOTE_ADDR'])){
778 return false;
779 }
781 // Move to binary...
782 $source= $_SERVER['REMOTE_ADDR'];
783 foreach ($this->restrictions as $restriction) {
785 // Single IP
786 if (preg_match('/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/', $restriction)) {
787 if ($source == $restriction){
788 return true;
789 }
790 }
792 // Match with short netmask
793 if (preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\/([0-9]+)$/', $restriction, $matches)) {
794 if (isIpInNet($source, $matches[1], long2ip(~(pow(2, (32-$matches[2]))-1)))) {
795 return true;
796 }
797 }
799 // Match with long netmask
800 if (preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/', $restriction, $matches)) {
801 if (isIpInNet($source, $matches[1], $matches[2])) {
802 return true;
803 }
804 }
806 }
808 return false;
809 }
811 return true;
812 }
814 }
817 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
818 ?>