mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
bug #2565: Join get_info and get_info_without_error
This commit is contained in:
parent
612fd8c2ab
commit
f949691cef
@ -117,8 +117,8 @@ protected:
|
||||
|
||||
/* -------------------- Constructors ---------------------------------- */
|
||||
|
||||
Request(const string& mn,
|
||||
const string& signature,
|
||||
Request(const string& mn,
|
||||
const string& signature,
|
||||
const string& help): pool(0),method_name(mn)
|
||||
{
|
||||
_signature = signature;
|
||||
@ -132,8 +132,8 @@ protected:
|
||||
|
||||
/**
|
||||
* Performs a basic authorization for this request using the uid/gid
|
||||
* from the request. The function gets the object from the pool to get
|
||||
* the public attribute and its owner. The authorization is based on
|
||||
* from the request. The function gets the object from the pool to get
|
||||
* the public attribute and its owner. The authorization is based on
|
||||
* object and type of operation for the request.
|
||||
* @param oid of the object, can be -1 for objects to be created, or
|
||||
* pools.
|
||||
@ -305,6 +305,7 @@ protected:
|
||||
*
|
||||
* @param perms returns the object's permissions
|
||||
* @param name returns the object's name
|
||||
* @param throw_error send error response to client if object not found
|
||||
*
|
||||
* @return 0 on success, -1 otherwise
|
||||
*/
|
||||
@ -313,7 +314,8 @@ protected:
|
||||
PoolObjectSQL::ObjectType type,
|
||||
RequestAttributes& att,
|
||||
PoolObjectAuth& perms,
|
||||
string& name);
|
||||
string& name,
|
||||
bool throw_error);
|
||||
|
||||
/**
|
||||
* Logs the method invocation, including the arguments
|
||||
|
@ -104,14 +104,6 @@ protected:
|
||||
|
||||
virtual int edit_resource_provider(
|
||||
Group* group, int zone_id, int cluster_id, string& error_msg) = 0;
|
||||
|
||||
int get_info_without_error(
|
||||
PoolSQL * pool,
|
||||
int id,
|
||||
PoolObjectSQL::ObjectType type,
|
||||
RequestAttributes& att,
|
||||
PoolObjectAuth& perms,
|
||||
string& name);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -678,13 +678,18 @@ int Request::get_info(
|
||||
PoolObjectSQL::ObjectType type,
|
||||
RequestAttributes& att,
|
||||
PoolObjectAuth& perms,
|
||||
string& name)
|
||||
string& name,
|
||||
bool throw_error)
|
||||
{
|
||||
PoolObjectSQL * ob;
|
||||
|
||||
if ((ob = pool->get(id,true)) == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS, get_error(object_name(type), id), att);
|
||||
if (throw_error)
|
||||
{
|
||||
failure_response(NO_EXISTS, get_error(object_name(type), id), att);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -178,7 +178,7 @@ void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params,
|
||||
if ( cluster_id != ClusterPool::NONE_CLUSTER_ID )
|
||||
{
|
||||
rc = get_info(clpool, cluster_id, PoolObjectSQL::CLUSTER, att,
|
||||
cluster_perms, cluster_name);
|
||||
cluster_perms, cluster_name, true);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
|
@ -41,11 +41,11 @@ PoolObjectSQL * RequestManagerChown::get_and_quota(
|
||||
|
||||
object = pool->get(oid,true);
|
||||
|
||||
if ( object == 0 )
|
||||
if ( object == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS,
|
||||
get_error(object_name(auth_object), oid),
|
||||
att);
|
||||
att);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ PoolObjectSQL * RequestManagerChown::get_and_quota(
|
||||
tmpl = (static_cast<VirtualMachine*>(object))->clone_template();
|
||||
qtype = Quotas::VIRTUALMACHINE;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
Image * img = static_cast<Image *>(object);
|
||||
tmpl = new Template;
|
||||
@ -71,7 +71,7 @@ PoolObjectSQL * RequestManagerChown::get_and_quota(
|
||||
}
|
||||
else
|
||||
{
|
||||
old_uid = object->get_uid();
|
||||
old_uid = object->get_uid();
|
||||
}
|
||||
|
||||
if ( new_gid == -1 )
|
||||
@ -84,7 +84,7 @@ PoolObjectSQL * RequestManagerChown::get_and_quota(
|
||||
}
|
||||
|
||||
object->unlock();
|
||||
|
||||
|
||||
RequestAttributes att_new(new_uid, new_gid, att);
|
||||
RequestAttributes att_old(old_uid, old_gid, att);
|
||||
|
||||
@ -104,16 +104,16 @@ PoolObjectSQL * RequestManagerChown::get_and_quota(
|
||||
|
||||
if ( object == 0 )
|
||||
{
|
||||
quota_rollback(tmpl, qtype, att_new);
|
||||
quota_rollback(tmpl, qtype, att_new);
|
||||
|
||||
quota_authorization(tmpl, qtype, att_old, error_str);
|
||||
|
||||
failure_response(NO_EXISTS,
|
||||
get_error(object_name(auth_object), oid),
|
||||
att);
|
||||
att);
|
||||
}
|
||||
|
||||
delete tmpl;
|
||||
delete tmpl;
|
||||
|
||||
return object;
|
||||
}
|
||||
@ -173,7 +173,7 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
int ngid = xmlrpc_c::value_int(paramList.getInt(3));
|
||||
|
||||
int rc;
|
||||
|
||||
|
||||
string oname;
|
||||
string nuname;
|
||||
string ngname;
|
||||
@ -191,18 +191,18 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
if ( noid > -1 )
|
||||
{
|
||||
rc = get_info(upool, noid, PoolObjectSQL::USER, att, nuperms, nuname);
|
||||
rc = get_info(upool,noid,PoolObjectSQL::USER,att,nuperms,nuname,true);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( ngid > -1 )
|
||||
{
|
||||
rc = get_info(gpool, ngid, PoolObjectSQL::GROUP, att, ngperms, ngname);
|
||||
|
||||
rc = get_info(gpool,ngid,PoolObjectSQL::GROUP,att,ngperms,ngname,true);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
return;
|
||||
@ -215,7 +215,7 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
{
|
||||
AuthRequest ar(att.uid, att.group_ids);
|
||||
|
||||
rc = get_info(pool, oid, auth_object, att, operms, oname);
|
||||
rc = get_info(pool, oid, auth_object, att, operms, oname, true);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
@ -256,7 +256,7 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
// --------------- Update the object and check quotas ----------------------
|
||||
|
||||
if ( auth_object == PoolObjectSQL::VM ||
|
||||
if ( auth_object == PoolObjectSQL::VM ||
|
||||
auth_object == PoolObjectSQL::IMAGE )
|
||||
{
|
||||
object = get_and_quota(oid, noid, ngid, att);
|
||||
@ -278,7 +278,7 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
if ( noid != -1 )
|
||||
if ( noid != -1 )
|
||||
{
|
||||
obj_name = object->get_name();
|
||||
old_uid = object->get_uid();
|
||||
@ -295,7 +295,7 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
object->unlock();
|
||||
|
||||
if ( noid != -1 )
|
||||
if ( noid != -1 )
|
||||
{
|
||||
pool->update_cache_index(obj_name, old_uid, obj_name, noid);
|
||||
}
|
||||
@ -334,14 +334,14 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
rc = get_info(upool, oid, PoolObjectSQL::USER, att, uperms, uname);
|
||||
rc = get_info(upool, oid, PoolObjectSQL::USER, att, uperms, uname, true);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
rc = get_info(gpool, ngid, PoolObjectSQL::GROUP, att, ngperms, ngname);
|
||||
rc = get_info(gpool, ngid, PoolObjectSQL::GROUP, att, ngperms, ngname,true);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
@ -384,13 +384,13 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
user = upool->get(oid,true);
|
||||
|
||||
if ( user == 0 )
|
||||
{
|
||||
if ( user == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS,
|
||||
get_error(object_name(PoolObjectSQL::USER),oid),
|
||||
att);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ((old_gid = user->get_gid()) == ngid)
|
||||
{
|
||||
@ -414,7 +414,7 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
}
|
||||
|
||||
upool->update(user);
|
||||
|
||||
|
||||
user->unlock();
|
||||
|
||||
// ------------- Updates new group with this new user ---------------------
|
||||
@ -423,7 +423,7 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
if( group == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS,
|
||||
failure_response(NO_EXISTS,
|
||||
get_error(object_name(PoolObjectSQL::GROUP),ngid),
|
||||
att);//TODO Rollback
|
||||
return;
|
||||
|
@ -49,7 +49,8 @@ void RequestManagerCluster::add_generic(
|
||||
|
||||
if ( cluster_id != ClusterPool::NONE_CLUSTER_ID )
|
||||
{
|
||||
rc = get_info(clpool, cluster_id, PoolObjectSQL::CLUSTER, att, c_perms, cluster_name);
|
||||
rc = get_info(clpool, cluster_id, PoolObjectSQL::CLUSTER, att, c_perms,
|
||||
cluster_name, true);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
@ -61,7 +62,7 @@ void RequestManagerCluster::add_generic(
|
||||
cluster_name = ClusterPool::NONE_CLUSTER_NAME;
|
||||
}
|
||||
|
||||
rc = get_info(pool, object_id, type, att, obj_perms, obj_name);
|
||||
rc = get_info(pool, object_id, type, att, obj_perms, obj_name, true);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
|
@ -33,8 +33,8 @@ void GroupSetQuota::
|
||||
|
||||
if ( id == GroupPool::ONEADMIN_ID )
|
||||
{
|
||||
failure_response(ACTION,
|
||||
request_error("Cannot set quotas for oneadmin group",""),
|
||||
failure_response(ACTION,
|
||||
request_error("Cannot set quotas for oneadmin group",""),
|
||||
att);
|
||||
return;
|
||||
}
|
||||
@ -82,33 +82,6 @@ void GroupSetQuota::
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int GroupEditProvider::get_info_without_error(
|
||||
PoolSQL * pool,
|
||||
int id,
|
||||
PoolObjectSQL::ObjectType type,
|
||||
RequestAttributes& att,
|
||||
PoolObjectAuth& perms,
|
||||
string& name)
|
||||
{
|
||||
PoolObjectSQL * ob;
|
||||
|
||||
if ((ob = pool->get(id,true)) == 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
ob->get_permissions(perms);
|
||||
|
||||
name = ob->get_name();
|
||||
|
||||
ob->unlock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void GroupEditProvider::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
@ -137,15 +110,15 @@ void GroupEditProvider::request_execute(
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
rc = get_info(pool, group_id, PoolObjectSQL::GROUP,
|
||||
att, group_perms, group_name);
|
||||
att, group_perms, group_name, true);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
rc = get_info_without_error(zonepool, zone_id, PoolObjectSQL::ZONE,
|
||||
att, zone_perms, zone_name);
|
||||
rc = get_info(zonepool, zone_id, PoolObjectSQL::ZONE, att, zone_perms,
|
||||
zone_name, false);
|
||||
|
||||
zone_exists = (rc == 0);
|
||||
|
||||
@ -161,8 +134,8 @@ void GroupEditProvider::request_execute(
|
||||
|
||||
if (cluster_id != ClusterPool::ALL_RESOURCES && zone_id == local_zone_id)
|
||||
{
|
||||
rc = get_info_without_error(clpool, cluster_id, PoolObjectSQL::CLUSTER,
|
||||
att, cluster_perms, cluster_name);
|
||||
rc = get_info(clpool, cluster_id, PoolObjectSQL::CLUSTER, att,
|
||||
cluster_perms, cluster_name, false);
|
||||
|
||||
cluster_exists = (rc == 0);
|
||||
|
||||
|
@ -44,7 +44,7 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
rc = get_info(pool, oid, auth_object, att, operms, old_name);
|
||||
rc = get_info(pool, oid, auth_object, att, operms, old_name, true);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
|
@ -225,14 +225,14 @@ void UserEditGroup::
|
||||
PoolObjectAuth uperms;
|
||||
PoolObjectAuth gperms;
|
||||
|
||||
rc = get_info(upool, user_id, PoolObjectSQL::USER, att, uperms, uname);
|
||||
rc = get_info(upool, user_id, PoolObjectSQL::USER, att, uperms, uname,true);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
rc = get_info(gpool, group_id, PoolObjectSQL::GROUP, att, gperms, gname);
|
||||
rc = get_info(gpool,group_id,PoolObjectSQL::GROUP,att,gperms,gname,true);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user