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

holyfoot at askmonty.org holyfoot at askmonty.org
Thu Aug 8 14:10:16 EEST 2013


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

------------------------------------------------------------
revno: 3845
revision-id: holyfoot at askmonty.org-20130808100040-j1wbvtl604zyduer
parent: holyfoot at askmonty.org-20130808092118-lf1byka9klj1flhi
committer: Alexey Botchkov <holyfoot at askmonty.org>
branch nick: mdev-4472
timestamp: Thu 2013-08-08 15:00:40 +0500
message:
  MDEV-4472 Audit plugin.
          additions 3.
-------------- next part --------------
=== modified file 'mysql-test/suite/plugins/r/server_audit.result'
--- a/mysql-test/suite/plugins/r/server_audit.result	2013-07-24 15:41:04 +0000
+++ b/mysql-test/suite/plugins/r/server_audit.result	2013-08-08 10:00:40 +0000
@@ -7,12 +7,14 @@ server_audit_file_path	
 server_audit_file_rotate_size   1000000
 server_audit_incl_users 
 server_audit_logging    OFF
-server_audit_mode_mysql OFF
+server_audit_mode       0
 server_audit_output_type        null
 server_audit_rotate     OFF
 server_audit_rotations  9
+server_audit_syslog_facility    LOG_USER
 server_audit_syslog_ident       mysql-server_auditing
 server_audit_syslog_info        
+server_audit_syslog_priority    LOG_INFO
 set global server_audit_file_path='server_audit.log';
 set global server_audit_output_type=file;
 set global server_audit_logging=on;
@@ -55,13 +57,15 @@ server_audit_file_path	server_audit.log
 server_audit_file_rotate_size   1000000
 server_audit_incl_users odin, root, dva, tri
 server_audit_logging    ON
-server_audit_mode_mysql OFF
+server_audit_mode       0
 server_audit_output_type        file
 server_audit_rotate     OFF
 server_audit_rotations  9
+server_audit_syslog_facility    LOG_USER
 server_audit_syslog_ident       mysql-server_auditing
 server_audit_syslog_info        
-set global server_audit_mode_mysql=on;
+server_audit_syslog_priority    LOG_INFO
+set global server_audit_mode=1;
 set global server_audit_events='';
 create table t1 (id2 int);
 insert into t1 values (1), (2);
@@ -79,12 +83,12 @@ TIME,HOSTNAME,root,localhost,ID,0,DISCON
 TIME,HOSTNAME,no_such_user,localhost,ID,0,FAILED_CONNECT,,,ID
 TIME,HOSTNAME,no_such_user,localhost,ID,0,DISCONNECT,,,0
 TIME,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_incl_users=\'odin, root, dva, tri\'',0
-TIME,HOSTNAME,root,localhost,ID,ID,CREATE,test,t2
+TIME,HOSTNAME,root,localhost,ID,ID,CREATE,test,t2,
 TIME,HOSTNAME,root,localhost,ID,ID,QUERY,test,'create table t2 (id int)',0
 TIME,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_incl_users=\'odin, root, dva, tri\'',0
-TIME,HOSTNAME,root,localhost,ID,ID,WRITE,test,t2
+TIME,HOSTNAME,root,localhost,ID,ID,WRITE,test,t2,
 TIME,HOSTNAME,root,localhost,ID,ID,QUERY,test,'insert into t2 values (1), (2)',0
-TIME,HOSTNAME,root,localhost,ID,ID,READ,test,t2
+TIME,HOSTNAME,root,localhost,ID,ID,READ,test,t2,
 TIME,HOSTNAME,root,localhost,ID,ID,QUERY,test,'select * from t2',0
 TIME,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_events=\'connect,query\'',0
 TIME,HOSTNAME,root,localhost,ID,ID,QUERY,test,'insert into t2 values (1), (2)',0
@@ -93,17 +97,17 @@ TIME,HOSTNAME,root,localhost,ID,ID,QUERY
 TIME,HOSTNAME,root,localhost,ID,ID,QUERY,test,'syntax_error_query',ID
 TIME,HOSTNAME,root,localhost,ID,ID,QUERY,test,'drop table t1, t2',0
 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_mysql=on',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,CONNECT,test,,0
-TIME,HOSTNAME,root,localhost,ID,ID,CREATE,test,t1
+TIME,HOSTNAME,root,localhost,ID,ID,CREATE,test,t1,
 TIME,HOSTNAME,root,localhost,ID,ID,QUERY,test,'create table t1 (id2 int)',0
-TIME,HOSTNAME,root,localhost,ID,ID,WRITE,test,t1
+TIME,HOSTNAME,root,localhost,ID,ID,WRITE,test,t1,
 TIME,HOSTNAME,root,localhost,ID,ID,QUERY,test,'insert into t1 values (1), (2)',0
-TIME,HOSTNAME,root,localhost,ID,ID,READ,test,t1
+TIME,HOSTNAME,root,localhost,ID,ID,READ,test,t1,
 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,DROP,test,t1,
 TIME,HOSTNAME,root,localhost,ID,ID,QUERY,test,'drop table t1',0
 TIME,HOSTNAME,root,localhost,ID,0,DISCONNECT,,,0
-TIME,HOSTNAME,root,localhost,ID,ID,WRITE,mysql,plugin
+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-07-24 15:41:04 +0000
+++ b/mysql-test/suite/plugins/t/server_audit.test	2013-08-08 10:00:40 +0000
@@ -37,7 +37,7 @@ select * from t_doesnt_exist;
 syntax_error_query;
 drop table t1, t2;
 show variables like 'server_audit%';
-set global server_audit_mode_mysql=on;
+set global server_audit_mode=1;
 set global server_audit_events='';
 connect (con1,localhost,root,,test);
 create table t1 (id2 int);

=== modified file 'plugin/server_audit/server_audit.c'
--- a/plugin/server_audit/server_audit.c	2013-08-08 09:21:18 +0000
+++ b/plugin/server_audit/server_audit.c	2013-08-08 10:00:40 +0000
@@ -64,10 +64,10 @@ static void closelog() {}
 
 extern char server_version[];
 static const char *serv_ver= NULL;
-static char mode_mysql;
 static int started_mysql= 0;
 static char *incl_users, *excl_users,
             *file_path, *syslog_info;
+static unsigned int mode, mode_readonly= 0;
 static ulong output_type= 0;
 static ulong syslog_facility, syslog_priority;
 
@@ -93,10 +93,10 @@ static void update_syslog_facility(MYSQL
                                    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_mode(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,
@@ -153,9 +153,8 @@ static MYSQL_SYSVAR_BOOL(rotate, rotate,
 static MYSQL_SYSVAR_BOOL(logging, logging,
        PLUGIN_VAR_OPCMDARG, "Turn on/off the logging.", NULL,
        update_logging, 0);
-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_UINT(mode, mode,
+       PLUGIN_VAR_OPCMDARG, "Auditing mode.", NULL, update_mode, 0, 0, 1, 1);
 static MYSQL_SYSVAR_STR(syslog_ident, syslog_ident, PLUGIN_VAR_RQCMDARG,
        "The SYSLOG identifier - the beginning of each SYSLOG record.",
        NULL, update_syslog_ident, syslog_ident_buffer);
@@ -224,7 +223,7 @@ static struct st_mysql_sys_var* vars[] =
     MYSQL_SYSVAR(rotations),
     MYSQL_SYSVAR(rotate),
     MYSQL_SYSVAR(logging),
-    MYSQL_SYSVAR(mode_mysql),
+    MYSQL_SYSVAR(mode),
     MYSQL_SYSVAR(syslog_info),
     MYSQL_SYSVAR(syslog_ident),
     MYSQL_SYSVAR(syslog_facility),
@@ -579,7 +578,7 @@ static int log_statement(const struct my
   unsigned int db_length;
   long long query_id= 0;
 
-  if (mode_mysql)
+  if (mode)
   {
     const struct connection_info *cn=
       find_connection(event->general_thread_id);
@@ -640,7 +639,7 @@ static int log_table(const struct mysql_
   time_t ctime;
   long long query_id= event->query_id;
 
-  if (mode_mysql)
+  if (mode)
   {
     const struct connection_info *cn;
     if ((cn= find_connection(event->thread_id)))
@@ -668,7 +667,7 @@ static int log_rename(const struct mysql
   time_t ctime;
   long long query_id= event->query_id;
 
-  if (mode_mysql)
+  if (mode)
   {
     const struct connection_info *cn;
     if ((cn= find_connection(event->thread_id)))
@@ -706,7 +705,7 @@ static void auditing(MYSQL_THD thd __att
     switch (event->event_subclass)
     {
       case MYSQL_AUDIT_GENERAL_LOG:
-        if (mode_mysql)
+        if (mode)
         {
           struct connection_info *cn;
           int init_db_command= event->general_command_length == 7 &&
@@ -773,12 +772,12 @@ static void auditing(MYSQL_THD thd __att
     switch (event->event_subclass)
     {
       case MYSQL_AUDIT_CONNECTION_CONNECT:
-        if (mode_mysql)
+        if (mode)
           (void) add_connection(ev);
         log_connection(event, event->status ? "FAILED_CONNECT": "CONNECT");
         break;
       case MYSQL_AUDIT_CONNECTION_DISCONNECT:
-        if (mode_mysql)
+        if (mode)
         {
           struct connection_info *cn= find_connection(event->thread_id);
           if (cn)
@@ -794,7 +793,7 @@ static void auditing(MYSQL_THD thd __att
           log_connection(event, "DISCONNECT");
         break;
       case MYSQL_AUDIT_CONNECTION_CHANGE_USER:
-        if (mode_mysql)
+        if (mode)
           change_connection(ev);
         log_connection(event, "CHANGEUSER");
         break;
@@ -816,8 +815,8 @@ static int server_audit_init(void *p __a
   {
     if (serv_ver[5]<'3')
     {
-      mode_mysql= 1;
-      mysql_sysvar_mode_mysql.flags|= PLUGIN_VAR_READONLY;
+      mode= 1;
+      mode_readonly= 1;
     }
   }
 
@@ -868,8 +867,8 @@ static int server_audit_init(void *p __a
 static int server_audit_init_mysql(void *p)
 {
   started_mysql= 1;
-  mode_mysql= 1;
-  mysql_sysvar_mode_mysql.flags|= PLUGIN_VAR_READONLY;
+  mode= 1;
+  mode_readonly= 1;
   return server_audit_init(p);
 }
 
@@ -1067,17 +1066,17 @@ static void update_logging(MYSQL_THD thd
 }
 
 
-static void update_mysqlmode(MYSQL_THD thd  __attribute__((unused)),
+static void update_mode(MYSQL_THD thd  __attribute__((unused)),
               struct st_mysql_sys_var *var  __attribute__((unused)),
               void *var_ptr  __attribute__((unused)), const void *save)
 {
-  char new_mode= *(char *) save;
-  if (new_mode == mode_mysql)
+  unsigned int new_mode= *(unsigned int *) save;
+  if (mode_readonly || new_mode == mode)
     return;
 
-  mode_mysql= new_mode;
   error_header();
-  fprintf(stderr, "MYSQL logging mode was %s.\n", mode_mysql ? "enabled" : "disabled");
+  fprintf(stderr, "Logging mode was changed from %d to %d.\n", mode, new_mode);
+  mode= new_mode;
 }
 
 static void update_syslog_ident(MYSQL_THD thd  __attribute__((unused)),



More information about the commits mailing list