Commit a8d97fb8 authored by Sergey Vojtovich's avatar Sergey Vojtovich

MDEV-9651 - Simplify audit event dispatching

Simplified audit event dispatching call chain from:
  mysql_audit_notify_connection_connect() // can be inlined
  mysql_audit_notify()                    // can't be inlined
  connection_class_handler()              // can't be inlined
  event_class_dispatch()                  // can be inlined
  plugins_dispatch()                      // can be inlined
  plugin->event_notify()                  // can't be inlined
to:
  mysql_audit_notify_connection_connect() // can be inlined
  mysql_audit_notify()                    // can't be inlined
  plugins_dispatch()                      // can be inlined
  plugin->event_notify()                  // can't be inlined
parent e9f6c816
...@@ -56,7 +56,7 @@ struct mysql_event_general ...@@ -56,7 +56,7 @@ struct mysql_event_general
unsigned int general_command_length; unsigned int general_command_length;
const char *general_query; const char *general_query;
unsigned int general_query_length; unsigned int general_query_length;
struct charset_info_st *general_charset; const struct charset_info_st *general_charset;
unsigned long long general_time; unsigned long long general_time;
unsigned long long general_rows; unsigned long long general_rows;
/* Added in version 0x302 */ /* Added in version 0x302 */
......
...@@ -422,7 +422,7 @@ struct mysql_event_general ...@@ -422,7 +422,7 @@ struct mysql_event_general
unsigned int general_command_length; unsigned int general_command_length;
const char *general_query; const char *general_query;
unsigned int general_query_length; unsigned int general_query_length;
struct charset_info_st *general_charset; const struct charset_info_st *general_charset;
unsigned long long general_time; unsigned long long general_time;
unsigned long long general_rows; unsigned long long general_rows;
unsigned long long query_id; unsigned long long query_id;
......
...@@ -24,6 +24,7 @@ extern int finalize_audit_plugin(st_plugin_int *plugin); ...@@ -24,6 +24,7 @@ extern int finalize_audit_plugin(st_plugin_int *plugin);
struct st_mysql_event_generic struct st_mysql_event_generic
{ {
unsigned long event_class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE];
unsigned int event_class; unsigned int event_class;
const void *event; const void *event;
}; };
...@@ -32,8 +33,6 @@ unsigned long mysql_global_audit_mask[MYSQL_AUDIT_CLASS_MASK_SIZE]; ...@@ -32,8 +33,6 @@ unsigned long mysql_global_audit_mask[MYSQL_AUDIT_CLASS_MASK_SIZE];
static mysql_mutex_t LOCK_audit_mask; static mysql_mutex_t LOCK_audit_mask;
static void event_class_dispatch(THD *, unsigned int, const void *);
static inline static inline
void set_audit_mask(unsigned long *mask, uint event_class) void set_audit_mask(unsigned long *mask, uint event_class)
...@@ -56,101 +55,6 @@ bool check_audit_mask(const unsigned long *lhs, ...@@ -56,101 +55,6 @@ bool check_audit_mask(const unsigned long *lhs,
} }
typedef void (*audit_handler_t)(THD *thd, uint event_subtype, va_list ap);
/**
MYSQL_AUDIT_GENERAL_CLASS handler
@param[in] thd
@param[in] event_subtype
@param[in] error_code
@param[in] ap
*/
static void general_class_handler(THD *thd, uint event_subtype, va_list ap)
{
mysql_event_general event;
event.event_subclass= event_subtype;
event.general_error_code= va_arg(ap, int);
event.general_thread_id= thd ? thd->thread_id : 0;
event.general_time= va_arg(ap, time_t);
event.general_user= va_arg(ap, const char *);
event.general_user_length= va_arg(ap, unsigned int);
event.general_command= va_arg(ap, const char *);
event.general_command_length= va_arg(ap, unsigned int);
event.general_query= va_arg(ap, const char *);
event.general_query_length= va_arg(ap, unsigned int);
event.general_charset= va_arg(ap, struct charset_info_st *);
event.general_rows= (unsigned long long) va_arg(ap, ha_rows);
event.database= va_arg(ap, const char *);
event.database_length= va_arg(ap, unsigned int);
event.query_id= (unsigned long long) (thd ? thd->query_id : 0);
event_class_dispatch(thd, MYSQL_AUDIT_GENERAL_CLASS, &event);
}
static void connection_class_handler(THD *thd, uint event_subclass, va_list ap)
{
mysql_event_connection event;
event.event_subclass= event_subclass;
event.status= va_arg(ap, int);
event.thread_id= (unsigned long) va_arg(ap, long long);
event.user= va_arg(ap, const char *);
event.user_length= va_arg(ap, unsigned int);
event.priv_user= va_arg(ap, const char *);
event.priv_user_length= va_arg(ap, unsigned int);
event.external_user= va_arg(ap, const char *);
event.external_user_length= va_arg(ap, unsigned int);
event.proxy_user= va_arg(ap, const char *);
event.proxy_user_length= va_arg(ap, unsigned int);
event.host= va_arg(ap, const char *);
event.host_length= va_arg(ap, unsigned int);
event.ip= va_arg(ap, const char *);
event.ip_length= va_arg(ap, unsigned int);
event.database= va_arg(ap, const char *);
event.database_length= va_arg(ap, unsigned int);
event_class_dispatch(thd, MYSQL_AUDIT_CONNECTION_CLASS, &event);
}
static void table_class_handler(THD *thd, uint event_subclass, va_list ap)
{
mysql_event_table event;
event.event_subclass= event_subclass;
event.read_only= va_arg(ap, int);
event.thread_id= va_arg(ap, unsigned long);
event.user= va_arg(ap, const char *);
event.priv_user= va_arg(ap, const char *);
event.priv_host= va_arg(ap, const char *);
event.external_user= va_arg(ap, const char *);
event.proxy_user= va_arg(ap, const char *);
event.host= va_arg(ap, const char *);
event.ip= va_arg(ap, const char *);
event.database= va_arg(ap, const char *);
event.database_length= va_arg(ap, unsigned int);
event.table= va_arg(ap, const char *);
event.table_length= va_arg(ap, unsigned int);
event.new_database= va_arg(ap, const char *);
event.new_database_length= va_arg(ap, unsigned int);
event.new_table= va_arg(ap, const char *);
event.new_table_length= va_arg(ap, unsigned int);
event.query_id= (unsigned long long) (thd ? thd->query_id : 0);
event_class_dispatch(thd, MYSQL_AUDIT_TABLE_CLASS, &event);
}
static audit_handler_t audit_handlers[] =
{
general_class_handler, connection_class_handler,
0,0,0,0,0,0,0,0,0,0,0,0,0, /* placeholders */
table_class_handler
};
static const uint audit_handlers_count=
(sizeof(audit_handlers) / sizeof(audit_handler_t));
/** /**
Acquire and lock any additional audit plugins as required Acquire and lock any additional audit plugins as required
...@@ -207,38 +111,16 @@ static my_bool acquire_plugins(THD *thd, plugin_ref plugin, void *arg) ...@@ -207,38 +111,16 @@ static my_bool acquire_plugins(THD *thd, plugin_ref plugin, void *arg)
void mysql_audit_acquire_plugins(THD *thd, ulong *event_class_mask) void mysql_audit_acquire_plugins(THD *thd, ulong *event_class_mask)
{ {
DBUG_ENTER("mysql_audit_acquire_plugins"); DBUG_ENTER("mysql_audit_acquire_plugins");
if (thd && !check_audit_mask(mysql_global_audit_mask, event_class_mask) && DBUG_ASSERT(thd);
check_audit_mask(thd->audit_class_mask, event_class_mask)) DBUG_ASSERT(!check_audit_mask(mysql_global_audit_mask, event_class_mask));
if (check_audit_mask(thd->audit_class_mask, event_class_mask))
{ {
plugin_foreach(thd, acquire_plugins, MYSQL_AUDIT_PLUGIN, event_class_mask); plugin_foreach(thd, acquire_plugins, MYSQL_AUDIT_PLUGIN, event_class_mask);
add_audit_mask(thd->audit_class_mask, event_class_mask); add_audit_mask(thd->audit_class_mask, event_class_mask);
} }
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
/**
Notify the audit system of an event
@param[in] thd
@param[in] event_class
@param[in] event_subtype
@param[in] error_code
*/
void mysql_audit_notify(THD *thd, uint event_class, uint event_subtype, ...)
{
va_list ap;
audit_handler_t *handlers= audit_handlers + event_class;
DBUG_ASSERT(event_class < audit_handlers_count);
unsigned long event_class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE];
set_audit_mask(event_class_mask, event_class);
mysql_audit_acquire_plugins(thd, event_class_mask);
va_start(ap, event_subtype);
(*handlers)(thd, event_subtype, ap);
va_end(ap);
}
/** /**
...@@ -496,17 +378,11 @@ static my_bool plugins_dispatch(THD *thd, plugin_ref plugin, void *arg) ...@@ -496,17 +378,11 @@ static my_bool plugins_dispatch(THD *thd, plugin_ref plugin, void *arg)
{ {
const struct st_mysql_event_generic *event_generic= const struct st_mysql_event_generic *event_generic=
(const struct st_mysql_event_generic *) arg; (const struct st_mysql_event_generic *) arg;
unsigned long event_class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE];
st_mysql_audit *data= plugin_data(plugin, struct st_mysql_audit *); st_mysql_audit *data= plugin_data(plugin, struct st_mysql_audit *);
set_audit_mask(event_class_mask, event_generic->event_class);
/* Check to see if the plugin is interested in this event */ /* Check to see if the plugin is interested in this event */
if (check_audit_mask(data->class_mask, event_class_mask)) if (!check_audit_mask(data->class_mask, event_generic->event_class_mask))
return 0; data->event_notify(thd, event_generic->event_class, event_generic->event);
/* Actually notify the plugin */
data->event_notify(thd, event_generic->event_class, event_generic->event);
return 0; return 0;
} }
...@@ -514,17 +390,18 @@ static my_bool plugins_dispatch(THD *thd, plugin_ref plugin, void *arg) ...@@ -514,17 +390,18 @@ static my_bool plugins_dispatch(THD *thd, plugin_ref plugin, void *arg)
/** /**
Distributes an audit event to plug-ins Distributes an audit event to plug-ins
@param[in] thd @param[in] thd
@param[in] event_class
@param[in] event @param[in] event
*/ */
static void event_class_dispatch(THD *thd, unsigned int event_class, void mysql_audit_notify(THD *thd, uint event_class, const void *event)
const void *event)
{ {
struct st_mysql_event_generic event_generic; struct st_mysql_event_generic event_generic;
event_generic.event_class= event_class; event_generic.event_class= event_class;
event_generic.event= event; event_generic.event= event;
set_audit_mask(event_generic.event_class_mask, event_class);
/* /*
Check if we are doing a slow global dispatch. This event occurs when Check if we are doing a slow global dispatch. This event occurs when
thd == NULL as it is not associated with any particular thread. thd == NULL as it is not associated with any particular thread.
...@@ -537,6 +414,8 @@ static void event_class_dispatch(THD *thd, unsigned int event_class, ...@@ -537,6 +414,8 @@ static void event_class_dispatch(THD *thd, unsigned int event_class,
{ {
plugin_ref *plugins, *plugins_last; plugin_ref *plugins, *plugins_last;
mysql_audit_acquire_plugins(thd, event_generic.event_class_mask);
/* Use the cached set of audit plugins */ /* Use the cached set of audit plugins */
plugins= (plugin_ref*) thd->audit_class_plugins.buffer; plugins= (plugin_ref*) thd->audit_class_plugins.buffer;
plugins_last= plugins + thd->audit_class_plugins.elements; plugins_last= plugins + thd->audit_class_plugins.elements;
......
...@@ -35,8 +35,7 @@ extern void mysql_audit_acquire_plugins(THD *thd, ulong *event_class_mask); ...@@ -35,8 +35,7 @@ extern void mysql_audit_acquire_plugins(THD *thd, ulong *event_class_mask);
#ifndef EMBEDDED_LIBRARY #ifndef EMBEDDED_LIBRARY
extern void mysql_audit_notify(THD *thd, uint event_class, extern void mysql_audit_notify(THD *thd, uint event_class, const void *event);
uint event_subtype, ...);
static inline bool mysql_audit_general_enabled() static inline bool mysql_audit_general_enabled()
{ {
...@@ -55,7 +54,7 @@ static inline bool mysql_audit_table_enabled() ...@@ -55,7 +54,7 @@ static inline bool mysql_audit_table_enabled()
#else #else
static inline void mysql_audit_notify(THD *thd, uint event_class, static inline void mysql_audit_notify(THD *thd, uint event_class,
uint event_subtype, ...) { } const void *event) {}
#define mysql_audit_general_enabled() 0 #define mysql_audit_general_enabled() 0
#define mysql_audit_connection_enabled() 0 #define mysql_audit_connection_enabled() 0
#define mysql_audit_table_enabled() 0 #define mysql_audit_table_enabled() 0
...@@ -94,15 +93,37 @@ void mysql_audit_general_log(THD *thd, time_t time, ...@@ -94,15 +93,37 @@ void mysql_audit_general_log(THD *thd, time_t time,
{ {
if (mysql_audit_general_enabled()) if (mysql_audit_general_enabled())
{ {
CHARSET_INFO *clientcs= thd ? thd->variables.character_set_client mysql_event_general event;
: global_system_variables.character_set_client;
const char *db= thd ? thd->db : ""; event.event_subclass= MYSQL_AUDIT_GENERAL_LOG;
size_t db_length= thd ? thd->db_length : 0; event.general_error_code= 0;
event.general_time= time;
mysql_audit_notify(thd, MYSQL_AUDIT_GENERAL_CLASS, MYSQL_AUDIT_GENERAL_LOG, event.general_user= user;
0, time, user, userlen, cmd, cmdlen, event.general_user_length= userlen;
query, querylen, clientcs, (ha_rows) 0, event.general_command= cmd;
db, db_length); event.general_command_length= cmdlen;
event.general_query= query;
event.general_query_length= querylen;
event.general_rows= 0;
if (thd)
{
event.general_thread_id= thd->thread_id;
event.general_charset= thd->variables.character_set_client;
event.database= thd->db;
event.database_length= thd->db_length;
event.query_id= thd->query_id;
}
else
{
event.general_thread_id= 0;
event.general_charset= global_system_variables.character_set_client;
event.database= "";
event.database_length= 0;
event.query_id= 0;
}
mysql_audit_notify(thd, MYSQL_AUDIT_GENERAL_CLASS, &event);
} }
} }
...@@ -124,38 +145,41 @@ void mysql_audit_general(THD *thd, uint event_subtype, ...@@ -124,38 +145,41 @@ void mysql_audit_general(THD *thd, uint event_subtype,
{ {
if (mysql_audit_general_enabled()) if (mysql_audit_general_enabled())
{ {
time_t time= my_time(0);
uint msglen= msg ? strlen(msg) : 0;
const char *user;
uint userlen;
char user_buff[MAX_USER_HOST_SIZE]; char user_buff[MAX_USER_HOST_SIZE];
CSET_STRING query; mysql_event_general event;
ha_rows rows;
const char *db; event.event_subclass= event_subtype;
size_t db_length; event.general_error_code= error_code;
event.general_time= my_time(0);
event.general_command= msg;
event.general_command_length= safe_strlen(msg);
if (thd) if (thd)
{ {
query= thd->query_string; event.general_user= user_buff;
user= user_buff; event.general_user_length= make_user_name(thd, user_buff);
userlen= make_user_name(thd, user_buff); event.general_thread_id= thd->thread_id;
rows= thd->get_stmt_da()->current_row_for_warning(); event.general_query= thd->query_string.str();
db= thd->db; event.general_query_length= thd->query_string.length();
db_length= thd->db_length; event.general_charset= thd->query_string.charset();
event.general_rows= thd->get_stmt_da()->current_row_for_warning();
event.database= thd->db;
event.database_length= thd->db_length;
event.query_id= thd->query_id;
} }
else else
{ {
user= 0; event.general_thread_id= 0;
userlen= 0; event.general_query= NULL;
rows= 0; event.general_query_length= 0;
db= ""; event.general_charset= &my_charset_bin;
db_length= 0; event.general_rows= 0;
event.database= "";
event.database_length= 0;
event.query_id= 0;
} }
mysql_audit_notify(thd, MYSQL_AUDIT_GENERAL_CLASS, event_subtype, mysql_audit_notify(thd, MYSQL_AUDIT_GENERAL_CLASS, &event);
error_code, time, user, userlen, msg, msglen,
query.str(), query.length(), query.charset(), rows,
db, db_length);
} }
} }
...@@ -165,19 +189,28 @@ void mysql_audit_notify_connection_connect(THD *thd) ...@@ -165,19 +189,28 @@ void mysql_audit_notify_connection_connect(THD *thd)
if (mysql_audit_connection_enabled()) if (mysql_audit_connection_enabled())
{ {
const Security_context *sctx= thd->security_ctx; const Security_context *sctx= thd->security_ctx;
Diagnostics_area *da= thd->get_stmt_da(); mysql_event_connection event;
mysql_audit_notify(thd, MYSQL_AUDIT_CONNECTION_CLASS,
MYSQL_AUDIT_CONNECTION_CONNECT, event.event_subclass= MYSQL_AUDIT_CONNECTION_CONNECT;
da->is_error() ? da->sql_errno() : 0, event.status= thd->get_stmt_da()->is_error() ?
thd->thread_id, thd->get_stmt_da()->sql_errno() : 0;
sctx->user, sctx->user ? strlen(sctx->user) : 0, event.thread_id= thd->thread_id;
sctx->priv_user, strlen(sctx->priv_user), event.user= sctx->user;
sctx->external_user, event.user_length= safe_strlen(sctx->user);
sctx->external_user ? strlen(sctx->external_user) : 0, event.priv_user= sctx->priv_user;
sctx->proxy_user, strlen(sctx->proxy_user), event.priv_user_length= strlen(sctx->priv_user);
sctx->host, sctx->host ? strlen(sctx->host) : 0, event.external_user= sctx->external_user;
sctx->ip, sctx->ip ? strlen(sctx->ip) : 0, event.external_user_length= safe_strlen(sctx->external_user);
thd->db, thd->db ? strlen(thd->db) : 0); event.proxy_user= sctx->proxy_user;
event.proxy_user_length= strlen(sctx->proxy_user);
event.host= sctx->host;
event.host_length= safe_strlen(sctx->host);
event.ip= sctx->ip;
event.ip_length= safe_strlen(sctx->ip);
event.database= thd->db;
event.database_length= safe_strlen(thd->db);
mysql_audit_notify(thd, MYSQL_AUDIT_CONNECTION_CLASS, &event);
} }
} }
...@@ -187,17 +220,27 @@ void mysql_audit_notify_connection_disconnect(THD *thd, int errcode) ...@@ -187,17 +220,27 @@ void mysql_audit_notify_connection_disconnect(THD *thd, int errcode)
if (mysql_audit_connection_enabled()) if (mysql_audit_connection_enabled())
{ {
const Security_context *sctx= thd->security_ctx; const Security_context *sctx= thd->security_ctx;
mysql_audit_notify(thd, MYSQL_AUDIT_CONNECTION_CLASS, mysql_event_connection event;
MYSQL_AUDIT_CONNECTION_DISCONNECT,
errcode, thd->thread_id, event.event_subclass= MYSQL_AUDIT_CONNECTION_DISCONNECT;
sctx->user, sctx->user ? strlen(sctx->user) : 0, event.status= errcode;
sctx->priv_user, strlen(sctx->priv_user), event.thread_id= thd->thread_id;
sctx->external_user, event.user= sctx->user;
sctx->external_user ? strlen(sctx->external_user) : 0, event.user_length= safe_strlen(sctx->user);
sctx->proxy_user, strlen(sctx->proxy_user), event.priv_user= sctx->priv_user;
sctx->host, sctx->host ? strlen(sctx->host) : 0, event.priv_user_length= strlen(sctx->priv_user);
sctx->ip, sctx->ip ? strlen(sctx->ip) : 0, event.external_user= sctx->external_user;
thd->db, thd->db ? strlen(thd->db) : 0); event.external_user_length= safe_strlen(sctx->external_user);
event.proxy_user= sctx->proxy_user;
event.proxy_user_length= strlen(sctx->proxy_user);
event.host= sctx->host;
event.host_length= safe_strlen(sctx->host);
event.ip= sctx->ip;
event.ip_length= safe_strlen(sctx->ip) ;
event.database= thd->db;
event.database_length= safe_strlen(thd->db);
mysql_audit_notify(thd, MYSQL_AUDIT_CONNECTION_CLASS, &event);
} }
} }
...@@ -207,19 +250,28 @@ void mysql_audit_notify_connection_change_user(THD *thd) ...@@ -207,19 +250,28 @@ void mysql_audit_notify_connection_change_user(THD *thd)
if (mysql_audit_connection_enabled()) if (mysql_audit_connection_enabled())
{ {
const Security_context *sctx= thd->security_ctx; const Security_context *sctx= thd->security_ctx;
Diagnostics_area *da= thd->get_stmt_da(); mysql_event_connection event;
mysql_audit_notify(thd, MYSQL_AUDIT_CONNECTION_CLASS,
MYSQL_AUDIT_CONNECTION_CHANGE_USER, event.event_subclass= MYSQL_AUDIT_CONNECTION_CHANGE_USER;
da->is_error() ? da->sql_errno() : 0, event.status= thd->get_stmt_da()->is_error() ?
thd->thread_id, thd->get_stmt_da()->sql_errno() : 0;
sctx->user, sctx->user ? strlen(sctx->user) : 0, event.thread_id= thd->thread_id;
sctx->priv_user, strlen(sctx->priv_user), event.user= sctx->user;
sctx->external_user, event.user_length= safe_strlen(sctx->user);
sctx->external_user ? strlen(sctx->external_user) : 0, event.priv_user= sctx->priv_user;
sctx->proxy_user, strlen(sctx->proxy_user), event.priv_user_length= strlen(sctx->priv_user);
sctx->host, sctx->host ? strlen(sctx->host) : 0, event.external_user= sctx->external_user;
sctx->ip, sctx->ip ? strlen(sctx->ip) : 0, event.external_user_length= safe_strlen(sctx->external_user);
thd->db, thd->db ? strlen(thd->db) : 0); event.proxy_user= sctx->proxy_user;
event.proxy_user_length= strlen(sctx->proxy_user);
event.host= sctx->host;
event.host_length= safe_strlen(sctx->host);
event.ip= sctx->ip;
event.ip_length= safe_strlen(sctx->ip);
event.database= thd->db;
event.database_length= safe_strlen(thd->db);
mysql_audit_notify(thd, MYSQL_AUDIT_CONNECTION_CLASS, &event);
} }
} }
...@@ -229,13 +281,29 @@ void mysql_audit_external_lock(THD *thd, TABLE_SHARE *share, int lock) ...@@ -229,13 +281,29 @@ void mysql_audit_external_lock(THD *thd, TABLE_SHARE *share, int lock)
if (lock != F_UNLCK && mysql_audit_table_enabled()) if (lock != F_UNLCK && mysql_audit_table_enabled())
{ {
const Security_context *sctx= thd->security_ctx; const Security_context *sctx= thd->security_ctx;
mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, MYSQL_AUDIT_TABLE_LOCK, mysql_event_table event;
(int)(lock == F_RDLCK), (ulong)thd->thread_id,
sctx->user, sctx->priv_user, sctx->priv_host, event.event_subclass= MYSQL_AUDIT_TABLE_LOCK;
sctx->external_user, sctx->proxy_user, sctx->host, event.read_only= lock == F_RDLCK;
sctx->ip, share->db.str, (uint)share->db.length, event.thread_id= thd->thread_id;
share->table_name.str, (uint)share->table_name.length, event.user= sctx->user;
0,0,0,0); event.priv_user= sctx->priv_user;
event.priv_host= sctx->priv_host;
event.external_user= sctx->external_user;
event.proxy_user= sctx->proxy_user;
event.host= sctx->host;
event.ip= sctx->ip;
event.database= share->db.str;
event.database_length= share->db.length;
event.table= share->table_name.str;
event.table_length= share->table_name.length;
event.new_database= 0;
event.new_database_length= 0;
event.new_table= 0;
event.new_table_length= 0;
event.query_id= thd->query_id;
mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, &event);
} }
} }
...@@ -247,13 +315,29 @@ void mysql_audit_create_table(TABLE *table) ...@@ -247,13 +315,29 @@ void mysql_audit_create_table(TABLE *table)
THD *thd= table->in_use; THD *thd= table->in_use;
const TABLE_SHARE *share= table->s; const TABLE_SHARE *share= table->s;
const Security_context *sctx= thd->security_ctx; const Security_context *sctx= thd->security_ctx;
mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, MYSQL_AUDIT_TABLE_CREATE, mysql_event_table event;
0, (ulong)thd->thread_id,
sctx->user, sctx->priv_user, sctx->priv_host, event.event_subclass= MYSQL_AUDIT_TABLE_CREATE;
sctx->external_user, sctx->proxy_user, sctx->host, event.read_only= 0;
sctx->ip, share->db.str, (uint)share->db.length, event.thread_id= thd->thread_id;
share->table_name.str, (uint)share->table_name.length, event.user= sctx->user;
0,0,0,0); event.priv_user= sctx->priv_user;
event.priv_host= sctx->priv_host;
event.external_user= sctx->external_user;
event.proxy_user= sctx->proxy_user;
event.host= sctx->host;
event.ip= sctx->ip;
event.database= share->db.str;
event.database_length= share->db.length;
event.table= share->table_name.str;
event.table_length= share->table_name.length;
event.new_database= 0;
event.new_database_length= 0;
event.new_table= 0;
event.new_table_length= 0;
event.query_id= thd->query_id;
mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, &event);
} }
} }
...@@ -263,13 +347,29 @@ void mysql_audit_drop_table(THD *thd, TABLE_LIST *table) ...@@ -263,13 +347,29 @@ void mysql_audit_drop_table(THD *thd, TABLE_LIST *table)
if (mysql_audit_table_enabled()) if (mysql_audit_table_enabled())
{ {
const Security_context *sctx= thd->security_ctx; const Security_context *sctx= thd->security_ctx;
mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, MYSQL_AUDIT_TABLE_DROP, mysql_event_table event;
0, (ulong)thd->thread_id,
sctx->user, sctx->priv_user, sctx->priv_host, event.event_subclass= MYSQL_AUDIT_TABLE_DROP;
sctx->external_user, sctx->proxy_user, sctx->host, event.read_only= 0;
sctx->ip, table->db, (uint)table->db_length, event.thread_id= thd->thread_id;
table->table_name, (uint)table->table_name_length, event.user= sctx->user;
0,0,0,0); event.priv_user= sctx->priv_user;
event.priv_host= sctx->priv_host;
event.external_user= sctx->external_user;
event.proxy_user= sctx->proxy_user;
event.host= sctx->host;
event.ip= sctx->ip;
event.database= table->db;
event.database_length= table->db_length;
event.table= table->table_name;
event.table_length= table->table_name_length;
event.new_database= 0;
event.new_database_length= 0;
event.new_table= 0;
event.new_table_length= 0;
event.query_id= thd->query_id;
mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, &event);
} }
} }
...@@ -280,13 +380,29 @@ void mysql_audit_rename_table(THD *thd, const char *old_db, const char *old_tb, ...@@ -280,13 +380,29 @@ void mysql_audit_rename_table(THD *thd, const char *old_db, const char *old_tb,
if (mysql_audit_table_enabled()) if (mysql_audit_table_enabled())
{ {
const Security_context *sctx= thd->security_ctx; const Security_context *sctx= thd->security_ctx;
mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, MYSQL_AUDIT_TABLE_RENAME, mysql_event_table event;
0, (ulong)thd->thread_id,
sctx->user, sctx->priv_user, sctx->priv_host, event.event_subclass= MYSQL_AUDIT_TABLE_RENAME;
sctx->external_user, sctx->proxy_user, sctx->host, event.read_only= 0;
sctx->ip, event.thread_id= thd->thread_id;
old_db, (uint)strlen(old_db), old_tb, (uint)strlen(old_tb), event.user= sctx->user;
new_db, (uint)strlen(new_db), new_tb, (uint)strlen(new_tb)); event.priv_user= sctx->priv_user;
event.priv_host= sctx->priv_host;
event.external_user= sctx->external_user;
event.proxy_user= sctx->proxy_user;
event.host= sctx->host;
event.ip= sctx->ip;
event.database= old_db;
event.database_length= strlen(old_db);
event.table= old_tb;
event.table_length= strlen(old_tb);
event.new_database= new_db;
event.new_database_length= strlen(new_db);
event.new_table= new_tb;
event.new_table_length= strlen(new_tb);
event.query_id= thd->query_id;
mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, &event);
} }
} }
...@@ -296,13 +412,29 @@ void mysql_audit_alter_table(THD *thd, TABLE_LIST *table) ...@@ -296,13 +412,29 @@ void mysql_audit_alter_table(THD *thd, TABLE_LIST *table)
if (mysql_audit_table_enabled()) if (mysql_audit_table_enabled())
{ {
const Security_context *sctx= thd->security_ctx; const Security_context *sctx= thd->security_ctx;
mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, MYSQL_AUDIT_TABLE_ALTER, mysql_event_table event;
0, (ulong)thd->thread_id,
sctx->user, sctx->priv_user, sctx->priv_host, event.event_subclass= MYSQL_AUDIT_TABLE_ALTER;
sctx->external_user, sctx->proxy_user, sctx->host, event.read_only= 0;
sctx->ip, table->db, (uint)table->db_length, event.thread_id= thd->thread_id;
table->table_name, (uint)table->table_name_length, event.user= sctx->user;
0,0,0,0); event.priv_user= sctx->priv_user;
event.priv_host= sctx->priv_host;
event.external_user= sctx->external_user;
event.proxy_user= sctx->proxy_user;
event.host= sctx->host;
event.ip= sctx->ip;
event.database= table->db;
event.database_length= table->db_length;
event.table= table->table_name;
event.table_length= table->table_name_length;
event.new_database= 0;
event.new_database_length= 0;
event.new_table= 0;
event.new_table_length= 0;
event.query_id= thd->query_id;
mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, &event);
} }
} }
......
...@@ -2152,7 +2152,8 @@ bool mysql_install_plugin(THD *thd, const LEX_STRING *name, ...@@ -2152,7 +2152,8 @@ bool mysql_install_plugin(THD *thd, const LEX_STRING *name,
*/ */
unsigned long event_class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE] = unsigned long event_class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE] =
{ MYSQL_AUDIT_GENERAL_CLASSMASK }; { MYSQL_AUDIT_GENERAL_CLASSMASK };
mysql_audit_acquire_plugins(thd, event_class_mask); if (mysql_audit_general_enabled())
mysql_audit_acquire_plugins(thd, event_class_mask);
mysql_mutex_lock(&LOCK_plugin); mysql_mutex_lock(&LOCK_plugin);
error= plugin_add(thd->mem_root, name, &dl, REPORT_TO_USER); error= plugin_add(thd->mem_root, name, &dl, REPORT_TO_USER);
...@@ -2282,7 +2283,8 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name, ...@@ -2282,7 +2283,8 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name,
*/ */
unsigned long event_class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE] = unsigned long event_class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE] =
{ MYSQL_AUDIT_GENERAL_CLASSMASK }; { MYSQL_AUDIT_GENERAL_CLASSMASK };
mysql_audit_acquire_plugins(thd, event_class_mask); if (mysql_audit_general_enabled())
mysql_audit_acquire_plugins(thd, event_class_mask);
mysql_mutex_lock(&LOCK_plugin); mysql_mutex_lock(&LOCK_plugin);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment