mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-25 02:50:08 +03:00
Custom format string to log xml-rpc calls
This commit is contained in:
parent
c27984b1bb
commit
cc1dc8cb70
@ -57,6 +57,25 @@ public:
|
||||
INTERNAL = 0x2000,
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the format string to log xml-rpc method calls. The format string
|
||||
* interprets the following sequences:
|
||||
* %i -- request id
|
||||
* %m -- method name
|
||||
* %u -- user id
|
||||
* %U -- user name
|
||||
* %l -- param list
|
||||
* %p -- user password
|
||||
* %g -- group id
|
||||
* %G -- group name
|
||||
* %a -- auth token
|
||||
* %% -- %
|
||||
*/
|
||||
static void set_call_log_format(const string& log_format)
|
||||
{
|
||||
format_str = log_format;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
/* ---------------------------------------------------------------------*/
|
||||
@ -73,6 +92,8 @@ protected:
|
||||
string uname; /**< name of the user */
|
||||
string gname; /**< name of the user's group */
|
||||
|
||||
string password; /**< password of the user */
|
||||
|
||||
set<int> group_ids; /**< set of user's group ids */
|
||||
|
||||
string session; /**< Session from ONE XML-RPC API */
|
||||
@ -92,6 +113,8 @@ protected:
|
||||
uname = ra.uname;
|
||||
gname = ra.gname;
|
||||
|
||||
password = ra.password;
|
||||
|
||||
session = ra.session;
|
||||
retval = ra.retval;
|
||||
|
||||
@ -103,6 +126,8 @@ protected:
|
||||
uid = _uid;
|
||||
gid = _gid;
|
||||
|
||||
password = "";
|
||||
|
||||
uname = "";
|
||||
gname = "";
|
||||
|
||||
@ -123,6 +148,8 @@ protected:
|
||||
|
||||
set<int> hidden_params;
|
||||
|
||||
static string format_str;
|
||||
|
||||
/* -------------------- Constructors ---------------------------------- */
|
||||
|
||||
Request(const string& mn,
|
||||
|
@ -49,20 +49,10 @@ public:
|
||||
int _keepalive_timeout,
|
||||
int _keepalive_max_conn,
|
||||
int _timeout,
|
||||
const string _xml_log_file):
|
||||
port(_port),
|
||||
socket_fd(-1),
|
||||
max_conn(_max_conn),
|
||||
max_conn_backlog(_max_conn_backlog),
|
||||
keepalive_timeout(_keepalive_timeout),
|
||||
keepalive_max_conn(_keepalive_max_conn),
|
||||
timeout(_timeout),
|
||||
xml_log_file(_xml_log_file)
|
||||
{
|
||||
am.addListener(this);
|
||||
};
|
||||
const string _xml_log_file,
|
||||
const string call_log_format);
|
||||
|
||||
~RequestManager(){};
|
||||
~RequestManager(){};
|
||||
|
||||
/**
|
||||
* This functions starts the associated listener thread (XML server), and
|
||||
|
@ -145,6 +145,7 @@ public:
|
||||
* @return false if authn failed, true otherwise
|
||||
*/
|
||||
bool authenticate(const string& session,
|
||||
string& password,
|
||||
int& uid,
|
||||
int& gid,
|
||||
string& uname,
|
||||
@ -221,6 +222,7 @@ private:
|
||||
*/
|
||||
bool authenticate_internal(User * user,
|
||||
const string& token,
|
||||
string& password,
|
||||
int& user_id,
|
||||
int& group_id,
|
||||
string& uname,
|
||||
@ -233,6 +235,7 @@ private:
|
||||
*/
|
||||
bool authenticate_server(User * user,
|
||||
const string& token,
|
||||
string& password,
|
||||
int& user_id,
|
||||
int& group_id,
|
||||
string& uname,
|
||||
@ -246,6 +249,7 @@ private:
|
||||
*/
|
||||
bool authenticate_external(const string& username,
|
||||
const string& token,
|
||||
string& password,
|
||||
int& user_id,
|
||||
int& group_id,
|
||||
string& uname,
|
||||
|
@ -134,6 +134,18 @@ FEDERATION = [
|
||||
#
|
||||
# MESSAGE_SIZE: Buffer size in bytes for XML-RPC responses. Only relevant for
|
||||
# slave zones.
|
||||
#
|
||||
# LOG_CALL_FORMAT: Format string to log XML-RPC calls. Interpreted strings:
|
||||
# %i -- request id
|
||||
# %m -- method name
|
||||
# %u -- user id
|
||||
# %U -- user name
|
||||
# %l -- param list
|
||||
# %p -- user password
|
||||
# %g -- group id
|
||||
# %G -- group name
|
||||
# %a -- auth token
|
||||
# %% -- %
|
||||
#*******************************************************************************
|
||||
|
||||
#MAX_CONN = 15
|
||||
@ -143,6 +155,7 @@ FEDERATION = [
|
||||
#TIMEOUT = 15
|
||||
#RPC_LOG = NO
|
||||
#MESSAGE_SIZE = 1073741824
|
||||
#LOG_CALL_FORMAT = "Req:%i UID:%u %m invoked %l"
|
||||
|
||||
#*******************************************************************************
|
||||
# Physical Networks configuration
|
||||
|
@ -809,7 +809,7 @@ void Nebula::start(bool bootstrap_only)
|
||||
int keepalive_max_conn;
|
||||
int timeout;
|
||||
bool rpc_log;
|
||||
|
||||
string log_call_format;
|
||||
string rpc_filename = "";
|
||||
|
||||
nebula_configuration->get("PORT", rm_port);
|
||||
@ -819,6 +819,7 @@ void Nebula::start(bool bootstrap_only)
|
||||
nebula_configuration->get("KEEPALIVE_MAX_CONN", keepalive_max_conn);
|
||||
nebula_configuration->get("TIMEOUT", timeout);
|
||||
nebula_configuration->get("RPC_LOG", rpc_log);
|
||||
nebula_configuration->get("LOG_CALL_FORMAT", log_call_format);
|
||||
|
||||
if (rpc_log)
|
||||
{
|
||||
@ -826,7 +827,8 @@ void Nebula::start(bool bootstrap_only)
|
||||
}
|
||||
|
||||
rm = new RequestManager(rm_port, max_conn, max_conn_backlog,
|
||||
keepalive_timeout, keepalive_max_conn, timeout, rpc_filename);
|
||||
keepalive_timeout, keepalive_max_conn, timeout, rpc_filename,
|
||||
log_call_format);
|
||||
}
|
||||
catch (bad_alloc&)
|
||||
{
|
||||
|
@ -220,6 +220,7 @@ void OpenNebulaTemplate::set_conf_default()
|
||||
# TIMEOUT
|
||||
# RPC_LOG
|
||||
# MESSAGE_SIZE
|
||||
# LOG_CALL_FORMAT
|
||||
#*******************************************************************************
|
||||
*/
|
||||
// MAX_CONN
|
||||
@ -263,6 +264,12 @@ void OpenNebulaTemplate::set_conf_default()
|
||||
|
||||
attribute = new SingleAttribute("MESSAGE_SIZE",value);
|
||||
conf_default.insert(make_pair(attribute->name(),attribute));
|
||||
|
||||
//LOG_CALL_FORMAT
|
||||
value = "Req:%i UID:%u %m invoked %l";
|
||||
|
||||
attribute = new SingleAttribute("LOG_CALL_FORMAT",value);
|
||||
conf_default.insert(make_pair(attribute->name(),attribute));
|
||||
/*
|
||||
#*******************************************************************************
|
||||
# Physical Networks configuration
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
#include "PoolObjectAuth.h"
|
||||
|
||||
string Request::format_str;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@ -37,6 +39,7 @@ void Request::execute(
|
||||
UserPool* upool = nd.get_upool();
|
||||
|
||||
bool authenticated = upool->authenticate(att.session,
|
||||
att.password,
|
||||
att.uid,
|
||||
att.gid,
|
||||
att.uname,
|
||||
@ -67,28 +70,74 @@ void Request::log_method_invoked(
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << "Req:" << att.req_id << " UID:";
|
||||
|
||||
if ( att.uid != -1 )
|
||||
for (unsigned int j = 0 ;j < format_str.length() - 1; j++ )
|
||||
{
|
||||
oss << att.uid;
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << "-";
|
||||
}
|
||||
|
||||
oss << " " << method_name << " invoked";
|
||||
|
||||
for (unsigned int i=1; i<paramList.size(); i++)
|
||||
{
|
||||
if ( hidden_params.count(i) == 1 )
|
||||
if (format_str[j] != '%')
|
||||
{
|
||||
oss << ", ****";
|
||||
oss << format_str[j];
|
||||
}
|
||||
else
|
||||
{
|
||||
log_xmlrpc_value(paramList[i], oss);
|
||||
char mod = format_str[j+1];
|
||||
|
||||
switch(mod)
|
||||
{
|
||||
case '%':
|
||||
oss << "%";
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
oss << att.req_id;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
oss << att.uid;
|
||||
break;
|
||||
|
||||
case 'U':
|
||||
oss << att.uname;
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
oss << att.gid;
|
||||
break;
|
||||
|
||||
case 'G':
|
||||
oss << att.gname;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
oss << att.password;
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
oss << att.session;
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
oss << method_name;
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
for (unsigned int i=1; i<paramList.size(); i++)
|
||||
{
|
||||
if ( hidden_params.count(i) == 1 )
|
||||
{
|
||||
oss << ", ****";
|
||||
}
|
||||
else
|
||||
{
|
||||
log_xmlrpc_value(paramList[i], oss);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
oss << format_str[j] << format_str[j+1];
|
||||
break;
|
||||
}
|
||||
|
||||
j = j+1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,8 @@
|
||||
#include "RequestManagerSystem.h"
|
||||
#include "RequestManagerProxy.h"
|
||||
|
||||
#include "Request.h"
|
||||
|
||||
#include <sys/signal.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
@ -50,6 +52,31 @@
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
RequestManager::RequestManager(
|
||||
int _port,
|
||||
int _max_conn,
|
||||
int _max_conn_backlog,
|
||||
int _keepalive_timeout,
|
||||
int _keepalive_max_conn,
|
||||
int _timeout,
|
||||
const string _xml_log_file,
|
||||
const string call_log_format):
|
||||
port(_port),
|
||||
socket_fd(-1),
|
||||
max_conn(_max_conn),
|
||||
max_conn_backlog(_max_conn_backlog),
|
||||
keepalive_timeout(_keepalive_timeout),
|
||||
keepalive_max_conn(_keepalive_max_conn),
|
||||
timeout(_timeout),
|
||||
xml_log_file(_xml_log_file)
|
||||
{
|
||||
Request::set_call_log_format(call_log_format);
|
||||
|
||||
am.addListener(this);
|
||||
};
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -415,6 +415,7 @@ int UserPool::update_quotas(User * user)
|
||||
|
||||
bool UserPool::authenticate_internal(User * user,
|
||||
const string& token,
|
||||
string& password,
|
||||
int& user_id,
|
||||
int& group_id,
|
||||
string& uname,
|
||||
@ -426,7 +427,6 @@ bool UserPool::authenticate_internal(User * user,
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
string password;
|
||||
string auth_driver;
|
||||
string username;
|
||||
|
||||
@ -527,6 +527,8 @@ auth_failure:
|
||||
user_id = -1;
|
||||
group_id = -1;
|
||||
|
||||
password = "";
|
||||
|
||||
group_ids.clear();
|
||||
|
||||
uname = "";
|
||||
@ -542,6 +544,7 @@ auth_failure:
|
||||
|
||||
bool UserPool::authenticate_server(User * user,
|
||||
const string& token,
|
||||
string& password,
|
||||
int& user_id,
|
||||
int& group_id,
|
||||
string& uname,
|
||||
@ -587,6 +590,8 @@ bool UserPool::authenticate_server(User * user,
|
||||
goto auth_failure_user;
|
||||
}
|
||||
|
||||
password = user->get_password();
|
||||
|
||||
user_id = user->oid;
|
||||
group_id = user->gid;
|
||||
|
||||
@ -663,6 +668,8 @@ auth_failure:
|
||||
user_id = -1;
|
||||
group_id = -1;
|
||||
|
||||
password = "";
|
||||
|
||||
group_ids.clear();
|
||||
|
||||
uname = "";
|
||||
@ -678,6 +685,7 @@ auth_failure:
|
||||
|
||||
bool UserPool::authenticate_external(const string& username,
|
||||
const string& token,
|
||||
string& password,
|
||||
int& user_id,
|
||||
int& group_id,
|
||||
string& uname,
|
||||
@ -855,6 +863,8 @@ bool UserPool::authenticate_external(const string& username,
|
||||
|
||||
uname = mad_name;
|
||||
|
||||
password = mad_pass;
|
||||
|
||||
umask = User::get_default_umask();
|
||||
|
||||
return true;
|
||||
@ -881,6 +891,8 @@ auth_failure:
|
||||
user_id = -1;
|
||||
group_id = -1;
|
||||
|
||||
password = "";
|
||||
|
||||
group_ids.clear();
|
||||
|
||||
uname = "";
|
||||
@ -895,6 +907,7 @@ auth_failure:
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
bool UserPool::authenticate(const string& session,
|
||||
string& password,
|
||||
int& user_id,
|
||||
int& group_id,
|
||||
string& uname,
|
||||
@ -924,19 +937,19 @@ bool UserPool::authenticate(const string& session,
|
||||
|
||||
if ( fnmatch(UserPool::SERVER_AUTH, driver.c_str(), 0) == 0 )
|
||||
{
|
||||
ar = authenticate_server(user, token, user_id, group_id, uname,
|
||||
gname, group_ids, umask);
|
||||
ar = authenticate_server(user, token, password, user_id, group_id,
|
||||
uname, gname, group_ids, umask);
|
||||
}
|
||||
else
|
||||
{
|
||||
ar = authenticate_internal(user, token, user_id, group_id, uname,
|
||||
gname, group_ids, umask);
|
||||
ar = authenticate_internal(user, token, password, user_id, group_id,
|
||||
uname, gname, group_ids, umask);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ar = authenticate_external(username, token, user_id, group_id, uname,
|
||||
gname, group_ids, umask);
|
||||
ar = authenticate_external(username, token, password, user_id, group_id,
|
||||
uname, gname, group_ids, umask);
|
||||
}
|
||||
|
||||
return ar;
|
||||
|
Loading…
x
Reference in New Issue
Block a user