[Commits] Rev 4226: MDEV-6369 Audit Plugin 1.1.7 not starting for *MySQL* 5.5. in file:///home/hf/wmar/mdev-6369/

holyfoot at askmonty.org holyfoot at askmonty.org
Wed Jul 9 09:45:52 EEST 2014


At file:///home/hf/wmar/mdev-6369/

------------------------------------------------------------
revno: 4226
revision-id: holyfoot at askmonty.org-20140709042648-0bbewysbu6gxlec8
parent: jplindst at mariadb.org-20140708142113-cb6uo46lnef2mr7v
committer: Alexey Botchkov <holyfoot at askmonty.org>
branch nick: mdev-6369
timestamp: Wed 2014-07-09 09:26:48 +0500
message:
  MDEV-6369 Audit Plugin 1.1.7 not starting for *MySQL* 5.5.
    Fix for the MySQL on Windows.
    The problem with the 'mysql_data_home' variable. It's declared
    as 'C++' call in MySQL so cannot be automatically linked.
    Changed so it's linked dynamically in the server_init().
  
    Fix for the ver below 5.5.14.
    The interface version is beeing adapted to in the library-init procedure.
-------------- next part --------------
=== modified file 'plugin/server_audit/server_audit.c'
--- a/plugin/server_audit/server_audit.c	2014-04-16 21:12:08 +0000
+++ b/plugin/server_audit/server_audit.c	2014-07-09 04:26:48 +0000
@@ -15,7 +15,7 @@
 
 
 #define PLUGIN_VERSION 0x101
-#define PLUGIN_STR_VERSION "1.1.7"
+#define PLUGIN_STR_VERSION "1.1.8"
 
 #include <stdio.h>
 #include <time.h>
@@ -140,6 +140,10 @@ static int my_strnncoll_binary(CHARSET_I
 #define flogger_mutex_lock(A) pthread_mutex_lock(&(A)->m_mutex)
 #define flogger_mutex_unlock(A) pthread_mutex_unlock(&(A)->m_mutex)
 
+static char **int_mysql_data_home;
+static char *default_home= (char *)".";
+#define mysql_data_home (*int_mysql_data_home)
+
 #include "../../mysys/file_logger.c"
 #endif /*!MARIADB_ONLY*/
 
@@ -163,6 +167,7 @@ static int my_strnncoll_binary(CHARSET_I
 extern char server_version[];
 static const char *serv_ver= NULL;
 static int started_mysql= 0;
+static int started_mariadb= 0;
 static int maria_above_5= 0;
 static char *incl_users, *excl_users,
             *file_path, *syslog_info;
@@ -1384,6 +1389,70 @@ static void auditing(MYSQL_THD thd __att
 }
 
 
+#ifdef DBUG_OFF
+  #ifdef __x86_64__
+static const int cmd_off= 4200;
+static const int db_off= 120;
+static const int db_len_off= 128;
+  #else
+static const int cmd_off= 2668;
+static const int db_off= 60;
+static const int db_len_off= 64;
+  #endif /*x86_64*/
+#else
+  #ifdef __x86_64__
+static const int cmd_off= 4432;
+static const int db_off= 120;
+static const int db_len_off= 128;
+  #else
+static const int cmd_off= 2808;
+static const int db_off= 64;
+static const int db_len_off= 68;
+  #endif /*x86_64*/
+#endif /*DBUG_OFF*/
+
+static void auditing_v8(MYSQL_THD thd, unsigned int *ev_v0)
+{
+  struct mysql_event_general event= *(const struct mysql_event_general *) (ev_v0+1);
+
+  if (event.general_query_length > 0)
+  {
+    event.event_subclass= MYSQL_AUDIT_GENERAL_STATUS;
+    event.general_command= "Query";
+    event.general_command_length= 5;
+#ifdef __linux__
+    event.database= *(char **) (((char *) thd) + db_off);
+    event.database_length= *(size_t *) (((char *) thd) + db_len_off);
+#endif /*__linux*/
+  }
+#ifdef __linux__
+  else if (*((int *) (((char *)thd) + cmd_off)) == 2)
+  {
+    event.event_subclass= MYSQL_AUDIT_GENERAL_LOG;
+    event.general_command= "Init DB";
+    event.general_command_length= 7;
+    event.general_query= *(char **) (((char *) thd) + db_off);
+    event.general_query_length= *(size_t *) (((char *) thd) + db_len_off);
+  }
+#endif /*__linux*/
+  auditing(thd, ev_v0[0], &event);
+}
+
+
+static void auditing_v13(MYSQL_THD thd, unsigned int *ev_v0)
+{
+  struct mysql_event_general event= *(const struct mysql_event_general *) (ev_v0+1);
+
+  if (event.general_query_length > 0)
+  {
+    event.event_subclass= MYSQL_AUDIT_GENERAL_STATUS;
+    event.general_command= "Query";
+    event.general_command_length= 5;
+  }
+  auditing(thd, ev_v0[0], &event);
+}
+
+
 /*
    As it's just too difficult to #include "sql_class.h",
    let's just copy the necessary part of the system_variables
@@ -1462,12 +1532,15 @@ typedef struct loc_system_variables
 static int server_audit_init(void *p __attribute__((unused)))
 {
   const void *my_hash_init_ptr;
+
+  if (!serv_ver)
+  {
 #ifdef _WIN32
-  serv_ver= (const char *) GetProcAddress(0, "server_version");
+    serv_ver= (const char *) GetProcAddress(0, "server_version");
 #else
-  serv_ver= server_version;
+    serv_ver= server_version;
 #endif /*_WIN32*/
-
+  }
   my_hash_init_ptr= dlsym(RTLD_DEFAULT, "_my_hash_init");
   if (!my_hash_init_ptr)
   {
@@ -1475,8 +1548,14 @@ static int server_audit_init(void *p __a
     my_hash_init_ptr= dlsym(RTLD_DEFAULT, "my_hash_init2");
   }
 
+  if(!(int_mysql_data_home= dlsym(RTLD_DEFAULT, "mysql_data_home")))
+  {
+    if(!(int_mysql_data_home= dlsym(RTLD_DEFAULT, "?mysql_data_home@@3PADA")))
+      int_mysql_data_home= &default_home;
+  }
+
   if (!serv_ver || !my_hash_init_ptr)
-    return 0;
+    return 1;
 
   if (!started_mysql)
   {
@@ -1913,3 +1991,48 @@ static void update_syslog_ident(MYSQL_TH
 }
 
 
+#ifdef _WIN32
+BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
+{
+  if (fdwReason != DLL_PROCESS_ATTACH)
+    return 1;
+
+  serv_ver= (const char *) GetProcAddress(0, "server_version");
+#else
+void __attribute__ ((constructor)) audit_plugin_so_init(void)
+{
+  serv_ver= server_version;
+#endif /*_WIN32*/
+
+  if (!serv_ver)
+    goto exit;
+
+  started_mariadb= strstr(serv_ver, "MariaDB") != 0;
+
+  if (!started_mariadb)
+  {
+    if (serv_ver[0] == '5' && serv_ver[2] == '5')
+    {
+      int sc= serv_ver[4] - '0';
+      if (serv_ver[5] >= '0' && serv_ver[5] <= '9')
+        sc= sc * 10 + serv_ver[5] - '0';
+      if (sc <= 10)
+      {
+        mysql_descriptor.interface_version= 0x0200;
+        mysql_descriptor.event_notify= (void *) auditing_v8;
+      }
+      else if (sc < 14)
+      {
+        mysql_descriptor.interface_version= 0x0200;
+        mysql_descriptor.event_notify= (void *) auditing_v13;
+      }
+    }
+  }
+exit:
+#ifdef _WIN32
+  return 1;
+#else
+  return;
+#endif
+}
+



More information about the commits mailing list