diff --git a/include/Request.h b/include/Request.h index 6e6d2774e5..c5fb3ac7ba 100644 --- a/include/Request.h +++ b/include/Request.h @@ -127,6 +127,14 @@ protected: */ void failure_response(ErrorCode ec, const string& val); + /** + * Gets a string representation for the Auth object in the + * request. + * @param ob object for the auth operation + * @returns string equivalent of the object + */ + static string object_name(AuthRequest::Object ob); + /** * Logs authorization errors * @param action authorization action diff --git a/src/rm/Request.cc b/src/rm/Request.cc index 6207d2b4c5..74d321d139 100644 --- a/src/rm/Request.cc +++ b/src/rm/Request.cc @@ -147,6 +147,34 @@ void Request::success_response(const string& val) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +string Request::object_name(AuthRequest::Object ob) +{ + switch (ob) + { + case AuthRequest::VM: + return "virtual machine"; + case AuthRequest::HOST: + return "host"; + case AuthRequest::NET: + return "virtual network"; + case AuthRequest::IMAGE: + return "image"; + case AuthRequest::USER: + return "user"; + case AuthRequest::CLUSTER: + return "cluster"; + case AuthRequest::TEMPLATE: + return "virtual machine template"; + case AuthRequest::GROUP: + return "group"; + default: + return "-"; + } +}; + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + string Request::authorization_error (const string &action, const string &object, int uid, diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index 5685574153..7ec147ea6f 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -27,7 +27,7 @@ string RequestManagerAllocate::allocate_error (const string& error) ostringstream oss; oss << "[" << method_name << "]" << " Error allocating a new " - << AuthRequest::object_name(auth_object) << "."; + << object_name(auth_object) << "."; if (!error.empty()) { @@ -45,7 +45,7 @@ string RequestManagerAllocate::allocate_error (char *error) ostringstream oss; oss << "[" << method_name << "]" << " Error allocating a new " - << AuthRequest::object_name(auth_object) << ". Parse error"; + << object_name(auth_object) << ". Parse error"; if ( error != 0 ) { @@ -147,7 +147,7 @@ int VirtualNetworkAllocate::pool_allocate(xmlrpc_c::paramList const& _paramList, string& error_str) { VirtualNetworkPool * vpool = static_cast(pool); - VirtualNetworkTemplate * vtmpl = static_cast(tmpl); + VirtualNetworkTemplate * vtmpl=static_cast(tmpl); return vpool->allocate(uid, gid, vtmpl, &id, error_str); } @@ -175,7 +175,8 @@ int TemplateAllocate::pool_allocate(xmlrpc_c::paramList const& _paramList, string& error_str) { VMTemplatePool * tpool = static_cast(pool); - VirtualMachineTemplate * ttmpl = static_cast(tmpl); + + VirtualMachineTemplate * ttmpl=static_cast(tmpl); return tpool->allocate(uid, gid, ttmpl, &id, error_str); } @@ -238,6 +239,7 @@ int GroupAllocate::pool_allocate(xmlrpc_c::paramList const& paramList, string& error_str) { string gname = xmlrpc_c::value_string(paramList.getString(1)); + GroupPool * gpool = static_cast(pool); return gpool->allocate(uid, gname, &id, error_str);