index 08e232de746e1c7f0b263c45eac5c3995d2d5d5f..e550a47d83aa1d08a2be8a835eae9ca96b51c398 100644 (file)
var $username;
var $cn;
var $uid;
var $username;
var $cn;
var $uid;
+ var $restrictions= array();
var $gidNumber= -1;
var $language= "";
var $config;
var $gidNumber= -1;
var $language= "";
var $config;
var $ocMapping= array();
var $groups= array();
var $result_cache =array();
var $ocMapping= array();
var $groups= array();
var $result_cache =array();
- var $ignoreACl = FALSE;
+ var $ignoreACL = NULL;
var $ACLperPath = array();
var $ACLperPath_usesFilter = array();
var $ACLperPath = array();
var $ACLperPath_usesFilter = array();
function userinfo(&$config, $userdn){
$this->config= &$config;
$ldap= $this->config->get_ldap_link();
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])){
$attrs= $ldap->fetch();
if (isset($attrs['givenName'][0]) && isset($attrs['sn'][0])){
$this->gidNumber= $attrs['gidNumber'][0];
}
$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];
/* Assign user language */
if (isset($attrs['preferredLanguage'][0])){
$this->language= $attrs['preferredLanguage'][0];
$this->uid= $attrs['uid'][0];
$this->ip= $_SERVER['REMOTE_ADDR'];
$this->uid= $attrs['uid'][0];
$this->ip= $_SERVER['REMOTE_ADDR'];
- $this->ignoreACL = ($this->config->get_cfg_value("ignoreAcl") == $this->dn);
-
/* Initialize ACL_CACHE */
$this->reset_acl_cache();
}
/* Initialize ACL_CACHE */
$this->reset_acl_cache();
}
public function reset_acl_cache()
{
/* Initialize ACL_CACHE */
public function reset_acl_cache()
{
/* Initialize ACL_CACHE */
- session::set('ACL_CACHE',array());
+ session::global_set('ACL_CACHE',array());
}
function loadACL()
{
$this->ACL= array();
}
function loadACL()
{
$this->ACL= array();
+ $this->allACLs= array();
$this->groups= array();
$this->result_cache =array();
$this->reset_acl_cache();
$this->groups= array();
$this->result_cache =array();
$this->reset_acl_cache();
foreach($aclc[$dn] as $idx => $type){
$interresting= FALSE;
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'])){
if (!count($type['members'])){
- $interresting= TRUE;
+ $interresting= FALSE;
} else {
/* Inspect members... */
foreach ($type['members'] as $grp => $grpdsc){
} else {
/* Inspect members... */
foreach ($type['members'] as $grp => $grpdsc){
+
/* Some group inside the members that is relevant for us? */
/* 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;
}
$interresting= TRUE;
}
if (preg_replace('/^U:/', '', $grp) == $this->dn){
$interresting= TRUE;
}
if (preg_replace('/^U:/', '', $grp) == $this->dn){
$interresting= TRUE;
}
+
+ /* Wildcard? */
+ if (preg_match('/^G:\*/', $grp)){
+ $interresting= TRUE;
+ }
+ $this->allACLs[$dn][$idx]= $type;
}
}
}
}
$without_self_acl = $all_acl = array();
foreach($this->ACL as $dn => $acl){
$sdn =$dn;
$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];
if(isset($this->ACL[$dn])){
$all_acl[$sdn][$dn] = $this->ACL[$dn];
$without_self_acl[$sdn][$dn] = $this->ACL[$dn];
/* Remove all acl entries which are especially for the current user (self acl)
*/
/* 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")){
- unset($without_self_acl[$sdn][$dn][$acl_id]['acl'][$object]);
- }
+ if(isset($acl_set['acl'])){
+ foreach($acl_set['acl'] as $object => $object_acls){
+ if(isset($object_acls[0]) && strpos($object_acls[0],"s")){
+ unset($without_self_acl[$sdn][$dn][$acl_id]['acl'][$object]);
+ }
+ }
}
}
}
}
}
}
}
}
+ /* 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)
{
function get_category_permissions($dn, $category, $any_acl = FALSE)
{
- return(@$this->get_permissions($dn,$category.'/0',""));
+ return($this->get_permissions($dn,$category.'/0',""));
}
}
}
/* Push cache answer? */
}
/* Push cache answer? */
- $ACL_CACHE = &session::get('ACL_CACHE');
+ $ACL_CACHE = &session::global_get('ACL_CACHE');
if (isset($ACL_CACHE["$dn+$object+$attribute"])){
$ret = $ACL_CACHE["$dn+$object+$attribute"];
if($skip_write){
if (isset($ACL_CACHE["$dn+$object+$attribute"])){
$ret = $ACL_CACHE["$dn+$object+$attribute"];
if($skip_write){
return($ret);
}
return($ret);
}
+ /* Check for correct category and class values... */
+ if(strpos($object,'/') !== FALSE){
+ list($aclCategory, $aclClass) = preg_split("!/!", $object);
+ }else{
+ $aclCategory = $object;
+ }
+
+ if($this->config->boolValueIsTrue("core","developmentMode")){
+
+ 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("");
+ }
+ if(isset($aclClass) && $aclClass != '0' && class_available($aclClass)){
+ $plInfo = call_user_func(array($aclClass, 'plInfo'));
+ if(!empty($attribute) && !isset($plInfo['plProvidedAcls'][$attribute])){
+ trigger_error("Invalid ACL attribute '".$attribute."'! ({$object})");
+ return("");
+ }
+ }
+ }
+
/* Detect the set of ACLs we have to check for this object
*/
$adn = $dn;
/* Detect the set of ACLs we have to check for this object
*/
$adn = $dn;
$acl= array("r" => "", "w" => "", "c" => "", "d" => "", "m" => "", "a" => "");
/* Build dn array */
$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 */
$path= array_reverse($path);
/* Walk along the path to evaluate the acl */
/* Inspect this ACL, place the result into ACL */
foreach ($ACL[$cpath] as $subacl){
/* Inspect this ACL, place the result into ACL */
foreach ($ACL[$cpath] as $subacl){
- /* Reset? Just clean the ACL and turn over to the next one... */
- if ($subacl['type'] == 'reset'){
- $acl= $this->cleanACL($acl, TRUE);
- continue;
- }
-
if($subacl['type'] == "role") {
echo "role skipped";
continue;
if($subacl['type'] == "role") {
echo "role skipped";
continue;
}
}
}
}
+ /* Reset? Just clean the ACL and turn over to the next one... */
+ if ($subacl['type'] == 'reset'){
+ $acl= $this->cleanACL($acl, TRUE);
+ continue;
+ }
+
/* Self ACLs?
*/
/* Self ACLs?
*/
- if($dn != $this->dn && isset($subacl['acl'][$object][0]) && strpos($subacl['acl'][$object][0],"s")){
+ if($dn != $this->dn && isset($subacl['acl'][$object][0]) && (strpos($subacl['acl'][$object][0],"s") !== FALSE)){
continue;
}
continue;
}
}
/* Global ACL? */
}
/* Global ACL? */
+ if (isset($subacl['acl']['all/all'][0])){
+ $acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl']['all/all'][0]);
+ continue;
+ }
+
+ /* Global ACL? - Old style global ACL - Was removed since class_core.inc was created */
if (isset($subacl['acl']['all'][0])){
$acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl']['all'][0]);
continue;
if (isset($subacl['acl']['all'][0])){
$acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl']['all'][0]);
continue;
if($attribute == ""){
foreach($this->ocMapping[$ocs] as $oc){
if (isset($subacl['acl'][$ocs.'/'.$oc])){
if($attribute == ""){
foreach($this->ocMapping[$ocs] as $oc){
if (isset($subacl['acl'][$ocs.'/'.$oc])){
+
+ // Skip ACLs wich are defined for ourselfs only - if not checking against ($ui->dn)
+ if(isset($subacl['acl'][$ocs.'/'.$oc][0]) &&
+ $dn != $this->dn &&
+ strpos($subacl['acl'][$ocs.'/'.$oc][0],"s") !== FALSE) continue;
+
foreach($subacl['acl'][$ocs.'/'.$oc] as $attr => $dummy){
$acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$ocs.'/'.$oc][$attr]);
}
foreach($subacl['acl'][$ocs.'/'.$oc] as $attr => $dummy){
$acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$ocs.'/'.$oc][$attr]);
}
}
}else{
if(isset($subacl['acl'][$ocs.'/'.$oc][0])){
}
}else{
if(isset($subacl['acl'][$ocs.'/'.$oc][0])){
+ if($dn != $this->dn && strpos($subacl['acl'][$ocs.'/'.$oc][0],"s") !== FALSE) continue;
$acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$ocs.'/'.$oc][0]);
}
}
$acl= $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$ocs.'/'.$oc][0]);
}
}
}
/* Use cached results if possilbe */
}
/* Use cached results if possilbe */
- $ACL_CACHE = &session::get('ACL_CACHE');
+ $ACL_CACHE = &session::global_get('ACL_CACHE');
if(!is_array($module)){
$module = array($module);
if(!is_array($module)){
$module = array($module);
foreach($this->ACL as $dn => $infos){
foreach($infos as $info){
$found = FALSE;
foreach($this->ACL as $dn => $infos){
foreach($infos as $info){
$found = FALSE;
- foreach($info['acl'] as $cat => $data){
-
- /* Skip self acls? */
- if($skip_self_acls && isset($data['0']) && strpos($data['0'], "s")) continue;
- if(preg_match("/^".preg_quote($mod, '/')."/",$cat)){
- $found =TRUE;
- break;
- }
- }
+ if(isset($info['acl'])){
+ foreach($info['acl'] as $cat => $data){
+
+ /* Skip self acls? */
+ if($skip_self_acls && isset($data['0']) && (strpos($data['0'], "s") !== FALSE)) continue;
+ if(preg_match("/^".preg_quote($mod, '/')."/",$cat)){
+ $found =TRUE;
+ break;
+ }
+ }
+ }
if($found && !isset($this->config->idepartments[$dn])){
while(!isset($this->config->idepartments[$dn]) && strpos($dn, ",")){
if($found && !isset($this->config->idepartments[$dn])){
while(!isset($this->config->idepartments[$dn]) && strpos($dn, ",")){
foreach(str_split($newACL) as $char){
foreach(str_split($newACL) as $char){
+ /* Skip "self" ACLs without combination of rwcdm, they have no effect.
+ -self flag without read/write/create/...
+ */
+ if(empty($char)) continue;
+
/* Skip permanent and subtree entries */
if (preg_match('/[sp]/', $acl[$char])){
continue;
/* Skip permanent and subtree entries */
if (preg_match('/[sp]/', $acl[$char])){
continue;
}
}
}else{
}
}
}else{
- trigger_error("Invalid type of category ".$category);
+ if($this->config->boolValueIsTrue("core","developmentMode")){
+ trigger_error("Invalid type of category ".$category);
+ }
$acl = "";
}
$this->result_cache['has_complete_category_acls'][$dn][$category] = $acl;
$acl = "";
}
$this->result_cache['has_complete_category_acls'][$dn][$category] = $acl;
*/
function ignore_acl_for_current_user()
{
*/
function ignore_acl_for_current_user()
{
+ if($this->ignoreACL === NULL){
+ $this->ignoreACL = ($this->config->get_cfg_value("core","ignoreAcl") == $this->dn);
+ }
return($this->ignoreACL);
}
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:
?>
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>