mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
Feature #662: New user.chown method. Allow chown to change either owner or group alone.
This commit is contained in:
parent
ccde165841
commit
43a7c5c67b
@ -78,9 +78,20 @@ public:
|
||||
return uid;
|
||||
};
|
||||
|
||||
void set_uid(int _uid)
|
||||
/**
|
||||
* Changes the object's owner id
|
||||
* @param _uid New User ID
|
||||
* @return 0 on success, -1 if the object does not have an owner
|
||||
*/
|
||||
int set_uid(int _uid)
|
||||
{
|
||||
if( uid == -1 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
uid = _uid;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_gid()
|
||||
@ -88,9 +99,20 @@ public:
|
||||
return gid;
|
||||
};
|
||||
|
||||
void set_gid(int _gid)
|
||||
/**
|
||||
* Changes the object's group id
|
||||
* @param _gid New Group ID
|
||||
* @return 0 on success, -1 if the object does not have a group
|
||||
*/
|
||||
int set_gid(int _gid)
|
||||
{
|
||||
if( gid == -1 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
gid = _gid;
|
||||
return 0;
|
||||
};
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
@ -41,6 +41,46 @@ protected:
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual int set_uid(int noid, PoolObjectSQL * object, string& error_msg)
|
||||
{
|
||||
int rc = object->set_uid(noid);
|
||||
if ( rc < 0 )
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << object_name(auth_object) << " objects do not have owner";
|
||||
|
||||
error_msg = oss.str();
|
||||
}
|
||||
|
||||
pool->update(object);
|
||||
|
||||
object->unlock();
|
||||
|
||||
return rc;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual int set_gid(int ngid, PoolObjectSQL * object, string& error_msg)
|
||||
{
|
||||
int rc = object->set_gid(ngid);
|
||||
if ( rc < 0 )
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << object_name(auth_object) << " objects do not have group";
|
||||
|
||||
error_msg = oss.str();
|
||||
}
|
||||
|
||||
pool->update(object);
|
||||
|
||||
object->unlock();
|
||||
|
||||
return rc;
|
||||
};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -136,6 +176,61 @@ public:
|
||||
~HostChown(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class UserChown : public RequestManagerChown
|
||||
{
|
||||
public:
|
||||
UserChown():
|
||||
RequestManagerChown("UserChown",
|
||||
"Changes ownership of a user")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_upool();
|
||||
auth_object = AuthRequest::USER;
|
||||
};
|
||||
|
||||
~UserChown(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
int set_gid(int ngid, PoolObjectSQL * object, string& error_msg)
|
||||
{
|
||||
User * user = static_cast<User*>(object);
|
||||
int oid = user->get_oid();
|
||||
|
||||
user->set_gid(ngid);
|
||||
|
||||
// Main group is also in the Group IDs set
|
||||
// This call's return code is not checked, because this new main group
|
||||
// could be already a secondary group
|
||||
user->add_group(ngid);
|
||||
|
||||
pool->update(object);
|
||||
object->unlock();
|
||||
|
||||
// Now add the User's ID to the Group
|
||||
Nebula& nd = Nebula::instance();
|
||||
GroupPool * gpool = nd.get_gpool();
|
||||
Group * group = gpool->get(ngid, true);
|
||||
|
||||
if( group == 0 )
|
||||
{
|
||||
get_error(object_name(AuthRequest::GROUP),ngid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
group->add_user(oid);
|
||||
|
||||
gpool->update(group);
|
||||
|
||||
group->unlock();
|
||||
|
||||
return 0;
|
||||
};
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -309,6 +309,7 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr vn_chown(new VirtualNetworkChown());
|
||||
xmlrpc_c::methodPtr image_chown(new ImageChown());
|
||||
xmlrpc_c::methodPtr host_chown(new HostChown());
|
||||
xmlrpc_c::methodPtr user_chown(new UserChown());
|
||||
|
||||
/* VM related methods */
|
||||
RequestManagerRegistry.addMethod("one.vm.deploy", vm_deploy);
|
||||
@ -363,14 +364,13 @@ void RequestManager::register_xml_methods()
|
||||
|
||||
|
||||
/* User related methods*/
|
||||
/*
|
||||
*/
|
||||
RequestManagerRegistry.addMethod("one.user.allocate", user_allocate);
|
||||
RequestManagerRegistry.addMethod("one.user.delete", user_delete);
|
||||
RequestManagerRegistry.addMethod("one.user.info", user_info);
|
||||
RequestManagerRegistry.addMethod("one.user.addgroup", user_add_group);
|
||||
RequestManagerRegistry.addMethod("one.user.delgroup", user_del_group);
|
||||
RequestManagerRegistry.addMethod("one.user.passwd", user_change_password);
|
||||
RequestManagerRegistry.addMethod("one.user.chown", user_chown);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.userpool.info", userpool_info);
|
||||
|
||||
|
@ -35,6 +35,11 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList)
|
||||
GroupPool * gpool = nd.get_gpool();
|
||||
UserPool * upool = nd.get_upool();
|
||||
|
||||
string error_msg;
|
||||
int rc;
|
||||
|
||||
// TODO: maybe this authorization should include new user and new group
|
||||
// tokens
|
||||
if ( basic_authorization(oid) == false )
|
||||
{
|
||||
return;
|
||||
@ -42,24 +47,14 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList)
|
||||
|
||||
// ------------- Check new user and group id's ---------------------
|
||||
|
||||
if ( noid < 0 )
|
||||
if ( noid > -1 && upool->get(noid,false) == 0 )
|
||||
{
|
||||
failure_response(XML_RPC_API,request_error("Wrong User ID",""));
|
||||
return;
|
||||
}
|
||||
else if ( upool->get(noid,false) == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS,
|
||||
failure_response(NO_EXISTS,
|
||||
get_error(object_name(AuthRequest::USER),noid));
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ngid < 0 )
|
||||
{
|
||||
failure_response(XML_RPC_API,request_error("Wrong Group ID",""));
|
||||
return;
|
||||
}
|
||||
else if ( gpool->get(ngid,false) == 0 )
|
||||
if ( ngid > -1 && gpool->get(ngid,false) == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS,
|
||||
get_error(object_name(AuthRequest::GROUP),ngid));
|
||||
@ -76,12 +71,20 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList)
|
||||
return;
|
||||
}
|
||||
|
||||
object->set_uid(noid);
|
||||
object->set_gid(ngid);
|
||||
if ( noid > -1 )
|
||||
{
|
||||
rc = set_uid(noid, object, error_msg);
|
||||
}
|
||||
if ( rc == 0 && ngid > -1 )
|
||||
{
|
||||
rc = set_gid(ngid, object, error_msg);
|
||||
}
|
||||
|
||||
pool->update(object);
|
||||
|
||||
object->unlock();
|
||||
if ( rc != 0 )
|
||||
{
|
||||
failure_response(INTERNAL, request_error(error_msg,""));
|
||||
return;
|
||||
}
|
||||
|
||||
success_response(oid);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user