Code

Updated filter automatic indent
[gosa.git] / gosa-core / include / class_userinfo.inc
index c410e70db7b47e410a67239eabdbcacc5f2fd813..4ac5ea37c9167bed0153341ac223e11577f85712 100644 (file)
@@ -27,6 +27,7 @@ class userinfo
   var $username;
   var $cn;
   var $uid;
+  var $restrictions= array();
   var $gidNumber= -1;
   var $language= "";
   var $config;
@@ -36,7 +37,7 @@ class userinfo
   var $ocMapping= array();
   var $groups= array();
   var $result_cache =array();
-  var $ignoreACl = FALSE;
+  var $ignoreACL = FALSE;
   var $ACLperPath = array();
   var $ACLperPath_usesFilter = array();
 
@@ -45,7 +46,7 @@ class userinfo
   function userinfo(&$config, $userdn){
     $this->config= &$config;
     $ldap= $this->config->get_ldap_link();
-    $ldap->cat($userdn,array('sn', 'givenName', 'uid', 'gidNumber', 'preferredLanguage', 'gosaUnitTag'));
+    $ldap->cat($userdn,array('sn', 'givenName', 'uid', 'gidNumber', 'preferredLanguage', 'gosaUnitTag', 'gosaLoginRestriction'));
     $attrs= $ldap->fetch();
 
     if (isset($attrs['givenName'][0]) && isset($attrs['sn'][0])){
@@ -57,6 +58,12 @@ class userinfo
       $this->gidNumber= $attrs['gidNumber'][0];
     }
 
+    /* Restrictions? */
+    if (isset($attrs['gosaLoginRestriction'])){
+      $this->restrictions= $attrs['gosaLoginRestriction'];
+      unset($this->restrictions['count']);
+    }
+
     /* Assign user language */
     if (isset($attrs['preferredLanguage'][0])){
       $this->language= $attrs['preferredLanguage'][0];
@@ -151,15 +158,16 @@ class userinfo
       foreach($aclc[$dn] as $idx => $type){
         $interresting= FALSE;
         
-        /* No members? This is good for all users... */
+        /* No members? This ACL rule is deactivated ... */
         if (!count($type['members'])){
-          $interresting= TRUE;
+          $interresting= FALSE; 
         } else {
 
           /* Inspect members... */
           foreach ($type['members'] as $grp => $grpdsc){
+
             /* Some group inside the members that is relevant for us? */
-            if (in_array_ics(preg_replace('/^G:/', '', $grp), $this->groups)){
+            if (in_array_ics(@LDAP::convert(preg_replace('/^G:/', '', $grp)), $this->groups)){
               $interresting= TRUE;
             }
 
@@ -167,6 +175,11 @@ class userinfo
             if (preg_replace('/^U:/', '', $grp) == $this->dn){
               $interresting= TRUE;
             }
+
+            /* Wildcard? */
+            if (preg_match('/^G:\*/',  $grp)){
+              $interresting= TRUE;
+            }
           }
         }
 
@@ -196,8 +209,9 @@ class userinfo
     $without_self_acl = $all_acl = array();
     foreach($this->ACL as $dn => $acl){
       $sdn =$dn;
-      while(strpos($dn,",") !== FALSE){
-
+      $first= TRUE; // Run at least once 
+      while(strpos($dn,",") !== FALSE || $first){
+        $first = FALSE;
         if(isset($this->ACL[$dn])){
           $all_acl[$sdn][$dn] = $this->ACL[$dn];
           $without_self_acl[$sdn][$dn] = $this->ACL[$dn]; 
@@ -212,7 +226,7 @@ class userinfo
             /* Remove all acl entries which are especially for the current user (self acl)
              */
             foreach($acl_set['acl'] as $object => $object_acls){
-              if(strpos($object_acls[0],"s")){
+              if(isset($object_acls[0]) && strpos($object_acls[0],"s")){
                 unset($without_self_acl[$sdn][$dn][$acl_id]['acl'][$object]);
               }
             }
@@ -234,9 +248,17 @@ class userinfo
   }
 
 
+  /* Returns an array containing all target objects we've permssions on.
+   */
+  function get_acl_target_objects()
+  {
+    return(array_keys($this->ACLperPath));
+  }
+  
+
   function get_category_permissions($dn, $category, $any_acl = FALSE)
   {
-    return(@$this->get_permissions($dn,$category.'/0',""));
+    return($this->get_permissions($dn,$category.'/0',""));
   }
 
   
@@ -337,6 +359,20 @@ class userinfo
       return($ret);
     }
 
+    /* Check for correct category and class values... */
+    if(strpos($object,'/') !== FALSE){
+      list($aclCategory, $aclClass) = split("/", $object);
+    }else{
+      $aclCategory = $object;
+    }
+    if(!isset($this->ocMapping[$aclCategory])){
+      trigger_error("Invalid ACL category '".$aclCategory."'! ({$object})");
+      return("");
+    }elseif(isset($aclClass) && !in_array($aclClass, $this->ocMapping[$aclCategory])){
+      trigger_error("Invalid ACL class '".$aclClass."'! ({$object})");
+      return("");
+    }
+
     /* Detect the set of ACLs we have to check for this object 
      */
     $adn = $dn;
@@ -375,7 +411,7 @@ class userinfo
     $acl= array("r" => "", "w" => "", "c" => "", "d" => "", "m" => "", "a" => "");
 
     /* Build dn array */
-    $path= split(',', $dn);
+    $path= explode(',', $dn);
     $path= array_reverse($path);
 
     /* Walk along the path to evaluate the acl */
@@ -703,7 +739,52 @@ class userinfo
     return($this->ignoreACL);
   }
 
+
+  function loginAllowed()
+  {
+    // Need to check restrictions?
+    if (count($this->restrictions)){
+
+      // We have restrictions but cannot check them
+      if (!isset($_SERVER['REMOTE_ADDR'])){
+        return false;
+      }
+
+      // Move to binary...
+      $source= $_SERVER['REMOTE_ADDR'];
+      foreach ($this->restrictions as $restriction) {
+
+        // Single IP
+        if (preg_match('/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/', $restriction)) {
+           if ($source == $restriction){
+             return true;
+           }
+        }
+
+        // Match with short netmask
+        if (preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\/([0-9]+)$/', $restriction, $matches)) {
+          if (isIpInNet($source, $matches[1], long2ip(~(pow(2, (32-$matches[2]))-1)))) {
+            return true;
+          }
+        }
+
+        // Match with long netmask
+        if (preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/', $restriction, $matches)) {
+          if (isIpInNet($source, $matches[1], $matches[2])) {
+            return true;
+          }
+        }
+
+      }
+
+      return false;
+    }
+
+    return true;
+  }
+
 }
 
+
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>