mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
Bug #1308: Before a chown operation, check if the new user already has an object with the same name
This commit is contained in:
parent
de579b57a3
commit
4c6233bd09
@ -57,6 +57,20 @@ protected:
|
||||
int new_uid,
|
||||
int new_gid,
|
||||
RequestAttributes& att);
|
||||
|
||||
/**
|
||||
* Checks if the new owner cannot has other object with the same name (if
|
||||
* the pool does not allow it)
|
||||
*
|
||||
* @param oid Object id
|
||||
* @param noid New owner user id
|
||||
* @param error_str Error reason, if any
|
||||
*
|
||||
* @return 0 if the operation is allowed, -1 otherwise
|
||||
*/
|
||||
virtual int check_name_unique(int oid, int noid, string& error_str);
|
||||
|
||||
virtual PoolObjectSQL * get(const string& name, int uid, bool lock) = 0;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -75,6 +89,16 @@ public:
|
||||
};
|
||||
|
||||
~VirtualMachineChown(){};
|
||||
|
||||
int check_name_unique(int oid, int noid, string& error_str)
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
|
||||
PoolObjectSQL * get(const string& name, int uid, bool lock)
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -86,13 +110,18 @@ public:
|
||||
TemplateChown():
|
||||
RequestManagerChown("TemplateChown",
|
||||
"Changes ownership of a virtual machine template")
|
||||
{
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_tpool();
|
||||
auth_object = PoolObjectSQL::TEMPLATE;
|
||||
};
|
||||
|
||||
~TemplateChown(){};
|
||||
|
||||
PoolObjectSQL * get(const string& name, int uid, bool lock)
|
||||
{
|
||||
return static_cast<VMTemplatePool*>(pool)->get(name, uid, lock);
|
||||
};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -113,6 +142,10 @@ public:
|
||||
|
||||
~VirtualNetworkChown(){};
|
||||
|
||||
PoolObjectSQL * get(const string& name, int uid, bool lock)
|
||||
{
|
||||
return static_cast<VirtualNetworkPool*>(pool)->get(name, uid, lock);
|
||||
};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -132,6 +165,10 @@ public:
|
||||
|
||||
~ImageChown(){};
|
||||
|
||||
PoolObjectSQL * get(const string& name, int uid, bool lock)
|
||||
{
|
||||
return static_cast<ImagePool*>(pool)->get(name, uid, lock);
|
||||
};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -156,6 +193,11 @@ public:
|
||||
|
||||
virtual void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att);
|
||||
|
||||
PoolObjectSQL * get(const string& name, int uid, bool lock)
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -175,6 +217,10 @@ public:
|
||||
|
||||
~DatastoreChown(){};
|
||||
|
||||
PoolObjectSQL * get(const string& name, int uid, bool lock)
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -193,6 +239,11 @@ public:
|
||||
};
|
||||
|
||||
~DocumentChown(){};
|
||||
|
||||
PoolObjectSQL * get(const string& name, int uid, bool lock)
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -115,6 +115,41 @@ PoolObjectSQL * RequestManagerChown::get_and_quota(
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int RequestManagerChown::check_name_unique(int oid, int noid, string& error_str)
|
||||
{
|
||||
PoolObjectSQL * object;
|
||||
string name;
|
||||
int obj_oid;
|
||||
ostringstream oss;
|
||||
|
||||
object = pool->get(oid, true);
|
||||
|
||||
name = object->get_name();
|
||||
|
||||
object->unlock();
|
||||
|
||||
object = get(name, noid, true);
|
||||
|
||||
if ( object != 0 )
|
||||
{
|
||||
obj_oid = object->get_oid();
|
||||
object->unlock();
|
||||
|
||||
oss << PoolObjectSQL::type_to_str(PoolObjectSQL::USER)
|
||||
<< " [" << noid << "] already owns "
|
||||
<< PoolObjectSQL::type_to_str(auth_object) << " ["
|
||||
<< obj_oid << "] with NAME " << name;
|
||||
|
||||
error_str = oss.str();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
@ -123,6 +158,7 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
int ngid = xmlrpc_c::value_int(paramList.getInt(3));
|
||||
|
||||
int rc;
|
||||
string error_str;
|
||||
|
||||
string oname;
|
||||
string nuname;
|
||||
@ -194,6 +230,17 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
}
|
||||
}
|
||||
|
||||
// --------------- Check name uniqueness -----------------------------------
|
||||
|
||||
if ( noid != -1 )
|
||||
{
|
||||
if ( check_name_unique(oid, noid, error_str) != 0 )
|
||||
{
|
||||
failure_response(INTERNAL, request_error(error_str, ""), att);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------- Update the object and check quotas ----------------------
|
||||
|
||||
if ( auth_object == PoolObjectSQL::VM ||
|
||||
|
Loading…
Reference in New Issue
Block a user