/usr/share/ltsp-cluster-control/Admin/util/Permissions.php is in ltsp-cluster-control 2.0.3-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | <?php
/*
# Copyright 2006, CRIM., Martin Rioux
#
# This file is part of the MILLE-XTERM distribution.
# See the MILLE-XTERM (english) and/or the MILLE (french) project web site
#
# http://www.revolutionlinux.com/mille-xterm/
# http://www.mille.ca/
#
# The MILLE-XTERM framework is covered by the GNU General Public License. See
# the COPYING file in the top-level MILLE-XTERM directory. Software packages
# that are included in the MILLE-XTERM distribution have their own licenses.
#
# -------------------------------------------------------------------------
*/
/* This is the login object when htacces is use instead of ldap or any authorization module
*
* Author: Martin Rioux
* Last modification:
* 7 Mar 2006 Martin Rioux <martin.rioux@crim.ca>
* - Creation
*/
require_once 'dbFunctions.php';
require_once 'Permission.php';
class Permissions {
var $listPermissions; // array of permissions
var $attributesList; //all attributes with one permission
function Permissions($nodeId) {
$this->setPermissions($this->getPermissionsFromDB($nodeId),$nodeId);
}
/** This function clean up permissionList in order to respect the following rules :
*
* 1- If they are permissions set at different level of hierarchy,
* the closest permission will be apply
* 2- If a user obtain two permissions on the same node from two different groups,
* the most privilegious permission will be selected.
*
*/
function setPermissions($permissions,$nodeId){
$this->attributeList=array();
$previousId;
$previousAttribute;
$ignoreNextSameId = false;
//remember all attributes
$newIndex=0;
for ($index = 0; $index < sizeof($permissions); $index++) {
//default-> it's a new attribute...
if(empty($this->attributesList) || !in_array($permissions[$index]->getAttribute(),$this->attributesList)){
$previousId = $permissions[$index]->getNodeId();
$previousAttribute = $permissions[$index]->getAttribute();
$permissions[$index]->setNodeId($nodeId);
$this->listPermissions[$newIndex] = $permissions[$index];
$this->attributesList[$newIndex] = $permissions[$index]->getAttribute();
$newIndex++;
$ignoreNextSameId = false;
continue;
}
//If the permission attribute is already define for another node continue... (rule #1)
if(in_array($permissions[$index]->getAttribute(),$this->attributesList) && $previousId != $permissions[$index]->getNodeId()){
$previousId = $permissions[$index]->getNodeId();
$previousAttribute = $permissions[$index]->getAttribute();
$ignoreNextSameId = true;
continue;
}
//If it's the same attribute and the same node the most privilegious permission will be selected. rule #2
if(!$ignoreNextSameId && in_array($permissions[$index]->getAttribute(),$this->attributesList) && $previousId == $permissions[$index]->getNodeId()){
$previousId = $permissions[$index]->getNodeId();
$previousAttribute = $permissions[$index]->getAttribute();
//update previous permission with this one
$this->listPermissions[$newIndex-1] = $this->mergePermissions($this->listPermissions[$newIndex-1],$permissions[$index]);
$ignoreNextSameId = false;
continue;
}
}
}
/**
* This function get all permission for a specific node
*/
function getPermissionsFromDB($nodeId){
$sessionData = $_SESSION['groups'];
//Superadmin role bypass all permissions
if($_SESSION['userRole'] == "Superadmin"){
$listPerms[] = new Permission(0,'*',1,1,1,1,1);
$listPerms[] = new Permission(0,"",1,1,1,1,1);
return $listPerms;
}
//Generate IN condition
$groups = $sessionData->getGroups();
$inCondition="";
for ($index = 0; $index < sizeof($groups); $index++) {
$inCondition = $inCondition."'".$groups[$index]."'";
if($index <(sizeof($groups))-1){
$inCondition = $inCondition.",";
}
}
$request = "SELECT id, attributes, scope, canadd, candelete, canread, canwrite ".
"FROM nodes,permissions ".
"WHERE leftval<=(select leftval from nodes where id=".$nodeId.") ".
"AND rightval >=(select rightval from nodes where id=".$nodeId.") ".
"AND id = nodes_id ".
"AND (scope = 1 OR nodes_id = ".$nodeId.") ".
"AND (".
" (granteekey IN (".$inCondition.") AND granteetype =2)".
" OR".
" (granteekey ='".$sessionData->getUsername()."' AND granteetype =1)".
" ) ".
"ORDER BY rightval, attributes";
$perms = select($request);
if (!is_array($perms) && !is_null($perms)) {
$this->lastError = getMessage('db_error') . $perms;
return NULL;
}
if (is_null($perms)) {
$this->lastError = "";
return NULL;
}
for ($index = 0; $index < sizeof($perms); $index++) {
$permission = new Permission($perms[$index]["id"],$perms[$index]["attributes"],$perms[$index]["scope"],$perms[$index]["canadd"],$perms[$index]["candelete"],$perms[$index]["canread"],$perms[$index]["canwrite"]);
$listPerms[$index] = $permission;
}
return $listPerms;
}
/**
* This function applied rule 2 - If a user obtain two permissions on the same node from
* two different groups, the most privilegious permission will be selected.
*/
function mergePermissions($perm1, $perm2){
if(!$perm1->getScope())$perm1->setScope($perm2->getScope());
if(!$perm1->getCanadd())$perm1->setCanadd($perm2->getCanadd());
if(!$perm1->getCandelete())$perm1->setCandelete($perm2->getCandelete());
if(!$perm1->getCanread())$perm1->setCanread($perm2->getCanread());
if(!$perm1->getCanwrite())$perm1->setCanwrite($perm2->getCanwrite());
return $perm1;
}
/**
* Get index permission for nodes...
*/
function getNodeIndex(){
$returnValue = -1;
for ($index = 0; $index < sizeof($this->listPermissions); $index++) {
//if attribute is empty it is the node permission
if($this->listPermissions[$index]->getAttribute() == ""){
$returnValue=$index;
break;
}
}
return $returnValue;
}
/**
* This function return the permission to use (index of listPermissions) for the attribute
* 1. if attribute name is in $attributesList
* 2. if attribute name begin with an attriubte in $attributesList contain XXXX* (ex. SCREEN_* match SCREEN_01)
* 3. if $attributeClass.$name isi defined.
* 4. if permission on all attribute is defined... (ex. *)
*
*/
function getIndexPermission($name, $attributeClass){
// 1.if attribute name is in $attributesList
$returnValue = -1; //index value return if no permission is -1
for ($index = 0; $index < sizeof($this->listPermissions); $index++) {
if($this->listPermissions[$index]->getAttribute() == $name){
$returnValue = $index;
break;
}
}
// 2. if attribute name begin with an attriubte in $attributesList contain XXXX*
if($returnValue == -1){
for ($index = 0; $index < sizeof($this->listPermissions); $index++) {
//MUST CONTAINT * at last position
$stringToCompare = $this->listPermissions[$index]->getAttribute();
if(strlen($stringToCompare)>1 && $stringToCompare{strlen($stringToCompare)-1}=='*' ){
$stringToCompare = substr($stringToCompare,0,strlen($stringToCompare)-1);
if(strpos($name,$stringToCompare)!==false){
$returnValue = $index;
break;
}
}
}
}
//3. if $attributeClass.$name is defined.
if($returnValue == -1){
for ($index = 0; $index < sizeof($this->listPermissions); $index++) {
if($this->listPermissions[$index]->getAttribute() == $attributeClass.'.*'){
$returnValue = $index;
break;
}
}
}
//4. if permission on all attribute is defined... (ex. *)
if($returnValue == -1){
for ($index = 0; $index < sizeof($this->listPermissions); $index++) {
if($this->listPermissions[$index]->getAttribute() == '*'){
$returnValue = $index;
break;
}
}
}
return $returnValue;
}
/**
* This function validate attribute delete rights
*/
function canDeleteAttribute($name, $attributeClass){
$index = $this->getIndexPermission($name, $attributeClass);
$returnValue = 0;//Default no permission
if($index != -1){
$returnValue = $this->listPermissions[$index]->getCandelete();
}
return $returnValue;
}
/**
* This function validate attribute add rights
*
*/
function canAddAttribute($name, $attributeClass){
$index = $this->getIndexPermission($name, $attributeClass);
$returnValue = 0;//Default no permission
if($index != -1){
$returnValue=$this->listPermissions[$index]->getCanadd();
}
return $returnValue;
}
/**
* This function validate attribute read rights
*
*/
function canReadAttribute($name, $attributeClass){
$index = $this->getIndexPermission($name, $attributeClass);
$returnValue = 0;//Default no permission
if($index != -1){
$returnValue=$this->listPermissions[$index]->getCanread();
}
return $returnValue;
}
/**
* This function validate attribute modify rights
*
*/
function canWriteAttribute($name, $attributeClass){
$index = $this->getIndexPermission($name, $attributeClass);
$returnValue = 0;//Default no permission
if($index != -1){
$returnValue=$this->listPermissions[$index]->getCanwrite();
}
return $returnValue;
}
/**
* This function validate attribute modify rights
*
*/
function canReadNode(){
$index = $this->getNodeIndex();
$returnValue = 0;//Default no permission
if($index != -1){
$returnValue=$this->listPermissions[$index]->getCanread();
}
return $returnValue;
}
/**
* This function validate attribute modify rights
*
*/
function canWriteNode(){
$index = $this->getNodeIndex();
$returnValue = 0;//Default no permission
if($index != -1){
$returnValue=$this->listPermissions[$index]->getCanwrite();
}
return $returnValue;
}
/**
* This function validate attribute modify rights
*
*/
function canAddNode(){
$index = $this->getNodeIndex();
$returnValue = 0;//Default no permission
if($index != -1){
$returnValue=$this->listPermissions[$index]->getCanadd();
}
return $returnValue;
}
}
?>
|