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

holyfoot at askmonty.org holyfoot at askmonty.org
Mon Aug 26 13:21:30 EEST 2013


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

------------------------------------------------------------
revno: 3863
revision-id: holyfoot at askmonty.org-20130826091144-eri6jpv3alodjaj8
parent: holyfoot at askmonty.org-20130825025230-92mvx0sefpylpgxw
committer: Alexey Botchkov <holyfoot at askmonty.org>
branch nick: mdev-4472
timestamp: Mon 2013-08-26 14:11:44 +0500
message:
  MDEV-4472 Audit plugin.
          additions 3
-------------- next part --------------
=== modified file 'plugin/server_audit/server_audit.c'
--- a/plugin/server_audit/server_audit.c	2013-08-25 02:52:30 +0000
+++ b/plugin/server_audit/server_audit.c	2013-08-26 09:11:44 +0000
@@ -266,6 +266,22 @@ static struct st_mysql_sys_var* vars[] =
 };
 
 
+/* Status variables for SHOW STATUS */
+static int is_active= 0;
+static long log_write_failures= 0;
+static char current_log_buf[256]= "";
+static char last_error_buf[512]= "";
+
+static struct st_mysql_show_var audit_status[]=
+{
+  {"server_audit_active", (char *)&is_active, SHOW_BOOL},
+  {"server_audit_current_log", current_log_buf, SHOW_CHAR},
+  {"server_audit_writes_failed", (char *)&log_write_failures, SHOW_LONG},
+  {"server_audit_last_error", last_error_buf, SHOW_CHAR},
+  {0,0,0}
+};
+
+
 static uchar *getkey_user(const char *entry, size_t *length,
                           my_bool nu __attribute__((unused)) )
 {
@@ -411,6 +427,8 @@ static int get_user_host(const char *uh_
 
 static int start_logging()
 {
+  last_error_buf[0]= 0;
+  log_write_failures= 0;
   if (output_type == OUTPUT_FILE)
   {
     logfile= logger_open(file_path, file_rotate_size, rotations);
@@ -419,23 +437,29 @@ static int start_logging()
       error_header();
       fprintf(stderr, "Could not create file '%s'. Logging was disabled.\n", file_path);
       logging= 0;
+      my_snprintf(last_error_buf, sizeof(last_error_buf), "Could not create file '%s'.", file_path);
+      is_active= 0;
       return 1;
     }
     error_header();
     fprintf(stderr, "logging started to the file %s.\n", file_path);
+    my_snprintf(current_log_buf, sizeof(current_log_buf), "%s", file_path);
   }
   else if (output_type == OUTPUT_SYSLOG)
   {
     openlog(syslog_ident, LOG_NOWAIT, syslog_facility_codes[syslog_facility]);
     error_header();
     fprintf(stderr, "logging started to the syslog.\n");
+    my_snprintf(current_log_buf, sizeof(current_log_buf), "[SYSLOG]");
   }
+  is_active= 1;
   return 0;
 }
 
 
 static int stop_logging()
 {
+  last_error_buf[0]= 0;
   if (output_type == OUTPUT_FILE && logfile)
   {
     logger_close(logfile);
@@ -446,6 +470,7 @@ static int stop_logging()
   }
   error_header();
   fprintf(stderr, "logging was stopped.\n");
+  is_active= 0;
   return 0;
 }
 
@@ -513,9 +538,11 @@ static int write_log(const char *message
 {
   if (output_type == OUTPUT_FILE)
   {
-    if (!logfile)
-      return 1;
-    return logger_write(logfile, message, len) != len;
+    if (logfile &&
+        (is_active= (logger_write(logfile, message, len) == len)))
+      return 0;
+    ++log_write_failures;
+    return 1;
   }
   else if (output_type == OUTPUT_SYSLOG)
   {
@@ -994,7 +1021,7 @@ mysql_declare_plugin(server_audit)
   server_audit_init_mysql,
   server_audit_deinit,
   0x0200,
-  NULL,
+  audit_status,
   vars,
   NULL,
   0
@@ -1022,7 +1049,7 @@ maria_declare_plugin(server_audit)
   server_audit_init,
   server_audit_deinit,
   0x0200,
-  NULL,
+  audit_status,
   vars,
   "2.0",
   MariaDB_PLUGIN_MATURITY_ALPHA



More information about the commits mailing list