forked from kunpengcompute/mysql-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WL#11378 Log the connection attributes into audit log's connection event
The client applications can send user-defined attributes to the server. They can be queried through the performance_schema.session_account_connect_attrs table. With this WL these connection attributes are logged in the audit log too. RB#22551
- Loading branch information
1 parent
050a57c
commit 3624b20
Showing
12 changed files
with
515 additions
and
8 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
components/mysql_server/mysql_connection_attributes_iterator_imp.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License, version 2.0, | ||
as published by the Free Software Foundation. | ||
This program is also distributed with certain software (including | ||
but not limited to OpenSSL) that is licensed under separate terms, | ||
as designated in a particular file or component or in included license | ||
documentation. The authors of MySQL hereby grant you an additional | ||
permission to link the program and your derivative works with the | ||
separately licensed software that they have included with MySQL. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License, version 2.0, for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ | ||
|
||
#ifndef MYSQL_CONNECTION_ATTRIBUTES_ITERATOR_IMP_H | ||
#define MYSQL_CONNECTION_ATTRIBUTES_ITERATOR_IMP_H | ||
|
||
#include <mysql/components/service_implementation.h> | ||
#include <mysql/components/services/mysql_connection_attributes_iterator.h> | ||
|
||
/** | ||
@class mysql_thd_variables_service_imp | ||
Thread variables' service implementation. | ||
This service provides functions for plugins and storage engines to | ||
obtain the thread's THD variables. | ||
@sa mysql_connection_attributes_iterator | ||
*/ | ||
|
||
class mysql_connection_attributes_iterator_imp { | ||
public: | ||
/** | ||
Initialize an iterator. | ||
Also position at the first attribute. | ||
@param opaque_thd The session to operate on. Can be null to use the | ||
current THD. | ||
@param[out] iterator Iterator pointer. | ||
@return | ||
@retval false Succeeded. | ||
@retval true Failed. | ||
@sa mysql_connection_attributes_iterator::init | ||
*/ | ||
static DEFINE_BOOL_METHOD(init, | ||
(MYSQL_THD opaque_thd, | ||
my_h_connection_attributes_iterator *iterator)); | ||
|
||
/** | ||
Deinitialize an iterator. | ||
@param iterator Iterator pointer. | ||
@return | ||
@retval false Succeeded. | ||
@retval true Failed. | ||
@sa mysql_connection_attributes_iterator::deinit | ||
*/ | ||
static DEFINE_BOOL_METHOD(deinit, | ||
(my_h_connection_attributes_iterator iterator)); | ||
|
||
/** | ||
Fetch the current name/value pair from the iterator and move it forward. | ||
Note: the attribute's name and value pointers are valid until the THD | ||
object is alive. | ||
@param opaque_thd The session to operate on. Can be NULL to use | ||
the current THD. | ||
@param iterator Iterator pointer. | ||
@param[out] name The attribute name. | ||
@param[out] name_length The attribute name's length. | ||
@param[out] value The attribute value. | ||
@param[out] value_length The attribute value's length. | ||
@param[out] client_charset The character set, used for encoding the | ||
connection attributes pair | ||
@return | ||
@retval false Succeeded. | ||
@retval true Failed. | ||
@sa mysql_connection_attributes_iterator::get | ||
*/ | ||
static DEFINE_BOOL_METHOD(get, (MYSQL_THD opaque_thd, | ||
my_h_connection_attributes_iterator *iterator, | ||
const char **name, size_t *name_length, | ||
const char **value, size_t *value_length, | ||
const char **client_charset)); | ||
}; | ||
|
||
#endif /* !MYSQL_CONNECTION_ATTRIBUTES_ITERATOR_IMP_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
include/mysql/components/services/mysql_connection_attributes_iterator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License, version 2.0, | ||
as published by the Free Software Foundation. | ||
This program is also distributed with certain software (including | ||
but not limited to OpenSSL) that is licensed under separate terms, | ||
as designated in a particular file or component or in included license | ||
documentation. The authors of MySQL hereby grant you an additional | ||
permission to link the program and your derivative works with the | ||
separately licensed software that they have included with MySQL. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License, version 2.0, for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ | ||
|
||
#ifndef MYSQL_CONNECTION_ATTRIBUTES_ITERATOR_H | ||
#define MYSQL_CONNECTION_ATTRIBUTES_ITERATOR_H | ||
|
||
#include <mysql/components/service.h> | ||
#include <mysql/components/services/mysql_current_thread_reader.h> // MYSQL_THD | ||
#include <stddef.h> | ||
|
||
/** | ||
@ingroup group_components_services_inventory | ||
A service to read the connection attributes from the current session | ||
It provides a read-only iterator over the attributes. | ||
This is some example code to use the iterator: | ||
@code | ||
// at init time. try to reuse the service handles as much as possible | ||
my_service<SERVICE_TYPE(mysql_current_thread_reader)> thd_reader( | ||
"mysql_current_thread_reader", m_reg_srv); | ||
my_service<SERVICE_TYPE(mysql_connection_attributes_iterator)> service( | ||
"mysql_connection_attributes_iterator", m_reg_srv); | ||
if (!service.is_valid() || !thd_reader.is_valid) { | ||
return; //error | ||
} | ||
... | ||
// at parse time | ||
MYSQL_THD thd; | ||
if (thd_reader->get(&thd)) | ||
return; //error | ||
my_h_connection_attributes_iterator iterator; | ||
MYSQL_LEX_CSTRING name; | ||
MYSQL_LEX_CSTRING value; | ||
const char *charset_string; | ||
const CHARSET_INFO *charset = nullptr; | ||
my_h_connection_attributes_iterator iterator; | ||
if (service->init(thd, &iterator)) return; // error | ||
while (!service->get(thd, &iterator, &name.str, &name.length, &value.str, | ||
&value.length, &charset_string)) { | ||
// Do something with name and value | ||
} | ||
service->deinit(iterator); | ||
@endcode | ||
*/ | ||
|
||
typedef const char *my_h_connection_attributes_iterator; | ||
|
||
BEGIN_SERVICE_DEFINITION(mysql_connection_attributes_iterator) | ||
|
||
/** | ||
Initialize an iterator. | ||
Also position at the first attribute. | ||
@param thd The session to operate on. Can be NULL to use the | ||
current THD. | ||
@param[out] iterator Iterator pointer. | ||
@return | ||
@retval false Succeeded. | ||
@retval true Failed. | ||
@sa mysql_connection_attributes_iterator_imp::init | ||
*/ | ||
DECLARE_BOOL_METHOD(init, (MYSQL_THD thd, | ||
my_h_connection_attributes_iterator *iterator)); | ||
|
||
/** | ||
Deinitialize an iterator. | ||
@param iterator Iterator pointer. | ||
@return | ||
@retval false Succeeded. | ||
@retval true Failed. | ||
@sa mysql_connection_attributes_iterator_imp::deinit | ||
*/ | ||
DECLARE_BOOL_METHOD(deinit, (my_h_connection_attributes_iterator iterator)); | ||
|
||
/** | ||
Fetch the current name/value pair from the iterator and move it forward. | ||
Note: the attribute's name and value pointers are valid until the THD object | ||
is alive. | ||
@param thd The session to operate on. Can be NULL to use the | ||
current THD. | ||
@param iterator Iterator pointer. | ||
@param[out] name The attribute name. | ||
@param[out] name_length The attribute name's length. | ||
@param[out] value The attribute value. | ||
@param[out] value_length The attribute value's length. | ||
@param[out] client_charset The character set, used for encoding the | ||
connection attributes pair | ||
@return | ||
@retval false Succeeded. | ||
@retval true Failed. | ||
@sa mysql_connection_attributes_iterator_imp::get | ||
*/ | ||
DECLARE_BOOL_METHOD(get, | ||
(MYSQL_THD thd, | ||
my_h_connection_attributes_iterator *iterator, | ||
const char **name, size_t *name_length, const char **value, | ||
size_t *value_length, const char **client_charset)); | ||
|
||
END_SERVICE_DEFINITION(mysql_connection_attributes_iterator) | ||
|
||
#endif /* MYSQL_CONNECTION_ATTRIBUTES_ITERATOR_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.