Merge branch '2.2' into develop

This commit is contained in:
Markus Mäkelä
2018-10-02 10:18:09 +03:00
16 changed files with 125 additions and 135 deletions

View File

@ -2405,21 +2405,7 @@ DCB* dcb_accept(DCB* dcb)
{
dcb->stats.n_accepts++;
/* set nonblocking */
sendbuf = MXS_CLIENT_SO_SNDBUF;
if (setsockopt(c_sock, SOL_SOCKET, SO_SNDBUF, &sendbuf, optlen) != 0)
{
MXS_ERROR("Failed to set socket options: %d, %s", errno, mxs_strerror(errno));
}
sendbuf = MXS_CLIENT_SO_RCVBUF;
if (setsockopt(c_sock, SOL_SOCKET, SO_RCVBUF, &sendbuf, optlen) != 0)
{
MXS_ERROR("Failed to set socket options: %d, %s", errno, mxs_strerror(errno));
}
setnonblocking(c_sock);
configure_network_socket(c_sock, client_conn.ss_family);
client_dcb = dcb_alloc(DCB_ROLE_CLIENT_HANDLER, dcb->listener);

View File

@ -348,9 +348,12 @@ static void sigterm_handler(int i)
if (n_shutdowns == 1)
{
if (write(STDERR_FILENO, shutdown_msg, sizeof(shutdown_msg) - 1) == -1)
if (!daemon_mode)
{
printf("Failed to write shutdown message!\n");
if (write(STDERR_FILENO, shutdown_msg, sizeof(shutdown_msg) - 1) == -1)
{
printf("Failed to write shutdown message!\n");
}
}
}
else
@ -366,16 +369,22 @@ static void sigint_handler(int i)
if (n_shutdowns == 1)
{
if (write(STDERR_FILENO, shutdown_msg, sizeof(shutdown_msg) - 1) == -1)
if (!daemon_mode)
{
printf("Failed to write shutdown message!\n");
if (write(STDERR_FILENO, shutdown_msg, sizeof(shutdown_msg) - 1) == -1)
{
printf("Failed to write shutdown message!\n");
}
}
}
else if (n_shutdowns == 2)
{
if (write(STDERR_FILENO, patience_msg, sizeof(patience_msg) - 1) == -1)
if (!daemon_mode)
{
printf("Failed to write shutdown message!\n");
if (write(STDERR_FILENO, patience_msg, sizeof(patience_msg) - 1) == -1)
{
printf("Failed to write shutdown message!\n");
}
}
}
else
@ -1919,6 +1928,11 @@ int main(int argc, char** argv)
mxs_log_finish();
}
if (cnf->log_target != MXB_LOG_TARGET_STDOUT && daemon_mode)
{
mxs_log_redirect_stdout(true);
}
if (!init_log())
{
rc = MAXSCALE_BADCONFIG;

View File

@ -983,17 +983,18 @@ void utils_end()
replace_values_re = NULL;
}
static bool configure_network_socket(int so)
bool configure_network_socket(int so, int type)
{
int sndbufsize = MXS_BACKEND_SO_SNDBUF;
int rcvbufsize = MXS_BACKEND_SO_RCVBUF;
int sndbufsize = MXS_SO_SNDBUF_SIZE;
int rcvbufsize = MXS_SO_RCVBUF_SIZE;
int one = 1;
if (setsockopt(so, SOL_SOCKET, SO_SNDBUF, &sndbufsize, sizeof(sndbufsize)) != 0
|| setsockopt(so, SOL_SOCKET, SO_RCVBUF, &rcvbufsize, sizeof(rcvbufsize)) != 0
|| setsockopt(so, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)) != 0)
|| (type != AF_UNIX && setsockopt(so, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)) != 0))
{
MXS_ERROR("Failed to set socket option: %d, %s.", errno, mxs_strerror(errno));
mxb_assert(!true);
return false;
}
@ -1065,7 +1066,7 @@ int open_network_socket(enum mxs_socket_type type,
freeaddrinfo(ai);
if ((type == MXS_SOCKET_NETWORK && !configure_network_socket(so))
if ((type == MXS_SOCKET_NETWORK && !configure_network_socket(so, addr->ss_family))
|| (type == MXS_SOCKET_LISTENER && !configure_listener_socket(so)))
{
close(so);

View File

@ -59,75 +59,23 @@ void gssapi_backend_auth_free(void* data)
static bool send_new_auth_token(DCB* dcb)
{
bool rval = false;
OM_uint32 major = 0, minor = 0;
gss_ctx_id_t handle = NULL;
gss_buffer_desc in = {0, 0};
gss_buffer_desc out = {0, 0};
gss_buffer_desc target = {0, 0};
gss_name_t princ = GSS_C_NO_NAME;
gssapi_auth_t* auth = (gssapi_auth_t*)dcb->authenticator_data;
MYSQL_session* ses = (MYSQL_session*)dcb->session->client_dcb->data;
GWBUF* buffer = gwbuf_alloc(MYSQL_HEADER_LEN + ses->auth_token_len);
/** The service principal name is sent by the backend server */
target.value = auth->principal_name;
target.length = auth->principal_name_len + 1;
// This function actually just forwards the client's token to the backend server
/** Convert the name into GSSAPI format */
major = gss_import_name(&minor, &target, GSS_C_NT_USER_NAME, &princ);
if (GSS_ERROR(major))
if (buffer)
{
report_error(major, minor);
}
uint8_t* data = (uint8_t*)GWBUF_DATA(buffer);
gw_mysql_set_byte3(data, ses->auth_token_len);
data += 3;
*data++ = ++auth->sequence;
memcpy(data, ses->auth_token, ses->auth_token_len);
/** Request the token for the service */
major = gss_init_sec_context(&minor,
GSS_C_NO_CREDENTIAL,
&handle,
princ,
GSS_C_NO_OID,
0,
0,
GSS_C_NO_CHANNEL_BINDINGS,
&in,
NULL,
&out,
0,
0);
if (GSS_ERROR(major))
{
report_error(major, minor);
}
else
{
/** We successfully requested the token, send it to the backend server */
GWBUF* buffer = gwbuf_alloc(MYSQL_HEADER_LEN + out.length);
if (buffer)
if (dcb_write(dcb, buffer))
{
uint8_t* data = (uint8_t*)GWBUF_DATA(buffer);
gw_mysql_set_byte3(data, out.length);
data += 3;
*data++ = ++auth->sequence;
memcpy(data, out.value, out.length);
if (dcb_write(dcb, buffer))
{
rval = true;
}
}
major = gss_delete_sec_context(&minor, &handle, &in);
if (GSS_ERROR(major))
{
report_error(major, minor);
}
major = gss_release_name(&minor, &princ);
if (GSS_ERROR(major))
{
report_error(major, minor);
rval = true;
}
}