1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

Bug #364; Users can see now its own images & networks as well as public ones

This commit is contained in:
Ruben S. Montero 2010-10-08 13:23:20 +02:00
parent a5cacd2e15
commit 9d959c2e55
2 changed files with 44 additions and 59 deletions

View File

@ -23,16 +23,15 @@
void RequestManager::ImagePoolInfo::execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retval)
{
{
string session;
ostringstream oss;
ostringstream where_string;
int rc;
int uid;
int filter_flag;
const string method_name = "ImagePoolInfo";
/* -- RPC specific vars -- */
@ -46,19 +45,17 @@ void RequestManager::ImagePoolInfo::execute(
filter_flag = xmlrpc_c::value_int(paramList.getInt(1));
// Check if it is a valid user
uid = ImagePoolInfo::upool->authenticate(session);
rc = ImagePoolInfo::upool->authenticate(session);
if ( uid == -1 )
if ( rc == -1 )
{
goto error_authenticate;
}
where_string.str("");
/** Filter flag meaning table
* -2 :: All Images (just for oneadmin)
* -2 :: All Images
* -1 :: User's Images AND public images belonging to any user
* >= 0 :: UID User's Images (just for oneadmin)
* >= 0 :: UID User's Images
**/
if ( filter_flag < -2 )
{
@ -69,10 +66,9 @@ void RequestManager::ImagePoolInfo::execute(
{
case -2:
// TODO define authentication bug #278
// where remains empty.
break;
case -1:
where_string << "UID=" << uid << " OR public = 'YES'";
where_string << "UID=" << rc << " OR PUBLIC=1";
break;
default:
where_string << "UID=" << filter_flag;
@ -87,7 +83,7 @@ void RequestManager::ImagePoolInfo::execute(
}
// All nice, return pool info to the client
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
arrayresult = new xmlrpc_c::value_array(arrayData);
@ -101,7 +97,7 @@ void RequestManager::ImagePoolInfo::execute(
return;
error_authenticate:
oss.str(authenticate_error(method_name));
oss.str(authenticate_error(method_name));
goto error_common;
error_filter_flag:
@ -115,13 +111,13 @@ error_dump:
error_common:
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
NebulaLog::log("ReM",Log::ERROR,oss);
NebulaLog::log("ReM",Log::ERROR,oss);
xmlrpc_c::value_array arrayresult_error(arrayData);
*retval = arrayresult_error;
return;
}

View File

@ -23,7 +23,7 @@
void RequestManager::VirtualNetworkPoolInfo::execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retval)
{
{
string session;
string username;
string password;
@ -34,8 +34,6 @@ void RequestManager::VirtualNetworkPoolInfo::execute(
int rc;
int filter_flag;
User * user;
const string method_name = "VirtualNetworkPoolInfo";
/* -- RPC specific vars -- */
@ -56,46 +54,37 @@ void RequestManager::VirtualNetworkPoolInfo::execute(
goto error_authenticate;
}
where_string.str("");
/** Filter flag meaning table
* <=-2 :: ALL VMs
* -1 :: User's VMs
* >=0 :: UID User's VMs
* <=-2 :: ALL Networks
* -1 :: User's Networks plus Public ones
* >=0 :: UID User's Networks
**/
// TODO define authorization (bug #278)
if (filter_flag == -1)
if ( filter_flag < -2 )
{
User::split_secret(session,username,password);
// Now let's get the user
user = VirtualNetworkPoolInfo::upool->get(username,true);
if ( user == 0 )
{
goto error_get_user;
}
where_string << "UID=" << user->get_uid();
user->unlock();
goto error_filter_flag;
}
switch(filter_flag)
{
case -2:
// TODO define authentication bug #278
break;
case -1:
where_string << "UID=" << rc << " OR PUBLIC=1";
break;
default:
where_string << "UID=" << filter_flag;
}
else if (filter_flag>=0)
{
where_string << "UID=" << filter_flag;
}
// Perform the allocation in the vmpool
rc = VirtualNetworkPoolInfo::vnpool->dump(oss,where_string.str());
if ( rc != 0 )
{
{
goto error_dump;
}
//All nice, return the host info to the client
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
//All nice, return the host info to the client
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
arrayresult = new xmlrpc_c::value_array(arrayData);
@ -112,25 +101,25 @@ error_authenticate:
oss.str(authenticate_error(method_name));
goto error_common;
error_get_user:
oss.str(get_error(method_name, "USER", -1));
error_filter_flag:
oss << "Incorrect filter_flag, must be >= -2.";
goto error_common;
error_dump:
oss.str(get_error(method_name, "HOST", -1));
oss.str(get_error(method_name, "NETWORK", -1));
goto error_common;
error_common:
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
NebulaLog::log("ReM",Log::ERROR,oss);
NebulaLog::log("ReM",Log::ERROR,oss);
xmlrpc_c::value_array arrayresult_error(arrayData);
*retval = arrayresult_error;
return;
}