summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorAlexey Botchkov <holyfoot@askmonty.org>2013-09-09 16:56:35 +0500
committerAlexey Botchkov <holyfoot@askmonty.org>2013-09-09 16:56:35 +0500
commit92265da9d77bc750eb234cfac9d6239675078983 (patch)
treef6ca280d04ecfdbeaf2a773f654d002231f2002f /sql
parent1e24cdc85be16d08bb079979ab5131e311542b80 (diff)
downloadmariadb-git-92265da9d77bc750eb234cfac9d6239675078983.tar.gz
MDEV-4472 Audit-plugin. Server-related part of the task.
file_logger became the service. Data like query_id now are sent to the audit plugin. Fix for MDEV-4770 ported from 10.0. Fix added for the read_maria_plugin_info(). Log rotation can be disabled with 'set rotations=0'.
Diffstat (limited to 'sql')
-rw-r--r--sql/mysqld.cc1
-rw-r--r--sql/mysqld.h1
-rw-r--r--sql/sql_audit.cc4
-rw-r--r--sql/sql_audit.h12
-rw-r--r--sql/sql_plugin.cc13
-rw-r--r--sql/sql_plugin_services.h13
6 files changed, 35 insertions, 9 deletions
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index e79106bca2d..c78ffcbcd14 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -593,7 +593,6 @@ key_map key_map_full(0); // Will be initialized later
DATE_TIME_FORMAT global_date_format, global_datetime_format, global_time_format;
Time_zone *default_tz;
-char *mysql_data_home= const_cast<char*>(".");
const char *mysql_real_data_home_ptr= mysql_real_data_home;
char server_version[SERVER_VERSION_LENGTH];
char *mysqld_unix_port, *opt_mysql_tmpdir;
diff --git a/sql/mysqld.h b/sql/mysqld.h
index 293c20ade55..7834968200d 100644
--- a/sql/mysqld.h
+++ b/sql/mysqld.h
@@ -314,7 +314,6 @@ extern uint mysql_data_home_len;
extern uint mysql_real_data_home_len;
extern const char *mysql_real_data_home_ptr;
extern ulong thread_handling;
-extern MYSQL_PLUGIN_IMPORT char *mysql_data_home;
extern "C" MYSQL_PLUGIN_IMPORT char server_version[SERVER_VERSION_LENGTH];
extern MYSQL_PLUGIN_IMPORT char mysql_real_data_home[];
extern char mysql_unpacked_real_data_home[];
diff --git a/sql/sql_audit.cc b/sql/sql_audit.cc
index 8e17f49df28..abf448fdac4 100644
--- a/sql/sql_audit.cc
+++ b/sql/sql_audit.cc
@@ -82,6 +82,9 @@ 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.database= va_arg(ap, const char *);
+ event.database_length= va_arg(ap, unsigned int);
+ event.query_id= (unsigned long long) thd->query_id;
event_class_dispatch(thd, MYSQL_AUDIT_GENERAL_CLASS, &event);
}
@@ -131,6 +134,7 @@ static void table_class_handler(THD *thd, uint event_subclass, va_list ap)
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->query_id;
event_class_dispatch(thd, MYSQL_AUDIT_TABLE_CLASS, &event);
}
diff --git a/sql/sql_audit.h b/sql/sql_audit.h
index 75b338a16c8..2e932a53d07 100644
--- a/sql/sql_audit.h
+++ b/sql/sql_audit.h
@@ -93,7 +93,8 @@ void mysql_audit_general_log(THD *thd, time_t time,
mysql_audit_notify(thd, MYSQL_AUDIT_GENERAL_CLASS, MYSQL_AUDIT_GENERAL_LOG,
0, time, user, userlen, cmd, cmdlen,
- query, querylen, clientcs, 0);
+ query, querylen, clientcs, (ha_rows) 0,
+ thd->db, thd->db_length);
}
}
@@ -139,7 +140,8 @@ void mysql_audit_general(THD *thd, uint event_subtype,
mysql_audit_notify(thd, MYSQL_AUDIT_GENERAL_CLASS, event_subtype,
error_code, time, user, userlen, msg, msglen,
- query.str(), query.length(), query.charset(), rows);
+ query.str(), query.length(), query.charset(), rows,
+ thd->db, thd->db_length);
}
}
@@ -162,7 +164,11 @@ void mysql_audit_general(THD *thd, uint event_subtype,
#define MYSQL_AUDIT_NOTIFY_CONNECTION_DISCONNECT(thd, errcode)\
mysql_audit_notify(\
(thd), MYSQL_AUDIT_CONNECTION_CLASS, MYSQL_AUDIT_CONNECTION_DISCONNECT,\
- (errcode), (thd)->thread_id, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
+ (errcode), (thd)->thread_id, (thd)->security_ctx->user,\
+ (thd)->security_ctx->user ? strlen((thd)->security_ctx->user) : 0,\
+ 0, 0, 0, 0, 0, 0, (thd)->security_ctx->host,\
+ (thd)->security_ctx->host ? strlen((thd)->security_ctx->host) : 0,\
+ 0, 0, 0, 0)
#define MYSQL_AUDIT_NOTIFY_CONNECTION_CHANGE_USER(thd) mysql_audit_notify(\
(thd), MYSQL_AUDIT_CONNECTION_CLASS, MYSQL_AUDIT_CONNECTION_CHANGE_USER,\
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index ee0b1ac0c4b..c3d201c2cca 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -702,6 +702,8 @@ static my_bool read_maria_plugin_info(struct st_plugin_dl *plugin_dl,
sym= cur;
plugin_dl->allocated= true;
}
+ else
+ sym= ptr;
}
plugin_dl->plugins= (struct st_maria_plugin *)sym;
@@ -2661,13 +2663,18 @@ static void update_func_longlong(THD *thd, struct st_mysql_sys_var *var,
static void update_func_str(THD *thd, struct st_mysql_sys_var *var,
void *tgt, const void *save)
{
- char *old= *(char **) tgt;
- *(char **)tgt= *(char **) save;
+ char *value= *(char**) save;
if (var->flags & PLUGIN_VAR_MEMALLOC)
{
- *(char **)tgt= my_strdup(*(char **) save, MYF(0));
+ char *old= *(char**) tgt;
+ if (value)
+ *(char**) tgt= my_strdup(value, MYF(0));
+ else
+ *(char**) tgt= 0;
my_free(old);
}
+ else
+ *(char**) tgt= value;
}
static void update_func_double(THD *thd, struct st_mysql_sys_var *var,
diff --git a/sql/sql_plugin_services.h b/sql/sql_plugin_services.h
index e3ef338eaad..ede8d9a675e 100644
--- a/sql/sql_plugin_services.h
+++ b/sql/sql_plugin_services.h
@@ -58,6 +58,16 @@ static struct kill_statement_service_st thd_kill_statement_handler= {
thd_kill_level
};
+static struct logger_service_st logger_service_handler= {
+ logger_init_mutexes,
+ logger_open,
+ logger_close,
+ logger_vprintf,
+ logger_printf,
+ logger_write,
+ logger_rotate
+};
+
static struct st_service_ref list_of_services[]=
{
{ "my_snprintf_service", VERSION_my_snprintf, &my_snprintf_handler },
@@ -66,6 +76,7 @@ static struct st_service_ref list_of_services[]=
{ "my_thread_scheduler_service", VERSION_my_thread_scheduler, &my_thread_scheduler_handler },
{ "progress_report_service", VERSION_progress_report, &progress_report_handler },
{ "debug_sync_service", VERSION_debug_sync, 0 }, // updated in plugin_init()
- { "thd_kill_statement_service", VERSION_kill_statement, &thd_kill_statement_handler }
+ { "thd_kill_statement_service", VERSION_kill_statement, &thd_kill_statement_handler },
+ { "logger_service", VERSION_logger, &logger_service_handler },
};