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 // Skip ACLs wich are defined for ourselfs only - if not checking against ($ui->dn)
521 if(isset($subacl['acl'][$ocs.'/'.$oc][0]) &&
522 $dn != $this->dn &&
523 strpos($subacl['acl'][$ocs.'/'.$oc][0],"s") !== FALSE) continue;
525 foreach($subacl['acl'][$ocs.'/'.$oc] as $attr => $dummy){
526 $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$ocs.'/'.$oc][$attr]);
527 }
528 continue;
529 }
530 }
531 }else{
532 if(isset($subacl['acl'][$ocs.'/'.$oc][0])){
533 if($dn != $this->dn && strpos($subacl['acl'][$ocs.'/'.$oc][0],"s") !== FALSE) continue;
534 $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$ocs.'/'.$oc][0]);
535 }
536 }
537 }
538 continue;
539 }
540 }
541 }
542 }
544 /* If the requested ACL is for a container object, then alter
545 ACLs by applying cleanACL a last time.
546 */
547 if(isset($this->config->idepartments[$dn])){
548 $acl = $this->cleanACL($acl);
549 }
551 /* Assemble string */
552 $ret= "";
553 foreach ($acl as $key => $value){
554 if ($value !== ""){
555 $ret.= $key;
556 }
557 }
559 $ACL_CACHE["$dn+$object+$attribute"]= $ret;
560 $ACL_CACHE["$orig_dn+$object+$attribute"]= $ret;
562 /* Remove write if needed */
563 if ($skip_write){
564 $ret = str_replace(array('w','c','d','m'), '',$ret);
565 }
566 return ($ret);
567 }
570 /* Extract all departments that are accessible (direct or 'on the way' to an
571 accessible department) */
572 function get_module_departments($module, $skip_self_acls = FALSE )
573 {
574 /* If we are forced to skip ACLs checks for the current user
575 then return all departments as valid.
576 */
577 if($this->ignore_acl_for_current_user()){
578 return(array_keys($this->config->idepartments));
579 }
581 /* Use cached results if possilbe */
582 $ACL_CACHE = &session::global_get('ACL_CACHE');
584 if(!is_array($module)){
585 $module = array($module);
586 }
588 global $plist;
589 $res = array();
590 foreach($module as $mod){
591 if(isset($ACL_CACHE['MODULE_DEPARTMENTS'][$mod])){
592 $res = array_merge($res,$ACL_CACHE['MODULE_DEPARTMENTS'][$mod]);
593 continue;
594 }
596 $deps = array();
598 /* Search for per object ACLs */
599 foreach($this->ACL as $dn => $infos){
600 foreach($infos as $info){
601 $found = FALSE;
602 if(isset($info['acl'])){
603 foreach($info['acl'] as $cat => $data){
605 /* Skip self acls? */
606 if($skip_self_acls && isset($data['0']) && (strpos($data['0'], "s") !== FALSE)) continue;
607 if(preg_match("/^".preg_quote($mod, '/')."/",$cat)){
608 $found =TRUE;
609 break;
610 }
611 }
612 }
614 if($found && !isset($this->config->idepartments[$dn])){
615 while(!isset($this->config->idepartments[$dn]) && strpos($dn, ",")){
616 $dn = preg_replace("/^[^,]+,/","",$dn);
617 }
618 if(isset($this->config->idepartments[$dn])){
619 $deps[$dn] = $dn;
620 }
621 }
622 }
623 }
625 /* For all gosaDepartments */
626 foreach ($this->config->departments as $dn){
627 if(isset($deps[$dn])) continue;
628 $acl = "";
629 if(strpos($mod, '/')){
630 $acl.= $this->get_permissions($dn,$mod);
631 }else{
632 $acl.= $this->get_category_permissions($dn,$mod,TRUE);
633 }
634 if(!empty($acl)) {
635 $deps[$dn] = $dn;
636 }
637 }
639 $ACL_CACHE['MODULE_DEPARTMENTS'][$mod] = $deps;
640 $res = array_merge($res,$deps);
641 }
643 return (array_values($res));
644 }
647 function mergeACL($acl, $type, $newACL)
648 {
649 $at= array("psub" => "p", "sub" => "s", "one" => "1");
651 if (strpos($newACL, 'w') !== FALSE && strpos($newACL, 'r') === FALSE){
652 $newACL .= "r";
653 }
655 /* Ignore invalid characters */
656 $newACL= preg_replace('/[^rwcdm]/', '', $newACL);
658 foreach(str_split($newACL) as $char){
660 /* Skip "self" ACLs without combination of rwcdm, they have no effect.
661 -self flag without read/write/create/...
662 */
663 if(empty($char)) continue;
665 /* Skip permanent and subtree entries */
666 if (preg_match('/[sp]/', $acl[$char])){
667 continue;
668 }
670 if ($type == "base" && $acl[$char] != 1) {
671 $acl[$char]= 0;
672 } else {
673 $acl[$char]= $at[$type];
674 }
675 }
677 return ($acl);
678 }
681 function cleanACL($acl, $reset= FALSE)
682 {
683 foreach ($acl as $key => $value){
685 /* Continue, if value is empty or permanent */
686 if ($value == "" || $value == "p") {
687 continue;
688 }
690 /* Reset removes everything but 'p' */
691 if ($reset && $value != 'p'){
692 $acl[$key]= "";
693 continue;
694 }
696 /* Decrease tree level */
697 if (is_int($value)){
698 if ($value){
699 $acl[$key]--;
700 } else {
701 $acl[$key]= "";
702 }
703 }
704 }
706 return ($acl);
707 }
710 /* #FIXME This could be logical wrong or could be optimized in the future
711 Return combined acls for a given category.
712 All acls will be combined like boolean AND
713 As example ('rwcdm' + 'rcd' + 'wrm'= 'r')
715 Results will be cached in $this->result_cache.
716 $this->result_cache will be resetted if load_acls is called.
717 */
718 function has_complete_category_acls($dn,$category)
719 {
720 $acl = "rwcdm";
721 $types = "rwcdm";
723 if(!is_string($category)){
724 trigger_error("category must be string");
725 $acl = "";
726 }else{
727 if(!isset($this->result_cache['has_complete_category_acls'][$dn][$category])) {
728 if (isset($this->ocMapping[$category])){
729 foreach($this->ocMapping[$category] as $oc){
731 /* Skip objectClass '0' (e.g. users/0) get_permissions will ever return '' ?? */
732 if($oc == "0") continue;
733 $tmp = $this->get_permissions($dn, $category."/".$oc);
734 for($i = 0, $l= strlen($types); $i < $l; $i++) {
735 if(!preg_match("/".$types[$i]."/",$tmp)){
736 $acl = preg_replace("/".$types[$i]."/","",$acl);
737 }
738 }
739 }
740 }else{
741 if($this->config->get_cfg_value("displayerrors") == "true"){
742 trigger_error("Invalid type of category ".$category);
743 }
744 $acl = "";
745 }
746 $this->result_cache['has_complete_category_acls'][$dn][$category] = $acl;
747 }else{
748 $acl = $this->result_cache['has_complete_category_acls'][$dn][$category];
749 }
750 }
751 return($acl);
752 }
755 /*! \brief Returns TRUE if the current user is configured in IGNORE_ACL=".." in your gosa.conf
756 @param Return Boolean TRUE if we have to skip ACL checks else FALSE.
757 */
758 function ignore_acl_for_current_user()
759 {
760 return($this->ignoreACL);
761 }
764 function loginAllowed()
765 {
766 // Need to check restrictions?
767 if (count($this->restrictions)){
769 // We have restrictions but cannot check them
770 if (!isset($_SERVER['REMOTE_ADDR'])){
771 return false;
772 }
774 // Move to binary...
775 $source= $_SERVER['REMOTE_ADDR'];
776 foreach ($this->restrictions as $restriction) {
778 // Single IP
779 if (preg_match('/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/', $restriction)) {
780 if ($source == $restriction){
781 return true;
782 }
783 }
785 // Match with short netmask
786 if (preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\/([0-9]+)$/', $restriction, $matches)) {
787 if (isIpInNet($source, $matches[1], long2ip(~(pow(2, (32-$matches[2]))-1)))) {
788 return true;
789 }
790 }
792 // Match with long netmask
793 if (preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/', $restriction, $matches)) {
794 if (isIpInNet($source, $matches[1], $matches[2])) {
795 return true;
796 }
797 }
799 }
801 return false;
802 }
804 return true;
805 }
807 }
810 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
811 ?>