1
#ifndef SQL_AUDIT_INCLUDED
2
#define SQL_AUDIT_INCLUDED
4
/* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
1
/* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
6
3
This program is free software; you can redistribute it and/or modify
7
4
it under the terms of the GNU General Public License as published by
16
13
along with this program; if not, write to the Free Software
17
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
#ifndef SQL_AUDIT_INCLUDED
17
#define SQL_AUDIT_INCLUDED
20
19
#include <my_global.h>
59
58
Call audit plugins of GENERAL audit class, MYSQL_AUDIT_GENERAL_LOG subtype.
62
@param[in] time time that event occurred
63
@param[in] user User name
64
@param[in] userlen User name length
65
61
@param[in] cmd Command name
66
62
@param[in] cmdlen Command name length
67
@param[in] query Query string
68
@param[in] querylen Query string length
63
@param[in] query_str query text. Leave empty to fetch it from THD
64
@param[in] query_len query text length. 0 to fetch it from THD
72
void mysql_audit_general_log(THD *thd, time_t time,
73
const char *user, uint userlen,
74
const char *cmd, uint cmdlen,
75
const char *query, uint querylen)
68
void mysql_audit_general_log(THD *thd, const char *cmd, uint cmdlen,
69
const char *query_str, size_t query_len)
77
71
#ifndef EMBEDDED_LIBRARY
78
72
if (mysql_global_audit_mask[0] & MYSQL_AUDIT_GENERAL_CLASSMASK)
80
74
MYSQL_LEX_STRING sql_command, ip, host, external_user;
75
MYSQL_LEX_STRING query={ (char *)query_str, query_len };
81
76
static MYSQL_LEX_STRING empty= { C_STRING_WITH_LEN("") };
79
char user_buff[MAX_USER_HOST_SIZE + 1];
80
const char *user= user_buff;
81
uint userlen= make_user_name(thd, user_buff);
82
time_t time= (time_t) thd->start_time.tv_sec;
88
/* no query specified, fetch from THD */
89
if (!thd->rewritten_query.length())
90
mysql_rewrite_query(thd);
91
if (thd->rewritten_query.length())
93
query.str= (char *) thd->rewritten_query.ptr();
94
query.length= thd->rewritten_query.length();
98
query.str= thd->query();
99
query.length= thd->query_length();
85
102
ip.str= (char *) thd->security_ctx->get_ip()->ptr();
86
103
ip.length= thd->security_ctx->get_ip()->length();
87
104
host.str= (char *) thd->security_ctx->get_host()->ptr();
102
119
: global_system_variables.character_set_client;
104
121
mysql_audit_notify(thd, MYSQL_AUDIT_GENERAL_CLASS, MYSQL_AUDIT_GENERAL_LOG,
105
0, time, user, userlen, cmd, cmdlen, query, querylen,
106
clientcs, 0, sql_command, host, external_user, ip);
122
error_code, time, user, userlen, cmd, cmdlen, query.str,
123
query.length, clientcs, rows, sql_command, host,
197
215
#define MYSQL_AUDIT_NOTIFY_CONNECTION_DISCONNECT(thd, errcode)\
198
216
mysql_audit_notify(\
199
217
(thd), MYSQL_AUDIT_CONNECTION_CLASS, MYSQL_AUDIT_CONNECTION_DISCONNECT,\
200
(errcode), (thd)->thread_id, "", 0, "", 0, "", 0, "", 0, "", 0, "", 0, "", 0)
218
(errcode), (thd)->thread_id,\
219
(thd)->security_ctx->user,\
220
(thd)->security_ctx->user ? strlen((thd)->security_ctx->user) : 0,\
221
(thd)->security_ctx->priv_user, strlen((thd)->security_ctx->priv_user),\
222
(thd)->security_ctx->get_external_user()->ptr(),\
223
(thd)->security_ctx->get_external_user()->length(),\
224
(thd)->security_ctx->proxy_user, strlen((thd)->security_ctx->proxy_user),\
225
(thd)->security_ctx->get_host()->ptr(),\
226
(thd)->security_ctx->get_host()->length(),\
227
(thd)->security_ctx->get_ip()->ptr(),\
228
(thd)->security_ctx->get_ip()->length(),\
229
(thd)->db, (thd)->db ? strlen((thd)->db) : 0)
202
231
#define MYSQL_AUDIT_NOTIFY_CONNECTION_CHANGE_USER(thd) mysql_audit_notify(\
203
232
(thd), MYSQL_AUDIT_CONNECTION_CLASS, MYSQL_AUDIT_CONNECTION_CHANGE_USER,\