diff --git a/SConstruct b/SConstruct index 282875e9fd..6492bb173e 100644 --- a/SConstruct +++ b/SConstruct @@ -57,7 +57,6 @@ main_env.Append(LIBPATH=[ cwd+'/src/log', cwd+'/src/sql', cwd+'/src/host', - cwd+'/src/cluster', cwd+'/src/group', cwd+'/src/mad', cwd+'/src/nebula', @@ -187,7 +186,6 @@ build_scripts=[ 'src/common/SConstruct', 'src/template/SConstruct', 'src/host/SConstruct', - 'src/cluster/SConstruct', 'src/group/SConstruct', 'src/mad/SConstruct', 'src/nebula/SConstruct', @@ -235,7 +233,6 @@ if testing=='yes': 'src/authm/test/SConstruct', 'src/common/test/SConstruct', 'src/host/test/SConstruct', - 'src/cluster/test/SConstruct', 'src/group/test/SConstruct', 'src/image/test/SConstruct', 'src/lcm/test/SConstruct', diff --git a/include/Group.h b/include/Group.h index f28f38c963..12265711d5 100644 --- a/include/Group.h +++ b/include/Group.h @@ -50,23 +50,24 @@ public: int from_xml(const string &xml_str); /** - * Adds this object's ID to the set. The object MUST be a User, locked. - * The group's ID is added to the User's set. - * @param object The new object - * - * @return 0 on success, -1 if the ID was already in the set + * Adds this user's ID to the set. + * @param id of the user to be added to the group + * @return 0 on success */ - int add_collection_id(PoolObjectSQL* object); + int add_user(int id) + { + return add_collection_id(id); + } /** - * Deletes this object's ID from the set. The object MUST be a User, - * locked. The group's ID is deleted form the User's set. - * @param object The object - * - * @return 0 on success, -1 if the ID was not in the set + * Deletes this users's ID from the set. + * @param id of the user to be deleted from the group + * @return 0 on success */ - int del_collection_id(PoolObjectSQL* object); - + int del_user(int id) + { + return del_collection_id(id); + } private: @@ -142,12 +143,6 @@ private: { return insert_replace(db, true); } - - // ************************************************************************* - // ID Set management - // ************************************************************************* - - int add_del_collection_id(User* object, bool add); }; #endif /*GROUP_H_*/ diff --git a/include/ObjectCollection.h b/include/ObjectCollection.h index e96b0b44b4..059639f0f2 100644 --- a/include/ObjectCollection.h +++ b/include/ObjectCollection.h @@ -28,7 +28,7 @@ using namespace std; */ class ObjectCollection { -public: +protected: ObjectCollection(const string& _collection_name) :collection_name(_collection_name){}; @@ -36,26 +36,20 @@ public: ~ObjectCollection(){}; /** - * Adds this object's ID to the set. - * @param object The new object + * Adds an ID to the set. + * @param id The new id * * @return 0 on success, -1 if the ID was already in the set */ - virtual int add_collection_id(PoolObjectSQL* object) - { - return add_collection_id(object->get_oid()); - }; + int add_collection_id(int id); /** - * Deletes this object's ID from the set. - * @param object The object + * Deletes an ID from the set. + * @param id The id * * @return 0 on success, -1 if the ID was not in the set */ - virtual int del_collection_id(PoolObjectSQL* object) - { - return del_collection_id(object->get_oid()); - }; + int del_collection_id(int id); /** * Returns how many IDs are there in the set. @@ -66,8 +60,6 @@ public: return collection_set.size(); }; -protected: - /** * Rebuilds the object from an xml node * @param node The xml node pointer @@ -84,21 +76,6 @@ protected: */ string& to_xml(string& xml) const; - /** - * Adds an ID to the set. - * @param id The new id - * - * @return 0 on success, -1 if the ID was already in the set - */ - int add_collection_id(int id); - - /** - * Deletes an ID from the set. - * @param id The id - * - * @return 0 on success, -1 if the ID was not in the set - */ - int del_collection_id(int id); /** * Returns a copy of the IDs set diff --git a/include/User.h b/include/User.h index 0b8621b1fc..f3886a04c5 100644 --- a/include/User.h +++ b/include/User.h @@ -96,9 +96,12 @@ public: static int split_secret(const string secret, string& user, string& pass); /** - * Sets the User's gid and add the User's oid to that group + * Returns a copy of the groups for the user */ - int set_gid(int _gid); + set get_groups() + { + return get_collection_copy(); + }; private: // ------------------------------------------------------------------------- diff --git a/src/group/Group.cc b/src/group/Group.cc index 9a67618c8d..5e78f11ebe 100644 --- a/src/group/Group.cc +++ b/src/group/Group.cc @@ -160,67 +160,6 @@ int Group::from_xml(const string& xml) return 0; } -/* ************************************************************************ */ -/* Group :: User ID Set */ -/* ************************************************************************ */ - -int Group::add_collection_id(PoolObjectSQL* object) -{ - // TODO: make a dynamic cast and check if object is indeed a User ? - return add_del_collection_id( static_cast(object), true ); -} - -/* ------------------------------------------------------------------------ */ -/* ------------------------------------------------------------------------ */ - -int Group::del_collection_id(PoolObjectSQL* object) -{ - // TODO: make a dynamic cast and check if object is indeed a User ? - return add_del_collection_id( static_cast(object), false ); -} - -/* ------------------------------------------------------------------------ */ -/* ------------------------------------------------------------------------ */ - -int Group::add_del_collection_id(User* object, bool add) -{ - int rc = 0; - ObjectCollection * object_collection = 0; - - // Get object id - int object_id = object->get_oid(); - - // Add/Remove object to the group - if(add) - { - rc = ObjectCollection::add_collection_id(object_id); - } - else - { - rc = ObjectCollection::del_collection_id(object_id); - } - - if( rc != 0 ) - { - return -1; - } - - // Users can be in more than one group, it has to store the - // reverse relation - object_collection = static_cast(object); - - if(add) - { - rc = object_collection->add_collection_id( this ); - } - else - { - rc = object_collection->del_collection_id( this ); - } - - return rc; -} - /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ diff --git a/src/group/GroupPool.cc b/src/group/GroupPool.cc index 7a64cad760..ece62639d6 100644 --- a/src/group/GroupPool.cc +++ b/src/group/GroupPool.cc @@ -128,8 +128,6 @@ error_common: int GroupPool::drop(Group * group) { - int rc; - // Return error if the group is a default one. if( group->get_oid() < 100 ) { @@ -147,7 +145,5 @@ int GroupPool::drop(Group * group) return -1; } - rc = group->drop(db); - - return rc; + return group->drop(db); } diff --git a/src/host/Host.cc b/src/host/Host.cc index d078f46c94..9f35de297f 100644 --- a/src/host/Host.cc +++ b/src/host/Host.cc @@ -30,12 +30,12 @@ Host::Host( int id, - int cluster_id, + int gid, const string& _hostname, const string& _im_mad_name, const string& _vmm_mad_name, const string& _tm_mad_name): - PoolObjectSQL(id,_hostname,-1,cluster_id,table), + PoolObjectSQL(id,_hostname,-1,gid,table), state(INIT), im_mad_name(_im_mad_name), vmm_mad_name(_vmm_mad_name), @@ -53,57 +53,6 @@ Host::~Host() } } -/* ************************************************************************** */ -/* Host :: Cluster Management */ -/* ************************************************************************** */ - -int Host::add_to_cluster() -{ - return add_del_to_cluster(true); -} - -int Host::delete_from_cluster() -{ - return add_del_to_cluster(false); -} - -int Host::add_del_to_cluster(bool add) -{ - // Add this Host's ID to the Cluster - int rc = 0; - Nebula& nd = Nebula::instance(); - ClusterPool * cpool = nd.get_cpool(); - - if( cpool == 0 ) - { - return -1; - } - - Cluster * cluster = cpool->get( get_gid(), true ); - - if( cluster == 0 ) - { - return -1; - } - - if( add ) - { - rc = static_cast(cluster)->add_collection_id(this); - } - else - { - rc = static_cast(cluster)->del_collection_id(this); - } - - if( rc == 0 ) - { - cpool->update(cluster); - } - cluster->unlock(); - - return rc; -} - /* ************************************************************************ */ /* Host :: Database Access Functions */ /* ************************************************************************ */ diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index 910d6b4e13..b9d7c3e809 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -256,7 +256,29 @@ int UserAllocate::pool_allocate(xmlrpc_c::paramList const& paramList, UserPool * upool = static_cast(pool); - return upool->allocate(&id,GroupPool::USERS_ID,uname,passwd,true,error_str); + int rc = upool->allocate(&id,GroupPool::USERS_ID,uname,passwd,true,error_str); + + if ( rc < 0 ) + { + return rc; + } + + Nebula& nd = Nebula::instance(); + GroupPool * gpool = nd.get_gpool(); + Group * group = gpool->get(gid, true); + + if( group == 0 ) + { + return -1; + } + + group->add_user(id); + + gpool->update(group); + + group->unlock(); + + return rc; } /* -------------------------------------------------------------------------- */ diff --git a/src/rm/RequestManagerDelete.cc b/src/rm/RequestManagerDelete.cc index 7592e6c23e..935b5821ad 100644 --- a/src/rm/RequestManagerDelete.cc +++ b/src/rm/RequestManagerDelete.cc @@ -25,6 +25,7 @@ void RequestManagerDelete::request_execute(xmlrpc_c::paramList const& paramList) { int oid = xmlrpc_c::value_int(paramList.getInt(1)); PoolObjectSQL * object; + set group_set; if ( basic_authorization(oid) == false ) { @@ -39,6 +40,12 @@ void RequestManagerDelete::request_execute(xmlrpc_c::paramList const& paramList) return; } + if ( auth_ob == AuthRequest::USER ) + { + User * user = static_cast(object); + group_set = user->get_groups(); + } + int rc = pool->drop(object); object->unlock(); @@ -49,6 +56,31 @@ void RequestManagerDelete::request_execute(xmlrpc_c::paramList const& paramList) return; } + if ( auth_ob == AuthRequest::USER ) + { + Nebula& nd = Nebula::instance(); + GroupPool * gpool = nd.get_gpool(); + + Group * group; + + set::iterator it; + + for ( it = group_set.begin(); it != group_set.end(); it++ ) + { + group = gpool->get(*it, true); + + if( group == 0 ) + { + continue; + } + + group->del_user(oid); + gpool->update(group); + + group->unlock(); + } + } + success_response(oid); return; diff --git a/src/um/User.cc b/src/um/User.cc index 10b3cb579e..924fa35479 100644 --- a/src/um/User.cc +++ b/src/um/User.cc @@ -26,95 +26,6 @@ #include "Nebula.h" #include "Group.h" -/* ************************************************************************** */ -/* User :: Group Set Management */ -/* ************************************************************************** */ - -int User::add_to_group() -{ - // Add this User's ID to the Main Group - int rc = 0; - Nebula& nd = Nebula::instance(); - GroupPool * gpool = nd.get_gpool(); - - if( gpool == 0 ) - { - return -1; - } - - Group * group = gpool->get( get_gid(), true ); - - if( group == 0 ) - { - return -1; - } - - rc = group->add_collection_id(this); - - if( rc == 0 ) - { - gpool->update(group); - } - group->unlock(); - - return rc; -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -int User::set_gid(int _gid) -{ - gid = _gid; - - // The primary group is also kept in the Group Ids set. - // This method may return -1, because the Group could be a secondary group - // and be already in the set. - add_to_group(); - - return 0; -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -int User::delete_from_groups() -{ - int rc = 0; - - Nebula& nd = Nebula::instance(); - GroupPool * gpool = nd.get_gpool(); - Group * group; - - // Get a copy of the set, because the original will be modified deleting - // elements from it. - set group_set; - set::iterator it; - - group_set = get_collection_copy(); - - if( gpool == 0 ) - { - return -1; - } - - for ( it = group_set.begin(); it != group_set.end(); it++ ) - { - group = gpool->get( *it, true ); - - if( group == 0 ) - { - rc = -1; - continue; - } - - rc += group->del_collection_id(this); - gpool->update(group); - group->unlock(); - } - - return rc; -} /* ************************************************************************** */ /* User :: Database Access Functions */ diff --git a/src/um/UserPool.cc b/src/um/UserPool.cc index b323a4e441..91d79e9006 100644 --- a/src/um/UserPool.cc +++ b/src/um/UserPool.cc @@ -144,26 +144,8 @@ int UserPool::allocate ( // Insert the Object in the pool *oid = PoolSQL::allocate(user, error_str); - if( *oid != -1 ) - { - // Add this User's ID to his group - - user = get(*oid, true); - - rc = user->add_to_group(); - - if( rc != 0 ) - { - goto error_group; - } - - update( user ); - user->unlock(); - } - return *oid; - error_name: oss << "NAME cannot be empty."; goto error_common;