Skip to content

Commit 22b2508

Browse files
lthfacebook-github-bot
authored andcommitted
Expose port for audit plugin
Summary: Expose the port current mysqld is running on for the audit plugin. If no port, 0 is used. Reviewed By: cevans87 Differential Revision: D5046701 fbshipit-source-id: e9d19be
1 parent 9263f54 commit 22b2508

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

include/mysql/plugin_audit.h

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ struct mysql_event_general
7171
unsigned long long affected_rows;
7272
const char *query_attributes;
7373
unsigned int query_attributes_length;
74+
unsigned int port;
7475
};
7576

7677

@@ -110,6 +111,7 @@ struct mysql_event_connection
110111
/* Added in version 0x304 */
111112
const char *connection_certificate;
112113
unsigned int connection_certificate_length;
114+
unsigned int port;
113115
};
114116

115117

include/mysql/plugin_audit.h.pp

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@
292292
unsigned long long affected_rows;
293293
const char *query_attributes;
294294
unsigned int query_attributes_length;
295+
unsigned int port;
295296
};
296297
struct mysql_event_connection
297298
{
@@ -314,6 +315,7 @@
314315
unsigned int database_length;
315316
const char *connection_certificate;
316317
unsigned int connection_certificate_length;
318+
unsigned int port;
317319
};
318320
struct st_mysql_audit
319321
{

sql/sql_audit.cc

+2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ static void general_class_handler(THD *thd, uint event_subtype, va_list ap)
9393
event.query_attributes= va_arg(ap, const char*);
9494
event.query_attributes_length= va_arg(ap, unsigned int);
9595
event.query_id= thd ? (unsigned long long) thd->query_id : 0LL;
96+
event.port = va_arg(ap, unsigned int);
9697
event_class_dispatch(thd, MYSQL_AUDIT_GENERAL_CLASS, &event);
9798
}
9899

@@ -119,6 +120,7 @@ static void connection_class_handler(THD *thd, uint event_subclass, va_list ap)
119120
event.database_length= va_arg(ap, unsigned int);
120121
event.connection_certificate= va_arg(ap, const char*);
121122
event.connection_certificate_length= va_arg(ap, unsigned int);
123+
event.port = va_arg(ap, unsigned int);
122124
event_class_dispatch(thd, MYSQL_AUDIT_CONNECTION_CLASS, &event);
123125
}
124126

sql/sql_audit.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void mysql_audit_general_log(THD *thd, const char *cmd, uint cmdlen,
135135
error_code, time, user, userlen, cmd, cmdlen, query.str,
136136
query.length, clientcs, resultrows, affectrows,
137137
sql_command, host, external_user, ip, database,
138-
databaselen, queryattr, queryattrlen);
138+
databaselen, queryattr, queryattrlen, mysqld_port);
139139
}
140140
#endif
141141
}
@@ -223,7 +223,7 @@ void mysql_audit_general(THD *thd, uint event_subtype,
223223
query.str(), query.length(), query.charset(),
224224
resultrows, affectrows, sql_command, host,
225225
external_user, ip, database, databaselen,
226-
queryattr, queryattrlen);
226+
queryattr, queryattrlen, mysqld_port);
227227
}
228228
#endif
229229
}
@@ -243,7 +243,7 @@ void mysql_audit_general(THD *thd, uint event_subtype,
243243
(thd)->security_ctx->get_ip()->length(),\
244244
(thd)->db, (thd)->db ? strlen((thd)->db) : 0,\
245245
(thd)->connection_certificate(),\
246-
(thd)->connection_certificate_length());
246+
(thd)->connection_certificate_length(), mysqld_port);
247247

248248

249249
#define MYSQL_AUDIT_NOTIFY_CONNECTION_DISCONNECT(thd, errcode)\
@@ -262,7 +262,7 @@ void mysql_audit_general(THD *thd, uint event_subtype,
262262
(thd)->security_ctx->get_ip()->length(),\
263263
(thd)->db, (thd)->db ? strlen((thd)->db) : 0,\
264264
(thd)->connection_certificate(),\
265-
(thd)->connection_certificate_length());
265+
(thd)->connection_certificate_length(), mysqld_port);
266266

267267
#define MYSQL_AUDIT_NOTIFY_CONNECTION_CHANGE_USER(thd) mysql_audit_notify(\
268268
(thd), MYSQL_AUDIT_CONNECTION_CLASS, MYSQL_AUDIT_CONNECTION_CHANGE_USER,\
@@ -279,6 +279,6 @@ void mysql_audit_general(THD *thd, uint event_subtype,
279279
(thd)->security_ctx->get_ip()->length(),\
280280
(thd)->db, (thd)->db ? strlen((thd)->db) : 0,\
281281
(thd)->connection_certificate(),\
282-
(thd)->connection_certificate_length());
282+
(thd)->connection_certificate_length(), mysqld_port);
283283

284284
#endif /* SQL_AUDIT_INCLUDED */

0 commit comments

Comments
 (0)