MXS-1762: Compare client IP when choosing a connection

When the connection pool is inspected, both the client username and IP
must match. This causes the pool to be partitioned by username and IP,
prevening unintentional sharing of connections between different users.
This commit is contained in:
Markus Mäkelä 2018-04-08 20:34:41 +03:00
parent d07d9d59df
commit cddf132d23
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
3 changed files with 19 additions and 7 deletions

View File

@ -283,7 +283,7 @@ extern void server_transfer_status(SERVER *dest_server, const SERVER *source_ser
extern void server_add_mon_user(SERVER *server, const char *user, const char *passwd);
extern const char *server_get_parameter(const SERVER *server, char *name);
extern void server_update_credentials(SERVER *server, const char *user, const char *passwd);
extern DCB *server_get_persistent(SERVER *server, const char *user, const char *protocol, int id);
extern DCB* server_get_persistent(SERVER *server, const char *user, const char* ip, const char *protocol, int id);
extern void server_update_address(SERVER *server, const char *address);
extern void server_update_port(SERVER *server, unsigned short port);
extern unsigned int server_map_status(const char *str);

View File

@ -617,7 +617,8 @@ dcb_connect(SERVER *server, MXS_SESSION *session, const char *protocol)
{
MXS_DEBUG("%lu [dcb_connect] Looking for persistent connection DCB "
"user %s protocol %s\n", pthread_self(), user, protocol);
dcb = server_get_persistent(server, user, protocol, session->client_dcb->thread.id);
dcb = server_get_persistent(server, user, session->client_dcb->remote,
protocol, session->client_dcb->thread.id);
if (dcb)
{
/**
@ -664,6 +665,11 @@ dcb_connect(SERVER *server, MXS_SESSION *session, const char *protocol)
memcpy(&(dcb->func), funcs, sizeof(MXS_PROTOCOL));
dcb->protoname = MXS_STRDUP_A(protocol);
if (session->client_dcb->remote)
{
dcb->remote = MXS_STRDUP_A(session->client_dcb->remote);
}
const char *authenticator = server->authenticator ?
server->authenticator : dcb->func.auth_default ?
dcb->func.auth_default() : "NullAuthDeny";

View File

@ -205,12 +205,15 @@ server_free(SERVER *tofreeserver)
/**
* Get a DCB from the persistent connection pool, if possible
*
* @param server The server to set the name on
* @param user The name of the user needing the connection
* @param protocol The name of the protocol needed for the connection
* @param server The server to set the name on
* @param user The name of the user needing the connection
* @param ip Client IP address
* @param protocol The name of the protocol needed for the connection
* @param id Thread ID
*
* @return A DCB or NULL if no connection is found
*/
DCB *
server_get_persistent(SERVER *server, const char *user, const char *protocol, int id)
DCB* server_get_persistent(SERVER *server, const char *user, const char* ip, const char *protocol, int id)
{
DCB *dcb, *previous = NULL;
@ -224,9 +227,12 @@ server_get_persistent(SERVER *server, const char *user, const char *protocol, in
{
if (dcb->user
&& dcb->protoname
&& dcb->remote
&& ip
&& !dcb-> dcb_errhandle_called
&& !(dcb->flags & DCBF_HUNG)
&& 0 == strcmp(dcb->user, user)
&& 0 == strcmp(dcb->remote, ip)
&& 0 == strcmp(dcb->protoname, protocol))
{
if (NULL == previous)