[Commits] Rev 3844: MDEV-4472 Audit plugin. in file:///home/hf/wmar/mdev-4472/

holyfoot at askmonty.org holyfoot at askmonty.org
Thu Aug 8 13:30:45 EEST 2013


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

------------------------------------------------------------
revno: 3844
revision-id: holyfoot at askmonty.org-20130808092118-lf1byka9klj1flhi
parent: holyfoot at askmonty.org-20130724201025-t4z1gyo6wt4wr6cq
committer: Alexey Botchkov <holyfoot at askmonty.org>
branch nick: mdev-4472
timestamp: Thu 2013-08-08 14:21:18 +0500
message:
  MDEV-4472 Audit plugin.
          additions 2
-------------- next part --------------
=== modified file 'mysys/file_logger.c'
--- a/mysys/file_logger.c	2013-07-24 15:41:04 +0000
+++ b/mysys/file_logger.c	2013-08-08 09:21:18 +0000
@@ -19,7 +19,9 @@
 #include <mysql/service_logger.h>
 #include <my_pthread.h>
 
+#ifndef _WIN32
 extern MYSQL_PLUGIN_IMPORT char  *mysql_data_home;
+#endif /*!_WIN32*/
 
 #ifdef HAVE_PSI_INTERFACE
 /* These belong to the service initialization */
@@ -51,6 +53,12 @@ LOGGER_HANDLE *logger_open(const char *p
                            unsigned int rotations)
 {
   LOGGER_HANDLE new_log, *l_perm;
+  char *local_mysql_data_home;
+#ifdef _WIN32
+  local_mysql_data_home= (char *)GetProcAddress(0, "mysql_data_home");
+#else
+  local_mysql_data_home= mysql_data_home;
+#endif /*_WIN32*/
 
   /*
     I don't think we ever need more rotations,
@@ -62,7 +70,7 @@ LOGGER_HANDLE *logger_open(const char *p
   new_log.rotations= rotations;
   new_log.size_limit= size_limit;
   new_log.path_len= strlen(fn_format(new_log.path, path,
-        mysql_data_home, "", MY_UNPACK_FILENAME));
+        local_mysql_data_home, "", MY_UNPACK_FILENAME));
 
   if (new_log.path_len+n_dig(rotations)+1 > FN_REFLEN)
   {

=== modified file 'plugin/server_audit/server_audit.c'
--- a/plugin/server_audit/server_audit.c	2013-07-24 20:10:25 +0000
+++ b/plugin/server_audit/server_audit.c	2013-08-08 09:21:18 +0000
@@ -16,7 +16,14 @@
 #include <stdio.h>
 #include <time.h>
 #include <string.h>
+
+#ifndef _WIN32
 #include <syslog.h>
+#else
+#define syslog(PRIORITY, FORMAT, INFO, MESSAGE_LEN, MESSAGE) do {}while(0)
+static void closelog() {}
+#define openlog(IDENT, LOG_NOWAIT, LOG_USER)  do {}while(0)
+#endif /*!_WIN32*/
 
 /*
    Defines that can be used to reshape the pluging:
@@ -62,6 +69,7 @@ static int started_mysql= 0;
 static char *incl_users, *excl_users,
             *file_path, *syslog_info;
 static ulong output_type= 0;
+static ulong syslog_facility, syslog_priority;
 
 static ulonglong events; /* mask for events to log */
 static unsigned long long file_rotate_size;
@@ -73,6 +81,7 @@ static char user_buffer[1024];
 static char servhost[256];
 static size_t servhost_len;
 static char *syslog_ident;
+static char syslog_ident_buffer[128]= "mysql-server_auditing";
 
 static void update_incl_users(MYSQL_THD thd, struct st_mysql_sys_var *var,
                               void *var_ptr, const void *save);
@@ -80,10 +89,16 @@ static void update_excl_users(MYSQL_THD 
                               void *var_ptr, const void *save);
 static void update_output_type(MYSQL_THD thd, struct st_mysql_sys_var *var,
                                void *var_ptr, const void *save);
+static void update_syslog_facility(MYSQL_THD thd, struct st_mysql_sys_var *var,
+                                   void *var_ptr, const void *save);
+static void update_syslog_priority(MYSQL_THD thd, struct st_mysql_sys_var *var,
+                                   void *var_ptr, const void *save);
 static void update_logging(MYSQL_THD thd, struct st_mysql_sys_var *var,
                            void *var_ptr, const void *save);
 static void update_mysqlmode(MYSQL_THD thd, struct st_mysql_sys_var *var,
                              void *var_ptr, const void *save);
+static void update_syslog_ident(MYSQL_THD thd, struct st_mysql_sys_var *var,
+                                void *var_ptr, const void *save);
 static void rotate_log(MYSQL_THD thd, struct st_mysql_sys_var *var,
                        void *var_ptr, const void *save);
 
@@ -112,8 +127,8 @@ static MYSQL_SYSVAR_SET(events, events, 
 #define OUTPUT_NULL 0
 #define OUTPUT_SYSLOG 1
 #define OUTPUT_FILE 2
-const char *output_type_names[]= { "null", "syslog", "file", 0 };
-TYPELIB output_typelib=
+static const char *output_type_names[]= { "null", "syslog", "file", 0 };
+static TYPELIB output_typelib=
 {
     array_elements(output_type_names) - 1, "output_typelib",
     output_type_names, NULL
@@ -141,14 +156,64 @@ static MYSQL_SYSVAR_BOOL(logging, loggin
 static MYSQL_SYSVAR_BOOL(mode_mysql, mode_mysql,
        PLUGIN_VAR_OPCMDARG, "Turn on/off the MySQL-compatible mode.", NULL,
        update_mysqlmode, 0);
-static MYSQL_SYSVAR_STR(syslog_ident, syslog_ident,
-       PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC,
+static MYSQL_SYSVAR_STR(syslog_ident, syslog_ident, PLUGIN_VAR_RQCMDARG,
        "The SYSLOG identifier - the beginning of each SYSLOG record.",
-       NULL, NULL, "mysql-server_auditing");
+       NULL, update_syslog_ident, syslog_ident_buffer);
 static MYSQL_SYSVAR_STR(syslog_info, syslog_info,
        PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC,
        "The <info> string to be added to the SYSLOG record.", NULL, NULL, "");
 
+static const char *syslog_facility_names[]=
+{
+  "LOG_USER", "LOG_MAIL", "LOG_DAEMON", "LOG_AUTH",
+  "LOG_SYSLOG", "LOG_LPR", "LOG_NEWS", "LOG_UUCP",
+  "LOG_CRON", "LOG_AUTHPRIV", "LOG_FTP",
+  "LOG_LOCAL0", "LOG_LOCAL1", "LOG_LOCAL2", "LOG_LOCAL3",
+  "LOG_LOCAL4", "LOG_LOCAL5", "LOG_LOCAL6", "LOG_LOCAL7",
+  0
+};
+static unsigned int syslog_facility_codes[]=
+{
+  LOG_USER, LOG_MAIL, LOG_DAEMON, LOG_AUTH,
+  LOG_SYSLOG, LOG_LPR, LOG_NEWS, LOG_UUCP,
+  LOG_CRON, LOG_AUTHPRIV, LOG_FTP,
+  LOG_LOCAL0, LOG_LOCAL1, LOG_LOCAL2, LOG_LOCAL3,
+  LOG_LOCAL4, LOG_LOCAL5, LOG_LOCAL6, LOG_LOCAL7,
+};
+static TYPELIB syslog_facility_typelib=
+{
+    array_elements(syslog_facility_names) - 1, "syslog_facility_typelib",
+    syslog_facility_names, NULL
+};
+static MYSQL_SYSVAR_ENUM(syslog_facility, syslog_facility, PLUGIN_VAR_RQCMDARG,
+       "The 'facility' parameter of the SYSLOG record."
+       " The default is LOG_USER.", 0, update_syslog_facility, 0/*LOG_USER*/,
+       &syslog_facility_typelib);
+
+static const char *syslog_priority_names[]=
+{
+  "LOG_EMERG", "LOG_ALERT", "LOG_CRIT", "LOG_ERR",
+  "LOG_WARNING", "LOG_NOTICE", "LOG_INFO", "LOG_DEBUG",
+  0
+};
+
+static unsigned int syslog_priority_codes[]=
+{
+  LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR,
+  LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG,
+};
+
+static TYPELIB syslog_priority_typelib=
+{
+    array_elements(syslog_priority_names) - 1, "syslog_priority_typelib",
+    syslog_priority_names, NULL
+};
+static MYSQL_SYSVAR_ENUM(syslog_priority, syslog_priority, PLUGIN_VAR_RQCMDARG,
+       "The 'priority' parameter of the SYSLOG record."
+       " The default is LOG_INFO.", 0, update_syslog_priority, 6/*LOG_INFO*/,
+       &syslog_priority_typelib);
+
+
 static struct st_mysql_sys_var* vars[] = {
     MYSQL_SYSVAR(incl_users),
     MYSQL_SYSVAR(excl_users),
@@ -162,6 +227,8 @@ static struct st_mysql_sys_var* vars[] =
     MYSQL_SYSVAR(mode_mysql),
     MYSQL_SYSVAR(syslog_info),
     MYSQL_SYSVAR(syslog_ident),
+    MYSQL_SYSVAR(syslog_facility),
+    MYSQL_SYSVAR(syslog_priority),
     NULL
 };
 
@@ -376,7 +443,9 @@ static int write_log(const char *message
   }
   else if (output_type == OUTPUT_SYSLOG)
   {
-    syslog(0, "%s %.*s", syslog_info, len, message);
+    syslog(LOG_MAKEPRI(syslog_facility_codes[syslog_facility],
+                       syslog_priority_codes[syslog_priority]),
+           "%s %.*s", syslog_info, len, message);
   }
   return 0;
 }
@@ -387,14 +456,14 @@ static size_t log_header(char *message, 
                       const char *serverhost, unsigned int serverhost_len,
                       const char *username, unsigned int username_len,
                       const char *host, unsigned int hostlen,
-                      unsigned int connection_id, unsigned int query_id,
+                      unsigned int connection_id, long long query_id,
                       const char *operation)
 {
   struct tm tm_time;
 
   if (output_type == OUTPUT_SYSLOG)
     return my_snprintf(message, message_len,
-        "%.*s,%.*s,%.*s,%d,%d,%s",
+        "%.*s,%.*s,%.*s,%d,%lld,%s",
         serverhost_len, serverhost,
         username_len, username,
         hostlen, host,
@@ -402,7 +471,7 @@ static size_t log_header(char *message, 
 
   (void) localtime_r(ts, &tm_time);
   return my_snprintf(message, message_len,
-      "%04d%02d%02d %02d:%02d:%02d,%.*s,%.*s,%.*s,%d,%d,%s",
+      "%04d%02d%02d %02d:%02d:%02d,%.*s,%.*s,%.*s,%d,%lld,%s",
       tm_time.tm_year+1900, tm_time.tm_mon+1, tm_time.tm_mday,
       tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec,
       serverhost_len, serverhost,
@@ -585,8 +654,8 @@ static int log_table(const struct mysql_
                     event->host, strlen(event->host),
                     event->thread_id, query_id, type);
   csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize,
-            ",%.*s,%.*s",event->database_length, event->database,
-                         event->table_length, event->table);
+            ",%.*s,%.*s,",event->database_length, event->database,
+                          event->table_length, event->table);
   message[csize]= '\n';
   return write_log(message, csize + 1);
 }
@@ -738,7 +807,7 @@ static void auditing(MYSQL_THD thd __att
 static int server_audit_init(void *p __attribute__((unused)))
 {
 #ifdef _WIN32
-  serv_ver= (const char *)GetProcAddress(current_module, "server_version");
+  serv_ver= (const char *)GetProcAddress(0, "server_version");
 #else
   serv_ver= server_version;
 #endif /*_WIN32*/
@@ -942,7 +1011,7 @@ static void update_output_type(MYSQL_THD
   }
   else if (new_output_type == OUTPUT_SYSLOG)
   {
-    openlog(syslog_ident, LOG_NOWAIT, LOG_USER);
+    openlog(syslog_ident, LOG_NOWAIT, syslog_facility_codes[syslog_facility]);
   }
 
   output_type= new_output_type;
@@ -952,6 +1021,38 @@ static void update_output_type(MYSQL_THD
 }
 
 
+static void update_syslog_facility(MYSQL_THD thd  __attribute__((unused)),
+              struct st_mysql_sys_var *var  __attribute__((unused)),
+              void *var_ptr  __attribute__((unused)), const void *save)
+{
+  ulong new_facility= *((ulong *) save);
+  if (syslog_facility == new_facility)
+    return;
+
+  error_header();
+  fprintf(stderr, "SysLog facility was changed from '%s' to '%s'.\n",
+          syslog_facility_names[syslog_facility],
+          syslog_facility_names[new_facility]);
+  syslog_facility= new_facility;
+}
+
+
+static void update_syslog_priority(MYSQL_THD thd  __attribute__((unused)),
+              struct st_mysql_sys_var *var  __attribute__((unused)),
+              void *var_ptr  __attribute__((unused)), const void *save)
+{
+  ulong new_priority= *((ulong *) save);
+  if (syslog_priority == new_priority)
+    return;
+
+  error_header();
+  fprintf(stderr, "SysLog priority was changed from '%s' to '%s'.\n",
+          syslog_priority_names[syslog_priority],
+          syslog_priority_names[new_priority]);
+  syslog_priority= new_priority;
+}
+
+
 static void update_logging(MYSQL_THD thd  __attribute__((unused)),
               struct st_mysql_sys_var *var  __attribute__((unused)),
               void *var_ptr  __attribute__((unused)), const void *save)
@@ -979,3 +1080,13 @@ static void update_mysqlmode(MYSQL_THD t
   fprintf(stderr, "MYSQL logging mode was %s.\n", mode_mysql ? "enabled" : "disabled");
 }
 
+static void update_syslog_ident(MYSQL_THD thd  __attribute__((unused)),
+              struct st_mysql_sys_var *var  __attribute__((unused)),
+              void *var_ptr  __attribute__((unused)), const void *save)
+{
+  strncpy(syslog_ident_buffer, *(const char **) save,
+          sizeof(syslog_ident_buffer));
+  syslog_ident= syslog_ident_buffer;
+}
+
+



More information about the commits mailing list