1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-23 17:33:56 +03:00

Feature #1681: Read User template's UMASK attribute to create new objects

This commit is contained in:
Carlos Martín 2013-01-21 14:38:07 +01:00
parent d4245a6699
commit 780d7742f2
7 changed files with 157 additions and 19 deletions

View File

@ -173,6 +173,14 @@ public:
*/
Quotas quota;
/**
* Returns the UMASK template attribute (read as an octal number), or the
* default UMASK from oned.conf if it does not exist
*
* @return the UMASK to create new objects
*/
int get_umask() const;
private:
// -------------------------------------------------------------------------
// Friends

View File

@ -138,6 +138,24 @@ void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params,
string cluster_name = ClusterPool::NONE_CLUSTER_NAME;
PoolObjectAuth cluster_perms;
User * user;
UserPool * upool = Nebula::instance().get_upool();
user = upool->get(att.uid, true);
if ( user == 0 )
{
failure_response(NO_EXISTS,
get_error(object_name(PoolObjectSQL::USER), att.uid),
att);
return;
}
umask = user->get_umask();
user->unlock();
if ( do_template == true )
{
string str_tmpl = xmlrpc_c::value_string(params.getString(1));
@ -179,8 +197,6 @@ void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params,
return;
}
umask = Nebula::instance().get_default_umask();
rc = pool_allocate(params, tmpl, id, error_str, att, cluster_id, cluster_name, umask);
if ( rc < 0 )
@ -314,21 +330,41 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
Nebula& nd = Nebula::instance();
UserPool * upool = nd.get_upool();
DatastorePool * dspool = nd.get_dspool();
ImagePool * ipool = static_cast<ImagePool *>(pool);
ImageManager * imagem = nd.get_imagem();
ImageTemplate * tmpl = new ImageTemplate;
ImageTemplate * tmpl;
Template img_usage;
User * user;
Datastore * ds;
Image::DiskType ds_disk_type;
string umask_st;
int umask;
int umask;
// ------------------------- Get user's umask ------------------------------
user = upool->get(att.uid, true);
if ( user == 0 )
{
failure_response(NO_EXISTS,
get_error(object_name(PoolObjectSQL::USER), att.uid),
att);
return;
}
umask = user->get_umask();
user->unlock();
// ------------------------- Parse image template --------------------------
tmpl = new ImageTemplate;
rc = tmpl->parse_str_or_xml(str_tmpl, error_str);
if ( rc != 0 )
@ -460,8 +496,6 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
}
}
umask = Nebula::instance().get_default_umask();
rc = ipool->allocate(att.uid,
att.gid,
att.uname,

View File

@ -34,9 +34,27 @@ void RequestManagerClone::request_execute(
Template * tmpl;
PoolObjectSQL * source_obj;
User * user;
UserPool * upool = Nebula::instance().get_upool();
string error_str;
user = upool->get(att.uid, true);
if ( user == 0 )
{
failure_response(NO_EXISTS,
get_error(object_name(PoolObjectSQL::USER), att.uid),
att);
return;
}
umask = user->get_umask();
user->unlock();
source_obj = pool->get(source_id, true);
if ( source_obj == 0 )
@ -80,8 +98,6 @@ void RequestManagerClone::request_execute(
}
}
umask = Nebula::instance().get_default_umask();
rc = pool_allocate(source_id, tmpl, new_id, error_str, att, umask);
if ( rc < 0 )

View File

@ -239,11 +239,30 @@ void ImageClone::request_execute(
Template img_usage;
Image * img;
Datastore * ds;
User * user;
Nebula& nd = Nebula::instance();
DatastorePool * dspool = nd.get_dspool();
ImagePool * ipool = static_cast<ImagePool *>(pool);
UserPool * upool = nd.get_upool();
// ------------------------- Get user's umask ------------------------------
user = upool->get(att.uid, true);
if ( user == 0 )
{
failure_response(NO_EXISTS,
get_error(object_name(PoolObjectSQL::USER), att.uid),
att);
return;
}
umask = user->get_umask();
user->unlock();
// ------------------------- Get source Image info -------------------------
@ -356,8 +375,6 @@ void ImageClone::request_execute(
}
}
umask = Nebula::instance().get_default_umask();
rc = ipool->allocate(att.uid,
att.gid,
att.uname,

View File

@ -38,11 +38,13 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList
Nebula& nd = Nebula::instance();
VirtualMachinePool* vmpool = nd.get_vmpool();
VMTemplatePool * tpool = static_cast<VMTemplatePool *>(pool);
VirtualMachinePool* vmpool = nd.get_vmpool();
VMTemplatePool * tpool = static_cast<VMTemplatePool *>(pool);
UserPool * upool = nd.get_upool();
VirtualMachineTemplate * tmpl;
VMTemplate * rtmpl;
User * user;
string error_str;
string aname;
@ -54,6 +56,25 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList
on_hold = xmlrpc_c::value_boolean(paramList.getBoolean(3));
}
/* ---------------------------------------------------------------------- */
/* Get user's umask */
/* ---------------------------------------------------------------------- */
user = upool->get(att.uid, true);
if ( user == 0 )
{
failure_response(NO_EXISTS,
get_error(object_name(PoolObjectSQL::USER), att.uid),
att);
return;
}
umask = user->get_umask();
user->unlock();
/* ---------------------------------------------------------------------- */
/* Get, check and clone the template */
/* ---------------------------------------------------------------------- */
@ -139,8 +160,6 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList
Template tmpl_back(*tmpl);
umask = Nebula::instance().get_default_umask();
rc = vmpool->allocate(att.uid, att.gid, att.uname, att.gname, umask,
tmpl, &vid, error_str, on_hold);

View File

@ -681,8 +681,9 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
{
Nebula& nd = Nebula::instance();
ImagePool * ipool = nd.get_ipool();
DatastorePool * dspool = nd.get_dspool();
ImagePool * ipool = nd.get_ipool();
DatastorePool * dspool = nd.get_dspool();
UserPool * upool = nd.get_upool();
int id = xmlrpc_c::value_int(paramList.getInt(1));
int disk_id = xmlrpc_c::value_int(paramList.getInt(2));
@ -695,8 +696,10 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
Image * img;
Datastore * ds;
User * user;
Image::DiskType ds_disk_type;
int umask;
int rc;
string error_str;
@ -730,6 +733,25 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
return;
}
// -------------------------------------------------------------------------
// Get user's umask
// -------------------------------------------------------------------------
user = upool->get(att.uid, true);
if ( user == 0 )
{
failure_response(NO_EXISTS,
get_error(object_name(PoolObjectSQL::USER), att.uid),
att);
return;
}
umask = user->get_umask();
user->unlock();
// -------------------------------------------------------------------------
// Get the data of the Image to be saved
// -------------------------------------------------------------------------
@ -855,8 +877,6 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
// Create the image
// -------------------------------------------------------------------------
int umask = Nebula::instance().get_default_umask();
rc = ipool->allocate(att.uid,
att.gid,
att.uname,

View File

@ -283,6 +283,30 @@ bool User::pass_is_valid(const string& pass, string& error_str)
return true;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int User::get_umask() const
{
string umask_st;
int umask;
istringstream iss;
get_template_attribute("UMASK", umask_st);
if(umask_st.empty())
{
return Nebula::instance().get_default_umask();
}
iss.str(umask_st);
iss >> oct >> umask;
return umask;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */