diff --git a/include/Group.h b/include/Group.h index 860d883e87..f732811b33 100644 --- a/include/Group.h +++ b/include/Group.h @@ -78,7 +78,7 @@ private: // ************************************************************************* Group(int id, const string& name): - PoolObjectSQL(id,name,-1,-1,table), + PoolObjectSQL(id,name,-1,-1,"","",table), ObjectCollection("USERS"){}; virtual ~Group(){}; diff --git a/include/Image.h b/include/Image.h index ad40595233..6c60ac4ab5 100644 --- a/include/Image.h +++ b/include/Image.h @@ -332,6 +332,8 @@ protected: Image(int uid, int gid, + const string& uname, + const string& gname, ImageTemplate* img_template); virtual ~Image(); diff --git a/include/ImagePool.h b/include/ImagePool.h index 6a5df81d8c..1c192997ec 100644 --- a/include/ImagePool.h +++ b/include/ImagePool.h @@ -48,6 +48,8 @@ public: * Function to allocate a new Image object * @param uid the user id of the image's 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 img_template template associated with the image * @param oid the id assigned to the Image * @param error_str Returns the error reason, if any @@ -58,6 +60,8 @@ public: int allocate ( int uid, int gid, + const string& uname, + const string& gname, ImageTemplate * img_template, int * oid, string& error_str); @@ -172,7 +176,7 @@ private: */ PoolObjectSQL * create() { - return new Image(-1,-1,0); + return new Image(-1,-1,"","",0); }; }; diff --git a/include/PoolObjectSQL.h b/include/PoolObjectSQL.h index 58794da920..36df15280e 100644 --- a/include/PoolObjectSQL.h +++ b/include/PoolObjectSQL.h @@ -36,11 +36,25 @@ using namespace std; class PoolObjectSQL : public ObjectSQL, public ObjectXML { public: - - PoolObjectSQL(int id, const string& _name, int _uid, - int _gid, const char *_table) - :ObjectSQL(),ObjectXML(),oid(id),name(_name),uid(_uid),gid(_gid), - valid(true),public_obj(0),obj_template(0),table(_table) + PoolObjectSQL(int id, + const string& _name, + int _uid, + int _gid, + const string& _uname, + const string& _gname, + const char * _table) + :ObjectSQL(), + ObjectXML(), + oid(id), + name(_name), + uid(_uid), + gid(_gid), + uname(_uname), + gname(_gname), + valid(true), + public_obj(0), + obj_template(0), + table(_table) { pthread_mutex_init(&mutex,0); }; @@ -84,21 +98,25 @@ public: }; /** - * Changes the object's owner id + * Changes the object's owner * @param _uid New User ID + * @param _uname Name of the new user */ - void set_uid(int _uid) + void set_user(int _uid, const string& _uname) { - uid = _uid; + uid = _uid; + uname = _uname; } /** * Changes the object's group id * @param _gid New Group ID + * @param _gname Name of the new group */ - void set_gid(int _gid) + void set_group(int _gid, const string& _gname) { - gid = _gid; + gid = _gid; + gname = _gname; }; /* --------------------------------------------------------------------- */ @@ -360,6 +378,16 @@ protected: */ int gid; + /** + * Name of the object's owner, empty if owner is not used + */ + string uname; + + /** + * Name of the object's group,, empty if group is not used + */ + string gname; + /** * The contents of this object are valid */ diff --git a/include/Request.h b/include/Request.h index 2f68ba3dbb..4a7d7121df 100644 --- a/include/Request.h +++ b/include/Request.h @@ -59,10 +59,12 @@ protected: /* ------------------- Attributes of the Request ---------------------- */ - int uid; /**< id of the user performing the request */ - + int uid; /**< id of the user */ int gid; /**< id of the user's group */ + string uname; /**< name of the user */ + string gname; /**< name of the user's group */ + set group_ids; /**< set of user's group ids */ PoolSQL * pool; /**< Pool of objects */ @@ -70,8 +72,7 @@ protected: string method_name; /**< The name of the XML-RPC method */ AuthRequest::Object auth_object; /**< Auth object for the request */ - - AuthRequest::Operation auth_op; /**< Auth operation for the request */ + AuthRequest::Operation auth_op; /**< Auth operation for the request */ /* -------------------- Constructors ---------------------------------- */ diff --git a/include/RequestManagerAcl.h b/include/RequestManagerAcl.h index fce48369a6..364cd9ea08 100644 --- a/include/RequestManagerAcl.h +++ b/include/RequestManagerAcl.h @@ -35,6 +35,7 @@ protected: :Request(method_name,params,help) { auth_object = AuthRequest::ACL; + auth_op = AuthRequest::MANAGE; }; ~RequestManagerAcl(){}; @@ -58,9 +59,7 @@ public: RequestManagerAcl("AclAddRule", "Adds a new ACL rule", "A:ssss") - { - // TODO: auth_op ? - }; + {}; ~AclAddRule(){}; @@ -77,9 +76,7 @@ public: RequestManagerAcl("AclDelRule", "Deletes an existing ACL rule", "A:si") - { - // TODO: auth_op ? - }; + {}; ~AclDelRule(){}; @@ -96,9 +93,7 @@ public: RequestManagerAcl("AclInfo", "Returns the ACL rule set", "A:s") - { - // TODO: auth_op ? - }; + {}; ~AclInfo(){}; diff --git a/include/User.h b/include/User.h index ee57ed35ba..b7b94775ee 100644 --- a/include/User.h +++ b/include/User.h @@ -189,11 +189,16 @@ protected: // Constructor // ************************************************************************* - User(int id, int _gid, const string& _username, const string& _password, bool _enabled): - PoolObjectSQL(id,_username,-1,_gid,table), + User(int id, + int _gid, + const string& _uname, + const string& _gname, + const string& _password, + bool _enabled): + PoolObjectSQL(id,_uname,-1,_gid,"",_gname,table), ObjectCollection("GROUPS"), - password(_password), enabled(_enabled) - { }; + password(_password), + enabled(_enabled){}; virtual ~User(){}; diff --git a/include/UserPool.h b/include/UserPool.h index 59db2b0a50..e543e65cde 100644 --- a/include/UserPool.h +++ b/include/UserPool.h @@ -51,8 +51,9 @@ public: int allocate ( int * oid, int gid, - string username, - string password, + const string& uname, + const string& gname, + const string& password, bool enabled, string& error_str); @@ -102,13 +103,17 @@ public: * @param session, colon separated username and password string * @param uid of the user if authN succeeded -1 otherwise * @param gid of the user if authN succeeded -1 otherwise + * @param uname of the user if authN succeeded "" otherwise + * @param gname of the group if authN succeeded "" otherwise * @param group_ids the user groups if authN succeeded, is empty otherwise * @return false if authn failed, true otherwise */ - bool authenticate(const string& session, int& uid, int& gid, - set& group_ids); - - + bool authenticate(const string& session, + int& uid, + int& gid, + string& uname, + string& gname, + set& group_ids); /** * Returns whether there is a user with given username/password or not * @param ar, an Authorization Request @@ -136,7 +141,7 @@ private: */ PoolObjectSQL * create() { - return new User(-1,-1,"","",true); + return new User(-1,-1,"","","",true); }; }; diff --git a/include/VMTemplate.h b/include/VMTemplate.h index b47a6fd705..819eb29c01 100644 --- a/include/VMTemplate.h +++ b/include/VMTemplate.h @@ -129,7 +129,11 @@ protected: // ************************************************************************* // Constructor // ************************************************************************* - VMTemplate(int id, int uid, int gid, + VMTemplate(int id, + int uid, + int gid, + const string& uname, + const string& gname, VirtualMachineTemplate * _template_contents); ~VMTemplate(); diff --git a/include/VMTemplatePool.h b/include/VMTemplatePool.h index 4ebb5a0280..0b66952bfd 100644 --- a/include/VMTemplatePool.h +++ b/include/VMTemplatePool.h @@ -44,6 +44,8 @@ public: */ int allocate(int uid, int gid, + const string& uname, + const string& gname, VirtualMachineTemplate * template_contents, int * oid, string& error_str); @@ -109,26 +111,13 @@ public: }; private: - //-------------------------------------------------------------------------- - // Configuration Attributes for Images - // ------------------------------------------------------------------------- - - // TODO - - //-------------------------------------------------------------------------- - // Pool Attributes - // ------------------------------------------------------------------------- - - // TODO - - /** * Factory method to produce Image objects * @return a pointer to the new Image */ PoolObjectSQL * create() { - return new VMTemplate(-1,-1,-1,0); + return new VMTemplate(-1,-1,-1,"","",0); }; }; diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index ff0e436ac5..3f52feb54a 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -865,8 +865,12 @@ protected: // Constructor //************************************************************************** - VirtualMachine(int id, int uid, - int gid, VirtualMachineTemplate * _vm_template); + VirtualMachine(int id, + int uid, + int gid, + const string& uname, + const string& gname, + VirtualMachineTemplate * _vm_template); virtual ~VirtualMachine(); diff --git a/include/VirtualMachinePool.h b/include/VirtualMachinePool.h index f84723259c..873e6de3d9 100644 --- a/include/VirtualMachinePool.h +++ b/include/VirtualMachinePool.h @@ -52,6 +52,8 @@ public: int allocate ( int uid, int gid, + const string& uname, + const string& gname, VirtualMachineTemplate * vm_template, int * oid, string& error_str, @@ -160,7 +162,7 @@ private: */ PoolObjectSQL * create() { - return new VirtualMachine(-1,-1,-1,0); + return new VirtualMachine(-1,-1,-1,"","",0); }; }; diff --git a/include/VirtualNetwork.h b/include/VirtualNetwork.h index a6d056854a..dc78655908 100644 --- a/include/VirtualNetwork.h +++ b/include/VirtualNetwork.h @@ -269,6 +269,8 @@ private: VirtualNetwork(int uid, int gid, + const string& _uname, + const string& _gname, VirtualNetworkTemplate * _vn_template = 0); ~VirtualNetwork(); diff --git a/include/VirtualNetworkPool.h b/include/VirtualNetworkPool.h index 1f6f2d3724..ff0fe2aed6 100644 --- a/include/VirtualNetworkPool.h +++ b/include/VirtualNetworkPool.h @@ -51,6 +51,8 @@ public: int allocate ( int uid, int gid, + const string& uname, + const string& gname, VirtualNetworkTemplate * vn_template, int * oid, string& error_str); @@ -156,7 +158,7 @@ private: */ PoolObjectSQL * create() { - return new VirtualNetwork(-1,-1, 0); + return new VirtualNetwork(-1,-1,"","",0); }; }; diff --git a/src/acl/AclManager.cc b/src/acl/AclManager.cc index d950a6075d..23a847e3c8 100644 --- a/src/acl/AclManager.cc +++ b/src/acl/AclManager.cc @@ -18,6 +18,7 @@ #include "AclManager.h" #include "NebulaLog.h" +#include "GroupPool.h" /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -105,6 +106,12 @@ const bool AclManager::authorize(int uid, const set &user_groups, bool auth = false; + // Only oneadmin, or someone in the oneadmin group can manage acl rules + if ( obj_type == AuthRequest::ACL ) + { + return ( uid == 0 || user_groups.count( GroupPool::ONEADMIN_ID ) == 1 ); + } + // Build masks for request long long user_req; long long resource_oid_req = obj_type + AclRule::INDIVIDUAL_ID + obj_id; diff --git a/src/host/Host.cc b/src/host/Host.cc index 992f0d87d3..062c456024 100644 --- a/src/host/Host.cc +++ b/src/host/Host.cc @@ -34,7 +34,7 @@ Host::Host( const string& _im_mad_name, const string& _vmm_mad_name, const string& _tm_mad_name): - PoolObjectSQL(id,_hostname,-1,-1,table), + PoolObjectSQL(id,_hostname,-1,-1,"","",table), state(INIT), im_mad_name(_im_mad_name), vmm_mad_name(_vmm_mad_name), diff --git a/src/image/Image.cc b/src/image/Image.cc index 928d371b3c..a752546490 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -36,8 +36,10 @@ Image::Image(int _uid, int _gid, + const string& _uname, + const string& _gname, ImageTemplate * _image_template): - PoolObjectSQL(-1,"",_uid,_gid,table), + PoolObjectSQL(-1,"",_uid,_gid,_uname,_gname,table), type(OS), regtime(time(0)), source("-"), @@ -324,6 +326,8 @@ string& Image::to_xml(string& xml) const "" << oid << "" << "" << uid << "" << "" << gid << "" << + "" << uname << "" << + "" << gname << "" << "" << name << "" << "" << type << "" << "" << public_obj << "" << @@ -332,7 +336,7 @@ string& Image::to_xml(string& xml) const "" << source << "" << "" << state << "" << "" << running_vms << "" << - obj_template->to_xml(template_xml) << + obj_template->to_xml(template_xml) << ""; xml = oss.str(); @@ -355,9 +359,13 @@ int Image::from_xml(const string& xml) update_from_str(xml); // Get class base attributes - rc += xpath(oid, "/IMAGE/ID", -1); + rc += xpath(oid, "/IMAGE/ID", -1); rc += xpath(uid, "/IMAGE/UID", -1); rc += xpath(gid, "/IMAGE/GID", -1); + + rc += xpath(uname, "/IMAGE/UNAME", "not_found"); + rc += xpath(gname, "/IMAGE/GNAME", "not_found"); + rc += xpath(name, "/IMAGE/NAME", "not_found"); rc += xpath(int_type, "/IMAGE/TYPE", 0); diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index b728fc2f0b..980715b6b9 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -57,6 +57,8 @@ ImagePool::ImagePool(SqlDB * db, int ImagePool::allocate ( int uid, int gid, + const string& uname, + const string& gname, ImageTemplate* img_template, int * oid, string& error_str) @@ -66,7 +68,7 @@ int ImagePool::allocate ( string name; ostringstream oss; - img = new Image(uid, gid, img_template); + img = new Image(uid, gid, uname, gname, img_template); // Check name img->get_template_attribute("NAME", name); diff --git a/src/rm/Request.cc b/src/rm/Request.cc index c3866b4d76..2a32ee6a64 100644 --- a/src/rm/Request.cc +++ b/src/rm/Request.cc @@ -33,7 +33,12 @@ void Request::execute( NebulaLog::log("ReM",Log::DEBUG, method_name + " method invoked"); - if ( upool->authenticate(session, uid, gid, group_ids) == false ) + if ( upool->authenticate(session, + uid, + gid, + uname, + gname, + group_ids) == false ) { failure_response(AUTHENTICATION, authenticate_error()); } @@ -166,6 +171,8 @@ string Request::object_name(AuthRequest::Object ob) return "virtual machine template"; case AuthRequest::GROUP: return "group"; + case AuthRequest::ACL: + return "ACL"; default: return "-"; } diff --git a/src/rm/RequestManagerAcl.cc b/src/rm/RequestManagerAcl.cc index aa30f041e1..676d54ce89 100644 --- a/src/rm/RequestManagerAcl.cc +++ b/src/rm/RequestManagerAcl.cc @@ -55,11 +55,8 @@ void AclAddRule::request_execute(xmlrpc_c::paramList const& paramList) string error_msg; - // TODO: Only oneadmin can manage ACL - if ( uid != 0 ) + if ( basic_authorization(-1) == false ) { - failure_response(AUTHORIZATION, - authorization_error("Only oneadmin can manage ACL rules")); return; } @@ -89,11 +86,8 @@ void AclDelRule::request_execute(xmlrpc_c::paramList const& paramList) string error_msg; - // TODO: Only oneadmin can manage ACL - if ( uid != 0 ) + if ( basic_authorization(-1) == false ) { - failure_response(AUTHORIZATION, - authorization_error("Only oneadmin can manage ACL rules")); return; } @@ -121,11 +115,8 @@ void AclInfo::request_execute(xmlrpc_c::paramList const& paramList) ostringstream oss; int rc; - // TODO: Only oneadmin can manage ACL - if ( uid != 0 ) + if ( basic_authorization(-1) == false ) { - failure_response(AUTHORIZATION, - authorization_error("Only oneadmin can manage ACL rules")); return; } diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index ccbbf9675a..175c92b5b0 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -133,10 +133,10 @@ int VirtualMachineAllocate::pool_allocate(xmlrpc_c::paramList const& paramList, int& id, string& error_str) { - VirtualMachineTemplate * ttmpl = static_cast(tmpl); - VirtualMachinePool * vmpool = static_cast(pool); + VirtualMachineTemplate * ttmpl= static_cast(tmpl); + VirtualMachinePool * vmpool = static_cast(pool); - return vmpool->allocate(uid, gid, ttmpl, &id, error_str, false); + return vmpool->allocate(uid, gid, uname, gname, ttmpl, &id,error_str,false); } @@ -151,7 +151,7 @@ int VirtualNetworkAllocate::pool_allocate(xmlrpc_c::paramList const& _paramList, VirtualNetworkPool * vpool = static_cast(pool); VirtualNetworkTemplate * vtmpl=static_cast(tmpl); - return vpool->allocate(uid, gid, vtmpl, &id, error_str); + return vpool->allocate(uid, gid, uname, gname, vtmpl, &id, error_str); } /* -------------------------------------------------------------------------- */ @@ -165,7 +165,7 @@ int ImageAllocate::pool_allocate(xmlrpc_c::paramList const& _paramList, ImagePool * ipool = static_cast(pool); ImageTemplate * itmpl = static_cast(tmpl); - return ipool->allocate(uid, gid, itmpl, &id, error_str); + return ipool->allocate(uid, gid, uname, gname, itmpl, &id, error_str); } /* -------------------------------------------------------------------------- */ @@ -180,7 +180,7 @@ int TemplateAllocate::pool_allocate(xmlrpc_c::paramList const& _paramList, VirtualMachineTemplate * ttmpl=static_cast(tmpl); - return tpool->allocate(uid, gid, ttmpl, &id, error_str); + return tpool->allocate(uid, gid, uname, gname, ttmpl, &id, error_str); } /* -------------------------------------------------------------------------- */ @@ -213,14 +213,17 @@ int UserAllocate::pool_allocate(xmlrpc_c::paramList const& paramList, string passwd = xmlrpc_c::value_string(paramList.getString(2)); UserPool * upool = static_cast(pool); - int users_group = gid; + + int ugid = gid; + string ugname = gname; if ( gid == GroupPool::ONEADMIN_ID ) { - users_group = GroupPool::USERS_ID; + ugid = GroupPool::USERS_ID; + ugname = GroupPool::USERS_NAME; } - return upool->allocate(&id,users_group,uname,passwd,true,error_str); + return upool->allocate(&id,ugid,uname,ugname,passwd,true,error_str); } /* -------------------------------------------------------------------------- */ diff --git a/src/rm/RequestManagerChown.cc b/src/rm/RequestManagerChown.cc index f2910aefe0..6e5c37b199 100644 --- a/src/rm/RequestManagerChown.cc +++ b/src/rm/RequestManagerChown.cc @@ -28,6 +28,9 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList) int noid = xmlrpc_c::value_int(paramList.getInt(2)); int ngid = xmlrpc_c::value_int(paramList.getInt(3)); + string nuname; + string ngname; + Nebula& nd = Nebula::instance(); GroupPool * gpool = nd.get_gpool(); UserPool * upool = nd.get_upool(); @@ -41,18 +44,36 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList) // ------------- Check new user and group id's --------------------- - if ( noid > -1 && upool->get(noid,false) == 0 ) + if ( noid > -1 ) { - failure_response(NO_EXISTS, + User * user; + + if ((user = upool->get(noid,true)) == 0) + { + failure_response(NO_EXISTS, get_error(object_name(AuthRequest::USER),noid)); - return; + return; + } + + nuname = user->get_name(); + + user->unlock(); } - if ( ngid > -1 && gpool->get(ngid,false) == 0 ) + if ( ngid > -1 ) { - failure_response(NO_EXISTS, + Group * group; + + if ((group = gpool->get(ngid,true)) == 0) + { + failure_response(NO_EXISTS, get_error(object_name(AuthRequest::GROUP),ngid)); - return; + return; + } + + ngname = group->get_name(); + + group->unlock(); } // ------------- Update the object --------------------- @@ -67,12 +88,12 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList) if ( noid != -1 ) { - object->set_uid(noid); + object->set_user(noid,nuname); } if ( ngid != -1 ) { - object->set_gid(ngid); + object->set_group(ngid,ngname); } pool->update(object); @@ -93,7 +114,7 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList) int ngid = xmlrpc_c::value_int(paramList.getInt(2)); int old_gid; - string str; + string ngname; Nebula& nd = Nebula::instance(); GroupPool * gpool = nd.get_gpool(); @@ -114,13 +135,18 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList) failure_response(XML_RPC_API,request_error("Wrong group ID","")); return; } - else if ( gpool->get(ngid,false) == 0 ) + + if ( (group = gpool->get(ngid,true)) == 0 ) { failure_response(NO_EXISTS, get_error(object_name(AuthRequest::GROUP),ngid)); return; } + ngname = group->get_name(); + + group->unlock(); + // ------------- Change users primary group --------------------- user = upool->get(oid,true); @@ -139,7 +165,7 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList) return; } - user->set_gid(ngid); + user->set_group(ngid,ngname); user->add_group(ngid); user->del_group(old_gid); @@ -154,7 +180,8 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList) if( group == 0 ) { - get_error(object_name(AuthRequest::GROUP),ngid); //TODO Rollback + failure_response(NO_EXISTS, + get_error(object_name(AuthRequest::GROUP),ngid));//TODO Rollback return; } diff --git a/src/rm/RequestManagerVMTemplate.cc b/src/rm/RequestManagerVMTemplate.cc index eac3224f2a..39e9e0aea0 100644 --- a/src/rm/RequestManagerVMTemplate.cc +++ b/src/rm/RequestManagerVMTemplate.cc @@ -69,7 +69,7 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList } } - rc = vmpool->allocate(uid, gid, tmpl, &vid, error_str, false); + rc = vmpool->allocate(uid, gid, uname, gname, tmpl, &vid, error_str, false); if ( rc < 0 ) { diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index cb93f988aa..de02b00f1b 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -398,7 +398,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis // ------------------ Create the image ------------------ - rc = ipool->allocate(uid, gid, itemplate, &iid,error_str); + rc = ipool->allocate(uid, gid, uname, gname, itemplate, &iid,error_str); if ( rc < 0 ) { diff --git a/src/um/User.cc b/src/um/User.cc index 3dd668b573..1a1d28aa6c 100644 --- a/src/um/User.cc +++ b/src/um/User.cc @@ -128,12 +128,13 @@ string& User::to_xml(string& xml) const oss << "" - "" << oid <<"" << - "" << gid <<"" << - "" << name <<"" << - "" << password <<"" << - "" << enabled_int <<"" << - collection_xml << + "" << oid <<"" << + "" << gid <<"" << + "" << gname <<"" << + "" << name <<"" << + "" << password <<""<< + "" << enabled_int <<"" << + collection_xml << ""; xml = oss.str(); @@ -155,6 +156,7 @@ int User::from_xml(const string& xml) rc += xpath(oid, "/USER/ID", -1); rc += xpath(gid, "/USER/GID", -1); + rc += xpath(gname, "/USER/GNAME", "not_found"); rc += xpath(name, "/USER/NAME", "not_found"); rc += xpath(password, "/USER/PASSWORD", "not_found"); rc += xpath(int_enabled, "/USER/ENABLED", 0); diff --git a/src/um/UserPool.cc b/src/um/UserPool.cc index 19a404a534..467263ab08 100644 --- a/src/um/UserPool.cc +++ b/src/um/UserPool.cc @@ -88,8 +88,13 @@ UserPool::UserPool(SqlDB * db):PoolSQL(db,User::table) string error_str; string sha1_pass = SSLTools::sha1_digest(one_pass); - allocate(&one_uid,GroupPool::ONEADMIN_ID,one_name,sha1_pass, - true, error_str); + allocate(&one_uid, + GroupPool::ONEADMIN_ID, + one_name, + GroupPool::ONEADMIN_NAME, + sha1_pass, + true, + error_str); } else { @@ -117,8 +122,9 @@ UserPool::UserPool(SqlDB * db):PoolSQL(db,User::table) int UserPool::allocate ( int * oid, int gid, - string username, - string password, + const string& uname, + const string& gname, + const string& password, bool enabled, string& error_str) { @@ -130,12 +136,12 @@ int UserPool::allocate ( ostringstream oss; - if ( username.empty() ) + if ( uname.empty() ) { goto error_name; } - user = get(username,false); + user = get(uname,false); if ( user !=0 ) { @@ -143,7 +149,7 @@ int UserPool::allocate ( } // Build a new User object - user = new User(-1, gid, username, password, enabled); + user = new User(-1, gid, uname, gname, password, enabled); user->add_collection_id(gid); //Adds the primary group to the collection @@ -190,9 +196,12 @@ error_common: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -//bool UserPool::authenticate(const string& session, int& user_id, int& group_id) -bool UserPool::authenticate(const string& session, int& user_id, int& group_id, - set& group_ids) +bool UserPool::authenticate(const string& session, + int& user_id, + int& group_id, + string& uname, + string& gname, + set& group_ids) { map::iterator index; @@ -200,6 +209,9 @@ bool UserPool::authenticate(const string& session, int& user_id, int& group_id, string username; string secret, u_pass; + string tuname; + string tgname; + int uid, gid; int rc; bool result; @@ -209,6 +221,8 @@ bool UserPool::authenticate(const string& session, int& user_id, int& group_id, user_id = -1; group_id = -1; + uname = ""; + gname = ""; result = false; rc = User::split_secret(session,username,secret); @@ -226,6 +240,9 @@ bool UserPool::authenticate(const string& session, int& user_id, int& group_id, uid = user->oid; gid = user->gid; + tuname = user->name; + tgname = user->gname; + group_ids = user->get_groups(); user->unlock(); @@ -245,8 +262,12 @@ bool UserPool::authenticate(const string& session, int& user_id, int& group_id, { if (ar.plain_authenticate()) { - user_id = 0; - group_id = GroupPool::ONEADMIN_ID; + user_id = uid; + group_id = gid; + + uname = tuname; + gname = tgname; + result = true; } } @@ -256,6 +277,10 @@ bool UserPool::authenticate(const string& session, int& user_id, int& group_id, { user_id = uid; group_id = gid; + + uname = tuname; + gname = tgname; + result = true; } } @@ -270,6 +295,10 @@ bool UserPool::authenticate(const string& session, int& user_id, int& group_id, { user_id = uid; group_id = gid; + + uname = tuname; + gname = tgname; + result = true; } else //External user, username & pass in driver message @@ -290,6 +319,7 @@ bool UserPool::authenticate(const string& session, int& user_id, int& group_id, allocate(&user_id, GroupPool::USERS_ID, mad_name, + GroupPool::USERS_NAME, mad_pass, true, error_str); @@ -308,6 +338,10 @@ bool UserPool::authenticate(const string& session, int& user_id, int& group_id, { group_ids.insert( GroupPool::USERS_ID ); group_id = GroupPool::USERS_ID; + + uname = mad_name; + gname = GroupPool::USERS_NAME; + result = true; } } diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index d6a505fc4c..7d12824d81 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -37,11 +37,13 @@ /* Virtual Machine :: Constructor/Destructor */ /* ************************************************************************** */ -VirtualMachine::VirtualMachine(int id, - int _uid, - int _gid, +VirtualMachine::VirtualMachine(int id, + int _uid, + int _gid, + const string& _uname, + const string& _gname, VirtualMachineTemplate * _vm_template): - PoolObjectSQL(id,"",_uid,_gid,table), + PoolObjectSQL(id,"",_uid,_gid,_uname,_gname,table), last_poll(0), state(INIT), lcm_state(LCM_INIT), @@ -1153,6 +1155,8 @@ string& VirtualMachine::to_xml(string& xml) const << "" << oid << "" << "" << uid << "" << "" << gid << "" + << "" << uname << "" + << "" << gname << "" << "" << name << "" << "" << last_poll << "" << "" << state << "" @@ -1185,34 +1189,38 @@ int VirtualMachine::from_xml(const string &xml_str) { vector content; - int int_state; - int int_lcmstate; + int istate; + int ilcmstate; int rc = 0; // Initialize the internal XML object update_from_str(xml_str); // Get class base attributes - rc += xpath(oid, "/VM/ID", -1); - rc += xpath(uid, "/VM/UID", -1); - rc += xpath(gid, "/VM/GID", -1); - rc += xpath(name, "/VM/NAME", "not_found"); + rc += xpath(oid, "/VM/ID", -1); - rc += xpath(last_poll, "/VM/LAST_POLL",0); - rc += xpath(int_state, "/VM/STATE", 0); - rc += xpath(int_lcmstate,"/VM/LCM_STATE", 0); + rc += xpath(uid, "/VM/UID", -1); + rc += xpath(gid, "/VM/GID", -1); - rc += xpath(stime, "/VM/STIME", 0); - rc += xpath(etime, "/VM/ETIME", 0); - rc += xpath(deploy_id, "/VM/DEPLOY_ID",""); + rc += xpath(uname, "/VM/UNAME", "not_found"); + rc += xpath(gname, "/VM/GNAME", "not_found"); + rc += xpath(name, "/VM/NAME", "not_found"); - rc += xpath(memory, "/VM/MEMORY", 0); - rc += xpath(cpu, "/VM/CPU", 0); - rc += xpath(net_tx, "/VM/NET_TX", 0); - rc += xpath(net_rx, "/VM/NET_RX", 0); + rc += xpath(last_poll, "/VM/LAST_POLL", 0); + rc += xpath(istate, "/VM/STATE", 0); + rc += xpath(ilcmstate, "/VM/LCM_STATE", 0); - state = static_cast( int_state ); - lcm_state = static_cast( int_lcmstate ); + rc += xpath(stime, "/VM/STIME", 0); + rc += xpath(etime, "/VM/ETIME", 0); + rc += xpath(deploy_id, "/VM/DEPLOY_ID",""); + + rc += xpath(memory, "/VM/MEMORY", 0); + rc += xpath(cpu, "/VM/CPU", 0); + rc += xpath(net_tx, "/VM/NET_TX", 0); + rc += xpath(net_rx, "/VM/NET_RX", 0); + + state = static_cast(istate); + lcm_state = static_cast(ilcmstate); // Get associated classes ObjectXML::get_nodes("/VM/TEMPLATE", content); diff --git a/src/vm/VirtualMachinePool.cc b/src/vm/VirtualMachinePool.cc index 9bb3bdd4fb..eae0cb0fde 100644 --- a/src/vm/VirtualMachinePool.cc +++ b/src/vm/VirtualMachinePool.cc @@ -178,6 +178,8 @@ VirtualMachinePool::VirtualMachinePool(SqlDB * db, int VirtualMachinePool::allocate ( int uid, int gid, + const string& uname, + const string& gname, VirtualMachineTemplate * vm_template, int * oid, string& error_str, @@ -188,7 +190,7 @@ int VirtualMachinePool::allocate ( // ------------------------------------------------------------------------ // Build a new Virtual Machine object // ------------------------------------------------------------------------ - vm = new VirtualMachine(-1, uid, gid, vm_template); + vm = new VirtualMachine(-1, uid, gid, uname, gname, vm_template); if (on_hold == true) { diff --git a/src/vm_template/VMTemplate.cc b/src/vm_template/VMTemplate.cc index 2ee020c124..94a7ce7230 100644 --- a/src/vm_template/VMTemplate.cc +++ b/src/vm_template/VMTemplate.cc @@ -26,8 +26,10 @@ VMTemplate::VMTemplate(int id, int _uid, int _gid, + const string& _uname, + const string& _gname, VirtualMachineTemplate * _template_contents): - PoolObjectSQL(id,"",_uid,_gid,table), + PoolObjectSQL(id,"",_uid,_gid,_uname,_gname,table), regtime(time(0)) { if (_template_contents != 0) @@ -190,6 +192,8 @@ string& VMTemplate::to_xml(string& xml) const << "" << oid << "" << "" << uid << "" << "" << gid << "" + << "" << uname << "" + << "" << gname << "" << "" << name << "" << "" << public_obj << "" << "" << regtime << "" @@ -216,6 +220,8 @@ int VMTemplate::from_xml(const string& xml) rc += xpath(oid, "/VMTEMPLATE/ID", -1); rc += xpath(uid, "/VMTEMPLATE/UID", -1); rc += xpath(gid, "/VMTEMPLATE/GID", -1); + rc += xpath(uname, "/VMTEMPLATE/UNAME", "not_found"); + rc += xpath(gname, "/VMTEMPLATE/GNAME", "not_found"); rc += xpath(name, "/VMTEMPLATE/NAME", "not_found"); rc += xpath(public_obj, "/VMTEMPLATE/PUBLIC", 0); rc += xpath(regtime, "/VMTEMPLATE/REGTIME", 0); diff --git a/src/vm_template/VMTemplatePool.cc b/src/vm_template/VMTemplatePool.cc index 24a84a6713..e0d330a4f2 100644 --- a/src/vm_template/VMTemplatePool.cc +++ b/src/vm_template/VMTemplatePool.cc @@ -26,6 +26,8 @@ int VMTemplatePool::allocate ( int uid, int gid, + const string& uname, + const string& gname, VirtualMachineTemplate * template_contents, int * oid, string& error_str) @@ -38,7 +40,7 @@ int VMTemplatePool::allocate ( // ------------------------------------------------------------------------ // Build a new VMTemplate object // ------------------------------------------------------------------------ - vm_template = new VMTemplate(-1, uid, gid, template_contents); + vm_template = new VMTemplate(-1, uid, gid, uname, gname,template_contents); // Check name vm_template->get_template_attribute("NAME", name); diff --git a/src/vnm/VirtualNetwork.cc b/src/vnm/VirtualNetwork.cc index c6326d018b..7dab044d06 100644 --- a/src/vnm/VirtualNetwork.cc +++ b/src/vnm/VirtualNetwork.cc @@ -29,10 +29,12 @@ /* Virtual Network :: Constructor/Destructor */ /* ************************************************************************** */ -VirtualNetwork::VirtualNetwork(int _uid, - int _gid, - VirtualNetworkTemplate *_vn_template): - PoolObjectSQL(-1,"",_uid,_gid,table), +VirtualNetwork::VirtualNetwork(int _uid, + int _gid, + const string& _uname, + const string& _gname, + VirtualNetworkTemplate * _vn_template): + PoolObjectSQL(-1,"",_uid,_gid,_uname,_gname,table), bridge(""), type(UNINITIALIZED), leases(0) @@ -514,12 +516,14 @@ string& VirtualNetwork::to_xml_extended(string& xml, bool extended) const os << "" << - "" << oid << "" << - "" << uid << "" << - "" << gid << "" << - "" << name << "" << - "" << type << "" << - "" << bridge << ""; + "" << oid << "" << + "" << uid << "" << + "" << gid << "" << + "" << uname << "" << + "" << gname << "" << + "" << name << "" << + "" << type << "" << + "" << bridge << ""; if (!phydev.empty()) { @@ -531,7 +535,7 @@ string& VirtualNetwork::to_xml_extended(string& xml, bool extended) const os << "" << vlan_id << ""; } - os << "" << public_obj << "" << + os << "" << public_obj << "" << ""<< total_leases << ""<< obj_template->to_xml(template_xml); @@ -561,18 +565,20 @@ int VirtualNetwork::from_xml(const string &xml_str) update_from_str(xml_str); // Get class base attributes - rc += xpath(oid, "/VNET/ID", -1); - rc += xpath(uid, "/VNET/UID", -1); - rc += xpath(gid, "/VNET/GID", -1); - rc += xpath(name, "/VNET/NAME", "not_found"); - rc += xpath(int_type, "/VNET/TYPE", -1); - rc += xpath(bridge, "/VNET/BRIDGE", "not_found"); - rc += xpath(public_obj, "/VNET/PUBLIC", 0); + rc += xpath(oid, "/VNET/ID", -1); + rc += xpath(uid, "/VNET/UID", -1); + rc += xpath(gid, "/VNET/GID", -1); + rc += xpath(uname, "/VNET/UNAME", "not_found"); + rc += xpath(gname, "/VNET/GNAME", "not_found"); + rc += xpath(name, "/VNET/NAME", "not_found"); + rc += xpath(int_type, "/VNET/TYPE", -1); + rc += xpath(bridge, "/VNET/BRIDGE", "not_found"); + rc += xpath(public_obj, "/VNET/PUBLIC", 0); xpath(phydev, "/VNET/PHYDEV", ""); - xpath(vlan_id, "/VNET/VLAN_ID", ""); + xpath(vlan_id, "/VNET/VLAN_ID",""); - type = static_cast( int_type ); + type = static_cast(int_type); // Get associated classes ObjectXML::get_nodes("/VNET/TEMPLATE", content); diff --git a/src/vnm/VirtualNetworkPool.cc b/src/vnm/VirtualNetworkPool.cc index e24464b33c..f292d9397b 100644 --- a/src/vnm/VirtualNetworkPool.cc +++ b/src/vnm/VirtualNetworkPool.cc @@ -72,6 +72,8 @@ VirtualNetworkPool::VirtualNetworkPool(SqlDB * db, int VirtualNetworkPool::allocate ( int uid, int gid, + const string& uname, + const string& gname, VirtualNetworkTemplate * vn_template, int * oid, string& error_str) @@ -80,7 +82,7 @@ int VirtualNetworkPool::allocate ( VirtualNetwork * vn_aux; string name; - vn = new VirtualNetwork(uid, gid, vn_template); + vn = new VirtualNetwork(uid, gid, uname, gname, vn_template); // Check for duplicates vn->get_template_attribute("NAME", name);