summaryrefslogtreecommitdiff
path: root/sql/sql_audit.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_audit.cc')
-rw-r--r--sql/sql_audit.cc55
1 files changed, 45 insertions, 10 deletions
diff --git a/sql/sql_audit.cc b/sql/sql_audit.cc
index 3f5c96ef9ff..be837ec51ba 100644
--- a/sql/sql_audit.cc
+++ b/sql/sql_audit.cc
@@ -21,11 +21,18 @@ extern int finalize_audit_plugin(st_plugin_int *plugin);
#ifndef EMBEDDED_LIBRARY
+struct st_mysql_event_generic
+{
+ unsigned int event_class;
+ const void *event;
+};
+
unsigned long mysql_global_audit_mask[MYSQL_AUDIT_CLASS_MASK_SIZE];
static mysql_mutex_t LOCK_audit_mask;
-static void event_class_dispatch(THD *thd, const struct mysql_event *event);
+static void event_class_dispatch(THD *thd, unsigned int event_class,
+ const void *event);
static inline
@@ -64,7 +71,6 @@ typedef void (*audit_handler_t)(THD *thd, uint event_subtype, va_list ap);
static void general_class_handler(THD *thd, uint event_subtype, va_list ap)
{
mysql_event_general event;
- event.event_class= MYSQL_AUDIT_GENERAL_CLASS;
event.event_subclass= event_subtype;
event.general_error_code= va_arg(ap, int);
event.general_thread_id= thd ? thd->thread_id : 0;
@@ -77,13 +83,37 @@ static void general_class_handler(THD *thd, uint event_subtype, va_list ap)
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_class_dispatch(thd, (const mysql_event*) &event);
+ 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= va_arg(ap, unsigned 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 audit_handler_t audit_handlers[] =
{
- general_class_handler
+ general_class_handler, connection_class_handler
};
static const uint audit_handlers_count=
@@ -408,18 +438,19 @@ int finalize_audit_plugin(st_plugin_int *plugin)
static my_bool plugins_dispatch(THD *thd, plugin_ref plugin, void *arg)
{
- const struct mysql_event *event= (const struct mysql_event *) 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->event_class);
+ 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 */
- data->event_notify(thd, event);
+ data->event_notify(thd, event_generic->event_class, event_generic->event);
return 0;
}
@@ -432,15 +463,19 @@ static my_bool plugins_dispatch(THD *thd, plugin_ref plugin, void *arg)
@param[in] event
*/
-static void event_class_dispatch(THD *thd, const struct mysql_event *event)
+static void event_class_dispatch(THD *thd, unsigned int event_class,
+ const void *event)
{
+ struct st_mysql_event_generic event_generic;
+ event_generic.event_class= event_class;
+ event_generic.event= event;
/*
Check if we are doing a slow global dispatch. This event occurs when
thd == NULL as it is not associated with any particular thread.
*/
if (unlikely(!thd))
{
- plugin_foreach(thd, plugins_dispatch, MYSQL_AUDIT_PLUGIN, (void*) event);
+ plugin_foreach(thd, plugins_dispatch, MYSQL_AUDIT_PLUGIN, &event_generic);
}
else
{
@@ -451,7 +486,7 @@ static void event_class_dispatch(THD *thd, const struct mysql_event *event)
plugins_last= plugins + thd->audit_class_plugins.elements;
for (; plugins < plugins_last; plugins++)
- plugins_dispatch(thd, *plugins, (void*) event);
+ plugins_dispatch(thd, *plugins, &event_generic);
}
}