summaryrefslogtreecommitdiff
path: root/sql/sql_audit.h
diff options
context:
space:
mode:
authorSergey Vojtovich <svoj@sun.com>2009-12-16 15:56:36 +0400
committerSergey Vojtovich <svoj@sun.com>2009-12-16 15:56:36 +0400
commit9130563708cbdbb488e5361af79eb9f4b9dab0ea (patch)
tree8df7485477b00a145ea370f2c5fa7822e249b010 /sql/sql_audit.h
parent45f2e0a7aad762af94eedd70b6fc0b91ae8e3376 (diff)
downloadmariadb-git-9130563708cbdbb488e5361af79eb9f4b9dab0ea.tar.gz
Backport from 6.0-codebase.
Bug #36098 Audit plugin (wl 3771) feature disabled in 6.0 avoid recusrive locking of LOCK_plugin include/mysql/plugin_audit.h: fix incorrect version sql/log.cc: move the common code to a shared header sql/mysqld.cc: restore the deleted functionality sql/set_var.cc: remove unused parameter sql/sql_audit.h: two inline convenience functions sql/sql_parse.cc: use a simplified convenience call sql/sql_plugin.cc: unlock LOCK_plugin for plugin->init() call, add missing OOM check, issue "unknown variable" error in find_sys_var, not down the stack
Diffstat (limited to 'sql/sql_audit.h')
-rw-r--r--sql/sql_audit.h87
1 files changed, 70 insertions, 17 deletions
diff --git a/sql/sql_audit.h b/sql/sql_audit.h
index 155211e7ba5..c25011d0d59 100644
--- a/sql/sql_audit.h
+++ b/sql/sql_audit.h
@@ -34,18 +34,21 @@ extern void mysql_audit_notify(THD *thd, uint event_class,
uint event_subtype, ...);
extern void mysql_audit_release(THD *thd);
-
+#define MAX_USER_HOST_SIZE 512
+static inline uint make_user_name(THD *thd, char *buf)
+{
+ Security_context *sctx= thd->security_ctx;
+ return strxnmov(buf, MAX_USER_HOST_SIZE,
+ sctx->priv_user ? sctx->priv_user : "", "[",
+ sctx->user ? sctx->user : "", "] @ ",
+ sctx->host ? sctx->host : "", " [",
+ sctx->ip ? sctx->ip : "", "]", NullS) - buf;
+}
/**
- Call audit plugins of GENERAL audit class.
- event_subtype should be set to one of:
- MYSQL_AUDIT_GENERAL_LOG
- MYSQL_AUDIT_GENERAL_ERROR
- MYSQL_AUDIT_GENERAL_RESULT
+ Call audit plugins of GENERAL audit class, MYSQL_AUDIT_GENERAL_LOG subtype.
@param[in] thd
- @param[in] event_subtype Type of general audit event.
- @param[in] error_code Error code
@param[in] time time that event occurred
@param[in] user User name
@param[in] userlen User name length
@@ -53,24 +56,74 @@ extern void mysql_audit_release(THD *thd);
@param[in] cmdlen Command name length
@param[in] query Query string
@param[in] querylen Query string length
- @param[in] clientcs Charset of query string
- @param[in] rows Number of affected rows
*/
static inline
+void mysql_audit_general_log(THD *thd, time_t time,
+ const char *user, uint userlen,
+ const char *cmd, uint cmdlen,
+ const char *query, uint querylen)
+{
+#ifndef EMBEDDED_LIBRARY
+ if (mysql_global_audit_mask[0] & MYSQL_AUDIT_GENERAL_CLASSMASK)
+ {
+ CHARSET_INFO *clientcs= thd ? thd->variables.character_set_client
+ : global_system_variables.character_set_client;
+
+ mysql_audit_notify(thd, MYSQL_AUDIT_GENERAL_CLASS, MYSQL_AUDIT_GENERAL_LOG,
+ 0, time, user, userlen, cmd, cmdlen,
+ query, querylen, clientcs, 0);
+ }
+#endif
+}
+
+/**
+ Call audit plugins of GENERAL audit class.
+ event_subtype should be set to one of:
+ MYSQL_AUDIT_GENERAL_ERROR
+ MYSQL_AUDIT_GENERAL_RESULT
+
+ @param[in] thd
+ @param[in] event_subtype Type of general audit event.
+ @param[in] error_code Error code
+ @param[in] msg Message
+*/
+static inline
void mysql_audit_general(THD *thd, uint event_subtype,
- int error_code, time_t time,
- const char *user, uint userlen,
- const char *cmd, uint cmdlen,
- const char *query, uint querylen,
- CHARSET_INFO *clientcs,
- ha_rows rows)
+ int error_code, const char *msg)
{
#ifndef EMBEDDED_LIBRARY
if (mysql_global_audit_mask[0] & MYSQL_AUDIT_GENERAL_CLASSMASK)
+ {
+ time_t time= my_time(0);
+ uint msglen= msg ? strlen(msg) : 0;
+ const char *query, *user;
+ uint querylen, userlen;
+ char user_buff[MAX_USER_HOST_SIZE];
+ CHARSET_INFO *clientcs;
+ ha_rows rows;
+
+ if (thd)
+ {
+ query= thd->query();
+ querylen= thd->query_length();
+ user= user_buff;
+ userlen= make_user_name(thd, user_buff);
+ clientcs= thd->variables.character_set_client;
+ rows= thd->warning_info->current_row_for_warning();
+ }
+ else
+ {
+ query= user= 0;
+ querylen= userlen= 0;
+ clientcs= global_system_variables.character_set_client;
+ rows= 0;
+ }
+
mysql_audit_notify(thd, MYSQL_AUDIT_GENERAL_CLASS, event_subtype,
- error_code, time, user, userlen, cmd, cmdlen,
+ error_code, time, user, userlen, msg, msglen,
query, querylen, clientcs, rows);
+ }
#endif
}