diff --git a/include/AclManager.h b/include/AclManager.h index 921a9faa5f..ac5d920c50 100644 --- a/include/AclManager.h +++ b/include/AclManager.h @@ -261,17 +261,16 @@ private: * @return true if any rule grants permission */ bool match_rules( - const long long &user_req, - const long long &resource_oid_req, - const long long &resource_gid_req, - const set &resource_cid_req, - const long long &resource_all_req, - const long long &rights_req, - const long long &resource_oid_mask, - const long long &resource_gid_mask, - const long long &resource_cid_mask, - const multimap &rules); - + long long user_req, + long long resource_oid_req, + long long resource_gid_req, + const set& resource_cid_req, + long long resource_all_req, + long long rights_req, + long long resource_oid_mask, + long long resource_gid_mask, + long long resource_cid_mask, + const multimap& rules); /** * Wrapper for match_rules. It will check if any rules in the temporary * multimap or in the internal one grants permission. @@ -290,17 +289,16 @@ private: * @return true if any rule grants permission */ bool match_rules_wrapper( - const long long &user_req, - const long long &resource_oid_req, - const long long &resource_gid_req, - const set &resource_cid_req, - const long long &resource_all_req, - const long long &rights_req, - const long long &individual_obj_type, - const long long &group_obj_type, - const long long &cluster_obj_type, + long long user_req, + long long resource_oid_req, + long long resource_gid_req, + const set& resource_cid_req, + long long resource_all_req, + long long rights_req, + long long individual_obj_type, + long long group_obj_type, + long long cluster_obj_type, const multimap &tmp_rules); - /** * Deletes all rules that match the user mask * diff --git a/include/Cluster.h b/include/Cluster.h index aa47376af4..4a58ed2589 100644 --- a/include/Cluster.h +++ b/include/Cluster.h @@ -192,10 +192,6 @@ public: */ int from_xml(const string &xml_str); - static const char * datastore_table; - - static const char * network_table; - private: // ------------------------------------------------------------------------- @@ -207,7 +203,6 @@ private: // ************************************************************************* // Constructor // ************************************************************************* - Cluster(int id, const string& name, ClusterTemplate* cl_template); @@ -217,7 +212,6 @@ private: // ************************************************************************* // Attributes (Private) // ************************************************************************* - ObjectCollection hosts; ObjectCollection datastores; ObjectCollection vnets; @@ -225,14 +219,15 @@ private: // ************************************************************************* // DataBase implementation (Private) // ************************************************************************* - static const char * db_names; static const char * db_bootstrap; static const char * table; + static const char * datastore_table; static const char * datastore_db_names; static const char * datastore_db_bootstrap; + static const char * network_table; static const char * network_db_names; static const char * network_db_bootstrap; diff --git a/include/ClusterPool.h b/include/ClusterPool.h index 4b3d16e604..75aeb243ce 100644 --- a/include/ClusterPool.h +++ b/include/ClusterPool.h @@ -146,8 +146,16 @@ public: limit); }; + /** + * Generates the cluster part of the ACL filter to look for objects. This + * filter is generated for objects that can be part of a cluster + * @param acl_filter stream to write the filter + * @param auth_object to generate the filter for + * @param cids vector of cluster ids + */ + static void cluster_acl_filter(ostringstream& filter, + PoolObjectSQL::ObjectType auth_object, const vector& cids); private: - /** * Factory method to produce objects * @return a pointer to the new object diff --git a/include/Clusterable.h b/include/Clusterable.h index a71a45e4c9..7dfb4dd685 100644 --- a/include/Clusterable.h +++ b/include/Clusterable.h @@ -19,8 +19,6 @@ #include "ObjectCollection.h" -using namespace std; - class Clusterable { public: @@ -40,7 +38,7 @@ public: * * @return The cluster IDs set */ - set get_cluster_ids() const + std::set get_cluster_ids() const { return cluster_ids.clone(); }; @@ -52,7 +50,7 @@ public: * * @return 0 on success, -1 otherwise */ - int from_xml(const ObjectXML* xml, const string& xpath_prefix) + int from_xml(const ObjectXML* xml, const std::string& xpath_prefix) { return cluster_ids.from_xml(xml, xpath_prefix); }; @@ -63,21 +61,15 @@ public: * @param xml the resulting XML string * @return a reference to the generated string */ - string& to_xml(string& xml) const + std::string& to_xml(std::string& xml) const { return cluster_ids.to_xml(xml); }; protected: - Clusterable(const set &_cluster_ids): - cluster_ids("CLUSTERS") - { - for(set::iterator i=_cluster_ids.begin();i!=_cluster_ids.end();i++) - { - cluster_ids.add(*i); - } - }; + Clusterable(const std::set &_cluster_ids): + cluster_ids("CLUSTERS", _cluster_ids){}; ~Clusterable(){}; diff --git a/include/ClusterableSingle.h b/include/ClusterableSingle.h index 96727b16a8..9023cc47f6 100644 --- a/include/ClusterableSingle.h +++ b/include/ClusterableSingle.h @@ -17,8 +17,6 @@ #ifndef CLUSTERABLE_SINGLE_H_ #define CLUSTERABLE_SINGLE_H_ -using namespace std; - class ClusterableSingle { public: @@ -29,7 +27,7 @@ public: * @param _cluster_id Id of the new cluster * @param _cluster Name of the new cluster */ - void set_cluster(int _cluster_id, const string& _cluster) + void set_cluster(int _cluster_id, const std::string& _cluster) { cluster_id = _cluster_id; cluster = _cluster; @@ -50,7 +48,7 @@ public: * * @return The cluster name */ - const string& get_cluster_name() const + const std::string& get_cluster_name() const { return cluster; }; @@ -58,7 +56,7 @@ public: protected: - ClusterableSingle(int _cluster_id, const string& _cluster): + ClusterableSingle(int _cluster_id, const std::string& _cluster): cluster_id(_cluster_id), cluster(_cluster){}; @@ -72,7 +70,7 @@ protected: /** * Name of the cluster this object belongs to. */ - string cluster; + std::string cluster; }; #endif /*CLUSTERABLE_SINGLE_H_*/ diff --git a/include/ObjectCollection.h b/include/ObjectCollection.h index 35eccff141..84110d3d2f 100644 --- a/include/ObjectCollection.h +++ b/include/ObjectCollection.h @@ -33,6 +33,9 @@ public: ObjectCollection(const string& _collection_name) :collection_name(_collection_name){}; + ObjectCollection(const string& cname, const set& cset) + :collection_name(cname), collection_set(cset){}; + ~ObjectCollection(){}; /** diff --git a/include/ObjectXML.h b/include/ObjectXML.h index 59cfeaa72a..f330aea201 100644 --- a/include/ObjectXML.h +++ b/include/ObjectXML.h @@ -187,15 +187,6 @@ public: return __search(name, value); } - /** - * Get xml nodes by Xpath - * @param xpath_expr the Xpath for the elements - * @param content nodes for the given Xpath expression. The nodes are - * returned as pointers to the object nodes. - * @return the number of nodes found - */ - int get_nodes(const char * xpath_expr, std::vector& content) const; - /** * Get xml nodes by Xpath * @param xpath_expr the Xpath for the elements diff --git a/include/RequestManagerAllocate.h b/include/RequestManagerAllocate.h index faf34bc07a..456c51410b 100644 --- a/include/RequestManagerAllocate.h +++ b/include/RequestManagerAllocate.h @@ -79,7 +79,7 @@ protected: return pool_allocate(_paramList, tmpl, id, att); }; - virtual int get_cluster_id(xmlrpc_c::paramList const& paramList) + virtual int get_cluster_id(xmlrpc_c::paramList const& paramList) { return ClusterPool::NONE_CLUSTER_ID; }; @@ -100,6 +100,17 @@ protected: protected: ClusterPool * clpool; + int get_cluster_id(xmlrpc_c::paramList const& paramList, int cluster_pos) + { + int cid = xmlrpc_c::value_int(paramList.getInt(cluster_pos)); + + if (cid == -1) + { + cid = ClusterPool::DEFAULT_CLUSTER_ID; + } + + return cid; + }; private: bool do_template; @@ -175,16 +186,9 @@ public: int cluster_id, const string& cluster_name); - int get_cluster_id(xmlrpc_c::paramList const& paramList) + int get_cluster_id(xmlrpc_c::paramList const& paramList) { - int cid = xmlrpc_c::value_int(paramList.getInt(2)); - - if (cid == -1) - { - cid = ClusterPool::DEFAULT_CLUSTER_ID; - } - - return cid; + return RequestManagerAllocate::get_cluster_id(paramList, 2); }; int add_to_cluster( @@ -285,16 +289,9 @@ public: int cluster_id, const string& cluster_name); - int get_cluster_id(xmlrpc_c::paramList const& paramList) + int get_cluster_id(xmlrpc_c::paramList const& paramList) { - int cid = xmlrpc_c::value_int(paramList.getInt(5)); - - if (cid == -1) - { - cid = ClusterPool::DEFAULT_CLUSTER_ID; - } - - return cid; + return RequestManagerAllocate::get_cluster_id(paramList, 5); }; int add_to_cluster( @@ -396,16 +393,9 @@ public: int cluster_id, const string& cluster_name); - int get_cluster_id(xmlrpc_c::paramList const& paramList) + int get_cluster_id(xmlrpc_c::paramList const& paramList) { - int cid = xmlrpc_c::value_int(paramList.getInt(2)); - - if (cid == -1) - { - cid = ClusterPool::DEFAULT_CLUSTER_ID; - } - - return cid; + return RequestManagerAllocate::get_cluster_id(paramList, 2); }; int add_to_cluster( diff --git a/include/RequestManagerCluster.h b/include/RequestManagerCluster.h index 5a2f8ce330..9e63e5563a 100644 --- a/include/RequestManagerCluster.h +++ b/include/RequestManagerCluster.h @@ -84,11 +84,6 @@ protected: PoolObjectSQL::ObjectType type, bool add); - virtual Datastore::DatastoreType get_ds_type(PoolObjectSQL *obj) - { - return Datastore::FILE_DS; - }; - /** * Add object to cluster id collection * @param cluster where to add the object @@ -204,11 +199,6 @@ public: ~RequestManagerClusterDatastore(){}; - virtual Datastore::DatastoreType get_ds_type(PoolObjectSQL *obj) - { - return static_cast(obj)->get_type(); - }; - virtual int add_object( Cluster* cluster, int id, diff --git a/src/acl/AclManager.cc b/src/acl/AclManager.cc index 6fa4e3cadb..47adfe4fc4 100644 --- a/src/acl/AclManager.cc +++ b/src/acl/AclManager.cc @@ -398,15 +398,15 @@ const bool AclManager::authorize( /* -------------------------------------------------------------------------- */ bool AclManager::match_rules_wrapper( - const long long &user_req, - const long long &resource_oid_req, - const long long &resource_gid_req, - const set &resource_cid_req, - const long long &resource_all_req, - const long long &rights_req, - const long long &individual_obj_type, - const long long &group_obj_type, - const long long &cluster_obj_type, + long long user_req, + long long resource_oid_req, + long long resource_gid_req, + const set& resource_cid_req, + long long resource_all_req, + long long rights_req, + long long individual_obj_type, + long long group_obj_type, + long long cluster_obj_type, const multimap &tmp_rules) { bool auth = false; @@ -452,10 +452,10 @@ bool AclManager::match_rules_wrapper( /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -inline bool match_cluster_req( - const set &resource_cid_req, - const long long &resource_cid_mask, - const long long &rule_resource) +static bool match_cluster_req( + const set &resource_cid_req, + long long resource_cid_mask, + long long rule_resource) { set::iterator i; @@ -474,15 +474,15 @@ inline bool match_cluster_req( /* -------------------------------------------------------------------------- */ bool AclManager::match_rules( - const long long &user_req, - const long long &resource_oid_req, - const long long &resource_gid_req, - const set &resource_cid_req, - const long long &resource_all_req, - const long long &rights_req, - const long long &resource_oid_mask, - const long long &resource_gid_mask, - const long long &resource_cid_mask, + long long user_req, + long long resource_oid_req, + long long resource_gid_req, + const set& resource_cid_req, + long long resource_all_req, + long long rights_req, + long long resource_oid_mask, + long long resource_gid_mask, + long long resource_cid_mask, const multimap &rules) { @@ -532,7 +532,8 @@ bool AclManager::match_rules( ( ( it->second->resource & resource_oid_mask ) == resource_oid_req ) || // Or rule's object type and one of the cluster object ID match - match_cluster_req(resource_cid_req, resource_cid_mask, it->second->resource) + match_cluster_req(resource_cid_req, resource_cid_mask, + it->second->resource) ); if ( auth == true ) diff --git a/src/cluster/ClusterPool.cc b/src/cluster/ClusterPool.cc index d9ddeb179c..f47de3be25 100644 --- a/src/cluster/ClusterPool.cc +++ b/src/cluster/ClusterPool.cc @@ -161,3 +161,51 @@ int ClusterPool::drop(PoolObjectSQL * objsql, string& error_msg) return rc; } + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void ClusterPool::cluster_acl_filter(ostringstream& filter, + PoolObjectSQL::ObjectType auth_object, const vector& cids) +{ + if ( cids.empty() ) + { + return; + } + + string fc = ""; + + switch (auth_object) + { + case PoolObjectSQL::HOST: + filter << " OR "; + break; + + case PoolObjectSQL::DATASTORE: + filter << " OR oid IN ( SELECT oid from " << Cluster::datastore_table + << " WHERE "; + fc = ")"; + break; + + case PoolObjectSQL::NET: + filter << " OR oid IN ( SELECT oid from " << Cluster::network_table + << " WHERE "; + fc = ")"; + break; + + default: + return; + } + + for ( vector::const_iterator it = cids.begin(); it < cids.end(); it++ ) + { + if ( it != cids.begin() ) + { + filter << " OR "; + } + + filter << "cid = " << *it; + } + + filter << fc; +} diff --git a/src/pool/ObjectCollection.cc b/src/pool/ObjectCollection.cc index 6f4e001b4c..4f4fe4f374 100644 --- a/src/pool/ObjectCollection.cc +++ b/src/pool/ObjectCollection.cc @@ -74,7 +74,6 @@ int ObjectCollection::from_xml(const ObjectXML* xml, const string& xpath_prefix) rc = from_xml_node(content[0]); xml->free_nodes(content); - content.clear(); return rc; } diff --git a/src/pool/PoolObjectSQL.cc b/src/pool/PoolObjectSQL.cc index 1bdc119b2b..a96b1c8f3c 100644 --- a/src/pool/PoolObjectSQL.cc +++ b/src/pool/PoolObjectSQL.cc @@ -370,11 +370,7 @@ void PoolObjectSQL::get_permissions(PoolObjectAuth& auth) if(cls != 0) { - set ids; - - ids.insert(cls->get_cluster_id()); - - auth.cids = ids; + auth.cids.insert(cls->get_cluster_id()); } } } diff --git a/src/pool/PoolSQL.cc b/src/pool/PoolSQL.cc index 35acb60fe5..89b3df9afb 100644 --- a/src/pool/PoolSQL.cc +++ b/src/pool/PoolSQL.cc @@ -702,7 +702,8 @@ void PoolSQL::acl_filter(int uid, { filter.clear(); - if ( uid == UserPool::ONEADMIN_ID || user_groups.count( GroupPool::ONEADMIN_ID ) == 1 ) + if ( uid == UserPool::ONEADMIN_ID || + user_groups.count( GroupPool::ONEADMIN_ID ) == 1 ) { all = true; return; @@ -740,34 +741,7 @@ void PoolSQL::acl_filter(int uid, acl_filter << " OR gid = " << *it; } - if (auth_object == PoolObjectSQL::HOST) - { - for ( it = cids.begin(); it < cids.end(); it++ ) - { - acl_filter << " OR cid = " << *it; - } - } - - string cl_table; - - if (auth_object == PoolObjectSQL::DATASTORE) - { - cl_table = Cluster::datastore_table; - } - else if (auth_object == PoolObjectSQL::NET) - { - cl_table = Cluster::network_table; - } - - if (!cl_table.empty()) - { - for ( it = cids.begin(); it < cids.end(); it++ ) - { - acl_filter << " OR oid IN (" - << "SELECT oid from " << cl_table - << " WHERE cid = " << *it << ")"; - } - } + ClusterPool::cluster_acl_filter(acl_filter, auth_object, cids); filter = acl_filter.str(); } diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index c2b431f4b7..344458bed5 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -665,7 +665,6 @@ void TransferManager::prolog_action(int vid) vector disk; const VectorAttribute * os_attr; int num; - int disk_id; string token_password; @@ -964,7 +963,6 @@ void TransferManager::prolog_resume_action(int vid) int ds_id; int disk_id; - int rc; vector disk; int num; diff --git a/src/xml/ObjectXML.cc b/src/xml/ObjectXML.cc index 0b3f991cc7..f1f02c4643 100644 --- a/src/xml/ObjectXML.cc +++ b/src/xml/ObjectXML.cc @@ -202,23 +202,13 @@ int ObjectXML::xpath_value(string& value,const char *doc,const char *the_xpath) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int ObjectXML::get_nodes( - const string& xpath_expr, +int ObjectXML::get_nodes(const string& xpath_expr, std::vector& content) const -{ - return get_nodes(xpath_expr.c_str(), content); -} - -/* -------------------------------------------------------------------------- */ - -int ObjectXML::get_nodes ( - const char * xpath_expr, - vector& content) const { xmlXPathObjectPtr obj; obj = xmlXPathEvalExpression( - reinterpret_cast(xpath_expr), ctx); + reinterpret_cast(xpath_expr.c_str()), ctx); if (obj == 0) {