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

holyfoot at askmonty.org holyfoot at askmonty.org
Thu Aug 29 23:44:46 EEST 2013


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

------------------------------------------------------------
revno: 3865
revision-id: holyfoot at askmonty.org-20130829193450-8a12fypvrkkajtey
parent: holyfoot at askmonty.org-20130829092759-20pmq0wwxnmcdjta
committer: Alexey Botchkov <holyfoot at askmonty.org>
branch nick: mdev-4472
timestamp: Fri 2013-08-30 00:34:50 +0500
message:
  MDEV-4472 Audit plugin.
          additions 5
-------------- next part --------------
=== modified file 'mysql-test/suite/plugins/r/server_audit.result'
--- a/mysql-test/suite/plugins/r/server_audit.result	2013-08-25 02:52:30 +0000
+++ b/mysql-test/suite/plugins/r/server_audit.result	2013-08-29 19:34:50 +0000
@@ -68,6 +68,7 @@ server_audit_syslog_info	
 server_audit_syslog_priority    LOG_INFO
 set global server_audit_mode=1;
 set global server_audit_events='';
+create database sa_db;
 create table t1 (id2 int);
 insert into t1 values (1), (2);
 select * from t1;
@@ -75,6 +76,11 @@ id2
 1
 2
 drop table t1;
+use sa_db;
+create table sa_t1(id int);
+insert into sa_t1 values (1), (2);
+drop table sa_t1;
+drop database sa_db;
 uninstall plugin server_audit;
 Warnings:
 Warning 1620    Plugin is busy and will be uninstalled on shutdown
@@ -104,6 +110,7 @@ TIME,HOSTNAME,root,localhost,ID,ID,QUERY
 TIME,HOSTNAME,root,localhost,ID,ID,QUERY,test,'show variables like \'server_audit%\'',0
 TIME,HOSTNAME,root,localhost,ID,0,QUERY,,'set global server_audit_mode=1',0
 TIME,HOSTNAME,root,localhost,ID,0,QUERY,,'set global server_audit_events=\'\'',0
+TIME,HOSTNAME,root,localhost,ID,0,QUERY,,'create database sa_db',0
 TIME,HOSTNAME,root,localhost,ID,0,CONNECT,test,,0
 TIME,HOSTNAME,root,localhost,ID,ID,CREATE,test,t1,
 TIME,HOSTNAME,root,localhost,ID,ID,QUERY,test,'create table t1 (id2 int)',0
@@ -113,6 +120,17 @@ TIME,HOSTNAME,root,localhost,ID,ID,READ,
 TIME,HOSTNAME,root,localhost,ID,ID,QUERY,test,'select * from t1',0
 TIME,HOSTNAME,root,localhost,ID,ID,DROP,test,t1,
 TIME,HOSTNAME,root,localhost,ID,ID,QUERY,test,'drop table t1',0
+TIME,HOSTNAME,root,localhost,ID,ID,QUERY,test,'use sa_db',0
+TIME,HOSTNAME,root,localhost,ID,ID,CREATE,sa_db,sa_t1,
+TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'create table sa_t1(id int)',0
+TIME,HOSTNAME,root,localhost,ID,ID,WRITE,sa_db,sa_t1,
+TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'insert into sa_t1 values (1), (2)',0
+TIME,HOSTNAME,root,localhost,ID,ID,DROP,sa_db,sa_t1,
+TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'drop table sa_t1',0
+TIME,HOSTNAME,root,localhost,ID,ID,READ,mysql,proc,
+TIME,HOSTNAME,root,localhost,ID,ID,WRITE,mysql,proc,
+TIME,HOSTNAME,root,localhost,ID,ID,WRITE,mysql,event,
+TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'drop database sa_db',0
 TIME,HOSTNAME,root,localhost,ID,0,DISCONNECT,,,0
 TIME,HOSTNAME,root,localhost,ID,ID,WRITE,mysql,plugin,
 TIME,HOSTNAME,root,localhost,ID,0,QUERY,,'uninstall plugin server_audit',0

=== modified file 'mysql-test/suite/plugins/t/server_audit.test'
--- a/mysql-test/suite/plugins/t/server_audit.test	2013-08-22 19:42:55 +0000
+++ b/mysql-test/suite/plugins/t/server_audit.test	2013-08-29 19:34:50 +0000
@@ -40,11 +40,17 @@ drop table renamed_t1, t2;
 show variables like 'server_audit%';
 set global server_audit_mode=1;
 set global server_audit_events='';
+create database sa_db;
 connect (con1,localhost,root,,test);
 create table t1 (id2 int);
 insert into t1 values (1), (2);
 select * from t1;
 drop table t1;
+use sa_db;
+create table sa_t1(id int);
+insert into sa_t1 values (1), (2);
+drop table sa_t1;
+drop database sa_db;
 connection default;
 disconnect con1;
 

=== modified file 'plugin/server_audit/server_audit.c'
--- a/plugin/server_audit/server_audit.c	2013-08-29 09:27:59 +0000
+++ b/plugin/server_audit/server_audit.c	2013-08-29 19:34:50 +0000
@@ -453,6 +453,8 @@ static int start_logging()
       logging= 0;
       my_snprintf(last_error_buf, sizeof(last_error_buf), "Could not create file '%s'.", file_path);
       is_active= 0;
+      my_printf_error(1, "SERVER AUDIT plugin can't create file %s. Logging disabled.",
+          MYF(ME_JUST_WARNING), file_path);
       return 1;
     }
     error_header();
@@ -871,7 +873,22 @@ static void auditing(MYSQL_THD thd __att
       case MYSQL_AUDIT_GENERAL_STATUS:
         if (event->general_command_length == 5 &&
             strncmp(event->general_command, "Query", 5) == 0)
-        log_statement(event, "QUERY");
+        {
+          log_statement(event, "QUERY");
+          if (event->general_error_code == 0 && mode)
+          {
+            /* We need to check if it's the USE command to change the DB */
+            struct connection_info *cn;
+            int use_command= event->general_query_length > 4 &&
+                             strncasecmp(event->general_query, "use ", 4) == 0;
+            if (use_command && (cn= find_connection(event->general_thread_id)))
+            {
+              /* Change DB */
+              get_str_n(cn->db, &cn->db_length, sizeof(cn->db),
+                  event->general_query + 4, event->general_query_length - 4);
+            }
+          }
+        }
         break;
       default:;
     }



More information about the commits mailing list