#At file:///usr/home/serg/Abk/mysql/6.0-maria/ based on revid:guilhem@stripped
2735 Sergei Golubchik 2009-04-07
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
modified:
include/mysql/plugin_audit.h
sql/log.cc
sql/mysqld.cc
sql/protocol.cc
sql/set_var.cc
sql/sql_audit.h
sql/sql_parse.cc
sql/sql_plugin.cc
=== modified file 'include/mysql/plugin_audit.h'
--- a/include/mysql/plugin_audit.h 2008-03-26 14:30:28 +0000
+++ b/include/mysql/plugin_audit.h 2009-04-07 20:19:26 +0000
@@ -24,8 +24,7 @@
#define MYSQL_AUDIT_CLASS_MASK_SIZE 1
-#define MYSQL_AUDIT_INTERFACE_VERSION ( 0x010000 | MYSQL_AUDIT_CLASS_MASK_SIZE )
-
+#define MYSQL_AUDIT_INTERFACE_VERSION 0x0100
/*
The first word in every event class struct indicates the specific
=== modified file 'sql/log.cc'
--- a/sql/log.cc 2009-04-01 21:36:07 +0000
+++ b/sql/log.cc 2009-04-07 20:19:26 +0000
@@ -45,7 +45,6 @@
/* max size of the log message */
#define MAX_LOG_BUFFER_SIZE 1024
-#define MAX_USER_HOST_SIZE 512
#define MAX_TIME_SIZE 32
#define MY_OFF_T_UNDEF (~(my_off_t)0UL)
@@ -1979,7 +1978,6 @@ bool LOGGER::general_log_write(THD *thd,
bool error= FALSE;
Log_event_handler **current_handler= general_log_handler_list;
char user_host_buff[MAX_USER_HOST_SIZE];
- Security_context *sctx= thd->security_ctx;
ulong id;
uint user_host_len= 0;
time_t current_time;
@@ -1995,21 +1993,15 @@ bool LOGGER::general_log_write(THD *thd,
unlock();
return 0;
}
- user_host_len= strxnmov(user_host_buff, MAX_USER_HOST_SIZE,
- sctx->priv_user ? sctx->priv_user : "", "[",
- sctx->user ? sctx->user : "", "] @ ",
- sctx->host ? sctx->host : "", " [",
- sctx->ip ? sctx->ip : "", "]", NullS) -
- user_host_buff;
+ user_host_len= make_user_name(thd, user_host_buff);
current_time= my_time(0);
- mysql_audit_general(thd, MYSQL_AUDIT_GENERAL_LOG, 0, current_time,
- user_host_buff, user_host_len,
- command_name[(uint) command].str,
- command_name[(uint) command].length,
- query, query_length,
- thd->variables.character_set_client,0);
+ mysql_audit_general_log(thd, current_time,
+ user_host_buff, user_host_len,
+ command_name[(uint) command].str,
+ command_name[(uint) command].length,
+ query, query_length);
while (*current_handler)
error|= (*current_handler++)->
=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc 2009-04-01 21:36:07 +0000
+++ b/sql/mysqld.cc 2009-04-07 20:19:26 +0000
@@ -2990,7 +2990,7 @@ extern "C" void my_message_sql(uint erro
void my_message_sql(uint error, const char *str, myf MyFlags)
{
- THD *thd;
+ THD *thd= current_thd;
DBUG_ENTER("my_message_sql");
DBUG_PRINT("error", ("error: %u message: '%s'", error, str));
@@ -3012,6 +3012,8 @@ void my_message_sql(uint error, const ch
error= ER_UNKNOWN_ERROR;
}
+ mysql_audit_general(thd, MYSQL_AUDIT_GENERAL_ERROR, error, str);
+
/*
TODO: ME_JUST_INFO and ME_JUST_WARNING are back doors used in
storage/maria to print to the server log files.
@@ -3036,7 +3038,7 @@ void my_message_sql(uint error, const ch
DBUG_VOID_RETURN;
}
- if ((thd= current_thd))
+ if (thd)
{
if (MyFlags & ME_FATALERROR)
thd->is_fatal_error= 1;
=== modified file 'sql/protocol.cc'
--- a/sql/protocol.cc 2009-04-01 21:36:07 +0000
+++ b/sql/protocol.cc 2009-04-07 20:19:26 +0000
@@ -28,15 +28,13 @@
#include <stdarg.h>
static const unsigned int PACKET_BUFFER_EXTRA_ALLOC= 1024;
-void net_send_error_packet(THD *thd, uint sql_errno, const char *err,
- const char* sqlstate);
+void net_send_error_packet(THD *, uint, const char *, const char *);
/* Declared non-static only because of the embedded library. */
void net_send_ok(THD *, uint, uint, ulonglong, ulonglong, const char *);
/* Declared non-static only because of the embedded library. */
void net_send_eof(THD *thd, uint server_status, uint statement_warn_count);
#ifndef EMBEDDED_LIBRARY
-static void write_eof_packet(THD *thd, NET *net,
- uint server_status, uint statement_warn_count);
+static void write_eof_packet(THD *, NET *, uint, uint);
#endif
#ifndef EMBEDDED_LIBRARY
=== modified file 'sql/set_var.cc'
--- a/sql/set_var.cc 2009-04-01 21:36:07 +0000
+++ b/sql/set_var.cc 2009-04-07 20:19:26 +0000
@@ -3938,7 +3938,6 @@ void set_var_free()
@param str Name of system variable to find
@param length Length of variable. zero means that we should use strlen()
on the variable
- @param no_error Refuse to emit an error, even if one occurred.
@retval
pointer pointer to variable definitions
@@ -3946,7 +3945,7 @@ void set_var_free()
0 Unknown variable (error message is given)
*/
-sys_var *intern_find_sys_var(const char *str, uint length, bool no_error)
+sys_var *intern_find_sys_var(const char *str, uint length)
{
sys_var *var;
@@ -3956,9 +3955,6 @@ sys_var *intern_find_sys_var(const char
*/
var= (sys_var*) my_hash_search(&system_variable_hash,
(uchar*) str, length ? length : strlen(str));
- if (!(var || no_error))
- my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
-
return var;
}
=== modified file 'sql/sql_audit.h'
--- a/sql/sql_audit.h 2008-03-26 14:30:28 +0000
+++ b/sql/sql_audit.h 2009-04-07 20:19:26 +0000
@@ -31,18 +31,21 @@ extern void mysql_audit_notify(THD *thd,
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
@@ -50,23 +53,75 @@ 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
}
+
+
=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc 2009-04-01 21:36:07 +0000
+++ b/sql/sql_parse.cc 2009-04-07 20:19:26 +0000
@@ -1456,13 +1456,7 @@ bool dispatch_command(enum enum_server_c
close_thread_tables(thd);
if (!thd->is_error() && !thd->killed_errno())
- {
- mysql_audit_general(thd,MYSQL_AUDIT_GENERAL_RESULT,0,my_time(0),
- 0,0,0,0,
- thd->query,thd->query_length,
- thd->variables.character_set_client,
- thd->warning_info->current_row_for_warning());
- }
+ mysql_audit_general(thd, MYSQL_AUDIT_GENERAL_RESULT, 0, 0);
log_slow_statement(thd);
=== modified file 'sql/sql_plugin.cc'
--- a/sql/sql_plugin.cc 2009-04-01 20:48:42 +0000
+++ b/sql/sql_plugin.cc 2009-04-07 20:19:26 +0000
@@ -213,7 +213,7 @@ static void reap_plugins(void);
/* declared in set_var.cc */
-extern sys_var *intern_find_sys_var(const char *str, uint length, bool no_error);
+extern sys_var *intern_find_sys_var(const char *str, uint length);
extern bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
const char *name, longlong val);
@@ -1002,6 +1002,9 @@ static int plugin_initialize(struct st_p
DBUG_ENTER("plugin_initialize");
safe_mutex_assert_owner(&LOCK_plugin);
+ DBUG_ASSERT(plugin->state == PLUGIN_IS_UNINITIALIZED);
+
+ pthread_mutex_unlock(&LOCK_plugin);
if (plugin_type_initialize[plugin->plugin->type])
{
@@ -1022,6 +1025,8 @@ static int plugin_initialize(struct st_p
}
}
+ pthread_mutex_lock(&LOCK_plugin);
+
plugin->state= PLUGIN_IS_READY;
if (plugin->plugin->status_vars)
@@ -1039,9 +1044,10 @@ static int plugin_initialize(struct st_p
{0, 0, SHOW_UNDEF}
};
if (add_status_vars(array)) // add_status_vars makes a copy
- goto err;
+ goto err1;
#else
- add_status_vars(plugin->plugin->status_vars); // add_status_vars makes a copy
+ if (add_status_vars(plugin->plugin->status_vars))
+ goto err1;
#endif /* FIX_LATER */
}
@@ -1063,6 +1069,8 @@ static int plugin_initialize(struct st_p
DBUG_RETURN(0);
err:
+ pthread_mutex_lock(&LOCK_plugin);
+err1:
DBUG_RETURN(1);
}
@@ -1671,7 +1679,6 @@ bool mysql_install_plugin(THD *thd, cons
}
else
{
- DBUG_ASSERT(tmp->state == PLUGIN_IS_UNINITIALIZED);
if (plugin_initialize(tmp))
{
my_error(ER_CANT_INITIALIZE_UDF, MYF(0), name->str,
@@ -2149,7 +2156,7 @@ sys_var *find_sys_var(THD *thd, const ch
pthread_mutex_lock(&LOCK_plugin);
rw_rdlock(&LOCK_system_variables_hash);
- if ((var= intern_find_sys_var(str, length, false)) &&
+ if ((var= intern_find_sys_var(str, length)) &&
(pi= var->cast_pluginvar()))
{
rw_unlock(&LOCK_system_variables_hash);
@@ -2168,11 +2175,7 @@ sys_var *find_sys_var(THD *thd, const ch
rw_unlock(&LOCK_system_variables_hash);
pthread_mutex_unlock(&LOCK_plugin);
- /*
- If the variable exists but the plugin it is associated with is not ready
- then the intern_plugin_lock did not raise an error, so we do it here.
- */
- if (pi && !var)
+ if (!var)
my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
DBUG_RETURN(var);
}
@@ -2375,7 +2378,7 @@ static uchar *intern_sys_var_ptr(THD* th
st_bookmark *v= (st_bookmark*) my_hash_element(&bookmark_hash,idx);
if (v->version <= thd->variables.dynamic_variables_version ||
- !(var= intern_find_sys_var(v->key + 1, v->name_len, true)) ||
+ !(var= intern_find_sys_var(v->key + 1, v->name_len)) ||
!(pi= var->cast_pluginvar()) ||
v->key[0] != (pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK))
continue;
@@ -2468,7 +2471,7 @@ static void cleanup_variables(THD *thd,
{
v= (st_bookmark*) my_hash_element(&bookmark_hash, idx);
if (v->version > vars->dynamic_variables_version ||
- !(var= intern_find_sys_var(v->key + 1, v->name_len, true)) ||
+ !(var= intern_find_sys_var(v->key + 1, v->name_len)) ||
!(pivar= var->cast_pluginvar()) ||
v->key[0] != (pivar->plugin_var->flags & PLUGIN_VAR_TYPEMASK))
continue;
Attachment: [text/bzr-bundle] bzr/serg@mysql.com-20090407201926-olrlj9wpqlkq37cj.bundle
| Thread |
|---|
| • bzr commit into mysql-6.0 branch (serg:2735) Bug#36098 | Sergei Golubchik | 7 Apr |