mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-25 22:26:26 +09:00
B #2374: Restricted attributes checked for attach-disk
(cherry picked from commit a46b8fd1a4)
This commit is contained in:
1 parent
b8ca4b3bfd
commit
13e7719151
2 files changed
+98
-44
No files matched your search
@@ -1611,51 +1611,26 @@ void VirtualMachineMonitoring::request_execute(
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachineAttach::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
void VirtualMachineAttach::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
DispatchManager * dm = nd.get_dm();
|
||||
VirtualMachine * vm;
|
||||
VirtualMachineTemplate tmpl;
|
||||
|
||||
VirtualMachineTemplate tmpl;
|
||||
PoolObjectAuth vm_perms;
|
||||
|
||||
VirtualMachine * vm;
|
||||
|
||||
int rc;
|
||||
bool volatile_disk;
|
||||
int rc;
|
||||
|
||||
int id = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
string str_tmpl = xmlrpc_c::value_string(paramList.getString(2));
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Parse Disk template
|
||||
// Check if the VM is a Virtual Router
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
rc = tmpl.parse_str_or_xml(str_tmpl, att.resp_msg);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
failure_response(INTERNAL, att);
|
||||
return;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Authorize the operation & check quotas
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
if ( vm_authorization(id, 0, &tmpl, att, 0, 0, 0, auth_op) == false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((vm = get_vm(id, att)) == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vm->get_permissions(vm_perms);
|
||||
|
||||
if ( !vm->hasHistory() )
|
||||
{
|
||||
att.resp_msg = "VM is not running in any host";
|
||||
@@ -1665,13 +1640,11 @@ void VirtualMachineAttach::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
volatile_disk = set_volatile_disk_info(vm, vm->get_ds_id(), tmpl);
|
||||
|
||||
if (vm->is_vrouter() &&
|
||||
!VirtualRouter::is_action_supported(History::DISK_ATTACH_ACTION))
|
||||
!VirtualRouter::is_action_supported(History::NIC_ATTACH_ACTION))
|
||||
{
|
||||
att.resp_msg = "Action is not supported for virtual router VMs";
|
||||
failure_response(ACTION, att);
|
||||
failure_response(Request::ACTION, att);
|
||||
|
||||
vm->unlock();
|
||||
return;
|
||||
@@ -1679,6 +1652,79 @@ void VirtualMachineAttach::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
vm->unlock();
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Parse NIC template
|
||||
// -------------------------------------------------------------------------
|
||||
rc = tmpl.parse_str_or_xml(str_tmpl, att.resp_msg);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
failure_response(INTERNAL, att);
|
||||
return;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Perform the attach
|
||||
// -------------------------------------------------------------------------
|
||||
ErrorCode ec = request_execute(id, tmpl, att);
|
||||
|
||||
if ( ec == SUCCESS )
|
||||
{
|
||||
success_response(id, att);
|
||||
}
|
||||
else
|
||||
{
|
||||
failure_response(ec, att);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
Request::ErrorCode VirtualMachineAttach::request_execute(int id,
|
||||
VirtualMachineTemplate& tmpl, RequestAttributes& att)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
DispatchManager * dm = nd.get_dm();
|
||||
|
||||
PoolObjectAuth vm_perms;
|
||||
|
||||
VirtualMachine * vm;
|
||||
|
||||
int rc;
|
||||
bool volatile_disk;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Authorize the operation & check quotas
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
if ( vm_authorization(id, 0, &tmpl, att, 0, 0, 0, auth_op) == false )
|
||||
{
|
||||
return AUTHORIZATION;
|
||||
}
|
||||
|
||||
if (!att.is_admin())
|
||||
{
|
||||
string aname;
|
||||
|
||||
if (tmpl.check_restricted(aname))
|
||||
{
|
||||
att.resp_msg = "DISK includes a restricted attribute " + aname;
|
||||
return AUTHORIZATION;
|
||||
}
|
||||
}
|
||||
|
||||
if ((vm = get_vm(id, att)) == 0)
|
||||
{
|
||||
return NO_EXISTS;
|
||||
}
|
||||
|
||||
vm->get_permissions(vm_perms);
|
||||
|
||||
volatile_disk = set_volatile_disk_info(vm, vm->get_ds_id(), tmpl);
|
||||
|
||||
vm->unlock();
|
||||
|
||||
RequestAttributes att_quota(vm_perms.uid, vm_perms.gid, att);
|
||||
|
||||
VirtualMachineTemplate deltas(tmpl);
|
||||
@@ -1688,7 +1734,7 @@ void VirtualMachineAttach::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
if (quota_resize_authorization(id, &deltas, att_quota) == false)
|
||||
{
|
||||
return;
|
||||
return AUTHORIZATION;
|
||||
}
|
||||
|
||||
if (volatile_disk == false)
|
||||
@@ -1696,7 +1742,7 @@ void VirtualMachineAttach::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
if ( quota_authorization(&tmpl, Quotas::IMAGE, att_quota) == false )
|
||||
{
|
||||
quota_rollback(&deltas, Quotas::VM, att_quota);
|
||||
return;
|
||||
return AUTHORIZATION;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1711,14 +1757,10 @@ void VirtualMachineAttach::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
quota_rollback(&tmpl, Quotas::IMAGE, att_quota);
|
||||
}
|
||||
|
||||
failure_response(ACTION, att);
|
||||
}
|
||||
else
|
||||
{
|
||||
success_response(id, att);
|
||||
return ACTION;
|
||||
}
|
||||
|
||||
return;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
Reference in new issue
Block a user