summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorSergey Vojtovich <svoj@sun.com>2009-12-15 23:52:47 +0400
committerSergey Vojtovich <svoj@sun.com>2009-12-15 23:52:47 +0400
commit45f2e0a7aad762af94eedd70b6fc0b91ae8e3376 (patch)
tree124275c3f1ec273b11d8f4b9c3952eef78477a02 /plugin
parent376cf4275f28f6b8167eaf19b2c66dee41fbc5c5 (diff)
downloadmariadb-git-45f2e0a7aad762af94eedd70b6fc0b91ae8e3376.tar.gz
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
Diffstat (limited to 'plugin')
-rw-r--r--plugin/audit_null/Makefile.am32
-rw-r--r--plugin/audit_null/audit_null.c130
-rw-r--r--plugin/audit_null/plug.in4
3 files changed, 166 insertions, 0 deletions
diff --git a/plugin/audit_null/Makefile.am b/plugin/audit_null/Makefile.am
new file mode 100644
index 00000000000..d57a72f8c18
--- /dev/null
+++ b/plugin/audit_null/Makefile.am
@@ -0,0 +1,32 @@
+# Copyright (C) 2007 MySQL AB
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+#Makefile.am example for a plugin
+
+pkgplugindir= $(pkglibdir)/plugin
+
+AM_CPPFLAGS = -I$(top_srcdir)/include
+
+EXTRA_LTLIBRARIES= adt_null.la
+pkgplugin_LTLIBRARIES= @plugin_audit_null_shared_target@
+adt_null_la_LDFLAGS= -module -rpath $(pkgplugindir)
+adt_null_la_CPPFLAGS= $(AM_CPPFLAGS) -DMYSQL_DYNAMIC_PLUGIN
+adt_null_la_SOURCES= audit_null.c
+
+EXTRA_LIBRARIES= libadtnull.a
+noinst_LIBRARIES= @plugin_audit_null_static_target@
+libadtnull_a_SOURCES= audit_null.c
+
+EXTRA_DIST= plug.in
diff --git a/plugin/audit_null/audit_null.c b/plugin/audit_null/audit_null.c
new file mode 100644
index 00000000000..52a9df08cf4
--- /dev/null
+++ b/plugin/audit_null/audit_null.c
@@ -0,0 +1,130 @@
+/* Copyright (C) 2006-2007 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+
+#include <stdio.h>
+#include <mysql/plugin.h>
+#include <mysql/plugin_audit.h>
+
+#if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8)
+#define __attribute__(A)
+#endif
+
+static volatile int number_of_calls; /* for SHOW STATUS, see below */
+
+
+/*
+ Initialize the plugin at server start or plugin installation.
+
+ SYNOPSIS
+ audit_null_plugin_init()
+
+ DESCRIPTION
+ Does nothing.
+
+ RETURN VALUE
+ 0 success
+ 1 failure (cannot happen)
+*/
+
+static int audit_null_plugin_init(void *arg __attribute__((unused)))
+{
+ number_of_calls= 0;
+ return(0);
+}
+
+
+/*
+ Terminate the plugin at server shutdown or plugin deinstallation.
+
+ SYNOPSIS
+ audit_null_plugin_deinit()
+ Does nothing.
+
+ RETURN VALUE
+ 0 success
+ 1 failure (cannot happen)
+
+*/
+
+static int audit_null_plugin_deinit(void *arg __attribute__((unused)))
+{
+ printf("audit_null was invoked %u times\n", number_of_calls);
+ return(0);
+}
+
+
+/*
+ Foo
+
+ SYNOPSIS
+ audit_null_notify()
+ thd connection context
+
+ DESCRIPTION
+*/
+
+static void audit_null_notify(MYSQL_THD thd __attribute__((unused)),
+ const struct mysql_event *event
+ __attribute__((unused)))
+{
+ /* prone to races, oh well */
+ number_of_calls++;
+}
+
+
+/*
+ Plugin type-specific descriptor
+*/
+
+static struct st_mysql_audit audit_null_descriptor=
+{
+ MYSQL_AUDIT_INTERFACE_VERSION, /* interface version */
+ NULL, /* release_thd function */
+ audit_null_notify, /* notify function */
+ { (unsigned long) -1 } /* class mask */
+};
+
+/*
+ Plugin status variables for SHOW STATUS
+*/
+
+static struct st_mysql_show_var simple_status[]=
+{
+ {"audit_null_called", (char *)&number_of_calls, SHOW_INT},
+ {0,0,0}
+};
+
+
+/*
+ Plugin library descriptor
+*/
+
+mysql_declare_plugin(audit_null)
+{
+ MYSQL_AUDIT_PLUGIN, /* type */
+ &audit_null_descriptor, /* descriptor */
+ "NULL_AUDIT", /* name */
+ "MySQL AB", /* author */
+ "Simple NULL Audit", /* description */
+ PLUGIN_LICENSE_GPL,
+ audit_null_plugin_init, /* init function (when loaded) */
+ audit_null_plugin_deinit, /* deinit function (when unloaded) */
+ 0x0001, /* version */
+ simple_status, /* status variables */
+ NULL, /* system variables */
+ NULL
+}
+mysql_declare_plugin_end;
+
diff --git a/plugin/audit_null/plug.in b/plugin/audit_null/plug.in
new file mode 100644
index 00000000000..15b1a48b408
--- /dev/null
+++ b/plugin/audit_null/plug.in
@@ -0,0 +1,4 @@
+MYSQL_PLUGIN(audit_null, [NULL Audit Plug-in],
+ [Simple black-hole Audit example plug-in])
+MYSQL_PLUGIN_DYNAMIC(audit_null, [adt_null.la])
+MYSQL_PLUGIN_STATIC(audit_null, [libadtnull.a])