Skip to content

Commit 3cbfe8c

Browse files
author
Alexey Botchkov
committed
MDEV-15480 Audit plugin does not respect QUERY_DML for audit plugin.
QUERY_DML_NO_SELECT flag added.
1 parent 4f42f0d commit 3cbfe8c

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

mysql-test/suite/plugins/r/server_audit.result

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,17 @@ select 2;
182182
2
183183
2
184184
drop table t1;
185+
set global server_audit_events='query_dml_no_select';
186+
create table t1(id int);
187+
insert into t1 values (1), (2);
188+
select * from t1;
189+
id
190+
1
191+
2
192+
select 2;
193+
2
194+
2
195+
drop table t1;
185196
set global server_audit_events='';
186197
set global server_audit_query_log_limit= 15;
187198
select (1), (2), (3), (4);
@@ -343,6 +354,7 @@ TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'SET PASSWORD \n# comment\nFOR u1
343354
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'SET PASSWORD FOR u1=<secret>',ID
344355
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'CREATE USER u3 IDENTIFIED BY *****',0
345356
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'drop user u1, u2, u3',0
357+
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'insert into t1 values (1), (2)',0
346358
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'set global server_audit_events=\'\'',0
347359
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'set global serv',0
348360
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'select (1), (2)',0

mysql-test/suite/plugins/t/server_audit.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ select 2;
121121
/*! select 2*/;
122122
/*comment*/ select 2;
123123
drop table t1;
124+
set global server_audit_events='query_dml_no_select';
125+
create table t1(id int);
126+
insert into t1 values (1), (2);
127+
select * from t1;
128+
select 2;
129+
drop table t1;
130+
124131
set global server_audit_events='';
125132

126133
set global server_audit_query_log_limit= 15;

plugin/server_audit/server_audit.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
#define PLUGIN_VERSION 0x104
18-
#define PLUGIN_STR_VERSION "1.4.3"
18+
#define PLUGIN_STR_VERSION "1.4.4"
1919

2020
#define _my_thread_var loc_thread_var
2121

@@ -364,24 +364,25 @@ static MYSQL_SYSVAR_STR(excl_users, excl_users, PLUGIN_VAR_RQCMDARG,
364364
/* bits in the event filter. */
365365
#define EVENT_CONNECT 1
366366
#define EVENT_QUERY_ALL 2
367-
#define EVENT_QUERY 58
367+
#define EVENT_QUERY 122
368368
#define EVENT_TABLE 4
369369
#define EVENT_QUERY_DDL 8
370370
#define EVENT_QUERY_DML 16
371371
#define EVENT_QUERY_DCL 32
372+
#define EVENT_QUERY_DML_NO_SELECT 64
372373

373374
static const char *event_names[]=
374375
{
375376
"CONNECT", "QUERY", "TABLE", "QUERY_DDL", "QUERY_DML", "QUERY_DCL",
376-
NULL
377+
"QUERY_DML_NO_SELECT", NULL
377378
};
378379
static TYPELIB events_typelib=
379380
{
380381
array_elements(event_names) - 1, "", event_names, NULL
381382
};
382383
static MYSQL_SYSVAR_SET(events, events, PLUGIN_VAR_RQCMDARG,
383384
"Specifies the set of events to monitor. Can be CONNECT, QUERY, TABLE,"
384-
" QUERY_DDL, QUERY_DML, QUERY_DCL.",
385+
" QUERY_DDL, QUERY_DML, QUERY_DML_NO_SELECT, QUERY_DCL.",
385386
NULL, NULL, 0, &events_typelib);
386387
#define OUTPUT_SYSLOG 0
387388
#define OUTPUT_FILE 1
@@ -855,6 +856,21 @@ struct sa_keyword dml_keywords[]=
855856
};
856857

857858

859+
struct sa_keyword dml_no_select_keywords[]=
860+
{
861+
{2, "DO", 0, SQLCOM_DML},
862+
{4, "CALL", 0, SQLCOM_DML},
863+
{4, "LOAD", &data_word, SQLCOM_DML},
864+
{4, "LOAD", &xml_word, SQLCOM_DML},
865+
{6, "DELETE", 0, SQLCOM_DML},
866+
{6, "INSERT", 0, SQLCOM_DML},
867+
{6, "UPDATE", 0, SQLCOM_DML},
868+
{7, "HANDLER", 0, SQLCOM_DML},
869+
{7, "REPLACE", 0, SQLCOM_DML},
870+
{0, NULL, 0, SQLCOM_DML}
871+
};
872+
873+
858874
struct sa_keyword dcl_keywords[]=
859875
{
860876
{6, "CREATE", &user_word, SQLCOM_DCL},
@@ -1636,6 +1652,11 @@ static int log_statement_ex(const struct connection_info *cn,
16361652
if (filter_query_type(query, dml_keywords))
16371653
goto do_log_query;
16381654
}
1655+
if (events & EVENT_QUERY_DML_NO_SELECT)
1656+
{
1657+
if (filter_query_type(query, dml_no_select_keywords))
1658+
goto do_log_query;
1659+
}
16391660
if (events & EVENT_QUERY_DCL)
16401661
{
16411662
if (filter_query_type(query, dcl_keywords))

0 commit comments

Comments
 (0)