~ubuntu-branches/ubuntu/wily/mysql-5.6/wily

« back to all changes in this revision

Viewing changes to sql/sql_audit.h

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2015-04-16 20:07:10 UTC
  • mto: (1.3.9 vivid-proposed)
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: package-import@ubuntu.com-20150416200710-pcrsa022082zj46k
Tags: upstream-5.6.24
ImportĀ upstreamĀ versionĀ 5.6.24

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef SQL_AUDIT_INCLUDED
2
 
#define SQL_AUDIT_INCLUDED
3
 
 
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.
5
2
 
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 */
18
15
 
 
16
#ifndef SQL_AUDIT_INCLUDED
 
17
#define SQL_AUDIT_INCLUDED
19
18
 
20
19
#include <my_global.h>
21
20
 
59
58
  Call audit plugins of GENERAL audit class, MYSQL_AUDIT_GENERAL_LOG subtype.
60
59
  
61
60
  @param[in] thd
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
69
 
*/
 
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
 
65
  */
70
66
 
71
67
static inline
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)
76
70
{
77
71
#ifndef EMBEDDED_LIBRARY
78
72
  if (mysql_global_audit_mask[0] & MYSQL_AUDIT_GENERAL_CLASSMASK)
79
73
  {
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("") };
 
77
    ha_rows rows= 0;
 
78
    int error_code= 0; 
 
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;
82
83
 
83
84
    if (thd)
84
85
    {
 
86
      if (!query_len)
 
87
      {
 
88
        /* no query specified, fetch from THD */
 
89
        if (!thd->rewritten_query.length())
 
90
          mysql_rewrite_query(thd);
 
91
        if (thd->rewritten_query.length())
 
92
        {
 
93
          query.str= (char *) thd->rewritten_query.ptr();
 
94
          query.length= thd->rewritten_query.length();
 
95
        }
 
96
        else
 
97
        {
 
98
          query.str= thd->query();
 
99
          query.length= thd->query_length();
 
100
        }
 
101
      }
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;
103
120
 
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,
 
124
                       external_user, ip);
107
125
  }
108
126
#endif
109
127
}
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)
201
230
 
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,\