1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-27 13:57:23 +03:00

feature #407: Users gets the gid of user performing the allocate if not oneadmin. Group are added to users groups in constructor. Groups are updated in user allocate

This commit is contained in:
Ruben S. Montero 2011-06-09 00:12:39 +02:00
parent edf3df5671
commit 954038d426
4 changed files with 34 additions and 37 deletions

View File

@ -193,7 +193,9 @@ protected:
PoolObjectSQL(id,_username,-1,_gid,table),
ObjectCollection("GROUPS"),
password(_password), enabled(_enabled)
{};
{
add_collection_id(_gid); //Adds the primary group to the collection
};
virtual ~User(){};

View File

@ -212,42 +212,14 @@ int UserAllocate::pool_allocate(xmlrpc_c::paramList const& paramList,
string passwd = xmlrpc_c::value_string(paramList.getString(2));
UserPool * upool = static_cast<UserPool *>(pool);
User * user;
int users_group = gid;
int rc = upool->allocate(&id,GroupPool::USERS_ID,uname,passwd,true,error_str);
if ( rc < 0 )
if ( gid == GroupPool::ONEADMIN_ID )
{
return rc;
users_group = GroupPool::USERS_ID;
}
user = static_cast<User *>(pool->get(id,true));
if( user == 0 )
{
return -1;
}
user->add_group(GroupPool::USERS_ID);
pool->update(user);
user->unlock();
Nebula& nd = Nebula::instance();
GroupPool * gpool = nd.get_gpool();
Group * group = gpool->get(GroupPool::USERS_ID, true);
if( group == 0 )
{
return -1;
}
group->add_user(id);
gpool->update(group);
group->unlock();
return rc;
return upool->allocate(&id,users_group,uname,passwd,true,error_str);
}
/* -------------------------------------------------------------------------- */

View File

@ -413,6 +413,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
if ( (img = ipool->get(iid,true)) != 0 )
{
string tmp_error;
ipool->drop(img, tmp_error);
img->unlock();
}
@ -436,6 +437,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
if ( (img = ipool->get(iid,true)) != 0 )
{
string tmp_error;
ipool->drop(img, tmp_error);
img->unlock();
}

View File

@ -88,7 +88,6 @@ UserPool::UserPool(SqlDB * db):PoolSQL(db,User::table)
string error_str;
string sha1_pass = SSLTools::sha1_digest(one_pass);
// TODO: Add oneadmin to ONEADMIN Group
allocate(&one_uid,GroupPool::ONEADMIN_ID,one_name,sha1_pass,
true, error_str);
}
@ -123,7 +122,12 @@ int UserPool::allocate (
bool enabled,
string& error_str)
{
User * user;
Nebula& nd = Nebula::instance();
User * user;
GroupPool * gpool;
Group * group;
ostringstream oss;
if ( username.empty() )
@ -144,7 +148,25 @@ int UserPool::allocate (
// Insert the Object in the pool
*oid = PoolSQL::allocate(user, error_str);
return *oid;
if ( *oid < 0 )
{
return *oid;
}
// Adds User to group
gpool = nd.get_gpool();
group = gpool->get(gid, true);
if( group == 0 )
{
return -1;
}
group->add_user(*oid);
gpool->update(group);
group->unlock();
error_name:
oss << "NAME cannot be empty.";
@ -257,7 +279,6 @@ bool UserPool::authenticate(const string& session, int& user_id, int& group_id)
if ( !is.fail() )
{
// TODO: Add new user to USERS Group
allocate(&user_id,
GroupPool::USERS_ID,
mad_name,