plugin_audit.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or
  3. modify it under the terms of the GNU General Public License
  4. as published by the Free Software Foundation; version 2 of
  5. the License.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  13. #ifndef _my_audit_h
  14. #define _my_audit_h
  15. /*************************************************************************
  16. API for Audit plugin. (MYSQL_AUDIT_PLUGIN)
  17. */
  18. #include "plugin.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. #define MYSQL_AUDIT_CLASS_MASK_SIZE 1
  23. #define MYSQL_AUDIT_INTERFACE_VERSION 0x0302
  24. /*************************************************************************
  25. AUDIT CLASS : GENERAL
  26. LOG events occurs before emitting to the general query log.
  27. ERROR events occur before transmitting errors to the user.
  28. RESULT events occur after transmitting a resultset to the user.
  29. STATUS events occur after transmitting a resultset or errors
  30. to the user.
  31. */
  32. #define MYSQL_AUDIT_GENERAL_CLASS 0
  33. #define MYSQL_AUDIT_GENERAL_CLASSMASK (1 << MYSQL_AUDIT_GENERAL_CLASS)
  34. #define MYSQL_AUDIT_GENERAL_LOG 0
  35. #define MYSQL_AUDIT_GENERAL_ERROR 1
  36. #define MYSQL_AUDIT_GENERAL_RESULT 2
  37. #define MYSQL_AUDIT_GENERAL_STATUS 3
  38. struct mysql_event_general
  39. {
  40. unsigned int event_subclass;
  41. int general_error_code;
  42. unsigned long general_thread_id;
  43. const char *general_user;
  44. unsigned int general_user_length;
  45. const char *general_command;
  46. unsigned int general_command_length;
  47. const char *general_query;
  48. unsigned int general_query_length;
  49. struct charset_info_st *general_charset;
  50. unsigned long long general_time;
  51. unsigned long long general_rows;
  52. /* Added in version 0x302 */
  53. unsigned long long query_id;
  54. const char *database;
  55. unsigned int database_length;
  56. };
  57. /*
  58. AUDIT CLASS : CONNECTION
  59. CONNECT occurs after authentication phase is completed.
  60. DISCONNECT occurs after connection is terminated.
  61. CHANGE_USER occurs after COM_CHANGE_USER RPC is completed.
  62. */
  63. #define MYSQL_AUDIT_CONNECTION_CLASS 1
  64. #define MYSQL_AUDIT_CONNECTION_CLASSMASK (1 << MYSQL_AUDIT_CONNECTION_CLASS)
  65. #define MYSQL_AUDIT_CONNECTION_CONNECT 0
  66. #define MYSQL_AUDIT_CONNECTION_DISCONNECT 1
  67. #define MYSQL_AUDIT_CONNECTION_CHANGE_USER 2
  68. struct mysql_event_connection
  69. {
  70. unsigned int event_subclass;
  71. int status;
  72. unsigned long thread_id;
  73. const char *user;
  74. unsigned int user_length;
  75. const char *priv_user;
  76. unsigned int priv_user_length;
  77. const char *external_user;
  78. unsigned int external_user_length;
  79. const char *proxy_user;
  80. unsigned int proxy_user_length;
  81. const char *host;
  82. unsigned int host_length;
  83. const char *ip;
  84. unsigned int ip_length;
  85. const char *database;
  86. unsigned int database_length;
  87. };
  88. /*
  89. AUDIT CLASS : TABLE
  90. LOCK occurs when a connection "locks" (this does not necessarily mean a table
  91. lock and also happens for row-locking engines) the table at the beginning of
  92. a statement. This event is generated at the beginning of every statement for
  93. every affected table, unless there's a LOCK TABLES statement in effect (in
  94. which case it is generated once for LOCK TABLES and then is suppressed until
  95. the tables are unlocked).
  96. CREATE/DROP/RENAME occur when a table is created, dropped, or renamed.
  97. */
  98. #define MYSQL_AUDIT_TABLE_CLASS 15
  99. #define MYSQL_AUDIT_TABLE_CLASSMASK (1 << MYSQL_AUDIT_TABLE_CLASS)
  100. #define MYSQL_AUDIT_TABLE_LOCK 0
  101. #define MYSQL_AUDIT_TABLE_CREATE 1
  102. #define MYSQL_AUDIT_TABLE_DROP 2
  103. #define MYSQL_AUDIT_TABLE_RENAME 3
  104. #define MYSQL_AUDIT_TABLE_ALTER 4
  105. struct mysql_event_table
  106. {
  107. unsigned int event_subclass;
  108. unsigned long thread_id;
  109. const char *user;
  110. const char *priv_user;
  111. const char *priv_host;
  112. const char *external_user;
  113. const char *proxy_user;
  114. const char *host;
  115. const char *ip;
  116. const char *database;
  117. unsigned int database_length;
  118. const char *table;
  119. unsigned int table_length;
  120. /* for MYSQL_AUDIT_TABLE_LOCK, true if read-only, false if read/write */
  121. int read_only;
  122. /* for MYSQL_AUDIT_TABLE_RENAME */
  123. const char *new_database;
  124. unsigned int new_database_length;
  125. const char *new_table;
  126. unsigned int new_table_length;
  127. /* Added in version 0x302 */
  128. unsigned long long query_id;
  129. };
  130. /*************************************************************************
  131. Here we define the descriptor structure, that is referred from
  132. st_mysql_plugin.
  133. release_thd() event occurs when the event class consumer is to be
  134. disassociated from the specified THD. This would typically occur
  135. before some operation which may require sleeping - such as when
  136. waiting for the next query from the client.
  137. event_notify() is invoked whenever an event occurs which is of any
  138. class for which the plugin has interest. The second argument
  139. indicates the specific event class and the third argument is data
  140. as required for that class.
  141. class_mask is an array of bits used to indicate what event classes
  142. that this plugin wants to receive.
  143. */
  144. struct st_mysql_audit
  145. {
  146. int interface_version;
  147. void (*release_thd)(MYSQL_THD);
  148. void (*event_notify)(MYSQL_THD, unsigned int, const void *);
  149. unsigned long class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE];
  150. };
  151. #ifdef __cplusplus
  152. }
  153. #endif
  154. #endif