fefdb397c5036d6e11f523b91264ec66b02ad3df
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->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) = split("/", $object);
369 }else{
370 $aclCategory = $object;
371 }
373 if($this->config->get_cfg_value("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 }
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 }
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'][0])){
503 $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl']['all'][0]);
504 continue;
505 }
507 /* Category ACLs (e.g. $object = "user/0")
508 */
509 if(strstr($object,"/0")){
510 $ocs = preg_replace("/\/0$/","",$object);
511 if(isset($this->ocMapping[$ocs])){
513 /* if $attribute is "", then check every single attribute for this object.
514 if it is 0, then just check the object category ACL.
515 */
516 if($attribute == ""){
517 foreach($this->ocMapping[$ocs] as $oc){
518 if (isset($subacl['acl'][$ocs.'/'.$oc])){
520 if($dn != $this->dn && strpos($subacl['acl'][$ocs.'/'.$oc][0],"s") !== FALSE) continue;
522 foreach($subacl['acl'][$ocs.'/'.$oc] as $attr => $dummy){
523 $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$ocs.'/'.$oc][$attr]);
524 }
525 continue;
526 }
527 }
528 }else{
529 if(isset($subacl['acl'][$ocs.'/'.$oc][0])){
530 if($dn != $this->dn && strpos($subacl['acl'][$ocs.'/'.$oc][0],"s") !== FALSE) continue;
531 $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$ocs.'/'.$oc][0]);
532 }
533 }
534 }
535 continue;
536 }
537 }
538 }
539 }
541 /* If the requested ACL is for a container object, then alter
542 ACLs by applying cleanACL a last time.
543 */
544 if(isset($this->config->idepartments[$dn])){
545 $acl = $this->cleanACL($acl);
546 }
548 /* Assemble string */
549 $ret= "";
550 foreach ($acl as $key => $value){
551 if ($value !== ""){
552 $ret.= $key;
553 }
554 }
556 $ACL_CACHE["$dn+$object+$attribute"]= $ret;
557 $ACL_CACHE["$orig_dn+$object+$attribute"]= $ret;
559 /* Remove write if needed */
560 if ($skip_write){
561 $ret = str_replace(array('w','c','d','m'), '',$ret);
562 }
563 return ($ret);
564 }
567 /* Extract all departments that are accessible (direct or 'on the way' to an
568 accessible department) */
569 function get_module_departments($module, $skip_self_acls = FALSE )
570 {
571 /* If we are forced to skip ACLs checks for the current user
572 then return all departments as valid.
573 */
574 if($this->ignore_acl_for_current_user()){
575 return(array_keys($this->config->idepartments));
576 }
578 /* Use cached results if possilbe */
579 $ACL_CACHE = &session::global_get('ACL_CACHE');
581 if(!is_array($module)){
582 $module = array($module);
583 }
585 global $plist;
586 $res = array();
587 foreach($module as $mod){
588 if(isset($ACL_CACHE['MODULE_DEPARTMENTS'][$mod])){
589 $res = array_merge($res,$ACL_CACHE['MODULE_DEPARTMENTS'][$mod]);
590 continue;
591 }
593 $deps = array();
595 /* Search for per object ACLs */
596 foreach($this->ACL as $dn => $infos){
597 foreach($infos as $info){
598 $found = FALSE;
599 if(isset($info['acl'])){
600 foreach($info['acl'] as $cat => $data){
602 /* Skip self acls? */
603 if($skip_self_acls && isset($data['0']) && (strpos($data['0'], "s") !== FALSE)) continue;
604 if(preg_match("/^".preg_quote($mod, '/')."/",$cat)){
605 $found =TRUE;
606 break;
607 }
608 }
609 }
611 if($found && !isset($this->config->idepartments[$dn])){
612 while(!isset($this->config->idepartments[$dn]) && strpos($dn, ",")){
613 $dn = preg_replace("/^[^,]+,/","",$dn);
614 }
615 if(isset($this->config->idepartments[$dn])){
616 $deps[$dn] = $dn;
617 }
618 }
619 }
620 }
622 /* For all gosaDepartments */
623 foreach ($this->config->departments as $dn){
624 if(isset($deps[$dn])) continue;
625 $acl = "";
626 if(strpos($mod, '/')){
627 $acl.= $this->get_permissions($dn,$mod);
628 }else{
629 $acl.= $this->get_category_permissions($dn,$mod,TRUE);
630 }
631 if(!empty($acl)) {
632 $deps[$dn] = $dn;
633 }
634 }
636 $ACL_CACHE['MODULE_DEPARTMENTS'][$mod] = $deps;
637 $res = array_merge($res,$deps);
638 }
640 return (array_values($res));
641 }
644 function mergeACL($acl, $type, $newACL)
645 {
646 $at= array("psub" => "p", "sub" => "s", "one" => "1");
648 if (strpos($newACL, 'w') !== FALSE && strpos($newACL, 'r') === FALSE){
649 $newACL .= "r";
650 }
652 /* Ignore invalid characters */
653 $newACL= preg_replace('/[^rwcdm]/', '', $newACL);
655 foreach(str_split($newACL) as $char){
657 /* Skip "self" ACLs without combination of rwcdm, they have no effect.
658 -self flag without read/write/create/...
659 */
660 if(empty($char)) continue;
662 /* Skip permanent and subtree entries */
663 if (preg_match('/[sp]/', $acl[$char])){
664 continue;
665 }
667 if ($type == "base" && $acl[$char] != 1) {
668 $acl[$char]= 0;
669 } else {
670 $acl[$char]= $at[$type];
671 }
672 }
674 return ($acl);
675 }
678 function cleanACL($acl, $reset= FALSE)
679 {
680 foreach ($acl as $key => $value){
682 /* Continue, if value is empty or permanent */
683 if ($value == "" || $value == "p") {
684 continue;
685 }
687 /* Reset removes everything but 'p' */
688 if ($reset && $value != 'p'){
689 $acl[$key]= "";
690 continue;
691 }
693 /* Decrease tree level */
694 if (is_int($value)){
695 if ($value){
696 $acl[$key]--;
697 } else {
698 $acl[$key]= "";
699 }
700 }
701 }
703 return ($acl);
704 }
707 /* #FIXME This could be logical wrong or could be optimized in the future
708 Return combined acls for a given category.
709 All acls will be combined like boolean AND
710 As example ('rwcdm' + 'rcd' + 'wrm'= 'r')
712 Results will be cached in $this->result_cache.
713 $this->result_cache will be resetted if load_acls is called.
714 */
715 function has_complete_category_acls($dn,$category)
716 {
717 $acl = "rwcdm";
718 $types = "rwcdm";
720 if(!is_string($category)){
721 trigger_error("category must be string");
722 $acl = "";
723 }else{
724 if(!isset($this->result_cache['has_complete_category_acls'][$dn][$category])) {
725 if (isset($this->ocMapping[$category])){
726 foreach($this->ocMapping[$category] as $oc){
728 /* Skip objectClass '0' (e.g. users/0) get_permissions will ever return '' ?? */
729 if($oc == "0") continue;
730 $tmp = $this->get_permissions($dn, $category."/".$oc);
731 for($i = 0, $l= strlen($types); $i < $l; $i++) {
732 if(!preg_match("/".$types[$i]."/",$tmp)){
733 $acl = preg_replace("/".$types[$i]."/","",$acl);
734 }
735 }
736 }
737 }else{
738 if($this->config->get_cfg_value("displayerrors") == "true"){
739 trigger_error("Invalid type of category ".$category);
740 }
741 $acl = "";
742 }
743 $this->result_cache['has_complete_category_acls'][$dn][$category] = $acl;
744 }else{
745 $acl = $this->result_cache['has_complete_category_acls'][$dn][$category];
746 }
747 }
748 return($acl);
749 }
752 /*! \brief Returns TRUE if the current user is configured in IGNORE_ACL=".." in your gosa.conf
753 @param Return Boolean TRUE if we have to skip ACL checks else FALSE.
754 */
755 function ignore_acl_for_current_user()
756 {
757 return($this->ignoreACL);
758 }
761 function loginAllowed()
762 {
763 // Need to check restrictions?
764 if (count($this->restrictions)){
766 // We have restrictions but cannot check them
767 if (!isset($_SERVER['REMOTE_ADDR'])){
768 return false;
769 }
771 // Move to binary...
772 $source= $_SERVER['REMOTE_ADDR'];
773 foreach ($this->restrictions as $restriction) {
775 // Single IP
776 if (preg_match('/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/', $restriction)) {
777 if ($source == $restriction){
778 return true;
779 }
780 }
782 // Match with short netmask
783 if (preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\/([0-9]+)$/', $restriction, $matches)) {
784 if (isIpInNet($source, $matches[1], long2ip(~(pow(2, (32-$matches[2]))-1)))) {
785 return true;
786 }
787 }
789 // Match with long netmask
790 if (preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/', $restriction, $matches)) {
791 if (isIpInNet($source, $matches[1], $matches[2])) {
792 return true;
793 }
794 }
796 }
798 return false;
799 }
801 return true;
802 }
804 }
807 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
808 ?>