diff --git a/include/Datastore.h b/include/Datastore.h index bb4acbbf3a..39ea26c348 100644 --- a/include/Datastore.h +++ b/include/Datastore.h @@ -123,7 +123,10 @@ private: // ************************************************************************* Datastore( - int id, + int uid, + int gid, + const string& uname, + const string& gname, DatastoreTemplate* ds_template, int cluster_id, const string& cluster_name); diff --git a/include/DatastorePool.h b/include/DatastorePool.h index 395cea46e6..294af9512d 100644 --- a/include/DatastorePool.h +++ b/include/DatastorePool.h @@ -61,6 +61,10 @@ public: /** * Allocates a new Datastore, writing it in the pool database. No memory is * allocated for the object. + * @param uid the user id of the Datastore owner + * @param gid the id of the group this object is assigned to + * @param uname name of the user + * @param gname name of the group * @param ds_template Datastore definition template * @param oid the id assigned to the Datastore * @param cluster_id the id of the cluster this Datastore will belong to @@ -69,11 +73,16 @@ public: * * @return the oid assigned to the object, -1 in case of failure */ - int allocate(DatastoreTemplate * ds_template, - int * oid, - int cluster_id, - const string& cluster_name, - string& error_str); + int allocate( + int uid, + int gid, + const string& uname, + const string& gname, + DatastoreTemplate * ds_template, + int * oid, + int cluster_id, + const string& cluster_name, + string& error_str); /** * Function to get a Datastore from the pool, if the object is not in memory @@ -163,7 +172,7 @@ private: */ PoolObjectSQL * create() { - return new Datastore(-1, 0, -1, ""); + return new Datastore(-1,-1,"","", 0, -1, ""); }; }; diff --git a/include/UserPool.h b/include/UserPool.h index 3926c71613..afe2e54e36 100644 --- a/include/UserPool.h +++ b/include/UserPool.h @@ -176,6 +176,16 @@ public: */ static const char * SERVER_NAME; + /** + * Name of the oneadmin user + */ + static string oneadmin_name; + + /** + * Identifier for the oneadmin user + */ + static const int ONEADMIN_ID; + private: //-------------------------------------------------------------------------- // Configuration Attributes for Users diff --git a/src/cli/one_helper/onedatastore_helper.rb b/src/cli/one_helper/onedatastore_helper.rb index 208aeb7b29..1202763765 100644 --- a/src/cli/one_helper/onedatastore_helper.rb +++ b/src/cli/one_helper/onedatastore_helper.rb @@ -66,6 +66,9 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper CLIHelper.print_header(str_h1 % "DATASTORE #{datastore['ID']} INFORMATION") puts str % ["ID", datastore.id.to_s] puts str % ["NAME", datastore.name] + puts str % ["USER", datastore['UNAME']] + puts str % ["GROUP", datastore['GNAME']] + puts str % ["TYPE", datastore['TYPE']] puts str % ["BASE PATH",datastore['BASE_PATH']] puts diff --git a/src/datastore/Datastore.cc b/src/datastore/Datastore.cc index fa81ddb0e1..d363dff1ca 100644 --- a/src/datastore/Datastore.cc +++ b/src/datastore/Datastore.cc @@ -34,16 +34,20 @@ const char * Datastore::db_bootstrap = /* Datastore :: Constructor/Destructor */ /* ************************************************************************ */ -Datastore::Datastore(int id, - DatastoreTemplate* ds_template, - int cluster_id, - const string& cluster_name): - PoolObjectSQL(id,DATASTORE,"",-1,-1,"","",table), - ObjectCollection("IMAGES"), - Clusterable(cluster_id, cluster_name), - type(""), - tm_mad(""), - base_path("") +Datastore::Datastore( + int uid, + int gid, + const string& uname, + const string& gname, + DatastoreTemplate* ds_template, + int cluster_id, + const string& cluster_name): + PoolObjectSQL(-1,DATASTORE,"",uid,gid,uname,gname,table), + ObjectCollection("IMAGES"), + Clusterable(cluster_id, cluster_name), + type(""), + tm_mad(""), + base_path("") { if (ds_template != 0) { @@ -144,10 +148,6 @@ int Datastore::insert_replace(SqlDB *db, bool replace, string& error_str) char * sql_name; char * sql_xml; - // Set the owner and group to oneadmin - set_user(0, ""); - set_group(GroupPool::ONEADMIN_ID, GroupPool::ONEADMIN_NAME); - // Update the Datastore sql_name = db->escape_str(name.c_str()); @@ -232,10 +232,14 @@ string& Datastore::to_xml(string& xml) const oss << "" << - "" << oid << "" << - "" << name << "" << - "" << type << "" << - "" << tm_mad << "" << + "" << oid << "" << + "" << uid << "" << + "" << gid << "" << + "" << uname << "" << + "" << gname << "" << + "" << name << "" << + "" << type << "" << + "" << tm_mad << "" << "" << base_path << "" << "" << cluster_id << "" << "" << cluster << "" << @@ -261,6 +265,10 @@ int Datastore::from_xml(const string& xml) // Get class base attributes rc += xpath(oid, "/DATASTORE/ID", -1); + rc += xpath(uid, "/DATASTORE/UID", -1); + rc += xpath(gid, "/DATASTORE/GID", -1); + rc += xpath(uname, "/DATASTORE/UNAME", "not_found"); + rc += xpath(gname, "/DATASTORE/GNAME", "not_found"); rc += xpath(name, "/DATASTORE/NAME", "not_found"); rc += xpath(type, "/DATASTORE/TYPE", "not_found"); rc += xpath(tm_mad, "/DATASTORE/TM_MAD", "not_found"); @@ -269,10 +277,6 @@ int Datastore::from_xml(const string& xml) rc += xpath(cluster_id, "/DATASTORE/CLUSTER_ID", -1); rc += xpath(cluster, "/DATASTORE/CLUSTER", "not_found"); - // Set the owner and group to oneadmin - set_user(0, ""); - set_group(GroupPool::ONEADMIN_ID, GroupPool::ONEADMIN_NAME); - // Get associated classes ObjectXML::get_nodes("/DATASTORE/IMAGES", content); diff --git a/src/datastore/DatastorePool.cc b/src/datastore/DatastorePool.cc index 7bec974218..9897f80790 100644 --- a/src/datastore/DatastorePool.cc +++ b/src/datastore/DatastorePool.cc @@ -67,7 +67,11 @@ DatastorePool::DatastorePool(SqlDB * db): goto error_bootstrap; } - allocate(ds_tmpl, + allocate(UserPool::ONEADMIN_ID, + GroupPool::ONEADMIN_ID, + UserPool::oneadmin_name, + GroupPool::ONEADMIN_NAME, + ds_tmpl, &system_id, ClusterPool::DEFAULT_CLUSTER_ID, ClusterPool::DEFAULT_CLUSTER_NAME, @@ -95,7 +99,11 @@ DatastorePool::DatastorePool(SqlDB * db): goto error_bootstrap; } - allocate(ds_tmpl, + allocate(UserPool::ONEADMIN_ID, + GroupPool::ONEADMIN_ID, + UserPool::oneadmin_name, + GroupPool::ONEADMIN_NAME, + ds_tmpl, &default_id, ClusterPool::DEFAULT_CLUSTER_ID, ClusterPool::DEFAULT_CLUSTER_NAME, @@ -145,18 +153,24 @@ error_bootstrap: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int DatastorePool::allocate(DatastoreTemplate * ds_template, - int * oid, - int cluster_id, - const string& cluster_name, - string& error_str) +int DatastorePool::allocate( + int uid, + int gid, + const string& uname, + const string& gname, + DatastoreTemplate * ds_template, + int * oid, + int cluster_id, + const string& cluster_name, + string& error_str) { Datastore * ds; Datastore * ds_aux = 0; string name; ostringstream oss; - ds = new Datastore(-1, ds_template, cluster_id, cluster_name); + ds = new Datastore(uid, gid, uname, gname, + ds_template, cluster_id, cluster_name); // ------------------------------------------------------------------------- // Check name & duplicates diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index 959a42827f..5342d9efd8 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -467,7 +467,8 @@ int DatastoreAllocate::pool_allocate( DatastoreTemplate * ds_tmpl = static_cast(tmpl); - return dspool->allocate(ds_tmpl, &id, cluster_id, cluster_name, error_str); + return dspool->allocate(att.uid, att.gid, att.uname, att.gname, + ds_tmpl, &id, cluster_id, cluster_name, error_str); } /* -------------------------------------------------------------------------- */ diff --git a/src/um/UserPool.cc b/src/um/UserPool.cc index 49598ed499..d06e6d90d6 100644 --- a/src/um/UserPool.cc +++ b/src/um/UserPool.cc @@ -40,11 +40,15 @@ const char * UserPool::DEFAULT_AUTH = "default"; const char * UserPool::SERVER_NAME = "serveradmin"; +const int UserPool::ONEADMIN_ID = 0; + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ time_t UserPool::_session_expiration_time; +string UserPool::oneadmin_name; + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -74,8 +78,13 @@ UserPool::UserPool(SqlDB * db, _session_expiration_time = __session_expiration_time; - if (get(0,false) != 0) + User * oneadmin_user = get(0, true); + + if (oneadmin_user != 0) { + oneadmin_name = oneadmin_user->get_name(); + oneadmin_user->unlock(); + return; } @@ -122,6 +131,8 @@ UserPool::UserPool(SqlDB * db, goto error_token; } + oneadmin_name = one_name; + if ( one_name == SERVER_NAME ) { goto error_one_name;