Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pve-manager
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
pve-manager
Commits
17dd123b
Commit
17dd123b
authored
Jan 25, 2012
by
Dietmar Maurer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved permission check code to RPCEnvironment.pm
parent
caac8e06
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
89 deletions
+2
-89
REST.pm
PVE/REST.pm
+2
-89
No files found.
PVE/REST.pm
View file @
17dd123b
...
...
@@ -271,93 +271,6 @@ sub proxy_handler {
return
OK
;
}
sub
exec_perm_check
{
my
(
$rpcenv
,
$check
,
$username
,
$param
,
$noerr
)
=
@_
;
# syslog("info", "CHECK " . join(', ', @$check));
my
$ind
=
0
;
my
$test
=
$check
->
[
$ind
++
];
die
"
no permission test specified
"
if
!
$test
;
if
(
$test
eq
'
and
')
{
while
(
my
$subcheck
=
$check
->
[
$ind
++
])
{
exec_perm_check
(
$rpcenv
,
$subcheck
,
$username
,
$param
);
}
return
1
;
}
elsif
(
$test
eq
'
or
')
{
while
(
my
$subcheck
=
$check
->
[
$ind
++
])
{
return
1
if
exec_perm_check
(
$rpcenv
,
$subcheck
,
$username
,
$param
,
1
);
}
return
0
if
$noerr
;
raise_perm_exc
();
}
elsif
(
$test
eq
'
perm
')
{
my
(
$t
,
$tmplpath
,
$privs
,
%
options
)
=
@$check
;
my
$any
=
$options
{
any
};
die
"
missing parameters
"
if
!
(
$tmplpath
&&
$privs
);
my
$path
=
PVE::Tools::
template_replace
(
$tmplpath
,
$param
);
if
(
$any
)
{
return
$rpcenv
->
check_any
(
$username
,
$path
,
$privs
,
$noerr
);
}
else
{
return
$rpcenv
->
check
(
$username
,
$path
,
$privs
,
$noerr
);
}
}
elsif
(
$test
eq
'
userid-group
')
{
my
$userid
=
$param
->
{
userid
};
my
(
$t
,
$privs
,
%
options
)
=
@$check
;
return
if
!
$options
{
groups_param
}
&&
!
$rpcenv
->
check_user_exist
(
$userid
,
$noerr
);
if
(
!
$rpcenv
->
check_any
(
$username
,
"
/access
",
$privs
,
1
))
{
my
$groups
=
$rpcenv
->
filter_groups
(
$username
,
$privs
,
1
);
if
(
$options
{
groups_param
})
{
my
@group_param
=
PVE::Tools::
split_list
(
$param
->
{
groups
});
raise_perm_exc
("
/access,
"
.
join
("
|
",
@$privs
))
if
!
scalar
(
@group_param
);
foreach
my
$pg
(
@group_param
)
{
raise_perm_exc
("
/access/groups/
$pg
,
"
.
join
("
|
",
@$privs
))
if
!
$groups
->
{
$pg
};
}
}
else
{
my
$allowed_users
=
$rpcenv
->
group_member_join
([
keys
%
$groups
]);
if
(
!
$allowed_users
->
{
$userid
})
{
return
0
if
$noerr
;
raise_perm_exc
();
}
}
}
return
1
;
}
elsif
(
$test
eq
'
userid-param
')
{
my
$userid
=
$param
->
{
userid
};
return
if
!
$rpcenv
->
check_user_exist
(
$userid
,
$noerr
);
my
(
$t
,
$subtest
)
=
@$check
;
die
"
missing parameters
"
if
!
$subtest
;
if
(
$subtest
eq
'
self
')
{
return
1
if
$username
eq
'
userid
';
return
0
if
$noerr
;
raise_perm_exc
();
}
else
{
die
"
unknown userid-param test
";
}
}
else
{
die
"
unknown permission test
";
}
};
my
$check_permissions
=
sub
{
my
(
$rpcenv
,
$perm
,
$username
,
$param
)
=
@_
;
return
1
if
!
$username
&&
$perm
->
{
user
}
eq
'
world
';
raise_perm_exc
("
user != null
")
if
!
$username
;
return
1
if
$username
eq
'
root@pam
';
raise_perm_exc
('
user != root@pam
')
if
!
$perm
;
return
1
if
$perm
->
{
user
}
&&
$perm
->
{
user
}
eq
'
all
';
return
exec_perm_check
(
$rpcenv
,
$perm
->
{
check
},
$username
,
$param
)
if
$perm
->
{
check
};
raise_perm_exc
();
};
sub
rest_handler
{
my
(
$rpcenv
,
$clientip
,
$method
,
$abs_uri
,
$rel_uri
,
$ticket
,
$token
)
=
@_
;
...
...
@@ -394,7 +307,7 @@ sub rest_handler {
path
=>
"
/storage/
$storeid
",
privs
=>
[
'
Datastore.AllocateSpace
'
],
};
&
$check_permissions
(
$rpcenv
,
$perm
,
$username
,
{});
$rpcenv
->
check_api2_permissions
(
$perm
,
$username
,
{});
$isUpload
=
1
;
}
...
...
@@ -448,7 +361,7 @@ sub rest_handler {
}
# check access permissions
eval
{
&
$check_permissions
(
$rpcenv
,
$info
->
{
permissions
},
$username
,
$uri_param
);
};
eval
{
$rpcenv
->
check_api2_permissions
(
$info
->
{
permissions
},
$username
,
$uri_param
);
};
if
(
my
$err
=
$@
)
{
return
{
status
=>
HTTP_FORBIDDEN
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment