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
unsigned int general_command_length;
const char *general_query;
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_rows;
/* Added in version 0x302 */
......
......@@ -422,7 +422,7 @@ struct mysql_event_general
unsigned int general_command_length;
const char *general_query;
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_rows;
unsigned long long query_id;
......
......@@ -24,6 +24,7 @@ extern int finalize_audit_plugin(st_plugin_int *plugin);
struct st_mysql_event_generic
{
unsigned long event_class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE];
unsigned int event_class;
const void *event;
};
......@@ -32,8 +33,6 @@ unsigned long mysql_global_audit_mask[MYSQL_AUDIT_CLASS_MASK_SIZE];
static mysql_mutex_t LOCK_audit_mask;
static void event_class_dispatch(THD *, unsigned int, const void *);
static inline
void set_audit_mask(unsigned long *mask, uint event_class)
......@@ -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
......@@ -207,8 +111,10 @@ static my_bool acquire_plugins(THD *thd, plugin_ref plugin, void *arg)
void mysql_audit_acquire_plugins(THD *thd, ulong *event_class_mask)
{
DBUG_ENTER("mysql_audit_acquire_plugins");
if (thd && !check_audit_mask(mysql_global_audit_mask, event_class_mask) &&
check_audit_mask(thd->audit_class_mask, event_class_mask))
DBUG_ASSERT(thd);
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);
add_audit_mask(thd->audit_class_mask, event_class_mask);
......@@ -217,30 +123,6 @@ void mysql_audit_acquire_plugins(THD *thd, ulong *event_class_mask)
}
/**
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);
}
/**
Release any resources associated with the current thd.
......@@ -496,16 +378,10 @@ 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 *) arg;
unsigned long event_class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE];
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 */
if (check_audit_mask(data->class_mask, event_class_mask))
return 0;
/* Actually notify the plugin */
if (!check_audit_mask(data->class_mask, event_generic->event_class_mask))
data->event_notify(thd, event_generic->event_class, event_generic->event);
return 0;
......@@ -516,15 +392,16 @@ static my_bool plugins_dispatch(THD *thd, plugin_ref plugin, void *arg)
Distributes an audit event to plug-ins
@param[in] thd
@param[in] event_class
@param[in] event
*/
static void event_class_dispatch(THD *thd, unsigned int event_class,
const void *event)
void mysql_audit_notify(THD *thd, uint event_class, const void *event)
{
struct st_mysql_event_generic event_generic;
event_generic.event_class= event_class;
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
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,
{
plugin_ref *plugins, *plugins_last;
mysql_audit_acquire_plugins(thd, event_generic.event_class_mask);
/* Use the cached set of audit plugins */
plugins= (plugin_ref*) thd->audit_class_plugins.buffer;
plugins_last= plugins + thd->audit_class_plugins.elements;
......
......@@ -35,8 +35,7 @@ extern void mysql_audit_acquire_plugins(THD *thd, ulong *event_class_mask);
#ifndef EMBEDDED_LIBRARY
extern void mysql_audit_notify(THD *thd, uint event_class,
uint event_subtype, ...);
extern void mysql_audit_notify(THD *thd, uint event_class, const void *event);
static inline bool mysql_audit_general_enabled()
{
......@@ -55,7 +54,7 @@ static inline bool mysql_audit_table_enabled()
#else
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_connection_enabled() 0
#define mysql_audit_table_enabled() 0
......@@ -94,15 +93,37 @@ void mysql_audit_general_log(THD *thd, time_t time,
{
if (mysql_audit_general_enabled())
{
CHARSET_INFO *clientcs= thd ? thd->variables.character_set_client
: global_system_variables.character_set_client;
const char *db= thd ? thd->db : "";
size_t db_length= thd ? thd->db_length : 0;
mysql_audit_notify(thd, MYSQL_AUDIT_GENERAL_CLASS, MYSQL_AUDIT_GENERAL_LOG,
0, time, user, userlen, cmd, cmdlen,
query, querylen, clientcs, (ha_rows) 0,
db, db_length);
mysql_event_general event;
event.event_subclass= MYSQL_AUDIT_GENERAL_LOG;
event.general_error_code= 0;
event.general_time= time;
event.general_user= user;
event.general_user_length= userlen;
event.general_command= cmd;
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,
{
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];
CSET_STRING query;
ha_rows rows;
const char *db;
size_t db_length;
mysql_event_general event;
event.event_subclass= event_subtype;
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)
{
query= thd->query_string;
user= user_buff;
userlen= make_user_name(thd, user_buff);
rows= thd->get_stmt_da()->current_row_for_warning();
db= thd->db;
db_length= thd->db_length;
event.general_user= user_buff;
event.general_user_length= make_user_name(thd, user_buff);
event.general_thread_id= thd->thread_id;
event.general_query= thd->query_string.str();
event.general_query_length= thd->query_string.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
{
user= 0;
userlen= 0;
rows= 0;
db= "";
db_length= 0;
event.general_thread_id= 0;
event.general_query= NULL;
event.general_query_length= 0;
event.general_charset= &my_charset_bin;
event.general_rows= 0;
event.database= "";
event.database_length= 0;
event.query_id= 0;
}
mysql_audit_notify(thd, MYSQL_AUDIT_GENERAL_CLASS, event_subtype,
error_code, time, user, userlen, msg, msglen,
query.str(), query.length(), query.charset(), rows,
db, db_length);
mysql_audit_notify(thd, MYSQL_AUDIT_GENERAL_CLASS, &event);
}
}
......@@ -165,19 +189,28 @@ void mysql_audit_notify_connection_connect(THD *thd)
if (mysql_audit_connection_enabled())
{
const Security_context *sctx= thd->security_ctx;
Diagnostics_area *da= thd->get_stmt_da();
mysql_audit_notify(thd, MYSQL_AUDIT_CONNECTION_CLASS,
MYSQL_AUDIT_CONNECTION_CONNECT,
da->is_error() ? da->sql_errno() : 0,
thd->thread_id,
sctx->user, sctx->user ? strlen(sctx->user) : 0,
sctx->priv_user, strlen(sctx->priv_user),
sctx->external_user,
sctx->external_user ? strlen(sctx->external_user) : 0,
sctx->proxy_user, strlen(sctx->proxy_user),
sctx->host, sctx->host ? strlen(sctx->host) : 0,
sctx->ip, sctx->ip ? strlen(sctx->ip) : 0,
thd->db, thd->db ? strlen(thd->db) : 0);
mysql_event_connection event;
event.event_subclass= MYSQL_AUDIT_CONNECTION_CONNECT;
event.status= thd->get_stmt_da()->is_error() ?
thd->get_stmt_da()->sql_errno() : 0;
event.thread_id= thd->thread_id;
event.user= sctx->user;
event.user_length= safe_strlen(sctx->user);
event.priv_user= sctx->priv_user;
event.priv_user_length= strlen(sctx->priv_user);
event.external_user= sctx->external_user;
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);
}
}
......@@ -187,17 +220,27 @@ void mysql_audit_notify_connection_disconnect(THD *thd, int errcode)
if (mysql_audit_connection_enabled())
{
const Security_context *sctx= thd->security_ctx;
mysql_audit_notify(thd, MYSQL_AUDIT_CONNECTION_CLASS,
MYSQL_AUDIT_CONNECTION_DISCONNECT,
errcode, thd->thread_id,
sctx->user, sctx->user ? strlen(sctx->user) : 0,
sctx->priv_user, strlen(sctx->priv_user),
sctx->external_user,
sctx->external_user ? strlen(sctx->external_user) : 0,
sctx->proxy_user, strlen(sctx->proxy_user),
sctx->host, sctx->host ? strlen(sctx->host) : 0,
sctx->ip, sctx->ip ? strlen(sctx->ip) : 0,
thd->db, thd->db ? strlen(thd->db) : 0);
mysql_event_connection event;
event.event_subclass= MYSQL_AUDIT_CONNECTION_DISCONNECT;
event.status= errcode;
event.thread_id= thd->thread_id;
event.user= sctx->user;
event.user_length= safe_strlen(sctx->user);
event.priv_user= sctx->priv_user;
event.priv_user_length= strlen(sctx->priv_user);
event.external_user= sctx->external_user;
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)
if (mysql_audit_connection_enabled())
{
const Security_context *sctx= thd->security_ctx;
Diagnostics_area *da= thd->get_stmt_da();
mysql_audit_notify(thd, MYSQL_AUDIT_CONNECTION_CLASS,
MYSQL_AUDIT_CONNECTION_CHANGE_USER,
da->is_error() ? da->sql_errno() : 0,
thd->thread_id,
sctx->user, sctx->user ? strlen(sctx->user) : 0,
sctx->priv_user, strlen(sctx->priv_user),
sctx->external_user,
sctx->external_user ? strlen(sctx->external_user) : 0,
sctx->proxy_user, strlen(sctx->proxy_user),
sctx->host, sctx->host ? strlen(sctx->host) : 0,
sctx->ip, sctx->ip ? strlen(sctx->ip) : 0,
thd->db, thd->db ? strlen(thd->db) : 0);
mysql_event_connection event;
event.event_subclass= MYSQL_AUDIT_CONNECTION_CHANGE_USER;
event.status= thd->get_stmt_da()->is_error() ?
thd->get_stmt_da()->sql_errno() : 0;
event.thread_id= thd->thread_id;
event.user= sctx->user;
event.user_length= safe_strlen(sctx->user);
event.priv_user= sctx->priv_user;
event.priv_user_length= strlen(sctx->priv_user);
event.external_user= sctx->external_user;
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);
}
}
......@@ -229,13 +281,29 @@ void mysql_audit_external_lock(THD *thd, TABLE_SHARE *share, int lock)
if (lock != F_UNLCK && mysql_audit_table_enabled())
{
const Security_context *sctx= thd->security_ctx;
mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, MYSQL_AUDIT_TABLE_LOCK,
(int)(lock == F_RDLCK), (ulong)thd->thread_id,
sctx->user, sctx->priv_user, sctx->priv_host,
sctx->external_user, sctx->proxy_user, sctx->host,
sctx->ip, share->db.str, (uint)share->db.length,
share->table_name.str, (uint)share->table_name.length,
0,0,0,0);
mysql_event_table event;
event.event_subclass= MYSQL_AUDIT_TABLE_LOCK;
event.read_only= lock == F_RDLCK;
event.thread_id= thd->thread_id;
event.user= sctx->user;
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)
THD *thd= table->in_use;
const TABLE_SHARE *share= table->s;
const Security_context *sctx= thd->security_ctx;
mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, MYSQL_AUDIT_TABLE_CREATE,
0, (ulong)thd->thread_id,
sctx->user, sctx->priv_user, sctx->priv_host,
sctx->external_user, sctx->proxy_user, sctx->host,
sctx->ip, share->db.str, (uint)share->db.length,
share->table_name.str, (uint)share->table_name.length,
0,0,0,0);
mysql_event_table event;
event.event_subclass= MYSQL_AUDIT_TABLE_CREATE;
event.read_only= 0;
event.thread_id= thd->thread_id;
event.user= sctx->user;
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)
if (mysql_audit_table_enabled())
{
const Security_context *sctx= thd->security_ctx;
mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, MYSQL_AUDIT_TABLE_DROP,
0, (ulong)thd->thread_id,
sctx->user, sctx->priv_user, sctx->priv_host,
sctx->external_user, sctx->proxy_user, sctx->host,
sctx->ip, table->db, (uint)table->db_length,
table->table_name, (uint)table->table_name_length,
0,0,0,0);
mysql_event_table event;
event.event_subclass= MYSQL_AUDIT_TABLE_DROP;
event.read_only= 0;
event.thread_id= thd->thread_id;
event.user= sctx->user;
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,
if (mysql_audit_table_enabled())
{
const Security_context *sctx= thd->security_ctx;
mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, MYSQL_AUDIT_TABLE_RENAME,
0, (ulong)thd->thread_id,
sctx->user, sctx->priv_user, sctx->priv_host,
sctx->external_user, sctx->proxy_user, sctx->host,
sctx->ip,
old_db, (uint)strlen(old_db), old_tb, (uint)strlen(old_tb),
new_db, (uint)strlen(new_db), new_tb, (uint)strlen(new_tb));
mysql_event_table event;
event.event_subclass= MYSQL_AUDIT_TABLE_RENAME;
event.read_only= 0;
event.thread_id= thd->thread_id;
event.user= sctx->user;
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)
if (mysql_audit_table_enabled())
{
const Security_context *sctx= thd->security_ctx;
mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, MYSQL_AUDIT_TABLE_ALTER,
0, (ulong)thd->thread_id,
sctx->user, sctx->priv_user, sctx->priv_host,
sctx->external_user, sctx->proxy_user, sctx->host,
sctx->ip, table->db, (uint)table->db_length,
table->table_name, (uint)table->table_name_length,
0,0,0,0);
mysql_event_table event;
event.event_subclass= MYSQL_AUDIT_TABLE_ALTER;
event.read_only= 0;
event.thread_id= thd->thread_id;
event.user= sctx->user;
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,6 +2152,7 @@ bool mysql_install_plugin(THD *thd, const LEX_STRING *name,
*/
unsigned long event_class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE] =
{ MYSQL_AUDIT_GENERAL_CLASSMASK };
if (mysql_audit_general_enabled())
mysql_audit_acquire_plugins(thd, event_class_mask);
mysql_mutex_lock(&LOCK_plugin);
......@@ -2282,6 +2283,7 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name,
*/
unsigned long event_class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE] =
{ MYSQL_AUDIT_GENERAL_CLASSMASK };
if (mysql_audit_general_enabled())
mysql_audit_acquire_plugins(thd, event_class_mask);
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