Skip to content

Commit

Permalink
use in_array to filter groups instead of preg_grep for acl
Browse files Browse the repository at this point in the history
the usage of preg_grep can result in "regular expression is too large"
warnings, which leads to errors in auth_aclcheck.
  • Loading branch information
Dominik Eckelmann committed Dec 20, 2011
1 parent df95970 commit 48d7b7a
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions inc/auth.php
Expand Up @@ -523,18 +523,19 @@ function auth_aclcheck($id,$user,$groups){
$groups[] = '@ALL';
//add User
if($user) $groups[] = $user;
//build regexp
$regexp = join('|',$groups);
}else{
$regexp = '@ALL';
$groups[] = '@ALL';
}

//check exact match first
$matches = preg_grep('/^'.preg_quote($id,'/').'\s+('.$regexp.')\s+/'.$ci,$AUTH_ACL);
$matches = preg_grep('/^'.preg_quote($id,'/').'\s+(\S+)\s+/'.$ci,$AUTH_ACL);
if(count($matches)){
foreach($matches as $match){
$match = preg_replace('/#.*$/','',$match); //ignore comments
$acl = preg_split('/\s+/',$match);
if (!in_array($acl[1], $groups)) {
continue;
}
if($acl[2] > AUTH_DELETE) $acl[2] = AUTH_DELETE; //no admins in the ACL!
if($acl[2] > $perm){
$perm = $acl[2];
Expand All @@ -554,20 +555,24 @@ function auth_aclcheck($id,$user,$groups){
}

do{
$matches = preg_grep('/^'.preg_quote($path,'/').'\s+('.$regexp.')\s+/'.$ci,$AUTH_ACL);
$matches = preg_grep('/^'.preg_quote($path,'/').'\s+(\S+)\s+/'.$ci,$AUTH_ACL);
if(count($matches)){
foreach($matches as $match){
$match = preg_replace('/#.*$/','',$match); //ignore comments
$acl = preg_split('/\s+/',$match);
if (!in_array($acl[1], $groups)) {
continue;
}
if($acl[2] > AUTH_DELETE) $acl[2] = AUTH_DELETE; //no admins in the ACL!
if($acl[2] > $perm){
$perm = $acl[2];
}
}
//we had a match - return it
return $perm;
if ($perm != -1) {
return $perm;
}
}

//get next higher namespace
$ns = getNS($ns);

Expand All @@ -582,9 +587,6 @@ function auth_aclcheck($id,$user,$groups){
return AUTH_NONE;
}
}while(1); //this should never loop endless

//still here? return no permissions
return AUTH_NONE;
}

/**
Expand Down

0 comments on commit 48d7b7a

Please sign in to comment.