summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorAlexey Botchkov <holyfoot@askmonty.org>2020-10-22 14:00:17 +0400
committerAlexey Botchkov <holyfoot@askmonty.org>2020-10-23 09:17:36 +0400
commitcc1646dae821a136c8368ee84954aac9937abdd4 (patch)
tree5a7b6194ece5dbdd7734a5b55d9b8326a288961a /plugin
parent21ea14db8cc8c5d88ff804650de7caf984d08a98 (diff)
downloadmariadb-git-cc1646dae821a136c8368ee84954aac9937abdd4.tar.gz
MDEV-19443 server_audit plugin doesn't log proxy users.
PROXY_USER event added.
Diffstat (limited to 'plugin')
-rw-r--r--plugin/server_audit/server_audit.c62
1 files changed, 61 insertions, 1 deletions
diff --git a/plugin/server_audit/server_audit.c b/plugin/server_audit/server_audit.c
index 1061c207a75..a029b426ea1 100644
--- a/plugin/server_audit/server_audit.c
+++ b/plugin/server_audit/server_audit.c
@@ -15,7 +15,7 @@
#define PLUGIN_VERSION 0x104
-#define PLUGIN_STR_VERSION "1.4.7"
+#define PLUGIN_STR_VERSION "1.4.9"
#define _my_thread_var loc_thread_var
@@ -328,6 +328,10 @@ struct connection_info
char query_buffer[1024];
time_t query_time;
int log_always;
+ char proxy[64];
+ int proxy_length;
+ char proxy_host[64];
+ int proxy_host_length;
};
#define DEFAULT_FILENAME_LEN 16
@@ -1128,9 +1132,13 @@ static void setup_connection_simple(struct connection_info *ci)
ci->ip_length= 0;
ci->query_length= 0;
ci->header= 0;
+ ci->proxy_length= 0;
}
+#define MAX_HOSTNAME 61
+#define USERNAME_LENGTH 384
+
static void setup_connection_connect(struct connection_info *cn,
const struct mysql_event_connection *event)
{
@@ -1147,6 +1155,29 @@ static void setup_connection_connect(struct connection_info *cn,
get_str_n(cn->ip, &cn->ip_length, sizeof(cn->ip),
event->ip, event->ip_length);
cn->header= 0;
+ if (event->proxy_user && event->proxy_user[0])
+ {
+ const char *priv_host= event->proxy_user +
+ sizeof(char[MAX_HOSTNAME+USERNAME_LENGTH+5]);
+ size_t priv_host_length;
+
+ if (mysql_57_started)
+ {
+ priv_host+= sizeof(size_t);
+ priv_host_length= *(size_t *) (priv_host + MAX_HOSTNAME);
+ }
+ else
+ priv_host_length= strlen(priv_host);
+
+
+ get_str_n(cn->proxy, &cn->proxy_length, sizeof(cn->proxy),
+ event->priv_user, event->priv_user_length);
+ get_str_n(cn->proxy_host, &cn->proxy_host_length,
+ sizeof(cn->proxy_host),
+ priv_host, priv_host_length);
+ }
+ else
+ cn->proxy_length= 0;
}
@@ -1346,6 +1377,31 @@ static size_t log_header(char *message, size_t message_len,
}
+static int log_proxy(const struct connection_info *cn,
+ const struct mysql_event_connection *event)
+
+{
+ time_t ctime;
+ size_t csize;
+ char message[1024];
+
+ (void) time(&ctime);
+ csize= log_header(message, sizeof(message)-1, &ctime,
+ servhost, servhost_len,
+ cn->user, cn->user_length,
+ cn->host, cn->host_length,
+ cn->ip, cn->ip_length,
+ event->thread_id, 0, "PROXY_CONNECT");
+ csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize,
+ ",%.*s,`%.*s`@`%.*s`,%d", cn->db_length, cn->db,
+ cn->proxy_length, cn->proxy,
+ cn->proxy_host_length, cn->proxy_host,
+ event->status);
+ message[csize]= '\n';
+ return write_log(message, csize + 1, 1);
+}
+
+
static int log_connection(const struct connection_info *cn,
const struct mysql_event_connection *event,
const char *type)
@@ -2007,9 +2063,13 @@ static void update_connection_info(struct connection_info *cn,
{
case MYSQL_AUDIT_CONNECTION_CONNECT:
setup_connection_connect(cn, event);
+ if (event->status == 0 && event->proxy_user && event->proxy_user[0])
+ log_proxy(cn, event);
break;
case MYSQL_AUDIT_CONNECTION_CHANGE_USER:
*after_action= AA_CHANGE_USER;
+ if (event->proxy_user && event->proxy_user[0])
+ log_proxy(cn, event);
break;
default:;
}