1
0
mirror of https://github.com/MariaDB/server.git synced 2026-01-06 05:22:24 +03:00

Backport from 6.0-codebase.

WL#3771
  "Audit Plugin Interface"
  Implement new plug-in type - AUDIT
  New plug-in: audit_null
    simply increments counter for how many times it was called.

include/Makefile.am:
  wl3771
    add new headers to distribution
include/mysql/plugin.h:
  wl3771
    define new AUDIT plugin type
    Split out fulltext plugin type into its own header
include/mysql/plugin.h.pp:
  wl3771
    no real API change, just re-arranged some code
include/mysql/plugin_audit.h:
  wl3771
    pluggable audit interface
include/mysql/plugin_ftparser.h:
  wl3771
    Split out fulltext plugin type into its own header
libmysqld/CMakeLists.txt:
  wl3771
    add sql_audit.cc to build
libmysqld/Makefile.am:
  wl3771
    add sql_audit.cc to build
plugin/audit_null:
  wl3771
    an example plugin for testing pluggable audit interface
plugin/audit_null/Makefile.am:
  wl3771
    an example plugin for testing pluggable audit interface
plugin/audit_null/audit_null.c:
  wl3771
    an example plugin for testing pluggable audit interface
plugin/audit_null/plug.in:
  wl3771
    an example plugin for testing pluggable audit interface
sql/CMakeLists.txt:
  wl3771
    add sql_audit.cc to build
sql/Makefile.am:
  wl3771
    add sql_audit.cc to build
sql/event_queue.cc:
  wl3771
    release audit resources before waiting
sql/log.cc:
  wl3771
    add general audit call for log
sql/mysqld.cc:
  wl3771
    add audit initialize/finalize
    add general audit call for error
sql/sql_audit.cc:
  wl3771
    pluggable audit interface implementation
sql/sql_audit.h:
  wl3771
    pluggable audit interface implementation
sql/sql_class.cc:
  wl3771
    add thd audit init/deinit calls
sql/sql_class.h:
  wl3771
    add required data structures for audit to THD
sql/sql_connect.cc:
  wl3771
    release audit resources before waiting
sql/sql_insert.cc:
  wl3771
    release audit plugins before waiting
sql/sql_parse.cc:
  wl3771
    add general audit call for results
sql/sql_plugin.cc:
  wl3771
    add declarations for audit plugin type
This commit is contained in:
Sergey Vojtovich
2009-12-15 23:52:47 +04:00
parent 376cf4275f
commit 45f2e0a7aa
23 changed files with 1133 additions and 237 deletions

View File

@@ -16,6 +16,7 @@
#include "mysql_priv.h"
#include <my_pthread.h>
#include <my_getopt.h>
#include <mysql/plugin_audit.h>
#define REPORT_TO_LOG 1
#define REPORT_TO_USER 2
@@ -47,12 +48,16 @@ const LEX_STRING plugin_type_names[MYSQL_MAX_PLUGIN_TYPE_NUM]=
{ C_STRING_WITH_LEN("FTPARSER") },
{ C_STRING_WITH_LEN("DAEMON") },
{ C_STRING_WITH_LEN("INFORMATION SCHEMA") },
{ C_STRING_WITH_LEN("AUDIT") },
{ C_STRING_WITH_LEN("REPLICATION") },
};
extern int initialize_schema_table(st_plugin_int *plugin);
extern int finalize_schema_table(st_plugin_int *plugin);
extern int initialize_audit_plugin(st_plugin_int *plugin);
extern int finalize_audit_plugin(st_plugin_int *plugin);
/*
The number of elements in both plugin_type_initialize and
plugin_type_deinitialize should equal to the number of plugins
@@ -60,12 +65,14 @@ extern int finalize_schema_table(st_plugin_int *plugin);
*/
plugin_type_init plugin_type_initialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
{
0,ha_initialize_handlerton,0,0,initialize_schema_table
0,ha_initialize_handlerton,0,0,initialize_schema_table,
initialize_audit_plugin
};
plugin_type_init plugin_type_deinitialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
{
0,ha_finalize_handlerton,0,0,finalize_schema_table
0,ha_finalize_handlerton,0,0,finalize_schema_table,
finalize_audit_plugin
};
#ifdef HAVE_DLOPEN
@@ -87,6 +94,7 @@ static int min_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
MYSQL_FTPARSER_INTERFACE_VERSION,
MYSQL_DAEMON_INTERFACE_VERSION,
MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION,
MYSQL_AUDIT_INTERFACE_VERSION,
MYSQL_REPLICATION_INTERFACE_VERSION,
};
static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
@@ -96,6 +104,7 @@ static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
MYSQL_FTPARSER_INTERFACE_VERSION,
MYSQL_DAEMON_INTERFACE_VERSION,
MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION,
MYSQL_AUDIT_INTERFACE_VERSION,
MYSQL_REPLICATION_INTERFACE_VERSION,
};
@@ -1341,26 +1350,22 @@ end:
*/
static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv)
{
THD thd;
TABLE_LIST tables;
TABLE *table;
READ_RECORD read_record_info;
int error;
THD *new_thd;
THD *new_thd= &thd;
#ifdef EMBEDDED_LIBRARY
bool table_exists;
#endif /* EMBEDDED_LIBRARY */
DBUG_ENTER("plugin_load");
if (!(new_thd= new THD))
{
sql_print_error("Can't allocate memory for plugin structures");
delete new_thd;
DBUG_VOID_RETURN;
}
new_thd->thread_stack= (char*) &tables;
new_thd->store_globals();
new_thd->db= my_strdup("mysql", MYF(0));
new_thd->db_length= 5;
bzero((char*) &thd.net, sizeof(thd.net));
bzero((uchar*)&tables, sizeof(tables));
tables.alias= tables.table_name= (char*)"plugin";
tables.lock_type= TL_READ;
@@ -1418,7 +1423,6 @@ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv)
new_thd->version--; // Force close to free memory
end:
close_thread_tables(new_thd);
delete new_thd;
/* Remember that we don't have a THD */
my_pthread_setspecific_ptr(THR_THD, 0);
DBUG_VOID_RETURN;