Commit 68f6c229 authored by Sergei Golubchik's avatar Sergei Golubchik

prefer static inline functions to macros.

avoid unnecessary strlen()'s
parent 775e8263
...@@ -2414,7 +2414,7 @@ void close_connection(THD *thd, uint sql_errno) ...@@ -2414,7 +2414,7 @@ void close_connection(THD *thd, uint sql_errno)
{ {
sleep(0); /* Workaround to avoid tailcall optimisation */ sleep(0); /* Workaround to avoid tailcall optimisation */
} }
MYSQL_AUDIT_NOTIFY_CONNECTION_DISCONNECT(thd, sql_errno); mysql_audit_notify_connection_disconnect(thd, sql_errno);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
#endif /* EMBEDDED_LIBRARY */ #endif /* EMBEDDED_LIBRARY */
......
...@@ -43,10 +43,16 @@ static inline bool mysql_audit_general_enabled() ...@@ -43,10 +43,16 @@ static inline bool mysql_audit_general_enabled()
return mysql_global_audit_mask[0] & MYSQL_AUDIT_GENERAL_CLASSMASK; return mysql_global_audit_mask[0] & MYSQL_AUDIT_GENERAL_CLASSMASK;
} }
static inline bool mysql_audit_connection_enabled()
{
return mysql_global_audit_mask[0] & MYSQL_AUDIT_CONNECTION_CLASSMASK;
}
#else #else
static inline void mysql_audit_notify(THD *thd, uint event_class, static inline void mysql_audit_notify(THD *thd, uint event_class,
uint event_subtype, ...) { } uint event_subtype, ...) { }
#define mysql_audit_general_enabled() 0 #define mysql_audit_general_enabled() 0
#define mysql_audit_connection_enabled() 0
#endif #endif
extern void mysql_audit_release(THD *thd); extern void mysql_audit_release(THD *thd);
...@@ -137,41 +143,58 @@ void mysql_audit_general(THD *thd, uint event_subtype, ...@@ -137,41 +143,58 @@ void mysql_audit_general(THD *thd, uint event_subtype,
} }
} }
#define MYSQL_AUDIT_NOTIFY_CONNECTION_CONNECT(thd) mysql_audit_notify(\ static inline
(thd), MYSQL_AUDIT_CONNECTION_CLASS, MYSQL_AUDIT_CONNECTION_CONNECT,\ void mysql_audit_notify_connection_connect(THD *thd)
(thd)->stmt_da->is_error() ? (thd)->stmt_da->sql_errno() : 0,\ {
(thd)->thread_id, (thd)->security_ctx->user,\ if (mysql_audit_connection_enabled())
(thd)->security_ctx->user ? strlen((thd)->security_ctx->user) : 0,\ {
(thd)->security_ctx->priv_user, strlen((thd)->security_ctx->priv_user),\ const Security_context *sctx= thd->security_ctx;
(thd)->security_ctx->external_user,\ mysql_audit_notify(thd, MYSQL_AUDIT_CONNECTION_CLASS,
(thd)->security_ctx->external_user ?\ MYSQL_AUDIT_CONNECTION_CONNECT,
strlen((thd)->security_ctx->external_user) : 0,\ thd->stmt_da->is_error() ? thd->stmt_da->sql_errno() : 0,
(thd)->security_ctx->proxy_user, strlen((thd)->security_ctx->proxy_user),\ thd->thread_id,
(thd)->security_ctx->host,\ sctx->user, sctx->user ? strlen(sctx->user) : 0,
(thd)->security_ctx->host ? strlen((thd)->security_ctx->host) : 0,\ sctx->priv_user, strlen(sctx->priv_user),
(thd)->security_ctx->ip,\ sctx->external_user,
(thd)->security_ctx->ip ? strlen((thd)->security_ctx->ip) : 0,\ sctx->external_user ? strlen(sctx->external_user) : 0,
(thd)->db, (thd)->db ? strlen((thd)->db) : 0) sctx->proxy_user, strlen(sctx->proxy_user),
sctx->host, sctx->host ? strlen(sctx->host) : 0,
#define MYSQL_AUDIT_NOTIFY_CONNECTION_DISCONNECT(thd, errcode)\ sctx->ip, sctx->ip ? strlen(sctx->ip) : 0,
mysql_audit_notify(\ thd->db, thd->db ? strlen(thd->db) : 0);
(thd), MYSQL_AUDIT_CONNECTION_CLASS, MYSQL_AUDIT_CONNECTION_DISCONNECT,\ }
(errcode), (thd)->thread_id, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) }
#define MYSQL_AUDIT_NOTIFY_CONNECTION_CHANGE_USER(thd) mysql_audit_notify(\ static inline
(thd), MYSQL_AUDIT_CONNECTION_CLASS, MYSQL_AUDIT_CONNECTION_CHANGE_USER,\ void mysql_audit_notify_connection_disconnect(THD *thd, int errcode)
(thd)->stmt_da->is_error() ? (thd)->stmt_da->sql_errno() : 0,\ {
(thd)->thread_id, (thd)->security_ctx->user,\ if (mysql_audit_connection_enabled())
(thd)->security_ctx->user ? strlen((thd)->security_ctx->user) : 0,\ {
(thd)->security_ctx->priv_user, strlen((thd)->security_ctx->priv_user),\ mysql_audit_notify(thd, MYSQL_AUDIT_CONNECTION_CLASS,
(thd)->security_ctx->external_user,\ MYSQL_AUDIT_CONNECTION_DISCONNECT,
(thd)->security_ctx->external_user ?\ errcode, thd->thread_id,
strlen((thd)->security_ctx->external_user) : 0,\ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
(thd)->security_ctx->proxy_user, strlen((thd)->security_ctx->proxy_user),\ }
(thd)->security_ctx->host,\ }
(thd)->security_ctx->host ? strlen((thd)->security_ctx->host) : 0,\
(thd)->security_ctx->ip,\ static inline
(thd)->security_ctx->ip ? strlen((thd)->security_ctx->ip) : 0,\ void mysql_audit_notify_connection_change_user(THD *thd)
(thd)->db, (thd)->db ? strlen((thd)->db) : 0) {
if (mysql_audit_connection_enabled())
{
const Security_context *sctx= thd->security_ctx;
mysql_audit_notify(thd, MYSQL_AUDIT_CONNECTION_CLASS,
MYSQL_AUDIT_CONNECTION_CHANGE_USER,
thd->stmt_da->is_error() ? thd->stmt_da->sql_errno() : 0,
thd->thread_id,
sctx->user, sctx->user ? strlen(sctx->user) : 0,
sctx->priv_user, strlen(sctx->priv_user),
sctx->external_user,
sctx->external_user ? strlen(sctx->external_user) : 0,
sctx->proxy_user, strlen(sctx->proxy_user),
sctx->host, sctx->host ? strlen(sctx->host) : 0,
sctx->ip, sctx->ip ? strlen(sctx->ip) : 0,
thd->db, thd->db ? strlen(thd->db) : 0);
}
}
#endif /* SQL_AUDIT_INCLUDED */ #endif /* SQL_AUDIT_INCLUDED */
...@@ -1187,7 +1187,7 @@ bool thd_prepare_connection(THD *thd) ...@@ -1187,7 +1187,7 @@ bool thd_prepare_connection(THD *thd)
bool rc; bool rc;
lex_start(thd); lex_start(thd);
rc= login_connection(thd); rc= login_connection(thd);
MYSQL_AUDIT_NOTIFY_CONNECTION_CONNECT(thd); mysql_audit_notify_connection_connect(thd);
if (rc) if (rc)
return rc; return rc;
......
...@@ -1011,7 +1011,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, ...@@ -1011,7 +1011,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
else else
rc= acl_authenticate(thd, 0, packet_length); rc= acl_authenticate(thd, 0, packet_length);
MYSQL_AUDIT_NOTIFY_CONNECTION_CHANGE_USER(thd); mysql_audit_notify_connection_change_user(thd);
if (rc) if (rc)
{ {
/* Free user if allocated by acl_authenticate */ /* Free user if allocated by acl_authenticate */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment